Cloning Trains (and possibly other vehicles)
Moderator: OpenTTD Developers
Cloning Trains (and possibly other vehicles)
Hello.
I couldn't find that idea published....
You build nice connection, have a train, and that unexpectedly
your industrie doubles production!
What you do?
Click-click-click-...-click! And have another train ready to cope with
growing production.
I would love to have button (probably in train depot window) saying
'Clone train'. You click 'clone', you click train to be cloned, and have new
identical train (with identical schedule) ready for action. Simple?
Of course there may be some conditions as engines of this type are no more available,
but this will end up with simple error message.
This may of course apply to rdveh/planes/ships, but building them is not
as annoying as trains.
Next step of my proposal: Clone 2, 3, 4, 5 times at one click.
What do you think?
(I may volunteer to implement as well, if anybody but me is finding this useful...)
Jan
I couldn't find that idea published....
You build nice connection, have a train, and that unexpectedly
your industrie doubles production!
What you do?
Click-click-click-...-click! And have another train ready to cope with
growing production.
I would love to have button (probably in train depot window) saying
'Clone train'. You click 'clone', you click train to be cloned, and have new
identical train (with identical schedule) ready for action. Simple?
Of course there may be some conditions as engines of this type are no more available,
but this will end up with simple error message.
This may of course apply to rdveh/planes/ships, but building them is not
as annoying as trains.
Next step of my proposal: Clone 2, 3, 4, 5 times at one click.
What do you think?
(I may volunteer to implement as well, if anybody but me is finding this useful...)
Jan
surely you would have to pay for the cloned train? 

Last edited by BobXP on 08 Aug 2004 13:03, edited 1 time in total.
I think it is a nice feature!
So i started working on it...
The current status is:
It basicly works! There is a new button in train depots, when you click it you get a cursor with which you can point a trains (on rails and in depots) to clone the, including its orders.
Q for u: Should the clone tool switch off after cloning or stay activated so one can easily clone an other train?
There are some things to fix before making it avaiable:
- Any wagons lingering in the depot will be added to the newly created train;
- When there is not enough money in your account, you will end up with a part of the train (mostly only the wagons, because they are cheaper than a loc);
- Now it is still possible to clone outdated trains.
- Multiheaded engines are not handled correctly yet. (you end up with two new trains)
- All the wagons are purchased one at the time, so the red cost animations overlap, making it unreadable.
- Handle refitted vehicles
- for now the goto cursor animation is used. This function should get his own nifty cool cursor
But i'm no graphics artist 
Future plans include:
- Making it generic, so that it will also work for road,air and water vehicles
As soon as the SVN will come up again i will post the patch.
So i started working on it...
The current status is:
It basicly works! There is a new button in train depots, when you click it you get a cursor with which you can point a trains (on rails and in depots) to clone the, including its orders.
Q for u: Should the clone tool switch off after cloning or stay activated so one can easily clone an other train?
There are some things to fix before making it avaiable:
- Any wagons lingering in the depot will be added to the newly created train;
- When there is not enough money in your account, you will end up with a part of the train (mostly only the wagons, because they are cheaper than a loc);
- Now it is still possible to clone outdated trains.
- Multiheaded engines are not handled correctly yet. (you end up with two new trains)
- All the wagons are purchased one at the time, so the red cost animations overlap, making it unreadable.
- Handle refitted vehicles
- for now the goto cursor animation is used. This function should get his own nifty cool cursor


