コード例 #1
0
        private static Dictionary <int, BuildSector> ReadSectors(MapSet map, BinaryReader reader)
        {
            int count = reader.ReadInt32();

            // Create lookup table
            var link = new Dictionary <int, BuildSector>(count);

            // Go for all collections
            map.SetCapacity(0, 0, 0, map.Sectors.Count + count, 0);

            for (int i = 0; i < count; i++)
            {
                BuildSector bs = new BuildSector();

                // Read Build properteis
                bs.FirstWallIndex = reader.ReadInt32();
                bs.CeilingHeight  = reader.ReadInt32();
                bs.FloorHeight    = reader.ReadInt32();

                bs.CeilingTileIndex    = reader.ReadInt32();
                bs.CeilingSlope        = reader.ReadInt32();
                bs.CeilingShade        = reader.ReadInt32();
                bs.CeilingPaletteIndex = reader.ReadInt32();
                bs.CeilingOffsetX      = reader.ReadInt32();
                bs.CeilingOffsetY      = reader.ReadInt32();

                bs.FloorTileIndex    = reader.ReadInt32();
                bs.FloorSlope        = reader.ReadInt32();
                bs.FloorShade        = reader.ReadInt32();
                bs.FloorPaletteIndex = reader.ReadInt32();
                bs.FloorOffsetX      = reader.ReadInt32();
                bs.FloorOffsetY      = reader.ReadInt32();

                bs.Visibility = reader.ReadInt32();

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

                // Flags
                bs.CeilingFlags = ReadFlags(reader, General.Map.Config.SectorFlags.Keys);
                bs.FloorFlags   = ReadFlags(reader, General.Map.Config.SectorFlags.Keys);

                // Create new item
                Sector s = map.CreateSector();
                if (s != null)
                {
                    // Set properties
                    s.Update(bs);
                    bs.Sector = s;

                    // Add it to the lookup table
                    link.Add(i, bs);
                }
            }

            // Return lookup table
            return(link);
        }
コード例 #2
0
        // This reads the sectors
        private Dictionary <int, Sector> ReadSectors(MapSet map, UniversalParser textmap)
        {
            Dictionary <int, Sector> link;

            // Get list of entries
            List <UniversalCollection> collections = GetNamedCollections(textmap.Root, "sector");

            // Create lookup table
            link = new Dictionary <int, Sector>(collections.Count);

            // Go for all collections
            map.SetCapacity(0, 0, 0, map.Sectors.Count + collections.Count, 0);
            for (int i = 0; i < collections.Count; i++)
            {
                // Read fields
                UniversalCollection c = collections[i];
                string where = "sector " + i;
                int[]  colors  = new int[Sector.NUM_COLORS];
                int    hfloor  = GetCollectionEntry <int>(c, "heightfloor", false, 0, where);
                int    hceil   = GetCollectionEntry <int>(c, "heightceiling", false, 0, where);
                string tfloor  = GetCollectionEntry <string>(c, "texturefloor", true, "-", where);
                string tceil   = GetCollectionEntry <string>(c, "textureceiling", true, "-", where);
                int    bright  = GetCollectionEntry <int>(c, "lightlevel", false, 160, where);
                int    special = GetCollectionEntry <int>(c, "special", false, 0, where);
                int    tag     = GetCollectionEntry <int>(c, "id", false, 0, where);

                // villsa 9/14/11 (builder64)
                colors[0] = GetCollectionEntry <int>(c, "color1", false, 0, where);
                colors[1] = GetCollectionEntry <int>(c, "color2", false, 0, where);
                colors[2] = GetCollectionEntry <int>(c, "color3", false, 0, where);
                colors[3] = GetCollectionEntry <int>(c, "color4", false, 0, where);
                colors[4] = GetCollectionEntry <int>(c, "color5", false, 0, where);

                // villsa 9/13/11 - Flags
                Dictionary <string, bool> stringflags = new Dictionary <string, bool>();
                foreach (KeyValuePair <string, string> flag in General.Map.Config.SectorFlags)
                {
                    stringflags[flag.Key] = GetCollectionEntry <bool>(c, flag.Key, false, false, where);
                }

                // Create new item
                Sector s = map.CreateSector();
                if (s != null)
                {
                    s.Update(stringflags, hfloor, hceil, tfloor, tceil, special, tag, colors);

                    // Custom fields
                    ReadCustomFields(c, s, "sector");

                    // Add it to the lookup table
                    link.Add(i, s);
                }
            }

            // Return lookup table
            return(link);
        }
