Ejemplo n.º 1
0
        public void Load(Wadfile.DirectoryEntry wad)
        {
            if (wad.Chunks.ContainsKey(MonsterDefinition.Tag))
            {
                LoadChunkList <MonsterDefinition>(monsterDefinitions, wad.Chunks[MonsterDefinition.Tag]);
            }
            else
            {
                throw new BadPhysicsException("Invalid physics: missing monster definitions");
            }

            if (wad.Chunks.ContainsKey(EffectDefinition.Tag))
            {
                LoadChunkList <EffectDefinition>(effectDefinitions, wad.Chunks[EffectDefinition.Tag]);
            }
            else
            {
                throw new BadPhysicsException("Invalid physics: missing effects definitions");
            }

            if (wad.Chunks.ContainsKey(ProjectileDefinition.Tag))
            {
                LoadChunkList <ProjectileDefinition>(projectileDefinitions, wad.Chunks[ProjectileDefinition.Tag]);
            }
            else
            {
                throw new BadPhysicsException("Invalid physics: missing projectile definitions");
            }

            if (wad.Chunks.ContainsKey(Weland.PhysicsConstants.Tag))
            {
                LoadChunkList <PhysicsConstants>(physicsConstants, wad.Chunks[Weland.PhysicsConstants.Tag]);
            }
            else
            {
                throw new BadPhysicsException("Invalid physics: missing physics constants");
            }

            if (wad.Chunks.ContainsKey(WeaponDefinition.Tag))
            {
                LoadChunkList <WeaponDefinition>(weaponDefinitions, wad.Chunks[WeaponDefinition.Tag]);
            }
            else
            {
                throw new BadPhysicsException("Invalid physics: missing weapon definitions");
            }
        }
Ejemplo n.º 2
0
        public Wadfile.DirectoryEntry Save()
        {
            Wadfile.DirectoryEntry wad = new Wadfile.DirectoryEntry();
            wad.Chunks = Chunks;
            wad.Chunks[MapInfo.Tag]        = SaveChunk(mapInfo);
            wad.Chunks[Point.Tag]          = SaveChunk(Endpoints);
            wad.Chunks[Line.Tag]           = SaveChunk(Lines);
            wad.Chunks[Polygon.Tag]        = SaveChunk(Polygons);
            wad.Chunks[Side.Tag]           = SaveChunk(Sides);
            wad.Chunks[MapObject.Tag]      = SaveChunk(Objects);
            wad.Chunks[Platform.StaticTag] = SaveChunk(Platforms);
            wad.Chunks[Light.Tag]          = SaveChunk(Lights);
            wad.Chunks[Annotation.Tag]     = SaveChunk(Annotations);
            wad.Chunks[Media.Tag]          = SaveChunk(Medias);
            wad.Chunks[AmbientSound.Tag]   = SaveChunk(AmbientSounds);
            wad.Chunks[RandomSound.Tag]    = SaveChunk(RandomSounds);

            {
                MemoryStream   stream = new MemoryStream();
                BinaryWriterBE writer = new BinaryWriterBE(stream);
                foreach (Placement placement in ItemPlacement)
                {
                    placement.Save(writer);
                }
                foreach (Placement placement in MonsterPlacement)
                {
                    placement.Save(writer);
                }

                wad.Chunks[Placement.Tag] = stream.ToArray();
            }


            // remove merge-type chunks
            foreach (uint tag in ChunkFilter)
            {
                wad.Chunks.Remove(tag);
            }

            return(wad);
        }
