private List<Tile> GetLandAttackableTiles(LandCombatUnit landUnit, Tile tile)
        {
            List<Tile> tiles = new List<Tile>();
            switch (landUnit.EquipmentClassEnum)
            {
                case EquipmentClassEnum.AirDefense:
                    tiles = GetAdjacentTiles(tile, landUnit.Equipment.Range, true);
                    tiles.Add(tile);
                    tiles = tiles.Where(t => t.AirUnit != null).ToList();
                    tiles = tiles.Where(t => t.AirUnit.SideEnum != landUnit.SideEnum).ToList();
                    break;
                case EquipmentClassEnum.AntiAir:
                    tiles = GetAdjacentTiles(tile, landUnit.Equipment.Range, true);
                    tiles.Add(tile);
                    tiles = tiles.Where(t => t.AirUnit != null).ToList();
                    tiles = tiles.Where(t => t.AirUnit.SideEnum != landUnit.SideEnum).ToList();
                    List<Tile> landTiles = new List<Tile>();
                    landTiles = GetAdjacentTiles(tile, 1, true);
                    landTiles = tiles.Where(t => t.GroundUnit != null).ToList();
                    landTiles = tiles.Where(t => t.GroundUnit.SideEnum != landUnit.SideEnum).ToList();
                    tiles.AddRange(landTiles);
                    break;
                case EquipmentClassEnum.Artillery:
                    tiles = GetAdjacentTiles(tile, landUnit.Equipment.Range, true);
                    tiles = tiles.Where(t => t.GroundUnit != null).ToList();
                    tiles = tiles.Where(t => t.GroundUnit.SideEnum != landUnit.SideEnum).ToList();
                    break;
                default:
                    tiles = GetAdjacentTiles(tile, 1, true);
                    tiles = tiles.Where(t => t.GroundUnit != null).ToList();
                    tiles = tiles.Where(t => t.GroundUnit.SideEnum != landUnit.SideEnum).ToList();
                    break;
            }

            return tiles;
        }
        private static Tile DetermineLandWithdrawlTile(LandCombatUnit landCombatUnit)
        {
            Tile targetTile = null;
            List<Tile> adjacentTiles = null;

            foreach (Tile tile in landCombatUnit.MoveableTiles)
            {
                adjacentTiles = Game.TileFactory.GetAdjacentTiles(tile, 1, false);
                adjacentTiles = adjacentTiles.Where(t => t.VictoryIndicator).ToList();
                targetTile = adjacentTiles.Where(t => t.GroundUnit.SideEnum == SideEnum.Allies).FirstOrDefault();
                if (targetTile != null)
                {
                    return targetTile;
                }
            }
            return null;
        }
 private static void MoveLandCombatUnit(LandCombatUnit landCombatUnit, Tile currentTile)
 {
     Tile targetTile = null;
     TargetAndJumpOffTile targetAndJumpOffTile = null;
     targetTile = DetermineCaptureTile(landCombatUnit);
     if (targetTile != null)
     {
         Game.BoardFactory.ActiveTile = currentTile;
         Game.BoardFactory.ActiveUnit = landCombatUnit;
         Game.BoardFactory.MoveUnitForComputerPlayer(landCombatUnit, currentTile, targetTile);
         return;
     }
     targetAndJumpOffTile = DetermineLandAttackJumpOffTile(landCombatUnit, currentTile);
     if (landCombatUnit.CanAttack && targetAndJumpOffTile != null)
     {
         Game.BoardFactory.ActiveTile = currentTile;
         Game.BoardFactory.ActiveUnit = landCombatUnit;
         Game.BoardFactory.MoveUnitForComputerPlayer(landCombatUnit, currentTile, targetAndJumpOffTile.JumpOffTile);
         Game.BoardFactory.ActiveTile = targetAndJumpOffTile.JumpOffTile;
         if (landCombatUnit.CanAttack)
         {
             Game.BoardFactory.CalculateBattleForComputerPlayer(targetAndJumpOffTile.TargetTile);
         }
         return;
     }
     targetTile = DetermineLandWithdrawlTile(landCombatUnit);
     if(targetTile != null)
     {
         Game.BoardFactory.ActiveTile = currentTile;
         Game.BoardFactory.ActiveUnit = landCombatUnit;
         Game.BoardFactory.MoveUnitForComputerPlayer(landCombatUnit, currentTile, targetTile);
         return;
     }
 }
        private static TargetAndJumpOffTile DetermineLandAttackJumpOffTile(LandCombatUnit landCombatUnit, Tile currentTile)
        {
            List<Tile> adjacentTiles = null;
            List<TargetAndJumpOffTile> targetAndJumpOffTiles = new List<TargetAndJumpOffTile>();
            TargetAndJumpOffTile targetAndJumpOffTile = null;

            foreach (Tile tile in landCombatUnit.MoveableTiles)
            {
                adjacentTiles = Game.TileFactory.GetAdjacentTiles(tile, 1, false);
                adjacentTiles = adjacentTiles.Where(t => t.GroundUnit != null).ToList();
                adjacentTiles = adjacentTiles.Where(t => t.GroundUnit.SideEnum == SideEnum.Axis).ToList();
                foreach (Tile potentialTargetTile in adjacentTiles)
                {
                    targetAndJumpOffTile = new TargetAndJumpOffTile();
                    targetAndJumpOffTile.TargetTile = potentialTargetTile;
                    targetAndJumpOffTile.JumpOffTile = tile;
                    targetAndJumpOffTiles.Add(targetAndJumpOffTile);
                }
            }

            return DetermineTarget(targetAndJumpOffTiles, TargetTypeEnum.SoftGround);
        }
        private static Tile DetermineCaptureTile(LandCombatUnit landCombatUnit)
        {
            if(!landCombatUnit.CanCaptureHexes)
            {
                return null;
            }

            Tile targetTile = null;
            foreach (Tile tile in landCombatUnit.MoveableTiles)
            {
                if (tile.VictoryIndicator == true && tile.GroundUnit == null)
                    return targetTile;
                if (tile.SupplyIndicator == true && tile.GroundUnit == null)
                    return targetTile;
            }
            return null;
        }
 private void DisplayLandCombatUnitInformation(LandCombatUnit landCombatUnit)
 {
     int totalCost = landCombatUnit.Equipment.UnitCost;
     SetCombatUnitTextBlock("Ammo", landCombatUnit.Equipment.MaxAmmo.ToString());
     if (landCombatUnit is IMotorizedUnit)
     {
         IMotorizedUnit motorizedUnit = (IMotorizedUnit)landCombatUnit;
         SetCombatUnitTextBlock("Fuel", motorizedUnit.Equipment.MaxFuel.ToString());
     }
     SetCombatUnitTextBlock("Movement Range", landCombatUnit.Equipment.BaseMovement.ToString());
     if (landCombatUnit.EquipmentClassEnum == EquipmentClassEnum.AirDefense ||
         landCombatUnit.EquipmentClassEnum == EquipmentClassEnum.Artillery)
     {
         SetCombatUnitTextBlock("Attack Range", landCombatUnit.Equipment.Range.ToString());
     }
     SetCombatUnitTextBlock("Hard Attack", landCombatUnit.Equipment.HardAttack.ToString());
     SetCombatUnitTextBlock("Soft Attack", landCombatUnit.Equipment.SoftAttack.ToString());
     SetCombatUnitTextBlock("Air Attack", landCombatUnit.Equipment.AirAttack.ToString());
     SetCombatUnitTextBlock("Sea Attack", landCombatUnit.Equipment.NavalAttack.ToString());
     SetCombatUnitTextBlock("Ground Defense", landCombatUnit.Equipment.GroundDefense.ToString());
     SetCombatUnitTextBlock("Air Defense", landCombatUnit.Equipment.AirDefense.ToString());
     SetCombatUnitTextBlock("Sea Defense", landCombatUnit.Equipment.SeaDefense.ToString());
     if (landCombatUnit.TransportUnit != null)
     {
         SetCombatUnitTextBlock("Transport", landCombatUnit.TransportUnit.UnitName.ToString());
         totalCost += landCombatUnit.TransportUnit.Equipment.UnitCost;
     }
     else
     {
         if (landCombatUnit is IMotorizedUnit == false)
         {
             SetCombatUnitTextBlock("Transport", "NONE");
             this.transportButton.Visibility = System.Windows.Visibility.Visible;
         }
     }
     SetCombatUnitTextBlock("COST", totalCost.ToString());
 }
 public LandCombatUnit CreateLandCombatUnit(int unitId, ScenarioUnit scenarioUnit)
 {
     LandCombatUnit unit = new LandCombatUnit();
     unit.UnitId = unitId;
     unit.Equipment = EquipmentFactory.GetEquipment(scenarioUnit.EquipmentId);
     unit.UnitName = String.Format("{0} {1}", unitId, unit.Equipment.EquipmentDescription);
     unit.CoreIndicator = scenarioUnit.CordInd;
     unit.CurrentExperience = scenarioUnit.Experience;
     unit.CurrentStrength = scenarioUnit.Strength;
     unit.CurrentAttackPoints = scenarioUnit.Strength;
     unit.Nation = Game.NationFactory.GetNation(scenarioUnit.NationId);
     unit.CoreIndicator = scenarioUnit.CordInd;
     unit.CurrentAmmo = unit.Equipment.MaxAmmo;
     unit.CurrentEntrenchedLevel = 0;
     unit.CanMove = true;
     unit.CanAttack = true;
     unit.CurrentTileId = scenarioUnit.StartingScenarioTileId;
     return unit;
 }
        public LandCombatUnit CreateDefaultAntiTankUnit(int unitId, Nation nation, int startingTileId)
        {
            LandCombatUnit unit = new LandCombatUnit();
            List<Equipment> equipments = EquipmentFactory.Equipments.Where(e => e.Nation == nation).ToList();
            Equipment equipment = equipments.Where(eq => eq.UnitCost == equipments.Min(e => e.UnitCost)).FirstOrDefault();

            unit.UnitId = unitId;
            unit.Equipment = equipment;
            unit.UnitName = String.Format("{0} {1}", unitId, unit.Equipment.EquipmentDescription);
            unit.Nation = nation;
            unit.CurrentStrength = 10;
            unit.CurrentExperience = 0;
            unit.CanMove = true;
            unit.CurrentTileId = startingTileId;

            if (unit.SideEnum == SideEnum.Axis)
            {
                Game.CurrentTurn.CurrentAxisPrestige = Game.CurrentTurn.CurrentAxisPrestige - unit.Equipment.UnitCost;
            }
            else
            {
                Game.CurrentTurn.CurrentAlliedPrestige = Game.CurrentTurn.CurrentAlliedPrestige - unit.Equipment.UnitCost;
            }

            return unit;
        }