Future plans include:
- Making it generic, so that it will also work for road,air and water vehicles
As soon as the SVN will come up again i will post the patch.
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]
[/url]
[url=callto://zoekdribbel]
Nice too see this implemented. If can be as free as to suggest some suggestions:Dribbel wrote:There are some things to fix before making it avaiable:
- Any wagons lingering in the depot will be added to the newly created train;
- When there is not enough money in your account, you will end up with a part of the train (mostly only the wagons, because they are cheaper than a loc);
- Now it is still possible to clone outdated trains.
- Multiheaded engines are not handled correctly yet. (you end up with two new trains)
- All the wagons are purchased one at the time, so the red cost animations overlap, making it unreadable.
- Handle refitted vehicles
- for now the goto cursor animation is used. This function should get his own nifty cool cursorBut i'm no graphics artist
Future plans include:
- Making it generic, so that it will also work for road,air and water vehicles
As soon as the SVN will come up again i will post the patch.
- Make a dry run of cloning the train beforehand. This ensures that you know the full cost (so if you don't have enough money you won't end up with half a train, and a lot of wasted money), get nice expension graphics, and can use "SHIFT" to show the total expected cost.
- ..hmm, that's it for now
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
Someone broke the SHIFT function (in my SVN version (27-7-04), that is) now it holds down the FastForward button. Now when you plan a piece of track using shift to see the cost, the game also goes into fast forward, very annoying, especially when trying to click on trains.Darkvater wrote:<snip> can use "SHIFT" to show the total expected cost. </snip>
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]
[/url]
[url=callto://zoekdribbel]
It's not broke, it's a featureDribbel wrote:Someone broke the SHIFT function (in my SVN version (27-7-04), that is) now it holds down the FastForward button. Now when you plan a piece of track using shift to see the cost, the game also goes into fast forward, very annoying, especially when trying to click on trains.Darkvater wrote:<snip> can use "SHIFT" to show the total expected cost. </snip>

Code: Select all
#if defined(_DEBUG)
if (_wnd.has_focus && GetAsyncKeyState(VK_SHIFT) < 0) {
#else
if (_wnd.has_focus && GetAsyncKeyState(VK_TAB) < 0) {
#endif
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
Making real progress here.... SHIFT modifier works. cost are displayed right now, orders are copied right.
Only those damn multi headed trains (the one loc, two vehicles AND the two loc and two vehicle version)
I'm hungry now, i'm going to have diner. Maybe later tonight
Only those damn multi headed trains (the one loc, two vehicles AND the two loc and two vehicle version)
I'm hungry now, i'm going to have diner. Maybe later tonight
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]
[/url]
[url=callto://zoekdribbel]
To be onest, I also start working on that :)Dribbel wrote:I think it is a nice feature!
So i started working on it...
Mine does the same, and does turn off after.The current status is:
It basicly works! There is a new button in train depots, when you click it you get a cursor with which you can point a trains (on rails and in depots) to clone the, including its orders.
Q for u: Should the clone tool switch off after cloning or stay activated so one can easily clone an other train?
Funny (or maybe not suprising) is that I end up with nearly the same functionality.There are some things to fix before making it avaiable:
- Any wagons lingering in the depot will be added to the newly created train;
- When there is not enough money in your account, you will end up with a part of the train (mostly only the wagons, because they are cheaper than a loc);
- Now it is still possible to clone outdated trains.
- Multiheaded engines are not handled correctly yet. (you end up with two new trains)
- All the wagons are purchased one at the time, so the red cost animations overlap, making it unreadable.
- Handle refitted vehicles
- for now the goto cursor animation is used. This function should get his own nifty cool cursor :) But i'm no graphics artist :(
Future plans include:
- Making it generic, so that it will also work for road,air and water vehicles
As soon as the SVN will come up again i will post the patch.
Only difference is that I do not attach other wagons, and join other locos of
multiheaded train.
But still I didn't get rid of all problems with multihead.
- Order of locos is sometimes not the same in new train
- No support for 'Half a Chimaera' (see http://www.tt-forums.net/viewtopic.php?t=9275 )
BTW.
Currently I have implemented it in GUI part. But in fact I think it sholud be implemented
as new command. How did you do this?
Greetings
Jan
checklist of features to consider
- clone the train
- also clone its orders (preferably share them)
- refit the loco if original was refitted
- be able to estimate the cost (holding shift)
- refuse to build any part of the train if money is not enough for whole
- handle multiheaded trains
- not include wagons that was in depot previously
- preserve order of locos (especially Chimera-like trains)
- handle half-Chimera configurations (head or rear part of Chimera-like train sold)
- block cloning outdated trains
- maybe some speical way of cloning only wagons+orders to separatelly build loco
- single price information after purchase
- new cursor animation
- clone train by choosing original in train depot window
- clone train by choosing original in train list window
- block cloning of oponents vehicle (at least of his orders ;)
- provide some way to make n clones at one time
- clone non-train vehicles
- create new command (DEF_COMMAND) for cloning (I believe some of above options
aren't possible without this)
Last edited by follow on 08 Aug 2004 13:49, edited 1 time in total.
Re: checklist of features to consider
Hmm, you added subject to your post, i didn't see that one directly so i thought you did all of the following yet

I'll keep on working today, as soon as i have finished more functionlity i'll post a patch.

Subject of the post wrote:Re: checklist of features to consider
- clone the train done
- also clone its orders (preferably share them)done, copying orders that is
- refit the loco if original was refitted NOT Done
- be able to estimate the cost (holding shift) Done
- refuse to build any part of the train if money is not enough for whole Done
- handle multiheaded trains NOT Done
- not include wagons that was in depot previously Done
- preserve order of locos (especially Chimera-like trains) NOT Done
- handle half-Chimera configurations (head or rear part of Chimera-like train sold) NOT Done
- block cloning outdated trains Almost done, It won't buy the loc, but does buy the cars, BUT charges you with a zillion dollars (nice bug! this will make your balance go trough the roof, up to 4.000.000.000 or something like that
)
- maybe some speical way of cloning only wagons+orders to separatelly build loco
- single price information after purchase Done
- new cursor animation
- clone train by choosing original in train depot window Done
- clone train by choosing original in train list window
- block cloning of oponents vehicle (at least of his orders
Not allowed
- provide some way to make n clones at one time
- clone non-train vehicles Future plans
- create new command (DEF_COMMAND) for cloning (I believe some of above options
aren't possible without this) Done, yes that's right

I'll keep on working today, as soon as i have finished more functionlity i'll post a patch.
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]
[/url]
[url=callto://zoekdribbel]
Re: checklist of features to consider
I think 'sharing orders' would be much better for a cloned train then copying them. Of course some people would want it a different way.Dribbel wrote:
- also clone its orders (preferably share them)done, copying orders that is
[tt-user mode]make it optional![/tt-user mode]

*topic moved to OpenTTD Development
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
Hmm, I've got a nasty problem on my hands now.
How to calculate the refitting cost in advance. If u don't have a train, doing the calculations first ( DC_EXEC flag is not set) there is no train/vehicle to preform the operation on.
And an other factor the makes this even more complicated is a train consisting of multiple multi head locs each with different refitted cargos. ie one can build three "Manley-Morel DMU" train, refit them each with a different type of cargo and then join them in one (very powerfull) train. To calculate the cost of refitting in advance become a nice puzzle this way....
How to calculate the refitting cost in advance. If u don't have a train, doing the calculations first ( DC_EXEC flag is not set) there is no train/vehicle to preform the operation on.
And an other factor the makes this even more complicated is a train consisting of multiple multi head locs each with different refitted cargos. ie one can build three "Manley-Morel DMU" train, refit them each with a different type of cargo and then join them in one (very powerfull) train. To calculate the cost of refitting in advance become a nice puzzle this way....
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]
[/url]
[url=callto://zoekdribbel]
I'm not sure I'll be right here, but I would do following:
1. Create LocoRefitCost function from CmdRefitRailVehicle
Something like:
2. Than replace cost computing code in CmdRefitRailVehicle()
with:
3. For every train piece you clone add cost of refitting it -- computed with LocoRefitCost
(using _rail_vehicle_info[engine_type].cargo_type as old_cargo_type)
---
This all may seem to general to create function for just one line,
and in theory you could use just hardcoded (_price.ship_base >> 7).
But from other hand if you do something like this, code will not break if somebody will
change way of how refinting cost is calculated. (eg. refitting
from mail to goods is probably cheaper than from mail to passangers ;)
Side note
Locomotive refiting cost is based on _price.ship_base that is suspicious....
I'm filling bug report for that
1. Create LocoRefitCost function from CmdRefitRailVehicle
Something like:
Code: Select all
int32 LocoRefitCost(uint16 engine_type, byte old_cargo_type,byte new_cargo_type)
{
if (!(_rail_vehicle_info[engine_type].flags & RVI_WAGON) && old_cargo_type != new_cargo_type && _rail_vehicle_info[engine_type].capacity)
return (_price.ship_base >> 7); /* this (ship_base) is originally in train_cmd.c, and probably it is a bug */
return 0;
}
Code: Select all
if (!(_rail_vehicle_info[v->engine_type].flags & RVI_WAGON) && (byte)p2 != v->cargo_type && v->cargo_cap != 0) {
cost += (_price.ship_base >> 7);
num += v->cargo_cap;
Code: Select all
if (!(_rail_vehicle_info[v->engine_type].flags & RVI_WAGON) && (byte)p2 != v->cargo_type && v->cargo_cap != 0) {
cost += LocoRefitCost(v->engine_type,v->cargo_type,(byte)p2);
num += v->cargo_cap;
(using _rail_vehicle_info[engine_type].cargo_type as old_cargo_type)
---
This all may seem to general to create function for just one line,
and in theory you could use just hardcoded (_price.ship_base >> 7).
But from other hand if you do something like this, code will not break if somebody will
change way of how refinting cost is calculated. (eg. refitting
from mail to goods is probably cheaper than from mail to passangers ;)
Side note
Locomotive refiting cost is based on _price.ship_base that is suspicious....
I'm filling bug report for that
Re: checklist of features to consider
I managed to solve lots of the challenges (no not problems!!):
- clone the train Done
- also clone its orders (preferably share them)done, copying orders that is,maybe i'll change it to clone(linking?), but thats a minor change (flipping one bit)
- refit the loco if original was refitted Done
- be able to estimate the cost (holding shift) Done
- refuse to build any part of the train if money is not enough for whole Done
- handle multiheaded trains Done
- not include wagons that was in depot previouslyDone
- preserve order of locos (especially Chimera-like trains)Almost Done, some tail parts of multie headed loc end up at the end of a train
- handle half-Chimera configurations (head or rear part of Chimera-like train sold) Done
- block cloning outdated trains Done
- maybe some speical way of cloning only wagons+orders to separatelly build loco future plans
- single price information after purchase Done
- new cursor animation For this one I need some help. Can any one make one for me? I'm no grphics artist and show me how to get it in the game. The GRF files/system still looks like magic to me
- clone train by choosing original in train depot window Done
- clone train by choosing original in train list window Not Done (yet?) now you will get the train window, in which you can click on the train to clone it
- block cloning of oponents vehicle (at least of his orders
Done, it's not allowed
- provide some way to make n clones at one time Any ideas a way to make this happen?
- clone non-train vehicles Future plans!!!! I'' do this one for sure!
- create new command (DEF_COMMAND) for cloning (I believe some of above options
aren't possible without this) Done, yes that's right
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]
[/url]
[url=callto://zoekdribbel]
Good plan, i'll use your piece of code, if u don't mindfollow wrote:I'm not sure I'll be right here, but I would do following:
<snip> three step plan with code snippets </snip>

Ypu got a good point, i went for the lame ass solution by just coping (_price.ship_base >> 7) into my new piecefollow wrote:This all may seem to general to create function for just one line, and in theory you could use just hardcoded (_price.ship_base >> 7).
But from other hand if you do something like this, code will not break if somebody will
change way of how refinting cost is calculated. (eg. refitting
from mail to goods is probably cheaper than from mail to passangers![]()

It is strange indeed. I wonderd why that was, but paid no attention to it. Maybe they are using pieces of a ship to refit a train, 128 pieces that isfollow wrote: Side note
Locomotive refiting cost is based on _price.ship_base that is suspicious....
I'm filling bug report for that

Last edited by Dribbel on 08 Aug 2004 21:28, edited 2 times in total.
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]
[/url]
[url=callto://zoekdribbel]
I feel that we can create patching team ;)
More seriously, I'm realy impressed by the speed you realiaze that project, and impatiently wait for effect.
And this is so nice that so many times in a little time I was totally agreeing with your ideas,
and several times you did what I just thought about (colored status of checklist recently).
More seriously, I'm realy impressed by the speed you realiaze that project, and impatiently wait for effect.
And this is so nice that so many times in a little time I was totally agreeing with your ideas,
and several times you did what I just thought about (colored status of checklist recently).
As there is no much work for me left, I've only published request for new graphics for
cursor in NEW GRAPHICS NEEDED topic. ( http://www.tt-forums.net/viewtopic.php?p=184573#184573 ).
unsorted comments:
I don't think you have to care much about order of locos. This may just go to 'minor glitches' section.
than:
In fact this is not essential function... I just wrote down all thoughts I had, not to forget them, but if checklist is priority list, it would be somewhere at the bottom.
than:
Also, would you mind of posting in SF some early version of your patch? I may became beta-tester ;)
cursor in NEW GRAPHICS NEEDED topic. ( http://www.tt-forums.net/viewtopic.php?p=184573#184573 ).
unsorted comments:
Also, while I remember -- I'm sure that you thought about it, but in the beggining I didn't...Dribbel wrote:I've a bug now: You can clone a maglev into a Railroad depot
- check not to clone aircraft into railway depot
I don't think you have to care much about order of locos. This may just go to 'minor glitches' section.
than:
Maybe some bash/readline like sequnece (CTRL-n and than click will make n clones)Dribbel wrote:
- provide some way to make n clones at one time Any ideas a way to make this happen?
In fact this is not essential function... I just wrote down all thoughts I had, not to forget them, but if checklist is priority list, it would be somewhere at the bottom.
than:
Also, would you mind of posting in SF some early version of your patch? I may became beta-tester ;)
Who is online
Users browsing this forum: Google [Bot], le_harv and 3 guests