(svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.

This commit is contained in:
frosch 2008-07-30 18:23:12 +00:00
parent 515b55c635
commit 93d0ca8731
14 changed files with 32 additions and 59 deletions

View File

@ -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;

View File

@ -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];
}
}

View File

@ -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;

View File

@ -21,6 +21,7 @@ enum CanalFeature {
struct WaterFeature {
const SpriteGroup *group;
const GRFFile *grffile; ///< newgrf where 'group' belongs to
uint8 callbackmask;
uint8 flags;
};

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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);
}

View File

@ -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;

View File

@ -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)

View File

@ -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,