示例#1
0
 public static MapState FromMap(Map map)
 {
     MapState ms = new MapState();
     foreach(Tile t in map.GetAllTiles())
         foreach (Unit u in t.Units)
             if (u.UnitOwner != Game.BarbarianPlayerId)
             {
                 while (ms.PlayerStarts.Count <= u.UnitOwner)
                     ms.PlayerStarts.Add(new PlayerStart() { PlayerId = ms.PlayerStarts.Count });
                 ms.PlayerStarts[u.UnitOwner].StartX = t.X;
                 ms.PlayerStarts[u.UnitOwner].StartY = t.Y;
             }
     return ms;
 }
示例#2
0
 public void ApplyToMap(Map map)
 {
     Dictionary<int, List<Unit>> playerUnits = new Dictionary<int, List<Unit>>();
     foreach (Tile t in map.GetAllTiles())
     {
         foreach (Unit u in t.Units)
         {
             if (!playerUnits.ContainsKey(u.UnitOwner))
                 playerUnits[u.UnitOwner] = new List<Unit>();
             playerUnits[u.UnitOwner].Add(u);
         }
         t.Units.Clear();
     }
     foreach (PlayerStart ps in PlayerStarts)
         map.GetTile(ps.StartX, ps.StartY).Units.AddRange(playerUnits[ps.PlayerId]);
 }
示例#3
0
 public static Map RotateCW(Map thisMap)
 {
     Map map = new Map();
     map.SetDimensions(thisMap.Height, thisMap.Width);
     map.IsHorizontalWrap = thisMap.IsVerticalWrap;
     map.IsVerticalWrap = thisMap.IsHorizontalWrap;
     map.UnparsedData = new List<string>(thisMap.UnparsedData);
     foreach (Tile t in thisMap.GetAllTiles())
     {
         map.SetTile(t.Y, map.Height - 1 - t.X, (Tile)t.Clone());
     }
     Map map2 = (Map)map.Clone();
     foreach (Tile t in map2.GetAllTiles())
     {
         t.IsWOfRiver = false;
         t.IsNOfRiver = false;
     }
     foreach (Tile t in map.GetAllTiles())
     {
         if (t.IsNOfRiver)
         {
             Tile w = map2.GetNeighbour(t.X, t.Y, HorizontalNeighbour.West, VerticalNeighbour.None);
             if (w != null)
             {
                 w.IsWOfRiver = true;
                 if (t.RiverWEDirection == RiverDirection.WEST_TO_EAST)
                     w.RiverNSDirection = RiverDirection.NORTH_TO_SOUTH;
                 else
                     w.RiverNSDirection = RiverDirection.SOUTH_TO_NORTH;
             }
         }
         if (t.IsWOfRiver)
         {
             Tile tt = map2.GetTile(t.X, t.Y);
             tt.IsNOfRiver = true;
             if (t.RiverNSDirection == RiverDirection.NORTH_TO_SOUTH)
                 tt.RiverWEDirection = RiverDirection.EAST_TO_WEST;
             else
                 tt.RiverWEDirection = RiverDirection.WEST_TO_EAST;
         }
     }
     return map2;
 }