summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-05-31 12:03:14 +0000
committerfrosch <frosch@openttd.org>2009-05-31 12:03:14 +0000
commit9853c0dc224e01cf3394336ab074cbb18592bd5b (patch)
tree8beff2dc7ba4f4426c471c831bbd7b62c0b8d0e6 /src
parent56988b198d6657cda7a404d2f13c0d50ec3eed06 (diff)
downloadopenttd-9853c0dc224e01cf3394336ab074cbb18592bd5b.tar.xz
(svn r16480) -Fix (r15617): Invalidate newgrf variable caches of more vehicles in more places. Esp. they were only invalidated for trains.
Diffstat (limited to 'src')
-rw-r--r--src/aircraft_cmd.cpp5
-rw-r--r--src/misc_cmd.cpp2
-rw-r--r--src/newgrf_engine.cpp2
-rw-r--r--src/roadveh_cmd.cpp5
-rw-r--r--src/ship_cmd.cpp5
-rw-r--r--src/train_cmd.cpp9
-rw-r--r--src/vehicle_base.h20
7 files changed, 44 insertions, 4 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 94be6a9b6..134ca6081 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -373,6 +373,8 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
v->vehicle_flags = 0;
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
+ v->InvalidateNewGRFCacheOfChain();
+
if (v->cargo_type != CT_PASSENGERS) {
uint16 callback = CALLBACK_FAILED;
@@ -391,6 +393,8 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
u->cargo_cap = 0;
}
+ v->InvalidateNewGRFCacheOfChain();
+
UpdateAircraftCache(v);
VehicleMove(v, false);
@@ -566,6 +570,7 @@ CommandCost CmdRefitAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
v->cargo_type = new_cid;
v->cargo_subtype = new_subtype;
v->colourmap = PAL_NONE; // invalidate vehicle colour map
+ v->InvalidateNewGRFCacheOfChain();
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp
index d79ab92b9..1e5365d0c 100644
--- a/src/misc_cmd.cpp
+++ b/src/misc_cmd.cpp
@@ -122,7 +122,7 @@ CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1,
/* Company colour data is indirectly cached. */
Vehicle *v;
FOR_ALL_VEHICLES(v) {
- if (v->owner == _current_company) v->vcache.cache_valid = 0;
+ if (v->owner == _current_company) v->InvalidateNewGRFCache();
}
}
return CommandCost();
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 9ea0152eb..9d8f25639 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -1098,7 +1098,9 @@ void TriggerVehicle(Vehicle *v, VehicleTrigger trigger)
VehicleEnteredDepotThisTick(v);
}
+ v->InvalidateNewGRFCacheOfChain();
DoTriggerVehicle(v, trigger, 0, true);
+ v->InvalidateNewGRFCacheOfChain();
}
/* Functions for changing the order of vehicle purchase lists
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 959fdfffb..d52795f9e 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -137,6 +137,8 @@ void RoadVehUpdateCache(RoadVehicle *v)
assert(v->type == VEH_ROAD);
assert(IsRoadVehFront(v));
+ v->InvalidateNewGRFCacheOfChain();
+
for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
/* Check the v->first cache. */
assert(u->First() == v);
@@ -252,12 +254,15 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
v->cargo_cap = rvi->capacity;
AddArticulatedParts(v, VEH_ROAD);
+ v->InvalidateNewGRFCacheOfChain();
/* Call various callbacks after the whole consist has been constructed */
for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
u->rcache.cached_veh_length = GetRoadVehLength(u);
/* Cargo capacity is zero if and only if the vehicle cannot carry anything */
if (u->cargo_cap != 0) u->cargo_cap = GetVehicleProperty(u, 0x0F, u->cargo_cap);
+ v->InvalidateNewGRFCache();
+ u->InvalidateNewGRFCache();
}
VehicleMove(v, false);
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 1ed7a0480..a5c8b9195 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -814,8 +814,12 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
v->vehicle_flags = 0;
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
+ v->InvalidateNewGRFCacheOfChain();
+
v->cargo_cap = GetVehicleProperty(v, 0x0D, svi->capacity);
+ v->InvalidateNewGRFCacheOfChain();
+
VehicleMove(v, false);
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
@@ -948,6 +952,7 @@ CommandCost CmdRefitShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
v->cargo_type = new_cid;
v->cargo_subtype = new_subtype;
v->colourmap = PAL_NONE; // invalidate vehicle colour map
+ v->InvalidateNewGRFCacheOfChain();
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
InvalidateWindowClassesData(WC_SHIPS_LIST, 0);
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index d0d09a2ff..91a4bccd2 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -241,13 +241,15 @@ void TrainConsistChanged(Train *v, bool same_length)
/* Set user defined data to its default value */
u->tcache.user_def_data = rvi_u->user_def_data;
- u->vcache.cache_valid = 0;
+ v->InvalidateNewGRFCache();
+ u->InvalidateNewGRFCache();
}
for (Train *u = v; u != NULL; u = u->Next()) {
/* Update user defined data (must be done before other properties) */
u->tcache.user_def_data = GetVehicleProperty(u, 0x25, u->tcache.user_def_data);
- u->vcache.cache_valid = 0;
+ v->InvalidateNewGRFCache();
+ u->InvalidateNewGRFCache();
}
for (Train *u = v; u != NULL; u = u->Next()) {
@@ -333,7 +335,8 @@ void TrainConsistChanged(Train *v, bool same_length)
if (!same_length) u->tcache.cached_veh_length = veh_len;
v->tcache.cached_total_length += u->tcache.cached_veh_length;
- u->vcache.cache_valid = 0;
+ v->InvalidateNewGRFCache();
+ u->InvalidateNewGRFCache();
}
/* store consist weight/max speed in cache */
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 581a55135..b4a43e2ae 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -246,6 +246,26 @@ public:
virtual SpriteID GetImage(Direction direction) const { return 0; }
/**
+ * Invalidates cached NewGRF variables
+ * @see InvalidateNewGRFCacheOfChain
+ */
+ FORCEINLINE void InvalidateNewGRFCache()
+ {
+ this->vcache.cache_valid = 0;
+ }
+
+ /**
+ * Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
+ * @see InvalidateNewGRFCache
+ */
+ FORCEINLINE void InvalidateNewGRFCacheOfChain()
+ {
+ for (Vehicle *u = this; u != NULL; u = u->Next()) {
+ u->InvalidateNewGRFCache();
+ }
+ }
+
+ /**
* Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
* @return the vehicle's speed
*/