Пример #1
0
        public void ApplyMoves(BoardMove boardMove, bool validate = false)
        {
            if (validate)
            {
                foreach (UnitMove move in boardMove)
                {
                    if (move.IsDisband || move.IsHold)
                    {
                        continue;
                    }
                    if (move.IsBuild)
                    {
                        if (OccupiedMapNodes.ContainsKey(move.Edge.Target))
                        {
                            throw new Exception($"Cannot build {move.Unit} at {move.Edge.Target} because a unit is already there");
                        }
                        if (move.Edge.Target.Territory.HomeSupplyPower != move.Unit.Power)
                        {
                            throw new Exception($"Cannot build {move.Unit} at {move.Edge.Target} because it is not a home supply for {move.Unit.Power}");
                        }
                    }
                    else
                    {
                        if (OccupiedMapNodes[move.Edge.Source] != move.Unit)
                        {
                            throw new Exception($"{move.Unit} is not in {move.Edge.Source}");
                        }
                        if (move.ConvoyRoute == null && !move.Unit.MyMap.AdjacentOutEdges(move.Edge.Source).Contains(move.Edge))
                        {
                            throw new Exception($"{move.Edge} is not a valid edge for {move.Unit}");
                        }
                        // todo add convoy check here
                    }
                }
            }

            OccupiedMapNodes.Clear();
            OccupiedTerritories.Clear();
            foreach (UnitMove move in boardMove)
            {
                if (move.IsDisband)
                {
                    continue;
                }
                if (validate && IsOccupied(move.Edge.Target.Territory))
                {
                    throw new Exception($"Territory {move.Edge.Target} has already been moved into during this BoardMove");
                }
                OccupiedMapNodes.Add(move.Edge.Target, move.Unit);
                OccupiedTerritories.Add(move.Edge.Target.Territory, move.Unit);
            }
        }
Пример #2
0
 public bool IsOccupied(Territory t) => OccupiedTerritories.ContainsKey(t);