Beispiel #1
0
            private void UnArchiveSpecials(World world)
            {
                var thinkers = world.Thinkers;
                var sa       = world.SectorAction;

                // Read in saved thinkers.
                while (true)
                {
                    var tclass = (SpecialClass)this.reader.ReadByte();

                    switch (tclass)
                    {
                    case SpecialClass.EndSpecials:
                        // End of list.
                        return;

                    case SpecialClass.Ceiling:
                        this.PadPointer();
                        var ceiling = new CeilingMove(world);
                        this.reader.BaseStream.Position += 8;
                        ceiling.ThinkerState             = LoadGame.GetThinkerState(this.reader.ReadInt32());
                        ceiling.Type               = (CeilingMoveType)this.reader.ReadInt32();
                        ceiling.Sector             = world.Map.Sectors[this.reader.ReadInt32()];
                        ceiling.Sector.SpecialData = ceiling;
                        ceiling.BottomHeight       = new Fixed(this.reader.ReadInt32());
                        ceiling.TopHeight          = new Fixed(this.reader.ReadInt32());
                        ceiling.Speed              = new Fixed(this.reader.ReadInt32());
                        ceiling.Crush              = this.reader.ReadInt32() != 0;
                        ceiling.Direction          = this.reader.ReadInt32();
                        ceiling.Tag          = this.reader.ReadInt32();
                        ceiling.OldDirection = this.reader.ReadInt32();

                        thinkers.Add(ceiling);
                        sa.AddActiveCeiling(ceiling);

                        break;

                    case SpecialClass.Door:
                        this.PadPointer();
                        var door = new VerticalDoor(world);
                        this.reader.BaseStream.Position += 8;
                        door.ThinkerState       = LoadGame.GetThinkerState(this.reader.ReadInt32());
                        door.Type               = (VerticalDoorType)this.reader.ReadInt32();
                        door.Sector             = world.Map.Sectors[this.reader.ReadInt32()];
                        door.Sector.SpecialData = door;
                        door.TopHeight          = new Fixed(this.reader.ReadInt32());
                        door.Speed              = new Fixed(this.reader.ReadInt32());
                        door.Direction          = this.reader.ReadInt32();
                        door.TopWait            = this.reader.ReadInt32();
                        door.TopCountDown       = this.reader.ReadInt32();

                        thinkers.Add(door);

                        break;

                    case SpecialClass.Floor:
                        this.PadPointer();
                        var floor = new FloorMove(world);
                        this.reader.BaseStream.Position += 8;
                        floor.ThinkerState       = LoadGame.GetThinkerState(this.reader.ReadInt32());
                        floor.Type               = (FloorMoveType)this.reader.ReadInt32();
                        floor.Crush              = this.reader.ReadInt32() != 0;
                        floor.Sector             = world.Map.Sectors[this.reader.ReadInt32()];
                        floor.Sector.SpecialData = floor;
                        floor.Direction          = this.reader.ReadInt32();
                        floor.NewSpecial         = (SectorSpecial)this.reader.ReadInt32();
                        floor.Texture            = this.reader.ReadInt32();
                        floor.FloorDestHeight    = new Fixed(this.reader.ReadInt32());
                        floor.Speed              = new Fixed(this.reader.ReadInt32());

                        thinkers.Add(floor);

                        break;

                    case SpecialClass.Plat:
                        this.PadPointer();
                        var plat = new Platform(world);
                        this.reader.BaseStream.Position += 8;
                        plat.ThinkerState       = LoadGame.GetThinkerState(this.reader.ReadInt32());
                        plat.Sector             = world.Map.Sectors[this.reader.ReadInt32()];
                        plat.Sector.SpecialData = plat;
                        plat.Speed     = new Fixed(this.reader.ReadInt32());
                        plat.Low       = new Fixed(this.reader.ReadInt32());
                        plat.High      = new Fixed(this.reader.ReadInt32());
                        plat.Wait      = this.reader.ReadInt32();
                        plat.Count     = this.reader.ReadInt32();
                        plat.Status    = (PlatformState)this.reader.ReadInt32();
                        plat.OldStatus = (PlatformState)this.reader.ReadInt32();
                        plat.Crush     = this.reader.ReadInt32() != 0;
                        plat.Tag       = this.reader.ReadInt32();
                        plat.Type      = (PlatformType)this.reader.ReadInt32();

                        thinkers.Add(plat);
                        sa.AddActivePlatform(plat);

                        break;

                    case SpecialClass.Flash:
                        this.PadPointer();
                        var flash = new LightFlash(world);
                        this.reader.BaseStream.Position += 8;
                        flash.ThinkerState = LoadGame.GetThinkerState(this.reader.ReadInt32());
                        flash.Sector       = world.Map.Sectors[this.reader.ReadInt32()];
                        flash.Count        = this.reader.ReadInt32();
                        flash.MaxLight     = this.reader.ReadInt32();
                        flash.MinLight     = this.reader.ReadInt32();
                        flash.MaxTime      = this.reader.ReadInt32();
                        flash.MinTime      = this.reader.ReadInt32();

                        thinkers.Add(flash);

                        break;

                    case SpecialClass.Strobe:
                        this.PadPointer();
                        var strobe = new StrobeFlash(world);
                        this.reader.BaseStream.Position += 8;
                        strobe.ThinkerState              = LoadGame.GetThinkerState(this.reader.ReadInt32());
                        strobe.Sector     = world.Map.Sectors[this.reader.ReadInt32()];
                        strobe.Count      = this.reader.ReadInt32();
                        strobe.MinLight   = this.reader.ReadInt32();
                        strobe.MaxLight   = this.reader.ReadInt32();
                        strobe.DarkTime   = this.reader.ReadInt32();
                        strobe.BrightTime = this.reader.ReadInt32();

                        thinkers.Add(strobe);

                        break;

                    case SpecialClass.Glow:
                        this.PadPointer();
                        var glow = new GlowingLight(world);
                        this.reader.BaseStream.Position += 8;
                        glow.ThinkerState = LoadGame.GetThinkerState(this.reader.ReadInt32());
                        glow.Sector       = world.Map.Sectors[this.reader.ReadInt32()];
                        glow.MinLight     = this.reader.ReadInt32();
                        glow.MaxLight     = this.reader.ReadInt32();
                        glow.Direction    = this.reader.ReadInt32();

                        thinkers.Add(glow);

                        break;

                    default:
                        throw new Exception("Unknown special in savegame!");
                    }
                }
            }