コード例 #3
0
        // This reads the SECTORS from WAD file
        // Returns a lookup table with indices
        private Dictionary <int, Sector> ReadSectors(MapSet map, int firstindex)
        {
            MemoryStream             mem;
            Dictionary <int, Sector> link;
            BinaryReader             reader;
            int    num, i, hfloor, hceil, bright, special, tag;
            string tfloor, tceil;
            Sector s;

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

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

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

            // Create lookup table
            link = new Dictionary <int, Sector>(num);

            // Read items from the lump
            map.SetCapacity(0, 0, 0, map.Sectors.Count + num, 0);
            for (i = 0; i < num; i++)
            {
                // Read properties from stream
                hfloor  = reader.ReadInt16();
                hceil   = reader.ReadInt16();
                tfloor  = Lump.MakeNormalName(reader.ReadBytes(8), WAD.ENCODING);
                tceil   = Lump.MakeNormalName(reader.ReadBytes(8), WAD.ENCODING);
                bright  = reader.ReadInt16();
                special = reader.ReadUInt16();
                tag     = reader.ReadUInt16();

                // Create new item
                s = map.CreateSector();
                s.Update(hfloor, hceil, tfloor, tceil, special, tag, bright);

                // Add it to the lookup table
                link.Add(i, s);
            }

            // Done
            mem.Dispose();

            // Return lookup table
            return(link);
        }
コード例 #4
0
ファイル: DukeMapSetIO.cs プロジェクト: Kizoky/Duke-Builder
        private static void CreateSectors(MapSet map, List <BuildSector> buildsectors)
        {
            // Create sectors
            map.SetCapacity(0, 0, 0, map.Sectors.Count + buildsectors.Count, 0);
            foreach (var bs in buildsectors)
            {
                // Create new item
                Sector s = map.CreateSector();
                s.Update(bs);

                // Add it to the lookup table
                bs.Sector = s;
            }
        }
コード例 #5
0
        // This reads the sectors
        private Dictionary <int, Sector> ReadSectors(MapSet map, UniversalParser textmap)
        {
            Dictionary <int, Sector> link;

            // Get list of entries
            List <UniversalCollection> collections = GetNamedCollections(textmap.Root, "sector");

            // Create lookup table
            link = new Dictionary <int, Sector>(collections.Count);

            // Go for all collections
            map.SetCapacity(0, 0, 0, map.Sectors.Count + collections.Count, 0);
            for (int i = 0; i < collections.Count; i++)
            {
                // Read fields
                UniversalCollection c = collections[i];
                string where = "sector " + i;
                int    hfloor  = GetCollectionEntry <int>(c, "heightfloor", false, 0, where);
                int    hceil   = GetCollectionEntry <int>(c, "heightceiling", false, 0, where);
                string tfloor  = GetCollectionEntry <string>(c, "texturefloor", true, "-", where);
                string tceil   = GetCollectionEntry <string>(c, "textureceiling", true, "-", where);
                int    bright  = GetCollectionEntry <int>(c, "lightlevel", false, 160, where);
                int    special = GetCollectionEntry <int>(c, "special", false, 0, where);
                int    tag     = GetCollectionEntry <int>(c, "id", false, 0, where);

                // Create new item
                Sector s = map.CreateSector();
                if (s != null)
                {
                    s.Update(hfloor, hceil, tfloor, tceil, special, tag, bright);

                    // Custom fields
                    ReadCustomFields(c, s, "sector");

                    // Add it to the lookup table
                    link.Add(i, s);
                }
            }

            // Return lookup table
            return(link);
        }
