Advanced Autoreplace Patch

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

What should happen to waggons upon conversion ?

Poll ended at 08 Jul 2006 10:14

Drop them. (easiest)
1
11%
Automatically select best fitting replacement.
2
22%
Manually set replacement.
6
67%
 
Total votes: 9

Haukinger
Engineer
Engineer
Posts: 110
Joined: 15 Mar 2006 16:38

Advanced Autoreplace Patch

Post by Haukinger »

Hi all !

I've coded again ;) Haukinger presents: advanced autoreplace.
With this patch, one can convert all enginetypes to all other. You select the engine to convert and the one to convert to, independent which one has which track-type. If a to-be-converted engine enters a depot, it will be replaced (as normal), but it will stay in the depot, if it can't leave it (Monorail can't drive out of electric depot for example). If all your trains are converted and waiting in depot, you convert all your tracks (as normal) and start all trains again. See screenshots.
I don't think this qualifies as a patch, it looks more like a hack to me. Perhaps some ottd-code-experts can suggest improvements...

TODOs:
* Find better solution for power-calculation (outside of VehicleEnter_Track())
* Replacement for red flag in depot-window for trains that can't leave the depot
* Replacement for start-stop-button-string in vehicle-window for trains that aren't allowed to be started

So long,
Haukinger
Attachments
steam engine being autoreplaced with monorail
steam engine being autoreplaced with monorail
Before.png (196.36 KiB) Viewed 1229 times
tracks converted to monorail
tracks converted to monorail
After.png (196.12 KiB) Viewed 1279 times
Last edited by Haukinger on 05 Jul 2006 13:39, edited 3 times in total.
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1732
Joined: 30 Mar 2005 09:43

Post by peter1138 »

You'd be better off posting a diff instead of an exe...
He's like, some kind of OpenTTD developer.
Haukinger
Engineer
Engineer
Posts: 110
Joined: 15 Mar 2006 16:38

Post by Haukinger »

hmmmm...... you're right. simply forgotten. But there's a limit of three attachments anyway ;)

EDIT: Cleaned up code, calling IsCompatibleRail() for trains only now.
EDIT: Changed diff for MiniIN
EDIT: Replacing waggons, too
Attachments
Advanced_Autoreplace_5461.diff
advanced autoreplace for 5461
(9.93 KiB) Downloaded 429 times
Advanced_Autoreplace_5461_MiniIN.diff
advanced autoreplace for MiniIN 5461
(3.81 KiB) Downloaded 307 times
Last edited by Haukinger on 05 Jul 2006 13:45, edited 5 times in total.
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1732
Joined: 30 Mar 2005 09:43

Post by peter1138 »

Hmm, not bad. Some coding style tips (follow existing code...):

* Don't put spaces inside braces, i.e. "(foo)" not "( foo )"
* All comments in English please...
* Use tabs for indenting and spaces for aligning columns (only problem I saw was the comment in train_cmd.c)
* Use squiggly brackets, { }, if an if-statement is split, even if only onto 1 line.
* Remove code, don't comment it out. That's what the diff is for :-)

But bear in mind, if I'm picking at the coding style, there can't be too much wrong ;-)
He's like, some kind of OpenTTD developer.
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Post by richk67 »

peter1138 wrote:Hmm, not bad. Some coding style tips (follow existing code...):

* Don't put spaces inside braces, i.e. "(foo)" not "( foo )"
* All comments in English please...
* Use tabs for indenting and spaces for aligning columns (only problem I saw was the comment in train_cmd.c)
* Use squiggly brackets, { }, if an if-statement is split, even if only onto 1 line.
* Remove code, don't comment it out. That's what the diff is for :-)

But bear in mind, if I'm picking at the coding style, there can't be too much wrong ;-)
Peter: currently autoreplace only works on arrival of a train in the depot. If a train is in depot, and you set the autoreplace up, it doesnt get autoreplaced.

Would it be easy to have a way to force the autoreplace on vehicles in depot too?
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
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1732
Joined: 30 Mar 2005 09:43

Post by peter1138 »

Yes, fairly easy...
He's like, some kind of OpenTTD developer.
Haukinger
Engineer
Engineer
Posts: 110
Joined: 15 Mar 2006 16:38

Post by Haukinger »

Hi !
peter1138 wrote:Hmm, not bad. Some coding style tips (follow existing code...):

* Don't put spaces inside braces, i.e. "(foo)" not "( foo )"
* All comments in English please...
* Use tabs for indenting and spaces for aligning columns (only problem I saw was the comment in train_cmd.c)
* Use squiggly brackets, { }, if an if-statement is split, even if only onto 1 line.
* Remove code, don't comment it out. That's what the diff is for :-)
You see, that diff comes directly from my working copy, that's why some code is commented out and not deleted. You never know if you're patching at the right place... removing '//' is the easiest way back :)
User avatar
Slace
Transport Coordinator
Transport Coordinator
Posts: 368
Joined: 15 Mar 2004 10:20

Post by Slace »

a question on its usage. How do we do it? Do we convert the depo to the new rail type and then change the engine or do we do the engine 1st or should I just install it and just play around?
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post by DaleStan »

That last one usually works pretty well.

...
Assuming, of course, that it's followed by a visit to The Manual whenever something doesn't work correctly.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
Haukinger
Engineer
Engineer
Posts: 110
Joined: 15 Mar 2006 16:38

Post by Haukinger »

