summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-07-13 16:35:22 +0000
committersmatz <smatz@openttd.org>2009-07-13 16:35:22 +0000
commit868c21cbcc3b04e4e6649417ff94763a82c7d8b5 (patch)
tree5b5c1b451eff9b600077da230411e02dd09ec514 /src
parentbb9fee178da65f6b606e6853821f15a26c1ab3eb (diff)
downloadopenttd-868c21cbcc3b04e4e6649417ff94763a82c7d8b5.tar.xz
(svn r16813) -Codechange: make IsEngineCountable() member of Vehicle
Diffstat (limited to 'src')
-rw-r--r--src/economy.cpp2
-rw-r--r--src/engine.cpp2
-rw-r--r--src/group_cmd.cpp6
-rw-r--r--src/vehicle.cpp15
-rw-r--r--src/vehicle_base.h2
-rw-r--r--src/vehicle_func.h1
6 files changed, 14 insertions, 14 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index 562f9e2b1..0006c564f 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 030b3ca8a..814f14e40 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 bd4905268..7ef41258b 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 bed1d0fcc..df1059391 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 8cb9e7761..ff8c34000 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 fa3fbc1b9..5d12ba9ca 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);