Author: conkerjo
(2009/07/01 23:47) Over 2 years ago
Documentation comments
32
private IBehavior _rootBehavior;
33
private LocomotionController _motionController;
34
35
/// <summary>
36
/// Gets or sets the Feelers on the agent.
37
/// </summary>
public List<Feeler> Feelers { get; set; }
38
39
40
41
/// Gets or sets the name of the Agent
42
public string Name { get; set; }
43
44
public int NextID
45
private int NextID
{
46
get
47
48
...
}
50
51
52
53
54
/// Gets the cells the agent is in
55
56
/// <remarks>Current implementation only supports 1</remarks>
public List<GridCell> CellsIAmIn { get; set; }
57
58
49
59
/// The position of the Actor
60
61
public Vector2 Position { get; set; }
62
63
64
/// Gets or sets the previous position of the agent
65
public Vector2 PreviousPosition{ get; set; }
66
67
68
141
Feelers.Add(new Feeler(new Vector2(x, y),length,this));
153
142
154
143
155
156
157
/// Update the agent every frame.
158
159
/// <param name="gameTime">The time elapsed since the last update</param>
144
public virtual void Update(GameTime gameTime)
160
145
161
146
if (RootBehavior != null &&
162
/// Every time an actor changes its position, it remembers all map's nodes
176
/// he is in.
177
178
163
public void UpdateLocationData()
179
private void UpdateLocationData()
164
180
165
// 1. remove itself from all previous AINodes
181
166
for (int index = 0; index < CellsIAmIn.Count; index++)
182
193
int indexY = (int)yComponent;
209
194
indexX = indexX % map.Cols;
210
195
indexY = indexY % map.Rows;
211
196
map = GetGridAtPosition(Position);
212
map = ParentWorld.Map.ClusterGrid.GetGridAtPosition(Position);
197
if (map != null)
213
198
214
199
GridCell desiredNode = map.GetCell(indexX, indexY);
215
Console.Write("");
229
230
231
216
public Grid GetGridAtPosition(Vector2 position)
217
218
foreach (var item in ParentWorld.Map.ClusterGrid.Grids)
219
220
if (
221
(position.X > item.Position.X && position.X < (item.Position.X + item.Width)) &&
222
(position.Y > item.Position.Y && position.Y < (item.Position.Y + item.Height))
223
)
224
225
return item;
226
227
228
return null;
232
/// Loads a Behavior from a file
233
234
3
using System.Linq;
4
using System.Text;
5
using Brains.Framework;
6
using Microsoft.Xna.Framework;
7
namespace Brains.Framework.Map
8
9
//HACK: should support different sized grids
get { return Grids[0].Rows* Rows; }
foreach (var item in Grids)
19
private int _type;
20
private Vector2 _position;
21
22
23
/// Gets or sets the annotation labels on the cell
24
public Dictionary<uint, int> Labels;
25
26
27
28
/// Gets the agents currently occupying this cell
29
public List<Agent> Agents;
30
31
14
15
public class WorldMap
16
17
18
/// Gets the Quadtree of all cells in the map
public QuadTree<GridCell> GridCellTree;
/// Gets the cluster of grids
public Cluster ClusterGrid { get { return _clusterGrid; } }
private Cluster _clusterGrid;
private int _height;
private List<GridCell> _allCells=new List<GridCell>();
/// Gets all of the cells in the map
public List<GridCell> AllCells
get { return _allCells; }
set { _allCells = value; }
/// Gets the top left position of the world
public Vector2 TopLeft
get { return _clusterGrid.Grids[0].Position; }
/// Gets the bottom right position of the world
public Vector2 BottomRight
get { return _clusterGrid.Grids[_clusterGrid.Grids.Count - 1].Position + _clusterGrid.Grids[_clusterGrid.Grids.Count - 1].Size; }
internal WorldMap(int width, int height)
_clusterGrid = new Cluster();
//
//privates
private List<Agent> _agentsToRemove = new List<Agent>();
private Texture2D _mapTexture;
private WorldMap _map;
public List<Agent> Actors = new List<Agent>();
/// Gets the world map
public WorldMap Map { get { return _map; } }
/// Initializes a new world map with the provides parameters
69
70
/// <param name="width">The width of the map in pixels</param>
71
/// <param name="height">The height of the map in pixels</param>
72
/// <param name="cellsize">The size of a cells width or height</param>
public void SetupMap(int width, int height, int cellsize)
73
74
SetupMap(width, height, cellsize, width / cellsize, height / cellsize,typeof(Grid));
75
287
actor.ParentWorld = this;
297
288
Actors.Add(actor);
298
289
299
300
301
/// Loads Map data from a texture
302
303
/// <param name="texture">The texture to use</param>
304
/// <param name="cellSize">The size of a cells width or height</param>
305
/// <param name="grid">The type of grid to create</param>
290
public void LoadMapDataFromTexture(Texture2D texture, int cellSize,Type grid)
306
291
307
292
LoadMapDataFromTexture(texture, 1, 1, cellSize, grid);
308
293
309
310
311
312
313
314
294
public void LoadMapDataFromTexture(Texture2D texture, int cellSize)
315
295
316
296
LoadMapDataFromTexture(texture, 1, 1, cellSize, typeof(Grid));
317
318
319
320
321
322
323
324
/// <param name="cols">The number of cols to split the map into</param>
325
/// <param name="rows">The number of rows to split the map into</param>
326
/// <param name="gridType">The type of grid to create</param>
public void LoadMapDataFromTexture(Texture2D texture, int cols, int rows, int cellSize, Type gridType)
327
328
_mapTexture = texture;
329
370
AddActor(_actor);
399
371
return _actor;
400
372
401
373
List<Agent> _agentsToRemove = new List<Agent>();
402
403
404
/// Removes an Agent from the world
405
406
/// <param name="agent"></param>
374
public void RemoveAgent(Agent agent)
407
375
408
376
_agentsToRemove.Add(agent);
409
public List<Feeler> Feelers { get; set; }public List<Feeler> Feelers { get; set; }public string Name { get; set; }public string Name { get; set; }public int NextIDprivate int NextID{{{{public List<GridCell> CellsIAmIn { get; set; }public List<GridCell> CellsIAmIn { get; set; }public Vector2 Position { get; set; }public Vector2 Position { get; set; }/// <summary>/// Gets or sets the previous position of the agent/// </summary>public Vector2 PreviousPosition{ get; set; }public Vector2 PreviousPosition{ get; set; }{{public void UpdateLocationData()private void UpdateLocationData(){{map = ParentWorld.Map.ClusterGrid.GetGridAtPosition(Position);{{Console.Write("");Console.Write("");public Grid GetGridAtPosition(Vector2 position){foreach (var item in ParentWorld.Map.ClusterGrid.Grids){if ((position.X > item.Position.X && position.X < (item.Position.X + item.Width)) &&(position.Y > item.Position.Y && position.Y < (item.Position.Y + item.Height))){return item;}}return null;}{{get { return Grids[0].Rows* Rows; }get { return Grids[0].Rows* Rows; }{{{{{public Cluster ClusterGrid { get { return _clusterGrid; } }public Cluster ClusterGrid { get { return _clusterGrid; } }{{get { return _allCells; }get { return _allCells; }set { _allCells = value; }set { _allCells = value; }{{get { return _clusterGrid.Grids[0].Position; }get { return _clusterGrid.Grids[0].Position; }{{get { return _clusterGrid.Grids[_clusterGrid.Grids.Count - 1].Position + _clusterGrid.Grids[_clusterGrid.Grids.Count - 1].Size; }get { return _clusterGrid.Grids[_clusterGrid.Grids.Count - 1].Position + _clusterGrid.Grids[_clusterGrid.Grids.Count - 1].Size; }{{public WorldMap Map { get { return _map; } }public WorldMap Map { get { return _map; } }{{{{{{{{List<Agent> _agentsToRemove = new List<Agent>();/// <summary>/// Removes an Agent from the world/// </summary>/// <param name="agent"></param>{{