Replacing to different types of trains - almost done

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

CruDeLioS
Engineer
Engineer
Posts: 19
Joined: 13 Jan 2005 13:21

Replacing to different types of trains - almost done

Post by CruDeLioS »

I've done this so I can save the hassle of manually upgrading all my trains.

You can convert from any type to any type of train. As soon as trains are of different type they will be stopped at the depot and you cannot use them until you convert the depot.

I'm not posting the patch yet as it's still not ready. The replace train window is buggy (can anyone help me out on this? - things keep getting changed there, as if I was pressing the left mouse button uncontrollably - works well when game is paused though) and I still need to implement a feature to start moving the trains as soon as the depots have been converted.
Attachments
Linhill Transport, 21st Aug 2009.png
Linhill Transport, 21st Aug 2009.png (144.52 KiB) Viewed 3315 times
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

nice work even through that layout just broke my idea for the next layout, where you should be able to replace cars too (useful in newgrf where bigger better cars are invented)
The question is how we really want this and how it should look

as for the clicking issue, it would be nice if anybody gets an idea of why this could happen.
CruDeLioS
Engineer
Engineer
Posts: 19
Joined: 13 Jan 2005 13:21

Post by CruDeLioS »

Diff against rev 1578
Attachments
trainreplace.diff
(11.2 KiB) Downloaded 529 times
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

