diff options
author | peter1138 <peter1138@openttd.org> | 2006-04-30 18:41:16 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2006-04-30 18:41:16 +0000 |
commit | ddbb61199b4695089d8c2eedbe84b0428386c42e (patch) | |
tree | b7b1dbf951ced2a8d3a8662a5f4f5db0a18855e3 | |
parent | 967752fe7c945fecc980ec46c0971038a161c846 (diff) | |
download | openttd-ddbb61199b4695089d8c2eedbe84b0428386c42e.tar.xz |
(svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
-rw-r--r-- | newgrf.c | 11 | ||||
-rw-r--r-- | newgrf_engine.c | 50 | ||||
-rw-r--r-- | newgrf_engine.h | 5 |
3 files changed, 64 insertions, 2 deletions
@@ -1742,8 +1742,14 @@ static void NewVehicle_SpriteGroupMapping(byte *buf, int len) } if (wagover) { - // TODO: No multiple cargo types per vehicle yet. --pasky - SetWagonOverrideSprites(engine, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count); + /* If the ID for this action 3 is the same as the vehicle ID, + * this indicates we have a helicopter rotor override. */ + if (feature == GSF_AIRCRAFT && engine == last_engines[i]) { + SetRotorOverrideSprites(engine, _cur_grffile->spritegroups[groupid]); + } else { + // TODO: No multiple cargo types per vehicle yet. --pasky + SetWagonOverrideSprites(engine, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count); + } } else { SetCustomEngineSprites(engine, GC_DEFAULT, _cur_grffile->spritegroups[groupid]); last_engines[i] = engine; @@ -2534,6 +2540,7 @@ static void ResetNewGRFData(void) // Unload sprite group data UnloadWagonOverrides(); + UnloadRotorOverrideSprites(); UnloadCustomEngineSprites(); UnloadCustomEngineNames(); ResetEngineListOrder(); 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 diff --git a/newgrf_engine.h b/newgrf_engine.h index cdd68ceaf..547adf26f 100644 --- a/newgrf_engine.h +++ b/newgrf_engine.h @@ -16,7 +16,11 @@ VARDEF const uint32 cargo_classes[16]; void SetWagonOverrideSprites(EngineID engine, const struct SpriteGroup *group, byte *train_id, int trains); void SetCustomEngineSprites(EngineID engine, byte cargo, const struct SpriteGroup *group); +void SetRotorOverrideSprites(EngineID engine, const struct SpriteGroup *group); SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle* v, Direction direction); +SpriteID GetRotorOverrideSprite(EngineID engine, const Vehicle* v); +#define GetCustomRotorSprite(v) GetRotorOverrideSprite(v->engine_type, v) +#define GetCustomRotorIcon(et) GetRotorOverrideSprite(et, NULL) void SetEngineGRF(EngineID engine, uint32 grfid); uint32 GetEngineGRFID(EngineID engine); @@ -41,6 +45,7 @@ void SetCustomEngineName(EngineID engine, StringID name); StringID GetCustomEngineName(EngineID engine); void UnloadWagonOverrides(void); +void UnloadRotorOverrideSprites(void); void UnloadCustomEngineSprites(void); void UnloadCustomEngineNames(void); |