Exemplo n.º 1
0
        /// <summary>
        /// Generates a list of potentially visitable tiles and the costs to enter them. Tiles outside the mapbounds are not added.
        /// </summary>
        /// <param name="speed"></param>
        /// <param name="pos"></param>
        /// <param name="moveCosts"></param>
        /// <returns></returns>
        private List <PathNode> GetUnvisitedTiles(int speed, Position pos, MovementMap moveCosts, UnitTeam team)
        {
            List <PathNode> unvisited = new List <PathNode>();

            //only look at the diamond of squares around the given position
            //within the speed. This assumes no 0 move-cost tiles.
            for (int i = -speed; i <= speed; i++)
            {
                int jVal = 0;
                if (i >= 0)
                {
                    jVal = speed - i;
                }
                else
                {
                    jVal = speed + i;
                }
                for (int j = -jVal; j <= jVal; j++)
                {
                    Position nodePos = new Position(i + pos.xPos, j + pos.yPos);
                    PathNode node    = new PathNode(nodePos);

                    if (nodePos.xPos < 0 || nodePos.xPos >= Width)
                    {
                        continue;                                                                //outside map bounds
                    }
                    if (nodePos.yPos < 0 || nodePos.yPos >= Height)
                    {
                        continue;                                                                 //outside map bounds
                    }
                    //check for another team in the square. These squares cannot be entered.
                    MapUnit mu = unitMap[i + pos.xPos, j + pos.yPos];
                    if (mu != null)
                    {
                        if (mu.Stats.TeamID != team)
                        {
                            continue;
                        }
                    }

                    TerrainType terrain = terrainMap[nodePos.xPos, nodePos.yPos];

                    if (node.pos.Equals(pos))
                    {
                        node.cost = 0;                         //free to "enter" the square you're already in.
                    }
                    else
                    {
                        node.cost = moveCosts.costDict[terrain];;                          //cost to enter the square
                    }

                    unvisited.Add(node);
                }
            }
            return(unvisited);
        }
        /// <summary>
        /// Generates a list of potentially visitable tiles and the costs to enter them. Tiles outside the mapbounds are not added.
        /// </summary>
        /// <param name="speed"></param>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        /// <param name="moveCosts"></param>
        /// <param name="blockedSpaces"></param>
        /// <returns></returns>
        private List <PathNode> GetUnvisitedTiles(int speed, int xPos, int yPos, MovementMap moveCosts)
        {
            List <PathNode> unvisited = new List <PathNode>();

            for (int i = -speed; i <= speed; i++)
            {
                int jVal = 0;
                if (i >= 0)
                {
                    jVal = speed - i;
                }
                else
                {
                    jVal = speed + i;
                }
                for (int j = -jVal; j <= jVal; j++)
                {
                    Position nodePos = new Position(i + xPos, j + yPos);
                    PathNode node    = new PathNode(nodePos);

                    if (nodePos.xPos < 0 || nodePos.xPos >= Width)
                    {
                        continue;                                                                //outside map bounds
                    }
                    if (nodePos.yPos < 0 || nodePos.yPos >= Height)
                    {
                        continue;                                                                 //outside map bounds
                    }
                    TerrainType terrain = terrainMap[nodePos.xPos, nodePos.yPos];

                    node.cost = moveCosts.costDict[terrain];;                      //cost to enter the square


                    unvisited.Add(node);
                }
            }
            return(unvisited);
        }
 public UnitEntity()
 {
     MoveCosts = new MovementMap();
 }