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 SwitchDoors(DoorState ds) { NWField f = (NWField)Owner; int num = Doors.Count; for (int i = 0; i < num; i++) { Door door = Doors[i]; if (door.State != ds) { door.State = ds; switch (ds) { case DoorState.Closed: Space.DoEvent(EventID.event_DoorOpen, door, null, null); break; case DoorState.Opened: Space.DoEvent(EventID.event_DoorClose, door, null, null); break; } f.GetTile(door.X, door.Y).Foreground = dbDoorsState[door.Dir - 1, (int)door.State]; } } }
public static void DrawWalls(NWField field, ExtRect r) { for (int x = r.Left; x <= r.Right; x++) { for (int y = r.Top; y <= r.Bottom; y++) { NWTile tile = (NWTile)field.GetTile(x, y); ushort bpk = NWField.GetBuildPlaceKind(x, y, r, RuinsMode); if (!RuinsMode) { tile.Background = PlaceID.pid_Floor; } else { if (bpk == PlaceID.pid_Undefined) { tile.Background = NWField.GetVarTile(PlaceID.pid_RnFloor); } } tile.Foreground = bpk; } } }
public void SwitchDoors(int ds) { NWField f = (NWField)Owner; int num = DoorsCount; for (int i = 0; i < num; i++) { Door door = GetDoor(i); if (door.State != ds) { door.State = ds; switch (ds) { case Door.STATE_CLOSED: Space.DoEvent(EventID.event_DoorOpen, door, null, null); break; case Door.STATE_OPENED: Space.DoEvent(EventID.event_DoorClose, door, null, null); break; } f.GetTile(door.X, door.Y).Foreground = dbDoorsState[door.Dir - 1, door.State]; } } }
public override BaseTile GetTile(int x, int y) { BaseTile result = base.GetTile(x, y); if (result == null) { int fx = fCoords.X; int fy = fCoords.Y; int px = x; int py = y; if (x < 0 || x >= StaticData.FieldWidth) { px = Math.Abs(Math.Abs(x) - StaticData.FieldWidth); } if (y < 0 || y >= StaticData.FieldHeight) { py = Math.Abs(Math.Abs(y) - StaticData.FieldHeight); } if (x < 0) { fx--; } if (x >= StaticData.FieldWidth) { fx++; } if (y < 0) { fy--; } if (y >= StaticData.FieldHeight) { fy++; } NWLayer layer = Layer; if (layer != null) { NWField fld = layer.GetField(fx, fy); if (fld != null) { result = fld.GetTile(px, py); } } } return(result); }
public override BaseTile GetTile(int x, int y) { BaseTile result = null; if (IsValid(x, y)) { int fx = x / StaticData.FieldWidth; int fy = y / StaticData.FieldHeight; int tx = x % StaticData.FieldWidth; int ty = y % StaticData.FieldHeight; NWField fld = GetField(fx, fy); result = fld.GetTile(tx, ty); } return(result); }
public void Flush() { try { NWField fld = (NWField)Owner; if (fld.LandID != GlobalVars.Land_Bazaar) { ExtRect rt = Area; DrawWalls(fld, rt); if (!RuinsMode) { int num3 = Doors.Count; for (int i = 0; i < num3; i++) { Door door = Doors[i]; fld.GetTile(door.X, door.Y).Foreground = dbDoorsState[door.Dir - 1, (int)door.State]; } } } } catch (Exception ex) { Logger.Write("Building.flush(): " + ex.Message); } }
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; } }