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

AIVehicle.GetBuildWithRefitCapacity returns -1 when at the max num of vehicles #9392

Closed
SamuXarick opened this issue Jun 21, 2021 · 1 comment · Fixed by #9393
Closed

AIVehicle.GetBuildWithRefitCapacity returns -1 when at the max num of vehicles #9392

SamuXarick opened this issue Jun 21, 2021 · 1 comment · Fixed by #9393

Comments

@SamuXarick
Copy link
Contributor

Version of OpenTTD

20210620-master-g6a05839d8d

Expected result

When an AI is at the max num of vehicles, AIVehicle.GetBuildWithRefitCapacity returns the actual capacity

Actual result

When an AI is at the max num of vehicles, AIVehicle.GetBuildWithRefitCapacity returns -1

Steps to reproduce

My AI builds aircraft and reaches the limit. It still continues its aircraft management checking if there are newer engine models available from time to time. I noticed a weird behaviour when Bakewell Luckett LB-9 became available. Normally, the AI would start replacing the old model of choice, the Coleman Count to this new model.
It failed to do so because it was simulating the new income using a capacity of -1 for passengers when using AIVehicle.GetBuildWithRefitCapacity function.

After investigating openttd code, I found that the issue is due to GetFreeUnitNumber not allowing a new vehicle to be temporarily purchased for requesting the refited capacity amount.

UnitID unit_num = (flags & DC_AUTOREPLACE || (type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON)) ? 0 : GetFreeUnitNumber(type);

@SamuXarick SamuXarick changed the title Bug Report AIVehicle.GetBuildWithRefitCapacity returns -1 when at the max num of vehicles Jun 21, 2021
@glx22
Copy link
Contributor

glx22 commented Jun 21, 2021

master...glx22:refit should partially fix the issue (at least when refitting to non default cargo)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants