News:

Simutrans Chat Room
Where cool people of Simutrans can meet up.

[patch] Replacing (aka the long, long crossing of the desert)

Started by isidoro, February 04, 2009, 02:07:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

isidoro

I talked with James Petts in a thread, whose subject I don't want to remember, about programming some replacing/upgrading/refurbishing related tools.  After some ten days of work, I would like to share with you what I've got so far.

The patch attached below is for r2260.  I have frozen there and will merge when done if needed.  The present version does, in fact, nothing.  I've split depot_frame functionality in two classes: depot_frame and gui_convoy_assembler.  The idea is to reuse the latter component in the replacing tool.  The only new thing players can see is that I've changed the actions button at the bottom right corner with a combo box.  The whole process has been quite complicated for me, so if you find errors, please tell.

The idea of doing this came from having a game with pak.german with 260 horse carriages to be replaced by buses.  I thought, how naïve myself, that perhaps programming a replacing tool would be easier than to replace the 260 vehicles.  I guess not.  Now, in the middle of the bridge, I will try to reach the other end...

EDIT: half of the patch was not in the file.  Please, look for the corrected version downstream...


gerw

So the whole lower part of the depot is a gui_convoy_assembler? Seems to be very nice! What will be the end? 'Replace one horse carriage with one bus' or even 'replace 3 horse carriage with one bus'?

Edit: I've found a major bug: You forgot 'svn add gui/components/gui_convoy_assembler.*' ;) I hope you can fix it :)

jamespetts

Very interesting! I do like the combo box idea... I should be very interested in any progress.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

VS

You will want to make the combobox text field longer to allow for translations. And some sort of arrow pointing down would be nice, too, since it is common in comboboxes across most platforms (and where not, it is double arrow pointing up and down, so...).

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

HeinBloed

Funny coincidence as I only thought last night that this is a feature Simutrans must have. :) My ideas were:

- It should be possible to replace either single components (e.g. a certain rail car X in all convoys) or entire configurations (e.g. all trains with head W and cars XYZ).
- In order to make the transition appear realistic, one could add a new command "upgrade at depot" to the concerned convoys and at the same time set them to "no load". The upgrade command could be inserted after a whole cycle of the current schedule has passed since the convoy is guaranteed to be empty then. The convoy would then drive to the depot, get upgraded and pick up normal schedule again.

Maybe this can serve as an additional inspiration, I'm sure you already had your own plans.
(previously known as "tttron")

isidoro

Thanks for your support.

Quote from: gerw on February 04, 2009, 08:25:50 AM
So the whole lower part of the depot is a gui_convoy_assembler? Seems to be very nice! What will be the end? 'Replace one horse carriage with one bus' or even 'replace 3 horse carriage with one bus'?

Edit: I've found a major bug: You forgot 'svn add gui/components/gui_convoy_assembler.*' ;) I hope you can fix it :)

Not exactly.  The convoy assembler is the image of the convoy plus the lower part.  There is a configurable hole in the middle.  The idea is not to be forced to change depot's present configuration.  My idea is to be able to replace only a certain number of convoys since it is very common that one bus can do the job of several horse carriages.  Thanks for the bug (half of the patch was out)...  I attach the corrected one below and delete the one above.

@James: Thanks

@VS: The size is the same of the old button, but can be easily changed.  The combo box was not made by me.  It is the standard combo-box in simutrans (used for line selection at the top of the window).  That, if wanted, would be a separate development.

@tttron: I don't believe in coincidence  :D .  As for your ideas: in the first phase at least only whole convoys may be replaced.  The "upgrade at depot" is already intended or something similar. 

Dwachs

Quote from: isidoro on February 04, 2009, 01:21:13 PM
@VS: The size is the same of the old button, but can be easily changed.  The combo box was not made by me.  It is the standard combo-box in simutrans (used for line selection at the top of the window).  That, if wanted, would be a separate development.
It should be possible to change the size of the combo-box, use this function:
void gui_combobox_t::set_groesse(koord gr);


Good luck with this patch! Something like this is surely needed.
Parsley, sage, rosemary, and maggikraut.

VS

So you could also use this component to search for a particular train?


OK, then all Simutrans comboboxes are broken :(

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

prissi

The Comboboxes work fine as they are ... the are broken only that they need specific action of the dialoge to close them ...

VS

prissi: Broken (not code) because you never know it is a combo box.

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

prissi


isidoro

Here's an update.  The dialog without functionality yet.  And some bugs.  The dialog will open with a new button in the convoys window.  You can select the convoy that will replace current convoy.  Two buttons below allow to replace all convoys equal to this one in the current line and to replace all convoys equal to this one.

"Replace cycle" allows the player not to replace all but some convoys.  It is very simple.  If you choose 5 in replace and 3 in skip, 5 vehicles are replaced, 3 are left the same, 5 replaced, 3 left, and so on, until all convoys are exhausted.

You can see some bugs: for example convoy max speed, trains are not centered, etc.  It is a WIP.

EDIT: patch erased.  See next version.

jamespetts

Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

isidoro

Thanks, James.  In fact, you started the idea and spurred me on...  ;)

