diff options
author | bjarni <bjarni@openttd.org> | 2006-09-08 10:47:39 +0000 |
---|---|---|
committer | bjarni <bjarni@openttd.org> | 2006-09-08 10:47:39 +0000 |
commit | 00a08601c9631282fc921b863843880d30e6fadc (patch) | |
tree | 6807547e48700a8903229c58abafc50330747e2c /vehicle.c | |
parent | f01e761f80ce7f17239a2e477a241a3a18a8c5d2 (diff) | |
download | openttd-00a08601c9631282fc921b863843880d30e6fadc.tar.xz |
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
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
Diffstat (limited to 'vehicle.c')
-rw-r--r-- | vehicle.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -535,8 +535,28 @@ uint CountVehiclesInChain(const Vehicle* v) return count; } +/** Check if a vehicle is counted in num_engines in each player struct + * @param *v Vehicle to test + * @return true if the vehicle is counted in num_engines + */ +bool IsEngineCountable(const Vehicle *v) +{ + switch (v->type) { + case VEH_Aircraft: return (v->subtype <= 2); // don't count plane shadows and helicopter rotors + case VEH_Train: + return !IsArticulatedPart(v) && // tenders and other articulated parts + (!IsMultiheaded(v) || IsTrainEngine(v)); // rear parts of multiheaded engines + case VEH_Road: + case VEH_Ship: + return true; + default: return false; // Only count player buildable vehicles + } +} + void DestroyVehicle(Vehicle *v) { + if (IsEngineCountable(v)) GetPlayer(v->owner)->num_engines[v->engine_type]--; + DeleteVehicleNews(v->index, INVALID_STRING_ID); DeleteName(v->string_id); |