Slace wrote:a question on its usage. How do we do it? Do we convert the depo to the new rail type and then change the engine or do we do the engine 1st or should I just install it and just play around?
You set the autoreplacement as ever, just order a, say, asia star to be replaced with x2001. Then let your trains run around, and everytime a asia star enters a depot, it's converted to x2001 and stays in the depot. once all trains are converted and stopped in depots, you convert your network to monorail, including depots. Then start the trains again :)
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

richk67 wrote:Peter: currently autoreplace only works on arrival of a train in the depot. If a train is in depot, and you set the autoreplace up, it doesnt get autoreplaced.

Would it be easy to have a way to force the autoreplace on vehicles in depot too?
I just wrote it in VehicleEnterDepot(), but it's a function call that we can add elsewhere as well. Nobody complained before.

Also it's funny that you ask Peter even though it was me, who wrote autoreplace. I guess fame is an overnight thing :cry:

As for the idea in this patch. I talked about doing this, but it was turned down in the channel by the other developers (mainly Darkvater) because we can't have trains of the wrong type in depots. Actually I agree, so I found another solution. Build two depots next to each other and when a train is sold, a new one is bought in the other depot. Main issue in that solution: I haven't had time to code it so far :?
gigajum
Route Supervisor
Route Supervisor
Posts: 511
Joined: 08 Mar 2006 08:33
Location: Germany

Post by gigajum »

Bjarni wrote:
richk67 wrote:Peter: currently autoreplace only works on arrival of a train in the depot. If a train is in depot, and you set the autoreplace up, it doesnt get autoreplaced.

Would it be easy to have a way to force the autoreplace on vehicles in depot too?
I just wrote it in VehicleEnterDepot(), but it's a function call that we can add elsewhere as well. Nobody complained before.

Also it's funny that you ask Peter even though it was me, who wrote autoreplace. I guess fame is an overnight thing :cry:

As for the idea in this patch. I talked about doing this, but it was turned down in the channel by the other developers (mainly Darkvater) because we can't have trains of the wrong type in depots. Actually I agree, so I found another solution. Build two depots next to each other and when a train is sold, a new one is bought in the other depot. Main issue in that solution: I haven't had time to code it so far :?
And how about replace trains while converting the train depot rail type?
Haukinger
Engineer
Engineer
Posts: 110
Joined: 15 Mar 2006 16:38

Post by Haukinger »

As stated in the MiniIN-thread, I have to find a solution for waggons.
I think it would be best if one has to specify manually which normal waggons become which monorail/maglev waggons, with waggons without conversion rule being dropped. The main difficulty here is the fact that not all rail-types have all waggon-types, e.g. UKRS has only passenger/post/goods for maglev.
klogg
Traffic Manager
Traffic Manager
Posts: 248
Joined: 10 May 2006 13:55

Post by klogg »

Bjarni wrote:I guess fame is an overnight thing :cry:
In fact I think you are one of the greates coders here.
When I grow up I just want to be like you.
At school/work most of the people talk most of the time
about your projects and your improvements on OPENTTD.
If anybody gets a great idea they say he got a bjarni.
"Hey everybody! I finally got a bjarni."
- "Cool, now we can make billions with it."
When me and my friend are talking about the game
we usually call it Bjarni's Open.

klogg
Haukinger
Engineer
Engineer
Posts: 110
Joined: 15 Mar 2006 16:38

Post by Haukinger »

I've added waggon-replacement. It works just like replacing engines, select the railtype and replace to the desired waggon. Trains are converted from one railtype to another one only if all waggons and engines in the train have replacements assigned (of the same railtype). A side-effect - you can convert waggon-types now, if you convert from one railtype to another one, e.g. normal passenger-waggons to monorail-coal-waggons.
klogg
Traffic Manager
Traffic Manager
Posts: 248
Joined: 10 May 2006 13:55

Post by klogg »

But that means if I autoreplace a coal train (rail) to monorail,
I HAVE to autoreplace the coal waggons too. (aditionally)
It would be cool, if "simple" replacements are linked to the vehicle replacement.

klogg
gigajum
Route Supervisor
Route Supervisor
Posts: 511
Joined: 08 Mar 2006 08:33
Location: Germany

Post by gigajum »

I get an assert failure if i merge the miniIN patch it into the current miniIN branch.

Code: Select all

openttd: engine.h:162: GetEngine: Assertion `i < (sizeof(_engines)/sizeof(_engines[0]))' failed.
This happens if a train arrives in a depot.

Please fix it and post the file in the miniIN thread to get added into the branch.
nonick37
Engineer
Engineer
Posts: 26
Joined: 25 Mar 2006 13:38
Contact:

problem cloning replaced vehicles

Post by nonick37 »

r5476-MiniIN:
When trying to clone an autoreplaced train monorail->maglev i get the error: "can't build railway type"
this happens no matter depot type i try to clone from.

is this because of the wagons?
gigajum
Route Supervisor
Route Supervisor
Posts: 511
Joined: 08 Mar 2006 08:33
Location: Germany

Re: problem cloning replaced vehicles

Post by gigajum »

nonick37 wrote:r5476-MiniIN:
When trying to clone an autoreplaced train monorail->maglev i get the error: "can't build railway type"
this happens no matter depot type i try to clone from.

is this because of the wagons?
Yeah it is, Haukinger released a patch for that issue, but that produces that error two posts above.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 38 guests