I just figured out why the concept of realistic train management was giving me trouble. I really hadn’t tried to figure it out in any detail before and as soon as I did, the problems became obvious.
A real railroad can do things that would be considered micro-management in a game. I don’t want a player to drive the train to the shop to pick up a new car and then deliver it, as a special consist, to some new location where it can then be part of a regular schedule. That’s just a pain-in-the-ass that a real railroad operator would pass on to some minion. The most amount of micro-management that I want for my game is at the level of the player making sure that the train has a schedule where it needs to take empty cars back to the place where they become full cars again.
Without special trains to do this, how do I let the player buy a new car for an existing or new industry and have it show up at the right location without screwing up the rest of the game? More importantly, how do I penalize the player if they decide to just buy new rolling stock instead of managing the existing set? There will be a cost associated with buying a car and a cost associated with placing it, by magic, at a specific location. It will always be cheaper to properly manage a train than to do any of the magic stuff.
I will let the player buy or sell rolling stock at any time and make them pay to place it the magic way at any location. They can even stick the new car into a train at any time as long as the penalty is paid. That way, a train that never uncouples its cars can still get a new one without having to do any special operation. A train that picks up cars at a siding will just deal with there being more cars than before. If that same train does some switching, I’ll need to make sure that the switching is done based on the type of cars in the train and not on an indexed position within the train.
It might all just work.
The train scheduling will need to have some interesting commands or instructions. Things like “go to x location and pick up all cars” should be do-able as long as the game can figure out to keep backing up the train (or driving forwards of course) until something make the game realize that there are no more cars to pick up. Getting to the end of a siding would cause the train to stop and change to the next instruction but what about cars parked on the main line?
This will take a little more thought but I can probably start writing the code to handle this and the first issue and then add more later when the instructions are obviously not complex enough. Or maybe I can detect when a new car is added at some location and change the player instructions to accommodate it. What I don’t want is to make the instructions so detailed that the whole train schedule needs to be changed manually if a car is added to the game while the player has been playing for a while. After all, this needs to be a game, not a full on simulation.
Note to Self
I want to make a note here that the train can automatically slow down to reach a given speed at a given location by determining the distance needed to make the change if the acceleration is known. In other words, if we know how much breaking we are going to do as an acceleration value (negative for braking of course) then we can figure out when to start slowing down. Here is the equation:
distance_needed = ( known_final_velocity^2 – known_current_velocity^2 ) / ( 2 * known_acceleration )
I need to figure out how to pick an acceleration value for the equation. For a train that is speeding up, the acceleration is determined by the amount of force that can be applied and the weight of the train. Maybe I can just use the same equation and make some guesses at how much force is applied using the brakes. I’ll give it some more thought.
Oh, and here’s an example of the above equation with some actual numbers.
known_acceleration = -4m/s^2
78.125 = ( 0 – 25^2 ) / ( 2 * -4 )
At that known acceleration value, it would take the train 78.125 meters to stop if it was traveling at 25 meters per second.
I wonder if I can apply the -.004 acceleration value per millisecond and still reach zero in that exact distance. I should have worked harder at math when I was younger. It seems like it will work fine because the acceleration is constant for this equation.