Changeset - r10493:b82fe3a35854
[Not reviewed]
master
0 6 0
rubidium - 15 years ago 2008-12-26 21:08:51
rubidium@openttd.org
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
6 files changed with 11 insertions and 39 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -459,17 +459,13 @@ CommandCost CmdBuildAircraft(TileIndex t
 
	return value;
 
}
 

	
 

	
 
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.
 
 * @param tile unused
 
 * @param flags for command type
 
 * @param p1 vehicle ID to be sold
src/economy.cpp
Show inline comments
 
@@ -382,16 +382,12 @@ void ChangeOwnershipOfCompanyItems(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;
 
					v->colormap = PAL_NONE;
 
					v->group_id = DEFAULT_GROUP;
 
					if (IsEngineCountable(v)) GetCompany(new_owner)->num_engines[v->engine_type]++;
src/roadveh_cmd.cpp
Show inline comments
 
@@ -341,18 +341,12 @@ CommandCost CmdSellRoadVeh(TileIndex til
 
		return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE);
 
	}
 

	
 
	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;
 
	}
 

	
 
	return ret;
 
}
 

	
 
@@ -534,21 +528,14 @@ static void ClearCrashedStation(Vehicle 
 
static void DeleteLastRoadVeh(Vehicle *v)
 
{
 
	Vehicle *u = 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;
 
}
 

	
 
static byte SetRoadVehPosition(Vehicle *v, int x, int y)
 
{
 
	byte new_z, old_z;
src/ship_cmd.cpp
Show inline comments
 
@@ -860,17 +860,12 @@ CommandCost CmdSellShip(TileIndex tile, 
 
		return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN);
 
	}
 

	
 
	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;
 
	}
 

	
 
	return ret;
 
}
 

	
src/train_cmd.cpp
Show inline comments
 
@@ -1415,13 +1415,12 @@ CommandCost CmdSellRailWagon(TileIndex t
 
				IsTrainEngine(v)) ? v->u.rail.other_multiheaded_part : NULL;
 

	
 
			if (rear != NULL) {
 
				cost.AddCost(-rear->value);
 
				if (flags & DC_EXEC) {
 
					UnlinkWagon(rear, first);
 
					DeleteDepotHighlightOfVehicle(rear);
 
					delete rear;
 
				}
 
			}
 

	
 
			/* 2. We are selling the front vehicle, some special action might be required
 
			 * here, so take attention */
 
@@ -1464,13 +1463,12 @@ CommandCost CmdSellRailWagon(TileIndex t
 
			}
 

	
 
			/* 3. Delete the requested wagon */
 
			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
 
				 * which UnlinkWagon() has changed to TS_Free_Car */
 
				if (switch_engine) SetFrontEngine(first);
 

	
 
@@ -1518,26 +1516,24 @@ CommandCost CmdSellRailWagon(TileIndex t
 
							 * been set it needs to be updated now so that the
 
							 * loop never sees the rear part. */
 
							if (tmp == rear) tmp = GetNextVehicle(tmp);
 

	
 
							if (flags & DC_EXEC) {
 
								first = UnlinkWagon(rear, first);
 
								DeleteDepotHighlightOfVehicle(rear);
 
								delete rear;
 
							}
 
						}
 
					} else if (v->u.rail.other_multiheaded_part != NULL) {
 
						/* The front to this engine is earlier in this train. Do nothing */
 
						continue;
 
					}
 
				}
 

	
 
				cost.AddCost(-v->value);
 
				if (flags & DC_EXEC) {
 
					first = UnlinkWagon(v, first);
 
					DeleteDepotHighlightOfVehicle(v);
 
					delete v;
 
				}
 
			}
 

	
 
			/* 3. If it is still a valid train after selling, update its acceleration and cached values */
 
			if (flags & DC_EXEC && first != NULL) {
 
@@ -3931,30 +3927,22 @@ static void DeleteLastWagon(Vehicle *v)
 
	 * *u is then the one-before-last wagon, and *v the last
 
	 * one which will physicially be removed */
 
	Vehicle *u = 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 -
 
		 * if v == first, then it is updated in PreDestructor() */
 
		if (first->u.rail.track == TRACK_BIT_DEPOT) {
 
			InvalidateWindow(WC_VEHICLE_DEPOT, first->tile);
 
		}
 
	}
 

	
 
	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;
 
	Owner owner = v->owner;
 

	
 
	delete v;
src/vehicle.cpp
Show inline comments
 
@@ -50,12 +50,13 @@
 
#include "depot_map.h"
 
#include "animated_tile_func.h"
 
#include "effectvehicle_base.h"
 
#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"
 

	
 
#define INVALID_COORD (0x7fffffff)
 
#define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6))
 
@@ -665,14 +666,23 @@ void Vehicle::PreDestructor()
 
	}
 

	
 
	if (this->type != VEH_TRAIN || (this->type == VEH_TRAIN && (IsFrontEngine(this) || IsFreeWagon(this)))) {
 
		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);
 
}
 

	
 
Vehicle::~Vehicle()
0 comments (0 inline, 0 general)