Cloning Trains (and possibly other vehicles)

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

follow
Engineer
Engineer
Posts: 55
Joined: 20 Jul 2004 02:43
Location: Warsaw, Poland
Contact:

Cloning Trains (and possibly other vehicles)

Post by follow »

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
BobXP
Tycoon
Tycoon
Posts: 2720
Joined: 04 May 2003 11:00
Location: Torquay, England
Contact:

Post by BobXP »

surely you would have to pay for the cloned train? :roll:
Last edited by BobXP on 08 Aug 2004 13:03, edited 1 time in total.
<!-- End Of Post !-->
Image
User avatar
hAmpzter
Engineer
Engineer
Posts: 41
Joined: 17 Jul 2004 15:04
Location: Sweden
Contact:

Post by hAmpzter »

That would be a nice feature and I think it has been requested before..
Maybe not here, could have been on IRC!

But it has been thought of and might be implemented sometime in the feature when time exist and SVN is working!
User avatar
Dribbel
Engineer
Engineer
Posts: 64
Joined: 11 Jul 2004 16:25
Location: The Netherlands - Grunn

Post by Dribbel »

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.
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]Image[/url]
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

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 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.
Nice too see this implemented. If can be as free as to suggest some suggestions:
  1. 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.
  2. ..hmm, that's it for now :P
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."
User avatar
Dribbel
Engineer
Engineer
Posts: 64
Joined: 11 Jul 2004 16:25
Location: The Netherlands - Grunn

Post by Dribbel »

Darkvater wrote:<snip> can use "SHIFT" to show the total expected cost. </snip>
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.
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]Image[/url]
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

Dribbel wrote:
Darkvater wrote:<snip> can use "SHIFT" to show the total expected cost. </snip>
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.
It's not broke, it's a feature :). With MSVC you can debug your application and on a break it will jump back to the editor. The default FF button was 'TAB', but that would immediately start to indent your lines in the debugger on a break. REALLY ANNOYING. So it was changed to 'shift' in the debug build. If you want, disable it, have a look at win32.c line 652.

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."
User avatar
Dribbel
Engineer
Engineer
Posts: 64
Joined: 11 Jul 2004 16:25
Location: The Netherlands - Grunn

Post by Dribbel »

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
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]Image[/url]
follow
Engineer
Engineer
Posts: 55
Joined: 20 Jul 2004 02:43
Location: Warsaw, Poland
Contact:

Post by follow »

Dribbel wrote:I think it is a nice feature!
So i started working on it...
To be onest, I also start working on that :)
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?
Mine does the same, and does turn off after.
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.
Funny (or maybe not suprising) is that I end up with nearly the same functionality.
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
follow
Engineer
Engineer
Posts: 55
Joined: 20 Jul 2004 02:43
Location: Warsaw, Poland
Contact:

checklist of features to consider

Post by follow »

  • 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.
follow
Engineer
Engineer
Posts: 55
Joined: 20 Jul 2004 02:43
Location: Warsaw, Poland
Contact:

Post by follow »

Here is Chimera-like wired configuration, that have at least two problems:
  • Two forward facing and three rear facing components
  • Wired order of locos
Also wagons can be attached in any place...
Attachments
Wired loco combination screenshot
Wired loco combination screenshot
multiheaded.png (51.01 KiB) Viewed 11169 times
follow
Engineer
Engineer
Posts: 55
Joined: 20 Jul 2004 02:43
Location: Warsaw, Poland
Contact:

Post by follow »

To moderator: please consider moving this thread to Development forum. I think it starts to be resonable.

Oh, and if you are able to do so, maybe topic title 'Cloning vehicles' would be better.

Thanks
User avatar
Dribbel
Engineer
Engineer
Posts: 64
Joined: 11 Jul 2004 16:25
Location: The Netherlands - Grunn

Re: checklist of features to consider

Post by Dribbel »

Hmm, you added subject to your post, i didn't see that one directly so i thought you did all of the following yet :)
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've a bug now: You can clone a maglev into a Railroad depot :)

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]Image[/url]
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Re: checklist of features to consider

Post by Darkvater »

Dribbel wrote:
  • also clone its orders (preferably share them)done, copying orders that is
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.
[tt-user mode]make it optional![/tt-user mode] :P


*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."
User avatar
Dribbel
Engineer
Engineer
Posts: 64
Joined: 11 Jul 2004 16:25
Location: The Netherlands - Grunn

Post by Dribbel »

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....
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]Image[/url]
follow
Engineer
Engineer
Posts: 55
Joined: 20 Jul 2004 02:43
Location: Warsaw, Poland
Contact:

Post by follow »

I'm not sure I'll be right here, but I would do following:

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;
}
2. Than replace cost computing code in CmdRefitRailVehicle()

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;
with:

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;
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
User avatar
Dribbel
Engineer
Engineer
Posts: 64
Joined: 11 Jul 2004 16:25
Location: The Netherlands - Grunn

Re: checklist of features to consider

Post by Dribbel »

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]Image[/url]
User avatar
Dribbel
Engineer
Engineer
Posts: 64
Joined: 11 Jul 2004 16:25
Location: The Netherlands - Grunn

Post by Dribbel »

follow wrote:I'm not sure I'll be right here, but I would do following:
<snip> three step plan with code snippets </snip>
Good plan, i'll use your piece of code, if u don't mind :D
follow 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 ;)
Ypu got a good point, i went for the lame ass solution by just coping (_price.ship_base >> 7) into my new piece :)
follow wrote: Side note
Locomotive refiting cost is based on _price.ship_base that is suspicious....
I'm filling bug report for that
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 is :)
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]Image[/url]
follow
Engineer
Engineer
Posts: 55
Joined: 20 Jul 2004 02:43
Location: Warsaw, Poland
Contact:

Post by follow »

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).
follow
Engineer
Engineer
Posts: 55
Joined: 20 Jul 2004 02:43
Location: Warsaw, Poland
Contact:

Post by follow »

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:
Dribbel wrote:I've a bug now: You can clone a maglev into a Railroad depot
Also, while I remember -- I'm sure that you thought about it, but in the beggining I didn't...
  • check not to clone aircraft into railway depot
than:

I don't think you have to care much about order of locos. This may just go to 'minor glitches' section.

than:
Dribbel wrote:
  • provide some way to make n clones at one time Any ideas a way to make this happen?
Maybe some bash/readline like sequnece (CTRL-n and than click will make n clones)
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 ;)
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 16 guests