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

Fix #8045: [AI/GS] Estimate costs for failed commands #8046

Conversation

SamuXarick
Copy link
Contributor

I'm not sure of this fix in a larger scale. I tested against my AI and it now gets the estimated costs correctly for AIVehicle.CloneVehicle even when it is returned as failed.

Maybe the alternative would be to change CmdCloneVehicle to return true to estimate costs, I'm unsure.

OpenTTD/src/vehicle_cmd.cpp

Lines 978 to 986 in 55e81d3

/* Since we can't estimate the cost of cloning a vehicle accurately we must
* check whether the company has enough money manually. */
if (!CheckCompanyHasMoney(total_cost)) {
if (flags & DC_EXEC) {
/* The vehicle has already been bought, so now it must be sold again. */
DoCommand(w_front->tile, w_front->index | 1 << 20, 0, flags, GetCmdSellVeh(w_front));
}
return total_cost;
}

@frosch123
Copy link
Member

I kind of doubt this is useful.
When command abort due to error, they usually set no cost.

What is your usecase? In what case do you want to get cost, when the operation does not succeed?

@SamuXarick
Copy link
Contributor Author

SamuXarick commented May 10, 2020

The AI queries for the cost of cloning a vehicle in test mode, to get how much it would cost, so that it can borrow the necessary money from bank. It was expected to get the cost, but CmdCloneVehicle returns failed for a command that was supposed to be run in test mode. Even though the cost is already computed, the AI received a £0 as estimate, and once it borrows the 'necessary' money, it tries to clone it in exec mode (and fails, because £0 was the wrong estimate).

@frosch123
Copy link
Member

The comment in vehicle_cmd explicitly states that cost estimates do not work for cloning.

This is the case for all commands with CMD_NO_TEST. Returning a wrong cost does not help either.

@frosch123 frosch123 closed this May 10, 2020
@Yexo
Copy link
Contributor

Yexo commented May 10, 2020

In the more general case the codechange is also wrong: when there are errors the cost is not guaranteed to be meaningfull in any way, which is exactly why it's fixed to 0 for AIs.

This could use an update to the AIVehicle.CloneVehicle documentation to let AI authors know there is no cost estimate available and what would be the alternatives (likely manually checking EngineIDs and get build costs for those).

@SamuXarick
Copy link
Contributor Author

@frosch123 In GUI, the tooltip for cloning vehicle says shift-click to get estimated cost. From a player perspective, I get an error and the required money as the 2nd part of the error message. Why limit that for AI's?

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

3 participants