Ejemplo n.º 3
0
        public void Load(Wadfile.DirectoryEntry wad)
        {
            Chunks = wad.Chunks;

            if (wad.Chunks.ContainsKey(MapInfo.Tag))
            {
                LoadChunk(mapInfo, wad.Chunks[MapInfo.Tag]);
            }
            else
            {
                throw new Wadfile.BadMapException("Incomplete level: missing map info chunk");
            }

            if (wad.Chunks.ContainsKey(Point.Tag))
            {
                LoadChunkList <Point>(Endpoints, wad.Chunks[Point.Tag]);
            }
            else if (wad.Chunks.ContainsKey(Endpoint.Tag))
            {
                Endpoints.Clear();
                List <Endpoint> endpointList = new List <Endpoint>();
                LoadChunkList <Endpoint>(endpointList, wad.Chunks[Endpoint.Tag]);
                foreach (Endpoint e in endpointList)
                {
                    Endpoints.Add(e.Vertex);
                }
            }
            else
            {
                throw new Wadfile.BadMapException("Incomplete level: missing points chunk");
            }

            if (wad.Chunks.ContainsKey(Line.Tag))
            {
                LoadChunkList <Line>(Lines, wad.Chunks[Line.Tag]);
            }
            else
            {
                throw new Wadfile.BadMapException("Incomplete level: missing lines chunk");
            }

            if (wad.Chunks.ContainsKey(Polygon.Tag))
            {
                LoadChunkList <Polygon>(Polygons, wad.Chunks[Polygon.Tag]);
            }
            else
            {
                throw new Wadfile.BadMapException("Incomplete level: missing polygons chunk");
            }

            if (wad.Chunks.ContainsKey(Side.Tag))
            {
                LoadChunkList <Side>(Sides, wad.Chunks[Side.Tag]);
            }

            if (wad.Chunks.ContainsKey(Platform.StaticTag))
            {
                LoadChunkList <Platform>(Platforms, wad.Chunks[Platform.StaticTag]);
            }
            else if (wad.Chunks.ContainsKey(Platform.DynamicTag))
            {
                BinaryReaderBE reader = new BinaryReaderBE(new MemoryStream(wad.Chunks[Platform.DynamicTag]));
                Platforms.Clear();
                while (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    Platform platform = new Platform();
                    platform.LoadDynamic(reader);
                    Platforms.Add(platform);

                    // open up the polygon
                    if (platform.PolygonIndex >= 0 && platform.PolygonIndex < Polygons.Count)
                    {
                        Polygon polygon = Polygons[platform.PolygonIndex];
                        if (platform.ComesFromFloor)
                        {
                            polygon.FloorHeight = platform.MinimumHeight;
                        }
                        if (platform.ComesFromCeiling)
                        {
                            polygon.CeilingHeight = platform.MaximumHeight;
                        }
                    }
                }
            }

            if (wad.Chunks.ContainsKey(Light.Tag))
            {
                LoadChunkList <Light>(Lights, wad.Chunks[Light.Tag]);
            }

            if (wad.Chunks.ContainsKey(Placement.Tag))
            {
                BinaryReaderBE reader = new BinaryReaderBE(new MemoryStream(wad.Chunks[Placement.Tag]));
                ItemPlacement.Clear();
                for (int i = 0; i < Placement.Count; ++i)
                {
                    Placement placement = new Placement();
                    placement.Load(reader);
                    ItemPlacement.Add(placement);
                }

                MonsterPlacement.Clear();
                for (int i = 0; i < Placement.Count; ++i)
                {
                    Placement placement = new Placement();
                    placement.Load(reader);
                    MonsterPlacement.Add(placement);
                }
            }

            if (wad.Chunks.ContainsKey(Annotation.Tag))
            {
                LoadChunkList <Annotation>(Annotations, wad.Chunks[Annotation.Tag]);
            }

            EndpointPolygons.Clear();
            EndpointLines.Clear();
            for (int i = 0; i < Endpoints.Count; ++i)
            {
                EndpointPolygons.Add(new HashSet <Polygon>());
                EndpointLines.Add(new HashSet <Line>());
            }

            foreach (Polygon polygon in Polygons)
            {
                UpdatePolygonConcavity(polygon);
                for (int i = 0; i < polygon.VertexCount; ++i)
                {
                    Line line = Lines[polygon.LineIndexes[i]];
                    EndpointPolygons[line.EndpointIndexes[0]].Add(polygon);
                    EndpointPolygons[line.EndpointIndexes[1]].Add(polygon);
                }
            }

            foreach (Line line in Lines)
            {
                EndpointLines[line.EndpointIndexes[0]].Add(line);
                EndpointLines[line.EndpointIndexes[1]].Add(line);
            }

            for (int i = 0; i < Polygons.Count; ++i)
            {
                Polygon polygon = Polygons[i];
                if (polygon.Type == PolygonType.Platform)
                {
                    bool found = false;
                    for (int j = 0; j < Platforms.Count; ++j)
                    {
                        Platform platform = Platforms[j];
                        if (platform.PolygonIndex == i)
                        {
                            polygon.Permutation = (short)j;
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        Platform platform = new Platform();
                        platform.SetTypeWithDefaults(PlatformType.SphtDoor);
                        platform.PolygonIndex = (short)i;
                        polygon.Permutation   = (short)Platforms.Count;
                        Platforms.Add(platform);
                    }
                }
            }

            foreach (Side side in Sides)
            {
                side.PolygonIndex = -1;
                side.LineIndex    = -1;
            }

            for (short index = 0; index < Lines.Count; ++index)
            {
                Line    line = Lines[index];
                Polygon p1   = null;
                Polygon p2   = null;
                if (line.ClockwisePolygonOwner != -1)
                {
                    p1 = Polygons[line.ClockwisePolygonOwner];
                }
                if (line.CounterclockwisePolygonOwner != -1)
                {
                    p2 = Polygons[line.CounterclockwisePolygonOwner];
                }

                if (p1 != null && p2 != null)
                {
                    line.HighestAdjacentFloor  = Math.Max(p1.FloorHeight, p2.FloorHeight);
                    line.LowestAdjacentCeiling = Math.Min(p1.CeilingHeight, p2.CeilingHeight);
                }
                else if (p1 != null)
                {
                    line.HighestAdjacentFloor  = p1.FloorHeight;
                    line.LowestAdjacentCeiling = p1.CeilingHeight;
                }
                else if (p2 != null)
                {
                    line.HighestAdjacentFloor  = p2.FloorHeight;
                    line.LowestAdjacentCeiling = p2.CeilingHeight;
                }
                else
                {
                    line.HighestAdjacentFloor  = 0;
                    line.LowestAdjacentCeiling = 0;
                }

                if (line.VariableElevation)
                {
                    line.Solid = (line.HighestAdjacentFloor >= line.LowestAdjacentCeiling);
                }

                if (line.ClockwisePolygonSideIndex != -1)
                {
                    Side side = Sides[line.ClockwisePolygonSideIndex];
                    side.LineIndex    = index;
                    side.PolygonIndex = line.ClockwisePolygonOwner;
                }

                if (line.CounterclockwisePolygonSideIndex != -1)
                {
                    Side side = Sides[line.CounterclockwisePolygonSideIndex];
                    side.LineIndex    = index;
                    side.PolygonIndex = line.CounterclockwisePolygonOwner;
                }
            }

            if (wad.Chunks.ContainsKey(MapObject.Tag))
            {
                LoadChunkList <MapObject>(Objects, wad.Chunks[MapObject.Tag]);
            }
            else
            {
                throw new Wadfile.BadMapException("Incomplete level: missing map objects chunk");
            }

            if (wad.Chunks.ContainsKey(Media.Tag))
            {
                LoadChunkList <Media>(Medias, wad.Chunks[Media.Tag]);
            }

            if (wad.Chunks.ContainsKey(AmbientSound.Tag))
            {
                LoadChunkList <AmbientSound>(AmbientSounds, wad.Chunks[AmbientSound.Tag]);
            }

            if (wad.Chunks.ContainsKey(RandomSound.Tag))
            {
                LoadChunkList <RandomSound>(RandomSounds, wad.Chunks[RandomSound.Tag]);
            }
        }