Beispiel #1
0
        internal override void BeginRender(RenderFrame frame)
        {
            // Do this here (instead of RenderProcess) because we only want to measure/time the running game.
            if (Game.Settings.Profiling)
            {
                if ((Game.Settings.ProfilingFrameCount > 0 && ++ProfileFrames > Game.Settings.ProfilingFrameCount) || (Game.Settings.ProfilingTime > 0 && Viewer != null && Viewer.RealTime >= Game.Settings.ProfilingTime))
                {
                    Game.PopState();
                }
            }

            if (FirstFrame)
            {
                // Turn off the 10FPS fixed-time-step and return to running as fast as we can.
                Game.IsFixedTimeStep   = false;
                Game.InactiveSleepTime = TimeSpan.Zero;

                // We must create these forms on the main thread (Render) or they won't pump events correctly.

                if (MPManager.IsMultiPlayer() || Game.Settings.ViewDispatcher)
                {
                    Program.DebugViewer = new DispatchViewer(Viewer.Simulator, Viewer);
                    Program.DebugViewer.Hide();
                    Viewer.DebugViewerEnabled = false;
                }

                Program.SoundDebugForm = new SoundDebugForm(Viewer);
                Program.SoundDebugForm.Hide();
                Viewer.SoundDebugFormEnabled = false;

                FirstFrame = false;
            }
            Viewer.BeginRender(frame);
        }
    // Start is called before the first frame update
    void Start()
    {
        uIManager        = FindObjectOfType <UIManager>();
        weaponManager    = FindObjectOfType <WeaponManager>();
        armorManager     = FindObjectOfType <ArmorManager>();
        healthManager    = GetComponent <HealthManager>();
        playerController = GetComponent <PlayerController>();
        mpManager        = GetComponent <MPManager>();
        AddStatsToCharacter(strengthLevels[level], defenseLevels[level], magicAttLevels[level], magicDefLevels[level], speedLevels[level], luckLevels[level], accuracyLevels[level]);

        //Vida del Enemigo y Player
        if (!statsForSkill)
        {
            healthManager.UpdateMaxHealth(hpLevels[level]);
        }

        //Actualizar en el arranque el Level en el UI HUD. Solamente al Player!
        if (gameObject.tag.Equals("Player"))
        {
            uIManager.LevelChanged(level, expToLevelUp.Length, expToLevelUp[level], expToLevelUp[level - 1]);
            mpManager.UpdateMaxMP(mpLevels[level]);
        }


        if (gameObject.tag.Equals("Enemy") && !statsForSkill)
        {
            if (!enemyWeapon)
            {
                EnemyController controller = GetComponent <EnemyController>();
                controller.speed += (1.0f + (float)newspeedLevels / MAX_STAT_VAL);
            }
        }
    }
Beispiel #3
0
 //================================================================================================//
 /// <summary>
 ///  check if linked route is set
 /// </summary>
 public int VerifyRouteSet()
 {
     // call route_set routine from main signal
     if (TrackJunctionNode > 0)
     {
         return(MainSignal.CheckRouteSet(JunctionMainNode, TrackJunctionNode) ? 1 : 0);
     }
     //added by JTang
     else if (MPManager.IsMultiPlayer())
     {
         TrackNode node = Simulator.Instance.TDB.TrackDB.TrackNodes[MainSignal.TrackNode];
         if (!(node is TrackJunctionNode) && node.TrackPins != null && (int)MainSignal.TrackCircuitDirection < node.TrackPins.Length)
         {
             node = Simulator.Instance.TDB.TrackDB.TrackNodes[node.TrackPins[(int)MainSignal.TrackCircuitDirection].Link];
             if (!(node is TrackJunctionNode junctionNode))
             {
                 return(0);
             }
             for (int pin = junctionNode.InPins; pin < junctionNode.InPins + junctionNode.OutPins; pin++)
             {
                 if (junctionNode.TrackPins[pin].Link == MainSignal.TrackNode && pin - junctionNode.InPins != junctionNode.SelectedRoute)
                 {
                     return(0);
                 }
             }
         }
     }
     return(1);
 }
Beispiel #4
0
        public void InitMessage()
        {
            Visible = true;
            keyboardInput.SuspendForOverlayInput();
            game.Window.TextInput += Window_TextInput;

            if (!string.IsNullOrEmpty(MPManager.Instance().lastSender))
            {
                messageLabel.Text = MPManager.Instance().lastSender + ":";
            }
        }
Beispiel #5
0
    void Awake()
    {
        if (instance != null)
        {
            DestroyImmediate(gameObject);
            return;
        }
        DontDestroyOnLoad(gameObject);
        instance = this;

        PhotonNetwork.automaticallySyncScene = true;
    }
