When an AI is at the max num of vehicles, AIVehicle.GetBuildWithRefitCapacity returns the actual capacity
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.