Пример #1
0
        /// <summary>
        /// Initiates loading of floors.
        /// </summary>
        public void Init()
        {
            this.Entries            = new Dictionary <ushort, FloorReference>();
            this.ById               = new Dictionary <ushort, Floor>();
            this.DynamicFloorFromID = new Dictionary <string, ushort>();

            var floorGlobalsPath = ContentManager.GetPath("objectdata/globals/floors.iff");
            var floorGlobals     = new Files.Formats.IFF.IffFile(floorGlobalsPath);

            FloorGlobals = floorGlobals;

            var buildGlobalsPath = ContentManager.GetPath("objectdata/globals/build.iff");
            var buildGlobals     = new Files.Formats.IFF.IffFile(buildGlobalsPath); //todo: centralize?

            /** There is a small handful of floors in a global file for some reason **/
            ushort floorID   = 1;
            var    floorStrs = buildGlobals.Get <STR>(0x83);

            for (ushort i = 1; i < (floorStrs.Length / 3); i++)
            {
                var far    = floorGlobals.Get <SPR2>(i);
                var medium = floorGlobals.Get <SPR2>((ushort)(i + 256));
                var near   = floorGlobals.Get <SPR2>((ushort)(i + 512)); //2048 is water tile

                this.AddFloor(new Floor
                {
                    ID     = floorID,
                    Far    = far,
                    Medium = medium,
                    Near   = near
                });

                Entries.Add(floorID, new FloorReference(this)
                {
                    ID       = floorID,
                    FileName = "global",

                    Name        = floorStrs.GetString((i - 1) * 3 + 1),
                    Price       = int.Parse(floorStrs.GetString((i - 1) * 3 + 0)),
                    Description = floorStrs.GetString((i - 1) * 3 + 2)
                });

                floorID++;
            }

            var waterStrs = buildGlobals.Get <STR>(0x85);

            //add pools for catalog logic
            Entries.Add(65535, new FloorReference(this)
            {
                ID       = 65535,
                FileName = "global",

                Price       = int.Parse(waterStrs.GetString(0)),
                Name        = waterStrs.GetString(1),
                Description = waterStrs.GetString(2)
            });

            floorID = 256;

            var archives = new string[]
            {
                "housedata/floors/floors.far",
                "housedata/floors2/floors2.far",
                "housedata/floors3/floors3.far",
                "housedata/floors4/floors4.far"
            };

            for (var i = 0; i < archives.Length; i++)
            {
                var archivePath = ContentManager.GetPath(archives[i]);
                var archive     = new FAR1Archive(archivePath, true);
                var entries     = archive.GetAllEntries();

                foreach (var entry in entries)
                {
                    var iff = new Files.Formats.IFF.IffFile();
                    DynamicFloorFromID[new string(entry.Key.TakeWhile(x => x != '.').ToArray()).ToLowerInvariant()] = floorID;
                    var bytes = archive.GetEntry(entry);
                    using (var stream = new MemoryStream(bytes))
                    {
                        iff.Read(stream);
                    }


                    var catStrings = iff.Get <STR>(0);

                    Entries.Add(floorID, new FloorReference(this)
                    {
                        ID       = floorID,
                        FileName = entry.Key,

                        Name        = catStrings.GetString(0),
                        Price       = int.Parse(catStrings.GetString(1)),
                        Description = catStrings.GetString(2)
                    });

                    floorID++;
                }
                archive.Close();
            }

            NumFloors   = floorID;
            this.Floors = new FAR1Provider <Files.Formats.IFF.IffFile>(ContentManager, new IffCodec(), new Regex(".*/floors.*\\.far"));
            Floors.Init();
        }
