root/src/BRAINSFramework/Map/GridCell.cs

User picture

Author: conkerjo

Revision: 30 («Previous)


File Size: 2.91 KB

(July 08, 2009 19:40 UTC) Almost 3 years ago


  

 
Show/hide line numbers

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Brains.Framework.Utility;

namespace Brains.Framework.Map
{
    /// <summary>
    /// Stores values about a cell within a grid. 
    /// </summary>
    /// <remarks>Used for pathfinding and other positioning techniques</remarks>
    public class GridCell
    {
        private int _x;
        private int _y;
        private int  _type;
        private Vector2 _position;

        /// <summary>
        /// Gets or sets the annotation labels on the cell
        /// </summary>
        public Dictionary<uint, int> Labels;
        
        /// <summary>
        /// Gets the agents currently occupying this cell
        /// </summary>
        public List<Agent> Agents;
        
        /// <summary>
        /// The Col index of the Grid Cell
        /// </summary>
        public int X { get { return _x; } }
        
        /// <summary>
        /// The Row index of the Grid Cell
        /// </summary>
        public int Y { get { return _y; } }
        
        /// <summary>
        /// The center position of the Grid Cell
        /// </summary>
        public Vector2 Position { get { return _position; } }

        /// <summary>
        /// Type value of the Grid Cell.
        /// </summary>
        /// <remarks>1 = Empty, 0 = Blocked</remarks>
        public int Type 
        { 
            get { return _type; }
            set
            {
                _type = value;
                Labels[AIConsts.BLOCKED_TILE] = _type == 0 ? 1 : 0;
            }
        }
        
        /// <summary>
        /// The Parent Grid
        /// </summary>
        public Grid Parent { get; set; }
        
        /// <summary>
        /// Default Constructor
        /// </summary>
        public GridCell()
        {
            Agents = new List<Agent>();
        }

        /// <summary>
        /// Initializes a new instance of the GridCell class with the specified x and y position and its position in world coordinates
        /// </summary>
        /// <param name="x">The X index of the GridCell</param>
        /// <param name="y">The Y index of the GridCell</param>
        /// <param name="position">The world coordinates of the gridcell</param>
        public GridCell(int x, int y, Vector2 position)
        {

            Labels = new Dictionary<uint, int>();
            Labels.Add(AIConsts.BLOCKED_TILE, 0);
            Labels.Add(AIConsts.RESERVED, 0);
            Labels.Add(AIConsts.CLEARANCEVALUE,0);
            Labels.Add(AIConsts.COLORR, 0);
            Labels.Add(AIConsts.COLORG, 0);
            Labels.Add(AIConsts.COLORB, 0);
            Labels.Add(AIConsts.COLORA, 0);
            
            _x = x;
            _y = y;
            _position = position;
            Agents = new List<Agent>();
        }
    }
}