public void BuildVillage(NWField field, ExtRect area) { if (field.AreaRect.Contains(area)) { for (int y = area.Top; y <= area.Bottom; y++) { for (int x = area.Left; x <= area.Right; x++) { BaseTile ft = field.GetTile(x, y); ft.Background = field.TranslateTile(TileType.ttGrass); int fg = (int)ft.Foreground; if (fg != field.TranslateTile(TileType.ttTree)) { ft.Foreground = PlaceID.pid_Undefined; } } } for (var bid = BuildingID.bid_First; bid <= BuildingID.bid_Last; bid++) { BuildingRec bRec = StaticData.dbBuildings[(int)bid]; int cnt = RandomHelper.GetBoundedRnd((int)bRec.MinCount, (int)bRec.MaxCount); for (int j = 1; j <= cnt; j++) { Building b = new Building(fSpace, field); if (b.Build(bRec.MaxDoors, bRec.MinSize, bRec.MaxSize, area)) { b.ID = bid; field.Features.Add(b); } else { b.Dispose(); } } } BuildBattlement(field); int wpX; int wpY; BaseTile tile; do { wpX = RandomHelper.GetBoundedRnd(area.Left + 5, area.Right - 5); wpY = RandomHelper.GetBoundedRnd(area.Top + 5, area.Bottom - 5); tile = field.GetTile(wpX, wpY); } while (tile.BackBase != PlaceID.pid_Grass || tile.ForeBase != PlaceID.pid_Undefined); field.GetTile(wpX, wpY).Foreground = PlaceID.pid_Well; } }
public void BuildBattlement(NWField field) { try { int lsd = field.Width - 1; int rsd = 0; int tsd = field.Height - 1; int bsd = 0; int num = field.Features.Count; for (int i = 0; i < num; i++) { GameEntity feat = field.Features.GetItem(i); if (feat is Building) { Building b = (Building)feat; ExtRect area = b.Area; if (lsd > area.Left) { lsd = area.Left; } if (rsd < area.Right) { rsd = area.Right; } if (tsd > area.Top) { tsd = area.Top; } if (bsd < area.Bottom) { bsd = area.Bottom; } } } ExtRect r = ExtRect.Create(lsd - 2, tsd - 2, rsd + 2, bsd + 2); for (int x = r.Left; x <= r.Right; x++) { for (int y = r.Top; y <= r.Bottom; y++) { TileType wKind = MapUtils.GetWallKind(x, y, r); if (wKind != TileType.ttFloor) { field.GetTile(x, y).Foreground = field.TranslateTile(wKind); } } } for (int side = Directions.DtSouth; side <= Directions.DtEast; side++) { int x = RandomHelper.GetBoundedRnd(r.Left + 1, r.Right - 1); int y = RandomHelper.GetBoundedRnd(r.Top + 1, r.Bottom - 1); switch (side) { case Directions.DtNorth: y = r.Top; break; case Directions.DtSouth: y = r.Bottom; break; case Directions.DtWest: x = r.Left; break; case Directions.DtEast: x = r.Right; break; } field.GetTile(x, y).Foreground = field.TranslateTile(TileType.ttUndefined); x += Directions.Data[side].DX; y += Directions.Data[side].DY; field.GetTile(x, y).Foreground = field.TranslateTile(TileType.ttUndefined); Gates.Add(new ExtPoint(x, y)); } } catch (Exception ex) { Logger.Write("Village.buildBattlement(): " + ex.Message); throw ex; } }