private static void add_map_area(List <Pair <Tile, TileData> > tiles) { int left = 2147483647; int top = 2147483647; int right = -2147483648; int bottom = -2147483648; foreach (Pair <Tile, TileData> tile in tiles) { Rectangle _rect = MapBuilder.get_rect(tile.First, tile.Second); if (_rect.Left < left) { left = _rect.Left; } if (_rect.Right > right) { right = _rect.Right; } if (_rect.Top < top) { top = _rect.Top; } if (_rect.Bottom <= bottom) { continue; } bottom = _rect.Bottom; } left--; top--; right++; bottom++; MapArea mapArea = new MapArea() { Name = string.Concat("Area ", MapBuilder.fMap.Areas.Count + 1), Region = new Rectangle(left, top, right - left, bottom - top) }; MapBuilder.fMap.Areas.Add(mapArea); }
private static TileData tile_at_point(Point pt) { TileData tileDatum; List <TileData> .Enumerator enumerator = MapBuilder.fMap.Tiles.GetEnumerator(); try { while (enumerator.MoveNext()) { TileData current = enumerator.Current; if (!MapBuilder.get_rect(Session.FindTile(current.TileID, SearchType.Global), current).Contains(pt)) { continue; } tileDatum = current; return(tileDatum); } return(null); } finally { ((IDisposable)enumerator).Dispose(); } }
private static bool check_rect_is_empty(Rectangle rect) { bool flag; List <TileData> .Enumerator enumerator = MapBuilder.fMap.Tiles.GetEnumerator(); try { while (enumerator.MoveNext()) { TileData current = enumerator.Current; if (!MapBuilder.get_rect(Session.FindTile(current.TileID, SearchType.Global), current).IntersectsWith(rect)) { continue; } flag = false; return(flag); } return(true); } finally { ((IDisposable)enumerator).Dispose(); } }
private static void build_warren(EventHandler callback) { MapBuilder.begin_map(); int num = 0; while (MapBuilder.fMap.Areas.Count < MapBuilder.fData.MaxAreaCount && MapBuilder.fEndpoints.Count != 0 && num != 100) { int num1 = Session.Random.Next() % MapBuilder.fEndpoints.Count; Endpoint item = MapBuilder.fEndpoints[num1]; bool flag = true; switch (Session.Random.Next() % 10) { case 0: case 1: case 2: { try { flag = MapBuilder.add_area(item); break; } catch (Exception exception) { LogSystem.Trace(exception); flag = false; break; } } case 3: case 4: case 5: case 6: case 7: { try { flag = MapBuilder.add_corridor(item, false); break; } catch (Exception exception1) { LogSystem.Trace(exception1); flag = false; break; } } case 8: { try { if (item.Category != TileCategory.Doorway) { flag = MapBuilder.add_doorway(item); } break; } catch (Exception exception2) { LogSystem.Trace(exception2); flag = false; break; } } case 9: { try { flag = MapBuilder.add_stairway(item); break; } catch (Exception exception3) { LogSystem.Trace(exception3); flag = false; break; } } } if (!flag) { num++; } else { MapBuilder.fEndpoints.Remove(item); num = 0; callback(null, null); } } List <TileData> tileDatas = new List <TileData>(); foreach (TileData tile in MapBuilder.fMap.Tiles) { Tile tile1 = Session.FindTile(tile.TileID, SearchType.Global); if (tile1 != null) { if (tile1.Category != TileCategory.Doorway) { continue; } Rectangle _rect = MapBuilder.get_rect(tile1, tile); int num2 = 0; int left = _rect.Left; while (left != _rect.Right) { int top = _rect.Top - 1; if (MapBuilder.tile_at_point(new Point(left, top)) != null) { left++; } else { num2++; break; } } int left1 = _rect.Left; while (left1 != _rect.Right) { int bottom = _rect.Bottom + 1; if (MapBuilder.tile_at_point(new Point(left1, bottom)) != null) { left1++; } else { num2++; break; } } int top1 = _rect.Top; while (top1 != _rect.Bottom) { int left2 = _rect.Left - 1; if (MapBuilder.tile_at_point(new Point(left2, top1)) != null) { top1++; } else { num2++; break; } } int top2 = _rect.Top; while (top2 != _rect.Bottom) { int right = _rect.Right + 1; if (MapBuilder.tile_at_point(new Point(right, top2)) != null) { top2++; } else { num2++; break; } } if (num2 == 2) { continue; } tileDatas.Add(tile); } else { tileDatas.Add(tile); } } foreach (TileData tileData in tileDatas) { MapBuilder.fMap.Tiles.Remove(tileData); callback(null, null); } }
private static bool add_area(Endpoint ep) { if (MapBuilder.fRoomTiles.Count == 0) { return(false); } List <Tile> tiles = new List <Tile>(); int num = 1 + Session.Random.Next() % 5; while (tiles.Count != num) { int num1 = Session.Random.Next() % MapBuilder.fRoomTiles.Count; tiles.Add(MapBuilder.fRoomTiles[num1]); } List <Endpoint> endpoints = new List <Endpoint>() { ep }; List <Pair <Tile, TileData> > pairs = new List <Pair <Tile, TileData> >(); foreach (Tile tile in tiles) { if (endpoints.Count == 0) { break; } int num2 = Session.Random.Next() % endpoints.Count; Endpoint item = endpoints[num2]; Pair <TileData, Direction> pair = MapBuilder.add_tile(tile, item, false, false); if (pair == null) { continue; } endpoints.Remove(item); pairs.Add(new Pair <Tile, TileData>(tile, pair.First)); if (pair.Second != Direction.South) { endpoints.Add(MapBuilder.get_endpoint(tile, pair.First, Direction.North)); } if (pair.Second != Direction.West) { endpoints.Add(MapBuilder.get_endpoint(tile, pair.First, Direction.East)); } if (pair.Second != Direction.North) { endpoints.Add(MapBuilder.get_endpoint(tile, pair.First, Direction.South)); } if (pair.Second == Direction.East) { continue; } endpoints.Add(MapBuilder.get_endpoint(tile, pair.First, Direction.West)); } if (pairs.Count != 0) { MapBuilder.add_map_area(pairs); List <Tile> item1 = MapBuilder.fTiles[TileCategory.Feature]; if (item1.Count != 0) { int area = 0; foreach (Pair <Tile, TileData> pair1 in pairs) { area += pair1.First.Area; } int num3 = Session.Random.Next() % (area / 10); int num4 = 0; int num5 = 0; List <Pair <Tile, TileData> > pairs1 = new List <Pair <Tile, TileData> >(); while (num4 != num3 && num5 != 1000) { int num6 = Session.Random.Next() % item1.Count; Tile tile1 = item1[num6]; TileData tileDatum = new TileData() { TileID = tile1.ID, Rotations = Session.Random.Next() % 4 }; int num7 = (tileDatum.Rotations % 2 == 0 ? tile1.Size.Width : tile1.Size.Height); int num8 = (tileDatum.Rotations % 2 == 0 ? tile1.Size.Height : tile1.Size.Width); List <Pair <Tile, TileData> > pairs2 = new List <Pair <Tile, TileData> >(); foreach (Pair <Tile, TileData> pair2 in pairs) { int num9 = (pair2.Second.Rotations % 2 == 0 ? pair2.First.Size.Width : pair2.First.Size.Height); int num10 = (pair2.Second.Rotations % 2 == 0 ? pair2.First.Size.Height : pair2.First.Size.Width); int num11 = num9 - num7; if (num11 < 0 || num10 - num8 < 0) { continue; } pairs2.Add(pair2); } bool flag = false; if (pairs2.Count != 0) { int num12 = Session.Random.Next() % pairs2.Count; Pair <Tile, TileData> item2 = pairs2[num12]; int num13 = (item2.Second.Rotations % 2 == 0 ? item2.First.Size.Width : item2.First.Size.Height); int num14 = (item2.Second.Rotations % 2 == 0 ? item2.First.Size.Height : item2.First.Size.Width); int num15 = num13 - num7; int num16 = num14 - num8; if (num15 >= 0 && num16 >= 0) { Point location = item2.Second.Location; int x = location.X; if (num15 != 0) { x = x + Session.Random.Next() % num15; } location = item2.Second.Location; int y = location.Y; if (num16 != 0) { y = y + Session.Random.Next() % num16; } tileDatum.Location = new Point(x, y); bool flag1 = true; Rectangle _rect = MapBuilder.get_rect(tile1, tileDatum); foreach (Pair <Tile, TileData> pair3 in pairs1) { if (!MapBuilder.get_rect(pair3.First, pair3.Second).IntersectsWith(_rect)) { continue; } flag1 = false; break; } if (flag1) { MapBuilder.fMap.Tiles.Add(tileDatum); pairs1.Add(new Pair <Tile, TileData>(tile1, tileDatum)); flag = true; break; } } } if (!flag) { num5++; } else { num4++; num5 = 0; } } } int num17 = 1 + Session.Random.Next() % 3; int num18 = 0; int num19 = 0; while (num18 != num17 && endpoints.Count != 0 && num19 != 1000) { int num20 = Session.Random.Next() % endpoints.Count; Endpoint endpoint = endpoints[num20]; bool flag2 = true; switch (Session.Random.Next() % 2) { case 0: { flag2 = MapBuilder.add_doorway(endpoint); break; } case 1: { flag2 = MapBuilder.add_corridor(endpoint, true); break; } } if (!flag2) { num19++; } else { num18++; endpoints.Remove(endpoint); num19 = 0; } } } return(pairs.Count != 0); }
private static Pair <TileData, Direction> add_tile(Tile t, Endpoint ep, bool follow_direction, bool not_alongside) { TileData tileDatum = new TileData() { TileID = t.ID }; Direction direction = ep.Direction; if (!follow_direction) { List <Direction> directions = new List <Direction>(); if (ep.Direction != Direction.North) { directions.Add(Direction.South); } if (ep.Direction != Direction.East) { directions.Add(Direction.West); } if (ep.Direction != Direction.South) { directions.Add(Direction.North); } if (ep.Direction != Direction.West) { directions.Add(Direction.East); } int num = Session.Random.Next() % directions.Count; direction = directions[num]; } if (!follow_direction) { tileDatum.Rotations = Session.Random.Next() % 4; } else { int num1 = Math.Min(t.Size.Width, t.Size.Height); if (direction == Direction.North || direction == Direction.South) { if (num1 > 1) { if (t.Size.Width > t.Size.Height) { tileDatum.Rotations = 1; } } else if (t.Size.Width < t.Size.Height) { tileDatum.Rotations = 1; } } if (direction == Direction.East || direction == Direction.West) { if (num1 > 1) { if (t.Size.Height > t.Size.Width) { tileDatum.Rotations = 1; } } else if (t.Size.Height < t.Size.Width) { tileDatum.Rotations = 1; } } } int num2 = (tileDatum.Rotations % 2 == 0 ? t.Size.Width : t.Size.Height); int num3 = (tileDatum.Rotations % 2 == 0 ? t.Size.Height : t.Size.Width); switch (ep.Direction) { case Direction.North: { tileDatum.Location = new Point(ep.TopLeft.X, ep.TopLeft.Y - (num3 - 1)); break; } case Direction.East: { tileDatum.Location = ep.TopLeft; break; } case Direction.South: { tileDatum.Location = ep.TopLeft; break; } case Direction.West: { tileDatum.Location = new Point(ep.TopLeft.X - (num2 - 1), ep.TopLeft.Y); break; } } Rectangle _rect = MapBuilder.get_rect(t, tileDatum); if (not_alongside) { switch (direction) { case Direction.North: case Direction.South: { _rect = new Rectangle(_rect.X - 1, _rect.Y, _rect.Width + 2, _rect.Height); break; } case Direction.East: case Direction.West: { _rect = new Rectangle(_rect.X, _rect.Y - 1, _rect.Width, _rect.Height + 2); break; } } } if (!MapBuilder.check_rect_is_empty(_rect)) { return(null); } MapBuilder.fMap.Tiles.Add(tileDatum); return(new Pair <TileData, Direction>(tileDatum, direction)); }