-
-
Notifications
You must be signed in to change notification settings - Fork 880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copy wagon configuration to all trains in shared orders/group. #10476
base: master
Are you sure you want to change the base?
Copy wagon configuration to all trains in shared orders/group. #10476
Conversation
How would this be different to the functionality that already exists in the "Replace vehicles"? |
So the scenario for my feature is like that: What I propose, you pick 1 train, get it to depot and do whatever needs to be done to its wagons: add, remove, reorder. Then open some train group, either |
aac7b82
to
b3a765c
Compare
b3a765c
to
3616668
Compare
This is an interesting alternative to defining train templates (which there is an example patch for in JGRPP). Templates are quite complex and require complicated new UI. This looks more lightweight. A suitable name might be 'match', but I'm not sure. Possibilities from the thesaurus: 'replicate', 'facsimile', 'correspond', 'harmonise', 'conform'. |
3616668
to
ae3b46d
Compare
ae3b46d
to
87cc454
Compare
87cc454
to
a1e606f
Compare
CMakeLists.txt
Outdated
@@ -340,6 +340,8 @@ if(EMSCRIPTEN) | |||
# Build the .html (which builds the .js, .wasm, and .data too). | |||
set_target_properties(openttd PROPERTIES SUFFIX ".html") | |||
target_link_libraries(openttd WASM::WASM) | |||
file(COPY ${CMAKE_SOURCE_DIR}/os/emscripten/demo.sav |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't mind this line. I wanted to include a demo save file into the browser version of the game. So ppl can try the functionality if any question.
Before merging I will revert this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It applies to files CMakeLists.txt
and os/emscripten/demo.sav
Thanks for the feedback. In my latest version I use these for button label:
I'm still hesitant, so feel free to point which one you like more or propose if you have another variant. |
6927283
to
a1e606f
Compare
Yes. Road vehicles, trams, ships and aircrafts cannot have attachable wagons (though the first two can be articulated units).
Yes.
Cargo types are like passenger, mail, goods, coal, etc. Subtypes determine different graphics (and maybe capacity and other properties) to be used for what the game regards as one cargo type. There are two main applications for them in NewGRFs (which I'm aware of):
You should try playing with various vehicle NewGRFs to check how your feature works with them. |
a1e606f
to
c0c424c
Compare
c0c424c
to
2b26885
Compare
2b26885
to
d186ae4
Compare
Sorry, I can't give a list of grfs which use these features. My opinion is that they're not features grfs should be using, but fortunately grf authors have the freedom to ignore me :) |
d186ae4
to
1d29278
Compare
Thanks! I just read a bunch of wikis about the callbacks trying to understand how they work and I feel like a grandma with a smartphone =) Just curious, is it possible to put a whatever logic like compiled or scripted code into GRFs or it's more like some predefined actions that you may configure? But anyway my feature is using just some standard commands like buy, sell, refit and move vehicles, so all the callbacks should be covered and if anything, it should handle everything gracefully, maximum popping an error. Plus the feature requires a functioning target that user creates by hand, so it should be at least structurally correct. The only situation I can image is copying a vehicle after its end-of-life. But I'm not sure if end-of-life applies to wagons at all, I only saw it for engines. And again if any encountered, it must be just another normal game error. |
I think the PR is ready for review. |
Hi @2TallTyler How do I proceed with the PR to get reviewed and merged? Initially it was a draft. But couple days ago as I finished coding I turned it into a normal PR to indicate it is ready for review. I'm not sure what is the process, do I need to somehow signal about it, so devs take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a load of nitpicky codestyle things to start with :)
src/vehicle.cpp
Outdated
* Sets a target for this vehicle to copy wagons from | ||
* @param src - source vehicle to copy wagons from | ||
*/ | ||
void Vehicle::CopyWagonsFrom(VehicleID src) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opening brace goes on its own line
src/vehicle.cpp
Outdated
StringID error_message = res.GetErrorMessage(); | ||
if (error_message == STR_ERROR_AUTOREPLACE_NOTHING_TO_DO || error_message == INVALID_STRING_ID) continue; | ||
// Copy wagons from another train | ||
if (v->type == VehicleType::VEH_TRAIN && v->copy_wagons_from != v->index){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing space (various other places too)
if (v->type == VehicleType::VEH_TRAIN && v->copy_wagons_from != v->index){ | |
if (v->type == VehicleType::VEH_TRAIN && v->copy_wagons_from != v->index) { |
|
||
if (example->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED); | ||
|
||
for (const Vehicle *v: vl) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (const Vehicle *v: vl) { | |
for (const Vehicle *v : vl) { |
src/vehicle_cmd.cpp
Outdated
} | ||
} | ||
if (replacement == nullptr) { | ||
// we didn't find enough matching wagons, we have to buy a new one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multi line comments, or comments on their own line should use /* */
src/vehicle_cmd.cpp
Outdated
assert(d_prev != nullptr); | ||
} | ||
} | ||
//When we finish copying all the source wagon units, it needs to sell the leftovers if any. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing space
src/vehicle_gui_base.h
Outdated
@@ -154,6 +159,14 @@ struct BaseVehicleListWindow : public Window { | |||
NOT_REACHED(); | |||
} | |||
} | |||
|
|||
bool OnVehicleSelect(const struct Vehicle *v) override { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unneeded struct
src/vehicle_cmd.cpp
Outdated
* Performs copy wagons operation for a train. | ||
* @param flags type of operation | ||
* @param train train to copy wagons to from its target (train->copy_wagons_from) | ||
* @return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing doc :)
@LordAro Is there a linter or extension fo clion/visual studio code/anything else that can help me avoid all these code-style things that I miss? Smth that I can run on mac. |
Practically speaking, no, I'm afraid not - we've experimented with various things in the past but none of them really work well with OTTD's style (particularly when it purposefully deviates from it) |
Ok, then I'll manually go through your comments and similar places in the change. |
@LordAro I decided to add some code changes into the PR and thus have a question regarding command flags and In my algorithm I perform these kinds of operations with vehicles(wagons): build, refit, move, sell.
If I would decide by myself, I'd go with approach#1 as I think it will be a simpler and cleaner code. But can you suggest is there a recommended way of implementing command's behavior when flags == DC_NONE? |
1d29278
to
8c1ade5
Compare
8c1ade5
to
5a7c9c6
Compare
This is a draft. No code-review required yet. I just wanted to initiate a discussion first.
Motivation / Problem
We have a great feature called auto-replacement and it works really great for engines and saves time. But there is a similar process that players have to do manually. It is to update their trains with more/new/other train cars(wagons). It is no fun cause it's a tedious process , it takes time to watch all the trains in a group and plus it messes up with the timetables if played without PAUSE.
Description
I know there is a patch
Template Based Train Replacement
. But I play vanila and don't know the status of that patch, although the idea looks really cool.How I see my solution? I want it to be simple and interfere with the existing code/logic as little as possible.
I see it as a button somewhere at the vehicle group window, so player can to click the button and then select some train as a target(similar to clone vehicle). When selected, all vehicles in the group are marked as to be refitted(not really, but it's the closest existing term).
Later on, when a marked vehicle enters a depot, it gets refitted. Which means, it will compare its wagons to the ones of the target and fix the difference. Once done, the vehicle clears its status and doesn't need to do the procedure until again explicitly marked by player.
Limitations
This functionality is only applicable to trains as I don't know of any other transports with non-engine units.
As I'm very new to OpenTTD, it would be great if I can get help with the following questions. Just keep in mind, I didn't even play any non-default NewGRFs.
Copy (wagons|train cars) from
. But I'm open to proposals.Thanks
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.