diff options
-rw-r--r-- | src/cargotype.h | 2 | ||||
-rw-r--r-- | src/newgrf.cpp | 5 | ||||
-rw-r--r-- | src/newgrf_canal.cpp | 5 | ||||
-rw-r--r-- | src/newgrf_canal.h | 1 | ||||
-rw-r--r-- | src/newgrf_cargo.cpp | 1 | ||||
-rw-r--r-- | src/newgrf_engine.cpp | 16 | ||||
-rw-r--r-- | src/newgrf_generic.cpp | 5 | ||||
-rw-r--r-- | src/newgrf_house.cpp | 15 | ||||
-rw-r--r-- | src/newgrf_industries.cpp | 17 | ||||
-rw-r--r-- | src/newgrf_industrytiles.cpp | 15 | ||||
-rw-r--r-- | src/newgrf_spritegroup.cpp | 4 | ||||
-rw-r--r-- | src/newgrf_spritegroup.h | 2 | ||||
-rw-r--r-- | src/newgrf_station.cpp | 1 | ||||
-rw-r--r-- | src/table/cargo_const.h | 2 |
14 files changed, 32 insertions, 59 deletions
diff --git a/src/cargotype.h b/src/cargotype.h index e8498cc72..db1a6f0d5 100644 --- a/src/cargotype.h +++ b/src/cargotype.h @@ -25,7 +25,6 @@ enum TownEffect { struct CargoSpec { uint8 bitnum; CargoLabel label; - uint32 grfid; uint8 legend_colour; uint8 rating_colour; uint8 weight; @@ -46,6 +45,7 @@ struct CargoSpec { SpriteID sprite; uint16 classes; + const struct GRFFile *grffile; ///< NewGRF where 'group' belongs to const struct SpriteGroup *group; bool IsValid() const; diff --git a/src/newgrf.cpp b/src/newgrf.cpp index b1dd7b620..6ae310600 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -1732,7 +1732,7 @@ static bool CargoChangeInfo(uint cid, int numinfo, int prop, byte **bufp, int le case 0x08: /* Bit number of cargo */ cs->bitnum = grf_load_byte(&buf); if (cs->IsValid()) { - cs->grfid = _cur_grffile->grfid; + cs->grffile = _cur_grffile; SetBit(_cargo_mask, cid + i); } else { ClrBit(_cargo_mask, cid + i); @@ -3045,6 +3045,7 @@ static void CanalMapSpriteGroup(byte *buf, uint8 idcount) continue; } + _water_feature[cf].grffile = _cur_grffile; _water_feature[cf].group = _cur_grffile->spritegroups[groupid]; } } @@ -3198,7 +3199,7 @@ static void CargoMapSpriteGroup(byte *buf, uint8 idcount) } CargoSpec *cs = &_cargo[cid]; - cs->grfid = _cur_grffile->grfid; + cs->grffile = _cur_grffile; cs->group = _cur_grffile->spritegroups[groupid]; } } diff --git a/src/newgrf_canal.cpp b/src/newgrf_canal.cpp index 70507dc11..3d0af0b61 100644 --- a/src/newgrf_canal.cpp +++ b/src/newgrf_canal.cpp @@ -71,7 +71,7 @@ static const SpriteGroup *CanalResolveReal(const ResolverObject *object, const S } -static void NewCanalResolver(ResolverObject *res, TileIndex tile) +static void NewCanalResolver(ResolverObject *res, TileIndex tile, const GRFFile *grffile) { res->GetRandomBits = &CanalGetRandomBits; res->GetTriggers = &CanalGetTriggers; @@ -88,6 +88,7 @@ static void NewCanalResolver(ResolverObject *res, TileIndex tile) res->trigger = 0; res->reseed = 0; res->count = 0; + res->grffile = grffile; } @@ -96,7 +97,7 @@ SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile) ResolverObject object; const SpriteGroup *group; - NewCanalResolver(&object, tile); + NewCanalResolver(&object, tile, _water_feature[feature].grffile); group = Resolve(_water_feature[feature].group, &object); if (group == NULL || group->type != SGT_RESULT) return 0; diff --git a/src/newgrf_canal.h b/src/newgrf_canal.h index 14813159e..a3975f300 100644 --- a/src/newgrf_canal.h +++ b/src/newgrf_canal.h @@ -21,6 +21,7 @@ enum CanalFeature { struct WaterFeature { const SpriteGroup *group; + const GRFFile *grffile; ///< newgrf where 'group' belongs to uint8 callbackmask; uint8 flags; }; diff --git a/src/newgrf_cargo.cpp b/src/newgrf_cargo.cpp index 1ff8de73f..06c6caedf 100644 --- a/src/newgrf_cargo.cpp +++ b/src/newgrf_cargo.cpp @@ -67,6 +67,7 @@ static void NewCargoResolver(ResolverObject *res, const CargoSpec *cs) res->trigger = 0; res->reseed = 0; res->count = 0; + res->grffile = cs->grffile; } diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index b5f2ceb4b..80c963ed7 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -439,16 +439,6 @@ static void VehicleSetTriggers(const ResolverObject *object, int triggers) } -static uint32 GetGRFParameter(EngineID engine_type, byte parameter) -{ - const GRFFile *file = GetEngineGRF(engine_type); - - if (file == NULL) return 0; - if (parameter >= file->param_end) return 0; - return file->param[parameter]; -} - - static uint8 LiveryHelper(EngineID engine, const Vehicle *v) { const Livery *l; @@ -479,7 +469,6 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by case 0x49: return _cur_year; // 'Long' format build year case 0xC4: return Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; // Build year case 0xDA: return INVALID_VEHICLE; // Next vehicle - case 0x7F: return GetGRFParameter(object->u.vehicle.self_type, parameter); // Read GRF parameter } *available = false; @@ -632,8 +621,6 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by return count; } - case 0x7F: return GetGRFParameter(v->engine_type, parameter); // Read GRF parameter - case 0xFE: case 0xFF: { uint16 modflags = 0; @@ -832,6 +819,9 @@ static inline void NewVehicleResolver(ResolverObject *res, EngineID engine_type, res->trigger = 0; res->reseed = 0; res->count = 0; + + const Engine *e = GetEngine(engine_type); + res->grffile = (e != NULL ? e->grffile : NULL); } diff --git a/src/newgrf_generic.cpp b/src/newgrf_generic.cpp index 0b8b81882..c2dd2734e 100644 --- a/src/newgrf_generic.cpp +++ b/src/newgrf_generic.cpp @@ -113,7 +113,7 @@ static const SpriteGroup *GenericCallbackResolveReal(const ResolverObject *objec } -static inline void NewGenericResolver(ResolverObject *res) +static inline void NewGenericResolver(ResolverObject *res, const GRFFile *grffile) { res->GetRandomBits = &GenericCallbackGetRandomBits; res->GetTriggers = &GenericCallbackGetTriggers; @@ -128,6 +128,7 @@ static inline void NewGenericResolver(ResolverObject *res) res->trigger = 0; res->reseed = 0; res->count = 0; + res->grffile = grffile; } @@ -166,7 +167,7 @@ uint16 GetAiPurchaseCallbackResult(uint8 feature, CargoID cargo_type, uint8 defa { ResolverObject object; - NewGenericResolver(&object); + NewGenericResolver(&object, *file); object.callback = CBID_GENERIC_AI_PURCHASE_SELECTION; object.u.generic.cargo_type = cargo_type; diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index 146a21682..5ef9089be 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -183,15 +183,6 @@ static uint32 GetNumHouses(HouseID house_id, const Town *town) return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count; } -static uint32 GetGRFParameter(HouseID house_id, byte parameter) -{ - const HouseSpec *hs = GetHouseSpecs(house_id); - const GRFFile *file = hs->grffile; - - if (parameter >= file->param_end) return 0; - return file->param[parameter]; -} - uint32 GetNearbyTileInformation(byte parameter, TileIndex tile) { tile = GetNearbyTile(parameter, tile); @@ -369,9 +360,6 @@ static uint32 HouseGetVariable(const ResolverObject *object, byte variable, byte /* Distance test for some house types */ case 0x65: return GetDistanceFromNearbyHouse(parameter, tile, object->u.house.house_id); - - /* Read GRF parameter */ - case 0x7F: return GetGRFParameter(object->u.house.house_id, parameter); } DEBUG(grf, 1, "Unhandled house property 0x%X", variable); @@ -410,6 +398,9 @@ static void NewHouseResolver(ResolverObject *res, HouseID house_id, TileIndex ti res->trigger = 0; res->reseed = 0; res->count = 0; + + const HouseSpec *hs = GetHouseSpecs(house_id); + res->grffile = (hs != NULL ? hs->grffile : NULL); } uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile) diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index 16a36dc6a..307cd2c0c 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -41,15 +41,6 @@ IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id) return _industry_mngr.GetID(GB(grf_type, 0, 6), grf_id); } -static uint32 GetGRFParameter(IndustryType ind_id, byte parameter) -{ - const IndustrySpec *indspec = GetIndustrySpec(ind_id); - const GRFFile *file = indspec->grf_prop.grffile; - - if (parameter >= file->param_end) return 0; - return file->param[parameter]; -} - /** * Finds the distance for the closest tile with water/land given a tile * @param tile the tile to find the distance too @@ -230,8 +221,6 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par if (industry == NULL) { /* industry does not exist, only use those variables that are "safe" */ switch (variable) { - /* Read GRF parameter */ - case 0x7F: return GetGRFParameter(type, parameter); /* Manhattan distance of closes dry/water tile */ case 0x43: return GetClosestWaterDistance(tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0); } @@ -318,9 +307,6 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par /* Get a variable from the persistent storage */ case 0x7C: return industry->psa.Get(parameter); - /* Read GRF parameter */ - case 0x7F: return GetGRFParameter(type, parameter); - /* Industry structure access*/ case 0x80: return industry->xy; case 0x81: return GB(industry->xy, 8, 8); @@ -430,6 +416,9 @@ static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *i res->trigger = 0; res->reseed = 0; res->count = 0; + + const IndustrySpec *indspec = GetIndustrySpec(type); + res->grffile = (indspec != NULL ? indspec->grf_prop.grffile : NULL); } uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile) diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index 63c7cbf34..50d59f173 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -30,15 +30,6 @@ #include "table/sprites.h" #include "table/strings.h" -static uint32 GetGRFParameter(IndustryGfx indtile_id, byte parameter) -{ - const IndustryTileSpec *indtspec = GetIndustryTileSpec(indtile_id); - const GRFFile *file = indtspec->grf_prop.grffile; - - if (parameter >= file->param_end) return 0; - return file->param[parameter]; -} - /** * Based on newhouses equivalent, but adapted for newindustries * @param parameter from callback. It's in fact a pair of coordinates @@ -110,9 +101,6 @@ static uint32 IndustryTileGetVariable(const ResolverObject *object, byte variabl /* Get industry tile ID at offset */ case 0x62 : return GetIndustryIDAtOffset(GetNearbyTile(parameter, tile), inds); - - /* Read GRF parameter */ - case 0x7F: return GetGRFParameter(GetIndustryGfx(tile), parameter); } DEBUG(grf, 1, "Unhandled industry tile property 0x%X", variable); @@ -174,6 +162,9 @@ static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIn res->trigger = 0; res->reseed = 0; res->count = 0; + + const IndustryTileSpec *its = GetIndustryTileSpec(gfx); + res->grffile = (its != NULL ? its->grf_prop.grffile : NULL); } void IndustryDrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte rnd_color, byte stage, IndustryGfx gfx) diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp index d2e19fb3e..d730d5017 100644 --- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -97,6 +97,10 @@ static inline uint32 GetVariable(const ResolverObject *object, byte variable, by case 0x7D: return _temp_store.Get(parameter); + case 0x7F: + if (object == NULL || object->grffile == NULL || parameter >= object->grffile->param_end) return 0; + return object->grffile->param[parameter]; + /* Not a common variable, so evalute the feature specific variables */ default: return object->GetVariable(object, variable, parameter, available); } diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index 2b2f3c60e..0b83934d9 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -218,6 +218,8 @@ struct ResolverObject { BaseStorageArray *psa; ///< The persistent storage array of this resolved object. + const GRFFile *grffile; ///< GRFFile the resolved SpriteGroup belongs to + union { struct { const struct Vehicle *self; diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index a2375298a..b63703206 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -590,6 +590,7 @@ static void NewStationResolver(ResolverObject *res, const StationSpec *statspec, res->trigger = 0; res->reseed = 0; res->count = 0; + res->grffile = (statspec != NULL ? statspec->grffile : NULL); } static const SpriteGroup *ResolveStation(ResolverObject *object) diff --git a/src/table/cargo_const.h b/src/table/cargo_const.h index 8467cb730..8421e368d 100644 --- a/src/table/cargo_const.h +++ b/src/table/cargo_const.h @@ -3,7 +3,7 @@ /** @file cargo_const.h Table of all default cargo types */ #define MK(bt, label, c, e, f, g, h, fr, te, ks1, ks2, ks3, ks4, ks5, l, m) \ - {bt, label, 0, c, c, e, f, {g, h}, fr, te, 0, 0, ks1, ks2, ks3, ks4, ks5, l, m, NULL} + {bt, label, c, c, e, f, {g, h}, fr, te, 0, 0, ks1, ks2, ks3, ks4, ks5, l, m, NULL, NULL} static const CargoSpec _default_cargo[] = { MK( 0, 'PASS', 152, 1, 3185, 0, 24, false, TE_PASSENGERS, STR_000F_PASSENGERS, STR_002F_PASSENGER, STR_PASSENGERS, STR_QUANTITY_PASSENGERS, STR_ABBREV_PASSENGERS, |