Another gamelength hack

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
coherently_olive
Engineer
Engineer
Posts: 14
Joined: 24 Apr 2015 17:16

Another gamelength hack

Post by coherently_olive »

After some time trying to both figure out other people's daylength patches and trying to write my own, I did not want to mess with OpenTTD's tick system any more. Here's a patch for everyone whose sole and only goal is to increase the time you have to set up a network without being overwhelmed with new engines and rail types far too quickly. This patch explicitly tries to invade as few of the game's tick mechanics as possible.

My solution to this problem is to touch neither the tick counter, nor the amount of ticks per day. Instead, I use the same code that OpenTTD uses to reset the year by one once MAX_YEAR + 1 has been reached. By doing so, every year of game-time is repeated a user-defined amount of times. This means that every feature of the game that works correctly in a game where MAX_YEAR has been reached, should probably work correctly with my patch. To solve the problem of engines aging too fast or being introduced "multiple times" because the introduction date is reached multiple times, a check is performed and engines are only aged or introduced in the last cycle of the respective year. Same for applying inflation.
Individual vehicles will still age one year "per cycle", and will need to be replaced accordingly. Preliminary testing has not revealed any problems with FIRS, 2cc trains, NuTracks, av8, FISH2 or automated timetable separation patch (though I don't remember which one of those I applied). I have not checked if the default ingame timetable works. I also have not checked if the patch works with the netcode. My uneducated guess would be that it doesn't. Although engine introduction dates work fine, I have not tested whether engine previews last the correct amount of time. Also, judging from the code, cargo aging should work (i.e. cargo should age in real-time), but I am not sure how to test if it actually does.

Known issues:
  1. The company performance graphs will retroactively show each cycle as a new year, so if you're in cycle 2 of 1950, cycle 1 will be displayed as 1949 etc.
  2. Running costs and maintenance costs of vehicles and infrastructure are displayed per cycle, not per whole year. I can live with this and won't fix it. The costs that are shown will be deducted from the account correctly (i.e. the shown costs are deducted every cycle).
  3. Every time you go into the main menu, the setting for cycles per year is reset to "1". This might be because the patch sets this setting to "1" when loading a pre-patch savegame, but I'm not sure. The setting and current cycle of the year is still stored and loaded correctly from savegames.
  4. Vehicles deliberately accumulate the profit of all cycles in the current year in their statistics, but they check if they made profit after every cycle of a year. This means that they still may complain about making losses after a cycle, even if they made profit. This happens when the accumulated losses of all cycles of the current year so far outweigh the accumulated profits. I'm not sure if I should change vehicles to accumulate only the profits of the current cycle or not, since this would in turn cause inconsistencies with the company profit statistics. On the other hand, having the vehicle check profit only after all cycles of a year have been completed might be the point of time where your network has been sneakily congested beyond redemption.
The attached patch should work when applied against svn r27242. Please tell me when it doesn't, so I can try to export the patch from my local repository correctly. I am happy to hear your opinion and / or suggestions.
year-cycles-r27242.patch
Cycling years patch, v0.1 against r27242
(15.71 KiB) Downloaded 44 times
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Another gamelength hack

Post by andythenorth »

FWIW, a long time ago Eddi gave me a near-identical patch with the same goals (was never made public).

Worked well for me with newgrf, no meaningful problems with any of the grfs I author, including FIRS. IIRC, it did trip up the 'new vehicle is available' mechanic a bit. :)
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: eboss128 and 50 guests