diff options
author | peter1138 <peter1138@openttd.org> | 2006-05-02 21:42:11 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2006-05-02 21:42:11 +0000 |
commit | 43451dfbd9605c4d7671415e4990f3f6c6bc27a5 (patch) | |
tree | 2602188537c2d2ebd0afd7d11584caeaf2899781 | |
parent | 48f70364089e5a63a10a8c3f99afe349399fcc34 (diff) | |
download | openttd-43451dfbd9605c4d7671415e4990f3f6c6bc27a5.tar.xz |
(svn r4702) - NewGRF: add support for 'special' vehicle callbacks that use a different vehicle for parent scope than the first vehicle in the consist.
-rw-r--r-- | newgrf_engine.c | 46 | ||||
-rw-r--r-- | newgrf_engine.h | 1 |
2 files changed, 47 insertions, 0 deletions
diff --git a/newgrf_engine.c b/newgrf_engine.c index de61aa01a..5c386ccc9 100644 --- a/newgrf_engine.c +++ b/newgrf_engine.c @@ -800,6 +800,52 @@ uint16 GetVehicleCallback(uint16 callback, uint32 param1, uint32 param2, EngineI return group->g.callback.result; } +/** + * Evaluate a newgrf callback for vehicles with a different vehicle for parent scope. + * @param callback The callback to evalute + * @param param1 First parameter of the callback + * @param param2 Second parameter of the callback + * @param engine Engine type of the vehicle to evaluate the callback for + * @param v The vehicle to evaluate the callback for, or NULL if it doesnt exist yet + * @param parent The vehicle to use for parent scope + * @return The value the callback returned, or CALLBACK_FAILED if it failed + */ +uint16 GetVehicleCallbackParent(uint16 callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent) +{ + const SpriteGroup *group; + ResolverObject object; + CargoID cargo; + + NewVehicleResolver(&object, v); + + object.callback = callback; + object.callback_param1 = param1; + object.callback_param2 = param2; + + object.u.vehicle.parent = parent; + + cargo = (v == NULL) ? GC_PURCHASE : _global_cargo_id[_opt.landscape][v->cargo_type]; + + group = engine_custom_sprites[engine][cargo]; + + if (v != NULL && v->type == VEH_Train) { + const SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, v->u.rail.first_engine); + + if (overset != NULL) group = overset; + } + + group = Resolve(group, &object); + + if ((group == NULL || group->type != SGT_CALLBACK) && cargo != GC_DEFAULT) { + // This group is empty but perhaps there'll be a default one. + group = Resolve(engine_custom_sprites[engine][GC_DEFAULT], &object); + } + + if (group == NULL || group->type != SGT_CALLBACK) + return CALLBACK_FAILED; + + return group->g.callback.result; +} static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_random_bits, bool first) { diff --git a/newgrf_engine.h b/newgrf_engine.h index e610f4050..248de61ee 100644 --- a/newgrf_engine.h +++ b/newgrf_engine.h @@ -26,6 +26,7 @@ void SetEngineGRF(EngineID engine, uint32 grfid); uint32 GetEngineGRFID(EngineID engine); uint16 GetVehicleCallback(uint16 callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v); +uint16 GetVehicleCallbackParent(uint16 callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent); bool UsesWagonOverride(const Vehicle *v); #define GetCustomVehicleSprite(v, direction) GetCustomEngineSprite(v->engine_type, v, direction) #define GetCustomVehicleIcon(et, direction) GetCustomEngineSprite(et, NULL, direction) |