Exemplo n.º 1
0
        public void InitializeLot()
        {
            CleanupLastWorld();

            if (FSOEnvironment.Enable3D)
            {
                var rc = new LotView.RC.WorldRC(GameFacade.GraphicsDevice);
                rc.SetSurroundingWorld(CityRenderer);
                World = rc;
            }
            else
            {
                World = new World(GameFacade.GraphicsDevice);
            }

            WorldLoaded   = false;
            World.Opacity = 0;
            GameFacade.Scenes.Add(World);
            Driver = new VMClientDriver(ClientStateChange);
            Driver.OnClientCommand += VMSendCommand;
            Driver.OnShutdown      += VMShutdown;

            vm = new VM(new VMContext(World), Driver, new UIHeadlineRendererProvider())
            {
                FSOVDoAsyncLoad = true
            };
            vm.ListenBHAVChanges();
            vm.Init();

            LotControl = new UILotControl(vm, World);
            AddAt(1, LotControl);

            var time    = DateTime.UtcNow;
            var tsoTime = TSOTime.FromUTC(time);

            vm.Context.Clock.Hours   = tsoTime.Item1;
            vm.Context.Clock.Minutes = tsoTime.Item2;
            if (m_ZoomLevel > 3)
            {
                World.Visible      = false;
                LotControl.Visible = false;
            }

            ZoomLevel = Math.Max(ZoomLevel, 4);

            if (IDEHook.IDE != null)
            {
                IDEHook.IDE.StartIDE(vm);
            }

            vm.OnFullRefresh      += VMRefreshed;
            vm.OnChatEvent        += Vm_OnChatEvent;
            vm.OnEODMessage       += LotControl.EODs.OnEODMessage;
            vm.OnRequestLotSwitch += VMLotSwitch;
            vm.OnGenericVMEvent   += Vm_OnGenericVMEvent;
        }
Exemplo n.º 2
0
        public void InitializeLot()
        {
            CleanupLastWorld();

            if (FSOEnvironment.Enable3D)
            {
                World = new FSO.LotView.RC.WorldRC(GameFacade.GraphicsDevice);
            }
            else
            {
                World = new FSO.LotView.World(GameFacade.GraphicsDevice);
            }

            World.Opacity = 1;
            GameFacade.Scenes.Add(World);

            var globalLink = new VMTSOGlobalLinkStub();

            Driver = new VMServerDriver(globalLink);

            vm = new VM(new VMContext(World), Driver, new UIHeadlineRendererProvider());
            vm.ListenBHAVChanges();
            vm.Init();

            LotControl = new UILotControl(vm, World);
            this.AddAt(0, LotControl);
            Frontend = new UISimitoneFrontend(this);
            this.Add(Frontend);

            var time    = DateTime.UtcNow;
            var tsoTime = TSOTime.FromUTC(time);

            vm.Context.Clock.Hours   = tsoTime.Item1;
            vm.Context.Clock.Minutes = tsoTime.Item2;
            if (m_ZoomLevel > 3)
            {
                World.Visible      = false;
                LotControl.Visible = false;
            }

            ZoomLevel = Math.Max(ZoomLevel, 4);

            if (IDEHook.IDE != null)
            {
                IDEHook.IDE.StartIDE(vm);
            }

            vm.OnFullRefresh += VMRefreshed;
            //vm.OnEODMessage += LotControl.EODs.OnEODMessage;
            vm.OnRequestLotSwitch += VMLotSwitch;
            vm.OnGenericVMEvent   += Vm_OnGenericVMEvent;
        }
