diff options
author | bjarni <bjarni@openttd.org> | 2007-02-07 19:10:19 +0000 |
---|---|---|
committer | bjarni <bjarni@openttd.org> | 2007-02-07 19:10:19 +0000 |
commit | 037d6367349afa5a27ddf2cf015f6490167cf786 (patch) | |
tree | b16bae58b03b0c68fe0ab88a8311dd7f6406238a /src/vehicle.cpp | |
parent | 5666d8d7272ff24116049757dc2405b55cfd4b97 (diff) | |
download | openttd-037d6367349afa5a27ddf2cf015f6490167cf786.tar.xz |
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
This means that "v->type" can be used as array indexes instead of VehTypeToIndex() (or "v->type - VEH_Train/0x10 as the code still used in some places)
Surprisingly this can be done without changing the savegame format
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r-- | src/vehicle.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp index dc06601c2..bdee6fcd5 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -84,7 +84,10 @@ static void VehiclePoolNewBlock(uint start_item) /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. * TODO - This is just a temporary stage, this will be removed. */ - for (v = GetVehicle(start_item); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) v->index = start_item++; + for (v = GetVehicle(start_item); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) { + v->index = start_item++; + v->type = VEH_Invalid; + } } /* Initialize the vehicle-pool */ @@ -263,6 +266,7 @@ static Vehicle *InitializeVehicle(Vehicle *v) assert(v->orders == NULL); + v->type = VEH_Invalid; v->left_coord = INVALID_COORD; v->first = NULL; v->next = NULL; @@ -656,7 +660,7 @@ void CallVehicleTicks(void) _first_veh_in_depot_list = NULL; // now we are sure it's initialized at the start of each tick FOR_ALL_VEHICLES(v) { - _vehicle_tick_procs[v->type - 0x10](v); + _vehicle_tick_procs[v->type](v); switch (v->type) { case VEH_Train: @@ -1568,7 +1572,7 @@ static void ShowVehicleGettingOld(Vehicle *v, StringID msg) // Do not show getting-old message if autorenew is active if (GetPlayer(v->owner)->engine_renew) return; - SetDParam(0, _vehicle_type_names[v->type - 0x10]); + SetDParam(0, _vehicle_type_names[v->type]); SetDParam(1, v->unitnumber); AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); } @@ -2569,7 +2573,7 @@ void VehicleEnterDepot(Vehicle *v) v->leave_depot_instantly = false; // We ensure that the vehicle stays in the depot if (v->owner == _local_player) { /* Notify the user that we stopped the vehicle */ - SetDParam(0, _vehicle_type_names[v->type - 0x10]); + SetDParam(0, _vehicle_type_names[v->type]); SetDParam(1, v->unitnumber); AddNewsItem(STR_ORDER_REFIT_FAILED, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); } @@ -3212,7 +3216,7 @@ static void Save_VEHS(void) // Write the vehicles FOR_ALL_VEHICLES(v) { SlSetArrayIndex(v->index); - SlObject(v, (SaveLoad*)_veh_descs[v->type - 0x10]); + SlObject(v, (SaveLoad*)_veh_descs[v->type]); } } |