I'm still not sure about the GUI, I feel that it is made less simple than mine, but this is a minor issue.
I just looked through your code (didn't compile it) and it's pretty nice for the internal stuff, but I found one thing, that would become an issue: rail cars.
You would have say 5 coal cars and when you convert, you would have a monorail engine with 5 coal cars, not 5 monorail cars.

It seems network stable since you do your stuff from a command called by DoCommand. I don't know if you planned it like this or that you might just be lucky. Either case is good :wink:

you used TS_Front_Engine, which deserves a great bonus :P

Code: Select all

        if(WP(w,replaceveh_d).vehicletype != VEH_Train)
				  DrawString(145, (w->resize.step_height == 24 ? 67 : 77 ) + ( w->resize.step_height * w->vscroll.cap), STR_02BD, 0x10);
        else
				  DrawString(145, (w->resize.step_height == 24 ? 79 : 89 ) + ( w->resize.step_height * w->vscroll.cap), STR_02BD, 0x10);
the last one is for trains only, so why not just write 89 instead of (w->resize.step_height == 24 ? 79 : 89 )?
another solution would be

Code: Select all

DrawString(145, (w->resize.step_height == 24 ? 67 : 77 ) + (WP(w,replaceveh_d).vehicletype == VEH_Train ? 12 : 0) + ( w->resize.step_height * w->vscroll.cap), STR_02BD, 0x10);
this would show the same and keep the drawstring to just one line. Not that it's really important through. The line is long enough already so an if might be a good idea for readability

as for the feature..... hmmm ... it's not the best solution to have monorail train in a rail depot, but the only solution I can think of is to place two depots next to each other like a "bridge" between the railtypes and I don't know about that idea either

BTW try this on a laggy network. There might be a risk that the train actually leaves the depot and then gets converted :(
CruDeLioS
Engineer
Engineer
Posts: 19
Joined: 13 Jan 2005 13:21

Post by CruDeLioS »

I just looked through your code (didn't compile it) and it's pretty nice for the internal stuff, but I found one thing, that would become an issue: rail cars.
You would have say 5 coal cars and when you convert, you would have a monorail engine with 5 coal cars, not 5 monorail cars.

It seems network stable since you do your stuff from a command called by DoCommand. I don't know if you planned it like this or that you might just be lucky. Either case is good :wink:
I actually was expecting a segfault or something from railcars, but since they amazingly worked as expected, I didn't bother replacing them. Perhaps it shoud be done anyway.
you used TS_Front_Engine, which deserves a great bonus :P
Yes, before that there was a segfault or two. I'm still not too familiar with the code, and it is pretty lacking in comments, so most times I just have to guess...
the last one is for trains only, so why not just write 89 instead of (w->resize.step_height == 24 ? 79 : 89 )
I didn't know what it meant, so I simply left it.
BTW try this on a laggy network. There might be a risk that the train actually leaves the depot and then gets converted :(
I only took a glance at the network code and from what I understood, it sends the DoCommands or something... Is it like that? I can only imagine the nasty effects of having a train over the wrong railtype...

I have a suggestion but I'm not sure if it should be implemented. When someone chooses to convert a train to a different rail type, trains immediately go to the depots. Since you are probably only going to upgrade your trains like that when you're upgrading your rail network, waiting for each and every single one of them to be in the depots can take a while, especially if you don't allow automatic servicing, like me :wink:
User avatar
acidd_uk
Traffic Manager
Traffic Manager
Posts: 194
Joined: 08 Sep 2004 14:38

Post by acidd_uk »

CruDeLioS wrote:I have a suggestion but I'm not sure if it should be implemented. When someone chooses to convert a train to a different rail type, trains immediately go to the depots. Since you are probably only going to upgrade your trains like that when you're upgrading your rail network, waiting for each and every single one of them to be in the depots can take a while, especially if you don't allow automatic servicing, like me :wink:
This might not be desired all the time - you might want your trains to finish their current goods run before going to the depot. Maybe a separate button 'all of type go to depot' and/or 'all go to depot'?
JenovaUK
Engineer
Engineer
Posts: 127
Joined: 21 Apr 2004 14:05
Location: Central Scotland
Contact:

Post by JenovaUK »

Also, with Large Maps, people might build three or four separate networks. Would it be too much hassle to add a option where the user clicks on the track to be upgraded, it then finds all attached track, stations and depots, then starts the cycle.

We would also need a visual confirmation displaying the cost before we begin. It would be some hassle if the network upgrades okay, then you find out half way through updating the trains that you don't have enough cash to replace them all. >.<
mtlife
Engineer
Engineer
Posts: 19
Joined: 24 May 2005 15:53
Contact:

Post by mtlife »

is this thing still worked on or is it abandoned?
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

I can only talk for myself, but I might do something about this in 4-5 weeks if nobody have done it before that time. It's sad when you don't have time to code at all, but that's life :(
User avatar
acidd_uk
Traffic Manager
Traffic Manager
Posts: 194
Joined: 08 Sep 2004 14:38

Post by acidd_uk »

Yay, that would be cool... now to invent a time machine...
mtlife
Engineer
Engineer
Posts: 19
Joined: 24 May 2005 15:53
Contact:

Post by mtlife »

time to kick this topic again (i want to use this patch :P)
User avatar
bobingabout
Tycoon
Tycoon
Posts: 1850
Joined: 21 May 2005 15:10
Location: Hull, England

Post by bobingabout »

i've got to say, this is an awsome patch, would make converting railway-monorail-maglev worth it without spending several hours trying to replace several hundred trains.

only thing missing is a send all trains to depot button, you might not want to have to wait untill they all need sevicing.
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
ajy170
Transport Coordinator
Transport Coordinator
Posts: 270
Joined: 03 Oct 2004 08:25
Location: Australia

Post by ajy170 »

zg_01 wrote:Also, with Large Maps, people might build three or four separate networks. Would it be too much hassle to add a option where the user clicks on the track to be upgraded, it then finds all attached track, stations and depots, then starts the cycle.
I would like this as well as i have yet to advance to the level where i have an entire network thing going (i'm getting there though :D ). So this idea would be very helpfull to me, especially as i normaly only go monorail for passengers/mail, and leave the rest as rail, ignoring mag.
Anb
Engineer
Engineer
Posts: 1
Joined: 22 Jul 2005 09:22

Post by Anb »

(First post here :wink: )

I've managed to have this patch working with the latest nightly (r2661). If noone is on this, maybe I could try to code the stuff to send all trains to depot.

However, this patch sould allow you to (re)test the feature with the latest nightly. Nothing changed since the last diff posted here though.
Attachments
trainreplace_v2661.diff
train replace patch for r2661
(12.51 KiB) Downloaded 355 times
mtlife
Engineer
Engineer
Posts: 19
Joined: 24 May 2005 15:53
Contact:

Post by mtlife »

Anyone got a compiled win32 version for that patch? I would like to see it in a nightly soon :D
Splatman
Engineer
Engineer
Posts: 31
Joined: 31 Jul 2005 16:08
Location: United Kingdom

Post by Splatman »

Slight problem with adding this patch to newer revisions, the patch made use of a bug that let you build the wrong type of train in a depot (i.e. you could build a maglev in a noraml railway depot), this bug was fixed when they added the clone vehicle patch. It may be possible to rewrite the patch to work by putting the bug back in. Failing that would it be possible to join different depot types together similar to stations?
User avatar
bobingabout
Tycoon
Tycoon
Posts: 1850
Joined: 21 May 2005 15:10
Location: Hull, England

Post by bobingabout »

AFAIK, or inderstand, you'd have to be able to build the wrong type of train in the depot, even if it couldn't leave, if it couldn't leave it would need to be able to be converted with trains in it.
JPG SUX!!! USE PNG!!!
There are times when JPG is useful, TTD screenshots is not one of them. Please use PNG instead.

[/url]
mtlife
Engineer
Engineer
Posts: 19
Joined: 24 May 2005 15:53
Contact:

Post by mtlife »

i think joined depots is an option? they made joint railway stations work why not depots?
User avatar
bobingabout
Tycoon
Tycoon
Posts: 1850
Joined: 21 May 2005 15:10
Location: Hull, England

Post by bobingabout »

difference is that a station worked like that in the begining(you could place a bus stop next to a train station and it would still be all 1 station). all they did was allow a train station to be placed ajacent to another train station. depots would be more difficult because they don't do this normally.
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
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Post by SirkoZ »

Please iron out the bugs, so it can be included in the next integrated nightly. ;-)
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 7 guests