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 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 marked this pull request as ready for review March 2, 2019 19:39
@frosch123
Copy link
Member

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 michicc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
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.

michicc
michicc previously approved these changes 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
@PeterN PeterN deleted the refit-on-purchase branch March 24, 2019 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants