(svn r8294) -Fix: deleting a vehicle with shared orders, but no orders would fail to reset prev_shared and next_shared
authorbjarni
Sun, 21 Jan 2007 00:13:39 +0000
changeset 5746 ab94eb9bdde6
parent 5745 c8069ea3af5d
child 5747 ba5393ff957a
(svn r8294) -Fix: deleting a vehicle with shared orders, but no orders would fail to reset prev_shared and next_shared
-As a result, vehicles in the game could end up having prev/next pointers to vehicles, that was no longer in the game
src/vehicle.cpp
src/vehicle.h
--- a/src/vehicle.cpp	Sun Jan 21 00:01:47 2007 +0000
+++ b/src/vehicle.cpp	Sun Jan 21 00:13:39 2007 +0000
@@ -572,7 +572,7 @@
 
 	UpdateVehiclePosHash(v, INVALID_COORD, 0);
 	v->next_hash = NULL;
-	if (v->orders != NULL) DeleteVehicleOrders(v);
+	if (IsPlayerBuildableVehicleType(v)) DeleteVehicleOrders(v);
 
 	/* Now remove any artic part. This will trigger an other
 	 *  destroy vehicle, which on his turn can remove any
--- a/src/vehicle.h	Sun Jan 21 00:01:47 2007 +0000
+++ b/src/vehicle.h	Sun Jan 21 00:13:39 2007 +0000
@@ -407,6 +407,18 @@
 	v->type = 0;
 }
 
+static inline bool IsPlayerBuildableVehicleType(const Vehicle *v)
+{
+	switch (v->type) {
+		case VEH_Train:
+		case VEH_Road:
+		case VEH_Ship:
+		case VEH_Aircraft:
+			return true;
+	}
+	return false;
+}
+
 #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(v) FOR_ALL_VEHICLES_FROM(v, 0)