diff options
-rw-r--r-- | newgrf.c | 2 | ||||
-rw-r--r-- | newgrf_engine.c | 34 | ||||
-rw-r--r-- | newgrf_engine.h | 7 |
3 files changed, 37 insertions, 6 deletions
@@ -1735,7 +1735,7 @@ static void FeatureMapSpriteGroup(byte *buf, int len) } } else { SetCustomEngineSprites(engine, GC_DEFAULT, _cur_grffile->spritegroups[groupid]); - SetEngineGRF(engine, _cur_grffile->grfid); + SetEngineGRF(engine, _cur_grffile); last_engines[i] = engine; } } diff --git a/newgrf_engine.c b/newgrf_engine.c index 8d33c9eab..5460c5932 100644 --- a/newgrf_engine.c +++ b/newgrf_engine.c @@ -10,6 +10,7 @@ #include "player.h" #include "station.h" #include "airport.h" +#include "newgrf.h" #include "newgrf_callbacks.h" #include "newgrf_engine.h" #include "newgrf_station.h" @@ -141,7 +142,7 @@ void UnloadWagonOverrides(void) // may appear in future - however it's more convenient to store it like this in // memory. --pasky) static const SpriteGroup *engine_custom_sprites[TOTAL_NUM_ENGINES][NUM_GLOBAL_CID]; -static uint32 _engine_grf[TOTAL_NUM_ENGINES]; +static const GRFFile *_engine_grf[TOTAL_NUM_ENGINES]; void SetCustomEngineSprites(EngineID engine, byte cargo, const SpriteGroup *group) { @@ -194,19 +195,44 @@ void UnloadRotorOverrideSprites(void) } } -void SetEngineGRF(EngineID engine, uint32 grfid) + +/** + * Tie a GRFFile entry to an engine, to allow us to retrieve GRF parameters + * etc during a game. + * @param engine Engine ID to tie the GRFFile to. + * @param file Pointer of GRFFile to tie. + */ +void SetEngineGRF(EngineID engine, const GRFFile *file) { assert(engine < TOTAL_NUM_ENGINES); - _engine_grf[engine] = grfid; + _engine_grf[engine] = file; } -uint32 GetEngineGRFID(EngineID engine) + +/** + * Retrieve the GRFFile tied to an engine + * @param engine Engine ID to retrieve. + * @return Pointer to GRFFile. + */ +const GRFFile *GetEngineGRF(EngineID engine) { assert(engine < TOTAL_NUM_ENGINES); return _engine_grf[engine]; } +/** + * Retrieve the GRF ID of the GRFFile tied to an engine + * @param engine Engine ID to retrieve. + * @return 32 bit GRFID value. + */ +uint32 GetEngineGRFID(EngineID engine) +{ + assert(engine < TOTAL_NUM_ENGINES); + return _engine_grf[engine]->grfid; +} + + static int MapOldSubType(const Vehicle *v) { if (v->type != VEH_Train) return v->subtype; diff --git a/newgrf_engine.h b/newgrf_engine.h index 0e3d37697..af42ff148 100644 --- a/newgrf_engine.h +++ b/newgrf_engine.h @@ -26,7 +26,12 @@ 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); +/* Forward declaration of GRFFile, to avoid unnecessary inclusion of newgrf.h + * elsewhere... */ +struct GRFFile; + +void SetEngineGRF(EngineID engine, const struct GRFFile *file); +const struct GRFFile *GetEngineGRF(EngineID engine); uint32 GetEngineGRFID(EngineID engine); uint16 GetVehicleCallback(uint16 callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v); |