Patch: Vehicle+town+industry console commands v20 for r19627

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

User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Patch: Vehicle+town+industry console commands v20 for r19627

Post by Bilbo »

I have created a patch that will add vehicle (train, plane, ship and road vehicles), town and industry console commands.

It adds command "train" in console, with several subcommands for trains, similarly "road" for road vehicles, "plane" or "aircraft" for aircrafts and "ship" for ships. Also command "vehicle" that will do the command on all appropriate vehicles of any type. From v16, there are also "industry" and "town" commands available.

For full manual to all commands, see the wiki page:
* http://wiki.openttd.org/index.php/Vehic ... e_commands
* http://wiki.openttd.org/index.php/Town_console_commands
* http://wiki.openttd.org/index.php/Indus ... e_commands

Changes:

v20:
Fixed match for exclusivity of other companies
Fixed bad format string
cmd-train-console-v20-19627.patch
Version 20 for r19627
(64.2 KiB) Downloaded 1211 times
cmd-train-console-v20-1.0.0.patch
Version 20 for 1.0.0
(64.31 KiB) Downloaded 716 times
cmd-train-console-v20-0.7.2.patch
Version 20 for 0.7.2
(65.1 KiB) Downloaded 767 times
v19:
Fixed few bugs in industry command

v18:
Added ability to perform town authority actions
Added expand/delete for towns (scenario editor only)
Added "and" function to match by multiple conditions

v17:
Many town and industry commands and matches added
Documentation added to wiki

v16:
Added first few town and industry commands
Large internal reoragnization

v15:
fixed bug with depot and service:
using them on vehicle that was already going to depot/service cancelled the order instead
added 'undepot' and 'unservice' commands for cancelling depot and service commands

v14:
Fixed desync with skip to random orders (thanks to Aali)
added 'broken' match to match broken down vehicles
added match for breakdowns since last service

v13:
Vehicle cloning now accepts parameter (how many clones to make) . If not specified, only one clone is created (as in older versions)

v12:
Added fix to allow compilation with MSVC suggested by chris

v11:
Added <> operator (not equal)
Added match for vehicles in depot
Added 'const' where appropriate
Fixed bug with some help entries not being shown
Code cleanup and beautifying

v10:
wagons will match real number of wagons
added wsell command (sell specified wagons from train)
number of required parameters is checked for commands which need them (service, wsell)

v9:
Added wagon info for trains
Removed duplication, as it was causing desyncs and repair would require rewriting parts of pathfinders

v8:
Added lexicographical match by group name ( <, >, = ...)
Added comments, small code cleanup

v7:
Swapped order of command and identifier as it is more consistent with command parameters
subcommand skip accepts parameter (how many orders to skip, 'r' = skip to random order)
Added match by service interval
Added command to change service interval

v6:
match type can be specified also by unambiguous part ("sp=0" instead of "speed=0")
added command "vehicle" that will execute command on all vehicle types where possible
added match by profit (this, last and both years)
added command "count" that will output number of vehicles matching given criteria
code cleanup

v5:
Added commands "rail", "ship" and "aircraft" (with alias "plane") doing the same for other vehicle types.
Not all commands are available for all vehicle types (most are now only for trains, as they are not
finished for other types)
Added match by speed, maximum speed and train length

v4:
Added commands: info, leave, skip, center
Possibility to specify only unique prefix of command (for example "train ser" instead of "train service")

v3:
Duplication added, groups can be referenced now only by its unique prefix in addition to full name, command can also be sent to all crashed trains. Does not try to send unavailable commands to crashed trains (but open or duplicate still works).

There are many operations (selling, cloning, opening windows, centering view, sending to depot, skipping orders ...) that can be performed. For complete list, type the corresponding command (e.g. "train", "plane" ...) without parameters. Target of the commands can be specified by second parameter. It can be single vehicle, group of vehicles, all vehicles or subset of vehicles based on some criteria (speed, length of train ...)

These may be used to ease some tasks.

Some future expansion may include better filtering options by additional criteria - like applying command on trains of certain type (all maglevs, number range, etc ... ) or state (trains near cursor, trains going into certain station)

New commands could also be added (like "extend all 10 wagon trains to 14 wagons")

Example usage:

"train all sell" - this can be used to sell all trains currently stopped in depot. This may ease conversion between railtypes - you usually send all trains to depots, then convert entire network and launch new maglev trains. But after that you have to "hunt down" the old trains in all depots around the network and sell them. Not anymore. "train all sell" can do it for you :)

"train all ignore" - maybe this one should be renamed to "train all crash" as this is roughly what happens :)

"road all turn" ... - Massive bus jam? This may help...

