summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2007-11-11 18:32:01 +0000
committerglx <glx@openttd.org>2007-11-11 18:32:01 +0000
commit8844bd6cded02f00149034eccd122811f5c4a1e9 (patch)
treedf1de08c96c81001d9cb3704884dda80652601bc
parent02a6debc111368a9986b753366f3b125a8505698 (diff)
downloadopenttd-8844bd6cded02f00149034eccd122811f5c4a1e9.tar.xz
(svn r11413) -Fix [FS#1405]: don't use cached override spriteset for callbacks
-rw-r--r--src/newgrf_engine.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index e0003dff5..2c0090da9 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -843,11 +843,12 @@ static inline void NewVehicleResolver(ResolverObject *res, EngineID engine_type,
/** Retrieve the SpriteGroup for the specified vehicle.
* If the vehicle is not specified, the purchase list group for the engine is
* chosen. For trains, an additional engine override lookup is performed.
- * @param engine Engine type of the vehicle.
- * @param v The vehicle itself.
- * @returns The selected SpriteGroup for the vehicle.
+ * @param engine Engine type of the vehicle.
+ * @param v The vehicle itself.
+ * @param use_cache Use cached override
+ * @returns The selected SpriteGroup for the vehicle.
*/
-static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle *v)
+static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle *v, bool use_cache = true)
{
const SpriteGroup *group;
CargoID cargo;
@@ -858,7 +859,10 @@ static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle *
cargo = v->cargo_type;
if (v->type == VEH_TRAIN) {
- group = v->u.rail.cached_override;
+ /* We always use cached value, except for callbacks because the override spriteset
+ * to use may be different than the one cached. It happens for callback 0x15 (refit engine),
+ * as v->cargo_type is temporary changed to the new type */
+ group = use_cache ? v->u.rail.cached_override : GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, v->u.rail.first_engine);
if (group != NULL) return group;
}
}
@@ -942,7 +946,7 @@ uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, Eng
object.callback_param1 = param1;
object.callback_param2 = param2;
- group = Resolve(GetVehicleSpriteGroup(engine, v), &object);
+ group = Resolve(GetVehicleSpriteGroup(engine, v, false), &object);
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
return group->g.callback.result;
@@ -971,7 +975,7 @@ uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param
object.u.vehicle.parent = parent;
- group = Resolve(GetVehicleSpriteGroup(engine, v), &object);
+ group = Resolve(GetVehicleSpriteGroup(engine, v, false), &object);
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
return group->g.callback.result;