Changeset - r21008:be2e3d3c935b
[Not reviewed]
src/base_station_base.h
Show inline comments
 
@@ -100,13 +100,13 @@ struct BaseStation : StationPool::PoolIt
 
	 * @param object the resolver object related to this query
 
	 * @param variable that is queried
 
	 * @param parameter parameter for that variable
 
	 * @param available will return false if ever the variable asked for does not exist
 
	 * @return the value stored in the corresponding variable
 
	 */
 
	virtual uint32 GetNewGRFVariable(const struct ResolverObject *object, byte variable, byte parameter, bool *available) const = 0;
 
	virtual uint32 GetNewGRFVariable(const struct ResolverObject &object, byte variable, byte parameter, bool *available) const = 0;
 

	
 
	/**
 
	 * Update the coordinated of the sign (as shown in the viewport).
 
	 */
 
	virtual void UpdateVirtCoord() = 0;
 

	
src/newgrf_airport.cpp
Show inline comments
 
@@ -21,13 +21,13 @@
 
struct AirportScopeResolver : public ScopeResolver {
 
	struct Station *st; ///< Station of the airport for which the callback is run, or \c NULL for build gui.
 
	byte airport_id;    ///< Type of airport for which the callback is run.
 
	byte layout;        ///< Layout of the airport to build.
 
	TileIndex tile;     ///< Tile for the callback, only valid for airporttile callbacks.
 

	
 
	AirportScopeResolver(ResolverObject *ro, TileIndex tile, Station *st, byte airport_id, byte layout);
 
	AirportScopeResolver(ResolverObject &ro, TileIndex tile, Station *st, byte airport_id, byte layout);
 

	
 
	/* virtual */ uint32 GetRandomBits() const;
 
	/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
 
	/* virtual */ void StorePSA(uint pos, int32 value);
 
};
 

	
 
@@ -213,13 +213,13 @@ void AirportOverrideManager::SetEntitySp
 

	
 
	if (this->st->airport.psa == NULL) {
 
		/* There is no need to create a storage if the value is zero. */
 
		if (value == 0) return;
 

	
 
		/* Create storage on first modification. */
 
		uint32 grfid = (this->ro->grffile != NULL) ? this->ro->grffile->grfid : 0;
 
		uint32 grfid = (this->ro.grffile != NULL) ? this->ro.grffile->grfid : 0;
 
		assert(PersistentStorage::CanAllocateItem());
 
		this->st->airport.psa = new PersistentStorage(grfid);
 
	}
 
	this->st->airport.psa->StoreValue(pos, value);
 
}
 

	
 
@@ -232,45 +232,45 @@ void AirportOverrideManager::SetEntitySp
 
 * @param callback Callback ID.
 
 * @param param1 First parameter (var 10) of the callback.
 
 * @param param2 Second parameter (var 18) of the callback.
 
 */
 
AirportResolverObject::AirportResolverObject(TileIndex tile, Station *st, byte airport_id, byte layout,
 
		CallbackID callback, uint32 param1, uint32 param2)
 
	: ResolverObject(AirportSpec::Get(airport_id)->grf_prop.grffile, callback, param1, param2), airport_scope(this, tile, st, airport_id, layout)
 
	: ResolverObject(AirportSpec::Get(airport_id)->grf_prop.grffile, callback, param1, param2), airport_scope(*this, tile, st, airport_id, layout)
 
{
 
}
 

	
 
/**
 
 * Constructor of the scope resolver for an airport.
 
 * @param ro Surrounding resolver.
 
 * @param tile %Tile for the callback, only valid for airporttile callbacks.
 
 * @param st %Station of the airport for which the callback is run, or \c NULL for build gui.
 
 * @param airport_id Type of airport for which the callback is run.
 
 * @param layout Layout of the airport to build.
 
 */
 
AirportScopeResolver::AirportScopeResolver(ResolverObject *ro, TileIndex tile, Station *st, byte airport_id, byte layout) : ScopeResolver(ro)
 
AirportScopeResolver::AirportScopeResolver(ResolverObject &ro, TileIndex tile, Station *st, byte airport_id, byte layout) : ScopeResolver(ro)
 
{
 
	this->st = st;
 
	this->airport_id = airport_id;
 
	this->layout = layout;
 
	this->tile = tile;
 
}
 

	
 
SpriteID GetCustomAirportSprite(const AirportSpec *as, byte layout)
 