Want to get rid of all unprofitable vehicles?
"vehicle profit<0 depot" ... wait a while for them to get to depots ... "vehicle profit<0 sell" ... they are GONE :)

Mass cloning may some people also find useful (send few trains to depot, then "train all clone_shared", "train all start")

"train service=150 interval 200" - this will raise service interval to 200 days for all trains that have it on 150.

Any oppinions, ideas or bug reports for the patch are welcome.
Last edited by Bilbo on 14 Apr 2010 17:50, edited 33 times in total.
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
benc
Engineer
Engineer
Posts: 62
Joined: 30 Apr 2007 01:57

Post by benc »

Great idea!
Bilbo wrote:Usage: 'train <command> <identifier>'
For me, 'train <identifier> <command>' seems more natural. Either one works though.
Bilbo wrote:'all' for all trains
Can you make '*' an alias for 'all'?

Also, remember there's new code in place in the trunk for grouping trains. Would be nice to be able to:
1) specify normal train commands by group name
2) manage train groups via console
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Post by Bilbo »

benc wrote:Great idea!
Bilbo wrote:Usage: 'train <command> <identifier>'
For me, 'train <identifier> <command>' seems more natural. Either one works though.
Originally I have it as you say, but later I changed it to command, identifier. Maybe I'll change it back, I'll wait for responses from others too ...
benc wrote:
Bilbo wrote:'all' for all trains
Can you make '*' an alias for 'all'?

Also, remember there's new code in place in the trunk for grouping trains. Would be nice to be able to:
1) specify normal train commands by group name
2) manage train groups via console
I have added ability to use name of group as the identifier, as well as * for all. See updated patch. I'll add managing of the groups later ...

Note that matching the group name is case sensitive (as it is in the game, you can have groups "X" and "x" ...)
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
benc
Engineer
Engineer
Posts: 62
Joined: 30 Apr 2007 01:57

Post by benc »

Bilbo wrote:Note that matching the group name is case sensitive (as it is in the game, you can have groups "X" and "x" ...)
Logical but not uber-user-friendly. How about a two-step search? I.e., try to find a case-sensitive match first. If that fails, then do a case-insensitive search.

EDIT: Maybe even a prefix search too? That could get overly complex though, having to resolve ambiguities. Context-sensitive tab completion isn't trivial to implement. ;-)
chrissicom
Route Supervisor
Route Supervisor
Posts: 415
Joined: 07 Oct 2004 10:05

Post by chrissicom »

New commands could also be added (like "extend all 10 wagon trains to 14 wagons")
The ability to do this would be really awesome especially when you use the DB Set XL or similar GRFs. The problem there is when you start in 1920 you will have really tiny wagons and to get a train that is 7 tiles long you can actually have 18 waggons or so. But once you just replace them with big waggons with the autoreplace feature the train will be way too long for short stations since it's 11 or so tiles long then. So... very nice idea :)
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Post by Rubidium »

chrissicom wrote:The ability to do this would be really awesome especially when you use the DB Set XL or similar GRFs. The problem there is when you start in 1920 you will have really tiny wagons and to get a train that is 7 tiles long you can actually have 18 waggons or so. But once you just replace them with big waggons with the autoreplace feature the train will be way too long for short stations since it's 11 or so tiles long then. So... very nice idea :)
Autoreplace already knows that and can keep the train length (almost) equal when you replace short wagons with long wagons.
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Post by Bilbo »

Rubidium wrote:
chrissicom wrote:The ability to do this would be really awesome especially when you use the DB Set XL or similar GRFs. The problem there is when you start in 1920 you will have really tiny wagons and to get a train that is 7 tiles long you can actually have 18 waggons or so. But once you just replace them with big waggons with the autoreplace feature the train will be way too long for short stations since it's 11 or so tiles long then. So... very nice idea :)
Autoreplace already knows that and can keep the train length (almost) equal when you replace short wagons with long wagons.
Still, autoreplace does not know that you have extended all your platforms from 8 to 12 tiles and so you want to replace length of all your ~50 trains accordingly :) Or shorten trains by 1 wagon if you accidentally forgot to turn "wagon removal" on when upgrating from 1 to 2 headed engine. Or do some other more advanced manipulation that autoreplace can't handle
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Post by Bilbo »

benc wrote:
Bilbo wrote:Note that matching the group name is case sensitive (as it is in the game, you can have groups "X" and "x" ...)
Logical but not uber-user-friendly. How about a two-step search? I.e., try to find a case-sensitive match first. If that fails, then do a case-insensitive search.