Beispiel #6
0
        private void SendMessage()
        {
            //we need to send message out
            string user = "";

            if (string.IsNullOrEmpty(MPManager.Instance().lastSender)) //server will broadcast the message to everyone
            {
                user = MPManager.IsServer() ? string.Join("", MPManager.OnlineTrains.Players.Keys.Select((string k) => $"{k}\r")) + "0END" : "0Server\r0END";
            }

            string msg   = messageText.ToString();
            int    index = msg.IndexOf(':');

            if (index > 0)
            {
                msg = messageText.ToString(index + 1, messageText.Length - index - 1);

                IEnumerable <string> onlinePlayers = messageLabel.Text.Substring(0, index)
                                                     .Split(',')
                                                     .Select((string n) => n.Trim())
                                                     .Where((string nt) => MPManager.OnlineTrains.Players.ContainsKey(nt))
                                                     .Select((string nt) => $"{nt}\r");

                string newUser = string.Join("", onlinePlayers);
                if (newUser.Length > 0)
                {
                    user = newUser;
                }
                user += "0END";
            }

            string msgText = new MSGText(MPManager.GetUserName(), user, msg).ToString();

            try
            {
                MPManager.Notify(msgText);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch
#pragma warning restore CA1031 // Do not catch general exception types
            {
            }
            finally
            {
                Visible = false;
                messageText.Clear();
                game.Window.TextInput -= Window_TextInput;
                keyboardInput.ResumeFromOverlayInput();
            }
        }
Beispiel #7
0
        public static void HandleUserInput()
        {
            //In Multiplayer, I maybe the helper, but I can request to be the controller
            if (UserInput.IsPressed(UserCommands.GameRequestControl))
            {
                MPManager.RequestControl();
            }

            if (UserInput.IsPressed(UserCommands.ControlHorn)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HORN", 1)).ToString());

            if (UserInput.IsReleased(UserCommands.ControlHorn)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HORN", 0)).ToString());

            if (UserInput.IsPressed(UserCommands.ControlPantograph2)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO2", (++PantoSecondCount) % 2)).ToString());

            if (UserInput.IsPressed(UserCommands.ControlPantograph1)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO1", (++PantoFirstCount) % 2)).ToString());

            if (UserInput.IsPressed(UserCommands.ControlBell)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", 1)).ToString());

            if (UserInput.IsReleased(UserCommands.ControlBell)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", 0)).ToString());

            if (UserInput.IsPressed(UserCommands.ControlBellToggle)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", (++BellCount) % 2)).ToString());

            if (UserInput.IsPressed(UserCommands.ControlWiper)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "WIPER", (++WiperCount) % 2)).ToString());

            if (UserInput.IsPressed(UserCommands.ControlDoorLeft)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "DOORL", (++DoorLeftCount) % 2)).ToString());

            if (UserInput.IsPressed(UserCommands.ControlDoorRight)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "DOORR", (++DoorRightCount) % 2)).ToString());

            if (UserInput.IsPressed(UserCommands.ControlMirror)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "MIRRORS", (++MirrorsCount) % 2)).ToString());

            if (UserInput.IsPressed(UserCommands.ControlHeadlightIncrease))
            {
                HeadLightCount++; if (HeadLightCount >= 3) HeadLightCount = 2;
                MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", HeadLightCount)).ToString());
            }

            if (UserInput.IsPressed(UserCommands.ControlHeadlightDecrease))
            {
                HeadLightCount--; if (HeadLightCount < 0) HeadLightCount = 0;
                MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", HeadLightCount)).ToString());
            }

        }
Beispiel #8
0
    // Start is called before the first frame update
    void Start()
    {
        thePlayer = FindObjectOfType <PlayerController>();
        uiManager = FindObjectOfType <UIManager>();
        //uiManager.ToggleHUD();

        healthManager   = GameObject.Find("Player").GetComponent <HealthManager>();
        stats           = GameObject.Find("Player").GetComponent <CharacterStats>();
        mpManager       = GameObject.Find("Player").GetComponent <MPManager>();
        itemsManager    = FindObjectOfType <ItemsManager>();
        weaponManager   = FindObjectOfType <WeaponManager>();
        armorManager    = FindObjectOfType <ArmorManager>();
        accesoryManager = FindObjectOfType <AccesoryManager>();
        itemsManager    = FindObjectOfType <ItemsManager>();
        questManager    = FindObjectOfType <QuestManager>();
        sceneTransition = FindObjectOfType <SceneTransition>();
        uiManager       = FindObjectOfType <UIManager>();
        moneyManager    = FindObjectOfType <MoneyManager>();

        alreadyLoading = false;
    }
Beispiel #9
0
        public static void RegisterInputEvents(Viewer viewer)
        {
            if (null == viewer)
            {
                throw new ArgumentNullException(nameof(viewer));
            }

            //In Multiplayer, I maybe the helper, but I can request to be the controller
            // Horn and bell are managed by UpdateHornAndBell in MSTSLocomotive.cs
            viewer.UserCommandController.AddEvent(UserCommand.GameRequestControl, KeyEventType.KeyPressed, MPManager.RequestControl);
            viewer.UserCommandController.AddEvent(UserCommand.ControlPantograph1, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "PANTO1", (++panto1) % 2).ToString()));
            viewer.UserCommandController.AddEvent(UserCommand.ControlPantograph2, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "PANTO2", (++panto2) % 2).ToString()));
            viewer.UserCommandController.AddEvent(UserCommand.ControlPantograph3, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "PANTO3", (++panto3) % 2).ToString()));
            viewer.UserCommandController.AddEvent(UserCommand.ControlPantograph4, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "PANTO4", (++panto4) % 2).ToString()));
            viewer.UserCommandController.AddEvent(UserCommand.ControlWiper, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "WIPER", (++wiper) % 2).ToString()));
            viewer.UserCommandController.AddEvent(UserCommand.ControlDoorLeft, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "DOORL", (++doorLeft) % 2).ToString()));
            viewer.UserCommandController.AddEvent(UserCommand.ControlDoorRight, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "DOORR", (++doorRight) % 2).ToString()));
            viewer.UserCommandController.AddEvent(UserCommand.ControlMirror, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "MIRRORS", (++mirrors) % 2).ToString()));

            viewer.UserCommandController.AddEvent(UserCommand.ControlHeadlightIncrease, KeyEventType.KeyPressed, () =>
            {
                headlight++;
                if (headlight >= 3)
                {
                    headlight = 2;
                }
                MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", headlight).ToString());
            });

            viewer.UserCommandController.AddEvent(UserCommand.ControlHeadlightDecrease, KeyEventType.KeyPressed, () =>
            {
                headlight--;
                if (headlight < 0)
                {
                    headlight = 0;
                }
                MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", headlight).ToString());
            });
        }