Exemplo n.º 3
0
        public void ResetVM()
        {
            LOG.Info("Resetting VM for lot with dbid = " + Context.DbId);
            VMGlobalLink              = Kernel.Get <LotServerGlobalLink>();
            VMDriver                  = new VMServerDriver(VMGlobalLink);
            VMDriver.OnTickBroadcast += TickBroadcast;
            VMDriver.OnDirectMessage += DirectMessage;
            VMDriver.OnDropClient    += DropClient;

            Lot = new VM(new VMContext(null), VMDriver, new VMNullHeadlineProvider());
            Lot.Init();

            bool isNew   = false;
            bool isMoved = (LotPersist.move_flags > 0);

            LoadAdj();
            if (!JobLot && LotPersist.ring_backup_num > -1 && AttemptLoadRing())
            {
                LOG.Info("Successfully loaded and cleaned fsov for dbid = " + Context.DbId);
            }
            else
            {
                isNew = true;
                BlueprintReset();
            }

            Lot.TSOState.Terrain          = Terrain;
            Lot.TSOState.Name             = LotPersist.name;
            Lot.TSOState.OwnerID          = LotPersist.owner_id;
            Lot.TSOState.Roommates        = new HashSet <uint>();
            Lot.TSOState.BuildRoommates   = new HashSet <uint>();
            Lot.TSOState.PropertyCategory = (byte)LotPersist.category;
            foreach (var roomie in LotRoommates)
            {
                if (roomie.is_pending > 0)
                {
                    continue;
                }
                Lot.TSOState.Roommates.Add(roomie.avatar_id);
                if (roomie.permissions_level > 0)
                {
                    Lot.TSOState.BuildRoommates.Add(roomie.avatar_id);
                }
                if (roomie.permissions_level > 1)
                {
                    Lot.TSOState.OwnerID = roomie.avatar_id;
                }
            }

            var time    = DateTime.UtcNow;
            var tsoTime = TSOTime.FromUTC(time);

            Lot.Context.UpdateTSOBuildableArea();

            Lot.MyUID = uint.MaxValue - 1;
            if ((LotPersist.move_flags & 2) > 0)
            {
                isNew = true;
            }
            ReturnInvalidObjects();
            if (!JobLot)
            {
                ReturnOOWObjects();
            }

            if (isMoved || isNew)
            {
                VMLotTerrainRestoreTools.RestoreTerrain(Lot);
            }
            if (isNew)
            {
                VMLotTerrainRestoreTools.PopulateBlankTerrain(Lot);
            }

            Lot.Context.Clock.Hours   = tsoTime.Item1;
            Lot.Context.Clock.Minutes = tsoTime.Item2;

            Lot.Context.UpdateTSOBuildableArea();

            var entClone = new List <VMEntity>(Lot.Entities);

            foreach (var ent in entClone)
            {
                if (ent is VMGameObject)
                {
                    ((VMGameObject)ent).Disabled &= ~VMGameObjectDisableFlags.TransactionIncomplete;
                    ((VMGameObject)ent).DisableIfTSOCategoryWrong(Lot.Context);
                    if (ent.GetFlag(VMEntityFlags.Occupied))
                    {
                        ent.ResetData();
                        ent.Init(Lot.Context); //objects should not be occupied when we join the lot...
                    }
                    {
                        ent.ExecuteEntryPoint(2, Lot.Context, true);
                    }
                }
            }
            LotActive.Set();
            ActiveYet = true;
        }
