summaryrefslogtreecommitdiff
path: root/newgrf_engine.c
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-04-30 18:41:16 +0000
committerpeter1138 <peter1138@openttd.org>2006-04-30 18:41:16 +0000
commitddbb61199b4695089d8c2eedbe84b0428386c42e (patch)
treeb7b1dbf951ced2a8d3a8662a5f4f5db0a18855e3 /newgrf_engine.c
parent967752fe7c945fecc980ec46c0971038a161c846 (diff)
downloadopenttd-ddbb61199b4695089d8c2eedbe84b0428386c42e.tar.xz
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
Diffstat (limited to 'newgrf_engine.c')
-rw-r--r--newgrf_engine.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/newgrf_engine.c b/newgrf_engine.c
index 84096f1b2..38f3af57a 100644
--- a/newgrf_engine.c
+++ b/newgrf_engine.c
@@ -125,6 +125,32 @@ void UnloadCustomEngineSprites(void)
}
}
+static const SpriteGroup *heli_rotor_custom_sprites[NUM_AIRCRAFT_ENGINES];
+
+/** Load a rotor override sprite group for an aircraft */
+void SetRotorOverrideSprites(EngineID engine, const SpriteGroup *group)
+{
+ assert(engine >= AIRCRAFT_ENGINES_INDEX);
+ assert(engine < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES);
+
+ if (heli_rotor_custom_sprites[engine - AIRCRAFT_ENGINES_INDEX] != NULL) {
+ DEBUG(grf, 6)("SetRotorOverrideSprites: engine `%d' already has group -- replacing.", engine);
+ }
+ heli_rotor_custom_sprites[engine - AIRCRAFT_ENGINES_INDEX] = group;
+}
+
+/** Unload all rotor override sprite groups */
+void UnloadRotorOverrideSprites(void)
+{
+ EngineID engine;
+
+ /* Starting at AIRCRAFT_ENGINES_INDEX may seem pointless, but it means
+ * the context of EngineID is correct */
+ for (engine = AIRCRAFT_ENGINES_INDEX; engine < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; engine++) {
+ heli_rotor_custom_sprites[engine - AIRCRAFT_ENGINES_INDEX] = NULL;
+ }
+}
+
void SetEngineGRF(EngineID engine, uint32 grfid)
{
assert(engine < TOTAL_NUM_ENGINES);
@@ -435,6 +461,30 @@ SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction dire
}
+SpriteID GetRotorOverrideSprite(EngineID engine, const Vehicle *v)
+{
+ const SpriteGroup *group;
+ ResolverObject object;
+
+ assert(engine >= AIRCRAFT_ENGINES_INDEX);
+ assert(engine < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES);
+
+ /* Only valid for helicopters */
+ assert((AircraftVehInfo(engine)->subtype & 1) == 0);
+
+ NewVehicleResolver(&object, v);
+
+ group = heli_rotor_custom_sprites[engine - AIRCRAFT_ENGINES_INDEX];
+ group = Resolve(group, &object);
+
+ if (group == NULL || group->type != SGT_RESULT) return 0;
+
+ if (v == NULL) return group->g.result.sprite;
+
+ return group->g.result.sprite + v->next->next->u.air.state;
+}
+
+
/**
* Check if a wagon is currently using a wagon override
* @param v The wagon to check