Patch: Speed Limits

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
Sug
Engineer
Engineer
Posts: 16
Joined: 10 Jan 2007 19:35

Patch: Speed Limits

Post by Sug »

I thought being able to set speed limits for sections of track would be a nice addition, so I had a go.
I have used richk67's route marker sprites for testing purposes, obviously a new set of sprites will be needed and I will have a go at drawing these later.

When you place a sign it gets the lowest speed limit (15mph), each subsequent click increase the limit until the last sign which has no speed limit. I decided on the following speeds for now:

15, 25, 30, 40, 60, 100 and 125mph

New version allows you to set your own speeds in the config, speed_limit_1 -- 7 in km/h.

Edit: new version of patch uploaded, and new grf: speedsigns.grf

r10115 uploaded, reduced the number of limits down to 6 + no_max. So it now only uses 3 bits, no point wasting a bit for 1 more value.
Attachments
Speedlimits.png
Screenshot showing a 60mph speed limit through a station.
(118.69 KiB) Downloaded 560 times
SpeedLimitsWIP_r10115v2.diff
Speed Limits Patch Rev 10115
(22.74 KiB) Downloaded 225 times
speedsign.grf
speedsign.grf
(779 Bytes) Downloaded 265 times
Last edited by Sug on 14 Jun 2007 15:34, edited 3 times in total.
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Post by richk67 »

I have no problem with use of the .grf. You are welcome to either link to it, or repost it here. If you want some alternatives, check out the original Speed Signs patch thread. (You'll have to search for it.)
OTTD NewGRF_ports. Add an airport design via newgrf.Superceded by Yexo's NewGrf Airports 2
Want to organise your trains? Try Routemarkers.
--- ==== --- === --- === ---
Firework Photography
Sug
Engineer
Engineer
Posts: 16
Joined: 10 Jan 2007 19:35

Post by Sug »

Thanks, Ill take a look at the speed signs patch. Just trying to get my head around some code at the moment.
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Post by richk67 »

Speed signs is very old - I like your idea much more. But a combination of your speed limits and the routemarkers patch could be very interesting indeed. I much prefer to code in train-sorting controls into the track itself, than to have to direct the trains using waypoints.
OTTD NewGRF_ports. Add an airport design via newgrf.Superceded by Yexo's NewGrf Airports 2
Want to organise your trains? Try Routemarkers.
--- ==== --- === --- === ---
Firework Photography
Sug
Engineer
Engineer
Posts: 16
Joined: 10 Jan 2007 19:35

Post by Sug »

New version uploaded, allowing user setting of speeds. Plus new sprites that look more like speed limits, shown below.
Attachments
Ginford Transport, 11th Mar 2007.png
(101.79 KiB) Downloaded 370 times
User avatar
bobingabout
Tycoon
Tycoon
Posts: 1850
Joined: 21 May 2005 15:10
Location: Hull, England

Post by bobingabout »

is this just to slow trains down, or do trains make a choice to choose the lane most suited to their speed?

EG, if you place 3 lanes, 1 of limit 300Mph, 1 of 150Mph and 1 of 100 Mph, would a 75Mph train take the 100Mph lane, a 125Mph train take the 150Mph lane, and a 200Mph train take the 300Mph lane?
JPG SUX!!! USE PNG!!!
There are times when JPG is useful, TTD screenshots is not one of them. Please use PNG instead.

[/url]
Sug
Engineer
Engineer
Posts: 16
Joined: 10 Jan 2007 19:35

Post by Sug »

As it is, the speed limits have no effect on path finding at all. So no you wouldn't get that behavior unless by a fluke.

Its just a blanket speed limit, that any train passing through will stick too. The main idea behind it was to improve flow on busy lines that have a mix of different speed trains, so instead of the faster trains constantly starting/stopping they would all follow each other at the same speed. Plus theres the realism side of slowing trains down for tight corners, or on approach to stations etc..

Actually, before starting on this patch I looked at trying to get a very old patch for yellow signals working on the current trunk. As the patch had the option of slowing trains that went through a yellow, also reducing the stop/start behavior. But a lot has changed since then and I don't know the code well enough, but I'm thinking of ways to add in another signal state, just not got anywhere yet.
User avatar
bobingabout
Tycoon
Tycoon
Posts: 1850
Joined: 21 May 2005 15:10
Location: Hull, England

Post by bobingabout »

here is a sugestion, simply add a path finding penalty option, indevidually to every speed limit, with more of a penalty on speeds slower than the train, and only slightly larger penalties on limits faster than the train, so it'll aim for 1 with its apropriate speedlimit.

something like this, number the limits 1 to 7

if the limit is slower, the train will see a penalty of 1500 - number * 100
if the limit is faster, the train will see a penalty of number * 100

why 1500? well, i originally thought of 1000, but if it was a fast train, and 6 was too low, then it'd see 1000-600=400, or 700, which would choose the slower track, where 1500-600=900, which is a higher penalty than 700.
if 2 limites were slower, it'd see 1500-400=1100 and 1500-500=1000, and take the faster of the 2 limits. if 2 limits were faster, it'd see 400 or 500, and take the slower of the 2 limits.

this assumes none of the tracks are busy, there is a penalty applied to signals, and trains and things like thats, a penalty difference of 100, or even 200 might not be large enough to force a train down its correct speed limit lane, and you might end of up with a slow train going down the fast lane. you should probably set up the formulae more like this:


lower limit = (15 - limitnumber) * mult
higher limit = limitnumber * mult
to get the example above, mult is 100, that way the player can set a penalty multiplier

although, multiplying every time the train sees a speed limit might become a bit CPU extensive. i supose once you get a number that works well, you could hardcode it into a bunch of 'if's?
Last edited by bobingabout on 18 Jun 2007 13:20, edited 1 time in total.
JPG SUX!!! USE PNG!!!
There are times when JPG is useful, TTD screenshots is not one of them. Please use PNG instead.

[/url]
Sug
Engineer
Engineer
Posts: 16
Joined: 10 Jan 2007 19:35

Post by Sug »

That's certainly something I can take a look at.
You have obviously put a bit of thought in to come up with some numbers, so thanks for that. I'll have a delve into the yapf code and see what's what.
User avatar
bobingabout
Tycoon
Tycoon
Posts: 1850
Joined: 21 May 2005 15:10
Location: Hull, England

Post by bobingabout »

well, like i said, the numbers might need changing, but it is a good starting point.
JPG SUX!!! USE PNG!!!
There are times when JPG is useful, TTD screenshots is not one of them. Please use PNG instead.

[/url]
User avatar
ostlandr
Chairman
Chairman
Posts: 882
Joined: 12 May 2007 01:09
Location: Northeastern USA

Post by ostlandr »

Pardon the crude American vernacular, but-

You guys rock!

It's a bit disconcerting watching a train running through zig-zag curves on a canyonside at 90 mph. :shock: I may need to add speed limits to stop these engineers from "whittlin'" (American railroad slang for trying to 'shave' (hence the term) time on a run by breaking speed limits.)

I really appreciate all the hard work that's being done by everybody here. I am trying to contribute myself- my current project is stats for pre-1920 road vehicles (50% complete) then I plan on jumping into creating the graphic sprites for them.
Who is John Galt?
User avatar
Elukka
Engineer
Engineer
Posts: 88
Joined: 20 Apr 2006 20:47

Post by Elukka »

It would be really, really awesome if you could make these affect the pathfinding in the way Bobingabout described. That would really make 4-track (or more!) mainlines work well.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 9 guests