An update (I will erase previous patch, to save some space in the server).  In this update:

  • Now the replacing vehicle is centered, even for trains
  • The speed is shown correctly
  • A new option is added in the replace cycle: replace, sell and skip.  The tool can then be used to sell all or a fraction of convoys in a line
  • Two more options rescued from the previous thread: "send to depot only" and "send to depot and restart".
  • Some functionality: now the options "replace all in line" and "replace all" work
  • In this version convoys are only marked for replacement, not really replaced

In the attach picture, you can see a train to be replaced by other.  All trains like this one in its line will be replaced too.  To be replaced trains will first go to depot, be replaced and restarted.  2/3 of trains in the line will be replaced, 1/3 will be sold.

And two questions I don't know how to deal with, if anybody has an idea:

  • Once in depot, if the train is to be restarted automatically, what if the track is reserved when it tries to do so?
  • Electricity: if electricity convoys are involved, is there to be any reinforced restrictions?  Which ones?


EDIT: Patch erased.  See next version.

jamespetts

Looking extremely promising! To answer your questions:

(1) in my view, the most user-friendly answer would be for it (a) to alert the user that the track is blocked; and (b) keep trying to reserve a section at an interval of, say, 10,000 ticks (10 seconds on a normal speed), and inform the player that it is doing that, too;

(2) this might be quite difficult; my provisional view is that it is enough for the convoy to say "cannot find route" in the usual way, but perhaps other have other ideas...?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

isidoro

Another version of the patch, first with some useful functionality.  Things are going quicker now:

  • Now the replace cycle works
  • Vehicles are skipped and sold correctly
  • Working towards replacement, a first step: a new button in convoy details window.  There, you have "withdraw" and "Sell mode".  Now there is another button: "Retire".  It will wait until the vehicle is empty and then, send it to the depot

Next step will be to really replace vehicles when they reach depot and are marked for replacement.  But enough for today.


EDIT: patch erased.  Please see next version.

jamespetts

Goodness, this is excellent progress! I particularly like "retire". This could really reduce micromanagement!
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

isidoro

Not so long crossing, as it seems...  :D

The second part was much easier than I thought.  The attached patch is a working version.  Now vehicles are sent to depot, replaced, and restarted if wanted.  Please consider this beta software.  It needs bug trapping.

It can be used to replace, sell, send to depot one, part or all of convoys belonging to a line.  Other use can be to ask a train to add a wagon without being compulsory to manual unload the vehicle, send it to the depot, add the wagon and restart it.

I hope you guys like it.

By the way, what year does the first bus appear in pak.german?

EDIT: The long waited-for bus arrived, but it was quite expensive.  I must wait for other newer still.  It is a good climber though.

Patch erased to save space.  Please see next version.

isidoro

Some corrected errors:

  • Line was not updated when replacing a vehicle and that made a fully upgraded line to appear as obsolete
  • There was a severe error that corrupted the heap.  It seems that you cannot delete vehicles any place in the code

The patch should be more stable now.  The "electric problem" keeps unsolved though.


gerw

I tried with r2325 and after fixing one failed hunk, it works fine.

