(svn r10756) -Codechange: use vehicle->IsValid in favour of IsValidVehicle(vehicle).
authorrubidium
Thu, 02 Aug 2007 21:19:07 +0000
changeset 7387 c81fff74048b
parent 7386 93f6a042d1c3
child 7388 0a3a9cc1a98b
(svn r10756) -Codechange: use vehicle->IsValid in favour of IsValidVehicle(vehicle).
src/ai/default/default.cpp
src/date.cpp
src/group_cmd.cpp
src/group_gui.cpp
src/vehicle.cpp
src/vehicle.h
--- a/src/ai/default/default.cpp	Thu Aug 02 21:05:54 2007 +0000
+++ b/src/ai/default/default.cpp	Thu Aug 02 21:19:07 2007 +0000
@@ -426,7 +426,7 @@
 {
 	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 @@
 
 	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);
 }
 
--- a/src/date.cpp	Thu Aug 02 21:05:54 2007 +0000
+++ b/src/date.cpp	Thu Aug 02 21:19:07 2007 +0000
@@ -220,7 +220,7 @@
 	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);
 	}
 }
 
--- a/src/group_cmd.cpp	Thu Aug 02 21:05:54 2007 +0000
+++ b/src/group_cmd.cpp	Thu Aug 02 21:19:07 2007 +0000
@@ -358,7 +358,7 @@
  */
 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 @@
 {
 	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 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) {
--- a/src/group_gui.cpp	Thu Aug 02 21:05:54 2007 +0000
+++ b/src/group_gui.cpp	Thu Aug 02 21:19:07 2007 +0000
@@ -557,7 +557,7 @@
 
 					gv->vehicle_sel = v->index;
 
-					if (IsValidVehicle(v)) {
+					if (v->IsValid()) {
 						SetObjectToPlaceWnd(v->GetImage(DIR_W), GetVehiclePalette(v), 4, w);
 					}
 
--- a/src/vehicle.cpp	Thu Aug 02 21:05:54 2007 +0000
+++ b/src/vehicle.cpp	Thu Aug 02 21:19:07 2007 +0000
@@ -332,7 +332,7 @@
 		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 @@
 	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);
 		}
 	}
 
--- a/src/vehicle.h	Thu Aug 02 21:05:54 2007 +0000
+++ b/src/vehicle.h	Thu Aug 02 21:19:07 2007 +0000
@@ -432,6 +432,8 @@
 	 * Calls the tick handler of the vehicle
 	 */
 	virtual void Tick() = 0;
+
+	bool IsValid() const { return this->type != VEH_INVALID; }
 };
 
 /**
@@ -634,14 +636,6 @@
 	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 @@
 	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 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 */