summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/aircraft_cmd.cpp2
-rw-r--r--src/disaster_cmd.cpp2
-rw-r--r--src/economy.cpp26
-rw-r--r--src/train_cmd.cpp3
-rw-r--r--src/vehicle.cpp33
-rw-r--r--src/vehicle_func.h1
6 files changed, 14 insertions, 53 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 8d0f911af..b98e25e90 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -465,7 +465,7 @@ static void DoDeleteAircraft(Vehicle *v)
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
InvalidateWindow(WC_COMPANY, v->owner);
DeleteDepotHighlightOfVehicle(v);
- DeleteVehicleChain(v);
+ delete v;
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
}
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index 910918f8c..18ffc26a6 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -148,7 +148,7 @@ static void InitializeDisasterVehicle(Vehicle *v, int x, int y, byte z, Directio
static void DeleteDisasterVeh(Vehicle *v)
{
- DeleteVehicleChain(v);
+ delete v;
}
static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z)
diff --git a/src/economy.cpp b/src/economy.cpp
index cccbf0b93..ccd0cc2b6 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -383,35 +383,13 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
}
FOR_ALL_VEHICLES(v) {
- if (v->owner == old_owner && IsInsideMM(v->type, VEH_TRAIN, VEH_AIRCRAFT + 1)) {
+ if (v->owner == old_owner && IsCompanyBuildableVehicleType(v->type)) {
if (new_owner == INVALID_OWNER) {
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
DeleteWindowById(WC_VEHICLE_DETAILS, v->index);
DeleteWindowById(WC_VEHICLE_ORDERS, v->index);
- if (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && IsFreeWagon(v))) {
- switch (v->type) {
- default: NOT_REACHED();
-
- case VEH_TRAIN: {
- Vehicle *u = v;
- do {
- Vehicle *next = GetNextVehicle(u);
- delete u;
- u = next;
- } while (u != NULL);
- } break;
-
- case VEH_ROAD:
- case VEH_SHIP:
- delete v;
- break;
-
- case VEH_AIRCRAFT:
- DeleteVehicleChain(v);
- break;
- }
- }
+ if (v->Previous() == NULL) delete v;
} else {
v->owner = new_owner;
v->colormap = PAL_NONE;
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 50f50b137..619a3e8a4 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -938,6 +938,7 @@ static Vehicle *UnlinkWagon(Vehicle *v, Vehicle *first)
if (v == NULL) return NULL;
if (IsTrainWagon(v)) SetFreeWagon(v);
+ first->SetNext(NULL);
return v;
}
@@ -4392,7 +4393,7 @@ void Train::Tick()
TrainLocoHandler(this, true);
} else if (IsFreeWagon(this) && HASBITS(this->vehstatus, VS_CRASHED)) {
/* Delete flooded standalone wagon chain */
- if (++this->u.rail.crash_anim_pos >= 4400) DeleteVehicleChain(this);
+ if (++this->u.rail.crash_anim_pos >= 4400) delete this;
}
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index faa042b33..f6dc3514d 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -671,13 +671,6 @@ void Vehicle::PreDestructor()
this->cargo.Truncate(0);
DeleteVehicleOrders(this);
- /* Now remove any artic part. This will trigger an other
- * destroy vehicle, which on his turn can remove any
- * other artic parts. */
- if ((this->type == VEH_TRAIN && EngineHasArticPart(this)) || (this->type == VEH_ROAD && RoadVehHasArticPart(this))) {
- delete this->Next();
- }
-
extern void StopGlobalFollowVehicle(const Vehicle *v);
StopGlobalFollowVehicle(this);
}
@@ -688,7 +681,15 @@ Vehicle::~Vehicle()
if (CleaningPool()) return;
+ /* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles,
+ * it may happen that vehicle chain is deleted when visible */
+ if (!(this->vehstatus & VS_HIDDEN)) MarkSingleVehicleDirty(this);
+
+ Vehicle *v = this->Next();
this->SetNext(NULL);
+
+ delete v;
+
UpdateVehiclePosHash(this, INVALID_COORD, 0);
this->next_hash = NULL;
this->next_new_hash = NULL;
@@ -699,24 +700,6 @@ Vehicle::~Vehicle()
}
/**
- * Deletes all vehicles in a chain.
- * @param v The first vehicle in the chain.
- */
-void DeleteVehicleChain(Vehicle *v)
-{
- assert(v->First() == v);
-
- do {
- Vehicle *u = v;
- /* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles,
- * it may happen that vehicle chain is deleted when visible */
- if (!(v->vehstatus & VS_HIDDEN)) MarkSingleVehicleDirty(v);
- v = v->Next();
- delete u;
- } while (v != NULL);
-}
-
-/**
* List of vehicles that should check for autoreplace this tick.
* Mapping of vehicle -> leave depot immediatelly after autoreplace.
*/
diff --git a/src/vehicle_func.h b/src/vehicle_func.h
index e17b0f39d..4b80ab1c1 100644
--- a/src/vehicle_func.h
+++ b/src/vehicle_func.h
@@ -27,7 +27,6 @@ Vehicle *GetLastVehicleInChain(Vehicle *v);
const Vehicle *GetLastVehicleInChain(const Vehicle *v);
uint CountVehiclesInChain(const Vehicle *v);
bool IsEngineCountable(const Vehicle *v);
-void DeleteVehicleChain(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);