summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-12-26 21:08:51 +0000
committerrubidium <rubidium@openttd.org>2008-12-26 21:08:51 +0000
commit3ebe66a5e47531e9033c8552a1abe82ad0ef448f (patch)
treedbb2d01a3da0060c340d6e2adcfcf1188c8f3891
parentf18043ee21218dc9ea26ce41b1294c5212ac363c (diff)
downloadopenttd-3ebe66a5e47531e9033c8552a1abe82ad0ef448f.tar.xz
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
-rw-r--r--src/aircraft_cmd.cpp4
-rw-r--r--src/economy.cpp4
-rw-r--r--src/roadveh_cmd.cpp13
-rw-r--r--src/ship_cmd.cpp5
-rw-r--r--src/train_cmd.cpp14
-rw-r--r--src/vehicle.cpp10
6 files changed, 11 insertions, 39 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index b98e25e90..3f9e6f7e2 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -462,11 +462,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
static void DoDeleteAircraft(Vehicle *v)
{
- DeleteWindowById(WC_VEHICLE_VIEW, v->index);
- InvalidateWindow(WC_COMPANY, v->owner);
- DeleteDepotHighlightOfVehicle(v);
delete v;
- InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
}
/** Sell an aircraft.
diff --git a/src/economy.cpp b/src/economy.cpp
index ccd0cc2b6..22d20f2d1 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -385,10 +385,6 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
FOR_ALL_VEHICLES(v) {
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->Previous() == NULL) delete v;
} else {
v->owner = new_owner;
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 65c040402..e53c133a9 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -344,12 +344,6 @@ CommandCost CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
CommandCost ret(EXPENSES_NEW_VEHICLES, -v->value);
if (flags & DC_EXEC) {
- // Invalidate depot
- InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
- InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
- InvalidateWindow(WC_COMPANY, v->owner);
- DeleteWindowById(WC_VEHICLE_VIEW, v->index);
- DeleteDepotHighlightOfVehicle(v);
delete v;
}
@@ -537,15 +531,8 @@ static void DeleteLastRoadVeh(Vehicle *v)
for (; v->Next() != NULL; v = v->Next()) u = v;
u->SetNext(NULL);
- DeleteWindowById(WC_VEHICLE_VIEW, v->index);
-
- InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
- InvalidateWindow(WC_COMPANY, v->owner);
-
if (IsTileType(v->tile, MP_STATION)) ClearCrashedStation(v);
- MarkSingleVehicleDirty(v);
-
delete v;
}
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index b93433514..029591692 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -863,11 +863,6 @@ CommandCost CmdSellShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
CommandCost ret(EXPENSES_NEW_VEHICLES, -v->value);
if (flags & DC_EXEC) {
- InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
- InvalidateWindowClassesData(WC_SHIPS_LIST, 0);
- InvalidateWindow(WC_COMPANY, v->owner);
- DeleteWindowById(WC_VEHICLE_VIEW, v->index);
- DeleteDepotHighlightOfVehicle(v);
delete v;
}
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 619a3e8a4..40604b55b 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1418,7 +1418,6 @@ CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
cost.AddCost(-rear->value);
if (flags & DC_EXEC) {
UnlinkWagon(rear, first);
- DeleteDepotHighlightOfVehicle(rear);
delete rear;
}
}
@@ -1467,7 +1466,6 @@ CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
cost.AddCost(-v->value);
if (flags & DC_EXEC) {
first = UnlinkWagon(v, first);
- DeleteDepotHighlightOfVehicle(v);
delete v;
/* 4 If the second wagon was an engine, update it to front_engine
@@ -1521,7 +1519,6 @@ CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) {
first = UnlinkWagon(rear, first);
- DeleteDepotHighlightOfVehicle(rear);
delete rear;
}
}
@@ -1534,7 +1531,6 @@ CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
cost.AddCost(-v->value);
if (flags & DC_EXEC) {
first = UnlinkWagon(v, first);
- DeleteDepotHighlightOfVehicle(v);
delete v;
}
}
@@ -3934,11 +3930,7 @@ static void DeleteLastWagon(Vehicle *v)
for (; v->Next() != NULL; v = v->Next()) u = v;
u->SetNext(NULL);
- if (first == v) {
- /* Removing front vehicle (the last to go) */
- DeleteWindowById(WC_VEHICLE_VIEW, v->index);
- InvalidateWindow(WC_COMPANY, v->owner);
- } else {
+ if (first != v) {
/* Recalculate cached train properties */
TrainConsistChanged(first, false);
/* Update the depot window if the first vehicle is in depot -
@@ -3948,10 +3940,6 @@ static void DeleteLastWagon(Vehicle *v)
}
}
- InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
-
- MarkSingleVehicleDirty(v);
-
/* 'v' shouldn't be accessed after it has been deleted */
TrackBits trackbits = v->u.rail.track;
TileIndex tile = v->tile;
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index f6dc3514d..6e1af2333 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -53,6 +53,7 @@
#include "core/alloc_func.hpp"
#include "core/smallmap_type.hpp"
#include "vehiclelist.h"
+#include "depot_func.h"
#include "table/sprites.h"
#include "table/strings.h"
@@ -668,8 +669,17 @@ void Vehicle::PreDestructor()
InvalidateWindowData(WC_VEHICLE_DEPOT, this->tile);
}
+ if (this->IsPrimaryVehicle()) {
+ DeleteWindowById(WC_VEHICLE_VIEW, this->index);
+ DeleteWindowById(WC_VEHICLE_DETAILS, this->index);
+ DeleteWindowById(WC_VEHICLE_ORDERS, this->index);
+ InvalidateWindow(WC_COMPANY, this->owner);
+ }
+ InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type), 0);
+
this->cargo.Truncate(0);
DeleteVehicleOrders(this);
+ DeleteDepotHighlightOfVehicle(this);
extern void StopGlobalFollowVehicle(const Vehicle *v);
StopGlobalFollowVehicle(this);