Пример #1
0
        public static void RestoreSurroundings(VM vm, byte[][] hollowAdj)
        {
            var myArch   = vm.Context.Architecture;
            var terrain  = vm.TSOState.Terrain;
            var size     = myArch.Width;
            var lotsMode = WorldConfig.Current.SurroundingLots;

            foreach (var world in vm.Context.Blueprint.SubWorlds)
            {
                world.Dispose();
            }
            vm.Context.Blueprint.SubWorlds.Clear();

            var baseHeight = GetBaseLevel(vm, terrain, 1, 1);

            //vm.Context.Blueprint.BaseAlt = 0;// 128;
            //vm.Context.World.State.BaseHeight = 0;// (128 * 3) / 16f;

            if (lotsMode == 0)
            {
                return;
            }
            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    if (x == 1 & y == 1)
                    {
                        continue;                  //that's us...
                    }
                    var gd       = vm.Context.World.State.Device;
                    var subworld = vm.Context.World.MakeSubWorld(gd);
                    subworld.Initialize(gd);
                    var tempVM = new VM(new VMContext(subworld), new VMServerDriver(new VMTSOGlobalLinkStub()), new VMNullHeadlineProvider());
                    tempVM.Init();

                    var state = (hollowAdj == null)? null : hollowAdj[y * 3 + x];
                    if (lotsMode == 1)
                    {
                        state = null;
                    }

                    float           height = 0;
                    VMHollowMarshal hollow = null;
                    if (state != null)
                    {
                        try
                        {
                            hollow = new VMHollowMarshal();
                            using (var reader = new BinaryReader(new MemoryStream(state))) {
                                hollow.Deserialize(reader);
                            }
                            tempVM.HollowLoad(hollow);
                            RestoreTerrain(tempVM, terrain.BlendN[x, y], terrain.Roads[x, y]);
                            if (hollow.Version < 19)
                            {
                                height = RestoreHeight(tempVM, terrain, x, y);
                            }
                            else
                            {
                                height = GetBaseLevel(tempVM, terrain, x, y);
                            }
                            tempVM.Context.Blueprint.BaseAlt = (int)((baseHeight - height));
                            foreach (var obj in tempVM.Entities)
                            {
                                obj.Position = obj.Position;
                            }

                            tempVM.Tick();
                            subworld.CalculateFloorsUsed();
                        } catch (Exception)
                        {
                            hollow = null;
                        }
                    }

                    if (hollow == null)
                    {
                        var blueprint = new Blueprint(size, size);
                        tempVM.Context.Blueprint = blueprint;
                        subworld.InitBlueprint(blueprint);
                        tempVM.Context.Architecture = new VMArchitecture(size, size, blueprint, tempVM.Context);

                        tempVM.Context.Architecture.EmptyRoomMap();
                        tempVM.Context.RegeneratePortalInfo();

                        var terrainC = new TerrainComponent(new Rectangle(0, 0, size, size), blueprint);
                        terrainC.Initialize(subworld.State.Device, subworld.State);
                        blueprint.Terrain = terrainC;

                        tempVM.Context.Architecture.Terrain.LowQualityGrassState = true;
                        RestoreTerrain(tempVM, terrain.BlendN[x, y], terrain.Roads[x, y]);
                        height = RestoreHeight(tempVM, terrain, x, y);
                        tempVM.Context.Blueprint.BaseAlt = (int)((baseHeight - height));

                        PopulateBlankTerrain(tempVM);
                        tempVM.Context.Architecture.ClearDirty();
                        tempVM.Context.Architecture.RegenRoomMap();
                        tempVM.Context.RegeneratePortalInfo();
                        tempVM.Context.RefreshAllLighting();
                        tempVM.Tick();
                    }

                    subworld.State.Level = 5;

                    subworld.GlobalPosition = new Vector2((1 - y) * (size - 2), (x - 1) * (size - 2));

                    vm.Context.Blueprint.SubWorlds.Add(subworld);
                }
            }
            vm.Context.World.InitSubWorlds();
        }
Пример #2
0
        public static void RestoreSurroundings(VM vm, byte[][] hollowAdj)
        {
            var myArch   = vm.Context.Architecture;
            var terrain  = vm.TSOState.Terrain;
            var size     = myArch.Width;
            var lotsMode = WorldConfig.Current.SurroundingLots;

            foreach (var world in vm.Context.Blueprint.SubWorlds)
            {
                world.Dispose();
            }
            vm.Context.Blueprint.SubWorlds.Clear();
            if (lotsMode == 0)
            {
                return;
            }
            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    if (x == 1 & y == 1)
                    {
                        continue;                  //that's us...
                    }
                    var gd       = vm.Context.World.State.Device;
                    var subworld = new SubWorldComponent(gd);
                    subworld.Initialize(gd);
                    var tempVM = new VM(new VMContext(subworld), new VMServerDriver(new VMTSOGlobalLinkStub()), new VMNullHeadlineProvider());
                    tempVM.Init();

                    var state = (hollowAdj == null)? null : hollowAdj[y * 3 + x];
                    if (lotsMode == 1)
                    {
                        state = null;
                    }

                    VMHollowMarshal hollow = null;
                    if (state != null)
                    {
                        try
                        {
                            hollow = new VMHollowMarshal();
                            using (var reader = new BinaryReader(new MemoryStream(state))) {
                                hollow.Deserialize(reader);
                            }
                            tempVM.HollowLoad(hollow);
                            RestoreTerrain(tempVM, terrain.BlendN[x, y], terrain.Roads[x, y]);
                            tempVM.Tick();
                        } catch (Exception)
                        {
                            hollow = null;
                        }
                    }

                    if (hollow == null)
                    {
                        var blueprint = new Blueprint(size, size);
                        tempVM.Context.Blueprint = blueprint;
                        subworld.InitBlueprint(blueprint);
                        tempVM.Context.Architecture = new VMArchitecture(size, size, blueprint, tempVM.Context);

                        tempVM.Context.Architecture.RegenRoomMap();
                        tempVM.Context.RegeneratePortalInfo();

                        var terrainC = new TerrainComponent(new Rectangle(1, 1, size - 2, size - 2), blueprint);
                        terrainC.Initialize(subworld.State.Device, subworld.State);
                        blueprint.Terrain = terrainC;

                        RestoreTerrain(tempVM, terrain.BlendN[x, y], terrain.Roads[x, y]);
                        PopulateBlankTerrain(tempVM);

                        tempVM.Tick();
                    }

                    subworld.State.Level    = 5;
                    subworld.GlobalPosition = new Vector2((1 - y) * (size - 2), (x - 1) * (size - 2));

                    vm.Context.Blueprint.SubWorlds.Add(subworld);
                }
            }
        }