EDIT: Maybe even a prefix search too? That could get overly complex though, having to resolve ambiguities. Context-sensitive tab completion isn't trivial to implement. ;-)
I'm adding that case-insensitivity - First it tries to match case sensitively, if it fails, it tries case-insensitive match and return it only if the match is unambigous. For example, matching of 'XYZ' against group 'xyz' and 'Xyz' will fail but 'Xyz' or 'xyz' will match appropriate group. I'll implement also prefix search (must be unambigous too). Also, if group name is equal to 'all' or '*', it cannot be matched (clash with special command). Also, if group name consist only of number, now the corresponding group is affected instad of trainn with that id. I may still need to fix this, posibly by adding some thing like n=1 or group=1 or group=all for disambiguating such cases :)

I think there is no auto-completion even for command (I pressed tab in console and it does nothing), so unless there will be code for it, autocompletion of train subcommands or group names won't work either :)
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Post by Bilbo »

I have done matching by prefix and I tried adding new duplication feature, where "train duplicate crashed" will find nearest depot for crashed trains and create copies there (thus solving the crashes quite easily, when something crashes, you use the command to re-create the trains in nearby depot and you do not have to care about it anymore, the wreckage to disappear in time :)

But I have run across a problem in FindClosestTrainDepot. It can't find closest depot for crashed vehicles (When I removed that assert at start of FindClosestTrainDepot I got another in yapf complaining about track_dir)

NPFRouteToDepotBreadthFirstTwoWay also does not work with crashed vehicles and NewTrainPathfind will only find depots directly accesible (if there is any other train between the depot and the crashed train, it fails)

Anybody have a hint how to solve it?
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
benc
Engineer
Engineer
Posts: 62
Joined: 30 Apr 2007 01:57

Post by benc »

Awesome work so far!

The root of the difficulties with FindClosestTrainDepot, of course, is that the path finders weren't designed to work with crashed vehicles. I'm only cursorily familiar with TT's path finders. That didn't stop me from poking around, though. :P

Attached are the non-working results of my fumblings. Basically I was trying to "uncrash" the train just for FindClosestTrainDepot.

I don't think there's an easy fix. Hopefully a path finding guru would have clearer idea, though.
Attachments
uncrash.diff
(21.47 KiB) Downloaded 498 times
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Post by Bilbo »

benc wrote:Awesome work so far!

The root of the difficulties with FindClosestTrainDepot, of course, is that the path finders weren't designed to work with crashed vehicles. I'm only cursorily familiar with TT's path finders. That didn't stop me from poking around, though. :P

Attached are the non-working results of my fumblings. Basically I was trying to "uncrash" the train just for FindClosestTrainDepot.

I don't think there's an easy fix. Hopefully a path finding guru would have clearer idea, though.
Well, technically, I need not to find "way to nearest depot" but actually "way FROM nearest depot", but I rely on fact, that if I find way To nearest depot, it will be good place to create a copy (with a bit of luck it will be ahead of the wreckage, so the cloned train can "continue" the trip and it will be almost certainly on the good track). Therefore there are slight modifications, as for example no reversal penalty applied when looking for "crash recovery" depot

I'll look at the diff and I'll possibly try to "uncrash" the vehicle ...
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
benc
Engineer
Engineer
Posts: 62
Joined: 30 Apr 2007 01:57

Post by benc »

Bilbo wrote:Well, technically, I need not to find "way to nearest depot" but actually "way FROM nearest depot"
Right, but it's still all path finding. :)

EDIT: Actually, why is a backwards search necessary? I don't see why you can't just search forward. It shouldn't be a problem as long as the replacement train is created in a depot on the same circuit.

I don't think the backwards search is implemented properly, either.

Code: Select all

/* Look backwards for source depot */
if (find_source) i = ReverseDiagDir(i);
You're ignoring one-way signals, methinks.
User avatar
benc
Engineer
Engineer
Posts: 62
Joined: 30 Apr 2007 01:57

Post by benc »

Nitpick time... your documentation is growing too big for its britches. :D I.e., the first line or two of train's built-in help message is scrolled away unless you have the console maximized.
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Post by Bilbo »

benc wrote:Nitpick time... your documentation is growing too big for its britches. :D I.e., the first line or two of train's built-in help message is scrolled away unless you have the console maximized.
Yes, you have to scroll the console to see it ... though size of the console depends on size of the window, so some people will see it all, some not.
BTW how do you make the console maximized?
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
belugas
OpenTTD Developer
OpenTTD Developer
Posts: 1507
Joined: 05 Apr 2005 01:48
Location: Deep down the deepest blue
Contact:

Post by belugas »