Beispiel #10
0
        private void ShowDispatchControls(bool dispatchView)
        {
            var multiPlayer = MPManager.IsMultiPlayer() && dispatchView;

            F.msgAll.Visible             = multiPlayer;
            F.msgSelected.Visible        = multiPlayer;
            F.composeMSG.Visible         = multiPlayer;
            F.MSG.Visible                = multiPlayer;
            F.messages.Visible           = multiPlayer;
            F.AvatarView.Visible         = multiPlayer;
            F.composeMSG.Visible         = multiPlayer;
            F.reply2Selected.Visible     = multiPlayer;
            F.chkShowAvatars.Visible     = multiPlayer;
            F.chkAllowUserSwitch.Visible = multiPlayer;
            F.chkAllowNew.Visible        = multiPlayer;
            F.chkBoxPenalty.Visible      = multiPlayer;
            F.chkPreferGreen.Visible     = multiPlayer;
            F.btnAssist.Visible          = multiPlayer;
            F.btnNormal.Visible          = multiPlayer;
            F.rmvButton.Visible          = multiPlayer;

            if (multiPlayer)
            {
                F.chkShowAvatars.Checked = Program.Simulator.Settings.ShowAvatar;
                F.pbCanvas.Location      = new System.Drawing.Point(F.pbCanvas.Location.X, F.label1.Location.Y + 18);
                F.refreshButton.Text     = "View Self";
            }

            F.chkDrawPath.Visible      = dispatchView;
            F.chkPickSignals.Visible   = dispatchView;
            F.chkPickSwitches.Visible  = dispatchView;
            F.btnSeeInGame.Visible     = dispatchView;
            F.btnFollow.Visible        = dispatchView;
            F.windowSizeUpDown.Visible = dispatchView;
            F.label1.Visible           = dispatchView;
            F.resLabel.Visible         = dispatchView;
            F.refreshButton.Visible    = dispatchView;
        }
Beispiel #11
0
    // Start is called before the first frame update
    void Start()
    {
        player    = FindObjectOfType <PlayerController>();
        theCamera = FindObjectOfType <CameraFollow>();

        healthManager   = GameObject.Find("Player").GetComponent <HealthManager>();
        stats           = GameObject.Find("Player").GetComponent <CharacterStats>();
        mpManager       = GameObject.Find("Player").GetComponent <MPManager>();
        itemsManager    = FindObjectOfType <ItemsManager>();
        weaponManager   = FindObjectOfType <WeaponManager>();
        armorManager    = FindObjectOfType <ArmorManager>();
        accesoryManager = FindObjectOfType <AccesoryManager>();
        itemsManager    = FindObjectOfType <ItemsManager>();
        questManager    = FindObjectOfType <QuestManager>();
        moneyManager    = FindObjectOfType <MoneyManager>();
        uiManager       = FindObjectOfType <UIManager>();

        if (!player.nextUuid.Equals(savePointId))
        {
            return;
        }
        player.transform.position    = this.transform.position;
        theCamera.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, theCamera.transform.position.z);
    }