コード例 #6
0
        private static Dictionary <int, Sector> ReadSectors(MapSet map, BinaryReader reader)
        {
            int count = reader.ReadInt32();

            // Create lookup table
            Dictionary <int, Sector> link = new Dictionary <int, Sector>(count);

            // Go for all collections
            map.SetCapacity(0, 0, 0, map.Sectors.Count + count, 0);

            for (int i = 0; i < count; i++)
            {
                int effect = reader.ReadInt32();
                int hfloor = reader.ReadInt32();
                int hceil  = reader.ReadInt32();
                int bright = reader.ReadInt32();

                //mxd. Tags
                int        numtags = reader.ReadInt32();          //mxd
                List <int> tags    = new List <int>(numtags);     //mxd
                for (int a = 0; a < numtags; a++)
                {
                    tags.Add(reader.ReadInt32());                                              //mxd
                }
                string tfloor = ReadString(reader);
                string tceil  = ReadString(reader);

                //mxd. Slopes
                float    foffset = reader.ReadSingle();
                Vector3D fslope  = new Vector3D(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                float    coffset = reader.ReadSingle();
                Vector3D cslope  = new Vector3D(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

                //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.SectorFlags)
                {
                    if (stringflags.ContainsKey(flag.Key))
                    {
                        continue;
                    }
                    stringflags.Add(flag.Key, false);
                }

                // Create new item
                Dictionary <string, UniValue> fields = ReadCustomFields(reader);
                Sector s = map.CreateSector();
                if (s != null)
                {
                    s.Update(hfloor, hceil, tfloor, tceil, effect, stringflags, tags, bright, foffset, fslope, coffset, cslope);

                    // Add custom fields
                    s.Fields.BeforeFieldsChange();
                    foreach (KeyValuePair <string, UniValue> group in fields)
                    {
                        s.Fields.Add(group.Key, group.Value);
                    }

                    // Add it to the lookup table
                    link.Add(i, s);
                }
            }

            // Return lookup table
            return(link);
        }
コード例 #7
0
        // This reads the sectors
        private Dictionary <int, Sector> ReadSectors(MapSet map, UniversalParser textmap)
        {
            // Get list of entries
            List <UniversalCollection> collections = GetNamedCollections(textmap.Root, "sector");

            // Create lookup table
            Dictionary <int, Sector> link = new Dictionary <int, Sector>(collections.Count);

            // Go for all collections
            map.SetCapacity(0, 0, 0, map.Sectors.Count + collections.Count, 0);
            char[] splitter = new[] { ' ' };             //mxd
            for (int i = 0; i < collections.Count; i++)
            {
                // Read fields
                UniversalCollection c = collections[i];
                string where = "sector " + i;
                int    hfloor  = GetCollectionEntry(c, "heightfloor", false, 0, where);
                int    hceil   = GetCollectionEntry(c, "heightceiling", false, 0, where);
                string tfloor  = GetCollectionEntry(c, "texturefloor", true, "-", where);
                string tceil   = GetCollectionEntry(c, "textureceiling", true, "-", where);
                int    bright  = GetCollectionEntry(c, "lightlevel", false, 160, where);
                int    special = GetCollectionEntry(c, "special", false, 0, where);
                int    tag     = GetCollectionEntry(c, "id", false, 0, where);

                //mxd. MoreIDs
                List <int> tags = new List <int> {
                    tag
                };
                string moreids = GetCollectionEntry(c, "moreids", false, string.Empty, where);
                if (!string.IsNullOrEmpty(moreids))
                {
                    string[] moreidscol = moreids.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string sid in moreidscol)
                    {
                        int id;
                        if (int.TryParse(sid.Trim(), out id) && id != 0 && !tags.Contains(id))
                        {
                            tags.Add(id);
                        }
                    }
                }
                if (tag == 0 && tags.Count > 1)
                {
                    tags.RemoveAt(0);
                }

                //mxd. Read slopes
                float fslopex = GetCollectionEntry(c, "floorplane_a", false, 0.0f, where);
                float fslopey = GetCollectionEntry(c, "floorplane_b", false, 0.0f, where);
                float fslopez = GetCollectionEntry(c, "floorplane_c", false, 0.0f, where);
                float foffset = GetCollectionEntry(c, "floorplane_d", false, float.NaN, where);

                float cslopex = GetCollectionEntry(c, "ceilingplane_a", false, 0.0f, where);
                float cslopey = GetCollectionEntry(c, "ceilingplane_b", false, 0.0f, where);
                float cslopez = GetCollectionEntry(c, "ceilingplane_c", false, 0.0f, where);
                float coffset = GetCollectionEntry(c, "ceilingplane_d", false, float.NaN, where);

                //mxd. Read flags
                Dictionary <string, bool> stringflags = new Dictionary <string, bool>(StringComparer.Ordinal);
                foreach (KeyValuePair <string, string> flag in General.Map.Config.SectorFlags)
                {
                    stringflags[flag.Key] = GetCollectionEntry(c, flag.Key, false, false, where);
                }
                foreach (KeyValuePair <string, string> flag in General.Map.Config.CeilingPortalFlags)
                {
                    stringflags[flag.Key] = GetCollectionEntry(c, flag.Key, false, false, where);
                }
                foreach (KeyValuePair <string, string> flag in General.Map.Config.FloorPortalFlags)
                {
                    stringflags[flag.Key] = GetCollectionEntry(c, flag.Key, false, false, where);
                }

                // Create new item
                Sector s = map.CreateSector();
                if (s != null)
                {
                    s.Update(hfloor, hceil, tfloor, tceil, special, stringflags, tags, bright, foffset, new Vector3D(fslopex, fslopey, fslopez).GetNormal(), coffset, new Vector3D(cslopex, cslopey, cslopez).GetNormal());

                    // Custom fields
                    ReadCustomFields(c, s, "sector");

                    // Add it to the lookup table
                    link.Add(i, s);
                }
            }

            // Return lookup table
            return(link);
        }
コード例 #8
0
        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);
        }