{
 
	AirportResolverObject object(INVALID_TILE, NULL, as->GetIndex(), layout);
 
	const SpriteGroup *group = SpriteGroup::Resolve(as->grf_prop.spritegroup[0], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(as->grf_prop.spritegroup[0], object);
 
	if (group == NULL) return as->preview_sprite;
 

	
 
	return group->GetResult();
 
}
 

	
 
uint16 GetAirportCallback(CallbackID callback, uint32 param1, uint32 param2, Station *st, TileIndex tile)
 
{
 
	AirportResolverObject object(tile, st, st->airport.type, st->airport.layout, callback, param1, param2);
 
	const SpriteGroup *group = SpriteGroup::Resolve(st->airport.GetSpec()->grf_prop.spritegroup[0], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(st->airport.GetSpec()->grf_prop.spritegroup[0], object);
 
	if (group == NULL) return CALLBACK_FAILED;
 

	
 
	return group->GetCallbackResult();
 
}
 

	
 
/**
 
@@ -280,13 +280,13 @@ uint16 GetAirportCallback(CallbackID cal
 
 * @param callback The callback to call.
 
 * @return The custom text.
 
 */
 
StringID GetAirportTextCallback(const AirportSpec *as, byte layout, uint16 callback)
 
{
 
	AirportResolverObject object(INVALID_TILE, NULL, as->GetIndex(), layout, (CallbackID)callback);
 
	const SpriteGroup *group = SpriteGroup::Resolve(as->grf_prop.spritegroup[0], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(as->grf_prop.spritegroup[0], object);
 
	uint16 cb_res = (group != NULL) ? group->GetCallbackResult() : CALLBACK_FAILED;
 
	if (cb_res == CALLBACK_FAILED || cb_res == 0x400) return STR_UNDEFINED;
 
	if (cb_res > 0x400) {
 
		ErrorUnknownCallbackResult(as->grf_prop.grffile->grfid, callback, cb_res);
 
		return STR_UNDEFINED;
 
	}
src/newgrf_airporttiles.cpp
Show inline comments
 
@@ -175,25 +175,25 @@ static uint32 GetAirportTileIDAtOffset(T
 
		case 0x43: return GetRelativePosition(this->tile, this->st->airport.tile);
 

	
 
		/* Animation frame of tile */
 
		case 0x44: return GetAnimationFrame(this->tile);
 

	
 
		/* Land info of nearby tiles */
 
		case 0x60: return GetNearbyAirportTileInformation(parameter, this->tile, this->st->index, this->ro->grffile->grf_version >= 8);
 
		case 0x60: return GetNearbyAirportTileInformation(parameter, this->tile, this->st->index, this->ro.grffile->grf_version >= 8);
 

	
 
		/* Animation stage of nearby tiles */
 
		case 0x61: {
 
			TileIndex tile = GetNearbyTile(parameter, this->tile);
 
			if (this->st->TileBelongsToAirport(tile)) {
 
				return GetAnimationFrame(tile);
 
			}
 
			return UINT_MAX;
 
		}
 

	
 
		/* Get airport tile ID at offset */
 
		case 0x62: return GetAirportTileIDAtOffset(GetNearbyTile(parameter, this->tile), this->st, this->ro->grffile->grfid);
 
		case 0x62: return GetAirportTileIDAtOffset(GetNearbyTile(parameter, this->tile), this->st, this->ro.grffile->grfid);
 
	}
 

	
 
	DEBUG(grf, 1, "Unhandled airport tile variable 0x%X", variable);
 

	
 
	*available = false;
 
	return UINT_MAX;
 
@@ -212,35 +212,35 @@ static uint32 GetAirportTileIDAtOffset(T
 
 * @param callback Callback ID.
 
 * @param callback_param1 First parameter (var 10) of the callback.
 
 * @param callback_param2 Second parameter (var 18) of the callback.
 
 */
 
AirportTileResolverObject::AirportTileResolverObject(const AirportTileSpec *ats, TileIndex tile, Station *st,
 
		CallbackID callback, uint32 callback_param1, uint32 callback_param2)
 
	: ResolverObject(ats->grf_prop.grffile, callback, callback_param1, callback_param2), tiles_scope(this, ats, tile, st)
 
	: ResolverObject(ats->grf_prop.grffile, callback, callback_param1, callback_param2), tiles_scope(*this, ats, tile, st)
 
{
 
}
 

	
 
/**
 
 * Constructor of the scope resolver specific for airport tiles.
 
 * @param ats Specification of the airport tiles.
 
 * @param tile %Tile for the callback, only valid for airporttile callbacks.
 
 * @param st Station of the airport for which the callback is run, or \c NULL for build gui.
 
 */
 
AirportTileScopeResolver::AirportTileScopeResolver(ResolverObject *ro, const AirportTileSpec *ats, TileIndex tile, Station *st) : ScopeResolver(ro)
 
AirportTileScopeResolver::AirportTileScopeResolver(ResolverObject &ro, const AirportTileSpec *ats, TileIndex tile, Station *st) : ScopeResolver(ro)
 
{
 
	assert(st != NULL);
 

	
 
	this->st = st;
 
	this->airport_id = st->airport.type;
 
	this->tile = tile;
 
}
 

	
 
uint16 GetAirportTileCallback(CallbackID callback, uint32 param1, uint32 param2, const AirportTileSpec *ats, Station *st, TileIndex tile, int extra_data = 0)
 
{
 
	AirportTileResolverObject object(ats, tile, st, callback, param1, param2);
 
	const SpriteGroup *group = SpriteGroup::Resolve(ats->grf_prop.spritegroup[0], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(ats->grf_prop.spritegroup[0], object);
 
	if (group == NULL) return CALLBACK_FAILED;
 

	
 
	return group->GetCallbackResult();
 
}
 

	
 
static void AirportDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, byte colour, StationGfx gfx)
 
@@ -272,13 +272,13 @@ bool DrawNewAirportTile(TileInfo *ti, St
 
		}
 

	
 
		if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED);
 
	}
 

	
 
	AirportTileResolverObject object(airts, ti->tile, st);
 
	const SpriteGroup *group = SpriteGroup::Resolve(airts->grf_prop.spritegroup[0], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(airts->grf_prop.spritegroup[0], object);
 
	if (group == NULL || group->type != SGT_TILELAYOUT) {
 
		return false;
 
	}
 

	
 
	const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group;
 
	AirportDrawTileLayout(ti, tlgroup, Company::Get(st->owner)->colour, gfx);
src/newgrf_airporttiles.h
Show inline comments
 
@@ -21,13 +21,13 @@
 
/** Scope resolver for handling the tiles of an airport. */
 
struct AirportTileScopeResolver : public ScopeResolver {
 
	struct Station *st;  ///< %Station of the airport for which the callback is run, or \c NULL for build gui.
 
	byte airport_id;     ///< Type of airport for which the callback is run.
 
	TileIndex tile;      ///< Tile for the callback, only valid for airporttile callbacks.
 

	
 
	AirportTileScopeResolver(ResolverObject *ro, const AirportTileSpec *ats, TileIndex tile, Station *st);
 
	AirportTileScopeResolver(ResolverObject &ro, const AirportTileSpec *ats, TileIndex tile, Station *st);
 

	
 
	/* virtual */ uint32 GetRandomBits() const;
 
	/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
 
};
 

	
 
/** Resolver for tiles of an airport. */
src/newgrf_canal.cpp
Show inline comments
 
@@ -20,13 +20,13 @@
 
WaterFeature _water_feature[CF_END];
 

	
 
/** Scope resolver of a canal tile. */
 
struct CanalScopeResolver : public ScopeResolver {
 
	TileIndex tile; ///< Tile containing the canal.
 

	
 
	CanalScopeResolver(ResolverObject *ro, TileIndex tile);
 
	CanalScopeResolver(ResolverObject &ro, TileIndex tile);
 

	
 
	/* virtual */ uint32 GetRandomBits() const;
 
	/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
 
};
 

	
 
/** Resolver object for canals. */
 
@@ -105,13 +105,13 @@ struct CanalResolverObject : public Reso
 
{
 
	if (group->num_loaded == 0) return NULL;
 

	
 
	return group->loaded[0];
 
}
 

	
 
CanalScopeResolver::CanalScopeResolver(ResolverObject *ro, TileIndex tile) : ScopeResolver(ro)
 
CanalScopeResolver::CanalScopeResolver(ResolverObject &ro, TileIndex tile) : ScopeResolver(ro)
 
{
 
	this->tile = tile;
 
}
 

	
 
/**
 
 * Canal resolver constructor.
 
@@ -120,26 +120,26 @@ CanalScopeResolver::CanalScopeResolver(R
 
 * @param callback Callback ID.
 
 * @param callback_param1 First parameter (var 10) of the callback.
 
 * @param callback_param2 Second parameter (var 18) of the callback.
 
 */
 
CanalResolverObject::CanalResolverObject(const GRFFile *grffile, TileIndex tile,
 
		CallbackID callback, uint32 callback_param1, uint32 callback_param2)
 
		: ResolverObject(grffile, callback, callback_param1, callback_param2), canal_scope(this, tile)
 
		: ResolverObject(grffile, callback, callback_param1, callback_param2), canal_scope(*this, tile)
 
{
 
}
 

	
 
/**
 
 * Lookup the base sprite to use for a canal.
 
 * @param feature Which canal feature we want.
 
 * @param tile Tile index of canal, if appropriate.
 
 * @return Base sprite returned by GRF, or \c 0 if none.
 
 */
 
SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile)
 
{
 
	CanalResolverObject object(_water_feature[feature].grffile, tile);
 
	const SpriteGroup *group = SpriteGroup::Resolve(_water_feature[feature].group, &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(_water_feature[feature].group, object);
 
	if (group == NULL) return 0;
 

	
 
	return group->GetResult();
 
}
 

	
 
/**
 
@@ -151,13 +151,13 @@ SpriteID GetCanalSprite(CanalFeature fea
 
 * @param tile     Tile index of canal.
 
 * @return Callback result or #CALLBACK_FAILED if the callback failed.
 
 */
 
static uint16 GetCanalCallback(CallbackID callback, uint32 param1, uint32 param2, CanalFeature feature, TileIndex tile)
 
{
 
	CanalResolverObject object(_water_feature[feature].grffile, tile, callback, param1, param2);
 
	const SpriteGroup *group = SpriteGroup::Resolve(_water_feature[feature].group, &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(_water_feature[feature].group, object);
 
	if (group == NULL) return CALLBACK_FAILED;
 

	
 
	return group->GetCallbackResult();
 
}
 

	
 
/**
src/newgrf_cargo.cpp
Show inline comments
 
@@ -47,23 +47,23 @@ CargoResolverObject::CargoResolverObject
 
 * @param cs Cargo being queried.
 
 * @return Custom sprite to draw, or \c 0 if not available.
 
 */
 
SpriteID GetCustomCargoSprite(const CargoSpec *cs)
 
{
 
	CargoResolverObject object(cs);
 
	const SpriteGroup *group = SpriteGroup::Resolve(cs->group, &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(cs->group, object);
 
	if (group == NULL) return 0;
 

	
 
	return group->GetResult();
 
}
 

	
 

	
 
uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const CargoSpec *cs)
 
{
 
	CargoResolverObject object(cs, callback, param1, param2);
 
	const SpriteGroup *group = SpriteGroup::Resolve(cs->group, &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(cs->group, object);
 
	if (group == NULL) return CALLBACK_FAILED;
 

	
 
	return group->GetCallbackResult();
 
}
 

	
 
/**
src/newgrf_engine.cpp
Show inline comments
 
@@ -357,13 +357,13 @@ static byte MapAircraftMovementAction(co
 
	 * way of avoiding this without removing consts deep within gui code.
 
	 */
 
	Vehicle *v = const_cast<Vehicle *>(this->v);
 

	
 
	/* This function must only be called when processing triggers -- any
 
	 * other time is an error. */
 
	assert(this->ro->trigger != 0);
 
	assert(this->ro.trigger != 0);
 

	
 
	if (v != NULL) v->waiting_triggers = triggers;
 
}
 

	
 

	
 
/* virtual */ ScopeResolver *VehicleResolverObject::GetScope(VarSpriteGroupScope scope, byte relative)
 
@@ -543,13 +543,13 @@ static uint32 VehicleGetVariable(Vehicle
 
			/* The cargo translation is specific to the accessing GRF, and thus cannot be cached. */
 
			CargoID common_cargo_type = (v->grf_cache.consist_cargo_information >> 8) & 0xFF;
 

	
 
			/* Unlike everywhere else the cargo translation table is only used since grf version 8, not 7.
 
			 * Note: The grffile == NULL case only happens if this function is called for default vehicles.
 
			 *       And this is only done by CheckCaches(). */
 
			const GRFFile *grffile = object->ro->grffile;
 
			const GRFFile *grffile = object->ro.grffile;
 
			uint8 common_bitnum = (common_cargo_type == CT_INVALID) ? 0xFF :
 
				(grffile == NULL || grffile->grf_version < 8) ? CargoSpec::Get(common_cargo_type)->bitnum : grffile->cargo_map[common_cargo_type];
 

	
 
			return (v->grf_cache.consist_cargo_information & 0xFFFF00FF) | common_bitnum << 8;
 
		}
 

	
 
@@ -614,13 +614,13 @@ static uint32 VehicleGetVariable(Vehicle
 
		case 0x48: return v->GetEngine()->flags; // Vehicle Type Info
 
		case 0x49: return v->build_year;
 

	
 
		case 0x4A: {
 
			if (v->type != VEH_TRAIN) return 0;
 
			RailType rt = GetTileRailType(v->tile);
 
			return (HasPowerOnRail(Train::From(v)->railtype, rt) ? 0x100 : 0) | GetReverseRailTypeTranslation(rt, object->ro->grffile);
 
			return (HasPowerOnRail(Train::From(v)->railtype, rt) ? 0x100 : 0) | GetReverseRailTypeTranslation(rt, object->ro.grffile);
 
		}
 

	
 
		case 0x4B: // Long date of last service
 
			return v->date_of_last_service;
 

	
 
		case 0x4C: // Current maximum speed in NewGRF units
 
@@ -640,14 +640,14 @@ static uint32 VehicleGetVariable(Vehicle
 
			}
 

	
 
		case 0x61: // Get variable of n-th vehicle in chain [signed number relative to vehicle]
 
			if (!v->IsGroundVehicle() || parameter == 0x61) return 0;
 

	
 
			/* Only allow callbacks that don't change properties to avoid circular dependencies. */
 
			if (object->ro->callback == CBID_NO_CALLBACK || object->ro->callback == CBID_RANDOM_TRIGGER || object->ro->callback == CBID_TRAIN_ALLOW_WAGON_ATTACH ||
 
					object->ro->callback == CBID_VEHICLE_START_STOP_CHECK || object->ro->callback == CBID_VEHICLE_32DAY_CALLBACK || object->ro->callback == CBID_VEHICLE_COLOUR_MAPPING) {
 
			if (object->ro.callback == CBID_NO_CALLBACK || object->ro.callback == CBID_RANDOM_TRIGGER || object->ro.callback == CBID_TRAIN_ALLOW_WAGON_ATTACH ||
 
					object->ro.callback == CBID_VEHICLE_START_STOP_CHECK || object->ro.callback == CBID_VEHICLE_32DAY_CALLBACK || object->ro.callback == CBID_VEHICLE_COLOUR_MAPPING) {
 
				Vehicle *u = v->Move((int32)GetRegister(0x10F));
 
				if (u == NULL) return 0;
 

	
 
				if (parameter == 0x5F) {
 
					/* This seems to be the only variable that makes sense to access via var 61, but is not handled by VehicleGetVariable */
 
					return (u->random_bits << 8) | u->waiting_triggers;
 
@@ -932,13 +932,13 @@ static uint32 VehicleGetVariable(Vehicle
 
 * Scope resolver of a single vehicle.
 
 * @param ro Surrounding resolver.
 
 * @param engine_type Engine type
 
 * @param v %Vehicle being resolved.
 
 * @param info_view Indicates if the item is being drawn in an info window.
 
 */
 
VehicleScopeResolver::VehicleScopeResolver(ResolverObject *ro, EngineID engine_type, const Vehicle *v, bool info_view)
 
VehicleScopeResolver::VehicleScopeResolver(ResolverObject &ro, EngineID engine_type, const Vehicle *v, bool info_view)
 
		: ScopeResolver(ro)
 
{
 
	this->v = v;
 
	this->self_type = engine_type;
 
	this->info_view = info_view;
 
}
 
@@ -963,15 +963,15 @@ static const GRFFile *GetEngineGrfFile(E
 
 * @param callback_param1 First parameter (var 10) of the callback.
 
 * @param callback_param2 Second parameter (var 18) of the callback.
 
 */
 
VehicleResolverObject::VehicleResolverObject(EngineID engine_type, const Vehicle *v, bool info_view,
 
		CallbackID callback, uint32 callback_param1, uint32 callback_param2)
 
	: ResolverObject(GetEngineGrfFile(engine_type), callback, callback_param1, callback_param2),
 
	self_scope(this, engine_type, v, info_view),
 
	parent_scope(this, engine_type, ((v != NULL) ? v->First() : v), info_view),
 
	relative_scope(this, engine_type, v, info_view),
 
	self_scope(*this, engine_type, v, info_view),
 
	parent_scope(*this, engine_type, ((v != NULL) ? v->First() : v), info_view),
 
	relative_scope(*this, engine_type, v, info_view),
 
	cached_relative_count(0)
 
{
 
}
 

	
 
/**
 
 * Retrieve the SpriteGroup for the specified vehicle.
 
@@ -1016,13 +1016,13 @@ static const SpriteGroup *GetVehicleSpri
 
}
 

	
 

	
 
SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction direction, EngineImageType image_type)
 
{
 
	VehicleResolverObject object(engine, v, false, CBID_NO_CALLBACK, image_type);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetVehicleSpriteGroup(engine, v), &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetVehicleSpriteGroup(engine, v), object);
 
	if (group == NULL || group->GetNumResults() == 0) return 0;
 

	
 
	return group->GetResult() + (direction % group->GetNumResults());
 
}
 

	
 

	
 
@@ -1033,13 +1033,13 @@ SpriteID GetRotorOverrideSprite(EngineID
 
	/* Only valid for helicopters */
 
	assert(e->type == VEH_AIRCRAFT);
 
	assert(!(e->u.air.subtype & AIR_CTOL));
 

	
 
	VehicleResolverObject object(engine, v, info_view, CBID_NO_CALLBACK, image_type);
 
	const SpriteGroup *group = GetWagonOverrideSpriteSet(engine, CT_DEFAULT, engine);
 
	group = SpriteGroup::Resolve(group, &object);
 
	group = SpriteGroup::Resolve(group, object);
 

	
 
	if (group == NULL || group->GetNumResults() == 0) return 0;
 

	
 
	if (v == NULL) return group->GetResult();
 

	
 
	return group->GetResult() + (info_view ? 0 : (v->Next()->Next()->state % group->GetNumResults()));
 
@@ -1066,13 +1066,13 @@ bool UsesWagonOverride(const Vehicle *v)
 
 * @param v        The vehicle to evaluate the callback for, or NULL if it doesnt exist yet
 
 * @return The value the callback returned, or CALLBACK_FAILED if it failed
 
 */
 
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
 
{
 
	VehicleResolverObject object(engine, v, false, callback, param1, param2);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetVehicleSpriteGroup(engine, v, false), &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetVehicleSpriteGroup(engine, v, false), object);
 
	if (group == NULL) return CALLBACK_FAILED;
 

	
 
	return group->GetCallbackResult();
 
}
 

	
 
/**
 
@@ -1087,13 +1087,13 @@ uint16 GetVehicleCallback(CallbackID cal
 
 */
 
uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent)
 
{
 
	VehicleResolverObject object(engine, v, false, callback, param1, param2);
 
	object.parent_scope.SetVehicle(parent);
 

	
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetVehicleSpriteGroup(engine, v, false), &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetVehicleSpriteGroup(engine, v, false), object);
 
	if (group == NULL) return CALLBACK_FAILED;
 

	
 
	return group->GetCallbackResult();
 
}
 

	
 

	
 
@@ -1118,13 +1118,13 @@ static void DoTriggerVehicle(Vehicle *v,
 
	/* We can't trigger a non-existent vehicle... */
 
	assert(v != NULL);
 

	
 
	VehicleResolverObject object(v->engine_type, v, false, CBID_RANDOM_TRIGGER);
 
	object.trigger = trigger;
 

	
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetVehicleSpriteGroup(v->engine_type, v), &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetVehicleSpriteGroup(v->engine_type, v), object);
 
	if (group == NULL) return;
 

	
 
	byte new_random_bits = Random();
 
	uint32 reseed = object.GetReseedSum(); // The scope only affects triggers, not the reseeding
 
	v->random_bits &= ~reseed;
 
	v->random_bits |= (first ? new_random_bits : base_random_bits) & reseed;
src/newgrf_engine.h
Show inline comments
 
@@ -23,13 +23,13 @@
 
/** Resolver for a vehicle scope. */
 
struct VehicleScopeResolver : public ScopeResolver {
 
	const struct Vehicle *v; ///< The vehicle being resolved.
 
	EngineID self_type;      ///< Type of the vehicle.
 
	bool info_view;          ///< Indicates if the item is being drawn in an info window.
 

	
 
	VehicleScopeResolver(ResolverObject *ro, EngineID engine_type, const Vehicle *v, bool info_view);
 
	VehicleScopeResolver(ResolverObject &ro, EngineID engine_type, const Vehicle *v, bool info_view);
 

	
 
	void SetVehicle(const Vehicle *v) { this->v = v; }
 

	
 
	/* virtual */ uint32 GetRandomBits() const;
 
	/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
 
	/* virtual */ uint32 GetTriggers() const;
src/newgrf_generic.cpp
Show inline comments
 
@@ -26,13 +26,13 @@ struct GenericScopeResolver : public Sco
 
	uint8 dst_industry;        ///< Destination industry substitute type. 0xFF for "town", 0xFE for "unknown".
 
	uint8 distance;
 
	AIConstructionEvent event;
 
	uint8 count;
 
	uint8 station_size;
 

	
 
	GenericScopeResolver(ResolverObject *ro, bool ai_callback);
 
	GenericScopeResolver(ResolverObject &ro, bool ai_callback);
 

	
 
	/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
 

	
 
private:
 
	bool ai_callback; ///< Callback comes from the AI.
 
};
 
@@ -101,13 +101,13 @@ void AddGenericCallback(uint8 feature, c
 
}
 

	
 
/* virtual */ uint32 GenericScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
 
{
 
	if (this->ai_callback) {
 
		switch (variable) {
 
			case 0x40: return this->ro->grffile->cargo_map[this->cargo_type];
 
			case 0x40: return this->ro.grffile->cargo_map[this->cargo_type];
 

	
 
			case 0x80: return this->cargo_type;
 
			case 0x81: return CargoSpec::Get(this->cargo_type)->bitnum;
 
			case 0x82: return this->default_selection;
 
			case 0x83: return this->src_industry;
 
			case 0x84: return this->dst_industry;
 
@@ -136,22 +136,22 @@ void AddGenericCallback(uint8 feature, c
 

	
 
/**
 
 * Generic resolver.
 
 * @param ai_callback Callback comes from the AI.
 
 * @param callback Callback ID.
 
 */
 
GenericResolverObject::GenericResolverObject(bool ai_callback, CallbackID callback) : ResolverObject(NULL, callback), generic_scope(this, ai_callback)
 
GenericResolverObject::GenericResolverObject(bool ai_callback, CallbackID callback) : ResolverObject(NULL, callback), generic_scope(*this, ai_callback)
 
{
 
}
 

	
 
/**
 
 * Generic scope resolver.
 
 * @param ro Surrounding resolver.
 
 * @param ai_callback Callback comes from the AI.
 
 */
 
GenericScopeResolver::GenericScopeResolver(ResolverObject *ro, bool ai_callback) : ScopeResolver(ro)
 
GenericScopeResolver::GenericScopeResolver(ResolverObject &ro, bool ai_callback) : ScopeResolver(ro)
 
{
 
	this->cargo_type = 0;
 
	this->default_selection = 0;
 
	this->src_industry = 0;
 
	this->dst_industry = 0;
 
	this->distance = 0;
 
@@ -170,22 +170,22 @@ GenericScopeResolver::GenericScopeResolv
 
 * @param param1_grfv7 callback_param1 for GRFs up to version 7.
 
 * @param param1_grfv8 callback_param1 for GRFs from version 8 on.
 
 * @param [out] file Optionally returns the GRFFile which made the final decision for the callback result.
 
 *                   May be NULL if not required.
 
 * @return callback value if successful or CALLBACK_FAILED
 
 */
 
static uint16 GetGenericCallbackResult(uint8 feature, ResolverObject *object, uint32 param1_grfv7, uint32 param1_grfv8, const GRFFile **file)
 
static uint16 GetGenericCallbackResult(uint8 feature, ResolverObject &object, uint32 param1_grfv7, uint32 param1_grfv8, const GRFFile **file)
 
{
 
	assert(feature < lengthof(_gcl));
 

	
 
	/* Test each feature callback sprite group. */
 
	for (GenericCallbackList::const_iterator it = _gcl[feature].begin(); it != _gcl[feature].end(); ++it) {
 
		const SpriteGroup *group = it->group;
 
		object->grffile = it->file;
 
		object.grffile = it->file;
 
		/* Set callback param based on GRF version. */
 
		object->callback_param1 = it->file->grf_version >= 8 ? param1_grfv8 : param1_grfv7;
 
		object.callback_param1 = it->file->grf_version >= 8 ? param1_grfv8 : param1_grfv7;
 
		group = SpriteGroup::Resolve(group, object);
 
		if (group == NULL || group->GetCallbackResult() == CALLBACK_FAILED) continue;
 

	
 
		/* Return NewGRF file if necessary */
 
		if (file != NULL) *file = it->file;
 

	
 
@@ -235,13 +235,13 @@ uint16 GetAiPurchaseCallbackResult(uint8
 
	object.generic_scope.dst_industry      = dst_industry;
 
	object.generic_scope.distance          = distance;
 
	object.generic_scope.event             = event;
 
	object.generic_scope.count             = count;
 
	object.generic_scope.station_size      = station_size;
 

	
 
	uint16 callback = GetGenericCallbackResult(feature, &object, 0, 0, file);
 
	uint16 callback = GetGenericCallbackResult(feature, object, 0, 0, file);
 
	if (callback != CALLBACK_FAILED) callback = GB(callback, 0, 8);
 
	return callback;
 
}
 

	
 

	
 
/**
 
@@ -261,10 +261,10 @@ void AmbientSoundEffectCallback(TileInde
 

	
 
	uint32 param1_v7 = GetTileType(tile) << 28 | Clamp(TileHeight(tile), 0, 15) << 24 | GB(r, 16, 8) << 16 | GetTerrainType(tile);
 
	uint32 param1_v8 = GetTileType(tile) << 24 | GetTileZ(tile) << 16 | GB(r, 16, 8) << 8 | (HasTileWaterClass(tile) ? GetWaterClass(tile) : 0) << 3 | GetTerrainType(tile);
 

	
 
	/* Run callback. */
 
	const GRFFile *grf_file;
 
	uint16 callback = GetGenericCallbackResult(GSF_SOUNDFX, &object, param1_v7, param1_v8, &grf_file);
 
	uint16 callback = GetGenericCallbackResult(GSF_SOUNDFX, object, param1_v7, param1_v8, &grf_file);
 

	
 
	if (callback != CALLBACK_FAILED) PlayTileSound(grf_file, callback, tile);
 
}
src/newgrf_house.cpp
Show inline comments
 
@@ -36,13 +36,13 @@ HouseOverrideManager _house_mngr(NEW_HOU
 
 * @param tile %Tile containing the house.
 
 * @param town %Town containing the house.
 
 * @param not_yet_constructed House is still under construction.
 
 * @param initial_random_bits Random bits during construction checks.
 
 * @param watched_cargo_triggers Cargo types that triggered the watched cargo callback.
 
 */
 
HouseScopeResolver::HouseScopeResolver(ResolverObject *ro, HouseID house_id, TileIndex tile, Town *town,
 
HouseScopeResolver::HouseScopeResolver(ResolverObject &ro, HouseID house_id, TileIndex tile, Town *town,
 
			bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
 
		: ScopeResolver(ro)
 
{
 
	this->house_id = house_id;
 
	this->tile = tile;
 
	this->town = town;
 
@@ -75,14 +75,14 @@ static const GRFFile *GetHouseSpecGrf(Ho
 
 * @param watched_cargo_triggers Cargo types that triggered the watched cargo callback.
 
 */
 
HouseResolverObject::HouseResolverObject(HouseID house_id, TileIndex tile, Town *town,
 
		CallbackID callback, uint32 param1, uint32 param2,
 
		bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
 
	: ResolverObject(GetHouseSpecGrf(house_id), callback, param1, param2),
 
	house_scope(this, house_id, tile, town, not_yet_constructed, initial_random_bits, watched_cargo_triggers),
 
	town_scope(this, town, not_yet_constructed) // Don't access StorePSA if house is not yet constructed.
 
	house_scope(*this, house_id, tile, town, not_yet_constructed, initial_random_bits, watched_cargo_triggers),
 
	town_scope(*this, town, not_yet_constructed) // Don't access StorePSA if house is not yet constructed.
 
{
 
}
 

	
 
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid)
 
{
 
	/* Start from 1 because 0 means that no class has been assigned. */
 
@@ -349,23 +349,23 @@ static uint32 GetDistanceFromNearbyHouse
 

	
 
			HouseID new_house = _house_mngr.GetID(parameter, hs->grf_prop.grffile->grfid);
 
			return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, this->town);
 
		}
 

	
 
		/* Land info for nearby tiles. */
 
		case 0x62: return GetNearbyTileInformation(parameter, this->tile, this->ro->grffile->grf_version >= 8);
 
		case 0x62: return GetNearbyTileInformation(parameter, this->tile, this->ro.grffile->grf_version >= 8);
 

	
 
		/* Current animation frame of nearby house tiles */
 
		case 0x63: {
 
			TileIndex testtile = GetNearbyTile(parameter, this->tile);
 
			return IsTileType(testtile, MP_HOUSE) ? GetAnimationFrame(testtile) : 0;
 
		}
 

	
 
		/* Cargo acceptance history of nearby stations */
 
		case 0x64: {
 
			CargoID cid = GetCargoTranslation(parameter, this->ro->grffile);
 
			CargoID cid = GetCargoTranslation(parameter, this->ro.grffile);
 
			if (cid == CT_INVALID) return 0;
 

	
 
			/* Extract tile offset. */
 
			int8 x_offs = GB(GetRegister(0x100), 0, 8);
 
			int8 y_offs = GB(GetRegister(0x100), 8, 8);
 
			TileIndex testtile = TILE_MASK(this->tile + TileDiffXY(x_offs, y_offs));
 
@@ -397,21 +397,21 @@ static uint32 GetDistanceFromNearbyHouse
 
			TileIndex testtile = GetNearbyTile(parameter, this->tile);
 
			if (!IsTileType(testtile, MP_HOUSE)) return 0xFFFFFFFF;
 
			HouseSpec *hs = HouseSpec::Get(GetHouseType(testtile));
 
			/* Information about the grf local classid if the house has a class */
 
			uint houseclass = 0;
 
			if (hs->class_id != HOUSE_NO_CLASS) {
 
				houseclass = (hs->grf_prop.grffile == this->ro->grffile ? 1 : 2) << 8;
 
				houseclass = (hs->grf_prop.grffile == this->ro.grffile ? 1 : 2) << 8;
 
				houseclass |= _class_mapping[hs->class_id].class_id;
 
			}
 
			/* old house type or grf-local houseid */
 
			uint local_houseid = 0;
 
			if (this->house_id < NEW_HOUSE_OFFSET) {
 
				local_houseid = this->house_id;
 
			} else {
 
				local_houseid = (hs->grf_prop.grffile == this->ro->grffile ? 1 : 2) << 8;
 
				local_houseid = (hs->grf_prop.grffile == this->ro.grffile ? 1 : 2) << 8;
 
				local_houseid |= hs->grf_prop.local_id;
 
			}
 
			return houseclass << 16 | local_houseid;
 
		}
 

	
 
		/* GRFID of nearby house tile */
 
@@ -437,13 +437,13 @@ uint16 GetHouseCallback(CallbackID callb
 
{
 
	assert(IsValidTile(tile) && (not_yet_constructed || IsTileType(tile, MP_HOUSE)));
 

	
 
	HouseResolverObject object(house_id, tile, town, callback, param1, param2,
 
			not_yet_constructed, initial_random_bits, watched_cargo_triggers);
 

	
 
	const SpriteGroup *group = SpriteGroup::Resolve(HouseSpec::Get(house_id)->grf_prop.spritegroup[0], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(HouseSpec::Get(house_id)->grf_prop.spritegroup[0], object);
 
	if (group == NULL) return CALLBACK_FAILED;
 

	
 
	return group->GetCallbackResult();
 
}
 

	
 
static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, byte stage, HouseID house_id)
 
@@ -487,13 +487,13 @@ void DrawNewHouseTile(TileInfo *ti, Hous
 

	
 
		if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED);
 
	}
 

	
 
	HouseResolverObject object(house_id, ti->tile, Town::GetByTile(ti->tile));
 

	
 
	const SpriteGroup *group = SpriteGroup::Resolve(hs->grf_prop.spritegroup[0], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(hs->grf_prop.spritegroup[0], object);
 
	if (group != NULL && group->type == SGT_TILELAYOUT) {
 
		/* Limit the building stage to the number of stages supplied. */
 
		const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group;
 
		byte stage = GetHouseBuildingStage(ti->tile);
 
		DrawTileLayout(ti, tlgroup, stage, house_id);
 
	}
 
@@ -612,13 +612,13 @@ static void DoTriggerHouse(TileIndex til
 

	
 
	if (hs->grf_prop.spritegroup[0] == NULL) return;
 

	
 
	HouseResolverObject object(hid, tile, Town::GetByTile(tile), CBID_RANDOM_TRIGGER);
 
	object.trigger = trigger;
 

	
 
	const SpriteGroup *group = SpriteGroup::Resolve(hs->grf_prop.spritegroup[0], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(hs->grf_prop.spritegroup[0], object);
 
	if (group == NULL) return;
 

	
 
	byte new_random_bits = Random();
 
	byte random_bits = GetHouseRandomBits(tile);
 
	uint32 reseed = object.GetReseedSum(); // The scope only affects triggers, not the reseeding
 
	random_bits &= ~reseed;
src/newgrf_house.h
Show inline comments
 
@@ -24,13 +24,13 @@ struct HouseScopeResolver : public Scope
 
	TileIndex tile;                ///< Tile of this house.
 
	Town *town;                    ///< Town of this house.
 
	bool not_yet_constructed;      ///< True for construction check.
 
	uint16 initial_random_bits;    ///< Random bits during construction checks.
 
	uint32 watched_cargo_triggers; ///< Cargo types that triggered the watched cargo callback.
 

	
 
	HouseScopeResolver(ResolverObject *ro, HouseID house_id, TileIndex tile, Town *town,
 
	HouseScopeResolver(ResolverObject &ro, HouseID house_id, TileIndex tile, Town *town,
 
			bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers);
 

	
 
	/* virtual */ uint32 GetRandomBits() const;
 
	/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
 
	/* virtual */ uint32 GetTriggers() const;
 
	/* virtual */ void SetTriggers(int triggers) const;
src/newgrf_industries.cpp
Show inline comments
 
@@ -156,13 +156,13 @@ static uint32 GetCountAndDistanceOfClose
 

	
 
	return count << 16 | GB(closest_dist, 0, 16);
 
}
 

	
 
/* virtual */ uint32 IndustriesScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
 
{
 
	if (this->ro->callback == CBID_INDUSTRY_LOCATION) {
 
	if (this->ro.callback == CBID_INDUSTRY_LOCATION) {
 
		/* Variables available during construction check. */
 

	
 
		switch (variable) {
 
			case 0x80: return this->tile;
 
			case 0x81: return GB(this->tile, 8, 8);
 

	
 
@@ -182,13 +182,13 @@ static uint32 GetCountAndDistanceOfClose
 
			case 0x88: return GetTownRadiusGroup(this->industry->town, this->tile);
 

	
 
			/* Manhattan distance of the closest town */
 
			case 0x89: return min(DistanceManhattan(this->industry->town->xy, this->tile), 255);
 

	
 
			/* Lowest height of the tile */
 
			case 0x8A: return Clamp(GetTileZ(this->tile) * (this->ro->grffile->grf_version >= 8 ? 1 : TILE_HEIGHT), 0, 0xFF);
 
			case 0x8A: return Clamp(GetTileZ(this->tile) * (this->ro.grffile->grf_version >= 8 ? 1 : TILE_HEIGHT), 0, 0xFF);
 

	
 
			/* Distance to the nearest water/land tile */
 
			case 0x8B: return GetClosestWaterDistance(this->tile, (GetIndustrySpec(this->industry->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
 

	
 
			/* Square of Euclidian distance from town */
 
			case 0x8D: return min(DistanceSquare(this->industry->town->xy, this->tile), 65535);
 
@@ -198,13 +198,13 @@ static uint32 GetCountAndDistanceOfClose
 
		}
 
	}
 

	
 
	const IndustrySpec *indspec = GetIndustrySpec(this->type);
 

	
 
	if (this->industry == NULL) {
 
		DEBUG(grf, 1, "Unhandled variable 0x%X (no available industry) in callback 0x%x", variable, this->ro->callback);
 
		DEBUG(grf, 1, "Unhandled variable 0x%X (no available industry) in callback 0x%x", variable, this->ro.callback);
 

	
 
		*available = false;
 
		return UINT_MAX;
 
	}
 

	
 
	switch (variable) {
 
@@ -248,25 +248,25 @@ static uint32 GetCountAndDistanceOfClose
 
			return this->industry->founder | (is_ai ? 0x10000 : 0) | (colours << 24);
 
		}
 

	
 
		case 0x46: return this->industry->construction_date; // Date when built - long format - (in days)
 

	
 
		/* Get industry ID at offset param */
 
		case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->industry->location.tile, false), this->industry, this->ro->grffile->grfid);
 
		case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->industry->location.tile, false), this->industry, this->ro.grffile->grfid);
 

	
 
		/* Get random tile bits at offset param */
 
		case 0x61: {
 
			if (this->tile == INVALID_TILE) break;
 
			TileIndex tile = GetNearbyTile(parameter, this->tile, false);
 
			return this->industry->TileBelongsToIndustry(tile) ? GetIndustryRandomBits(tile) : 0;
 
		}
 

	
 
		/* Land info of nearby tiles */
 
		case 0x62:
 
			if (this->tile == INVALID_TILE) break;
 
			return GetNearbyIndustryTileInformation(parameter, this->tile, INVALID_INDUSTRY, false, this->ro->grffile->grf_version >= 8);
 
			return GetNearbyIndustryTileInformation(parameter, this->tile, INVALID_INDUSTRY, false, this->ro.grffile->grf_version >= 8);
 

	
 
		/* Animation stage of nearby tiles */
 
		case 0x63: {
 
			if (this->tile == INVALID_TILE) break;
 
			TileIndex tile = GetNearbyTile(parameter, this->tile, false);
 
			if (this->industry->TileBelongsToIndustry(tile)) {
 
@@ -426,13 +426,13 @@ static const GRFFile *GetGrffile(Industr
 
 * @param callback_param1 First parameter (var 10) of the callback.
 
 * @param callback_param2 Second parameter (var 18) of the callback.
 
 */
 
IndustriesResolverObject::IndustriesResolverObject(TileIndex tile, Industry *indus, IndustryType type, uint32 random_bits,
 
		CallbackID callback, uint32 callback_param1, uint32 callback_param2)
 
	: ResolverObject(GetGrffile(type), callback, callback_param1, callback_param2),
 
	industries_scope(this, tile, indus, type, random_bits),
 
	industries_scope(*this, tile, indus, type, random_bits),
 
	town_scope(NULL)
 
{
 
}
 

	
 
IndustriesResolverObject::~IndustriesResolverObject()
 
{
 
@@ -452,26 +452,26 @@ TownScopeResolver *IndustriesResolverObj
 
			t = this->industries_scope.industry->town;
 
			readonly = this->industries_scope.industry->index == INVALID_INDUSTRY;
 
		} else if (this->industries_scope.tile != INVALID_TILE) {
 
			t = ClosestTownFromTile(this->industries_scope.tile, UINT_MAX);
 
		}
 
		if (t == NULL) return NULL;
 
		this->town_scope = new TownScopeResolver(this, t, readonly);
 
		this->town_scope = new TownScopeResolver(*this, t, readonly);
 
	}
 
	return this->town_scope;
 
}
 

	
 
/**
 
 * Scope resolver for industries.
 
 * @param ro Surrounding resolver.
 
 * @param tile %Tile owned by the industry.
 
 * @param industry %Industry being resolved.
 
 * @param type Type of the industry.
 
 * @param random_bits Random bits of the new industry.
 
 */
 
IndustriesScopeResolver::IndustriesScopeResolver(ResolverObject *ro, TileIndex tile, Industry *industry, IndustryType type, uint32 random_bits)
 
IndustriesScopeResolver::IndustriesScopeResolver(ResolverObject &ro, TileIndex tile, Industry *industry, IndustryType type, uint32 random_bits)
 
	: ScopeResolver(ro)
 
{
 
	this->tile = tile;
 
	this->industry = industry;
 
	this->type = type;
 
	this->random_bits = random_bits;
 
@@ -487,13 +487,13 @@ IndustriesScopeResolver::IndustriesScope
 
 * @param tile The tile associated with the callback.
 
 * @return The callback result.
 
 */
 
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
 
{
 
	IndustriesResolverObject object(tile, industry, type, 0, callback, param1, param2);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup[0], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup[0], object);
 
	if (group == NULL) return CALLBACK_FAILED;
 

	
 
	return group->GetCallbackResult();
 
}
 

	
 
/**
 
@@ -520,13 +520,13 @@ CommandCost CheckIfCallBackAllowsCreatio
 
	ind.town = ClosestTownFromTile(tile, UINT_MAX);
 
	ind.random = initial_random_bits;
 
	ind.founder = founder;
 
	ind.psa = NULL;
 

	
 
	IndustriesResolverObject object(tile, &ind, type, seed, CBID_INDUSTRY_LOCATION, 0, creation_type);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup[0], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup[0], object);
 

	
 
	/* Unlike the "normal" cases, not having a valid result means we allow
 
	 * the building of the industry, as that's how it's done in TTDP. */
 
	if (group == NULL) return CommandCost();
 
	uint16 result = group->GetCallbackResult();
 
	if (result == CALLBACK_FAILED) return CommandCost();
 
@@ -593,13 +593,13 @@ void IndustryProductionCallback(Industry
 

	
 
			/* abort the function early, this error isn't critical and will allow the game to continue to run */
 
			break;
 
		}
 

	
 
		SB(object.callback_param2, 8, 16, loop);
 
		const SpriteGroup *tgroup = SpriteGroup::Resolve(spec->grf_prop.spritegroup[0], &object);
 
		const SpriteGroup *tgroup = SpriteGroup::Resolve(spec->grf_prop.spritegroup[0], object);
 
		if (tgroup == NULL || tgroup->type != SGT_INDUSTRY_PRODUCTION) break;
 
		const IndustryProductionSpriteGroup *group = (const IndustryProductionSpriteGroup *)tgroup;
 

	
 
		bool deref = (group->version == 1);
 

	
 
		for (uint i = 0; i < 3; i++) {
src/newgrf_industries.h
Show inline comments
 
@@ -18,13 +18,13 @@
 
struct IndustriesScopeResolver : public ScopeResolver {
 
	TileIndex tile;     ///< Tile owned by the industry.
 
	Industry *industry; ///< %Industry being resolved.
 
	IndustryType type;  ///< Type of the industry.
 
	uint32 random_bits; ///< Random bits of the new industry.
 

	
 
	IndustriesScopeResolver(ResolverObject *ro, TileIndex tile, Industry *industry, IndustryType type, uint32 random_bits = 0);
 
	IndustriesScopeResolver(ResolverObject &ro, TileIndex tile, Industry *industry, IndustryType type, uint32 random_bits = 0);
 

	
 
	/* virtual */ uint32 GetRandomBits() const;
 
	/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
 
	/* virtual */ uint32 GetTriggers() const;
 
	/* virtual */ void SetTriggers(int triggers) const;
 
	/* virtual */ void StorePSA(uint pos, int32 value);
src/newgrf_industrytiles.cpp
Show inline comments
 
@@ -75,25 +75,25 @@ uint32 GetRelativePosition(TileIndex til
 

	
 
		/* Animation frame. Like house variable 46 but can contain anything 0..FF. */
 
		case 0x44: return IsTileType(this->tile, MP_INDUSTRY) ? GetAnimationFrame(this->tile) : 0;
 

	
 
		/* Land info of nearby tiles */
 
		case 0x60: return GetNearbyIndustryTileInformation(parameter, this->tile,
 
				this->industry == NULL ? (IndustryID)INVALID_INDUSTRY : this->industry->index, true, this->ro->grffile->grf_version >= 8);
 
				this->industry == NULL ? (IndustryID)INVALID_INDUSTRY : this->industry->index, true, this->ro.grffile->grf_version >= 8);
 

	
 
		/* Animation stage of nearby tiles */
 
		case 0x61: {
 
			TileIndex tile = GetNearbyTile(parameter, this->tile);
 
			if (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == this->industry) {
 
				return GetAnimationFrame(tile);
 
			}
 
			return UINT_MAX;
 
		}
 

	
 
		/* Get industry tile ID at offset */
 
		case 0x62: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->tile), this->industry, this->ro->grffile->grfid);
 
		case 0x62: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->tile), this->industry, this->ro.grffile->grfid);
 
	}
 

	
 
	DEBUG(grf, 1, "Unhandled industry tile variable 0x%X", variable);
 

	
 
	*available = false;
 
	return UINT_MAX;
 
@@ -141,24 +141,24 @@ static const GRFFile *GetIndTileGrffile(
 
 * @param callback_param1 First parameter (var 10) of the callback.
 
 * @param callback_param2 Second parameter (var 18) of the callback.
 
 */
 
IndustryTileResolverObject::IndustryTileResolverObject(IndustryGfx gfx, TileIndex tile, Industry *indus,
 
			CallbackID callback, uint32 callback_param1, uint32 callback_param2)
 
	: ResolverObject(GetIndTileGrffile(gfx), callback, callback_param1, callback_param2),
 
	indtile_scope(this, indus, tile),
 
	ind_scope(this, tile, indus, indus->type)
 
	indtile_scope(*this, indus, tile),
 
	ind_scope(*this, tile, indus, indus->type)
 
{
 
}
 

	
 
/**
 
 * Constructor of the scope resolver for the industry tile.
 
 * @param ro Surrounding resolver.
 
 * @param industry %Industry owning the tile.
 
 * @param tile %Tile of the industry.
 
 */
 
IndustryTileScopeResolver::IndustryTileScopeResolver(ResolverObject *ro, Industry *industry, TileIndex tile) : ScopeResolver(ro)
 
IndustryTileScopeResolver::IndustryTileScopeResolver(ResolverObject &ro, Industry *industry, TileIndex tile) : ScopeResolver(ro)
 
{
 
	this->industry = industry;
 
	this->tile = tile;
 
}
 

	
 
static void IndustryDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, byte rnd_colour, byte stage, IndustryGfx gfx)
 
@@ -187,13 +187,13 @@ static void IndustryDrawTileLayout(const
 
uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile)
 
{
 
	assert(industry != NULL && IsValidTile(tile));
 
	assert(industry->index == INVALID_INDUSTRY || IsTileType(tile, MP_INDUSTRY));
 

	
 
	IndustryTileResolverObject object(gfx_id, tile, industry, callback, param1, param2);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetIndustryTileSpec(gfx_id)->grf_prop.spritegroup[0], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetIndustryTileSpec(gfx_id)->grf_prop.spritegroup[0], object);
 
	if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
 

	
 
	return group->GetCallbackResult();
 
}
 

	
 
bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds)
 
@@ -208,13 +208,13 @@ bool DrawNewIndustryTile(TileInfo *ti, I
 

	
 
		if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED);
 
	}
 

	
 
	IndustryTileResolverObject object(gfx, ti->tile, i);
 

	
 
	const SpriteGroup *group = SpriteGroup::Resolve(inds->grf_prop.spritegroup[0], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(inds->grf_prop.spritegroup[0], object);
 
	if (group == NULL || group->type != SGT_TILELAYOUT) return false;
 

	
 
	/* Limit the building stage to the number of stages supplied. */
 
	const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group;
 
	byte stage = GetIndustryConstructionStage(ti->tile);
 
	IndustryDrawTileLayout(ti, tlgroup, i->random_colour, stage, gfx);
 
@@ -325,13 +325,13 @@ static void DoTriggerIndustryTile(TileIn
 

	
 
	if (itspec->grf_prop.spritegroup[0] == NULL) return;
 

	
 
	IndustryTileResolverObject object(gfx, tile, ind, CBID_RANDOM_TRIGGER);
 
	object.trigger = trigger;
 

	
 
	const SpriteGroup *group = SpriteGroup::Resolve(itspec->grf_prop.spritegroup[0], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(itspec->grf_prop.spritegroup[0], object);
 
	if (group == NULL) return;
 

	
 
	byte new_random_bits = Random();
 
	byte random_bits = GetIndustryRandomBits(tile);
 
	random_bits &= ~object.reseed[VSG_SCOPE_SELF];
 
	random_bits |= new_random_bits & object.reseed[VSG_SCOPE_SELF];
src/newgrf_industrytiles.h
Show inline comments
 
@@ -18,13 +18,13 @@
 

	
 
/** Resolver for the industry tiles scope. */
 
struct IndustryTileScopeResolver : public ScopeResolver {
 
	Industry *industry; ///< Industry owning the tiles.
 
	TileIndex tile;     ///< %Tile being resolved.
 

	
 
	IndustryTileScopeResolver(ResolverObject *ro, Industry *industry, TileIndex tile);
 
	IndustryTileScopeResolver(ResolverObject &ro, Industry *industry, TileIndex tile);
 

	
 
	/* virtual */ uint32 GetRandomBits() const;
 
	/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
 
	/* virtual */ uint32 GetTriggers() const;
 
	/* virtual */ void SetTriggers(int triggers) const;
 
};
src/newgrf_object.cpp
Show inline comments
 
@@ -130,13 +130,13 @@ INSTANTIATE_NEWGRF_CLASS_METHODS(ObjectC
 
 * Constructor of an object scope resolver.
 
 * @param ro Surrounding resolver.
 
 * @param obj Object being resolved.
 
 * @param tile %Tile of the object.
 
 * @param view View of the object.
 
 */
 
ObjectScopeResolver::ObjectScopeResolver(ResolverObject *ro, Object *obj, TileIndex tile, uint8 view)
 
ObjectScopeResolver::ObjectScopeResolver(ResolverObject &ro, Object *obj, TileIndex tile, uint8 view)
 
		: ScopeResolver(ro)
 
{
 
	this->obj = obj;
 
	this->tile = tile;
 
	this->view = view;
 
}
 
@@ -323,31 +323,31 @@ static uint32 GetCountAndDistanceOfClose
 
		case 0x47: return this->obj->colour;
 

	
 
		/* Object view */
 
		case 0x48: return this->obj->view;
 

	
 
		/* Get object ID at offset param */
 
		case 0x60: return GetObjectIDAtOffset(GetNearbyTile(parameter, this->tile), this->ro->grffile->grfid);
 
		case 0x60: return GetObjectIDAtOffset(GetNearbyTile(parameter, this->tile), this->ro.grffile->grfid);
 

	
 
		/* Get random tile bits at offset param */
 
		case 0x61: {
 
			TileIndex tile = GetNearbyTile(parameter, this->tile);
 
			return (IsTileType(tile, MP_OBJECT) && Object::GetByTile(tile) == this->obj) ? GetObjectRandomBits(tile) : 0;
 
		}
 

	
 
		/* Land info of nearby tiles */
 
		case 0x62: return GetNearbyObjectTileInformation(parameter, this->tile, this->obj == NULL ? INVALID_OBJECT : this->obj->index, this->ro->grffile->grf_version >= 8);
 
		case 0x62: return GetNearbyObjectTileInformation(parameter, this->tile, this->obj == NULL ? INVALID_OBJECT : this->obj->index, this->ro.grffile->grf_version >= 8);
 

	
 
		/* Animation counter of nearby tile */
 
		case 0x63: {
 
			TileIndex tile = GetNearbyTile(parameter, this->tile);
 
			return (IsTileType(tile, MP_OBJECT) && Object::GetByTile(tile) == this->obj) ? GetAnimationFrame(tile) : 0;
 
		}
 

	
 
		/* Count of object, distance of closest instance */
 
		case 0x64: return GetCountAndDistanceOfClosestInstance(parameter, this->ro->grffile->grfid, this->tile, this->obj);
 
		case 0x64: return GetCountAndDistanceOfClosestInstance(parameter, this->ro.grffile->grfid, this->tile, this->obj);
 
	}
 

	
 
unhandled:
 
	DEBUG(grf, 1, "Unhandled object variable 0x%X", variable);
 

	
 
	*available = false;
 
@@ -380,13 +380,13 @@ static const SpriteGroup *GetObjectSprit
 
 * @param callback Callback ID.
 
 * @param callback_param1 First parameter (var 10) of the callback.
 
 * @param callback_param2 Second parameter (var 18) of the callback.
 
 */
 
ObjectResolverObject::ObjectResolverObject(const ObjectSpec *spec, Object *obj, TileIndex tile, uint8 view,
 
		CallbackID callback, uint32 param1, uint32 param2)
 
	: ResolverObject(spec->grf_prop.grffile, callback, param1, param2), object_scope(this, obj, tile, view)
 
	: ResolverObject(spec->grf_prop.grffile, callback, param1, param2), object_scope(*this, obj, tile, view)
 
{
 
	this->town_scope = NULL;
 
}
 

	
 
ObjectResolverObject::~ObjectResolverObject()
 
{
 
@@ -405,13 +405,13 @@ TownScopeResolver *ObjectResolverObject:
 
		if (this->object_scope.obj != NULL) {
 
			t = this->object_scope.obj->town;
 
		} else {
 
			t = ClosestTownFromTile(this->object_scope.tile, UINT_MAX);
 
		}
 
		if (t == NULL) return NULL;
 
		this->town_scope = new TownScopeResolver(this, t, this->object_scope.obj == NULL);
 
		this->town_scope = new TownScopeResolver(*this, t, this->object_scope.obj == NULL);
 
	}
 
	return this->town_scope;
 
}
 

	
 
/**
 
 * Perform a callback for an object.
 
@@ -424,13 +424,13 @@ TownScopeResolver *ObjectResolverObject:
 
 * @param view     The view of the object (only used when o == NULL).
 
 * @return The result of the callback.
 
 */
 
uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view)
 
{
 
	ObjectResolverObject object(spec, o, tile, view, callback, param1, param2);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetObjectSpriteGroup(spec, o), &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetObjectSpriteGroup(spec, o), object);
 
	if (group == NULL) return CALLBACK_FAILED;
 

	
 
	return group->GetCallbackResult();
 
}
 

	
 
/**
 
@@ -467,13 +467,13 @@ static void DrawTileLayout(const TileInf
 
 */
 
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
 
{
 
	Object *o = Object::GetByTile(ti->tile);
 
	ObjectResolverObject object(spec, o, ti->tile);
 

	
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetObjectSpriteGroup(spec, o), &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetObjectSpriteGroup(spec, o), object);
 
	if (group == NULL || group->type != SGT_TILELAYOUT) return;
 

	
 
	DrawTileLayout(ti, (const TileLayoutSpriteGroup *)group, spec);
 
}
 

	
 
/**
 
@@ -483,13 +483,13 @@ void DrawNewObjectTile(TileInfo *ti, con
 
 * @param spec Object spec to draw.
 
 * @param view The object's view.
 
 */
 
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view)
 
{
 
	ObjectResolverObject object(spec, NULL, INVALID_TILE, view);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetObjectSpriteGroup(spec, NULL), &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(GetObjectSpriteGroup(spec, NULL), object);
 
	if (group == NULL || group->type != SGT_TILELAYOUT) return;
 

	
 
	const DrawTileSprites *dts = ((const TileLayoutSpriteGroup *)group)->ProcessRegisters(NULL);
 

	
 
	PaletteID palette;
 
	if (Company::IsValidID(_local_company)) {
src/newgrf_object.h
Show inline comments
 
@@ -101,13 +101,13 @@ struct ObjectSpec {
 
/** Object scope resolver. */
 
struct ObjectScopeResolver : public ScopeResolver {
 
	struct Object *obj; ///< The object the callback is ran for.
 
	TileIndex tile;     ///< The tile related to the object.
 
	uint8 view;         ///< The view of the object.
 

	
 
	ObjectScopeResolver(ResolverObject *ro, Object *obj, TileIndex tile, uint8 view = 0);
 
	ObjectScopeResolver(ResolverObject &ro, Object *obj, TileIndex tile, uint8 view = 0);
 

	
 
	/* virtual */ uint32 GetRandomBits() const;
 
	/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
 
};
 

	
 
/** A resolver object to be used with feature 0F spritegroups. */
src/newgrf_railtype.cpp
Show inline comments
 
@@ -68,13 +68,13 @@
 
/**
 
 * Constructor of the railtype scope resolvers.
 
 * @param ro Surrounding resolver.
 
 * @param tile %Tile containing the track. For track on a bridge this is the southern bridgehead.
 
 * @param context Are we resolving sprites for the upper halftile, or on a bridge?
 
 */
 
RailTypeScopeResolver::RailTypeScopeResolver(ResolverObject *ro, TileIndex tile, TileContext context) : ScopeResolver(ro)
 
RailTypeScopeResolver::RailTypeScopeResolver(ResolverObject &ro, TileIndex tile, TileContext context) : ScopeResolver(ro)
 
{
 
	this->tile = tile;
 
	this->context = context;
 
}
 

	
 
/**
 
@@ -83,13 +83,13 @@ RailTypeScopeResolver::RailTypeScopeReso
 
 * @param context Are we resolving sprites for the upper halftile, or on a bridge?
 
 * @param grffile The GRF to do the lookup for.
 
 * @param param1 Extra parameter (first parameter of the callback, except railtypes do not have callbacks).
 
 * @param param2 Extra parameter (second parameter of the callback, except railtypes do not have callbacks).
 
 */
 
RailTypeResolverObject::RailTypeResolverObject(TileIndex tile, TileContext context, const GRFFile *grffile, uint32 param1, uint32 param2)
 
	: ResolverObject(grffile, CBID_NO_CALLBACK, param1, param2), railtype_scope(this, tile, context)
 
	: ResolverObject(grffile, CBID_NO_CALLBACK, param1, param2), railtype_scope(*this, tile, context)
 
{
 
}
 

	
 
/**
 
 * Get the sprite to draw for the given tile.
 
 * @param rti The rail type data (spec).
 
@@ -102,13 +102,13 @@ SpriteID GetCustomRailSprite(const Railt
 
{
 
	assert(rtsg < RTSG_END);
 

	
 
	if (rti->group[rtsg] == NULL) return 0;
 

	
 
	RailTypeResolverObject object(tile, context, rti->grffile[rtsg]);
 
	const SpriteGroup *group = SpriteGroup::Resolve(rti->group[rtsg], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(rti->group[rtsg], object);
 
	if (group == NULL || group->GetNumResults() == 0) return 0;
 

	
 
	return group->GetResult();
 
}
 

	
 
/**
 
@@ -126,13 +126,13 @@ SpriteID GetCustomSignalSprite(const Rai
 
	if (rti->group[RTSG_SIGNALS] == NULL) return 0;
 

	
 
	uint32 param1 = gui ? 0x10 : 0x00;
 
	uint32 param2 = (type << 16) | (var << 8) | state;
 
	RailTypeResolverObject object(tile, TCX_NORMAL, rti->grffile[RTSG_SIGNALS], param1, param2);
 

	
 
	const SpriteGroup *group = SpriteGroup::Resolve(rti->group[RTSG_SIGNALS], &object);
 
	const SpriteGroup *group = SpriteGroup::Resolve(rti->group[RTSG_SIGNALS], object);
 
	if (group == NULL || group->GetNumResults() == 0) return 0;
 

	
 
	return group->GetResult();
 
}
 

	
 
/**
src/newgrf_railtype.h
Show inline comments
 
@@ -18,13 +18,13 @@
 

	
 
/** Resolver for the railtype scope. */
 
struct RailTypeScopeResolver : public ScopeResolver {
 
	TileIndex tile;      ///< Tracktile. For track on a bridge this is the southern bridgehead.
 
	TileContext context; ///< Are we resolving sprites for the upper halftile, or on a bridge?
 

	
 
	RailTypeScopeResolver(ResolverObject *ro, TileIndex tile, TileContext context);
 
	RailTypeScopeResolver(ResolverObject &ro, TileIndex tile, TileContext context);
 

	
 
	/* virtual */ uint32 GetRandomBits() const;
 
	/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
 
};
 

	
 
/** Resolver object for rail types. */
src/newgrf_spritegroup.cpp
Show inline comments
 
@@ -34,41 +34,41 @@ RandomizedSpriteGroup::~RandomizedSprite
 
	free(this->groups);
 
}
 

	
 
TemporaryStorageArray<int32, 0x110> _temp_store;
 

	
 

	
 
static inline uint32 GetVariable(const ResolverObject *object, ScopeResolver *scope, byte variable, uint32 parameter, bool *available)
 
static inline uint32 GetVariable(const ResolverObject &object, ScopeResolver *scope, byte variable, uint32 parameter, bool *available)
 
{
 
	/* First handle variables common with Action7/9/D */
 
	uint32 value;
 
	if (GetGlobalVariable(variable, &value, object->grffile)) return value;
 
	if (GetGlobalVariable(variable, &value, object.grffile)) return value;
 

	
 
	/* Non-common variable */
 
	switch (variable) {
 
		case 0x0C: return object->callback;
 
		case 0x10: return object->callback_param1;
 
		case 0x18: return object->callback_param2;
 
		case 0x1C: return object->last_value;
 
		case 0x0C: return object.callback;
 
		case 0x10: return object.callback_param1;
 
		case 0x18: return object.callback_param2;
 
		case 0x1C: return object.last_value;
 

	
 
		case 0x5F: return (scope->GetRandomBits() << 8) | scope->GetTriggers();
 

	
 
		case 0x7D: return _temp_store.GetValue(parameter);
 

	
 
		case 0x7F:
 
			if (object == NULL || object->grffile == NULL) return 0;
 
			return object->grffile->GetParam(parameter);
 
			if (object.grffile == NULL) return 0;
 
			return object.grffile->GetParam(parameter);
 

	
 
		/* Not a common variable, so evaluate the feature specific variables */
 
		default: return scope->GetVariable(variable, parameter, available);
 
	}
 
}
 

	
 
ScopeResolver::ScopeResolver(ResolverObject *ro)
 
ScopeResolver::ScopeResolver(ResolverObject &ro)
 
		: ro(ro)
 
{
 
	this->ro = ro;
 
}
 

	
 
ScopeResolver::~ScopeResolver() {}
 

	
 
/**
 
 * Get a few random bits. Default implementation has no random bits.
 
@@ -120,13 +120,13 @@ ScopeResolver::~ScopeResolver() {}
 
 * @param grffile NewGRF file associated with the object (or \c NULL if none).
 
 * @param callback Callback code being resolved (default value is #CBID_NO_CALLBACK).
 
 * @param callback_param1 First parameter (var 10) of the callback (only used when \a callback is also set).
 
 * @param callback_param2 Second parameter (var 18) of the callback (only used when \a callback is also set).
 
 */
 
ResolverObject::ResolverObject(const GRFFile *grffile, CallbackID callback, uint32 callback_param1, uint32 callback_param2)
 
		: default_scope(this)
 
		: default_scope(*this)
 
{
 
	this->callback = callback;
 
	this->callback_param1 = callback_param1;
 
	this->callback_param2 = callback_param2;
 
	this->ResetState();
 

	
 
@@ -213,19 +213,19 @@ static U EvalAdjustT(const Deterministic
 
		case DSGA_OP_SAR:  return (S)last_value >> ((U)value & 0x1F);
 
		default:           return value;
 
	}
 
}
 

	
 

	
 
const SpriteGroup *DeterministicSpriteGroup::Resolve(ResolverObject *object) const
 
const SpriteGroup *DeterministicSpriteGroup::Resolve(ResolverObject &object) const
 
{
 
	uint32 last_value = 0;
 
	uint32 value = 0;
 
	uint i;
 

	
 
	ScopeResolver *scope = object->GetScope(this->var_scope);
 
	ScopeResolver *scope = object.GetScope(this->var_scope);
 

	
 
	for (i = 0; i < this->num_adjusts; i++) {
 
		DeterministicSpriteGroupAdjust *adjust = &this->adjusts[i];
 

	
 
		/* Try to get the variable. We shall assume it is available, unless told otherwise. */
 
		bool available = true;
 
@@ -256,13 +256,13 @@ const SpriteGroup *DeterministicSpriteGr
 
			case DSG_SIZE_DWORD: value = EvalAdjustT<uint32, int32>(adjust, scope, last_value, value); break;
 
			default: NOT_REACHED();
 
		}
 
		last_value = value;
 
	}
 

	
 
	object->last_value = last_value;
 
	object.last_value = last_value;
 

	
 
	if (this->num_ranges == 0) {
 
		/* nvar == 0 is a special case -- we turn our value into a callback result */
 
		if (value != CALLBACK_FAILED) value = GB(value, 0, 15);
 
		static CallbackResultSpriteGroup nvarzero(0, true);
 
		nvarzero.result = value;
 
@@ -276,42 +276,42 @@ const SpriteGroup *DeterministicSpriteGr
 
	}
 

	
 
	return SpriteGroup::Resolve(this->default_group, object);
 
}
 

	
 

	
 
const SpriteGroup *RandomizedSpriteGroup::Resolve(ResolverObject *object) const
 
const SpriteGroup *RandomizedSpriteGroup::Resolve(ResolverObject &object) const
 
{
 
	ScopeResolver *scope = object->GetScope(this->var_scope, this->count);
 
	if (object->trigger != 0) {
 
	ScopeResolver *scope = object.GetScope(this->var_scope, this->count);
 
	if (object.trigger != 0) {
 
		/* Handle triggers */
 
		/* Magic code that may or may not do the right things... */
 
		byte waiting_triggers = scope->GetTriggers();
 
		byte match = this->triggers & (waiting_triggers | object->trigger);
 
		byte match = this->triggers & (waiting_triggers | object.trigger);
 
		bool res = (this->cmp_mode == RSG_CMP_ANY) ? (match != 0) : (match == this->triggers);
 

	
 
		if (res) {
 
			waiting_triggers &= ~match;
 
			object->reseed[this->var_scope] |= (this->num_groups - 1) << this->lowest_randbit;
 
			object.reseed[this->var_scope] |= (this->num_groups - 1) << this->lowest_randbit;
 
		} else {
 
			waiting_triggers |= object->trigger;
 
			waiting_triggers |= object.trigger;
 
		}
 

	
 
		scope->SetTriggers(waiting_triggers);
 
	}
 

	
 
	uint32 mask  = (this->num_groups - 1) << this->lowest_randbit;
 
	byte index = (scope->GetRandomBits() & mask) >> this->lowest_randbit;
 

	
 
	return SpriteGroup::Resolve(this->groups[index], object);
 
}
 

	
 

	
 
const SpriteGroup *RealSpriteGroup::Resolve(ResolverObject *object) const
 
const SpriteGroup *RealSpriteGroup::Resolve(ResolverObject &object) const
 
{
 
	return object->ResolveReal(this);
 
	return object.ResolveReal(this);
 
}
 

	
 
/**
 
 * Process registers and the construction stage into the sprite layout.
 
 * The passed construction stage might get reset to zero, if it gets incorporated into the layout
 
 * during the preprocessing.
src/newgrf_spritegroup.h
Show inline comments
 
@@ -54,25 +54,26 @@ enum SpriteGroupType {
 
	SGT_TILELAYOUT,
 
	SGT_INDUSTRY_PRODUCTION,
 
};
 

	
 
struct SpriteGroup;
 
typedef uint32 SpriteGroupID;
 
struct ResolverObject;
 

	
 
/* SPRITE_WIDTH is 24. ECS has roughly 30 sprite groups per real sprite.
 
 * Adding an 'extra' margin would be assuming 64 sprite groups per real
 
 * sprite. 64 = 2^6, so 2^30 should be enough (for now) */
 
typedef Pool<SpriteGroup, SpriteGroupID, 1024, 1 << 30, PT_DATA> SpriteGroupPool;
 
extern SpriteGroupPool _spritegroup_pool;
 

	
 
/* Common wrapper for all the different sprite group types */
 
struct SpriteGroup : SpriteGroupPool::PoolItem<&_spritegroup_pool> {
 
protected:
 
	SpriteGroup(SpriteGroupType type) : type(type) {}
 
	/** Base sprite group resolver */
 
	virtual const SpriteGroup *Resolve(struct ResolverObject *object) const { return this; };
 
	virtual const SpriteGroup *Resolve(ResolverObject &object) const { return this; };
 

	
 
public:
 
	virtual ~SpriteGroup() {}
 

	
 
	SpriteGroupType type;
 

	
 
@@ -86,13 +87,13 @@ public:
 
	 * do not like NULL and checking for NULL *everywhere* is more cumbersome than
 
	 * this little helper function.
 
	 * @param group the group to resolve for
 
	 * @param object information needed to resolve the group
 
	 * @return the resolved group
 
	 */
 
	static const SpriteGroup *Resolve(const SpriteGroup *group, ResolverObject *object)
 
	static const SpriteGroup *Resolve(const SpriteGroup *group, ResolverObject &object)
 
	{
 
		return group == NULL ? NULL : group->Resolve(object);
 
	}
 
};
 

	
 

	
 
@@ -112,13 +113,13 @@ struct RealSpriteGroup : SpriteGroup {
 
	byte num_loaded;       ///< Number of loaded groups
 
	byte num_loading;      ///< Number of loading groups
 
	const SpriteGroup **loaded;  ///< List of loaded groups (can be SpriteIDs or Callback results)
 
	const SpriteGroup **loading; ///< List of loading groups (can be SpriteIDs or Callback results)
 

	
 
protected:
 
	const SpriteGroup *Resolve(ResolverObject *object) const;
 
	const SpriteGroup *Resolve(ResolverObject &object) const;
 
};
 

	
 
/* Shared by deterministic and random groups. */
 
enum VarSpriteGroupScope {
 
	VSG_BEGIN,
 

	
 
@@ -201,13 +202,13 @@ struct DeterministicSpriteGroup : Sprite
 
	DeterministicSpriteGroupRange *ranges; // Dynamically allocated
 

	
 
	/* Dynamically allocated, this is the sole owner */
 
	const SpriteGroup *default_group;
 

	
 
protected:
 
	const SpriteGroup *Resolve(ResolverObject *object) const;
 
	const SpriteGroup *Resolve(ResolverObject &object) const;
 
};
 

	
 
enum RandomizedSpriteGroupCompareMode {
 
	RSG_CMP_ANY,
 
	RSG_CMP_ALL,
 
};
 
@@ -225,13 +226,13 @@ struct RandomizedSpriteGroup : SpriteGro
 
	byte lowest_randbit; ///< Look for this in the per-object randomized bitmask:
 
	byte num_groups; ///< must be power of 2
 

	
 
	const SpriteGroup **groups; ///< Take the group with appropriate index:
 

	
 
protected:
 
	const SpriteGroup *Resolve(ResolverObject *object) const;
 
	const SpriteGroup *Resolve(ResolverObject &object) const;
 
};
 

	
 

	
 
/* This contains a callback result. A failed callback has a value of
 
 * CALLBACK_FAILED */
 
struct CallbackResultSpriteGroup : SpriteGroup {
 
@@ -298,24 +299,22 @@ struct IndustryProductionSpriteGroup : S
 
	uint8 version;
 
	int16 subtract_input[3];  // signed
 
	uint16 add_output[2];     // unsigned
 
	uint8 again;
 
};
 

	
 
struct ResolverObject;
 

	
 
/**
 
 * Interface to query and set values specific to a single #VarSpriteGroupScope (action 2 scope).
 
 *
 
 * Multiple of these interfaces are combined into a #ResolverObject to allow access
 
 * to different game entities from a #SpriteGroup-chain (action 1-2-3 chain).
 
 */
 
struct ScopeResolver {
 
	ResolverObject *ro; ///< Surrounding resolver object.
 
	ResolverObject &ro; ///< Surrounding resolver object.
 

	
 
	ScopeResolver(ResolverObject *ro);
 
	ScopeResolver(ResolverObject &ro);
 
	virtual ~ScopeResolver();
 

	
 
	virtual uint32 GetRandomBits() const;
 
	virtual uint32 GetTriggers() const;
 
	virtual void SetTriggers(int triggers) const;
 

	
src/newgrf_station.cpp
Show inline comments
 
@@ -267,13 +267,13 @@ TownScopeResolver *StationResolverObject
 
		if (this->station_scope.st != NULL) {
 
			t = this->station_scope.st->town;
 
		} else if (this->station_scope.tile != INVALID_TILE) {
 
			t = ClosestTownFromTile(this->station_scope.tile, UINT_MAX);
 
		}
 
		if (t == NULL) return NULL;
 
		this->town_scope = new TownScopeResolver(this, t, this->station_scope.st == NULL);
 
		this->town_scope = new TownScopeResolver(*this, t, this->station_scope.st == NULL);
 
	}
 
	return this->town_scope;
 
}
 

	
 
/* virtual */ uint32 StationScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
 
{
 
@@ -293,13 +293,13 @@ TownScopeResolver *StationResolverObject
 
					TileIndex tile = this->tile;
 
					if (parameter != 0) tile = GetNearbyTile(parameter, tile, true, this->axis); // only perform if it is required
 

	
 
					Slope tileh = GetTileSlope(tile);
 
					bool swap = (this->axis == AXIS_Y && HasBit(tileh, CORNER_W) != HasBit(tileh, CORNER_E));
 

	
 
					return GetNearbyTileInformation(tile, this->ro->grffile->grf_version >= 8) ^ (swap ? SLOPE_EW : 0);
 
					return GetNearbyTileInformation(tile, this->ro.grffile->grf_version >= 8) ^ (swap ? SLOPE_EW : 0);
 
				}
 
				break;
 

	
 
			case 0xFA: return Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Build date, clamped to a 16 bit value
 
		}
 

	
 
@@ -352,13 +352,13 @@ TownScopeResolver *StationResolverObject
 
			TileIndex tile = this->tile;
 
			if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
 

	
 
			Slope tileh = GetTileSlope(tile);
 
			bool swap = (axis == AXIS_Y && HasBit(tileh, CORNER_W) != HasBit(tileh, CORNER_E));
 

	
 
			return GetNearbyTileInformation(tile, this->ro->grffile->grf_version >= 8) ^ (swap ? SLOPE_EW : 0);
 
			return GetNearbyTileInformation(tile, this->ro.grffile->grf_version >= 8) ^ (swap ? SLOPE_EW : 0);
 
		}
 

	
 
		case 0x68: { // Station info of nearby tiles
 
			TileIndex nearby_tile = GetNearbyTile(parameter, this->tile);
 

	
 
			if (!HasStationTileRail(nearby_tile)) return 0xFFFFFFFF;
 
@@ -383,13 +383,13 @@ TownScopeResolver *StationResolverObject
 
		case 0xFA: return Clamp(this->st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535);
 
	}
 

	
 
	return this->st->GetNewGRFVariable(this->ro, variable, parameter, available);
 
}
 

	
 
uint32 Station::GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const
 
uint32 Station::GetNewGRFVariable(const ResolverObject &object, byte variable, byte parameter, bool *available) const
 
{
 
	switch (variable) {
 
		case 0x48: { // Accepted cargo types
 
			CargoID cargo_type;
 
			uint32 value = 0;
 

	
 
@@ -406,13 +406,13 @@ uint32 Station::GetNewGRFVariable(const 
 
		case 0xF6: return this->airport.flags;
 
		case 0xF7: return GB(this->airport.flags, 8, 8);
 
	}
 

	
 
	/* Handle cargo variables with parameter, 0x60 to 0x65 and 0x69 */
 
	if ((variable >= 0x60 && variable <= 0x65) || variable == 0x69) {
 
		CargoID c = GetCargoTranslation(parameter, object->grffile);
 
		CargoID c = GetCargoTranslation(parameter, object.grffile);
 

	
 
		if (c == CT_INVALID) {
 
			switch (variable) {
 
				case 0x62: return 0xFFFFFFFF;
 
				case 0x64: return 0xFF00;
 
				default:   return 0;
 
@@ -454,13 +454,13 @@ uint32 Station::GetNewGRFVariable(const 
 
	DEBUG(grf, 1, "Unhandled station variable 0x%X", variable);
 

	
 
	*available = false;
 
	return UINT_MAX;
 
}
 

	
 
uint32 Waypoint::GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const
 
uint32 Waypoint::GetNewGRFVariable(const ResolverObject &object, byte variable, byte parameter, bool *available) const
 
{
 
	switch (variable) {
 
		case 0x48: return 0; // Accepted cargo types
 
		case 0x8A: return HVOT_WAYPOINT;
 
		case 0xF1: return 0; // airport type
 
		case 0xF2: return 0; // truck stop status
 
@@ -543,13 +543,13 @@ uint32 Waypoint::GetNewGRFVariable(const
 
 * @param callback_param1 First parameter (var 10) of the callback.
 
 * @param callback_param2 Second parameter (var 18) of the callback.
 
 */
 
StationResolverObject::StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile,
 
		CallbackID callback, uint32 callback_param1, uint32 callback_param2)
 
	: ResolverObject((statspec != NULL ? statspec->grf_prop.grffile : NULL), callback, callback_param1, callback_param2),
 
	station_scope(this, statspec, st, tile), town_scope(NULL)
 
	station_scope(*this, statspec, st, tile), town_scope(NULL)
 
{
 
	/* Invalidate all cached vars */
 
	_svc.valid = 0;
 
}
 

	
 
StationResolverObject::~StationResolverObject()
 
@@ -561,51 +561,51 @@ StationResolverObject::~StationResolverO
 
 * Constructor for station scopes.
 
 * @param ro Surrounding resolver.
 
 * @param statspec Station (type) specification.
 
 * @param st Instance of the station.
 
 * @param tile %Tile of the station.
 
 */
 
StationScopeResolver::StationScopeResolver(ResolverObject *ro, const StationSpec *statspec, BaseStation *st, TileIndex tile)
 
StationScopeResolver::StationScopeResolver(ResolverObject &ro, const StationSpec *statspec, BaseStation *st, TileIndex tile)
 
	: ScopeResolver(ro)
 
{
 
	this->tile = tile;
 
	this->st = st;
 
	this->statspec = statspec;
 
	this->cargo_type = CT_INVALID;
 
	this->axis = INVALID_AXIS;
 
}
 

	
 
static const SpriteGroup *ResolveStation(StationResolverObject *object)
 
static const SpriteGroup *ResolveStation(StationResolverObject &object)
 
{
 
	CargoID ctype = CT_DEFAULT_NA;
 

	
 
	if (object->station_scope.st == NULL) {
 
	if (object.station_scope.st == NULL) {
 
		/* No station, so we are in a purchase list */
 
		ctype = CT_PURCHASE;
 
	} else if (Station::IsExpected(object->station_scope.st)) {
 
		const Station *st = Station::From(object->station_scope.st);
 
	} else if (Station::IsExpected(object.station_scope.st)) {
 
		const Station *st = Station::From(object.station_scope.st);
 
		/* Pick the first cargo that we have waiting */
 
		const CargoSpec *cs;
 
		FOR_ALL_CARGOSPECS(cs) {
 
			if (object->station_scope.statspec->grf_prop.spritegroup[cs->Index()] != NULL &&
 
			if (object.station_scope.statspec->grf_prop.spritegroup[cs->Index()] != NULL &&
 
					st->goods[cs->Index()].cargo.TotalCount() > 0) {
 
				ctype = cs->Index();
 
				break;
 
			}
 
		}
 
	}
 

	
 
	const SpriteGroup *group = object->station_scope.statspec->grf_prop.spritegroup[ctype];
 
	const SpriteGroup *group = object.station_scope.statspec->grf_prop.spritegroup[ctype];
 
	if (group == NULL) {
 
		ctype = CT_DEFAULT;
 
		group = object->station_scope.statspec->grf_prop.spritegroup[ctype];
 
		group = object.station_scope.statspec->grf_prop.spritegroup[ctype];
 
		if (group == NULL) return NULL;
 
	}
 

	
 
	/* Remember the cargo type we've picked */
 
	object->station_scope.cargo_type = ctype;
 
	object.station_scope.cargo_type = ctype;
 

	
 
	return SpriteGroup::Resolve(group, object);
 
}
 

	
 
/**
 
 * Resolve sprites for drawing a station tile.
 
@@ -615,13 +615,13 @@ static const SpriteGroup *ResolveStation
 
 * @param var10 Value to put in variable 10; normally 0; 1 when resolving the groundsprite and SSF_SEPARATE_GROUND is set.
 
 * @return First sprite of the Action 1 spriteset to use, minus an offset of 0x42D to accommodate for weird NewGRF specs.
 
 */
 
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10)
 
{
 
	StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, var10);
 
	const SpriteGroup *group = ResolveStation(&object);
 
	const SpriteGroup *group = ResolveStation(object);
 
	if (group == NULL || group->type != SGT_RESULT) return 0;
 
	return group->GetResult() - 0x42D;
 
}
 

	
 
/**
 
 * Resolve the sprites for custom station foundations.
 
@@ -635,22 +635,22 @@ SpriteID GetCustomStationRelocation(cons
 
SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info)
 
{
 
	/* callback_param1 == 2 means  we are resolving the foundation sprites. */
 
	StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, 2, layout | (edge_info << 16));
 

	
 
	ClearRegister(0x100);
 
	const SpriteGroup *group = ResolveStation(&object);
 
	const SpriteGroup *group = ResolveStation(object);
 
	if (group == NULL || group->type != SGT_RESULT) return 0;
 
	return group->GetResult() + GetRegister(0x100);
 
}
 

	
 

	
 
uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile)
 
{
 
	StationResolverObject object(statspec, st, tile, callback, param1, param2);
 
	const SpriteGroup *group = ResolveStation(&object);
 
	const SpriteGroup *group = ResolveStation(object);
 
	if (group == NULL) return CALLBACK_FAILED;
 
	return group->GetCallbackResult();
 
}
 

	
 
/**
 
 * Check the slope of a tile of a new station.
 
@@ -669,13 +669,13 @@ CommandCost PerformStationTileSlopeCheck
 

	
 
	StationResolverObject object(statspec, NULL, cur_tile, CBID_STATION_LAND_SLOPE_CHECK,
 
			(slope << 4) | (slope ^ (axis == AXIS_Y && HasBit(slope, CORNER_W) != HasBit(slope, CORNER_E) ? SLOPE_EW : 0)),
 
			(numtracks << 24) | (plat_len << 16) | (axis == AXIS_Y ? TileX(diff) << 8 | TileY(diff) : TileY(diff) << 8 | TileX(diff)));
 
	object.station_scope.axis = axis;
 

	
 
	const SpriteGroup *group = ResolveStation(&object);
 
	const SpriteGroup *group = ResolveStation(object);
 
	uint16 cb_res = group != NULL ? group->GetCallbackResult() : CALLBACK_FAILED;
 

	
 
	/* Failed callback means success. */
 
	if (cb_res == CALLBACK_FAILED) return CommandCost();
 

	
 
	/* The meaning of bit 10 is inverted for a grf version < 8. */
 
@@ -1020,13 +1020,13 @@ void TriggerStationRandomisation(Station
 
			}
 

	
 
			if (cargo_type == CT_INVALID || HasBit(ss->cargo_triggers, cargo_type)) {
 
				StationResolverObject object(ss, st, tile, CBID_RANDOM_TRIGGER, 0);
 
				object.trigger = trigger_bit;
 

	
 
				const SpriteGroup *group = ResolveStation(&object);
 
				const SpriteGroup *group = ResolveStation(object);
 
				if (group == NULL) continue;
 

	
 
				uint32 reseed = object.GetReseedSum();
 
				if (reseed != 0) {
 
					whole_reseed |= reseed;
 
					reseed >>= 16;
src/newgrf_station.h
Show inline comments
 
@@ -27,13 +27,13 @@ struct StationScopeResolver : public Sco
 
	TileIndex tile;                     ///< %Tile of the station.
 
	struct BaseStation *st;             ///< Instance of the station.
 
	const struct StationSpec *statspec; ///< Station (type) specification.
 
	CargoID cargo_type;                 ///< Type of cargo of the station.
 
	Axis axis;                          ///< Station axis, used only for the slope check callback.
 

	
 
	StationScopeResolver(ResolverObject *ro, const StationSpec *statspec, BaseStation *st, TileIndex tile);
 
	StationScopeResolver(ResolverObject &ro, const StationSpec *statspec, BaseStation *st, TileIndex tile);
 

	
 
	/* virtual */ uint32 GetRandomBits() const;
 
	/* virtual */ uint32 GetTriggers() const;
 
	/* virtual */ void SetTriggers(int triggers) const;
 

	
 
	/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
src/newgrf_town.cpp
Show inline comments
 
@@ -17,13 +17,13 @@
 
/**
 
 * Resolver of a town scope.
 
 * @param ro Surrounding resolver.
 
 * @param t %Town of the scope.
 
 * @param readonly Scope may change persistent storage of the town.
 
 */
 
TownScopeResolver::TownScopeResolver(ResolverObject *ro, Town *t, bool readonly) : ScopeResolver(ro)
 
TownScopeResolver::TownScopeResolver(ResolverObject &ro, Town *t, bool readonly) : ScopeResolver(ro)
 
{
 
	this->t = t;
 
	this->readonly = readonly;
 
}
 

	
 
/* virtual */ uint32 TownScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
 
@@ -40,14 +40,14 @@ TownScopeResolver::TownScopeResolver(Res
 

	
 
		/* Get a variable from the persistent storage */
 
		case 0x7C: {
 
			/* Check the persistent storage for the GrfID stored in register 100h. */
 
			uint32 grfid = GetRegister(0x100);
 
			if (grfid == 0xFFFFFFFF) {
 
				if (this->ro->grffile == NULL) return 0;
 
				grfid = this->ro->grffile->grfid;
 
				if (this->ro.grffile == NULL) return 0;
 
				grfid = this->ro.grffile->grfid;
 
			}
 

	
 
			std::list<PersistentStorage *>::iterator iter;
 
			for (iter = this->t->psa_list.begin(); iter != this->t->psa_list.end(); iter++) {
 
				if ((*iter)->grfid == grfid) return (*iter)->GetValue(parameter);
 
			}
 
@@ -132,20 +132,20 @@ TownScopeResolver::TownScopeResolver(Res
 
/* virtual */ void TownScopeResolver::StorePSA(uint pos, int32 value)
 
{
 
	if (this->readonly) return;
 

	
 
	assert(this->t != NULL);
 
	/* We can't store anything if the caller has no #GRFFile. */
 
	if (this->ro->grffile == NULL) return;
 
	if (this->ro.grffile == NULL) return;
 

	
 
	/* Check the persistent storage for the GrfID stored in register 100h. */
 
	uint32 grfid = GetRegister(0x100);
 

	
 
	/* A NewGRF can only write in the persistent storage associated to its own GRFID. */
 
	if (grfid == 0xFFFFFFFF) grfid = this->ro->grffile->grfid;
 
	if (grfid != this->ro->grffile->grfid) return;
 
	if (grfid == 0xFFFFFFFF) grfid = this->ro.grffile->grfid;
 
	if (grfid != this->ro.grffile->grfid) return;
 

	
 
	/* Check if the storage exists. */
 
	std::list<PersistentStorage *>::iterator iter;
 
	for (iter = t->psa_list.begin(); iter != t->psa_list.end(); iter++) {
 
		if ((*iter)->grfid == grfid) {
 
			(*iter)->StoreValue(pos, value);
 
@@ -164,10 +164,10 @@ TownScopeResolver::TownScopeResolver(Res
 
 * Resolver for a town.
 
 * @param grffile NewGRF file associated with the town.
 
 * @param t %Town of the scope.
 
 * @param readonly Scope may change persistent storage of the town.
 
 */
 
TownResolverObject::TownResolverObject(const struct GRFFile *grffile, Town *t, bool readonly)
 
		: ResolverObject(grffile), town_scope(this, t, readonly)
 
		: ResolverObject(grffile), town_scope(*this, t, readonly)
 
{
 
}
 

	
src/newgrf_town.h
Show inline comments
 
@@ -22,13 +22,13 @@
 
 *       and to check the town's persistent storage.
 
 */
 
struct TownScopeResolver : public ScopeResolver {
 
	Town *t;       ///< %Town of the scope.
 
	bool readonly; ///< When set, persistent storage of the town is read-only,
 

	
 
	TownScopeResolver(ResolverObject *ro, Town *t, bool readonly);
 
	TownScopeResolver(ResolverObject &ro, Town *t, bool readonly);
 

	
 
	virtual uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
 
	virtual void StorePSA(uint reg, int32 value);
 
};
 

	
 
/** Resolver of town properties. */
src/station_base.h
Show inline comments
 
@@ -489,13 +489,13 @@ public:
 

	
 
	inline bool TileBelongsToAirport(TileIndex tile) const
 
	{
 
		return IsAirportTile(tile) && GetStationIndex(tile) == this->index;
 
	}
 

	
 
	/* virtual */ uint32 GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const;
 
	/* virtual */ uint32 GetNewGRFVariable(const ResolverObject &object, byte variable, byte parameter, bool *available) const;
 

	
 
	/* virtual */ void GetTileArea(TileArea *ta, StationType type) const;
 
};
 

	
 
#define FOR_ALL_STATIONS(var) FOR_ALL_BASE_STATIONS_OF_TYPE(Station, var)
 

	
src/waypoint_base.h
Show inline comments
 
@@ -29,13 +29,13 @@ struct Waypoint FINAL : SpecializedStati
 

	
 
	/* virtual */ inline bool TileBelongsToRailStation(TileIndex tile) const
 
	{
 
		return IsRailWaypointTile(tile) && GetStationIndex(tile) == this->index;
 
	}
 

	
 
	/* virtual */ uint32 GetNewGRFVariable(const struct ResolverObject *object, byte variable, byte parameter, bool *available) const;
 
	/* virtual */ uint32 GetNewGRFVariable(const struct ResolverObject &object, byte variable, byte parameter, bool *available) const;
 

	
 
	/* virtual */ void GetTileArea(TileArea *ta, StationType type) const;
 

	
 
	/* virtual */ uint GetPlatformLength(TileIndex tile, DiagDirection dir) const
 
	{
 
		return 1;
0 comments (0 inline, 0 general)