Beispiel #12
0
        /// <summary>
        /// SkyDrawer constructor
        /// </summary>
        public MSTSSkyDrawer(Viewer viewer)
        {
            MSTSSkyViewer   = viewer;
            MSTSSkyMaterial = viewer.MaterialManager.Load("MSTSSky");
            // Instantiate classes
            MSTSSkyMesh    = new MSTSSkyMesh(MSTSSkyViewer.RenderProcess);
            MSTSSkyVectors = new SunMoonPos();

            //viewer.World.MSTSSky.MSTSSkyMaterial.Viewer.MaterialManager.sunDirection.Y < 0
            // Set default values
            mstsskyseasonType = (int)MSTSSkyViewer.Simulator.Season;
            date.ordinalDate  = 82 + mstsskyseasonType * 91;
            // TODO: Set the following three externally from ORTS route files (future)
            date.month = 1 + date.ordinalDate / 30;
            date.day   = 21;
            date.year  = 2010;
            // Default wind speed and direction
            mstsskywindSpeed     = 5.0f; // m/s (approx 11 mph)
            mstsskywindDirection = 4.7f; // radians (approx 270 deg, i.e. westerly)

            // The following keyboard commands are used for viewing sky and weather effects in "demo" mode.
            // Control- and Control+ for overcast, Shift- and Shift+ for fog and - and + for time.

            // Don't let multiplayer clients adjust the weather.
            if (!MPManager.IsClient())
            {
                // Overcast ranges from 0 (completely clear) to 1 (completely overcast).
                viewer.UserCommandController.AddEvent(UserCommand.DebugOvercastIncrease, KeyEventType.KeyDown, (GameTime gameTIme) =>
                {
                    mstsskyovercastFactor = (float)MathHelperD.Clamp(mstsskyovercastFactor + gameTIme.ElapsedGameTime.TotalSeconds / 10, 0, 1);
                });
                viewer.UserCommandController.AddEvent(UserCommand.DebugOvercastDecrease, KeyEventType.KeyDown, (GameTime gameTIme) =>
                {
                    mstsskyovercastFactor = (float)MathHelperD.Clamp(mstsskyovercastFactor - gameTIme.ElapsedGameTime.TotalSeconds / 10, 0, 1);
                });
                // Fog ranges from 10m (can't see anything) to 100km (clear arctic conditions).
                viewer.UserCommandController.AddEvent(UserCommand.DebugFogIncrease, KeyEventType.KeyDown, (GameTime gameTIme) =>
                {
                    mstsskyfogDistance = (float)MathHelperD.Clamp(mstsskyfogDistance - gameTIme.ElapsedGameTime.TotalSeconds * mstsskyfogDistance, 10, 100000);
                });
                viewer.UserCommandController.AddEvent(UserCommand.DebugFogDecrease, KeyEventType.KeyDown, (GameTime gameTIme) =>
                {
                    mstsskyfogDistance = (float)MathHelperD.Clamp(mstsskyfogDistance + gameTIme.ElapsedGameTime.TotalSeconds * mstsskyfogDistance, 10, 100000);
                });
            }
            // Don't let clock shift if multiplayer.
            if (!MPManager.IsMultiPlayer())
            {
                // Shift the clock forwards or backwards at 1h-per-second.
                viewer.UserCommandController.AddEvent(UserCommand.DebugClockForwards, KeyEventType.KeyDown, (GameTime gameTIme) =>
                {
                    MSTSSkyViewer.Simulator.ClockTime += gameTIme.ElapsedGameTime.TotalSeconds * 3600;
                });
                viewer.UserCommandController.AddEvent(UserCommand.DebugClockBackwards, KeyEventType.KeyDown, (GameTime gameTIme) =>
                {
                    MSTSSkyViewer.Simulator.ClockTime -= gameTIme.ElapsedGameTime.TotalSeconds * 3600;
                });
            }
            // Server needs to notify clients of weather changes.
            if (MPManager.IsServer())
            {
                viewer.UserCommandController.AddEvent(UserCommand.DebugOvercastIncrease, KeyEventType.KeyReleased, SendMultiPlayerSkyChangeNotification);
                viewer.UserCommandController.AddEvent(UserCommand.DebugOvercastDecrease, KeyEventType.KeyReleased, SendMultiPlayerSkyChangeNotification);
                viewer.UserCommandController.AddEvent(UserCommand.DebugFogIncrease, KeyEventType.KeyReleased, SendMultiPlayerSkyChangeNotification);
                viewer.UserCommandController.AddEvent(UserCommand.DebugFogDecrease, KeyEventType.KeyReleased, SendMultiPlayerSkyChangeNotification);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Used to update information affecting the SkyMesh
        /// </summary>
        public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
        {
            // Adjust dome position so the bottom edge is not visible
            Vector3 ViewerXNAPosition   = new Vector3(MSTSSkyViewer.Camera.Location.X, MSTSSkyViewer.Camera.Location.Y - 100, -MSTSSkyViewer.Camera.Location.Z);
            Matrix  XNASkyWorldLocation = Matrix.CreateTranslation(ViewerXNAPosition);

            if (mstsskyworldLoc == null)
            {
                // First time around, initialize the following items:
                mstsskyworldLoc     = new WorldLatLon();
                mstsskyoldClockTime = MSTSSkyViewer.Simulator.ClockTime % 86400;
                while (mstsskyoldClockTime < 0)
                {
                    mstsskyoldClockTime += 86400;
                }
                step1 = step2 = (int)(mstsskyoldClockTime / 1200);
                step2 = step2 < maxSteps - 1 ? step2 + 1 : 0; // limit to max. steps in case activity starts near midnight
                // Get the current latitude and longitude coordinates
                mstsskyworldLoc.ConvertWTC(MSTSSkyViewer.Camera.TileX, MSTSSkyViewer.Camera.TileZ, MSTSSkyViewer.Camera.Location, ref mstsskylatitude, ref mstsskylongitude);
                if (mstsskyseasonType != (int)MSTSSkyViewer.Simulator.Season)
                {
                    mstsskyseasonType = (int)MSTSSkyViewer.Simulator.Season;
                    date.ordinalDate  = mstsskylatitude >= 0 ? 82 + mstsskyseasonType * 91 : (82 + (mstsskyseasonType + 2) * 91) % 365;
                    // TODO: Set the following three externally from ORTS route files (future)
                    date.month = 1 + date.ordinalDate / 30;
                    date.day   = 21;
                    date.year  = 2017;
                }
                // Fill in the sun- and moon-position lookup tables
                for (int i = 0; i < maxSteps; i++)
                {
                    mstsskysolarPosArray[i] = SunMoonPos.SolarAngle(mstsskylatitude, mstsskylongitude, ((float)i / maxSteps), date);
                    mstsskylunarPosArray[i] = SunMoonPos.LunarAngle(mstsskylatitude, mstsskylongitude, ((float)i / maxSteps), date);
                }
                // Phase of the moon is generated at random
                mstsskymoonPhase = Viewer.Random.Next(8);
                if (mstsskymoonPhase == 6 && date.ordinalDate > 45 && date.ordinalDate < 330)
                {
                    mstsskymoonPhase = 3; // Moon dog only occurs in winter
                }
                // Overcast factor: 0.0=almost no clouds; 0.1=wispy clouds; 1.0=total overcast
                //mstsskyovercastFactor = MSTSSkyViewer.World.WeatherControl.overcastFactor;
                mstsskyfogDistance = MSTSSkyViewer.Simulator.Weather.FogDistance;
            }

            MPManager manager = MPManager.Instance();

            if (MPManager.IsClient() && manager.weatherChanged)
            {
                //received message about weather change
                if (manager.overcastFactor >= 0)
                {
                    mstsskyovercastFactor = manager.overcastFactor;
                }

                //received message about weather change
                if (manager.fogDistance > 0)
                {
                    mstsskyfogDistance = manager.fogDistance;
                }

                if (manager.overcastFactor >= 0 || manager.fogDistance > 0)
                {
                    manager.weatherChanged = false;
                    manager.overcastFactor = -1;
                    manager.fogDistance    = -1;
                }
            }

            ////////////////////// T E M P O R A R Y ///////////////////////////

            // The following keyboard commands are used for viewing sky and weather effects in "demo" mode.
            // Control- and Control+ for overcast, Shift- and Shift+ for fog and - and + for time.

            // Don't let multiplayer clients adjust the weather.
            if (!MPManager.IsClient())
            {
                // Overcast ranges from 0 (completely clear) to 1 (completely overcast).
                if (UserInput.IsDown(UserCommand.DebugOvercastIncrease))
                {
                    mstsskyovercastFactor = MathHelper.Clamp(mstsskyovercastFactor + elapsedTime.RealSeconds / 10, 0, 1);
                }
                if (UserInput.IsDown(UserCommand.DebugOvercastDecrease))
                {
                    mstsskyovercastFactor = MathHelper.Clamp(mstsskyovercastFactor - elapsedTime.RealSeconds / 10, 0, 1);
                }
                // Fog ranges from 10m (can't see anything) to 100km (clear arctic conditions).
                if (UserInput.IsDown(UserCommand.DebugFogIncrease))
                {
                    mstsskyfogDistance = MathHelper.Clamp(mstsskyfogDistance - elapsedTime.RealSeconds * mstsskyfogDistance, 10, 100000);
                }
                if (UserInput.IsDown(UserCommand.DebugFogDecrease))
                {
                    mstsskyfogDistance = MathHelper.Clamp(mstsskyfogDistance + elapsedTime.RealSeconds * mstsskyfogDistance, 10, 100000);
                }
            }
            // Don't let clock shift if multiplayer.
            if (!MPManager.IsMultiPlayer())
            {
                // Shift the clock forwards or backwards at 1h-per-second.
                if (UserInput.IsDown(UserCommand.DebugClockForwards))
                {
                    MSTSSkyViewer.Simulator.ClockTime += elapsedTime.RealSeconds * 3600;
                }
                if (UserInput.IsDown(UserCommand.DebugClockBackwards))
                {
                    MSTSSkyViewer.Simulator.ClockTime -= elapsedTime.RealSeconds * 3600;
                }
            }
            // Server needs to notify clients of weather changes.
            if (MPManager.IsServer())
            {
                if (UserInput.IsReleased(UserCommand.DebugOvercastIncrease) || UserInput.IsReleased(UserCommand.DebugOvercastDecrease) || UserInput.IsReleased(UserCommand.DebugFogIncrease) || UserInput.IsReleased(UserCommand.DebugFogDecrease))
                {
                    manager.SetEnvInfo(mstsskyovercastFactor, mstsskyfogDistance);
                    MPManager.Notify(new MSGWeather(-1, mstsskyovercastFactor, -1, mstsskyfogDistance).ToString());
                }
            }

            ////////////////////////////////////////////////////////////////////

            // Current solar and lunar position are calculated by interpolation in the lookup arrays.
            // Using the Lerp() function, so need to calculate the in-between differential
            float diff = (float)(MSTSSkyViewer.Simulator.ClockTime - mstsskyoldClockTime) / 1200;

            // The rest of this increments/decrements the array indices and checks for overshoot/undershoot.
            if (MSTSSkyViewer.Simulator.ClockTime >= (mstsskyoldClockTime + 1200)) // Plus key, or normal forward in time
            {
                step1++;
                step2++;
                mstsskyoldClockTime = MSTSSkyViewer.Simulator.ClockTime;
                diff = 0;
                if (step2 >= maxSteps) // Midnight.
                {
                    step2 = 0;
                }
                if (step1 >= maxSteps) // Midnight.
                {
                    step1 = 0;
                }
            }
            if (MSTSSkyViewer.Simulator.ClockTime <= (mstsskyoldClockTime - 1200)) // Minus key
            {
                step1--;
                step2--;
                mstsskyoldClockTime = MSTSSkyViewer.Simulator.ClockTime;
                diff = 0;
                if (step1 < 0) // Midnight.
                {
                    step1 = maxSteps - 1;
                }
                if (step2 < 0) // Midnight.
                {
                    step2 = maxSteps - 1;
                }
            }


            mstsskysolarDirection.X = MathHelper.Lerp(mstsskysolarPosArray[step1].X, mstsskysolarPosArray[step2].X, diff);
            mstsskysolarDirection.Y = MathHelper.Lerp(mstsskysolarPosArray[step1].Y, mstsskysolarPosArray[step2].Y, diff);
            mstsskysolarDirection.Z = MathHelper.Lerp(mstsskysolarPosArray[step1].Z, mstsskysolarPosArray[step2].Z, diff);
            mstsskylunarDirection.X = MathHelper.Lerp(mstsskylunarPosArray[step1].X, mstsskylunarPosArray[step2].X, diff);
            mstsskylunarDirection.Y = MathHelper.Lerp(mstsskylunarPosArray[step1].Y, mstsskylunarPosArray[step2].Y, diff);
            mstsskylunarDirection.Z = MathHelper.Lerp(mstsskylunarPosArray[step1].Z, mstsskylunarPosArray[step2].Z, diff);

            frame.AddPrimitive(MSTSSkyMaterial, MSTSSkyMesh, RenderPrimitiveGroup.Sky, ref XNASkyWorldLocation);
        }
Beispiel #14
0
        public static void HandleUserInput()
        {
            //In Multiplayer, I maybe the helper, but I can request to be the controller
            // Horn and bell are managed by UpdateHornAndBell in MSTSLocomotive.cs
            if (UserInput.IsPressed(UserCommand.GameRequestControl))
            {
                MPManager.RequestControl();
            }

            if (UserInput.IsPressed(UserCommand.ControlPantograph2))
            {
                MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO2", (++PantoSecondCount) % 2)).ToString());
            }

            if (UserInput.IsPressed(UserCommand.ControlPantograph1))
            {
                MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO1", (++PantoFirstCount) % 2)).ToString());
            }

            if (UserInput.IsPressed(UserCommand.ControlPantograph4))
            {
                MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO4", (++PantoFourthCount) % 2)).ToString());
            }

            if (UserInput.IsPressed(UserCommand.ControlPantograph3))
            {
                MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO3", (++PantoThirdCount) % 2)).ToString());
            }

            if (UserInput.IsPressed(UserCommand.ControlWiper))
            {
                MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "WIPER", (++WiperCount) % 2)).ToString());
            }

            if (UserInput.IsPressed(UserCommand.ControlDoorLeft))
            {
                MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "DOORL", (++DoorLeftCount) % 2)).ToString());
            }

            if (UserInput.IsPressed(UserCommand.ControlDoorRight))
            {
                MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "DOORR", (++DoorRightCount) % 2)).ToString());
            }

            if (UserInput.IsPressed(UserCommand.ControlMirror))
            {
                MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "MIRRORS", (++MirrorsCount) % 2)).ToString());
            }

            if (UserInput.IsPressed(UserCommand.ControlHeadlightIncrease))
            {
                HeadLightCount++; if (HeadLightCount >= 3)
                {
                    HeadLightCount = 2;
                }
                MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", HeadLightCount)).ToString());
            }

            if (UserInput.IsPressed(UserCommand.ControlHeadlightDecrease))
            {
                HeadLightCount--; if (HeadLightCount < 0)
                {
                    HeadLightCount = 0;
                }
                MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", HeadLightCount)).ToString());
            }
        }
