This is only possible in SP (or in the intro menu). During game play you will
get a confirmation window when applying the changes as some actions can crash
OpenTTD and/or make your current game unplayable.
This turned out to be due to continue to drag the old vehicle, that autoreplace sold
This could also be triggered if more than one player used the same company
Now deleting a vehicle will remove all depot highlights of that vehicle
This should prevent a vehicle from failing to be refitted and then show up and block a station with full load.
In such a case, it's better to stop in a depot (that will not stop any other vehicles) and notify the owner
This gives the ability to invalidate some window data and recalculate as needed instead of doing it for each WE_PAINT
This event is called right away when using InvalidateWindowData(), so it may be a good idea to set a bool or similar in the window
or similar and then act on that bool in WE_PAINT instead of doing a lot of stuff in WE_INVALIDATE_DATA as it might be called more than once before WE_PAINT is called
InvalidateWindowData() will not automatically repaint the window, so if you want to repaint it as well, you need to mark it dirty as well.
Made the depot windows use WE_INVALIDATE_DATA to set when to generate the engine and wagon lists instead of at each redraw
It makes no sense to regenerate the list when say using the scrollbar if we know that no vehicle have entered or left the list
NOTE: currently there is a piece of code to generate the list when it's not needed and compare it to the stored list and assert if they mismatch
This check is somewhat slow and kills the whole idea of WE_INVALIDATE_DATA, so it's a short lived one to verify that InvalidateWindowData() is used everywhere where it's needed
Say we got 40k for selling the old one and the new one costs 60k, then the player only needs 20k to replace
The new engine is still built before selling the old one for various reasons, but now the player gets a loan
of the sell value, which is always repaid when replace fails or the old engine is sold. The player will never notice this loan.
This revealed duplicated code like aircraft lists got invalidated twice
Moved invalidation of the vehicle detail window to VehicleServiceInDepot() as it should always be updated when serviced
Example: make a train transport iron ore from A to B, then it visits a depot and refits to steel
It then transport steel back to A or near A if there is a factory and then it visits another depot to refit to iron ore again
This is controlled in the orders. If a goto depot order is lightlighted, then "Unload" changes to "Refit"
Control click "Refit" removes the refit part of the order (as the tooltip says)
The player will still pay the normal refit costs
Known issues:
If a vehicle is not in a depot, then the refit window will fail to tell refitted cargo capacity
Refit costs in the refit window can sometimes print 0 when it should not because the refit calculation is unaware that the vehicle will be refitted in between
Warning: autoreplace got a protection against replacing something so you get a new cargo type, but it can fail here. In the iron ore/steel example, it can see that
the vehicle carries iron ore and the new one can be refitted to iron ore, then it will replace. It will not check to see that it's valid for steel as well.
This is something to look into in the future
It got one known issue though. The top bar got a plural issue so expect to see stuff like "1 trains" until we figure out why it behaves this way
Added the button to the depot windows. Made the autoreplace button bigger while I was moving some widgets anyway
Made road vehicle depot windows start with one more row to make room for the buttons
This will prevent some reallocations when sorting vehicle list windows
It also prevents moving the whole array into a new one each time the list is generated/updated (it used to make the list in one array and then move it into another one each time)
Also ensured that neither GenerateVehicleSortList() or BuildDepotVehicleList() will never allocate lists longer than the total number of vehicles in the game
It's right below the sell button (sell whole chain button for trains)
It's still missing a sprite. That one will be added as soon as anybody draws something we can use
To make room for this button, all depots except train depots now opens with an additional row and can't be resized shorter than that
This will ensure that you can always get the same list when checking for vehicles in a depot (no need to duplicate code for each place, that needs such a list)
Since the vehicles are only looped once for each redraw, drawing speed is around twice as fast (measured to be 114%-121% faster depending on the number of vehicles in the game)
We should only reach this error() if there is a bug, that would otherwise make the vehicles carry a different type of cargo without telling the user
This also kills the warning added in r6464 (oops)
added an error popup in the game if autoreplace fails to refit
Since it's only triggered by conditions bugs can trigger, it works kind of like a non-fatal assert in builds without asserts
To do this, the player struct contains an array, that contains the count of each engine type that the player owns
Those arrays are updated each time a vehicle is build or deleted and is calculated on load (it's not saved)
It's possible to access the arrays outside of the autoreplace GUI, so feel free to read from them in other patches as well
-Fix: [autoreplace] fixed a very rare failure when building an engine could cost more than the player could pay before selling the old one
this happened when the replacing the front cost so much that the the rear end didn't have enough money to build as expected
now the estimate keeps track of the price for the wagons/engines in front of the unit it's currently looking at
-Codechange: [autoreplace] added function to learn if and what cargo type to refit to. Needed to allow the estimation to tell refit costs