One thing: Please replace the inclusion of header files in other headers by forward declarations, whenever it is possible (http://en.wikipedia.org/wiki/Forward_declaration). This will save compile time.

jamespetts

I am missing replace_frame.h from the latest patch.

Edit: Never mind, found it.

Edit 2: gerw, what did you do to get it to complile? I have a great difficulty with header files, such that it produces thousands of errors. Specifically, grund.h, which includes simdepot.h (which, in turn, includes the new gui_convoi_assember.h) complains that the depot_t class is not defined. I have pored over gui_convoi_assember.h for a very long time and not found any syntax errors, so I am very confused.

Edit 3: I have managed to fix the problem by replacing the line, #include "gui/components/gui_convoy_assembler.h in simdepot.h with a forward declaration to gui_convoy_assembler. I am still not quite sure what caused the original problem, but, since this solution is preferable in any event, it seems satisfactory overall.

Edit 4: An interim idea for dealing with the electrics issue: simply have a button in the replace GUI with the label, "show electrics", which is on by default if the current convoy contains electrics, and off by default if it does not.

Edit 5: Another idea would be to suppress the "entered depot" dialogue box when vehicles enter a depot as a result of the vehicle replacer and they are set to leave the depot again automatically. Also, we need help text for the replace window.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

z9999

My impression.

- Is it possible to show the number of target convoy to replace on replace window ? It is useful to set the value of replace cycle.
- Is it possible to show sum of cost to replace on replace window ?
- Is it possible to show a message window when all replace was done ?


Fabio


isidoro

Thank you for your answers.

@gerw: I'll try to fix the headers in the final polish.  I'm not good at it, though.  It is confusing for me.

@jamespetts: I'll try to crosscompile a version for windows from linux and post it in the patches repository if I success, for more people to try.  Nice suggestions about the enter depot message.  Regarding the help message window, when finished, I would ask for your help if you don't mind.  A native speaker will surely do better.

@z9999: very nice ideas.  First should be easy.  Second also, but that cost changes as vehicles get older and also there is a difficulty regarding already bought vehicles in depot which need not to be bought again.  Third I believe impossible.  Once marked for replacement, convois loose "contact" with each other.  There had to be a transaction id or something like that and things get much complicated.

Fabio

Quote from: isidoro on February 15, 2009, 05:43:01 PM
Third I believe impossible.  Once marked for replacement, convois loose "contact" with each other.  There had to be a transaction id or something like that and things get much complicated.
well, i think this could be done monitorizing the line: if you set to replace with 10 new vehicles of type X and 3 xX are already in the line, you could have the feedback when the line contains 13 vehicles X.

z9999

Quote from: isidoro on February 15, 2009, 05:43:01 PM
Third I believe impossible.

I think so, too.  :) It's not a big broblem because I can see it in line management window. Thanks.

Another things.

- If I uncheck both "send to depot only" and "send to depot and restart" and click "Replace" button, button label changes to "Replacing" but convoy don't go to depot.
- If I don't select any convoy on replace window and click "Replace" button, button label don't change and convoy go to depot.

I think both of these cases, "Replace" button should be inactive.

jamespetts

For anyone who wants to try this without having to compile from source, I have integrated it into Simutrans-Experimental, a binary version of which can be downloaded as described in this thread.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

isidoro

@fabio: good point.  I'll see if anything can be done

@z9999: first is intended. "Replacing" in the implementation means something like "marked to be replaced".  The idea is that if you have a very complicated line and you fear that some convoys go to the wrong depots, you uncheck both buttons, but convoys are marked for replace.  Later, when the convoys are near the good depot, you manually press "Go to depot" and they get replaced.  I'll have a look to the second.

@jamespetts: thanks for including in ST-exp.  Read on, though.

I've tried to crosscompile the windows executable from linux with the patch.  The result is in http://simutrans-germany.com/~patches/download.php?file=sim-wingdi-replacing-r2260.zip.  I don't know if the process has succeeded since I don't have any Windows machine at home.  If any of you try it, please tell if it worked.

I you want a linux binary, just ask and I'll upload it.

jamespetts

Isidoro,

my compilation with Windows, albeit the modified version with the forward declaration instead of the header file, works fine.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

prissi

The replace dialog did not even fit the screen in the starting size of simutrans. This should be fixed, since resizing also does not work properly. Also the actions by the buttons are completely incomprehensive.

Even more, it would make more sense to have this as a line tool. As part of convoi it does not really make sense, because a single convoi is easily replace manually (Send to depot => window pop up => replace: same effort as before, schedule is kept)

Also there is a Cancel button, which I do not want to appear. (THe cancel button of the save dialoge is actually a long time candidate to be gone anyway.)

jamespetts

Prissi,

it would be a serious mistake to abolish the cancel button on the save dialogue - it is easy to press SHIFT + S by mistake, and it would be silly if, every time that a player does that, he/she is forced to enter a save filename, wait for the game to save, and then have extra disc space taken up. Almost all programmes have cancel options for things of that nature, including saving files. Indeed, I am not aware of a single serious or professional piece of software that does not allow a user to cancel a mistake.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Combuijs

Well, you can just close the dialogue if you don't want to save anything.

You will usually find the cancel button on a modal dialog. Simutrans does not have a modal dialogue. For instance when the save dialogue is up, you still can change things on the map, and in fact just ignore the dialogue. You can't do that with Microsoft Word!
Bob Marley: No woman, no cry

Programmer: No user, no bugs



Fabio

cancel buttons are easier to click on than X buttons to close windows, because they are bigger.
what's wrong with them, in your opinion, if i may ask?

prissi

The is the delete ley which close the topmost window anyway. It is usually only eating space and attention.

Cancel just do not make sense on a non-modal dialog, since no action started yet.

VS

True. Since the window can be closed with mouse or keyboard, it makes less sense to have a dedicated button for that.

On the other hand, users may think the dialog must be used... and hitting that small X is hard.

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!