Beispiel #15
0
        public void AppendMessage(Keys[] newKeys, Keys[] oldKeys)
        {
#if false
            foreach (var k in keys)
            {
                if (k == Keys.Enter)
                {
                    this.Visible = false;
                    UserInput.ComposingMessage = false;
                }
                if (k == Keys.Back)
                {
                    if (Message.Text.Length <= 1)
                    {
                        Message.Text = "";
                    }
                    else
                    {
                        Message.Text = Message.Text.Remove(Message.Text.Length - 1);
                    }
                }
                else if (k == Keys.OemComma)
                {
                    Message.Text += ",";
                }
                else if (k == Keys.OemPeriod)
                {
                    Message.Text += ".";
                }
                else if (k == Keys.OemMinus)
                {
                    Message.Text += "-";
                }
                else if (k == Keys.OemQuestion)
                {
                    Message.Text += "?";
                }
                else if (k == Keys.OemQuotes)
                {
                    Message.Text += "\"";
                }
                else if (k == Keys.OemSemicolon)
                {
                    Message.Text += ";";
                }
                else if (k == Keys.OemPlus)
                {
                    Message.Text += "+";
                }
                else
                {
                    char c = (char)k;
                    if (char.IsLetterOrDigit(c))
                    {
                        Message.Text += char.ToLower(c);
                    }
                    if (c == ' ' || char.IsPunctuation(c))
                    {
                        Message.Text += c;
                    }
                }
            }
#endif
            EnterReceived = false;

            string input = Convert(newKeys);
            foreach (char x in input)
            {
                //process backspace
                if (x == '\b')
                {
                    if (Message.Text.Length >= 1)
                    {
                        Message.Text = Message.Text.Remove(Message.Text.Length - 1, 1);
                    }
                }
                else
                {
                    Message.Text += x;
                }
            }

            //we need to send message out
            if (EnterReceived == true)
            {
                string user = "";
                if (MPManager.Instance().lastSender == "") //server will broadcast the message to everyone
                {
                    user = MPManager.IsServer() ? string.Join("", MPManager.OnlineTrains.Players.Keys.Select((string k) => $"{k}\r")) + "0END" : "0Server\r0END";
                }

                int    index = Message.Text.IndexOf(':');
                string msg   = Message.Text;
                if (index > 0)
                {
                    msg = Message.Text.Remove(0, index + 1);
                    var onlinePlayers = Message.Text.Substring(0, index)
                                        .Split(',')
                                        .Select((string n) => n.Trim())
                                        .Where((string nt) => MPManager.OnlineTrains.Players.ContainsKey(nt))
                                        .Select((string nt) => $"{nt}\r");
                    string newUser = string.Join("", onlinePlayers);
                    if (newUser != "")
                    {
                        user = newUser;
                    }
                    user += "0END";
                }
                string msgText = new MSGText(MPManager.GetUserName(), user, msg).ToString();
                try
                {
                    MPManager.Notify(msgText);
                }
                catch { }
                finally
                {
                    Visible = false;
                    UserInput.ComposingMessage = false;
                    Message.Text = "";
                }
            }
        }