I was wondering if it had been easier to use an array for those commands.
Like, Use the TrainCommand as the index, gathering the command keywords, the help descriptions, remove the DotranCommand cascades of ifs by a case switch, stuff like that. Maybe more can be added to it.
The GetTrainCommand could iterate the above mentionned array for the keywords finding, as an example...

You may revise your coding style too...
variable=value should be variable = value
condition_value==status1 should be condition_value == status1

GetGroupByName: Replace the tabs before the comments by spaces. If possible, aligned

Just a few suggestions. ;)
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Post by Bilbo »

belugas wrote:I was wondering if it had been easier to use an array for those commands.
Like, Use the TrainCommand as the index, gathering the command keywords, the help descriptions, remove the DotranCommand cascades of ifs by a case switch, stuff like that. Maybe more can be added to it.
The GetTrainCommand could iterate the above mentionned array for the keywords finding, as an example...

You may revise your coding style too...
variable=value should be variable = value
condition_value==status1 should be condition_value == status1

GetGroupByName: Replace the tabs before the comments by spaces. If possible, aligned

Just a few suggestions. ;)
Well, by converting to one switch/case I'll lose the possibility "commands below work only when train in depot...." (when converting to one switch/case I'll have to add "if(!crashed) return;" line to each of the commands)
Still, I can get it to three switch/cases to make it more tidy... or perhaps do it a bit different .... add flags to train_commands[] array (NEED_TRAIN_TO_BE_NOT_CRASHED) and check it extra at once elsewhere. This would allow making it single switch case and it'll be a bit cleaner ...:)

And I'll move the help text to train_commands[] array, this can make it a bit easier. (Now the array also holds aliases, so it can't be directly indexed)

And coding style ... hmm .. Maybe I'll pipe it thru indent ... but I found no setting for it at http://wiki.openttd.org/index.php/Coding_style :)

Still it is a bit beta, but once it'll be done, it should be easily extendable also to buses, ships and planes :)

BTW what's wrong with tabs before comment?
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
belugas
OpenTTD Developer
OpenTTD Developer
Posts: 1507
Joined: 05 Apr 2005 01:48
Location: Deep down the deepest blue
Contact:

Post by belugas »

This would allow making it single switch case and it'll be a bit cleaner ...Smile
That's the whole point ;) PLus, the logic of the data is held in only one place, allowing, as you mentionned it yourself, to easily add new possibilities.

Coding style:
wiki wrote:Put a space before and after binary operators: a + b, a == b, a & b, a <<= b, etc.. Exceptions are ".", "->" and "[]" (no spaces) and "," (just space after it).
You will find no settings for indent since it is not required.
Basically:
wiki wrote: Only use tabs to indent from the start of the line.
Keep in mind tabs indentation are configurable within each editor used. So it's not uniform. What seems to be fine for you will appear broken for somebody else. Consistence is the keyword :)
I understand it is only a beta. One more reason to start it the right way, right from the beginning
8)
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Post by Bilbo »

belugas wrote: Coding style:
wiki wrote:Put a space before and after binary operators: a + b, a == b, a & b, a <<= b, etc.. Exceptions are ".", "->" and "[]" (no spaces) and "," (just space after it).
You will find no settings for indent since it is not required.
Well, my usual habit is not putting space there, so sometimes I may have forgot that style...

Still, some tool that will make svn diff and re-indent things to maintain the style found in rest of the file would be nice :) But I know of no such tool :(
belugas wrote: Keep in mind tabs indentation are configurable within each editor used. So it's not uniform.
I my editor it is 8 spaces and I can't change it (technically I can change it, but having it not 8 will break other things for me). But still, even when not using tabs after the command and before the comment you can't guarantee that comment will be aligned, because of the tabs before. If one line have one tab at start and second line have two tabs, there is no way you can align the comments at end of the lines for someone using different tab width than you by using only spaces
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
Maedhros
OpenTTD Developer
OpenTTD Developer
Posts: 603
Joined: 30 Mar 2006 18:24
Location: Durham, UK

Post by Maedhros »

Bilbo wrote:I my editor it is 8 spaces and I can't change it (technically I can change it, but having it not 8 will break other things for me). But still, even when not using tabs after the command and before the comment you can't guarantee that comment will be aligned, because of the tabs before. If one line have one tab at start and second line have two tabs, there is no way you can align the comments at end of the lines for someone using different tab width than you by using only spaces
That's why we use tabs for the beginning of the line, and spaces for any alignment after that. :)
No-one's more important than the earthworm.
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Post by Bilbo »

Well, I have performed some code cleanup and except the tabs and not-enough-spaces between = and == and so (which I will solve later by piping the source thru some perl script to fix it :) it should be quite clean. Except the duplication feature, which is not basically not working most of the time the rest should work quite well.
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 23 guests