(svn r16813) -Codechange: make IsEngineCountable() member of Vehicle

pull/155/head
smatz 15 years ago
parent 0a1b4912ef
commit 98b8479f56

@ -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();
}
}

@ -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);

@ -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;
}

@ -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);

@ -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)

@ -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);

Loading…
Cancel
Save