The International Simutrans Forum

 

Author Topic: [Patch] Cornering and weight limits - fully revised (Updated 10 Jan.)  (Read 12459 times)

0 Members and 1 Guest are viewing this topic.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
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 assets produced with this version of makeobj will be compatible with default Simutrans 100/101, and assets produced with the default makeobj will be compatible with Simutrans as patched, but assets 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 class (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 asset files (I call them feature stubs because, while the coding for the asset 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 passenger 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:

Code: [Select]
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 assets 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 class, 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 class) 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.
« Last Edit: January 10, 2009, 05:58:52 PM by jamespetts »

Offline isidoro

  • Devotee
  • *
  • Posts: 1129
Re: [Patch] Cornering and weight limits - fully revised
« Reply #1 on: January 06, 2009, 05:29:58 AM »
My God!  That's real hard work!  I like some of your patches more than others, but work is there for sure.  I'll try to look into them and see if I understand them.  I'm pretty bad at that, though...

Congrats!

Offline The Hood

  • Devotee
  • *
  • Posts: 2889
  • pak128.Britain developer
Re: [Patch] Cornering and weight limits - fully revised
« Reply #2 on: January 06, 2009, 09:19:43 AM »
Wow!  If this works the way I understand, then this adds quite a few nice options for the game.  Good work! 

I'm keen to add some of these new features into the next version of PakBritain (hopefully due for a release in a month or two).  I will add tilting properties to APT and Pendolino, and create two versions of the Voyager (standard non-tilting and tilting Super Voyager, maybe I will repaint the standard Voyager as a Midland Mainline Meridian or a Cross Country Voyager for easy identification).

The only thing I need to know is how to create a version of the exe with the patch applied (or how to get it).  I'm running Linux.  Can anyone help?

Offline Fabio

  • Devotee
  • Administrator
  • *
  • Posts: 2898
  • The Pak128 Guy
    • Visit me on Facebook
  • Languages: EN, IT, RO, FR
Re: [Patch] Cornering and weight limits - fully revised
« Reply #3 on: January 06, 2009, 10:53:35 AM »
Congrats, jamespetts!!!

a wonderful job!!!

Offline isidoro

  • Devotee
  • *
  • Posts: 1129
Re: [Patch] Cornering and weight limits - fully revised
« Reply #4 on: January 06, 2009, 03:34:00 PM »
The only thing I need to know is how to create a version of the exe with the patch applied (or how to get it).  I'm running Linux.  Can anyone help?

Easy:
  • Get the source code with a SVN client.
  • Compile it
  • Run it and try
  • Move to the trunk directory
  • Type patch -p0 < name_of_the_patch_file
  • Compile and run again

There are detailed directions on how to get and compile the code in this forum.

Offline colonyan

  • Devotee
  • *
  • Posts: 526
  • Full and Warm
Re: [Patch] Cornering and weight limits - fully revised
« Reply #5 on: January 06, 2009, 04:01:04 PM »
Tilting train! Awesome Juice! Wow....... Its getting exciting.
Now I seriously need to learn to compile...

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [Patch] Cornering and weight limits - fully revised
« Reply #6 on: January 06, 2009, 04:10:56 PM »
Tilting train! Awesome Juice! Wow....... Its getting exciting.
Now I seriously need to learn to compile...

Or persuade Prissi to add this feature to the main version so that there's a downloadable binary ;-)

Offline Ashley

  • Coder/Patcher
  • Devotee
  • *
  • Posts: 1288
    • entropy.me.uk
Re: [Patch] Cornering and weight limits - fully revised
« Reply #7 on: January 06, 2009, 09:56:43 PM »
This is excellent work, I have long hoped for enforced weight limits, and the cornering/gradient stuff will make for much more realistic railways, cuttings and tunnels might suddenly become a lot more useful!

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [Patch] Cornering and weight limits - fully revised
« Reply #8 on: January 06, 2009, 11:01:33 PM »
This is excellent work, I have long hoped for enforced weight limits, and the cornering/gradient stuff will make for much more realistic railways, cuttings and tunnels might suddenly become a lot more useful!

As hopefully will the lighter weight but less powerful locomotives that aren't overweight for the cheaper/earlier tunnels/bridges ;-)

Offline whoami

  • Devotees (Inactive)
  • *
  • Posts: 693
Re: [Patch] Cornering and weight limits - fully revised
« Reply #9 on: January 07, 2009, 10:03:23 PM »
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.
I have been looking forward to this, because it should make the behaviour of trains far more realistic.
Will the pathfinding code take the new limitations into account?

Many people - who didn't care about too many narrow curves in their track layout - will be in for a surprise. ;-) The waybuilder seems to have improved a lot (and the preview also helps), but it still builds unnecessary 90° bends and detours in certain cases. However, this is no reason to not use the patch.

Quote
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.
Also highly appreciated.

Quote
3. Weight limits are now enforced.
I am not sure about this part. Serious overweight normally means: must not pass at all. For trains (in RL), empty waggons need to be inserted. If the slowdown is really so steep, the pathfinding has to handle the limiting tiles properly.

Quote
Tilting trains can take corners faster than non-tilting trains.
By how much do you increase the speed limit? Sources say 30% maximum speed gain, but I guess this only applies to low speeds. A fixed difference might be more realistic. Tilting is also not allowed on all types of curves - they have to be rather smooth (long and with constant curve radius, with curve radius changing slowly, to allow the tilting angle to be adjusted over time).

Quote
Tilting trains are indicated as such in the depot window with the words, "This is a tilting vehicle".
This string takes a litte too much space - maybe just put "(Tilting)" behind the engine type.

Edit: correcting myself
« Last Edit: January 08, 2009, 04:17:45 AM by whoami »

Offline The Hood

  • Devotee
  • *
  • Posts: 2889
  • pak128.Britain developer
Re: [Patch] Cornering and weight limits - fully revised
« Reply #10 on: January 07, 2009, 10:46:49 PM »
OK, trying to apply this patch to sourcecode but it all fails :s  Probably because I don't have the first idea about how to apply a patch (should really stick to drawing things but curiosity got the better of me!).  I've downloaded the patches and put them in the trunk folder, then run:

patch -p0 < cornering_and_weight_limits.patch

but I keep getting messages like:

patching file bauer/brueckenbauer.cc
Hunk #1 FAILED at 502.
1 out of 1 hunk FAILED -- saving rejects to file bauer/brueckenbauer.cc.rej

What's going on?  I've checked the code at those lines and it looks like it should find a match!

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [Patch] Cornering and weight limits - fully revised
« Reply #11 on: January 07, 2009, 11:03:15 PM »
I have been looking forward to this, because it should make the behaviour of trains far more realistic.
Will the pathfinding code take the new limitations into account?

The old code did slow trains quite a bit in any event. I have not altered the pathfinding, because there was already a penalty for corners built in (the pathfinding does not distinguish between corners of different angles, and it would be extremely hard to change that). Since slow trains are now slowed less by corners, and fast trains slowed more, the overall average I should have thought would be the same, and no change to the pathfinding needed. If it is found that corners are, overall, more of a penalty than they used to be, it would be easy to increase the cost per corner given by the pathfinding engine.

Quote
I am not sure about this part. Serious overweight normally means: must not pass at all. For trains (in RL), empty waggons need to be inserted. If the slowdown is really so steep, the pathfinding has to handle the limiting tiles properly.

I did consider this part carefully. I decided to use the speed limit reduction because of some comments that some people made here about people possibly being confused by why their vehicle would not route. Certainly, it would be very hard for player (especially a new player) to diagnose a "no route" when the only reason for the refusal is that one of the vehicles in a train is too heavy for a single tile of old track with a low weight limit hidden behind a tree somewhere. The new behaviour was intended to penalise excess weight (a reduction in speed by a factor of 10 is a significant penalty, I think, especially when considering the effects on other traffic on the line), and be at least partly realistic: weight limits often go with speed limits for heavier vehicles that do not apply to lighter vehicles. It is not exactly realistic (or else it would be a weight limit by axle, and the heavier the weight, the higher the maintenance cost for track/road, etc.), but it works in gameplay terms: the yellow message telling players that their vehicles are overweight makes it very clear why it is going so very slowly.


Quote
By how much do you increase the speed limit? Sources say 30% maximum speed gain, but I guess this only applies to low speeds. A fixed difference might be more realistic. Tilting is also not allowed on all types of curves - they have to be rather smooth (long and with constant curve radius).


That is useful information about the particular type of corner. The way that I have it coded now, there is a limit adjustment factor by which the speed limit is multiplied based on the normal speed limit of the track, and some values read from simuconf.tab (see the original post). If the vehicle is tilting, 0.15 is added to that factor so that, if, for example, the factor was 0.75 (i.e., a 25% reduction in speed), a tilting train would return a factor of 0.85 (i.e., only a 15% reduction in speed). It could easily be made such that the tilting bonus applies only if the immediate corner is no more than 45 degrees. I could also change the mathematics to give a 30% increase in speed limit instead of adding 0.15 to the factor (checking, of course, that the modified speed limit is not lower than the existing track limit). That real-life information is most useful.

Quote
This string takes a litte too much space - maybe just put "(Tilting)" behind the engine type.

That would be easy to change - what do other people think?

Offline whoami

  • Devotees (Inactive)
  • *
  • Posts: 693
Re: [Patch] Cornering and weight limits - fully revised
« Reply #12 on: January 08, 2009, 04:26:43 AM »
(I corrected one part of my post regarding tilting: instead of a constant curve radius - leading to a constant tilting angle - the curve has to reduce its curve radius to the minimum, and then increase it, optimally at a rate that allows the tilting angle to adjust smoothly; but I don't think this needs to be covered in the ST representation.)

I have not altered the pathfinding, because there was already a penalty for corners built in (the pathfinding does not distinguish between corners of different angles, and it would be extremely hard to change that).
Hmm, that's a pity: changing that would be useful for the proposed patch, and for realistic behaviour at switching areas - trains take unrealistic 90° curves far too often IMO.
« Last Edit: January 08, 2009, 04:31:29 AM by whoami »

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [Patch] Cornering and weight limits - fully revised
« Reply #13 on: January 08, 2009, 11:42:09 AM »
Whoami,

perhaps just increasing the overall cost assigned to corners in the routing engine would suffice for that purpose? A 90 degree bend is interpreted by the game as about three 45 degree bends immediately next to each other (although, so is a 45 degree bend...), so an increase in the cost of cornering should have at least some deterrent effect on excessive switching from line to line.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [Patch] Cornering and weight limits - fully revised (New version 10 Jan.)
« Reply #14 on: January 10, 2009, 05:29:30 PM »
Attached is a new and slightly revised version of this patch. It incorporates the supplementary patch posted in the original post on this thread, so there is no need to apply two patches. I have taken into account some of the feedback from Whoami, and increased the effectiveness of tilting trains, but made them check for a moderate corner before they work properly (I have not fully tested that part: if the test is not rigorous enough, it could be made stricter, but then it would be very strict indeed and allow tilting only on the gentlest of corners (i.e., no bends in any different direction anywhere near the corner)). I have also cleaned the code a little and removed some redundant and commented out sections.

I have not changed the "this is a tilting vehicle" indication, however, since, as the phrase gets a line to itself, there is no problem with space: it fits exactly in the depot window. Just "tilting" is potentially more confusing, at least to some, and there is no advantage of shortening it.

I had mistakenly remembered how the system for assessing the cost of a route calculates the cost of a corner. It does not, as I thought initially when I replied to Whoami's post, have a specific function for checking whether there is a corner (indeed, one would be very hard to write), but it prefers shorter routes, which have, of necessity, fewer corners. It is not, therefore, possible to tweak the level of preferences, but players can, of course, simply set waypoints to customise their routes - for railways, where corners have the greatest effect, there is very unlikely in any event to be a better route overall that the wayfinder does not find.

Offline Fabio

  • Devotee
  • Administrator
  • *
  • Posts: 2898
  • The Pak128 Guy
    • Visit me on Facebook
  • Languages: EN, IT, RO, FR
ONE QUESTION ABOUT WEIGHTS
« Reply #15 on: January 15, 2009, 02:56:54 PM »
An important question:
does the max weight include ALSO the loaded freight?
i guess so, but i need to check

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [Patch] Cornering and weight limits - fully revised (Updated 10 Jan.)
« Reply #16 on: January 15, 2009, 07:15:51 PM »
Yes - I obtain the weight from the method that calculates the total weight of the vehicle, including the loaded cargo.