mirror of https://github.com/OpenTTD/OpenTTD
(svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
parent
73ca72922c
commit
f18043ee21
|
@ -465,7 +465,7 @@ static void DoDeleteAircraft(Vehicle *v)
|
||||||
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
|
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
|
||||||
InvalidateWindow(WC_COMPANY, v->owner);
|
InvalidateWindow(WC_COMPANY, v->owner);
|
||||||
DeleteDepotHighlightOfVehicle(v);
|
DeleteDepotHighlightOfVehicle(v);
|
||||||
DeleteVehicleChain(v);
|
delete v;
|
||||||
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
|
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ static void InitializeDisasterVehicle(Vehicle *v, int x, int y, byte z, Directio
|
||||||
|
|
||||||
static void DeleteDisasterVeh(Vehicle *v)
|
static void DeleteDisasterVeh(Vehicle *v)
|
||||||
{
|
{
|
||||||
DeleteVehicleChain(v);
|
delete v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z)
|
static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z)
|
||||||
|
|
|
@ -383,35 +383,13 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
FOR_ALL_VEHICLES(v) {
|
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) {
|
if (new_owner == INVALID_OWNER) {
|
||||||
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
|
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
|
||||||
DeleteWindowById(WC_VEHICLE_DETAILS, v->index);
|
DeleteWindowById(WC_VEHICLE_DETAILS, v->index);
|
||||||
DeleteWindowById(WC_VEHICLE_ORDERS, v->index);
|
DeleteWindowById(WC_VEHICLE_ORDERS, v->index);
|
||||||
|
|
||||||
if (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && IsFreeWagon(v))) {
|
if (v->Previous() == NULL) delete 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
v->owner = new_owner;
|
v->owner = new_owner;
|
||||||
v->colormap = PAL_NONE;
|
v->colormap = PAL_NONE;
|
||||||
|
|
|
@ -938,6 +938,7 @@ static Vehicle *UnlinkWagon(Vehicle *v, Vehicle *first)
|
||||||
if (v == NULL) return NULL;
|
if (v == NULL) return NULL;
|
||||||
|
|
||||||
if (IsTrainWagon(v)) SetFreeWagon(v);
|
if (IsTrainWagon(v)) SetFreeWagon(v);
|
||||||
|
first->SetNext(NULL);
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
@ -4392,7 +4393,7 @@ void Train::Tick()
|
||||||
TrainLocoHandler(this, true);
|
TrainLocoHandler(this, true);
|
||||||
} else if (IsFreeWagon(this) && HASBITS(this->vehstatus, VS_CRASHED)) {
|
} else if (IsFreeWagon(this) && HASBITS(this->vehstatus, VS_CRASHED)) {
|
||||||
/* Delete flooded standalone wagon chain */
|
/* 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -671,13 +671,6 @@ void Vehicle::PreDestructor()
|
||||||
this->cargo.Truncate(0);
|
this->cargo.Truncate(0);
|
||||||
DeleteVehicleOrders(this);
|
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);
|
extern void StopGlobalFollowVehicle(const Vehicle *v);
|
||||||
StopGlobalFollowVehicle(this);
|
StopGlobalFollowVehicle(this);
|
||||||
}
|
}
|
||||||
|
@ -688,7 +681,15 @@ Vehicle::~Vehicle()
|
||||||
|
|
||||||
if (CleaningPool()) return;
|
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);
|
this->SetNext(NULL);
|
||||||
|
|
||||||
|
delete v;
|
||||||
|
|
||||||
UpdateVehiclePosHash(this, INVALID_COORD, 0);
|
UpdateVehiclePosHash(this, INVALID_COORD, 0);
|
||||||
this->next_hash = NULL;
|
this->next_hash = NULL;
|
||||||
this->next_new_hash = NULL;
|
this->next_new_hash = NULL;
|
||||||
|
@ -698,24 +699,6 @@ Vehicle::~Vehicle()
|
||||||
new (this) InvalidVehicle();
|
new (this) InvalidVehicle();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
* List of vehicles that should check for autoreplace this tick.
|
||||||
* Mapping of vehicle -> leave depot immediatelly after autoreplace.
|
* Mapping of vehicle -> leave depot immediatelly after autoreplace.
|
||||||
|
|
|
@ -27,7 +27,6 @@ Vehicle *GetLastVehicleInChain(Vehicle *v);
|
||||||
const Vehicle *GetLastVehicleInChain(const Vehicle *v);
|
const Vehicle *GetLastVehicleInChain(const Vehicle *v);
|
||||||
uint CountVehiclesInChain(const Vehicle *v);
|
uint CountVehiclesInChain(const Vehicle *v);
|
||||||
bool IsEngineCountable(const Vehicle *v);
|
bool IsEngineCountable(const Vehicle *v);
|
||||||
void DeleteVehicleChain(Vehicle *v);
|
|
||||||
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
||||||
void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
|
void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
|
||||||
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
||||||
|
|
Loading…
Reference in New Issue