Exemplo n.º 4
0
        public void InitializeLot(string lotName, bool external)
        {
            if (lotName == "")
            {
                return;
            }
            var recording = lotName.ToLowerInvariant().EndsWith(".fsor");

            CleanupLastWorld();

            Content.Content.Get().Upgrades.LoadJSONTuning();

            if (FSOEnvironment.Enable3D)
            {
                var rc = new LotView.RC.WorldRC(GameFacade.GraphicsDevice);
                World = rc;
            }
            else
            {
                World = new World(GameFacade.GraphicsDevice);
            }
            World.Opacity = 1;
            GameFacade.Scenes.Add(World);

            var settings = GlobalSettings.Default;
            var myState  = new VMNetAvatarPersistState()
            {
                Name         = settings.LastUser,
                DefaultSuits = new VMAvatarDefaultSuits(settings.DebugGender),
                BodyOutfit   = settings.DebugBody,
                HeadOutfit   = settings.DebugHead,
                PersistID    = (uint)(new Random()).Next(),
                SkinTone     = (byte)settings.DebugSkin,
                Gender       = (short)(settings.DebugGender ? 0 : 1),
                Permissions  = SimAntics.Model.TSOPlatform.VMTSOAvatarPermissions.Admin,
                //CustomGUID = 0x396CD3D1,
                Budget = 1000000,
            };

            if (recording)
            {
                var stream = new FileStream(lotName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                var rd     = new VMFSORDriver(stream);
                Driver = rd;
            }
            else if (external)
            {
                var cd = new VMClientDriver(ClientStateChange);
                SandCli             = new FSOSandboxClient();
                cd.OnClientCommand += (msg) => { SandCli.Write(new VMNetMessage(VMNetMessageType.Command, msg)); };
                cd.OnShutdown      += (reason) => SandCli.Disconnect();
                SandCli.OnMessage  += cd.ServerMessage;
                SandCli.Connect(lotName);
                Driver = cd;

                var dat = new MemoryStream();
                var str = new BinaryWriter(dat);
                myState.SerializeInto(str);
                var ava = new VMNetMessage(VMNetMessageType.AvatarData, dat.ToArray());
                dat.Close();
                SandCli.OnConnectComplete += () =>
                {
                    SandCli.Write(ava);
                };
            }
            else
            {
                var globalLink = new VMTSOGlobalLinkStub();
                globalLink.Database = new SimAntics.Engine.TSOGlobalLink.VMTSOStandaloneDatabase();
                var sd = new VMServerDriver(globalLink);
                SandServer = new FSOSandboxServer();

                Driver                   = sd;
                sd.OnDropClient         += SandServer.ForceDisconnect;
                sd.OnTickBroadcast      += SandServer.Broadcast;
                sd.OnDirectMessage      += SandServer.SendMessage;
                SandServer.OnConnect    += sd.ConnectClient;
                SandServer.OnDisconnect += sd.DisconnectClient;
                SandServer.OnMessage    += sd.HandleMessage;

                SandServer.Start((ushort)37564);
            }

            //Driver.OnClientCommand += VMSendCommand;
            //Driver.OnShutdown += VMShutdown;

            vm = new VM(new VMContext(World), Driver, new UIHeadlineRendererProvider());
            vm.ListenBHAVChanges();
            vm.Init();

            LotControl = new UILotControl(vm, World);
            this.AddAt(0, LotControl);

            var time    = DateTime.UtcNow;
            var tsoTime = TSOTime.FromUTC(time);

            vm.Context.Clock.Hours   = tsoTime.Item1;
            vm.Context.Clock.Minutes = tsoTime.Item2;
            if (m_ZoomLevel > 3)
            {
                World.Visible      = false;
                LotControl.Visible = false;
            }

            if (IDEHook.IDE != null)
            {
                IDEHook.IDE.StartIDE(vm);
            }

            vm.OnFullRefresh      += VMRefreshed;
            vm.OnChatEvent        += Vm_OnChatEvent;
            vm.OnEODMessage       += LotControl.EODs.OnEODMessage;
            vm.OnRequestLotSwitch += VMLotSwitch;
            vm.OnGenericVMEvent   += Vm_OnGenericVMEvent;

            if (!external && !recording)
            {
                if (!Downtown && ActiveFamily != null)
                {
                    ActiveFamily.SelectWholeFamily();
                    vm.TS1State.ActivateFamily(vm, ActiveFamily);
                }
                BlueprintReset(lotName);

                var experimentalTuning = new Common.Model.DynamicTuning(new List <Common.Model.DynTuningEntry> {
                    new Common.Model.DynTuningEntry()
                    {
                        tuning_type = "overfill", tuning_table = 255, tuning_index = 15, value = 200
                    },
                    new Common.Model.DynTuningEntry()
                    {
                        tuning_type = "overfill", tuning_table = 255, tuning_index = 5, value = 200
                    },
                    new Common.Model.DynTuningEntry()
                    {
                        tuning_type = "overfill", tuning_table = 255, tuning_index = 6, value = 200
                    },
                    new Common.Model.DynTuningEntry()
                    {
                        tuning_type = "overfill", tuning_table = 255, tuning_index = 7, value = 200
                    },
                    new Common.Model.DynTuningEntry()
                    {
                        tuning_type = "overfill", tuning_table = 255, tuning_index = 8, value = 200
                    },
                    new Common.Model.DynTuningEntry()
                    {
                        tuning_type = "overfill", tuning_table = 255, tuning_index = 9, value = 200
                    },
                    new Common.Model.DynTuningEntry()
                    {
                        tuning_type = "feature", tuning_table = 0, tuning_index = 0, value = 1
                    },                                                                                                            //ts1/tso engine animation timings (1.2x faster)
                });
                vm.ForwardCommand(new VMNetTuningCmd {
                    Tuning = experimentalTuning
                });

                vm.TSOState.PropertyCategory = 255; //11 is community
                vm.TSOState.ActivateValidator(vm);
                vm.Context.Clock.Hours = 0;
                vm.TSOState.Size      &= unchecked ((int)0xFFFF0000);
                vm.TSOState.Size      |= (10) | (3 << 8);
                vm.Context.UpdateTSOBuildableArea();

                if (vm.GetGlobalValue(11) > -1)
                {
                    for (int y = 0; y < 3; y++)
                    {
                        for (int x = 0; x < 3; x++)
                        {
                            vm.TSOState.Terrain.Roads[x, y] = 0xF; //crossroads everywhere
                        }
                    }
                    VMLotTerrainRestoreTools.RestoreTerrain(vm);
                }

                var myClient = new VMNetClient
                {
                    PersistID   = myState.PersistID,
                    RemoteIP    = "local",
                    AvatarState = myState
                };

                var server = (VMServerDriver)Driver;
                server.ConnectClient(myClient);

                GameFacade.Cursor.SetCursor(CursorType.Normal);
                ZoomLevel = 1;
            }
            vm.MyUID  = myState.PersistID;
            ZoomLevel = 1;
        }
Exemplo n.º 5
0
        public override void Update(FSO.Common.Rendering.Framework.Model.UpdateState state)
        {
            GameFacade.Game.IsFixedTimeStep = (vm == null || vm.Ready);

            base.Update(state);

            if (CityRenderer != null)
            {
                if (ZoomLevel > 3 && (CityRenderer.m_Zoomed == TerrainZoomMode.Near) != (ZoomLevel == 4))
                {
                    ZoomLevel = (CityRenderer.m_Zoomed == TerrainZoomMode.Near) ? 4 : 5;
                }

                if (World != null)
                {
                    if (CityRenderer.m_Zoomed == TerrainZoomMode.Lot)
                    {
                        if (World.FrameCounter < 3)
                        {
                            //wait until the draw stage has stabalized a bit. tends to be like this
                            // 1. heavy singular draw
                            // 2. update * 30
                            // 3. normal draws
                            CityRenderer.m_LotZoomProgress = 0;
                            World.Visible = true;
                            World.Opacity = 0;
                        }
                        else if (World.FrameCounter == 5 && GlobalSettings.Default.CompatState < GlobalSettings.TARGET_COMPAT_STATE)
                        {
                            GlobalSettings.Default.CompatState = GlobalSettings.TARGET_COMPAT_STATE;
                            GlobalSettings.Default.Save();
                        }
                        else
                        {
                            CityRenderer.InheritPosition(World, FindController <CoreGameScreenController>());
                        }
                    }
                    if (CityRenderer.m_LotZoomProgress > 0f && CityRenderer.m_LotZoomProgress < 1f)
                    {
                        if (CityRenderer.m_Zoomed == TerrainZoomMode.Lot)
                        {
                            if (CityRenderer.m_LotZoomProgress > 0.9995f)
                            {
                                CityRenderer.m_LotZoomProgress = 1f;
                                CityRenderer.Visible           = false;
                            }
                        }
                        else
                        {
                            if (CityRenderer.m_LotZoomProgress < 0.001f)
                            {
                                CityRenderer.m_LotZoomProgress = 0f;
                                World.Visible = false;
                            }
                        }
                        World.Opacity = Math.Max(0, (CityRenderer.m_LotZoomProgress - 0.5f) * 2);

                        var scale =
                            1 / ((CityRenderer.m_LotZoomProgress * (1 / CityRenderer.m_LotZoomSize) + (1 - CityRenderer.m_LotZoomProgress) * (1 / (Terrain.NEAR_ZOOM_SIZE * CityRenderer.m_WheelZoom))))
                            / CityRenderer.m_LotZoomSize;

                        World.State.PreciseZoom = scale;
                    }
                }

                if (InLot) //if we're in a lot, use the VM's more accurate time!
                {
                    CityRenderer.SetTimeOfDay((vm.Context.Clock.Hours / 24.0) + (vm.Context.Clock.Minutes / 1440.0) + (vm.Context.Clock.Seconds / 86400.0));
                }
                else
                {
                    var time    = DateTime.UtcNow;
                    var tsoTime = TSOTime.FromUTC(time);
                    CityRenderer.SetTimeOfDay((tsoTime.Item1 / 24.0) + (tsoTime.Item2 / 1440.0) + (tsoTime.Item3 / 86400.0));
                }
            }

            lock (StateChanges)
            {
                while (StateChanges.Count > 0)
                {
                    var e = StateChanges.Dequeue();
                    ClientStateChangeProcess(e.State, e.Progress);
                }
            }

            if (vm != null)
            {
                vm.Update();
            }
        }
Exemplo n.º 6
0
        public override void Update(FSO.Common.Rendering.Framework.Model.UpdateState state)
        {
            var time    = DateTime.UtcNow;
            var tsoTime = TSOTime.FromUTC(time);
            int min     = tsoTime.Item2;
            int hour    = tsoTime.Item1;

            if (MoneyHighlightFrames > 0)
            {
                if (--MoneyHighlightFrames == 0)
                {
                    MoneyText.CaptionStyle.Color = TextStyle.DefaultLabel.Color;
                }
            }
            uint budget = 0;

            if (Game.InLot)
            {
                // if ingame, use time from ingame clock
                // (should be very close to server time anyways, if we set the game pacing up right...)
                min  = Game.vm.Context.Clock.Minutes;
                hour = Game.vm.Context.Clock.Hours;

                // update with ingame budget.
                var cont = Game.LotControl;
                if (cont.ActiveEntity != null && cont.ActiveEntity is VMAvatar)
                {
                    var avatar = (VMAvatar)cont.ActiveEntity;
                    budget = avatar.TSOState.Budget.Value;

                    //check if we have build/buy permissions
                    //TODO: global build/buy enable/disable (via the global calls)
                    BuildModeButton.Disabled = ((VMTSOAvatarState)(avatar.TSOState)).Permissions
                                               < VMTSOAvatarPermissions.BuildBuyRoommate;
                    HouseModeButton.Disabled = BuyModeButton.Disabled;

                    if (CurrentPanel == 2)
                    {
                        var panel    = (UIBuyMode)Panel;
                        var isRoomie = ((VMTSOAvatarState)(avatar.TSOState)).Permissions
                                       >= VMTSOAvatarPermissions.Roommate;
                        panel.SetRoommate(isRoomie);
                    }
                }
                var level = Game.LotControl.World.State.Level.ToString();
                if (FloorNumLabel.Caption != level)
                {
                    FloorNumLabel.Caption = level;
                }

                if (CurrentPanel == 3 && BuildModeButton.Disabled)
                {
                    SetPanel(-1);
                }
                if (LastZoom != Game.ZoomLevel)
                {
                    UpdateZoomButton();
                }
            }
            else
            {
                budget = OldMoney;
            }

            if (budget != OldMoney)
            {
                OldMoney = budget;
                MoneyText.CaptionStyle.Color = Color.White;
                MoneyHighlightFrames         = 45;
                Game.VisualBudget            = budget;
            }

            string suffix = (hour > 11) ? "pm" : "am";

            hour %= 12;
            if (hour == 0)
            {
                hour = 12;
            }

            TimeText.Caption  = hour.ToString() + ":" + ZeroPad(min.ToString(), 2) + " " + suffix;
            MoneyText.Caption = "$" + Game.VisualBudget.ToString("##,#0");

            if (InboxFlashing)
            {
                if ((InboxFlashTime++) > FSOEnvironment.RefreshRate / 2)
                {
                    if (PhoneButton.ForceState == 2)
                    {
                        PhoneButton.ForceState = -1;
                        Invalidate();
                    }
                }
                else
                {
                    if (PhoneButton.ForceState != 2)
                    {
                        PhoneButton.ForceState = 2;
                        Invalidate();
                    }
                }
                InboxFlashTime %= FSOEnvironment.RefreshRate;
            }

            var keys    = state.NewKeys;
            var nofocus = state.InputManager.GetFocus() == null;

            base.Update(state);
            if (Game.InLot && state.WindowFocused)
            {
                if (keys.Contains(Keys.F1) && !state.CtrlDown)
                {
                    SetPanel(1);                                            // Live Mode Panel
                }
                if (keys.Contains(Keys.F2))
                {
                    SetPanel(2);                         // Buy Mode Panel
                }
                if (keys.Contains(Keys.F3) && !BuildModeButton.Disabled)
                {
                    SetPanel(3);                                                      // Build Mode Panel
                }
                if (keys.Contains(Keys.F4))
                {
                    SetPanel(4);                         // House Mode Panel
                }
                if (nofocus)
                {
                    if (FSOEnvironment.Enable3D)
                    {
                        //if the zoom or rotation buttons are down, gradually change their values.
                        if (RotateClockwiseButton.IsDown || state.KeyboardState.IsKeyDown(Keys.OemPeriod))
                        {
                            ((WorldStateRC)Game.vm.Context.World.State).RotationX += 2f / FSOEnvironment.RefreshRate;
                        }
                        if (RotateCounterClockwiseButton.IsDown || state.KeyboardState.IsKeyDown(Keys.OemComma))
                        {
                            ((WorldStateRC)Game.vm.Context.World.State).RotationX -= 2f / FSOEnvironment.RefreshRate;
                        }
                        if (ZoomInButton.IsDown || (state.KeyboardState.IsKeyDown(Keys.OemPlus) && !state.CtrlDown))
                        {
                            Game.LotControl.TargetZoom = Math.Max(0.25f, Math.Min(Game.LotControl.TargetZoom + 1f / FSOEnvironment.RefreshRate, 2));
                        }
                        if (ZoomOutButton.IsDown || (state.KeyboardState.IsKeyDown(Keys.OemMinus) && !state.CtrlDown))
                        {
                            Game.LotControl.TargetZoom = Math.Max(0.25f, Math.Min(Game.LotControl.TargetZoom - 1f / FSOEnvironment.RefreshRate, 2));
                        }
                    }
                    else
                    {
                        if (keys.Contains(Keys.OemPlus) && !state.CtrlDown && !ZoomInButton.Disabled)
                        {
                            Game.ZoomLevel -= 1; UpdateZoomButton();
                        }
                        if (keys.Contains(Keys.OemMinus) && !state.CtrlDown && !ZoomOutButton.Disabled)
                        {
                            Game.ZoomLevel += 1; UpdateZoomButton();
                        }
                        if (keys.Contains(Keys.OemComma))
                        {
                            RotateCounterClockwise(null);
                        }
                        if (keys.Contains(Keys.OemPeriod))
                        {
                            RotateClockwise(null);
                        }
                    }
                    if (keys.Contains(Keys.PageDown))
                    {
                        FirstFloor(null);
                    }
                    if (keys.Contains(Keys.PageUp))
                    {
                        SecondFloor(null);
                    }
                    if (keys.Contains(Keys.Home))
                    {
                        UpdateWallsViewKeyHandler(1);
                    }
                    if (keys.Contains(Keys.End))
                    {
                        UpdateWallsViewKeyHandler(0);
                    }
                }
            }
            if (keys.Contains(Keys.F5))
            {
                SetPanel(5);                         // Options Mode Panel
            }
        }
Exemplo n.º 7
0
        public override void Update(FSO.Common.Rendering.Framework.Model.UpdateState state)
        {
            GameFacade.Game.IsFixedTimeStep = (vm == null || vm.Ready);

            Visible = World?.Visible == false || (World?.State as FSO.LotView.RC.WorldStateRC)?.CameraMode != true;
            GameFacade.Game.IsMouseVisible = Visible;

            base.Update(state);

            if (state.NewKeys.Contains(Microsoft.Xna.Framework.Input.Keys.F1) && state.CtrlDown)
            {
                FSOFacade.Controller.ToggleDebugMenu();
            }

            if (CityRenderer != null)
            {
                if (ZoomLevel > 3 && (CityRenderer.m_Zoomed == TerrainZoomMode.Near) != (ZoomLevel == 4))
                {
                    ZoomLevel = (CityRenderer.m_Zoomed == TerrainZoomMode.Near) ? 4 : 5;
                }

                if (World != null)
                {
                    if (CityRenderer.m_Zoomed == TerrainZoomMode.Lot)
                    {
                        if (World.FrameCounter < 3)
                        {
                            //wait until the draw stage has stabalized a bit. tends to be like this
                            // 1. heavy singular draw
                            // 2. update * 30
                            // 3. normal draws
                            CityRenderer.m_LotZoomProgress = 0;
                            World.Visible = true;
                            World.Opacity = 0;
                        }
                        else if (World.FrameCounter == 5 && GlobalSettings.Default.CompatState < GlobalSettings.TARGET_COMPAT_STATE)
                        {
                            GlobalSettings.Default.CompatState = GlobalSettings.TARGET_COMPAT_STATE;
                            GlobalSettings.Default.Save();
                        }
                        else
                        {
                            CityRenderer.InheritPosition(World, FindController <CoreGameScreenController>());
                        }
                    }
                    if (CityRenderer.m_LotZoomProgress > 0f && CityRenderer.m_LotZoomProgress < 1f)
                    {
                        if (CityRenderer.m_Zoomed == TerrainZoomMode.Lot)
                        {
                            if (CityRenderer.m_LotZoomProgress > 0.9999f)
                            {
                                CityRenderer.m_LotZoomProgress = 1f;
                                CityRenderer.Visible           = false;
                            }
                        }
                        else
                        {
                            if (CityRenderer.m_LotZoomProgress < 0.0001f)
                            {
                                CityRenderer.m_LotZoomProgress = 0f;
                                World.Visible = false;
                            }
                        }
                        World.Opacity = Math.Max(0, (CityRenderer.m_LotZoomProgress - 0.5f) * 2);

                        var scale =
                            1 / ((CityRenderer.m_LotZoomProgress * (1 / CityRenderer.m_LotZoomSize) + (1 - CityRenderer.m_LotZoomProgress) * (1 / (Terrain.NEAR_ZOOM_SIZE * CityRenderer.m_WheelZoom))))
                            / CityRenderer.m_LotZoomSize;

                        World.State.PreciseZoom = scale;
                    }
                }

                if (InLot) //if we're in a lot, use the VM's more accurate time!
                {
                    CityRenderer.SetTimeOfDay((vm.Context.Clock.Hours / 24.0) + (vm.Context.Clock.Minutes / 1440.0) + (vm.Context.Clock.Seconds / 86400.0));
                }
                else
                {
                    var time    = DateTime.UtcNow;
                    var tsoTime = TSOTime.FromUTC(time);
                    CityRenderer.SetTimeOfDay((tsoTime.Item1 / 24.0) + (tsoTime.Item2 / 1440.0) + (tsoTime.Item3 / 86400.0));
                }
            }

            lock (StateChanges)
            {
                while (StateChanges.Count > 0)
                {
                    var e = StateChanges.Dequeue();
                    ClientStateChangeProcess(e.State, e.Progress);
                }
            }

            if (vm != null)
            {
                vm.Update();
            }

            var joinAttempt = DiscordRpcEngine.Secret;

            if (joinAttempt != null)
            {
                var  split = joinAttempt.Split('#');
                uint lotID;
                if (uint.TryParse(split[0], out lotID))
                {
                    FindController <CoreGameScreenController>()?.JoinLot(lotID);
                }

                DiscordRpcEngine.Secret = null;
            }
        }
Exemplo n.º 8
0
        public void InitializeLot(string lotName, bool external)
        {
            if (lotName == "")
            {
                return;
            }
            CleanupLastWorld();

            World         = new LotView.World(GameFacade.GraphicsDevice);
            World.Opacity = 1;
            GameFacade.Scenes.Add(World);

            if (external)
            {
                //external not yet implemented
                Driver = new VMClientDriver(ClientStateChange);
            }
            else
            {
                var globalLink = new VMTSOGlobalLinkStub();
                Driver = new VMServerDriver(globalLink);
            }

            //Driver.OnClientCommand += VMSendCommand;
            //Driver.OnShutdown += VMShutdown;

            vm = new VM(new VMContext(World), Driver, new UIHeadlineRendererProvider());
            vm.ListenBHAVChanges();
            vm.Init();

            LotControl = new UILotControl(vm, World);
            this.AddAt(0, LotControl);

            var time    = DateTime.UtcNow;
            var tsoTime = TSOTime.FromUTC(time);

            vm.Context.Clock.Hours   = tsoTime.Item1;
            vm.Context.Clock.Minutes = tsoTime.Item2;
            if (m_ZoomLevel > 3)
            {
                World.Visible      = false;
                LotControl.Visible = false;
            }

            ZoomLevel = Math.Max(ZoomLevel, 4);

            if (IDEHook.IDE != null)
            {
                IDEHook.IDE.StartIDE(vm);
            }

            vm.OnFullRefresh      += VMRefreshed;
            vm.OnChatEvent        += Vm_OnChatEvent;
            vm.OnEODMessage       += LotControl.EODs.OnEODMessage;
            vm.OnRequestLotSwitch += VMLotSwitch;
            vm.OnGenericVMEvent   += Vm_OnGenericVMEvent;

            if (!external)
            {
                vm.ActivateFamily(ActiveFamily);
                BlueprintReset(lotName);

                vm.Context.Clock.Hours = 0;
                vm.TSOState.Size       = (10) | (3 << 8);
                vm.Context.UpdateTSOBuildableArea();
                vm.MyUID = 1;
                var settings = GlobalSettings.Default;
                var myClient = new VMNetClient
                {
                    PersistID   = 1,
                    RemoteIP    = "local",
                    AvatarState = new VMNetAvatarPersistState()
                    {
                        Name         = settings.LastUser,
                        DefaultSuits = new VMAvatarDefaultSuits(settings.DebugGender),
                        BodyOutfit   = settings.DebugBody,
                        HeadOutfit   = settings.DebugHead,
                        PersistID    = 1,
                        SkinTone     = (byte)settings.DebugSkin,
                        Gender       = (short)(settings.DebugGender ? 1 : 0),
                        Permissions  = SimAntics.Model.TSOPlatform.VMTSOAvatarPermissions.Admin,
                        Budget       = 100000
                    }
                };

                var server = (VMServerDriver)Driver;
                server.ConnectClient(myClient);

                GameFacade.Cursor.SetCursor(CursorType.Normal);
                ZoomLevel = 1;
            }
        }
Exemplo n.º 9
0
        public override void Update(FSO.Common.Rendering.Framework.Model.UpdateState state)
        {
            var time    = DateTime.UtcNow;
            var tsoTime = TSOTime.FromUTC(time);
            int min     = tsoTime.Item2;
            int hour    = tsoTime.Item1;

            if (MoneyHighlightFrames > 0)
            {
                if (--MoneyHighlightFrames == 0)
                {
                    MoneyText.CaptionStyle.Color = TextStyle.DefaultLabel.Color;
                }
            }
            uint budget = 0;

            if (Game.InLot)
            {
                // if ingame, use time from ingame clock
                // (should be very close to server time anyways, if we set the game pacing up right...)
                min  = Game.vm.Context.Clock.Minutes;
                hour = Game.vm.Context.Clock.Hours;

                // update with ingame budget.
                var cont = Game.LotControl;
                if (cont.ActiveEntity != null && cont.ActiveEntity is VMAvatar)
                {
                    var avatar = (VMAvatar)cont.ActiveEntity;
                    budget = avatar.TSOState.Budget.Value;

                    //check if we have build/buy permissions
                    //TODO: global build/buy enable/disable (via the global calls)
                    BuildModeButton.Disabled = ((VMTSOAvatarState)(avatar.TSOState)).Permissions
                                               < VMTSOAvatarPermissions.BuildBuyRoommate;
                    HouseModeButton.Disabled = BuyModeButton.Disabled;

                    if (CurrentPanel == 2)
                    {
                        var panel    = (UIBuyMode)Panel;
                        var isRoomie = ((VMTSOAvatarState)(avatar.TSOState)).Permissions
                                       >= VMTSOAvatarPermissions.Roommate;
                        panel.SetRoommate(isRoomie);
                    }
                }
                var level = Game.LotControl.World.State.Level.ToString();
                if (FloorNumLabel.Caption != level)
                {
                    FloorNumLabel.Caption = level;
                }

                if (CurrentPanel == 3 && BuildModeButton.Disabled)
                {
                    SetPanel(-1);
                }
            }
            else
            {
                budget = OldMoney;
            }

            if (budget != OldMoney)
            {
                OldMoney = budget;
                MoneyText.CaptionStyle.Color = Color.White;
                MoneyHighlightFrames         = 45;
                Game.VisualBudget            = budget;
            }

            string suffix = (hour > 11) ? "pm" : "am";

            hour %= 12;
            if (hour == 0)
            {
                hour = 12;
            }

            TimeText.Caption  = hour.ToString() + ":" + ZeroPad(min.ToString(), 2) + " " + suffix;
            MoneyText.Caption = "$" + Game.VisualBudget.ToString("##,#0");

            base.Update(state);
        }
Exemplo n.º 10
0
        public void InitializeLot(string lotName, bool external)
        {
            if (lotName == "")
            {
                return;
            }
            var recording = lotName.ToLowerInvariant().EndsWith(".fsor");

            CleanupLastWorld();

            if (FSOEnvironment.Enable3D)
            {
                var rc = new LotView.RC.WorldRC(GameFacade.GraphicsDevice);
                World = rc;
            }
            else
            {
                World = new World(GameFacade.GraphicsDevice);
            }
            World.Opacity = 1;
            GameFacade.Scenes.Add(World);

            var settings = GlobalSettings.Default;
            var myState  = new VMNetAvatarPersistState()
            {
                Name         = settings.LastUser,
                DefaultSuits = new VMAvatarDefaultSuits(settings.DebugGender),
                BodyOutfit   = settings.DebugBody,
                HeadOutfit   = settings.DebugHead,
                PersistID    = (uint)(new Random()).Next(),
                SkinTone     = (byte)settings.DebugSkin,
                Gender       = (short)(settings.DebugGender ? 0 : 1),
                Permissions  = SimAntics.Model.TSOPlatform.VMTSOAvatarPermissions.Admin,
                Budget       = 1000000,
            };

            if (recording)
            {
                var stream = new FileStream(lotName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                var rd     = new VMFSORDriver(stream);
                Driver = rd;
            }
            else if (external)
            {
                var cd = new VMClientDriver(ClientStateChange);
                SandCli             = new FSOSandboxClient();
                cd.OnClientCommand += (msg) => { SandCli.Write(new VMNetMessage(VMNetMessageType.Command, msg)); };
                cd.OnShutdown      += (reason) => SandCli.Disconnect();
                SandCli.OnMessage  += cd.ServerMessage;
                SandCli.Connect(lotName);
                Driver = cd;

                var dat = new MemoryStream();
                var str = new BinaryWriter(dat);
                myState.SerializeInto(str);
                var ava = new VMNetMessage(VMNetMessageType.AvatarData, dat.ToArray());
                dat.Close();
                SandCli.OnConnectComplete += () =>
                {
                    SandCli.Write(ava);
                };
            }
            else
            {
                var globalLink = new VMTSOGlobalLinkStub();
                var sd         = new VMServerDriver(globalLink);
                SandServer = new FSOSandboxServer();

                Driver                   = sd;
                sd.OnDropClient         += SandServer.ForceDisconnect;
                sd.OnTickBroadcast      += SandServer.Broadcast;
                sd.OnDirectMessage      += SandServer.SendMessage;
                SandServer.OnConnect    += sd.ConnectClient;
                SandServer.OnDisconnect += sd.DisconnectClient;
                SandServer.OnMessage    += sd.HandleMessage;

                SandServer.Start((ushort)37564);
            }

            //Driver.OnClientCommand += VMSendCommand;
            //Driver.OnShutdown += VMShutdown;

            vm = new VM(new VMContext(World), Driver, new UIHeadlineRendererProvider());
            vm.ListenBHAVChanges();
            vm.Init();

            LotControl = new UILotControl(vm, World);
            this.AddAt(0, LotControl);

            var time    = DateTime.UtcNow;
            var tsoTime = TSOTime.FromUTC(time);

            vm.Context.Clock.Hours   = tsoTime.Item1;
            vm.Context.Clock.Minutes = tsoTime.Item2;
            if (m_ZoomLevel > 3)
            {
                World.Visible      = false;
                LotControl.Visible = false;
            }

            if (IDEHook.IDE != null)
            {
                IDEHook.IDE.StartIDE(vm);
            }

            vm.OnFullRefresh      += VMRefreshed;
            vm.OnChatEvent        += Vm_OnChatEvent;
            vm.OnEODMessage       += LotControl.EODs.OnEODMessage;
            vm.OnRequestLotSwitch += VMLotSwitch;
            vm.OnGenericVMEvent   += Vm_OnGenericVMEvent;

            if (!external && !recording)
            {
                if (!Downtown && ActiveFamily != null)
                {
                    ActiveFamily.SelectWholeFamily();
                    vm.ActivateFamily(ActiveFamily);
                }
                BlueprintReset(lotName);

                vm.TSOState.PropertyCategory = 255;
                vm.Context.Clock.Hours       = 0;
                vm.TSOState.Size             = (10) | (3 << 8);
                vm.Context.UpdateTSOBuildableArea();
                var myClient = new VMNetClient
                {
                    PersistID   = myState.PersistID,
                    RemoteIP    = "local",
                    AvatarState = myState
                };

                var server = (VMServerDriver)Driver;
                server.ConnectClient(myClient);

                GameFacade.Cursor.SetCursor(CursorType.Normal);
                ZoomLevel = 1;
            }
            vm.MyUID  = myState.PersistID;
            ZoomLevel = 1;
        }