Exemplo n.º 1
0
        public void AddTrap(int aX, int aY, ushort trapTileID, bool discovered)
        {
            NWTile tile = (NWTile)GetTile(aX, aY);

            tile.Foreground      = trapTileID;
            tile.Trap_Discovered = discovered;
        }
Exemplo n.º 2
0
        public bool CanSink(int x, int y)
        {
            NWTile tile = (NWTile)GetTile(x, y);
            int    bg   = tile.BackBase;

            return(bg == PlaceID.pid_Water || bg == PlaceID.pid_Quicksand);
        }
Exemplo n.º 3
0
        public void LoadFromStream(BinaryReader stream, FileVersion version)
        {
            //Logger.LogWrite("TField.avail: " + String.valueOf(stream.available()));

            try {
                for (int y = 0; y < StaticData.FieldHeight; y++)
                {
                    for (int x = 0; x < StaticData.FieldWidth; x++)
                    {
                        NWTile tile = (NWTile)GetTile(x, y);
                        tile.LoadFromStream(stream, version);
                    }
                }

                fCreatures.LoadFromStream(stream, version);
                fItems.LoadFromStream(stream, version);

                int num3 = fItems.Count;
                for (int i = 0; i < num3; i++)
                {
                    fItems.GetItem(i).Owner = this;
                }

                Features.LoadFromStream(stream, version);

                Visited = StreamUtils.ReadBoolean(stream);
            } catch (Exception ex) {
                Logger.Write("NWField.loadFromStream(): " + ex.Message);
                throw ex;
            }
        }
Exemplo n.º 4
0
        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;
                }
            }
        }
Exemplo n.º 5
0
        public bool IsTrap(int tx, int ty)
        {
            bool   result = false;
            NWTile tile   = (NWTile)GetTile(tx, ty);
            int    fg     = tile.ForeBase;

            if (fg != PlaceID.pid_Undefined)
            {
                result = ((StaticData.dbPlaces[fg].Signs.Contains(PlaceFlags.psIsTrap)));
            }
            return(result);
        }
Exemplo n.º 6
0
        public override bool IsBarrier(int x, int y)
        {
            bool   result = true;
            NWTile p      = (NWTile)GetTile(x, y);

            if (p != null)
            {
                int bg = (p.BackBase);
                int fg = (p.ForeBase);

                result = ((StaticData.dbPlaces[bg].Signs.Contains(PlaceFlags.psBarrier)) || (fg != PlaceID.pid_Undefined && (StaticData.dbPlaces[fg].Signs.Contains(PlaceFlags.psBarrier))));
            }
            return(result);
        }
Exemplo n.º 7
0
 private void ProcessVariants()
 {
     for (int y = 0; y < StaticData.FieldHeight; y++)
     {
         for (int x = 0; x < StaticData.FieldWidth; x++)
         {
             NWTile tile = (NWTile)GetTile(x, y);
             if (tile.ForeBase == PlaceID.pid_Mountain)
             {
                 tile.Foreground = GetVarTile(PlaceID.pid_Mountain);
             }
         }
     }
 }
Exemplo n.º 8
0
        public void AddGate(ushort tileID, int posX, int posY, int targetLayer, ExtPoint targetField, ExtPoint targetPos)
        {
            NWTile tile = (NWTile)GetTile(posX, posY);

            tile.Foreground = tileID;

            Gate gate = new Gate(fSpace, this);

            gate.CLSID = tileID;
            gate.SetPos(posX, posY);
            gate.TargetLayer = targetLayer;
            gate.TargetField = targetField.Clone();
            gate.TargetPos   = targetPos.Clone();
            Features.Add(gate);
        }
