summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vehicle.c29
-rw-r--r--vehicle.h9
2 files changed, 20 insertions, 18 deletions
diff --git a/vehicle.c b/vehicle.c
index 4800aa3de..dcd10e3e2 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -528,26 +528,21 @@ uint CountVehiclesInChain(const Vehicle* v)
return count;
}
-void DeleteVehicle(Vehicle *v)
+void DestroyVehicle(Vehicle *v)
{
- Vehicle *u;
- bool has_artic_part = false;
-
DeleteVehicleNews(v->index, INVALID_STRING_ID);
- do {
- u = v->next;
- has_artic_part = EngineHasArticPart(v);
- DeleteName(v->string_id);
- if (v->type == VEH_Road) ClearSlot(v);
- v->type = 0;
- UpdateVehiclePosHash(v, INVALID_COORD, 0);
- v->next_hash = INVALID_VEHICLE;
-
- if (v->orders != NULL)
- DeleteVehicleOrders(v);
- v = u;
- } while (v != NULL && has_artic_part);
+ DeleteName(v->string_id);
+ if (v->type == VEH_Road) ClearSlot(v);
+
+ UpdateVehiclePosHash(v, INVALID_COORD, 0);
+ v->next_hash = INVALID_VEHICLE;
+ if (v->orders != NULL) DeleteVehicleOrders(v);
+
+ /* Now remove any artic part. This will trigger an other
+ * destroy vehicle, which on his turn can remove any
+ * other artic parts. */
+ if (EngineHasArticPart(v)) DeleteVehicle(v->next);
}
void DeleteVehicleChain(Vehicle *v)
diff --git a/vehicle.h b/vehicle.h
index 694caba50..73bca86b2 100644
--- a/vehicle.h
+++ b/vehicle.h
@@ -255,7 +255,6 @@ Vehicle *GetLastVehicleInChain(Vehicle *v);
Vehicle *GetPrevVehicleInChain(const Vehicle *v);
Vehicle *GetFirstVehicleInChain(const Vehicle *v);
uint CountVehiclesInChain(const Vehicle* v);
-void DeleteVehicle(Vehicle *v);
void DeleteVehicleChain(Vehicle *v);
void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
void CallVehicleTicks(void);
@@ -377,6 +376,14 @@ static inline bool IsValidVehicle(const Vehicle *v)
return v->type != 0;
}
+void DestroyVehicle(Vehicle *v);
+
+static inline void DeleteVehicle(Vehicle *v)
+{
+ DestroyVehicle(v);
+ v->type = 0;
+}
+
#define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1 < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) if (IsValidVehicle(v))
#define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0)