Ejemplo n.º 1
0
        private static void ReadThings(MapSet map, BinaryReader reader)
        {
            int count = reader.ReadInt32();

            // Go for all collections
            map.SetCapacity(0, 0, 0, 0, map.Things.Count + count);
            for (int i = 0; i < count; i++)
            {
                int[] args     = new int[Linedef.NUM_ARGS];
                int   tag      = reader.ReadInt32();
                float x        = reader.ReadSingle();
                float y        = reader.ReadSingle();
                float height   = reader.ReadSingle();
                int   angledeg = reader.ReadInt32();
                int   pitch    = reader.ReadInt32();           //mxd
                int   roll     = reader.ReadInt32();           //mxd
                float scaleX   = reader.ReadSingle();          //mxd
                float scaleY   = reader.ReadSingle();          //mxd
                int   type     = reader.ReadInt32();
                int   special  = reader.ReadInt32();
                for (int a = 0; a < Linedef.NUM_ARGS; a++)
                {
                    args[a] = reader.ReadInt32();
                }

                //flags
                Dictionary <string, bool> stringflags = new Dictionary <string, bool>(StringComparer.Ordinal);
                int numFlags = reader.ReadInt32();
                for (int f = 0; f < numFlags; f++)
                {
                    stringflags.Add(ReadString(reader), reader.ReadBoolean());
                }

                //add missing flags
                foreach (KeyValuePair <string, string> flag in General.Map.Config.ThingFlags)
                {
                    if (stringflags.ContainsKey(flag.Key))
                    {
                        continue;
                    }
                    stringflags.Add(flag.Key, false);
                }

                // Create new item
                Dictionary <string, UniValue> fields = ReadCustomFields(reader);
                Thing t = map.CreateThing();
                if (t != null)
                {
                    t.Update(type, x, y, height, angledeg, pitch, roll, scaleX, scaleY, stringflags, tag, special, args);

                    // Add custom fields
                    t.Fields.BeforeFieldsChange();
                    foreach (KeyValuePair <string, UniValue> group in fields)
                    {
                        t.Fields.Add(group.Key, group.Value);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        // This reads the THINGS from WAD file
        private void ReadThings(MapSet map, int firstindex)
        {
            int[] args = new int[Thing.NUM_ARGS];

            // Get the lump from wad file
            Lump lump = wad.FindLump("THINGS", firstindex);

            if (lump == null)
            {
                throw new Exception("Could not find required lump THINGS!");
            }

            // Prepare to read the items
            MemoryStream mem    = new MemoryStream(lump.Stream.ReadAllBytes());
            int          num    = (int)lump.Stream.Length / 20;
            BinaryReader reader = new BinaryReader(mem);

            // Read items from the lump
            map.SetCapacity(0, 0, 0, 0, map.Things.Count + num);
            for (int i = 0; i < num; i++)
            {
                // Read properties from stream
                int tag    = reader.ReadUInt16();
                int x      = reader.ReadInt16();
                int y      = reader.ReadInt16();
                int z      = reader.ReadInt16();
                int angle  = reader.ReadInt16();
                int type   = reader.ReadUInt16();
                int flags  = reader.ReadUInt16();
                int action = reader.ReadByte();
                args[0] = reader.ReadByte();
                args[1] = reader.ReadByte();
                args[2] = reader.ReadByte();
                args[3] = reader.ReadByte();
                args[4] = reader.ReadByte();

                // Make string flags
                Dictionary <string, bool> stringflags = new Dictionary <string, bool>(StringComparer.Ordinal);
                foreach (KeyValuePair <string, string> f in manager.Config.ThingFlags)
                {
                    int fnum;
                    if (int.TryParse(f.Key, out fnum))
                    {
                        stringflags[f.Key] = ((flags & fnum) == fnum);
                    }
                }

                // Create new item
                Thing t = map.CreateThing();
                t.Update(type, x, y, z, angle, 0, 0, 1.0f, 1.0f, stringflags, tag, action, args);
            }

            // Done
            mem.Dispose();
        }
Ejemplo n.º 3
0
        // This reads the THINGS from WAD file
        private void ReadThings(MapSet map, int firstindex)
        {
            MemoryStream mem;
            BinaryReader reader;
            int          num, i, x, y, type, flags;
            Dictionary <string, bool> stringflags;
            float angle;
            Thing t;

            // Get the lump from wad file
            Lump lump = wad.FindLump("THINGS", firstindex);

            if (lump == null)
            {
                throw new Exception("Could not find required lump THINGS!");
            }

            // Prepare to read the items
            mem    = new MemoryStream(lump.Stream.ReadAllBytes());
            num    = (int)lump.Stream.Length / 10;
            reader = new BinaryReader(mem);

            // Read items from the lump
            map.SetCapacity(0, 0, 0, 0, map.Things.Count + num);
            for (i = 0; i < num; i++)
            {
                // Read properties from stream
                x     = reader.ReadInt16();
                y     = reader.ReadInt16();
                angle = Angle2D.DoomToReal(reader.ReadInt16());
                type  = reader.ReadUInt16();
                flags = reader.ReadUInt16();

                // Make string flags
                stringflags = new Dictionary <string, bool>();
                foreach (KeyValuePair <string, string> f in manager.Config.ThingFlags)
                {
                    int fnum;
                    if (int.TryParse(f.Key, out fnum))
                    {
                        stringflags[f.Key] = ((flags & fnum) == fnum);
                    }
                }

                // Create new item
                t = map.CreateThing();
                t.Update(type, x, y, 0, angle, stringflags, 0, 0, new int[Thing.NUM_ARGS]);
            }

            // Done
            mem.Dispose();
        }
Ejemplo n.º 4
0
        // This reads the things
        private void ReadThings(MapSet map, UniversalParser textmap)
        {
            // Get list of entries
            List <UniversalCollection> collections = GetNamedCollections(textmap.Root, "thing");

            // Go for all collections
            map.SetCapacity(0, 0, 0, 0, map.Things.Count + collections.Count);
            for (int i = 0; i < collections.Count; i++)
            {
                // Read fields
                UniversalCollection c = collections[i];
                int[] args            = new int[Linedef.NUM_ARGS];
                string where = "thing " + i;
                float x        = GetCollectionEntry <float>(c, "x", true, 0.0f, where);
                float y        = GetCollectionEntry <float>(c, "y", true, 0.0f, where);
                float height   = GetCollectionEntry <float>(c, "height", false, 0.0f, where);
                int   tag      = GetCollectionEntry <int>(c, "id", false, 0, where);
                int   angledeg = GetCollectionEntry <int>(c, "angle", false, 0, where);
                int   type     = GetCollectionEntry <int>(c, "type", true, 0, where);
                int   special  = GetCollectionEntry <int>(c, "special", false, 0, where);
                args[0] = GetCollectionEntry <int>(c, "arg0", false, 0, where);
                args[1] = GetCollectionEntry <int>(c, "arg1", false, 0, where);
                args[2] = GetCollectionEntry <int>(c, "arg2", false, 0, where);
                args[3] = GetCollectionEntry <int>(c, "arg3", false, 0, where);
                args[4] = GetCollectionEntry <int>(c, "arg4", false, 0, where);

                // Flags
                Dictionary <string, bool> stringflags = new Dictionary <string, bool>();
                foreach (KeyValuePair <string, string> flag in General.Map.Config.ThingFlags)
                {
                    stringflags[flag.Key] = GetCollectionEntry <bool>(c, flag.Key, false, false, where);
                }
                foreach (FlagTranslation ft in General.Map.Config.ThingFlagsTranslation)
                {
                    foreach (string field in ft.Fields)
                    {
                        stringflags[field] = GetCollectionEntry <bool>(c, field, false, false, where);
                    }
                }

                // Create new item
                Thing t = map.CreateThing();
                if (t != null)
                {
                    t.Update(type, x, y, height, angledeg, stringflags, tag, special, args);

                    // Custom fields
                    ReadCustomFields(c, t, "thing");
                }
            }
        }
Ejemplo n.º 5
0
        private static void ReadSprites(MapSet map, BinaryReader reader)
        {
            int count = reader.ReadInt32();

            // Go for all sprites
            map.SetCapacity(0, 0, 0, 0, map.Things.Count + count);
            for (int i = 0; i < count; i++)
            {
                BuildSprite bs = new BuildSprite();

                // Read Build properties
                bs.X = reader.ReadInt32();
                bs.Y = reader.ReadInt32();
                bs.Z = reader.ReadInt32();

                bs.TileIndex    = reader.ReadInt32();
                bs.Shade        = reader.ReadInt32();
                bs.PaletteIndex = reader.ReadInt32();
                bs.ClipDistance = reader.ReadInt32();
                bs.RepeatX      = reader.ReadInt32();
                bs.RepeatY      = reader.ReadInt32();
                bs.OffsetX      = reader.ReadInt32();
                bs.OffsetY      = reader.ReadInt32();
                bs.Angle        = reader.ReadInt32();

                bs.Owner = reader.ReadInt32();
                bs.VelX  = reader.ReadInt32();
                bs.VelY  = reader.ReadInt32();
                bs.VelZ  = reader.ReadInt32();

                bs.HiTag = reader.ReadInt32();
                bs.LoTag = reader.ReadInt32();
                bs.Extra = reader.ReadInt32();

                // Read flags
                bs.Flags = ReadFlags(reader, General.Map.Config.SpriteFlags.Keys);

                // Create new item
                Thing t = map.CreateThing();
                if (t != null)
                {
                    t.Update(bs);
                }
            }
        }
Ejemplo n.º 6
0
        private static void CreateSprites(MapSet map, List <BuildSprite> buildsprites, List <BuildSector> sectors)
        {
            // Create sprites
            map.SetCapacity(0, 0, 0, 0, map.Things.Count + buildsprites.Count);

            for (int i = 0; i < buildsprites.Count; i++)
            {
                var bs = buildsprites[i];

                // Link sector
                if (bs.SectorIndex < sectors.Count)
                {
                    bs.Sector = sectors[bs.SectorIndex].Sector;
                }
                else
                {
                    General.ErrorLogger.Add(ErrorType.Warning, "Sprite " + i + " references non-existing sector " + bs.SectorIndex);
                }

                // Create new item
                Thing t = map.CreateThing();
                t.Update(bs);
            }
        }
        private bool CreateGeometry(List <Vector3D> verts, List <Face> faces, int maxZ)
        {
            if (verts.Count < 3 || faces.Count == 0)
            {
                MessageBox.Show("Cannot import the model: failed to find any suitable polygons!",
                                "Terrain Importer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            MapSet map = General.Map.Map;

            // Capacity checks
            int totalverts   = map.Vertices.Count + verts.Count;
            int totalsides   = map.Sidedefs.Count + faces.Count * 6;
            int totallines   = map.Linedefs.Count + faces.Count * 3;
            int totalsectors = map.Sectors.Count + faces.Count;
            int totalthings  = 0;

            if (form.UseVertexHeights && !General.Map.UDMF)
            {
                // We'll use vertex height things in non-udmf maps, if such things are defined in Game Configuration
                totalthings = map.Things.Count + verts.Count;
            }

            if (totalverts > General.Map.FormatInterface.MaxVertices)
            {
                MessageBox.Show("Cannot import the model: resulting vertex count (" + totalverts
                                + ") is larger than map format's maximum (" + General.Map.FormatInterface.MaxVertices + ")!",
                                "Terrain Importer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (totalsides > General.Map.FormatInterface.MaxSidedefs)
            {
                MessageBox.Show("Cannot import the model: resulting sidedefs count (" + totalsides
                                + ") is larger than map format's maximum (" + General.Map.FormatInterface.MaxSidedefs + ")!",
                                "Terrain Importer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (totallines > General.Map.FormatInterface.MaxLinedefs)
            {
                MessageBox.Show("Cannot import the model: resulting sidedefs count (" + totallines
                                + ") is larger than map format's maximum (" + General.Map.FormatInterface.MaxLinedefs + ")!",
                                "Terrain Importer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (totalsectors > General.Map.FormatInterface.MaxSectors)
            {
                MessageBox.Show("Cannot import the model: resulting sidedefs count (" + totalsectors
                                + ") is larger than map format's maximum (" + General.Map.FormatInterface.MaxSectors + ")!",
                                "Terrain Importer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (totalthings > General.Map.FormatInterface.MaxThings)
            {
                MessageBox.Show("Cannot import the model: resulting things count (" + totalthings
                                + ") is larger than map format's maximum (" + General.Map.FormatInterface.MaxThings + ")!",
                                "Terrain Importer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            //make undo
            General.Map.UndoRedo.CreateUndo("Import Terrain");

            //prepare mapset
            List <Linedef> newlines = new List <Linedef>();

            map.BeginAddRemove();
            map.SetCapacity(totalverts, totallines, totalsides, totalsectors, totalthings);

            //terrain has many faces... let's create them
            Dictionary <Vector3D, Vertex> newverts = new Dictionary <Vector3D, Vertex>();

            foreach (Face face in faces)
            {
                // Create sector
                Sector s = map.CreateSector();
                s.Selected    = true;
                s.FloorHeight = (int)Math.Round((face.V1.z + face.V2.z + face.V3.z) / 3);
                s.CeilHeight  = maxZ;
                s.Brightness  = General.Settings.DefaultBrightness;                //todo: allow user to change this
                s.SetCeilTexture(General.Map.Config.SkyFlatName);
                s.SetFloorTexture(General.Map.Options.DefaultFloorTexture);        //todo: allow user to change this

                // And linedefs
                Linedef newline = GetLine(newverts, s, face.V1, face.V2);
                if (newline != null)
                {
                    newlines.Add(newline);
                }

                newline = GetLine(newverts, s, face.V2, face.V3);
                if (newline != null)
                {
                    newlines.Add(newline);
                }

                newline = GetLine(newverts, s, face.V3, face.V1);
                if (newline != null)
                {
                    newlines.Add(newline);
                }

                s.UpdateCache();
            }

            // Add slope things
            if (form.UseVertexHeights && !General.Map.UDMF)
            {
                foreach (Vector3D pos in newverts.Keys)
                {
                    Thing t = map.CreateThing();
                    General.Settings.ApplyDefaultThingSettings(t);
                    t.Type = VERTEX_HEIGHT_THING_TYPE;
                    t.Move(pos);
                    t.Selected = true;
                }
            }

            //update new lines
            foreach (Linedef l in newlines)
            {
                l.ApplySidedFlags();
            }

            map.EndAddRemove();
            return(true);
        }