diff options
-rw-r--r-- | src/ai/default/default.cpp | 4 | ||||
-rw-r--r-- | src/date.cpp | 2 | ||||
-rw-r--r-- | src/group_cmd.cpp | 6 | ||||
-rw-r--r-- | src/group_gui.cpp | 2 | ||||
-rw-r--r-- | src/vehicle.cpp | 4 | ||||
-rw-r--r-- | src/vehicle.h | 14 |
6 files changed, 13 insertions, 19 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp index 5df2b5930..7235ab704 100644 --- a/src/ai/default/default.cpp +++ b/src/ai/default/default.cpp @@ -426,7 +426,7 @@ static void AiStateCheckReplaceVehicle(Player *p) { const Vehicle* v = p->ai.cur_veh; - if (!IsValidVehicle(v) || + if (!v->IsValid() || v->owner != _current_player || v->type > VEH_SHIP || _veh_check_replace_proc[v->type - VEH_TRAIN](p, v) == INVALID_ENGINE) { @@ -443,7 +443,7 @@ static void AiStateDoReplaceVehicle(Player *p) p->ai.state = AIS_VEH_LOOP; // vehicle is not owned by the player anymore, something went very wrong. - if (!IsValidVehicle(v) || v->owner != _current_player) return; + if (!v->IsValid() || v->owner != _current_player) return; _veh_do_replace_proc[v->type - VEH_TRAIN](p); } diff --git a/src/date.cpp b/src/date.cpp index 168f127c1..315c35db8 100644 --- a/src/date.cpp +++ b/src/date.cpp @@ -220,7 +220,7 @@ static void RunVehicleDayProc(uint daytick) for (i = daytick; i < total; i += DAY_TICKS) { Vehicle *v = GetVehicle(i); - if (IsValidVehicle(v)) _on_new_vehicle_day_proc[v->type](v); + if (v->IsValid()) _on_new_vehicle_day_proc[v->type](v); } } diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index ddfd522d5..b8e68fbbf 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -358,7 +358,7 @@ CommandCost CmdSetGroupReplaceProtection(TileIndex tile, uint32 flags, uint32 p1 */ void RemoveVehicleFromGroup(const Vehicle *v) { - if (!IsValidVehicle(v) || !(v->HasFront() && v->IsPrimaryVehicle())) return; + if (!v->IsValid() || !(v->HasFront() && v->IsPrimaryVehicle())) return; if (!IsDefaultGroupID(v->group_id)) DecreaseGroupNumVehicle(v->group_id); } @@ -374,7 +374,7 @@ void SetTrainGroupID(Vehicle *v, GroupID new_g) { if (!IsValidGroupID(new_g) && !IsDefaultGroupID(new_g)) return; - assert(IsValidVehicle(v) && v->type == VEH_TRAIN && IsFrontEngine(v)); + assert(v->IsValid() && v->type == VEH_TRAIN && IsFrontEngine(v)); for (Vehicle *u = v; u != NULL; u = u->next) { if (IsEngineCountable(u)) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g); @@ -396,7 +396,7 @@ void SetTrainGroupID(Vehicle *v, GroupID new_g) */ void UpdateTrainGroupID(Vehicle *v) { - assert(IsValidVehicle(v) && v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))); + assert(v->IsValid() && v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))); GroupID new_g = IsFrontEngine(v) ? v->group_id : (GroupID)DEFAULT_GROUP; for (Vehicle *u = v; u != NULL; u = u->next) { diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 179845f6b..95708ed3a 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -557,7 +557,7 @@ static void GroupWndProc(Window *w, WindowEvent *e) gv->vehicle_sel = v->index; - if (IsValidVehicle(v)) { + if (v->IsValid()) { SetObjectToPlaceWnd(v->GetImage(DIR_W), GetVehiclePalette(v), 4, w); } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index fbc061c62..86a87c5c6 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -332,7 +332,7 @@ Vehicle *ForceAllocateSpecialVehicle() if (v->index >= (1 << Vehicle_POOL_BLOCK_SIZE_BITS) * BLOCKS_FOR_SPECIAL_VEHICLES) return NULL; - if (!IsValidVehicle(v)) return InitializeVehicle(v); + if (!v->IsValid()) return InitializeVehicle(v); } return NULL; @@ -358,7 +358,7 @@ static Vehicle *AllocateSingleVehicle(VehicleID *skip_vehicles) if (*skip_vehicles < (_Vehicle_pool.GetSize() - offset)) { // make sure the offset in the array is not larger than the array itself for (v = GetVehicle(offset + *skip_vehicles); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) { (*skip_vehicles)++; - if (!IsValidVehicle(v)) return InitializeVehicle(v); + if (!v->IsValid()) return InitializeVehicle(v); } } diff --git a/src/vehicle.h b/src/vehicle.h index 207893c34..0ff3c247f 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -432,6 +432,8 @@ struct Vehicle { * Calls the tick handler of the vehicle */ virtual void Tick() = 0; + + bool IsValid() const { return this->type != VEH_INVALID; } }; /** @@ -634,14 +636,6 @@ static inline uint GetNumVehicles() return GetVehiclePoolSize(); } -/** - * Check if a Vehicle really exists. - */ -static inline bool IsValidVehicle(const Vehicle *v) -{ - return v->type != VEH_INVALID; -} - void DestroyVehicle(Vehicle *v); static inline void DeleteVehicle(Vehicle *v) @@ -668,7 +662,7 @@ static inline bool IsPlayerBuildableVehicleType(const Vehicle *v) return IsPlayerBuildableVehicleType(v->type); } -#define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) if (IsValidVehicle(v)) +#define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) if (v->IsValid()) #define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0) /** @@ -678,7 +672,7 @@ static inline bool IsPlayerBuildableVehicleType(const Vehicle *v) */ static inline bool IsValidVehicleID(uint index) { - return index < GetVehiclePoolSize() && IsValidVehicle(GetVehicle(index)); + return index < GetVehiclePoolSize() && GetVehicle(index)->IsValid(); } /* Returns order 'index' of a vehicle or NULL when it doesn't exists */ |