Exemplo n.º 9
0
        public void SpreadTiles(ushort tileID, float density)
        {
            try {
                int             tsz    = 0;
                List <ExtPoint> bounds = new List <ExtPoint>();
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        NWTile tile = (NWTile)GetTile(x, y);
                        if (tile.BackBase != tileID)
                        {
                            int cnt = GetBackTilesCount(x, y, (short)tileID);
                            if (cnt > 0)
                            {
                                bounds.Add(new ExtPoint(x, y));
                            }
                        }
                        else
                        {
                            tsz++;
                        }
                    }
                }

                int xcnt = RandomHelper.GetBoundedRnd(1, Math.Max(1, (int)Math.Round(bounds.Count * density)));
                for (int i = 1; i <= xcnt; i++)
                {
                    int      idx = RandomHelper.GetRandom(bounds.Count);
                    ExtPoint pt  = bounds[idx];
                    bounds.RemoveAt(idx);

                    ChangeTile(pt.X, pt.Y, tileID, false);
                }
                tsz += xcnt;

                // ALERT: change genBackTiles for compatibility with changeTile()
                float min = AreaRect.Square * 0.1f;
                if ((float)tsz < min)
                {
                    UniverseBuilder.GenBackTiles(this, (int)(min - tsz), tileID);
                }

                Normalize();
            } catch (Exception ex) {
                Logger.Write("NWField.spreadTiles(): " + ex.Message);
            }
        }
Exemplo n.º 10
0
        public override void Assign(BaseTile source)
        {
            base.Assign(source);
            NWTile srcTile = (NWTile)source;

            FogID    = srcTile.FogID;
            FogExtID = srcTile.FogExtID;
            FogAge   = srcTile.FogAge;

            Trap_Discovered = srcTile.Trap_Discovered;
            Lake_LiquidID   = srcTile.Lake_LiquidID;

            // runtime
            //this.CreaturePtr;
            //this.ScentAge;
            //this.ScentTrail;
        }
Exemplo n.º 11
0
        public void AddSeveralTraps(ushort[] kinds, int f)
        {
            int cnt;

            if (f > 0)
            {
                cnt = f;
            }
            else
            {
                cnt = RandomHelper.GetBoundedRnd(3, -4 * f);
            }

            int fx = fCoords.X;
            int fy = fCoords.Y;

            for (int i = 1; i <= cnt; i++)
            {
                while (true)
                {
                    int    y    = RandomHelper.GetBoundedRnd(0, Height - 1);
                    int    x    = RandomHelper.GetBoundedRnd(0, Width - 1);
                    NWTile tile = (NWTile)GetTile(x, y);

                    bool ready = (FindBuilding(x, y) == null && tile.ForeBase == PlaceID.pid_Undefined);
                    if (ready)
                    {
                        ushort trapKind;
                        do
                        {
                            trapKind = RandomHelper.GetRandomItem(kinds);
                            bool crt = (trapKind == PlaceID.pid_CrushRoofTrap);

                            int lx = (fx * StaticData.FieldWidth) + x;
                            int ly = (fy * StaticData.FieldHeight) + y;

                            bool hasDunRoom = crt && (FindDungeonRoom(x, y) != null || Layer.FindDungeonRoom(lx, ly) != null);
                            ready = (!crt || (crt & hasDunRoom));
                        } while (!ready);

                        AddTrap(x, y, trapKind, false);
                        break;
                    }
                }
            }
        }
Exemplo n.º 12
0
        public override CreatureEntity FindCreature(int aX, int aY)
        {
            NWTile tile = (NWTile)GetTile(aX, aY);

            CreatureEntity result;

            if (tile != null)
            {
                result = tile.CreaturePtr;
            }
            else
            {
                result = null;
            }

            return(result);
        }
Exemplo n.º 13
0
 public void Close(bool needFG)
 {
     for (int y = 0; y < StaticData.FieldHeight; y++)
     {
         for (int x = 0; x < StaticData.FieldWidth; x++)
         {
             NWTile tile = (NWTile)GetTile(x, y);
             if (needFG && tile.ForeBase != PlaceID.pid_Undefined)
             {
                 // dummy
             }
             else
             {
                 tile.ExcludeState(BaseTile.TS_VISITED);
             }
         }
     }
 }
