Patch: Railroad Track Limit by Using Named Waypoint

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
Coala17
Engineer
Engineer
Posts: 1
Joined: 06 Sep 2015 03:48

Patch: Railroad Track Limit by Using Named Waypoint

Post by Coala17 »

This patch will give a way how to limit a railroad speed for more reality.

It is useful to make a railroad track which both slower and faster train passes.
for example, in Korea, express train whose max speed is 300km/h and normal train whose max speed is 150km/h meet some common tracks.
but the track limits all trains under 150km/h. It is unrealistic that any express train passes a major station over 200km/h.

Furthermore, because of using waypoint, it has NO SIDE EFFECTS.
that is, it is like a feature in a old patch pack, Chill's patch pack ( http://www.tt-forums.net/viewtopic.php?t=47622 )
However, it used a signal, so it has some side effects when I use both the speed limit signal and PBS signal.

USAGE:
You should change a waypoint's name to "[SpeedLimit(km/h)][Underbar][Any Name]"
for example: "60_mywaypoint" is 60km/h limit.

Image

I attached a diff patch file based stable 1.5.2 version and Win64 binary file.
(Savefile will be compatible because of save format is not changed.)

Any bugs or any suggestion will be welcome !
Attachments
TrainSpeedPatch.patch
Patch File
(2.31 KiB) Downloaded 162 times
1.5.2-KHJR.zip
Win64 Binary
(9.09 MiB) Downloaded 118 times
Telk
Engineer
Engineer
Posts: 64
Joined: 05 May 2008 14:04
Location: Seoul, South Korea
Contact:

Re: Patch: Railroad Track Limit by Using Named Waypoint

Post by Telk »

It is great to see you here, coala lol, Nice job.
여기서 뵈니 기쁘네요 알라 님ㅋ 훌륭하네요.
Image
- OpenTTD/OpenRCT2/Parkitect Korean Translator
- TELKLAND site manager, the korean website of OpenRCT2/OpenTTD (https://telk.kr)
User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: Patch: Railroad Track Limit by Using Named Waypoint

Post by HackaLittleBit »

Nice!

I hope you don't mind but I could not resist rewriting some of your code.
There are very strict rules for writing code in OTTD.
see coding style

Code: Select all

if (prev == NULL && gp.new_tile != gp.old_tile && IsRailWaypointTile(gp.new_tile)) {
	int speed = 0;
	Waypoint *wp = Waypoint::GetByTile(gp.new_tile);
	if (wp->name != NULL) {
		for (uint32 i = 0; i < strlen(wp->name); i++) {
			if (wp->name[i] == '_' && speed > 0) {
				v->current_order.SetMaxSpeed((uint16)speed);
				break;
			}
			if (wp->name[i] < '0' || wp->name[i] > '9') {
				break;
			}
			speed *= 10;
			speed += (wp->name[i] - '0');
		}							
	}
	if (speed == 0) v->current_order.SetMaxSpeed(UINT16_MAX);
}

Also I advise you to check your patch file for errors before you send it.(white space etc.)
The location of this code should most probably be in the end part of the TrainController function.
See AffectSpeedByZChange

P.S Code was not really tested.
I have no time at the moment.:-(

Success
chester00
Engineer
Engineer
Posts: 16
Joined: 21 Jan 2011 11:24

Re: Patch: Railroad Track Limit by Using Named Waypoint

Post by chester00 »

I´ve tested your code and it seems to work properly.
So it´s a nice addition to NuTracks and the game is way more realistic now.
Clemo56
Engineer
Engineer
Posts: 16
Joined: 13 Aug 2015 09:47

Re: Patch: Railroad Track Limit by Using Named Waypoint

Post by Clemo56 »

I've always limited my trains using waypoints and speed limits in the timetableing feature which is easy enough but does require a bit of time, particularly if i want to chance the speed limit on a particular section of track that already has a number of trains running.
Looking forward to trying this out at some point.

My suggestion for improvement is to remove the need for waypoints at all. The user could activate a visualisation of speed limits using a button in the rail construction menu, to apply a speed limit the user can select the speed then click and drag over a section of track. For the visualisation a color can be calculated based on the logic that the highest speed limit in the network is deep red and the slowest is deep green, the generated color would be selected appropriately from the spectum in between and this color will be overlayed over the track when the speed limits data view is on, clicking on a section of track while in the speed limit view will bring up a window that will allow the user to fine tune the limit asigned to the particular section.
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Patch: Railroad Track Limit by Using Named Waypoint

Post by Eddi »

You can use NuTracks for speed limits, if you do not want to use waypoints.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 30 guests