Beispiel #16
0
 private void SendMultiPlayerSkyChangeNotification()
 {
     MPManager.Instance().SetEnvInfo(mstsskyovercastFactor, mstsskyfogDistance);
     MPManager.Notify(new MSGWeather(-1, mstsskyovercastFactor, -1, mstsskyfogDistance).ToString());
 }
Beispiel #17
0
        public void Update(ElapsedTime elapsedTime)
        {
            if (MPManager.IsClient() && MPManager.Instance().weatherChanged)
            {
                // Multiplayer weather has changed so we need to update our state to match weather, overcastFactor, pricipitationIntensity and fogDistance.
                if (MPManager.Instance().weather >= 0 && MPManager.Instance().weather != (int)Viewer.Simulator.WeatherType)
                {
                    Viewer.Simulator.WeatherType = (Orts.Formats.Msts.WeatherType)MPManager.Instance().weather; UpdateWeatherParameters();
                }
                if (MPManager.Instance().overcastFactor >= 0)
                {
                    Weather.OvercastFactor = MPManager.Instance().overcastFactor;
                }
                if (MPManager.Instance().pricipitationIntensity >= 0)
                {
                    Weather.PricipitationIntensityPPSPM2 = MPManager.Instance().pricipitationIntensity; UpdateVolume();
                }
                if (MPManager.Instance().fogDistance >= 0)
                {
                    Weather.FogDistance = MPManager.Instance().fogDistance;
                }

                // Reset the message now that we've applied all the changes.
                try
                {
                    if ((MPManager.Instance().weather >= 0 && MPManager.Instance().weather != (int)Viewer.Simulator.WeatherType) || MPManager.Instance().overcastFactor >= 0 || MPManager.Instance().pricipitationIntensity >= 0 || MPManager.Instance().fogDistance >= 0)
                    {
                        MPManager.Instance().weatherChanged         = false;
                        MPManager.Instance().weather                = -1;
                        MPManager.Instance().overcastFactor         = -1;
                        MPManager.Instance().pricipitationIntensity = -1;
                        MPManager.Instance().fogDistance            = -1;
                    }
                }
                catch { }
            }

            if (!MPManager.IsClient())
            {
                // The user is able to change the weather for debugging. This will cycle through clear, rain and snow.
                if (UserInput.IsPressed(UserCommands.DebugWeatherChange))
                {
                    switch (Viewer.Simulator.WeatherType)
                    {
                    case Orts.Formats.Msts.WeatherType.Clear:
                        Viewer.Simulator.WeatherType = Orts.Formats.Msts.WeatherType.Rain;
                        break;

                    case Orts.Formats.Msts.WeatherType.Rain:
                        Viewer.Simulator.WeatherType = Orts.Formats.Msts.WeatherType.Snow;
                        break;

                    case Orts.Formats.Msts.WeatherType.Snow:
                        Viewer.Simulator.WeatherType = Orts.Formats.Msts.WeatherType.Clear;
                        break;
                    }
                    // block dynamic weather change after a manual weather change operation
                    weatherChangeOn = false;
                    if (dynamicWeather != null)
                    {
                        dynamicWeather.ResetWeatherTargets();
                    }
                    UpdateWeatherParameters();

                    // If we're a multiplayer server, send out the new weather to all clients.
                    if (MPManager.IsServer())
                    {
                        MPManager.Notify((new MSGWeather((int)Viewer.Simulator.WeatherType, -1, -1, -1)).ToString());
                    }
                }

                // Overcast ranges from 0 (completely clear) to 1 (completely overcast).
                if (UserInput.IsDown(UserCommands.DebugOvercastIncrease))
                {
                    Weather.OvercastFactor = MathHelper.Clamp(Weather.OvercastFactor + elapsedTime.RealSeconds / 10, 0, 1);
                    weatherChangeOn        = false;
                    if (dynamicWeather != null)
                    {
                        dynamicWeather.ORTSOvercast = -1;
                    }
                }
                if (UserInput.IsDown(UserCommands.DebugOvercastDecrease))
                {
                    Weather.OvercastFactor = MathHelper.Clamp(Weather.OvercastFactor - elapsedTime.RealSeconds / 10, 0, 1);
                    weatherChangeOn        = false;
                    if (dynamicWeather != null)
                    {
                        dynamicWeather.ORTSOvercast = -1;
                    }
                }

                // Pricipitation ranges from 0 to max PrecipitationViewer.MaxIntensityPPSPM2 if 32bit.
                // 16bit uses PrecipitationViewer.MaxIntensityPPSPM2_16
                if (Viewer.GraphicsDevice.GraphicsDeviceCapabilities.MaxVertexIndex > 0xFFFF) // 0xFFFF represents 65535 which is the max for 16bit devices.
                {
                    if (UserInput.IsDown(UserCommands.DebugPrecipitationIncrease))
                    {
                        Weather.PricipitationIntensityPPSPM2 = MathHelper.Clamp(Weather.PricipitationIntensityPPSPM2 * 1.05f, PrecipitationViewer.MinIntensityPPSPM2, PrecipitationViewer.MaxIntensityPPSPM2);
                        weatherChangeOn = false;
                        if (dynamicWeather != null)
                        {
                            dynamicWeather.ORTSPrecipitationIntensity = -1;
                        }
                    }
                    if (UserInput.IsDown(UserCommands.DebugPrecipitationDecrease))
                    {
                        Weather.PricipitationIntensityPPSPM2 = MathHelper.Clamp(Weather.PricipitationIntensityPPSPM2 / 1.05f, PrecipitationViewer.MinIntensityPPSPM2, PrecipitationViewer.MaxIntensityPPSPM2);
                        weatherChangeOn = false;
                        if (dynamicWeather != null)
                        {
                            dynamicWeather.ORTSPrecipitationIntensity = -1;
                        }
                    }
                    if (UserInput.IsDown(UserCommands.DebugPrecipitationIncrease) || UserInput.IsDown(UserCommands.DebugPrecipitationDecrease))
                    {
                        UpdateVolume();
                    }
                }
                else
                {
                    if (UserInput.IsDown(UserCommands.DebugPrecipitationIncrease))
                    {
                        Weather.PricipitationIntensityPPSPM2 = MathHelper.Clamp(Weather.PricipitationIntensityPPSPM2 * 1.05f, PrecipitationViewer.MinIntensityPPSPM2, PrecipitationViewer.MaxIntensityPPSPM2_16);
                        weatherChangeOn = false;
                        if (dynamicWeather != null)
                        {
                            dynamicWeather.ORTSPrecipitationIntensity = -1;
                        }
                    }
                    if (UserInput.IsDown(UserCommands.DebugPrecipitationDecrease))
                    {
                        Weather.PricipitationIntensityPPSPM2 = MathHelper.Clamp(Weather.PricipitationIntensityPPSPM2 / 1.05f, PrecipitationViewer.MinIntensityPPSPM2, PrecipitationViewer.MaxIntensityPPSPM2_16);
                        weatherChangeOn = false;
                        if (dynamicWeather != null)
                        {
                            dynamicWeather.ORTSPrecipitationIntensity = -1;
                        }
                    }
                    if (UserInput.IsDown(UserCommands.DebugPrecipitationIncrease) || UserInput.IsDown(UserCommands.DebugPrecipitationDecrease))
                    {
                        UpdateVolume();
                    }
                }
                // Fog ranges from 10m (can't see anything) to 100km (clear arctic conditions).
                if (UserInput.IsDown(UserCommands.DebugFogIncrease))
                {
                    Weather.FogDistance = MathHelper.Clamp(Weather.FogDistance - elapsedTime.RealSeconds * Weather.FogDistance, 10, 100000);
                    weatherChangeOn     = false;
                    if (dynamicWeather != null)
                    {
                        dynamicWeather.ORTSFog = -1;
                    }
                }
                if (UserInput.IsDown(UserCommands.DebugFogDecrease))
                {
                    Weather.FogDistance = MathHelper.Clamp(Weather.FogDistance + elapsedTime.RealSeconds * Weather.FogDistance, 10, 100000);
                    if (dynamicWeather != null)
                    {
                        dynamicWeather.ORTSFog = -1;
                    }
                    weatherChangeOn = false;
                }

                UpdateWind(elapsedTime);
            }

            if (!Orts.MultiPlayer.MPManager.IsMultiPlayer())
            {
                // Shift the clock forwards or backwards at 1h-per-second.
                if (UserInput.IsDown(UserCommands.DebugClockForwards))
                {
                    Viewer.Simulator.ClockTime += elapsedTime.RealSeconds * 3600;
                }
                if (UserInput.IsDown(UserCommands.DebugClockBackwards))
                {
                    Viewer.Simulator.ClockTime -= elapsedTime.RealSeconds * 3600;
                }
            }

            // If we're a multiplayer server, send out the new overcastFactor, pricipitationIntensity and fogDistance to all clients.
            if (MPManager.IsServer())
            {
                if (UserInput.IsReleased(UserCommands.DebugOvercastIncrease) || UserInput.IsReleased(UserCommands.DebugOvercastDecrease) ||
                    UserInput.IsReleased(UserCommands.DebugPrecipitationIncrease) || UserInput.IsReleased(UserCommands.DebugPrecipitationDecrease) ||
                    UserInput.IsReleased(UserCommands.DebugFogIncrease) || UserInput.IsReleased(UserCommands.DebugFogDecrease))
                {
                    MPManager.Instance().SetEnvInfo(Weather.OvercastFactor, Weather.FogDistance);
                    MPManager.Notify((new MSGWeather(-1, Weather.OvercastFactor, Weather.PricipitationIntensityPPSPM2, Weather.FogDistance)).ToString());
                }
            }
            if (Program.Simulator != null && Program.Simulator.ActivityRun != null && Program.Simulator.ActivityRun.triggeredEvent != null &&
                Program.Simulator.ActivityRun.triggeredEvent.ORTSWeatherChange != null)
            // Start a weather change sequence in activity mode
            {
                // if not yet weather changes, create the instance
                if (dynamicWeather == null)
                {
                    dynamicWeather = new DynamicWeather();
                }
                dynamicWeather.WeatherChange_Init(Program.Simulator.ActivityRun.triggeredEvent.ORTSWeatherChange, this);
                Program.Simulator.ActivityRun.triggeredEvent = null;
            }
            if (weatherChangeOn)
            // manage the weather change sequence
            {
                dynamicWeather.WeatherChange_Update(elapsedTime, this);
            }
        }
Beispiel #18
0
 private void Start()
 {
     playerHealthManager = GetComponentInParent <HealthManager>();
     playerMPManager     = GetComponentInParent <MPManager>();
 }