changeset 9750:0654bf387d06 draft

(svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
author frosch <frosch@openttd.org>
date Wed, 30 Jul 2008 18:23:12 +0000
parents d3514ad21801
children 8702be5e8787
files src/cargotype.h src/newgrf.cpp src/newgrf_canal.cpp src/newgrf_canal.h src/newgrf_cargo.cpp src/newgrf_engine.cpp src/newgrf_generic.cpp src/newgrf_house.cpp src/newgrf_industries.cpp src/newgrf_industrytiles.cpp src/newgrf_spritegroup.cpp src/newgrf_spritegroup.h src/newgrf_station.cpp src/table/cargo_const.h
diffstat 14 files changed, 32 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/src/cargotype.h
+++ b/src/cargotype.h
@@ -25,7 +25,6 @@
 struct CargoSpec {
 	uint8 bitnum;
 	CargoLabel label;
-	uint32 grfid;
 	uint8 legend_colour;
 	uint8 rating_colour;
 	uint8 weight;
@@ -46,6 +45,7 @@
 	SpriteID sprite;
 
 	uint16 classes;
+	const struct GRFFile *grffile;   ///< NewGRF where 'group' belongs to
 	const struct SpriteGroup *group;
 
 	bool IsValid() const;
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -1732,7 +1732,7 @@
 			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 @@
 			continue;
 		}
 
+		_water_feature[cf].grffile = _cur_grffile;
 		_water_feature[cf].group = _cur_grffile->spritegroups[groupid];
 	}
 }
@@ -3198,7 +3199,7 @@
 		}
 
 		CargoSpec *cs = &_cargo[cid];
-		cs->grfid = _cur_grffile->grfid;
+		cs->grffile = _cur_grffile;
 		cs->group = _cur_grffile->spritegroups[groupid];
 	}
 }
--- a/src/newgrf_canal.cpp
+++ b/src/newgrf_canal.cpp
@@ -71,7 +71,7 @@
 }
 
 
-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 @@
 	res->trigger         = 0;
 	res->reseed          = 0;
 	res->count           = 0;
+	res->grffile         = grffile;
 }
 
 
@@ -96,7 +97,7 @@
 	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;
--- a/src/newgrf_canal.h
+++ b/src/newgrf_canal.h
@@ -21,6 +21,7 @@
 
 struct WaterFeature {
 	const SpriteGroup *group;
+	const GRFFile *grffile;   ///< newgrf where 'group' belongs to
 	uint8 callbackmask;
 	uint8 flags;
 };
--- a/src/newgrf_cargo.cpp
+++ b/src/newgrf_cargo.cpp
@@ -67,6 +67,7 @@
 	res->trigger         = 0;
 	res->reseed          = 0;
 	res->count           = 0;
+	res->grffile         = cs->grffile;
 }
 
 
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -439,16 +439,6 @@
 }
 
 
-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 @@
 			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 @@
 				return count;
 			}
 
-		case 0x7F: return GetGRFParameter(v->engine_type, parameter); // Read GRF parameter
-
 		case 0xFE:
 		case 0xFF: {
 			uint16 modflags = 0;
@@ -832,6 +819,9 @@
 	res->trigger         = 0;
 	res->reseed          = 0;
 	res->count           = 0;
+
+	const Engine *e = GetEngine(engine_type);
+	res->grffile         = (e != NULL ? e->grffile : NULL);
 }
 
 
--- a/src/newgrf_generic.cpp
+++ b/src/newgrf_generic.cpp
@@ -113,7 +113,7 @@
 }
 
 
-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 @@
 	res->trigger         = 0;
 	res->reseed          = 0;
 	res->count           = 0;
+	res->grffile         = grffile;
 }
 
 
@@ -166,7 +167,7 @@
 {
 	ResolverObject object;
 
-	NewGenericResolver(&object);
+	NewGenericResolver(&object, *file);
 
 	object.callback = CBID_GENERIC_AI_PURCHASE_SELECTION;
 	object.u.generic.cargo_type        = cargo_type;
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -183,15 +183,6 @@
 	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 @@
 
 		/* 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 @@
 	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)
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -41,15 +41,6 @@
 	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 @@
 	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 @@
 		/* 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 @@
 	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)
--- 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 @@
 
 		/* 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 @@
 	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)
--- a/src/newgrf_spritegroup.cpp
+++ b/src/newgrf_spritegroup.cpp
@@ -97,6 +97,10 @@
 
 		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);
 	}
--- a/src/newgrf_spritegroup.h
+++ b/src/newgrf_spritegroup.h
@@ -218,6 +218,8 @@
 
 	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;
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -590,6 +590,7 @@
 	res->trigger         = 0;
 	res->reseed          = 0;
 	res->count           = 0;
+	res->grffile         = (statspec != NULL ? statspec->grffile : NULL);
 }
 
 static const SpriteGroup *ResolveStation(ResolverObject *object)
--- 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,