Beispiel #2
0
            private void UnArchiveThinkers(World world)
            {
                var thinkers = world.Thinkers;
                var ta       = world.ThingAllocation;

                // Remove all the current thinkers.
                foreach (var thinker in thinkers)
                {
                    var mobj = thinker as Mobj;

                    if (mobj != null)
                    {
                        ta.RemoveMobj(mobj);
                    }
                }

                thinkers.Reset();

                // Read in saved thinkers.
                while (true)
                {
                    var tclass = (ThinkerClass)this.reader.ReadByte();

                    switch (tclass)
                    {
                    case ThinkerClass.End:
                        // End of list.
                        return;

                    case ThinkerClass.Mobj:
                        this.PadPointer();
                        var mobj = new Mobj(world);
                        this.reader.BaseStream.Position += 8;
                        mobj.ThinkerState = LoadGame.GetThinkerState(this.reader.ReadInt32());
                        mobj.X            = new Fixed(this.reader.ReadInt32());
                        mobj.Y            = new Fixed(this.reader.ReadInt32());
                        mobj.Z            = new Fixed(this.reader.ReadInt32());
                        this.reader.BaseStream.Position += 8;
                        mobj.Angle  = new Angle(this.reader.ReadInt32());
                        mobj.Sprite = (Sprite)this.reader.ReadInt32();
                        mobj.Frame  = this.reader.ReadInt32();
                        this.reader.BaseStream.Position += 12;
                        mobj.FloorZ   = new Fixed(this.reader.ReadInt32());
                        mobj.CeilingZ = new Fixed(this.reader.ReadInt32());
                        mobj.Radius   = new Fixed(this.reader.ReadInt32());
                        mobj.Height   = new Fixed(this.reader.ReadInt32());
                        mobj.MomX     = new Fixed(this.reader.ReadInt32());
                        mobj.MomY     = new Fixed(this.reader.ReadInt32());
                        mobj.MomZ     = new Fixed(this.reader.ReadInt32());
                        this.reader.BaseStream.Position += 4;
                        mobj.Type = (MobjType)this.reader.ReadInt32();
                        mobj.Info = DoomInfo.MobjInfos[(int)mobj.Type];
                        this.reader.BaseStream.Position += 4;
                        mobj.Tics      = this.reader.ReadInt32();
                        mobj.State     = DoomInfo.States[this.reader.ReadInt32()];
                        mobj.Flags     = (MobjFlags)this.reader.ReadInt32();
                        mobj.Health    = this.reader.ReadInt32();
                        mobj.MoveDir   = (Direction)this.reader.ReadInt32();
                        mobj.MoveCount = this.reader.ReadInt32();
                        this.reader.BaseStream.Position += 4;
                        mobj.ReactionTime = this.reader.ReadInt32();
                        mobj.Threshold    = this.reader.ReadInt32();
                        var playerNumber = this.reader.ReadInt32();

                        if (playerNumber != 0)
                        {
                            mobj.Player      = world.Options.Players[playerNumber - 1];
                            mobj.Player.Mobj = mobj;
                        }

                        mobj.LastLook = this.reader.ReadInt32();

                        mobj.SpawnPoint = new MapThing(
                            Fixed.FromInt(this.reader.ReadInt16()),
                            Fixed.FromInt(this.reader.ReadInt16()),
                            new Angle(Angle.Ang45.Data * (uint)(this.reader.ReadInt16() / 45)),
                            this.reader.ReadInt16(),
                            (ThingFlags)this.reader.ReadInt16()
                            );

                        this.reader.BaseStream.Position += 4;

                        world.ThingMovement.SetThingPosition(mobj);

                        // mobj.FloorZ = mobj.Subsector.Sector.FloorHeight;
                        // mobj.CeilingZ = mobj.Subsector.Sector.CeilingHeight;
                        thinkers.Add(mobj);

                        break;

                    default:
                        throw new Exception("Unknown thinker class in savegame!");
                    }
                }
            }