The International Simutrans Forum

Development => Patches & Projects => Topic started by: jamespetts on December 23, 2008, 06:58:58 PM

Title: [Patch] Enforcing weight limits (Superseded)
Post by: jamespetts on December 23, 2008, 06:58:58 PM
Attached is a patch which enforces the "max_weight" property already found in waytype .dat files based on the loaded weight of the vehicle. It does not prevent an overweight vehicle from using a weight limited route, but simply makes the vehicle/train much slower (by a factor of 3 if it is within 10% of the limit, otherwise by a factor of 10) when passing over the weight limited route. It also displays a message next to the vehicle with a yellow background, stating, "Vehicle %s is too heavy for this route: speed limited.", where "%s" is the name of the vehicle.

Edit: I have now implemented weight limits in the GUI, so that weight limits for railway track and roads are visible: (1) as a tooltip in the purchasing menu; and (2) in the statistics box. A revised patch is attached. Note that the previous patch did not include a crucial file, and therefore would not have worked.

Also, I have noticed that, whilst a weight limit parameter is included for plain track and road, is it not, somewhat oddly, included for bridges or tunnels: it is for bridges, in particular, that weight limits are likely to be useful. I shall have to set about adding that to bridges, but that will involve a re-versioning of the pak files.

As ever, any feedback would be appreciated :-)

Edit: This patch is now superseded by the one that can be found here (http://forum.simutrans.com/index.php?topic=1157.0), which also incorporates the improvements to cornering.
Title: Re: [Patch] Enforcing weight limits
Post by: jbode on December 23, 2008, 09:41:05 PM
Quote from: jamespetts on December 23, 2008, 06:58:58 PM
Also, I have noticed that, whilst a weight limit parameter is included for plain track and road, is it not, somewhat oddly, included for bridges or tunnels: it is for bridges, in particular, that weight limits are likely to be useful. I shall have to set about adding that to bridges, but that will involve a re-versioning of the pak files.

... thats a side effect of thinking ... most of the time not thought of ;) , ugly isn't it?

SCNR ... - Jörg
Title: Re: [Patch] Enforcing weight limits
Post by: Fabio on December 24, 2008, 08:02:39 AM
Quote from: jamespetts on December 23, 2008, 06:58:58 PM
I shall have to set about adding that to bridges, but that will involve a re-versioning of the pak files.

What about setting weight limit = 0 or not indicated to unlimited? so this would imply changes only for the future packs, not for the pre-compiled ones.
Title: Re: [Patch] Enforcing weight limits
Post by: jamespetts on December 24, 2008, 09:07:16 AM
Quote from: fabio on December 24, 2008, 08:02:39 AM
What about setting weight limit = 0 or not indicated to unlimited? so this would imply changes only for the future packs, not for the pre-compiled ones.

The Paks will still need to be re-versioned, but the old paks will be able to be used: this is the standard way of doing things, which does involve, as you suggest, detecting if a pak is of an older version, and giving a default value (of 999 is the custom for weight limits).
Title: Re: [Patch] Enforcing weight limits
Post by: prissi on December 24, 2008, 10:34:04 AM
This must be enforced by the search function, otherwise trains would not go on non-limited track whioch is just parralel. Adjusting this is needed (and bridges) before inclusion.
Title: Re: [Patch] Enforcing weight limits
Post by: jamespetts on December 24, 2008, 12:34:16 PM
Quote from: prissi on December 24, 2008, 10:34:04 AM
This must be enforced by the search function, otherwise trains would not go on non-limited track whioch is just parralel. Adjusting this is needed (and bridges) before inclusion.

Ahh, interesting. It could be done manually with waypoints, but I suppose that that would be tedious and difficult for newer players. Where in the code is the part of the search algorithm that deals with electrification? If I found that, I could copy the code (although I would have to alter it to allow it on overweight track as a fallback).
Title: Re: [Patch] Enforcing weight limits
Post by: prissi on December 24, 2008, 09:26:15 PM
This is done by running the vehicle all over the track (can_go_this_tile or so in simvehicle.cc)
Title: Re: [Patch] Enforcing weight limits
Post by: jamespetts on December 25, 2008, 05:19:16 PM
Prissi,

thank you very much for your help. What I have done is use the waggon_t::gib_costen and automobile_t::gib_costen functions to dissuade the routing system from routing over weight limited track if the vehicle is overweight by adding a cost of 40 if the vehicle is overweight. That way, it will not refuse to route if the way is too heavy (intended, so as not to make it too difficult for players, who might get confused as to why the vehicle is not routing), but it will try to find other routes if it can. I thought that this was the simplest and computationally cheapest way of doing it. I have tested it, and it works: it will take a longer route over a hill instead of route over flat weight restricted track.

I will upload the patch once I have added weight restrictions for bridges and tunnels.
Title: Re: [Patch] Enforcing weight limits
Post by: z9999 on January 07, 2009, 09:41:47 AM
Sorry, a stupid question.

What is weight limits ?
A vehicle ? a convoi ? or on a tile ? - which means that if each vehicle's length is 8, sum of 2 vehicles.
Title: Re: [Patch] Enforcing weight limits
Post by: jamespetts on January 07, 2009, 10:42:14 AM
Weight limits are enforced per vehicle, since, in a convoy/train, the weight would be spread out over a number of axles. In real railways, weight limits are per axle...
Title: Re: [Patch] Enforcing weight limits
Post by: z9999 on January 07, 2009, 12:03:11 PM
Thanks, jamespetts. :)