示例#1
0
 public static Selection SelectTiles(Map thisMap, Selection selection, int left, int top, int width, int height)
 {
     var result = new Selection();
     result.AddRange(selection);
     for (int x = left; x < left + width; x++)
         for (int y = top; y < top + height; y++)
         {
             Tile t = thisMap.GetTileAcrossWrap(x, y);
             if (t != null && !selection.ContainsTile(t))
                 result.Add(t.GetCoordinate());
         }
     return result;
 }
示例#2
0
 public static Map ScrambleSelection(Map thisMap, Selection selection, int distance, bool dontScrambleWater)
 {
     Map map = (Map)thisMap.Clone();
     var unswappedTiles = map.GetAllTiles().Where(t => selection.ContainsTile(t) && !(t.IsWater() && dontScrambleWater)).ToList();
     unswappedTiles = Utility.ShuffleList(unswappedTiles);
     Dictionary<Tile, Tile> swaps = new Dictionary<Tile, Tile>();
     while (unswappedTiles.Count > 0)
     {
         var tileToSwap = unswappedTiles[0];
         Tile tileToSwapWith = null;
         for (var i = 1; i < unswappedTiles.Count; i++)
         {
             var t = unswappedTiles[i];
             if (map.GetDistanceBetween(t.X, t.Y, tileToSwap.X, tileToSwap.Y) <= distance)
             {
                 tileToSwapWith = t;
                 break;
             }
         }
         if (tileToSwapWith != null)
         {
             swaps[tileToSwap] = tileToSwapWith;
             unswappedTiles.Remove(tileToSwapWith);
         }
         unswappedTiles.Remove(tileToSwap);
     }
     foreach (var tile in swaps.Keys)
     {
         Utility.SwapTiles(tile, swaps[tile]);
     }
     map.CalculateFreshWater();
     map.CalculateIrrigationStatus();
     map.AssignContinentIds();
     return map;
 }