root/src/BRAINSFramework/Agent.cs

1320
32
        private IBehavior _rootBehavior;
32
        private IBehavior _rootBehavior;
33
        private LocomotionController _motionController;
33
        private LocomotionController _motionController;
34
34
35
        /// <summary>
36
        /// Gets or sets the Feelers on the agent.
37
        /// </summary>
35
        public List<Feeler> Feelers { get; set; }
38
        public List<Feeler> Feelers { get; set; }
36
39
40
        /// <summary>
41
        /// Gets or sets the name of the Agent
42
        /// </summary>
37
        public string Name { get; set; }
43
        public string Name { get; set; }
38
44
39
        public int NextID
45
        private int NextID
40
        {
46
        {
41
            get
47
            get
42
            {
48
            {
...
...
44
            }
50
            }
45
        }
51
        }
46
52
53
        /// <summary>
54
        /// Gets the cells the agent is in
55
        /// </summary>
56
        /// <remarks>Current implementation only supports 1</remarks>
47
        public List<GridCell> CellsIAmIn { get; set; }
57
        public List<GridCell> CellsIAmIn { get; set; }
48
58
49
        /// <summary>
59
        /// <summary>
50
        /// The position of the Actor
60
        /// The position of the Actor
51
        /// </summary>
61
        /// </summary>
52
        public Vector2 Position { get; set; }
62
        public Vector2 Position { get; set; }
53
63
        /// <summary>
64
        /// Gets or sets the previous position of the agent
65
        /// </summary>
54
        public Vector2 PreviousPosition{ get; set; }
66
        public Vector2 PreviousPosition{ get; set; }
55
67
56
        /// <summary>
68
        /// <summary>
...
...
141
            Feelers.Add(new Feeler(new Vector2(x, y),length,this));
153
            Feelers.Add(new Feeler(new Vector2(x, y),length,this));
142
        }
154
        }
143
155
156
        /// <summary>
157
        /// Update the agent every frame. 
158
        /// </summary>
159
        /// <param name="gameTime">The time elapsed since the last update</param>
144
        public virtual void Update(GameTime gameTime)
160
        public virtual void Update(GameTime gameTime)
145
        {
161
        {
146
            if (RootBehavior != null &&
162
            if (RootBehavior != null &&
...
...
160
        /// Every time an actor changes its position, it remembers all map's nodes
176
        /// Every time an actor changes its position, it remembers all map's nodes
161
        /// he is in.
177
        /// he is in.
162
        /// </summary>
178
        /// </summary>
163
        public void UpdateLocationData()
179
        private void UpdateLocationData()
164
        {
180
        {
165
            // 1. remove itself from all previous AINodes
181
            // 1. remove itself from all previous AINodes
166
            for (int index = 0; index < CellsIAmIn.Count; index++)
182
            for (int index = 0; index < CellsIAmIn.Count; index++)
...
...
193
            int indexY = (int)yComponent;
209
            int indexY = (int)yComponent;
194
            indexX = indexX % map.Cols;
210
            indexX = indexX % map.Cols;
195
            indexY = indexY % map.Rows;
211
            indexY = indexY % map.Rows;
196
            map = GetGridAtPosition(Position);
212
            map = ParentWorld.Map.ClusterGrid.GetGridAtPosition(Position);
197
            if (map != null)
213
            if (map != null)
198
            {
214
            {
199
                GridCell desiredNode = map.GetCell(indexX, indexY);
215
                GridCell desiredNode = map.GetCell(indexX, indexY);
...
...
213
                Console.Write("");
229
                Console.Write("");
214
            }
230
            }
215
        }
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;
229
        }
230
        /// <summary>
232
        /// <summary>
231
        /// Loads a Behavior from a file
233
        /// Loads a Behavior from a file
232
        /// </summary>
234
        /// </summary>