Пример #2
0
        /// <summary>
        /// Initiates loading of walls.
        /// </summary>
        public void Init()
        {
            WallStyleToIndex = WallStyleIDs.ToDictionary(x => x, x => Array.IndexOf(WallStyleIDs, x));

            this.Entries           = new Dictionary <ushort, WallReference>();
            this.ById              = new Dictionary <ushort, Wall>();
            this.DynamicWallFromID = new Dictionary <string, ushort>();
            this.StyleById         = new Dictionary <ushort, WallStyle>();
            this.WallStyles        = new List <WallStyle>();

            var wallGlobalsPath = ContentManager.GetPath("objectdata/globals/walls.iff");

            WallGlobals = new Files.Formats.IFF.IffFile(wallGlobalsPath);

            var buildGlobalsPath = ContentManager.GetPath("objectdata/globals/build.iff");
            var buildGlobals     = new Files.Formats.IFF.IffFile(buildGlobalsPath); //todo: centralize?

            /** Get wall styles from globals file **/
            var    styleStrs = buildGlobals.Get <STR>(0x81);
            ushort wallID    = 1;

            for (ushort i = 2; i < 512; i += 2)
            {
                var far    = WallGlobals.Get <SPR>((ushort)(i));
                var medium = WallGlobals.Get <SPR>((ushort)(i + 512));
                var near   = WallGlobals.Get <SPR>((ushort)(i + 1024));

                var fard    = WallGlobals.Get <SPR>((ushort)(i + 1));
                var mediumd = WallGlobals.Get <SPR>((ushort)(i + 513));
                var neard   = WallGlobals.Get <SPR>((ushort)(i + 1025));

                if (fard == null)
                { //no walls down, just render exactly the same
                    fard    = far;
                    mediumd = medium;
                    neard   = near;
                }

                string name = null, description = null;
                int    price    = -1;
                int    buyIndex = -1;
                WallStyleToIndex.TryGetValue(wallID, out buyIndex);

                if (buyIndex != -1)
                {
                    price       = int.Parse(styleStrs.GetString(buyIndex * 3));
                    name        = styleStrs.GetString(buyIndex * 3 + 1);
                    description = styleStrs.GetString(buyIndex * 3 + 2);
                }

                this.AddWallStyle(new WallStyle
                {
                    ID              = wallID,
                    WallsUpFar      = far,
                    WallsUpMedium   = medium,
                    WallsUpNear     = near,
                    WallsDownFar    = fard,
                    WallsDownMedium = mediumd,
                    WallsDownNear   = neard,

                    Price       = price,
                    Name        = name,
                    Description = description
                });

                wallID++;
            }

            DynamicStyleID = 256; //styles loaded from objects start at 256. The objd reference is dynamically altered to reference this new id,
            //so only refresh wall cache at same time as obj cache! (do this on lot unload)

            /** Get wall patterns from globals file **/
            var wallStrs = buildGlobals.Get <STR>(0x83);

            wallID = 0;
            for (ushort i = 0; i < 256; i++)
            {
                var far    = WallGlobals.Get <SPR>((ushort)(i + 1536));
                var medium = WallGlobals.Get <SPR>((ushort)(i + 1536 + 256));
                var near   = WallGlobals.Get <SPR>((ushort)(i + 1536 + 512));

                this.AddWall(new Wall
                {
                    ID     = wallID,
                    Far    = far,
                    Medium = medium,
                    Near   = near,
                });

                if (i > 0 && i < (wallStrs.Length / 3) + 1)
                {
                    Entries.Add(wallID, new WallReference(this)
                    {
                        ID       = wallID,
                        FileName = "global",

                        Name        = wallStrs.GetString((i - 1) * 3 + 1),
                        Price       = int.Parse(wallStrs.GetString((i - 1) * 3 + 0)),
                        Description = wallStrs.GetString((i - 1) * 3 + 2)
                    });
                }

                wallID++;
            }

            Junctions = new Wall
            {
                ID     = wallID,
                Far    = WallGlobals.Get <SPR>(4096),
                Medium = WallGlobals.Get <SPR>(4097),
                Near   = WallGlobals.Get <SPR>(4098),
            };

            wallID = 256;

            var archives = new string[]
            {
                "housedata/walls/walls.far",
                "housedata/walls2/walls2.far",
                "housedata/walls3/walls3.far",
                "housedata/walls4/walls4.far"
            };

            for (var i = 0; i < archives.Length; i++)
            {
                var archivePath = ContentManager.GetPath(archives[i]);
                var archive     = new FAR1Archive(archivePath, true);
                var entries     = archive.GetAllEntries();

                foreach (var entry in entries)
                {
                    var iff = new Files.Formats.IFF.IffFile();
                    DynamicWallFromID[Path.GetFileNameWithoutExtension(entry.ToString().Replace('\\', '/')).ToLowerInvariant()] = wallID;
                    var bytes = archive.GetEntry(entry);
                    using (var stream = new MemoryStream(bytes))
                    {
                        iff.Read(stream);
                    }

                    var catStrings = iff.Get <STR>(0);

                    Entries.Add(wallID, new WallReference(this)
                    {
                        ID       = wallID,
                        FileName = entry.Key,

                        Name        = catStrings.GetString(0),
                        Price       = int.Parse(catStrings.GetString(1)),
                        Description = catStrings.GetString(2)
                    });

                    wallID++;
                }
                archive.Close();
            }

            this.Walls = new FAR1Provider <Files.Formats.IFF.IffFile>(ContentManager, new IffCodec(), new Regex(".*/walls.*\\.far"));
            Walls.Init();
            NumWalls = wallID;
        }