Changeset - r12373:30da669f3dfa
[Not reviewed]
master
0 6 0
smatz - 15 years ago 2009-07-13 16:35:22
smatz@openttd.org
(svn r16813) -Codechange: make IsEngineCountable() member of Vehicle
6 files changed with 14 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -369,7 +369,7 @@ void ChangeOwnershipOfCompanyItems(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();
 
				}
 
			}
src/engine.cpp
Show inline comments
 
@@ -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);
 

	
src/group_cmd.cpp
Show inline comments
 
@@ -215,7 +215,7 @@ CommandCost CmdAddVehicleGroup(TileIndex
 
			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 n
 
	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;
 
	}
src/vehicle.cpp
Show inline comments
 
@@ -473,17 +473,16 @@ uint CountVehiclesInChain(const Vehicle 
 
}
 

	
 
/** 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);
 

	
src/vehicle_base.h
Show inline comments
 
@@ -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)
src/vehicle_func.h
Show inline comments
 
@@ -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);
0 comments (0 inline, 0 general)