[Patch] Cornering and weight limits - fully revised (Updated 10 Jan.)
Attached is a patch (which I have been refining for some considerable time) dealing with cornering, weight limits and gradients. There are a number of different changes, but here is a brief executive summary:
Executive summary
1. Vehicles (other than ships) no longer have extra friction when turning a corner; instead, they have a lower speed limit, based on the speed limit of the way itself and the overall tightness of the bend over the last few tiles. The higher the speed limit, the more tiles that are taken into account. Now, a 45 degree corner can be taken faster than a 90 degree corner, which can be taken faster than a hairpin bend. Also, a 45 degree bend immediately following another 45 degree bend is treated as being almost as sharp as a 90 degree bend, whereas 45 degree bends many tiles apart are not. This is now fully configurable in simuconf.tab (sample file attached, including detailed documentation in the comments), which configuration includes an option of reverting to the original behaviour of additional friction on corners. Further, the configuration can be customised per way type (giving different cornering characteristics to trains, trams, road vehicles, monorails, maglevs and narrow gauge trains).
2. Vehicles travelling up hill have progressively more friction applied if they have to ascend consecutive tiles (up to a maximum of three). This incentivises smoothing gradients.
3. Weight limits are now enforced. If a vehicle travels on a way for which it is too heavy, its speed is very greatly restricted (either 1/3rd or 1/10th of the speed limit that would otherwise apply, depending on how overweight that it is), and the player gets a message (similar to the "no route" message, but in yellow) explaining why the vehicle is going so slowly. The weight limit for ways is now displayed in the menu bar when purchasing new ways, and also displayed in the information dialogue box when clicking on the way in question. Track already had weight limits (but were not enforced), but now tunnels and bridges also have weight limits, which are specified using the same keyword ("max_weight") in the .dat file as for track/roads. When searching for a route, vehicles will only select a route over a way for which they are overweight as a last resort, and will prefer detours over hills than using a weight restricted route for which they are overweight.
4. It is possible to have tilting trains (but not represented graphically). Tilting trains can take corners faster than non-tilting trains. Tilting trains are indicated as such in the depot window with the words, "This is a tilting vehicle". Pakset authors can specify a vehicle as tilting by using the new "is_tilting=1" parameter in any vehicle .dat file.
Notes
In order to be able to use the new features (weight limits for bridges and tunnels, and tilting trains), pakset authors must compile their .dat files using a version of makeobj compiled with the files that come with this patch. The ****ets produced with this version of makeobj will be compatible with default Simutrans 100/101, and ****ets produced with the default makeobj will be compatible with Simutrans as patched, but ****ets compiled using the default makeobj will not have the new features enabled even if the new features are specified in the .dat files.
These modifications have been tested, but not fully beta tested. As such, the patched game should be regarded as a beta release. Any bug reports or suggestions for refinement would be greatly appreciated. The cornering algorithms use a new fixed sorted list cl**** (fixed_list_tpl.h), which can be used anywhere else in Simutrans, or, indeed, for any other open source project. That data structure has been tested fairly thoroughly, and quite a number of bugs from earlier versions detected and removed.
There are, in addition to the completed features documented above, a number of feature stubs built into the new sub-version of the ****et files (I call them feature stubs because, while the coding for the ****et data is present, I have not yet written any code for them to have any effect in the game). Those feature stubs are: (1) a catering level for vehicles; and (2) way constraints. The catering level is quite simple: one can just specify "catering_level=x" (where x is any number between 0 and 255) in any vehicle file, and the code will be able to access a "catering_level" variable with that number for any vehicle type in the game. It is anticipated that this feature will be used to increase p****enger revenues if a convoy contains a vehicle with catering facilities, and the journey is of at least a particular length.
The second feature stub is way constraints: these are a little more complicated. In essence, they are two sets of on/off ("boolean") flags, one set called "permissive" and the other set called "prohibitive". They are present on vehicles, ways, way objects, tunnels and bridges. In any .dat file, they are specified by stipulating something like:
way_constraint_permissive[0]=0
way_constraint_permissive[1]=4
way_constraint_permissive[2]=5
way_constraint_prohibitive[0]=2
(where the number after the = sign must be between 0 and 7 (inclusive); any higher number, and the line will be ignored). They are intended for use as discussed here, but, as stated above, there is no code written yet to check for them in routing, and they are not referenced in the UI, either.
I have included the feature stubs here partly because separating them would be laborious, partly because I recall that somebody else expressed an interest in coding for catering (see here for details) but mainly because I wanted to release as many as possible changes to the data files all at once to minimise any possible problems with compatibility. Also, pakset authors can work now on updating their ****ets in time for the code to be released.
References to previous discussions
The following threads refer to discussions about the ideas put into effect in this patch, or previous versions of this patch.
* [Patch] New cornering algorithm - allows for tilting trains
* [Patch] Enforcing weight limits
* [Patch, newer exists] Check for tightness of railway curve?
* Diverse jamespetts questions
Versions and licence
As of the 5th of January, this is the latest version of any patch of mine relating to cornering, hill climbing and weight limits. I recommend that this be installed in preference to all earlier patches. Unfortunately, the effort to make trains slow in advance of speed limits was not successful, but the original cornering patch has been improved and made cleaner and more efficient as a result of attempts to add reading ahead. The patched code, including the new fixed sorted list cl****, is released under the Artistic Licence to be compatible with Simutrans. However, if anybody would like, I am willing to make any of the parts of code that I have written alone (such as the list cl****) available under the GPL, too.
This version is fully updated to take account of the new translation patches, and compiles with the latest nightly. I should very much appreciate any bug reports or suggestions for refinement.
Edit: In the original patch attached, I forgot to include some important files that are necessary in order to make the weight limits on bridges and tunnels work properly. I have attached a supplementary patch with the missing files. In order to make this work properly, both patches should be installed.
Edit 2: Note that a revised version of this patch, now incorporating the supplementary patch, is posted further along in this thread.