Erabior / RouteManager

Mod for Railroader the game that adds basic automation for passenger routes
12 stars 5 forks source link

V2 - onApproachShortDist - unexpectedly changes RMMaxSpeed #61

Closed armyf35 closed 7 months ago

armyf35 commented 7 months ago

Another dev branch bug

On departure of a station the max speed is set to 5 MPH

So far I have had the issue occur multiple times, however this test was setup with a train in Sylva, enabling route mode and waiting until it arrived and then departed from Dillsboro.

It seems like https://github.com/Erabior/RouteManager/blob/138185b6c9adfbb749ec775ca9e6488c456830fb/v2/core/AutoEngineer.cs#L497 is the issue

I have modified the generalTransit function to include some extra logging

        private static void generalTransit(Car locomotive)
        {
            //Trace Function
            Logger.LogToDebug("ENTERED FUNCTION: generalTransit", Logger.logLevel.Trace);

            Logger.LogToDebug(String.Format("Locomotive {0} triggered General Transit.", locomotive.DisplayName), Logger.logLevel.Verbose);

            //Set AI Maximum speed
            //Track max speed takes precedence. 
            //ImplementFeature enhancement #30
            //LocoTelem.RMMaxSpeed[locomotive] = 100f;

            //Optimization of code. No need to repetitively spam the statemanager with data that is not changing.
            //Apply Updated Max Speed

            if (LocoTelem.initialSpeedSliderSet[locomotive] == false)
            {
                Logger.LogToDebug(String.Format("Locomotive {0} setting speed to default.", locomotive.DisplayName), Logger.logLevel.Verbose);
                StateManager.ApplyLocal(new AutoEngineerCommand(locomotive.id, AutoEngineerMode.Road, LocoTelem.locoTravelingEastWard[locomotive], 45, null));
                LocoTelem.initialSpeedSliderSet[locomotive] = true;
            }
            else
            {
                AutoEngineerPersistence persistence = new AutoEngineerPersistence(locomotive.KeyValueObject);
                Logger.LogToDebug(String.Format("Locomotive {0} setting speed to saved", locomotive.DisplayName), Logger.logLevel.Verbose);

                if (LocoTelem.locoTravelingEastWard[locomotive] != persistence.Orders.Forward || (int)LocoTelem.RMMaxSpeed[locomotive] != (int)persistence.Orders.MaxSpeedMph)
                {
                    StateManager.ApplyLocal(new AutoEngineerCommand(locomotive.id, AutoEngineerMode.Road, LocoTelem.locoTravelingEastWard[locomotive], (int)LocoTelem.RMMaxSpeed[locomotive], null));
                    Logger.LogToDebug(String.Format("Locomotive {0} setting speed to saved at {1}.", locomotive.DisplayName, (int)LocoTelem.RMMaxSpeed[locomotive]), Logger.logLevel.Verbose);
                }
            }

            //Trace Function
            Logger.LogToDebug("EXITING FUNCTION: generalTransit", Logger.logLevel.Trace);
        }

Log: Player.log Save: Save1.zip

AdamC1228 commented 7 months ago

Missed a line of code while implementing #30

AdamC1228 commented 7 months ago

Fixed with Pull request #62