コード例 #1
0
ファイル: GameState.cs プロジェクト: jakobharder/burntime
 public GameState(GameStateInfo info)
 {
     this.info = info;
 }
コード例 #2
0
        public bool Open(Stream file)
        {
            if (file == null)
            {
                return(false);
            }

            const int LocationCount  = 37;
            const int PlayerCount    = 4;
            const int CharacterCount = 309;
            const int ItemCount      = 1199;
            const int FirstTraderId  = 21;

            BinaryReader reader = new BinaryReader(file);

            BURN = reader.ReadBytes(4);

            CharIdOffset = reader.ReadUInt16(); // player-char link
            Unknown2     = reader.ReadBytes(2); // unknown 2 bytes

            // read global game info
            GameStateInfo gsi = new GameStateInfo();

            gsi.ActiveID2               = reader.ReadUInt16();
            gsi.ActivePlayer            = reader.ReadUInt16();
            gsi.Day                     = reader.ReadUInt16();
            gsi.FirstCityMerchantCityId = reader.ReadUInt16();
            gsi.Unknown                 = reader.ReadBytes(4);              // unknown 4 bytes
            gsi.Difficulty              = reader.ReadUInt16();
            state = new GameState(gsi);

            // read location info
            int traderindex = FirstTraderId;

            locations = new Location[LocationCount];
            for (int i = 0; i < LocationCount; i++)
            {
                LocationInfo info = new LocationInfo();
                info.TitleId       = reader.ReadUInt16();
                info.Owner         = reader.ReadUInt16();
                info.Unknown1      = reader.ReadBytes(8);                    // unknown 8 bytes
                info.Water         = reader.ReadUInt16();
                info.WaterCapacity = reader.ReadUInt16();
                info.WaterSource   = reader.ReadUInt16();

                info.EntryPointX = reader.ReadUInt16();
                info.EntryPointY = reader.ReadUInt16();

                info.CityFlag    = reader.ReadUInt16();
                info.Production1 = reader.ReadByte();
                info.Production2 = reader.ReadByte();
                info.Production3 = reader.ReadByte();
                info.Production4 = reader.ReadByte();
                info.Producing   = reader.ReadUInt16();
                info.Unknown2    = reader.ReadBytes(2);                      // unknown 2 bytes

                info.Neighbour1 = reader.ReadByte();
                info.Neighbour2 = reader.ReadByte();
                info.Neighbour3 = reader.ReadByte();
                info.Neighbour4 = reader.ReadByte();

                info.WayTime1 = reader.ReadByte();
                info.WayTime2 = reader.ReadByte();
                info.WayTime3 = reader.ReadByte();
                info.WayTime4 = reader.ReadByte();

                info.Way1 = reader.ReadByte();
                info.Way2 = reader.ReadByte();
                info.Way3 = reader.ReadByte();
                info.Way4 = reader.ReadByte();

                info.Unknown3      = reader.ReadBytes(1);                    // unknown 1 byte
                info.Danger        = reader.ReadByte();
                info.DangerAmount  = reader.ReadUInt16();
                info.LifeReduction = reader.ReadUInt16();

                locations[i] = new Location(info);

                if (locations[i].IsCity)
                {
                    locations[i].traderId = traderindex++;
                }
            }

            Unknown3 = reader.ReadBytes(2);                                 // unknown 2 bytes

            // read player info
            player = new Player[PlayerCount];
            for (int i = 0; i < PlayerCount; i++)
            {
                PlayerInfo info = new PlayerInfo();

                info.FlagId       = reader.ReadUInt16();
                info.TravelDays   = reader.ReadUInt16();
                info.TravelCityId = reader.ReadUInt16();
                info.Unknown1     = reader.ReadBytes(3);                    // unknown 3 bytes
                info.Color        = reader.ReadByte();

                info.CharacterId = reader.ReadUInt16();
                info.Unknown2    = reader.ReadBytes(2);                     // unknown 2 bytes
                info.Controller  = reader.ReadUInt16();
                info.Unknown3    = reader.ReadBytes(6);                     // unknown 6 bytes
                info.IconId      = reader.ReadUInt16();

                info.Name = reader.ReadBytes(14);

                info.Unknown4   = reader.ReadBytes(4);                      // unknown 4 bytes
                info.DayTime    = reader.ReadUInt16();
                info.PlayerId   = reader.ReadUInt16();
                info.LocationId = reader.ReadByte();
                info.Unknown5   = reader.ReadBytes(11);                     // unknown 11 bytes
                info.FromCityId = reader.ReadByte();
                info.Unknown6   = reader.ReadBytes(3);                      // unknown 3 bytes

                player[i] = new Player(info);

                player[i].name = "";
                for (int j = 0; j < 14; j++)
                {
                    player[i].name += (char)info.Name[j];
                }
                if (player[i].name.IndexOf("}") > 0)
                {
                    player[i].name = player[i].name.Substring(0, player[i].name.IndexOf("}"));
                }

                if (player[i].name.StartsWith("\0"))
                {
                    player[i].name = "";
                }
            }

            Unknown4 = reader.ReadBytes(0x190);                             // unknown 400 bytes

            // read character info
            characters = new Character[CharacterCount];
            for (int i = 0; i < CharacterCount; i++)
            {
                CharacterInfo info = new CharacterInfo();

                info.LocationId = reader.ReadUInt16();
                info.Water      = reader.ReadByte();
                info.FaceId     = reader.ReadByte();
                info.Unknown1   = reader.ReadBytes(1);                      // unknown 1 byte
                info.Food       = reader.ReadByte();
                info.NameId     = reader.ReadUInt16();
                info.CharType   = reader.ReadByte();
                info.Unknown2   = reader.ReadBytes(1);          // unknown 1 byte    // hire > 40
                info.EmployerId = reader.ReadUInt16();          // hire > 49
                info.MoveX      = reader.ReadUInt16();
                info.MoveY      = reader.ReadUInt16();
                info.MoveCharId = reader.ReadUInt16();
                info.Unknown3   = reader.ReadBytes(18);                     // unknown 18 bytes
                info.HireItemId = reader.ReadUInt16();
                info.TextId     = reader.ReadByte();
                info.Unknown4   = reader.ReadBytes(1);                      // unknown 1 byte
                info.SpriteId   = reader.ReadByte();
                info.Unknown5   = reader.ReadBytes(3);                      // unknown 3 bytes
                info.Experience = reader.ReadByte();
                info.Health     = reader.ReadByte();

                characters[i] = new Character(info);

                characters[i].ID  = ((ushort)(i * 46 + 0x33b0));
                characters[i].ID2 = ((ushort)(i * 62 + 0x3128));

                if (characters[i].LocationId == -1 && i >= 4)
                {
                    player[characters[i].EmployerId].Group.Add(i);
                }
            }

            for (int i = 0; i < 4; i++)
            {
                player[i].character = characters[i];
            }

            Unknown5 = reader.ReadBytes(0xE);                               // unknown 14 bytes

            // read item info
            items = new Item[ItemCount];
            for (int i = 0; i < ItemCount; i++)
            {
                ItemInfo info = new ItemInfo();

                info.SpriteId   = reader.ReadByte();
                info.Value      = reader.ReadByte(); // Water, ...
                info.TitleId    = reader.ReadUInt16();
                info.Owner      = reader.ReadUInt16();
                info.Damage     = reader.ReadUInt16();
                info.XOrRoom    = reader.ReadUInt16(); // room index / map X position
                info.YOrNothing = reader.ReadUInt16(); // unused / map Y position

                items[i] = new Item(info);

                if (items[i].OwnerType == ItemOwnerType.Character)
                {
                    characters[items[i].OwnerId].Items.Add(i);
                }
            }

            return(true);
        }