Exemplo n.º 14
0
 private void DoTurn_prepareScentTrails()
 {
     for (int y = 0; y < StaticData.FieldHeight; y++)
     {
         for (int x = 0; x < StaticData.FieldWidth; x++)
         {
             NWTile tile = (NWTile)GetTile(x, y);
             if (tile.ScentAge > 0)
             {
                 tile.ScentAge = (byte)(tile.ScentAge - 1);
             }
             if (tile.ScentAge == 0)
             {
                 tile.ScentTrail = null;
             }
         }
     }
 }
Exemplo n.º 15
0
        public string GetPlaceName(int x, int y)
        {
            string result = "";

            NWTile tile = (NWTile)base.GetTile(x, y);

            if (tile != null && !tile.EmptyStates)
            {
                int bg = tile.BackBase;
                int fg = tile.ForeBase;

                if (bg != PlaceID.pid_Undefined)
                {
                    result = BaseLocale.GetStr(StaticData.dbPlaces[bg].NameRS);
                    if (bg == PlaceID.pid_Liquid)
                    {
                        result = result + " (" + GlobalVars.nwrDB.GetEntry(tile.Lake_LiquidID).Name + ")";
                    }
                }

                if (fg != PlaceID.pid_Undefined)
                {
                    if (IsTrap(x, y) && tile.Trap_Discovered)
                    {
                        result = result + ", " + BaseLocale.GetStr(StaticData.dbPlaces[fg].NameRS);
                    }
                    else
                    {
                        Gate gate = FindGate(x, y);
                        if (gate != null)
                        {
                            result = result + ", " + gate.Name;
                        }
                        else
                        {
                            result = result + ", " + BaseLocale.GetStr(StaticData.dbPlaces[fg].NameRS);
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 16
0
        public override bool IsBlockLOS(int x, int y)
        {
            bool result;

            NWTile tile = (NWTile)GetTile(x, y);

            if (tile == null)
            {
                result = true;
            }
            else
            {
                int bg = tile.BackBase;
                int fg = tile.ForeBase;

                result = ((StaticData.dbPlaces[bg].Signs.Contains(PlaceFlags.psBlockLOS)) || (fg != PlaceID.pid_Undefined && (StaticData.dbPlaces[fg].Signs.Contains(PlaceFlags.psBlockLOS))));
            }

            return(result);
        }
Exemplo n.º 17
0
        public void SaveToStream(BinaryWriter stream, FileVersion version)
        {
            try {
                for (int y = 0; y < StaticData.FieldHeight; y++)
                {
                    for (int x = 0; x < StaticData.FieldWidth; x++)
                    {
                        NWTile tile = (NWTile)GetTile(x, y);
                        tile.SaveToStream(stream, version);
                    }
                }

                fCreatures.SaveToStream(stream, version);
                fItems.SaveToStream(stream, version);
                Features.SaveToStream(stream, version);

                StreamUtils.WriteBoolean(stream, Visited);
            } catch (Exception ex) {
                Logger.Write("NWField.saveToStream(): " + ex.Message);
                throw ex;
            }
        }
Exemplo n.º 18
0
        public void Research(bool onlyForeground, int tileStates)
        {
            for (int y = 0; y < StaticData.FieldHeight; y++)
            {
                for (int x = 0; x < StaticData.FieldWidth; x++)
                {
                    NWTile tile = (NWTile)GetTile(x, y);

                    if (onlyForeground)
                    {
                        if (tile.ForeBase != PlaceID.pid_Undefined)
                        {
                            tile.AddStates(tileStates);
                        }
                    }
                    else
                    {
                        tile.AddStates(tileStates);
                    }
                }
            }
        }
Exemplo n.º 19
0
        private void DoTurn_prepareFogs()
        {
            for (int y = 0; y < StaticData.FieldHeight; y++)
            {
                for (int x = 0; x < StaticData.FieldWidth; x++)
                {
                    NWTile tile = (NWTile)GetTile(x, y);
                    if (tile.FogID == PlaceID.pid_Fog)
                    {
                        if (tile.FogAge > 0)
                        {
                            tile.FogAge = (sbyte)(tile.FogAge - 1);
                        }
                        if (tile.FogAge == 0)
                        {
                            tile.FogID = (ushort)PlaceID.pid_Undefined;
                        }
                    }
                }
            }

            NormalizeFog();
        }
Exemplo n.º 20
0
        public void LoadFromEntry(FieldEntry entry)
        {
            for (int yy = 0; yy < StaticData.FieldHeight; yy++)
            {
                for (int xx = 0; xx < StaticData.FieldWidth; xx++)
                {
                    NWTile tile = (NWTile)GetTile(xx, yy);

                    FieldEntry.FDTile fdTile = entry.Data.Tiles[yy, xx];

                    tile.Background    = fdTile.BackGround;
                    tile.BackgroundExt = (ushort)PlaceID.pid_Undefined;

                    tile.Foreground    = fdTile.ForeGround;
                    tile.ForegroundExt = (ushort)PlaceID.pid_Undefined;

                    tile.CreaturePtr = null;

                    tile.FogID    = (ushort)PlaceID.pid_Undefined;
                    tile.FogExtID = (ushort)PlaceID.pid_Undefined;
                    tile.FogAge   = 0;
                }
            }
        }
Exemplo n.º 21
0
        public void InitField()
        {
            try {
                NWLayer layer = Layer;
                if (fEntry != null && fEntry.Source == FieldSource.fsTemplate)
                {
                    LoadFromEntry(fEntry);
                    ProcessVariants();
                }
                else
                {
                    if (LandID == GlobalVars.Land_Armory || LandID == GlobalVars.Land_GrynrHalls)
                    {
                        UniverseBuilder.Build_Dungeon(this, AreaRect);
                    }
                    else
                    {
                        if (layer.EntryID != GlobalVars.Layer_Svartalfheim1 && layer.EntryID != GlobalVars.Layer_Svartalfheim2 && layer.EntryID != GlobalVars.Layer_Svartalfheim3)
                        {
                            Prepare(PlaceID.pid_Grass);
                        }
                    }
                }

                int defTS = 0;
                if (LandID == GlobalVars.Land_Bifrost || LandID == GlobalVars.Land_Crossroads)
                {
                    defTS = BaseTile.TS_VISITED;
                }

                for (int y = 0; y < StaticData.FieldHeight; y++)
                {
                    for (int x = 0; x < StaticData.FieldWidth; x++)
                    {
                        NWTile tile = (NWTile)GetTile(x, y);
                        tile.BackgroundExt = 0;
                        tile.ForegroundExt = 0;
                        tile.ScentAge      = 0;
                        tile.ScentTrail    = null;
                        tile.AddStates(defTS);
                    }
                }

                if (fLandEntry.Flags.Contains(LandFlags.lsHasForest))
                {
                    UniverseBuilder.Build_Forest(this);
                }
                if (fLandEntry.Flags.Contains(LandFlags.lsHasMountain))
                {
                    UniverseBuilder.Gen_RarelyMountains(this);
                }
                if (fLandEntry.Flags.Contains(LandFlags.lsHasItems))
                {
                    UniverseBuilder.Gen_Items(this, -1);
                }
                if (fLandEntry.Flags.Contains(LandFlags.lsIsCave))
                {
                    UniverseBuilder.Gen_CaveObjects(this);
                }

                if (LandID == GlobalVars.Land_Ocean)
                {
                    Prepare(PlaceID.pid_Water);
                }

                if (LandID == GlobalVars.Land_Vanaheim)
                {
                    UniverseBuilder.Build_Vanaheim(this);
                }
                if (LandID == GlobalVars.Land_Alfheim)
                {
                    UniverseBuilder.Build_Alfheim(this);
                }
                if (LandID == GlobalVars.Land_Wasteland)
                {
                    UniverseBuilder.Build_Wasteland(this);
                }
                if (LandID == GlobalVars.Land_Crossroads)
                {
                    UniverseBuilder.Build_Crossroads(this);
                }
                if (LandID == GlobalVars.Land_Village)
                {
                    UniverseBuilder.Build_Village(this);
                }
                if (LandID == GlobalVars.Land_MimerRealm)
                {
                    UniverseBuilder.Build_MimerRealm(this);
                }
                if (LandID == GlobalVars.Land_MimerWell)
                {
                    UniverseBuilder.Build_MimerWell(this);
                }
                if (LandID == GlobalVars.Land_GrynrHalls)
                {
                    UniverseBuilder.Build_GrynrHalls(this);
                }
                if (LandID == GlobalVars.Land_Bazaar)
                {
                    UniverseBuilder.Build_Bazaar(this);
                }
                if (LandID == GlobalVars.Land_Temple)
                {
                    UniverseBuilder.Build_VidurTemple(this);
                }
                if (LandID == GlobalVars.Land_GodsFortress)
                {
                    UniverseBuilder.Build_GodsFortress(this);
                }
                if (LandID == GlobalVars.Land_Valhalla)
                {
                    UniverseBuilder.Build_Valhalla(this);
                }
                if (LandID == GlobalVars.Land_Muspelheim)
                {
                    UniverseBuilder.Build_Muspelheim(this);
                }

                if (LandID == GlobalVars.Land_Ocean)
                {
                    UniverseBuilder.Build_Ocean(this);
                }
                else
                {
                    UniverseBuilder.Gen_Creatures(this, -1);
                    UniverseBuilder.Gen_Traps(this, -2);
                }
            } catch (Exception ex) {
                Logger.Write("NWField.InitField(" + DebugSign + "): " + ex.Message);
            }
        }
Exemplo n.º 22
0
        private int DoTurn_eruptionWastelandVulcan()
        {
            int state = WS_ERUPTION;

            try {
                bool vulcan_ex = false;

                List <ExtPoint> lava_bounds = new List <ExtPoint>();

                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        NWTile tile = (NWTile)GetTile(x, y);
                        int    cnt  = GetBackTilesCount(x, y, (short)PlaceID.pid_Lava);

                        if (tile.ForeBase == PlaceID.pid_Vulcan)
                        {
                            vulcan_ex = true;
                        }

                        if (tile.BackBase == PlaceID.pid_Grass && cnt > 0)
                        {
                            lava_bounds.Add(new ExtPoint(x, y));
                        }
                    }
                }

                if (lava_bounds.Count == 0)
                {
                    state = WS_FINISH;
                }
                if (!vulcan_ex)
                {
                    state = WS_VULCAN_NOT_EXISTS;
                }

                if (state != WS_ERUPTION)
                {
                    return(state);
                }

                if (lava_bounds.Count > 5)
                {
                    GlobalVars.nwrWin.ShowText(GlobalVars.nwrWin, BaseLocale.GetStr(RS.rs_GroundBeginsToShake));
                }

                int xcnt = RandomHelper.GetBoundedRnd(1, Math.Max(1, (int)Math.Round(lava_bounds.Count * 0.25f)));
                for (int i = 1; i <= xcnt; i++)
                {
                    int      idx = RandomHelper.GetRandom(lava_bounds.Count);
                    ExtPoint pt  = lava_bounds[idx];
                    lava_bounds.RemoveAt(idx);

                    ChangeTile(pt.X, pt.Y, PlaceID.pid_Lava, false);
                }

                Normalize();
            } catch (Exception ex) {
                Logger.Write("NWField.doTurn_eruptionWastelandVulcan(): " + ex.Message);
            }

            return(state);
        }