TG:Logic/Wagon logic

There are many steps involved in getting a wagon loaded with goods at one end of a trip, and unloaded at the other end.

Purchasing
Wagons must be bought and delivered either by magic "truck" (aka slow teleport) or by a class-1 railroad passing through the region. (Another idea: specialized industry for wagon production, possibly player-made).

If purchased by magic truck, the wagons will appear after a longish period at an idle track (defined below) or a maintenance track (again, defined below). Maintenance tracks should be preferred and provide a mild speed bonus in delivery. Maintenance facilities would provide the maximum bonus and essentially halve the time of delivery (which should still be pretty slow, but not quite as slow).

If purchased from class-1 railroad, the wagons will be delivered from off-map to the pre-placed interchange track with random values on age, time to next maintenance overhaul, etc. (alternately, when purchasing, the class-1's fleet may be visible for the player to choose whether they want cheap busted wagons and repair them or expensive fully-repaired wagons). Time to deliver should be much better than by truck, making this the preferred method when available.

Assuming a specialized industry will exist, the time to deliver should be around the same as for delivery by slowest truck, but the resulting wagon should be in guaranteed top shape (after all, they just built it brand-new for you).

Normal Operation
In normal operation, a wagon must be delivered to an industry loading track where that industry has a contract that has been awarded to the current transport company to deliver a cargo that can be loaded into that wagon.

Once delivered, the wagon may need to wait to be loaded. Some industry addons can make the loading process near-instant, e.g. a coal loader at a coal mine can simply drop coal into a slowly-moving coal car passing underneath. In the absence of such an insta-loader, the wagon must wait until it's been loaded by hand. While waiting at an industry, the wagon does not need to be attached to an engine (in fact, it shouldn't be. Engines are expensive pieces of equipment to keep hanging around for days at a time).

Once full, an engine must pick up the wagon and then either deliver it to a classification yard to be attached to a longer train or deliver it to the destination industry's unloading track.

In the case of delivery to a classification yard, the wagon may travel to another classification yard (possibly more than one!) until finally being broken from the longer train and being delivered to the aforementioned unloading track.

In either case, once on the unloading track, the unloading process may again be either slow or fast, analogously with the loading.

Once empty, the cycle normally starts over again.

Cabooses/brake vans/FREDs
It must be possible for the player to require that cabooses/brake vans be attached to all trains that leave yard limits to provide braking power in early-age scenarios where not all wagons have self-brakes fitted.

Similarly, it must be possible to simulate the effects of running brakeless wagons without cabooses/brake vans -- trains should then overshoot red signals and potentially crash if speed limits are poorly chosen.

In modern days, the caboose/brake van is rendered unnecessary by the Flashing Read End Device (the FRED), which allows for simultaneous brake application from both ends of the train at the same time.

Idle Wagons
When not in use, a wagon will wait on a designated "idle wagons" track. While in this idle state, it may be picked up, as needed, by schedules specifying a requirement for wagons of this type (or able to carry one of the cargoes the wagon is good for).

It is possible for a long-idle wagon to become stored deep behind a queue of other idle wagons, at which point extracting it will require some shunting movements -- this must be handled automatically for the user. The user is encouraged to create multiple parallel shorter idle tracks instead of one long one.

If no idle tracks are available, classification tracks of yards may be used for this purpose. Wagons should not be taken too far for idling -- if no idle tracks are available within a small number of tiles but classification tracks are, use one of those.

Maintenance and Repairs
Wagons need periodic maintenance, and also have a chance of developing faults (e.g. hotbox (stuck with brakes on, leading to overheating of the axles)). If due for maintenance or faulty, a wagon must be broken out of its string and delivered to a designated maintenance track, where a crew will inspect and/or repair it.

While being maintained/repaired (a slow operation), a wagon does not need to be attached to an engine (and, as before, shouldn't be).

After maintenance/repair, the wagon can return to the pool of available wagons.

To speed up the maintenance/repair process, specialized facilities can be constructed by the player.