chronofanz / EnhancedDistrictServices

EnhancedDistrictServices mod for Cities Skylines, which allows more granular control of services and supply chains.
MIT License
8 stars 5 forks source link

Solution to compatibility issue of Real Time mod #74

Open HuangFuSL opened 3 years ago

HuangFuSL commented 3 years ago

As reported in Steam Community, this mod is partly incompatible with Real Time by dymanoid. Using both mods will cause warehouse and other industrial buildings not sending vehicles even if their storage is full. I've inspected the mechanism of Enhanced District Services mod by investigating the source code and adding outputs to log files. I think the problem is as follows:

In MatchOffersClosest() method in TransferManagerMod.cs, the expiry time of each offer is checked. If the offer is not expired, it's disabled. The related code is on line 276 of TransferManagerMod.cs:

TransferHistory.PurgeOldEvents(material);

PurgeOldEvents() method is defined in TransferHistory.cs (line 100 to line 120):

            public void PurgeOldEvents()
            {
                var timestamp = Singleton<SimulationManager>.instance.m_currentGameTime;
                var expiry = timestamp.AddDays(-MaterialEvents.MAX_TTL);

                foreach (var list in Events.Values)
                {
                    for (int i = 0; i < list.Count;)
                    {
                        if (list[i].TimeStamp < expiry)
                        {
                            list.RemoveAt(i);
                        }
                        else
                        {
                            i++;
                        }
                    }
                }
            }

Here, the expiry is set to 30 days later to the current game time, it DOES work in the original game as the time unit of the game time is day. But with Real Time mod installed, speed of the time flow is decreased and the unit of the game time is minute. It can be verified by inspecting the timestamp variable by adding the following code:

Logger.Log($"{timestamp}");

after the definition of the timestamp variable. The observed output is:

8/10/2021 9:17:58 PM: 8/8/2021 6:54:02 AM
8/10/2021 9:17:58 PM: 8/8/2021 6:54:02 AM
8/10/2021 9:17:58 PM: 8/8/2021 6:54:02 AM
...
8/10/2021 9:17:59 PM: 8/8/2021 6:54:05 AM
8/10/2021 9:17:59 PM: 8/8/2021 6:54:05 AM
8/10/2021 9:17:59 PM: 8/8/2021 6:54:05 AM

A possible solution is change the expiry time:

var expiry = timestamp.AddMinutes(-MaterialEvents.MAX_TTL);

After applying the modification and re-compiling the mod, the warehouses and industrial building will start releasing vehicles normally. But the side-effect is to be investigated.

CityGecko commented 3 years ago

@HuangFuSL - also thanks for your approach to solve ! Do you found any side effects in the meantime ? We are looking into reviving this mod with some fixes, Chronofanz granted access to the GitHub repo here and we have full access on the workshop object as well.

I could think here to add a "Beta" section in the option panel to switch this on/off for users, which like to take some risks :)

Thanks to share experience made so far and again, thanks for contribution.

HuangFuSL commented 3 years ago

@CityGecko It seems that the mod is living in harmony with other mods, and I've observed no side effects up to now.