Hacker News new | ask | show | jobs
by JamesTRexx 34 days ago
I made version 12.2 my programming hobby project. First time I tackled it years ago was to have it run at real time instead of the default fast pace (even with the day length patch). Worked great including a feature to really schedule routes and have working yards for vehicles to wait. But when I wanted to change internal mechanics to add other features I hit the spaghetti code wall several times (and the code after 12.2 is just more complex with every version bump).

Took a break from it for a while and picked it up again, this time by not doing anything much feature-wise but pulling the code apart and de-C++-ing it. Bit by bit building a categorised code tree with single functions per file, deconstructing classes to plain functions and data structs, with the goal to convert from C++ to clear C. And then one day consolidate code to have for instance the same diagonal road options as current train tracks.

Might be pointless and take a long time to finish, but it's comforting to turn something overly complex into simple, small pieces and also create a unique code formatting style to visualise elements of a line of code for easier reading. Another fun part is reading about data design and coming up with a custom data container to replace the std::vector uses.

1 comments

How fast do the trains and buses run on "real time" speed?

I suppose a 15 meter bus going 50km/h travels roughly its own length (13.40 meters to be exact) every second, so it takes 3 seconds to pass a grid square - checking out a YouTube video, it seems that's already the speed right now!

I calculated it long ago but I can't find the original notes. It can be extrapolated from the default 74 ticks a day (and the distance represented by 1 tile) to ((33 ticks per cpu second) * 86400) in my patch, and I think it came about a tile size of around 8 metres or so. Too long ago to be sure, but I found a time speedup of 4x compared to realtime was a good compromise. It made transport by slow vehicles viable to keep factories running, or a lot less were needed to keep up deliveries. The newer setting for minutes per tick made realtime possible eventually. I had it set to 11, I think.

It was also quite easy to limit production (or passengers) in the code from 06:00 to 20:00 a day for a little extra realism with either emptying a station during the night or have no traffic servicing buildings. Even weekends are possible. Warehouses would be a nice addition.