public override StrategyResult Apply(UnitBase unit) { if (unit.Power < unit.MoveCost * unit.GetTerrainPenalty(World.GetTerrainType(unit.Y, unit.X))) { return(StrategyResult.NotEnoughPower); } var x = unit.X + _dx; var y = unit.Y + _dy; var blockingUnit = World.Army.GetFirstUnit(unit, _dx, _dy, 5); if (blockingUnit != null && blockingUnit.Team == unit.Team) { if ((blockingUnit as UnitBase).MoveCost > unit.MoveCost) { if (((x + y) & 1) == 0) { x += 1; } else { x -= 1; } } } if (!World.IsPointWithin(x, y)) { return(StrategyResult.NotApplicable); } if (World.Army.GetUnit(y, x) != null) { return(StrategyResult.NotApplicable); } World.MoveUnit(unit, y, x); return(StrategyResult.Applied); }
public virtual StrategyResult Apply(UnitBase unit) { if (unit.Power < unit.MoveCost * unit.GetTerrainPenalty(World.Terrain[unit.X, unit.Y])) { return(StrategyResult.NotEnoughPower); } var x = unit.X + _dx; var y = unit.Y + _dy; if (x >= World.Width || x < 0 || y >= World.Length || y < 0) { return(StrategyResult.NotApplicable); } if (World.Army.GetUnit(y, x) != null) { return(StrategyResult.NotApplicable); } World.MoveUnit(unit, y, x); return(StrategyResult.Applied); }