diff --git a/src/economy.cpp b/src/economy.cpp index 562f9e2b17..0006c564f6 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -369,7 +369,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) } else { v->owner = new_owner; v->colourmap = PAL_NONE; - if (IsEngineCountable(v)) Company::Get(new_owner)->num_engines[v->engine_type]++; + if (v->IsEngineCountable()) Company::Get(new_owner)->num_engines[v->engine_type]++; if (v->IsPrimaryVehicle()) v->unitnumber = unitidgen[v->type].NextID(); } } diff --git a/src/engine.cpp b/src/engine.cpp index 030b3ca8a7..814f14e409 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -386,7 +386,7 @@ void SetCachedEngineCounts() const Vehicle *v; FOR_ALL_VEHICLES(v) { - if (!IsEngineCountable(v)) continue; + if (!v->IsEngineCountable()) continue; assert(v->engine_type < engines); diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index bd4905268a..7ef41258b9 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -215,7 +215,7 @@ CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, u case VEH_ROAD: case VEH_SHIP: case VEH_AIRCRAFT: - if (IsEngineCountable(v)) UpdateNumEngineGroup(v->engine_type, v->group_id, new_g); + if (v->IsEngineCountable()) UpdateNumEngineGroup(v->engine_type, v->group_id, new_g); v->group_id = new_g; break; } @@ -349,7 +349,7 @@ void SetTrainGroupID(Train *v, GroupID new_g) assert(v->IsFrontEngine()); for (Vehicle *u = v; u != NULL; u = u->Next()) { - if (IsEngineCountable(u)) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g); + if (u->IsEngineCountable()) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g); u->group_id = new_g; } @@ -372,7 +372,7 @@ void UpdateTrainGroupID(Train *v) GroupID new_g = v->IsFrontEngine() ? v->group_id : (GroupID)DEFAULT_GROUP; for (Vehicle *u = v; u != NULL; u = u->Next()) { - if (IsEngineCountable(u)) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g); + if (u->IsEngineCountable()) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g); u->group_id = new_g; } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index bed1d0fcc7..df1059391b 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -473,17 +473,16 @@ uint CountVehiclesInChain(const Vehicle *v) } /** Check if a vehicle is counted in num_engines in each company struct - * @param *v Vehicle to test * @return true if the vehicle is counted in num_engines */ -bool IsEngineCountable(const Vehicle *v) +bool Vehicle::IsEngineCountable() const { - switch (v->type) { - case VEH_AIRCRAFT: return IsNormalAircraft(v); // don't count plane shadows and helicopter rotors + switch (this->type) { + case VEH_AIRCRAFT: return IsNormalAircraft(this); // don't count plane shadows and helicopter rotors case VEH_TRAIN: - return !Train::From(v)->IsArticulatedPart() && // tenders and other articulated parts - !Train::From(v)->IsRearDualheaded(); // rear parts of multiheaded engines - case VEH_ROAD: return RoadVehicle::From(v)->IsRoadVehFront(); + return !Train::From(this)->IsArticulatedPart() && // tenders and other articulated parts + !Train::From(this)->IsRearDualheaded(); // rear parts of multiheaded engines + case VEH_ROAD: return RoadVehicle::From(this)->IsRoadVehFront(); case VEH_SHIP: return true; default: return false; // Only count company buildable vehicles } @@ -501,7 +500,7 @@ void Vehicle::PreDestructor() delete this->cargo_payment; } - if (IsEngineCountable(this)) { + if (this->IsEngineCountable()) { Company::Get(this->owner)->num_engines[this->engine_type]--; if (this->owner == _local_company) InvalidateAutoreplaceWindow(this->engine_type, this->group_id); diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 8cb9e77617..ff8c340009 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -511,6 +511,8 @@ public: { return (this->orders.list == NULL) ? NULL : this->orders.list->GetLastOrder(); } + + bool IsEngineCountable() const; }; #define FOR_ALL_VEHICLES_FROM(var, start) FOR_ALL_ITEMS_FROM(Vehicle, vehicle_index, var, start) diff --git a/src/vehicle_func.h b/src/vehicle_func.h index fa3fbc1b90..5d12ba9ca7 100644 --- a/src/vehicle_func.h +++ b/src/vehicle_func.h @@ -26,7 +26,6 @@ void VehicleServiceInDepot(Vehicle *v); Vehicle *GetLastVehicleInChain(Vehicle *v); const Vehicle *GetLastVehicleInChain(const Vehicle *v); uint CountVehiclesInChain(const Vehicle *v); -bool IsEngineCountable(const Vehicle *v); void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc); void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc); bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);