public void LoadFromStream(BinaryReader stream, FileVersion version) { try { for (int y = 0; y < fH; y++) { for (int x = 0; x < fW; x++) { NWField fld = fFields[y, x]; fld.Clear(); fld.LoadFromStream(stream, version); GlobalVars.nwrWin.ProgressStep(); } } for (int y = 0; y < fH; y++) { for (int x = 0; x < fW; x++) { NWField fld = fFields[y, x]; fld.Normalize(); fld.NormalizeFog(); } } } catch (Exception ex) { Logger.Write("NWLayer.loadFromStream(): " + ex.Message); throw ex; } }
public NWLayer(NWGameSpace space, int layerID) : base(0, 0) { fSpace = space; fEntry = (LayerEntry)GlobalVars.nwrDB.GetEntry(layerID); fW = fEntry.W; fH = fEntry.H; Resize(fW * StaticData.FieldWidth, fH * StaticData.FieldHeight); EntryID = layerID; fFields = new NWField[fH, fW]; for (int y = 0; y < fH; y++) { for (int x = 0; x < fW; x++) { fFields[y, x] = new NWField(space, this, new ExtPoint(x, y)); } } fEffects = new EffectsList(this, true); }
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 LocatedEntity FindItem(int aX, int aY) { int fx = aX / StaticData.FieldWidth; int fy = aY / StaticData.FieldHeight; int x = aX % StaticData.FieldWidth; int y = aY % StaticData.FieldHeight; NWField f = GetField(fx, fy); return(f.FindItem(x, y)); }
public bool Gen_Creature(int aID, int aX, int aY, bool aFlock) { int fx = aX / StaticData.FieldWidth; int fy = aY / StaticData.FieldHeight; int x = aX % StaticData.FieldWidth; int y = aY % StaticData.FieldHeight; NWField f = GetField(fx, fy); return(UniverseBuilder.Gen_Creature(f, aID, x, y, aFlock)); }
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 Village(GameSpace space, object owner) : base(space, owner) { NWField fld = (NWField)owner; ExtRect v = fld.AreaRect; v.Left += 18; v.Right -= 18; v.Top += 7; v.Bottom -= 5; Area = v; Gates = new List <ExtPoint>(); }
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); }
/// <summary> /// Performs the passage of time for the entire layer. /// Necessary in cases, such as for example, the battle on the field Vigrid if the player is in Valhalla. /// </summary> public void DoTurn() { try { for (int y = 0; y < fH; y++) { for (int x = 0; x < fW; x++) { NWField fld = fFields[y, x]; fld.DoTurn(); } } fEffects.Execute(); } catch (Exception ex) { Logger.Write("NWLayer.doTurn(): " + ex.Message); } }
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; } }
// FIXME: total check & tests public void Prepare() { NWField fld = (NWField)Owner; ExtRect r = Area; r.Inflate(-1, -1); int id = (int)ID; var blRec = StaticData.dbBuildings[id]; if (ID >= BuildingID.bid_MerchantShop && ID <= BuildingID.bid_WoodsmanShop) { NWCreature merchant = (NWCreature)Holder; if (merchant == null) { Item coins = new Item(fSpace, null); coins.CLSID = GlobalVars.iid_Coin; coins.Count = (ushort)RandomHelper.GetBoundedRnd(15000, 25000); int x = RandomHelper.GetBoundedRnd(r.Left, r.Right); int y = RandomHelper.GetBoundedRnd(r.Top, r.Bottom); merchant = fld.AddCreature(x, y, GlobalVars.nwrDB.FindEntryBySign(StaticData.dbSysCreatures[(int)blRec.Owner].Sign).GUID); merchant.IsTrader = true; merchant.AddItem(coins); Holder = merchant; } else { Item coins = (Item)merchant.Items.FindByCLSID(GlobalVars.iid_Coin); if (coins != null) { coins.Count = (ushort)RandomHelper.GetBoundedRnd(15000, 25000); } } ProbabilityTable <int> data = blRec.Wares; if (((data != null) ? data.Size() : 0) > 0) { for (int y = r.Top; y <= r.Bottom; y++) { for (int x = r.Left; x <= r.Right; x++) { Item item = (Item)fld.FindItem(x, y); if (item == null) { item = new Item(fSpace, this); item.CLSID = data.GetRandomItem(); item.SetPos(x, y); item.Owner = merchant; item.GenCount(); fld.Items.Add(item, false); } else { if (AuxUtils.Chance(20)) { item.CLSID = data.GetRandomItem(); item.GenCount(); } } } } } } }