Skip to content
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

Feature: When filtering purchase list by cargo type, make buy button perform a refit if required. #7301

Merged
merged 3 commits into from Mar 24, 2019

Conversation

@PeterN
Copy link
Member

PeterN commented Feb 28, 2019

This solves a user-experience issue where purchasing a vehicle ends up with the 'wrong' cargo type.

This turned out to be quite nasty to implement as testing a refit cost requires a vehicle to be present. This is achieved similarly to how autoreplace works, by buying the vehicle and then selling it again, if in test mode.

@PeterN
Copy link
Member Author

PeterN commented Feb 28, 2019

Well played, "works" with clang, but nothing else. Oops!

@PeterN PeterN force-pushed the PeterN:refit-on-purchase branch from 6187c03 to 61fef5d Feb 28, 2019
@PeterN PeterN marked this pull request as ready for review Mar 2, 2019
@frosch123
Copy link
Member

frosch123 commented Mar 3, 2019

Is it possible to run a test-execute when selecting a vehicle, so stuff like _returned_refit_capacity can be shown?

@PeterN
Copy link
Member Author

PeterN commented Mar 4, 2019

Good idea, that should allow the true cost to be shown as well.

@nielsmh
Copy link
Contributor

nielsmh commented Mar 4, 2019

This might also fix one of the things Samu has been complaining about repeatedly, that NoAI can't query the cost or capacity of a refit without purchasing? Although that would require a new API to purchase a vehicle already refitted too.

@PeterN
Copy link
Member Author

PeterN commented Mar 4, 2019

Hmm, one issue is that the query requires a depot to operate from, so will only work on a purchase list window from a depot.

@glx22
Copy link
Contributor

glx22 commented Mar 5, 2019

Using AITestMode() it's possible to query the cost I think, so it should be possible to add a new parameter to ScriptVehicle::BuildVehicle(). But for the capacity a new function similar to ScriptVehicle::GetRefitCapacity() will be needed.

Copy link
Member

michicc left a comment

Did you check if autoreplace and clone work? BuildReplacementVehicle and CmdCloneVehicle both call CmdBuildVehicle and make separate refits later. As they pass 0 for the cargo type, the vehicles would be refitted to passengers first unless I misread the code somewhere.

@glx22
Copy link
Contributor

glx22 commented Mar 8, 2019

AIs should be able to use this feature with PeterN#1

@PeterN PeterN force-pushed the PeterN:refit-on-purchase branch from 4f416fa to f89b003 Mar 24, 2019
@PeterN
Copy link
Member Author

PeterN commented Mar 24, 2019

@michicc Good catch. I've looked to see whether we can just use the buy & refit functionality for these but they try to preserve cargo subtype, so it's not really feasible. I have updated the calls so they don't do a refit.

@PeterN
Copy link
Member Author

PeterN commented Mar 24, 2019

New functionality, when filtering from a depot view, the extra cost and the refitted cargo capacity are now shown.

@PeterN PeterN force-pushed the PeterN:refit-on-purchase branch from f89b003 to 2f0f344 Mar 24, 2019
@PeterN PeterN force-pushed the PeterN:refit-on-purchase branch from 2f0f344 to 89bc9aa Mar 24, 2019
@PeterN
Copy link
Member Author

PeterN commented Mar 24, 2019

Rebased due to conflict.

@PeterN PeterN merged commit e6bb905 into OpenTTD:master Mar 24, 2019
8 checks passed
8 checks passed
OpenTTD CI Build #20190324.21 succeeded
Details
OpenTTD CI (Linux commit-checker) Linux commit-checker succeeded
Details
OpenTTD CI (Linux linux-amd64-clang-3.8) Linux linux-amd64-clang-3.8 succeeded
Details
OpenTTD CI (Linux linux-amd64-gcc-6) Linux linux-amd64-gcc-6 succeeded
Details
OpenTTD CI (Linux linux-i386-gcc-6) Linux linux-i386-gcc-6 succeeded
Details
OpenTTD CI (MacOS) MacOS succeeded
Details
OpenTTD CI (Windows Win32) Windows Win32 succeeded
Details
OpenTTD CI (Windows Win64) Windows Win64 succeeded
Details
@PeterN PeterN deleted the PeterN:refit-on-purchase branch Mar 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.