/// <summary>
 /// </summary>
 /// <param name="building"></param>
 /// <param name="unit"></param>
 public BuildAction(Building building, Unit unit, GameWorld gw)
 {
     this.building = building;
     this.unit = unit;
     this.actionType = ActionType.BuildBuilding;
     this.gw = gw;
 }
 /// <summary>
 /// Check's if the player has enough resources to build the Building
 /// </summary>
 /// <param name="b">Building to be built</param>
 /// <param name="p">Player that is building</param>
 /// <returns>True if the player has enough resources, false if else</returns>
 public bool checkResources(Building b, ZRTSModel.Player.Player p)
 {
     if (b.stats.waterCost > p.player_resources[0])
         return false;
     if (b.stats.lumberCost > p.player_resources[1])
         return false;
     if (b.stats.foodCost > p.player_resources[2])
         return false;
     if (b.stats.metalCost > p.player_resources[3])
         return false;
     return true;
 }
        /// <summary>
        /// Given a Building, this method will update the visibility map to show that all cells in the range of the building have
        /// been explored.
        /// </summary>
        /// <param name="building"></param>
        public void updateVisMap(Building building)
        {
            // Only update the visibilty map for buildings belonging to the Human player.
            if (building.getOwner() != humanPlayer)
            {
                return;
            }

            byte offset = (byte)STATIC_ENTITY_VIS_RANGE;

            int xStart = (short)building.orginCell.Xcoord - offset;
            int xEnd = (short)building.orginCell.Xcoord + building.width + offset;
            int yStart = (short)building.orginCell.Ycoord - offset;
            int yEnd = (short)building.orginCell.Ycoord + building.height + offset;

            exploreMap(xStart, xEnd, yStart, yEnd);
        }
 /// <summary>
 /// Check if there is room for the building
 /// </summary>
 /// <param name="b">Building to be built</param>
 /// <param name="c">Cell to be origin cell</param>
 /// <returns>True if there is enough space, false if else</returns>
 public bool checkSpace(Building b, Cell c)
 {
     int x = c.Xcoord;
     int y = c.Ycoord;
     if (x < 0 || x + b.width > map.width)
         return false;
     if (y < 0 || y + b.height > map.height)
         return false;
     for (int i = x; i < x + b.width; i++)
     {
         for (int j = y; j < y + b.height; j++)
         {
             if (!map.getCell(i, j).isValid)
                 return false;
         }
     }
     return true;
 }
        /// <summary>
        /// Gives a command to a unit to build a building.
        /// </summary>
        /// <param name="unit">Unit to build the building</param>
        /// <param name="b">Building to be built</param>
        /// <param name="c">Origin cell of the building-to-be</param>
        /// <returns></returns>
        public bool makeUnitBuild(Entity unit, Building b, Cell c)
        {
            if (unit.entityType == Entity.EntityType.Unit)
            {
                if (gameWorld.checkSpace(b, c) && gameWorld.checkResources(b, scenario.getPlayer()))
                {
                    if (locController.addEntity(b, c.Xcoord, c.Ycoord))
                    {
                        b.health = 1;
                        return ActionController.Instance.giveCommand(unit, new BuildAction(b, (Unit)unit, gameWorld));
                    }
                    else
                    {
                        return false;
                    }

                }
            }
            return false;
        }
 /// <summary>
 /// Gives a command to a unit to build a building.
 /// </summary>
 /// <param name="unit">Unit to build the building</param>
 /// <param name="b">Building to be built</param>
 /// <param name="c">Origin cell of the building-to-be</param>
 /// <returns></returns>
 public bool makeUnitBuild(Entity unit, Building b, Cell c)
 {
     if (unit.entityType == Entity.EntityType.Unit)
     {
         if (gameWorld.checkSpace(b, c) && gameWorld.checkResources(b, scenario.getPlayer()))
         {
             gameWorld.insert(b, c);
             return ActionController.Instance.giveCommand(unit, new BuildAction(b, (Unit) unit, gameWorld));
         }
     }
     return false;
 }