1
0
Fork 0

(svn r26085) -Codechange: Pass ResolverObjects as reference instead of pointer since they are never NULL.

release/1.4
frosch 2013-11-24 14:41:19 +00:00
parent 45a5aba8d5
commit db894b0b3f
27 changed files with 155 additions and 156 deletions

View File

@ -103,7 +103,7 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
* @param available will return false if ever the variable asked for does not exist * @param available will return false if ever the variable asked for does not exist
* @return the value stored in the corresponding variable * @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). * Update the coordinated of the sign (as shown in the viewport).

View File

@ -24,7 +24,7 @@ struct AirportScopeResolver : public ScopeResolver {
byte layout; ///< Layout of the airport to build. byte layout; ///< Layout of the airport to build.
TileIndex tile; ///< Tile for the callback, only valid for airporttile callbacks. 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 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const; /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
@ -216,7 +216,7 @@ void AirportOverrideManager::SetEntitySpec(AirportSpec *as)
if (value == 0) return; if (value == 0) return;
/* Create storage on first modification. */ /* 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()); assert(PersistentStorage::CanAllocateItem());
this->st->airport.psa = new PersistentStorage(grfid); this->st->airport.psa = new PersistentStorage(grfid);
} }
@ -235,7 +235,7 @@ void AirportOverrideManager::SetEntitySpec(AirportSpec *as)
*/ */
AirportResolverObject::AirportResolverObject(TileIndex tile, Station *st, byte airport_id, byte layout, AirportResolverObject::AirportResolverObject(TileIndex tile, Station *st, byte airport_id, byte layout,
CallbackID callback, uint32 param1, uint32 param2) 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)
{ {
} }
@ -247,7 +247,7 @@ AirportResolverObject::AirportResolverObject(TileIndex tile, Station *st, byte a
* @param airport_id Type of airport for which the callback is run. * @param airport_id Type of airport for which the callback is run.
* @param layout Layout of the airport to build. * @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->st = st;
this->airport_id = airport_id; this->airport_id = airport_id;
@ -258,7 +258,7 @@ AirportScopeResolver::AirportScopeResolver(ResolverObject *ro, TileIndex tile, S
SpriteID GetCustomAirportSprite(const AirportSpec *as, byte layout) SpriteID GetCustomAirportSprite(const AirportSpec *as, byte layout)
{ {
AirportResolverObject object(INVALID_TILE, NULL, as->GetIndex(), 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; if (group == NULL) return as->preview_sprite;
return group->GetResult(); return group->GetResult();
@ -267,7 +267,7 @@ SpriteID GetCustomAirportSprite(const AirportSpec *as, byte layout)
uint16 GetAirportCallback(CallbackID callback, uint32 param1, uint32 param2, Station *st, TileIndex tile) 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); 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; if (group == NULL) return CALLBACK_FAILED;
return group->GetCallbackResult(); return group->GetCallbackResult();
@ -283,7 +283,7 @@ uint16 GetAirportCallback(CallbackID callback, uint32 param1, uint32 param2, Sta
StringID GetAirportTextCallback(const AirportSpec *as, byte layout, uint16 callback) StringID GetAirportTextCallback(const AirportSpec *as, byte layout, uint16 callback)
{ {
AirportResolverObject object(INVALID_TILE, NULL, as->GetIndex(), layout, (CallbackID)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; uint16 cb_res = (group != NULL) ? group->GetCallbackResult() : CALLBACK_FAILED;
if (cb_res == CALLBACK_FAILED || cb_res == 0x400) return STR_UNDEFINED; if (cb_res == CALLBACK_FAILED || cb_res == 0x400) return STR_UNDEFINED;
if (cb_res > 0x400) { if (cb_res > 0x400) {

View File

@ -178,7 +178,7 @@ static uint32 GetAirportTileIDAtOffset(TileIndex tile, const Station *st, uint32
case 0x44: return GetAnimationFrame(this->tile); case 0x44: return GetAnimationFrame(this->tile);
/* Land info of nearby tiles */ /* 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 */ /* Animation stage of nearby tiles */
case 0x61: { case 0x61: {
@ -190,7 +190,7 @@ static uint32 GetAirportTileIDAtOffset(TileIndex tile, const Station *st, uint32
} }
/* Get airport tile ID at offset */ /* 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); DEBUG(grf, 1, "Unhandled airport tile variable 0x%X", variable);
@ -215,7 +215,7 @@ static uint32 GetAirportTileIDAtOffset(TileIndex tile, const Station *st, uint32
*/ */
AirportTileResolverObject::AirportTileResolverObject(const AirportTileSpec *ats, TileIndex tile, Station *st, AirportTileResolverObject::AirportTileResolverObject(const AirportTileSpec *ats, TileIndex tile, Station *st,
CallbackID callback, uint32 callback_param1, uint32 callback_param2) 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)
{ {
} }
@ -225,7 +225,7 @@ AirportTileResolverObject::AirportTileResolverObject(const AirportTileSpec *ats,
* @param tile %Tile for the callback, only valid for airporttile callbacks. * @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 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); assert(st != NULL);
@ -237,7 +237,7 @@ AirportTileScopeResolver::AirportTileScopeResolver(ResolverObject *ro, const Air
uint16 GetAirportTileCallback(CallbackID callback, uint32 param1, uint32 param2, const AirportTileSpec *ats, Station *st, TileIndex tile, int extra_data = 0) 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); 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; if (group == NULL) return CALLBACK_FAILED;
return group->GetCallbackResult(); return group->GetCallbackResult();
@ -275,7 +275,7 @@ bool DrawNewAirportTile(TileInfo *ti, Station *st, StationGfx gfx, const Airport
} }
AirportTileResolverObject object(airts, ti->tile, st); 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) { if (group == NULL || group->type != SGT_TILELAYOUT) {
return false; return false;
} }

View File

@ -24,7 +24,7 @@ struct AirportTileScopeResolver : public ScopeResolver {
byte airport_id; ///< Type of airport for which the callback is run. byte airport_id; ///< Type of airport for which the callback is run.
TileIndex tile; ///< Tile for the callback, only valid for airporttile callbacks. 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 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const; /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;

View File

@ -23,7 +23,7 @@ WaterFeature _water_feature[CF_END];
struct CanalScopeResolver : public ScopeResolver { struct CanalScopeResolver : public ScopeResolver {
TileIndex tile; ///< Tile containing the canal. TileIndex tile; ///< Tile containing the canal.
CanalScopeResolver(ResolverObject *ro, TileIndex tile); CanalScopeResolver(ResolverObject &ro, TileIndex tile);
/* virtual */ uint32 GetRandomBits() const; /* virtual */ uint32 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const; /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
@ -108,7 +108,7 @@ struct CanalResolverObject : public ResolverObject {
return group->loaded[0]; return group->loaded[0];
} }
CanalScopeResolver::CanalScopeResolver(ResolverObject *ro, TileIndex tile) : ScopeResolver(ro) CanalScopeResolver::CanalScopeResolver(ResolverObject &ro, TileIndex tile) : ScopeResolver(ro)
{ {
this->tile = tile; this->tile = tile;
} }
@ -123,7 +123,7 @@ CanalScopeResolver::CanalScopeResolver(ResolverObject *ro, TileIndex tile) : Sco
*/ */
CanalResolverObject::CanalResolverObject(const GRFFile *grffile, TileIndex tile, CanalResolverObject::CanalResolverObject(const GRFFile *grffile, TileIndex tile,
CallbackID callback, uint32 callback_param1, uint32 callback_param2) 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)
{ {
} }
@ -136,7 +136,7 @@ CanalResolverObject::CanalResolverObject(const GRFFile *grffile, TileIndex tile,
SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile) SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile)
{ {
CanalResolverObject object(_water_feature[feature].grffile, 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; if (group == NULL) return 0;
return group->GetResult(); return group->GetResult();
@ -154,7 +154,7 @@ SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile)
static uint16 GetCanalCallback(CallbackID callback, uint32 param1, uint32 param2, CanalFeature feature, TileIndex tile) static uint16 GetCanalCallback(CallbackID callback, uint32 param1, uint32 param2, CanalFeature feature, TileIndex tile)
{ {
CanalResolverObject object(_water_feature[feature].grffile, tile, callback, param1, param2); 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; if (group == NULL) return CALLBACK_FAILED;
return group->GetCallbackResult(); return group->GetCallbackResult();

View File

@ -50,7 +50,7 @@ CargoResolverObject::CargoResolverObject(const CargoSpec *cs, CallbackID callbac
SpriteID GetCustomCargoSprite(const CargoSpec *cs) SpriteID GetCustomCargoSprite(const CargoSpec *cs)
{ {
CargoResolverObject object(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; if (group == NULL) return 0;
return group->GetResult(); return group->GetResult();
@ -60,7 +60,7 @@ SpriteID GetCustomCargoSprite(const CargoSpec *cs)
uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const CargoSpec *cs) uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const CargoSpec *cs)
{ {
CargoResolverObject object(cs, callback, param1, param2); 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; if (group == NULL) return CALLBACK_FAILED;
return group->GetCallbackResult(); return group->GetCallbackResult();

View File

@ -360,7 +360,7 @@ static byte MapAircraftMovementAction(const Aircraft *v)
/* This function must only be called when processing triggers -- any /* This function must only be called when processing triggers -- any
* other time is an error. */ * other time is an error. */
assert(this->ro->trigger != 0); assert(this->ro.trigger != 0);
if (v != NULL) v->waiting_triggers = triggers; if (v != NULL) v->waiting_triggers = triggers;
} }
@ -546,7 +546,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
/* Unlike everywhere else the cargo translation table is only used since grf version 8, not 7. /* 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. * Note: The grffile == NULL case only happens if this function is called for default vehicles.
* And this is only done by CheckCaches(). */ * 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 : 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]; (grffile == NULL || grffile->grf_version < 8) ? CargoSpec::Get(common_cargo_type)->bitnum : grffile->cargo_map[common_cargo_type];
@ -617,7 +617,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
case 0x4A: { case 0x4A: {
if (v->type != VEH_TRAIN) return 0; if (v->type != VEH_TRAIN) return 0;
RailType rt = GetTileRailType(v->tile); 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 case 0x4B: // Long date of last service
@ -643,8 +643,8 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
if (!v->IsGroundVehicle() || parameter == 0x61) return 0; if (!v->IsGroundVehicle() || parameter == 0x61) return 0;
/* Only allow callbacks that don't change properties to avoid circular dependencies. */ /* 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 || 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) { 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)); Vehicle *u = v->Move((int32)GetRegister(0x10F));
if (u == NULL) return 0; if (u == NULL) return 0;
@ -935,7 +935,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
* @param v %Vehicle being resolved. * @param v %Vehicle being resolved.
* @param info_view Indicates if the item is being drawn in an info window. * @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) : ScopeResolver(ro)
{ {
this->v = v; this->v = v;
@ -966,9 +966,9 @@ static const GRFFile *GetEngineGrfFile(EngineID engine_type)
VehicleResolverObject::VehicleResolverObject(EngineID engine_type, const Vehicle *v, bool info_view, VehicleResolverObject::VehicleResolverObject(EngineID engine_type, const Vehicle *v, bool info_view,
CallbackID callback, uint32 callback_param1, uint32 callback_param2) CallbackID callback, uint32 callback_param1, uint32 callback_param2)
: ResolverObject(GetEngineGrfFile(engine_type), callback, callback_param1, callback_param2), : ResolverObject(GetEngineGrfFile(engine_type), callback, callback_param1, callback_param2),
self_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), parent_scope(*this, engine_type, ((v != NULL) ? v->First() : v), info_view),
relative_scope(this, engine_type, v, info_view), relative_scope(*this, engine_type, v, info_view),
cached_relative_count(0) cached_relative_count(0)
{ {
} }
@ -1019,7 +1019,7 @@ static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle *
SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction direction, EngineImageType image_type) SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction direction, EngineImageType image_type)
{ {
VehicleResolverObject object(engine, v, false, CBID_NO_CALLBACK, 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; if (group == NULL || group->GetNumResults() == 0) return 0;
return group->GetResult() + (direction % group->GetNumResults()); return group->GetResult() + (direction % group->GetNumResults());
@ -1036,7 +1036,7 @@ SpriteID GetRotorOverrideSprite(EngineID engine, const Aircraft *v, bool info_vi
VehicleResolverObject object(engine, v, info_view, CBID_NO_CALLBACK, image_type); VehicleResolverObject object(engine, v, info_view, CBID_NO_CALLBACK, image_type);
const SpriteGroup *group = GetWagonOverrideSpriteSet(engine, CT_DEFAULT, engine); 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 (group == NULL || group->GetNumResults() == 0) return 0;
@ -1069,7 +1069,7 @@ bool UsesWagonOverride(const Vehicle *v)
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v) uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
{ {
VehicleResolverObject object(engine, v, false, callback, param1, param2); 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; if (group == NULL) return CALLBACK_FAILED;
return group->GetCallbackResult(); return group->GetCallbackResult();
@ -1090,7 +1090,7 @@ uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param
VehicleResolverObject object(engine, v, false, callback, param1, param2); VehicleResolverObject object(engine, v, false, callback, param1, param2);
object.parent_scope.SetVehicle(parent); 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; if (group == NULL) return CALLBACK_FAILED;
return group->GetCallbackResult(); return group->GetCallbackResult();
@ -1121,7 +1121,7 @@ static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_rando
VehicleResolverObject object(v->engine_type, v, false, CBID_RANDOM_TRIGGER); VehicleResolverObject object(v->engine_type, v, false, CBID_RANDOM_TRIGGER);
object.trigger = 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; if (group == NULL) return;
byte new_random_bits = Random(); byte new_random_bits = Random();

View File

@ -26,7 +26,7 @@ struct VehicleScopeResolver : public ScopeResolver {
EngineID self_type; ///< Type of the vehicle. EngineID self_type; ///< Type of the vehicle.
bool info_view; ///< Indicates if the item is being drawn in an info window. 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; } void SetVehicle(const Vehicle *v) { this->v = v; }

View File

@ -29,7 +29,7 @@ struct GenericScopeResolver : public ScopeResolver {
uint8 count; uint8 count;
uint8 station_size; 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; /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
@ -104,7 +104,7 @@ void AddGenericCallback(uint8 feature, const GRFFile *file, const SpriteGroup *g
{ {
if (this->ai_callback) { if (this->ai_callback) {
switch (variable) { 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 0x80: return this->cargo_type;
case 0x81: return CargoSpec::Get(this->cargo_type)->bitnum; case 0x81: return CargoSpec::Get(this->cargo_type)->bitnum;
@ -139,7 +139,7 @@ void AddGenericCallback(uint8 feature, const GRFFile *file, const SpriteGroup *g
* @param ai_callback Callback comes from the AI. * @param ai_callback Callback comes from the AI.
* @param callback Callback ID. * @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)
{ {
} }
@ -148,7 +148,7 @@ GenericResolverObject::GenericResolverObject(bool ai_callback, CallbackID callba
* @param ro Surrounding resolver. * @param ro Surrounding resolver.
* @param ai_callback Callback comes from the AI. * @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->cargo_type = 0;
this->default_selection = 0; this->default_selection = 0;
@ -173,16 +173,16 @@ GenericScopeResolver::GenericScopeResolver(ResolverObject *ro, bool ai_callback)
* May be NULL if not required. * May be NULL if not required.
* @return callback value if successful or CALLBACK_FAILED * @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)); assert(feature < lengthof(_gcl));
/* Test each feature callback sprite group. */ /* Test each feature callback sprite group. */
for (GenericCallbackList::const_iterator it = _gcl[feature].begin(); it != _gcl[feature].end(); ++it) { for (GenericCallbackList::const_iterator it = _gcl[feature].begin(); it != _gcl[feature].end(); ++it) {
const SpriteGroup *group = it->group; const SpriteGroup *group = it->group;
object->grffile = it->file; object.grffile = it->file;
/* Set callback param based on GRF version. */ /* 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); group = SpriteGroup::Resolve(group, object);
if (group == NULL || group->GetCallbackResult() == CALLBACK_FAILED) continue; if (group == NULL || group->GetCallbackResult() == CALLBACK_FAILED) continue;
@ -238,7 +238,7 @@ uint16 GetAiPurchaseCallbackResult(uint8 feature, CargoID cargo_type, uint8 defa
object.generic_scope.count = count; object.generic_scope.count = count;
object.generic_scope.station_size = station_size; 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); if (callback != CALLBACK_FAILED) callback = GB(callback, 0, 8);
return callback; return callback;
} }
@ -264,7 +264,7 @@ void AmbientSoundEffectCallback(TileIndex tile)
/* Run callback. */ /* Run callback. */
const GRFFile *grf_file; 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); if (callback != CALLBACK_FAILED) PlayTileSound(grf_file, callback, tile);
} }

View File

@ -39,7 +39,7 @@ HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, NUM_HOUSES, INVALID_HOUSE_ID)
* @param initial_random_bits Random bits during construction checks. * @param initial_random_bits Random bits during construction checks.
* @param watched_cargo_triggers Cargo types that triggered the watched cargo callback. * @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) bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
: ScopeResolver(ro) : ScopeResolver(ro)
{ {
@ -78,8 +78,8 @@ HouseResolverObject::HouseResolverObject(HouseID house_id, TileIndex tile, Town
CallbackID callback, uint32 param1, uint32 param2, CallbackID callback, uint32 param1, uint32 param2,
bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers) bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
: ResolverObject(GetHouseSpecGrf(house_id), callback, param1, param2), : ResolverObject(GetHouseSpecGrf(house_id), callback, param1, param2),
house_scope(this, house_id, tile, town, not_yet_constructed, initial_random_bits, watched_cargo_triggers), 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. town_scope(*this, town, not_yet_constructed) // Don't access StorePSA if house is not yet constructed.
{ {
} }
@ -352,7 +352,7 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
} }
/* Land info for nearby tiles. */ /* 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 */ /* Current animation frame of nearby house tiles */
case 0x63: { case 0x63: {
@ -362,7 +362,7 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
/* Cargo acceptance history of nearby stations */ /* Cargo acceptance history of nearby stations */
case 0x64: { case 0x64: {
CargoID cid = GetCargoTranslation(parameter, this->ro->grffile); CargoID cid = GetCargoTranslation(parameter, this->ro.grffile);
if (cid == CT_INVALID) return 0; if (cid == CT_INVALID) return 0;
/* Extract tile offset. */ /* Extract tile offset. */
@ -400,7 +400,7 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
/* Information about the grf local classid if the house has a class */ /* Information about the grf local classid if the house has a class */
uint houseclass = 0; uint houseclass = 0;
if (hs->class_id != HOUSE_NO_CLASS) { 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; houseclass |= _class_mapping[hs->class_id].class_id;
} }
/* old house type or grf-local houseid */ /* old house type or grf-local houseid */
@ -408,7 +408,7 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
if (this->house_id < NEW_HOUSE_OFFSET) { if (this->house_id < NEW_HOUSE_OFFSET) {
local_houseid = this->house_id; local_houseid = this->house_id;
} else { } 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; local_houseid |= hs->grf_prop.local_id;
} }
return houseclass << 16 | local_houseid; return houseclass << 16 | local_houseid;
@ -440,7 +440,7 @@ uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, House
HouseResolverObject object(house_id, tile, town, callback, param1, param2, HouseResolverObject object(house_id, tile, town, callback, param1, param2,
not_yet_constructed, initial_random_bits, watched_cargo_triggers); 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; if (group == NULL) return CALLBACK_FAILED;
return group->GetCallbackResult(); return group->GetCallbackResult();
@ -490,7 +490,7 @@ void DrawNewHouseTile(TileInfo *ti, HouseID house_id)
HouseResolverObject object(house_id, ti->tile, Town::GetByTile(ti->tile)); 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) { if (group != NULL && group->type == SGT_TILELAYOUT) {
/* Limit the building stage to the number of stages supplied. */ /* Limit the building stage to the number of stages supplied. */
const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group; const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group;
@ -615,7 +615,7 @@ static void DoTriggerHouse(TileIndex tile, HouseTrigger trigger, byte base_rando
HouseResolverObject object(hid, tile, Town::GetByTile(tile), CBID_RANDOM_TRIGGER); HouseResolverObject object(hid, tile, Town::GetByTile(tile), CBID_RANDOM_TRIGGER);
object.trigger = 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; if (group == NULL) return;
byte new_random_bits = Random(); byte new_random_bits = Random();

View File

@ -27,7 +27,7 @@ struct HouseScopeResolver : public ScopeResolver {
uint16 initial_random_bits; ///< Random bits during construction checks. uint16 initial_random_bits; ///< Random bits during construction checks.
uint32 watched_cargo_triggers; ///< Cargo types that triggered the watched cargo callback. 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); bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers);
/* virtual */ uint32 GetRandomBits() const; /* virtual */ uint32 GetRandomBits() const;

View File

@ -159,7 +159,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
/* virtual */ uint32 IndustriesScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const /* 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. */ /* Variables available during construction check. */
switch (variable) { switch (variable) {
@ -185,7 +185,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
case 0x89: return min(DistanceManhattan(this->industry->town->xy, this->tile), 255); case 0x89: return min(DistanceManhattan(this->industry->town->xy, this->tile), 255);
/* Lowest height of the tile */ /* 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 */ /* Distance to the nearest water/land tile */
case 0x8B: return GetClosestWaterDistance(this->tile, (GetIndustrySpec(this->industry->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0); case 0x8B: return GetClosestWaterDistance(this->tile, (GetIndustrySpec(this->industry->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
@ -201,7 +201,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
const IndustrySpec *indspec = GetIndustrySpec(this->type); const IndustrySpec *indspec = GetIndustrySpec(this->type);
if (this->industry == NULL) { 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; *available = false;
return UINT_MAX; return UINT_MAX;
@ -251,7 +251,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
case 0x46: return this->industry->construction_date; // Date when built - long format - (in days) case 0x46: return this->industry->construction_date; // Date when built - long format - (in days)
/* Get industry ID at offset param */ /* 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 */ /* Get random tile bits at offset param */
case 0x61: { case 0x61: {
@ -263,7 +263,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
/* Land info of nearby tiles */ /* Land info of nearby tiles */
case 0x62: case 0x62:
if (this->tile == INVALID_TILE) break; 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 */ /* Animation stage of nearby tiles */
case 0x63: { case 0x63: {
@ -429,7 +429,7 @@ static const GRFFile *GetGrffile(IndustryType type)
IndustriesResolverObject::IndustriesResolverObject(TileIndex tile, Industry *indus, IndustryType type, uint32 random_bits, IndustriesResolverObject::IndustriesResolverObject(TileIndex tile, Industry *indus, IndustryType type, uint32 random_bits,
CallbackID callback, uint32 callback_param1, uint32 callback_param2) CallbackID callback, uint32 callback_param1, uint32 callback_param2)
: ResolverObject(GetGrffile(type), callback, callback_param1, 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) town_scope(NULL)
{ {
} }
@ -455,7 +455,7 @@ TownScopeResolver *IndustriesResolverObject::GetTown()
t = ClosestTownFromTile(this->industries_scope.tile, UINT_MAX); t = ClosestTownFromTile(this->industries_scope.tile, UINT_MAX);
} }
if (t == NULL) return NULL; 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; return this->town_scope;
} }
@ -468,7 +468,7 @@ TownScopeResolver *IndustriesResolverObject::GetTown()
* @param type Type of the industry. * @param type Type of the industry.
* @param random_bits Random bits of the new 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) : ScopeResolver(ro)
{ {
this->tile = tile; this->tile = tile;
@ -490,7 +490,7 @@ IndustriesScopeResolver::IndustriesScopeResolver(ResolverObject *ro, TileIndex t
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile) uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
{ {
IndustriesResolverObject object(tile, industry, type, 0, callback, param1, param2); 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; if (group == NULL) return CALLBACK_FAILED;
return group->GetCallbackResult(); return group->GetCallbackResult();
@ -523,7 +523,7 @@ CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uin
ind.psa = NULL; ind.psa = NULL;
IndustriesResolverObject object(tile, &ind, type, seed, CBID_INDUSTRY_LOCATION, 0, creation_type); 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 /* 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. */ * the building of the industry, as that's how it's done in TTDP. */
@ -596,7 +596,7 @@ void IndustryProductionCallback(Industry *ind, int reason)
} }
SB(object.callback_param2, 8, 16, loop); 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; if (tgroup == NULL || tgroup->type != SGT_INDUSTRY_PRODUCTION) break;
const IndustryProductionSpriteGroup *group = (const IndustryProductionSpriteGroup *)tgroup; const IndustryProductionSpriteGroup *group = (const IndustryProductionSpriteGroup *)tgroup;

View File

@ -21,7 +21,7 @@ struct IndustriesScopeResolver : public ScopeResolver {
IndustryType type; ///< Type of the industry. IndustryType type; ///< Type of the industry.
uint32 random_bits; ///< Random bits of the new 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 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const; /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;

View File

@ -78,7 +78,7 @@ uint32 GetRelativePosition(TileIndex tile, TileIndex ind_tile)
/* Land info of nearby tiles */ /* Land info of nearby tiles */
case 0x60: return GetNearbyIndustryTileInformation(parameter, this->tile, 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 */ /* Animation stage of nearby tiles */
case 0x61: { case 0x61: {
@ -90,7 +90,7 @@ uint32 GetRelativePosition(TileIndex tile, TileIndex ind_tile)
} }
/* Get industry tile ID at offset */ /* 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); DEBUG(grf, 1, "Unhandled industry tile variable 0x%X", variable);
@ -144,8 +144,8 @@ static const GRFFile *GetIndTileGrffile(IndustryGfx gfx)
IndustryTileResolverObject::IndustryTileResolverObject(IndustryGfx gfx, TileIndex tile, Industry *indus, IndustryTileResolverObject::IndustryTileResolverObject(IndustryGfx gfx, TileIndex tile, Industry *indus,
CallbackID callback, uint32 callback_param1, uint32 callback_param2) CallbackID callback, uint32 callback_param1, uint32 callback_param2)
: ResolverObject(GetIndTileGrffile(gfx), callback, callback_param1, callback_param2), : ResolverObject(GetIndTileGrffile(gfx), callback, callback_param1, callback_param2),
indtile_scope(this, indus, tile), indtile_scope(*this, indus, tile),
ind_scope(this, tile, indus, indus->type) ind_scope(*this, tile, indus, indus->type)
{ {
} }
@ -155,7 +155,7 @@ IndustryTileResolverObject::IndustryTileResolverObject(IndustryGfx gfx, TileInde
* @param industry %Industry owning the tile. * @param industry %Industry owning the tile.
* @param tile %Tile of the industry. * @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->industry = industry;
this->tile = tile; this->tile = tile;
@ -190,7 +190,7 @@ uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2
assert(industry->index == INVALID_INDUSTRY || IsTileType(tile, MP_INDUSTRY)); assert(industry->index == INVALID_INDUSTRY || IsTileType(tile, MP_INDUSTRY));
IndustryTileResolverObject object(gfx_id, tile, industry, callback, param1, param2); 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; if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
return group->GetCallbackResult(); return group->GetCallbackResult();
@ -211,7 +211,7 @@ bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const Indus
IndustryTileResolverObject object(gfx, ti->tile, i); 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; if (group == NULL || group->type != SGT_TILELAYOUT) return false;
/* Limit the building stage to the number of stages supplied. */ /* Limit the building stage to the number of stages supplied. */
@ -328,7 +328,7 @@ static void DoTriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger, I
IndustryTileResolverObject object(gfx, tile, ind, CBID_RANDOM_TRIGGER); IndustryTileResolverObject object(gfx, tile, ind, CBID_RANDOM_TRIGGER);
object.trigger = 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; if (group == NULL) return;
byte new_random_bits = Random(); byte new_random_bits = Random();

View File

@ -21,7 +21,7 @@ struct IndustryTileScopeResolver : public ScopeResolver {
Industry *industry; ///< Industry owning the tiles. Industry *industry; ///< Industry owning the tiles.
TileIndex tile; ///< %Tile being resolved. 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 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const; /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;

View File

@ -133,7 +133,7 @@ INSTANTIATE_NEWGRF_CLASS_METHODS(ObjectClass, ObjectSpec, ObjectClassID, OBJECT_
* @param tile %Tile of the object. * @param tile %Tile of the object.
* @param view View 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) : ScopeResolver(ro)
{ {
this->obj = obj; this->obj = obj;
@ -326,7 +326,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte local_id, uint32 grfid,
case 0x48: return this->obj->view; case 0x48: return this->obj->view;
/* Get object ID at offset param */ /* 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 */ /* Get random tile bits at offset param */
case 0x61: { case 0x61: {
@ -335,7 +335,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte local_id, uint32 grfid,
} }
/* Land info of nearby tiles */ /* 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 */ /* Animation counter of nearby tile */
case 0x63: { case 0x63: {
@ -344,7 +344,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte local_id, uint32 grfid,
} }
/* Count of object, distance of closest instance */ /* 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: unhandled:
@ -383,7 +383,7 @@ static const SpriteGroup *GetObjectSpriteGroup(const ObjectSpec *spec, const Obj
*/ */
ObjectResolverObject::ObjectResolverObject(const ObjectSpec *spec, Object *obj, TileIndex tile, uint8 view, ObjectResolverObject::ObjectResolverObject(const ObjectSpec *spec, Object *obj, TileIndex tile, uint8 view,
CallbackID callback, uint32 param1, uint32 param2) 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; this->town_scope = NULL;
} }
@ -408,7 +408,7 @@ TownScopeResolver *ObjectResolverObject::GetTown()
t = ClosestTownFromTile(this->object_scope.tile, UINT_MAX); t = ClosestTownFromTile(this->object_scope.tile, UINT_MAX);
} }
if (t == NULL) return NULL; 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; return this->town_scope;
} }
@ -427,7 +427,7 @@ TownScopeResolver *ObjectResolverObject::GetTown()
uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view) 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); 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; if (group == NULL) return CALLBACK_FAILED;
return group->GetCallbackResult(); return group->GetCallbackResult();
@ -470,7 +470,7 @@ void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
Object *o = Object::GetByTile(ti->tile); Object *o = Object::GetByTile(ti->tile);
ObjectResolverObject object(spec, o, 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; if (group == NULL || group->type != SGT_TILELAYOUT) return;
DrawTileLayout(ti, (const TileLayoutSpriteGroup *)group, spec); DrawTileLayout(ti, (const TileLayoutSpriteGroup *)group, spec);
@ -486,7 +486,7 @@ void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view) void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view)
{ {
ObjectResolverObject object(spec, NULL, INVALID_TILE, 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; if (group == NULL || group->type != SGT_TILELAYOUT) return;
const DrawTileSprites *dts = ((const TileLayoutSpriteGroup *)group)->ProcessRegisters(NULL); const DrawTileSprites *dts = ((const TileLayoutSpriteGroup *)group)->ProcessRegisters(NULL);

View File

@ -104,7 +104,7 @@ struct ObjectScopeResolver : public ScopeResolver {
TileIndex tile; ///< The tile related to the object. TileIndex tile; ///< The tile related to the object.
uint8 view; ///< The view of 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 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const; /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;

View File

@ -71,7 +71,7 @@
* @param tile %Tile containing the track. For track on a bridge this is the southern bridgehead. * @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? * @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->tile = tile;
this->context = context; this->context = context;
@ -86,7 +86,7 @@ RailTypeScopeResolver::RailTypeScopeResolver(ResolverObject *ro, TileIndex tile,
* @param param2 Extra parameter (second 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) 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)
{ {
} }
@ -105,7 +105,7 @@ SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSp
if (rti->group[rtsg] == NULL) return 0; if (rti->group[rtsg] == NULL) return 0;
RailTypeResolverObject object(tile, context, rti->grffile[rtsg]); 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; if (group == NULL || group->GetNumResults() == 0) return 0;
return group->GetResult(); return group->GetResult();
@ -129,7 +129,7 @@ SpriteID GetCustomSignalSprite(const RailtypeInfo *rti, TileIndex tile, SignalTy
uint32 param2 = (type << 16) | (var << 8) | state; uint32 param2 = (type << 16) | (var << 8) | state;
RailTypeResolverObject object(tile, TCX_NORMAL, rti->grffile[RTSG_SIGNALS], param1, param2); 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; if (group == NULL || group->GetNumResults() == 0) return 0;
return group->GetResult(); return group->GetResult();

View File

@ -21,7 +21,7 @@ struct RailTypeScopeResolver : public ScopeResolver {
TileIndex tile; ///< Tracktile. For track on a bridge this is the southern bridgehead. 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? 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 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const; /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;

View File

@ -37,35 +37,35 @@ RandomizedSpriteGroup::~RandomizedSpriteGroup()
TemporaryStorageArray<int32, 0x110> _temp_store; 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 */ /* First handle variables common with Action7/9/D */
uint32 value; uint32 value;
if (GetGlobalVariable(variable, &value, object->grffile)) return value; if (GetGlobalVariable(variable, &value, object.grffile)) return value;
/* Non-common variable */ /* Non-common variable */
switch (variable) { switch (variable) {
case 0x0C: return object->callback; case 0x0C: return object.callback;
case 0x10: return object->callback_param1; case 0x10: return object.callback_param1;
case 0x18: return object->callback_param2; case 0x18: return object.callback_param2;
case 0x1C: return object->last_value; case 0x1C: return object.last_value;
case 0x5F: return (scope->GetRandomBits() << 8) | scope->GetTriggers(); case 0x5F: return (scope->GetRandomBits() << 8) | scope->GetTriggers();
case 0x7D: return _temp_store.GetValue(parameter); case 0x7D: return _temp_store.GetValue(parameter);
case 0x7F: case 0x7F:
if (object == NULL || object->grffile == NULL) return 0; if (object.grffile == NULL) return 0;
return object->grffile->GetParam(parameter); return object.grffile->GetParam(parameter);
/* Not a common variable, so evaluate the feature specific variables */ /* Not a common variable, so evaluate the feature specific variables */
default: return scope->GetVariable(variable, parameter, available); default: return scope->GetVariable(variable, parameter, available);
} }
} }
ScopeResolver::ScopeResolver(ResolverObject *ro) ScopeResolver::ScopeResolver(ResolverObject &ro)
: ro(ro)
{ {
this->ro = ro;
} }
ScopeResolver::~ScopeResolver() {} ScopeResolver::~ScopeResolver() {}
@ -123,7 +123,7 @@ ScopeResolver::~ScopeResolver() {}
* @param callback_param2 Second parameter (var 18) 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) ResolverObject::ResolverObject(const GRFFile *grffile, CallbackID callback, uint32 callback_param1, uint32 callback_param2)
: default_scope(this) : default_scope(*this)
{ {
this->callback = callback; this->callback = callback;
this->callback_param1 = callback_param1; this->callback_param1 = callback_param1;
@ -216,13 +216,13 @@ static U EvalAdjustT(const DeterministicSpriteGroupAdjust *adjust, ScopeResolver
} }
const SpriteGroup *DeterministicSpriteGroup::Resolve(ResolverObject *object) const const SpriteGroup *DeterministicSpriteGroup::Resolve(ResolverObject &object) const
{ {
uint32 last_value = 0; uint32 last_value = 0;
uint32 value = 0; uint32 value = 0;
uint i; uint i;
ScopeResolver *scope = object->GetScope(this->var_scope); ScopeResolver *scope = object.GetScope(this->var_scope);
for (i = 0; i < this->num_adjusts; i++) { for (i = 0; i < this->num_adjusts; i++) {
DeterministicSpriteGroupAdjust *adjust = &this->adjusts[i]; DeterministicSpriteGroupAdjust *adjust = &this->adjusts[i];
@ -259,7 +259,7 @@ const SpriteGroup *DeterministicSpriteGroup::Resolve(ResolverObject *object) con
last_value = value; last_value = value;
} }
object->last_value = last_value; object.last_value = last_value;
if (this->num_ranges == 0) { if (this->num_ranges == 0) {
/* nvar == 0 is a special case -- we turn our value into a callback result */ /* nvar == 0 is a special case -- we turn our value into a callback result */
@ -279,21 +279,21 @@ const SpriteGroup *DeterministicSpriteGroup::Resolve(ResolverObject *object) con
} }
const SpriteGroup *RandomizedSpriteGroup::Resolve(ResolverObject *object) const const SpriteGroup *RandomizedSpriteGroup::Resolve(ResolverObject &object) const
{ {
ScopeResolver *scope = object->GetScope(this->var_scope, this->count); ScopeResolver *scope = object.GetScope(this->var_scope, this->count);
if (object->trigger != 0) { if (object.trigger != 0) {
/* Handle triggers */ /* Handle triggers */
/* Magic code that may or may not do the right things... */ /* Magic code that may or may not do the right things... */
byte waiting_triggers = scope->GetTriggers(); 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); bool res = (this->cmp_mode == RSG_CMP_ANY) ? (match != 0) : (match == this->triggers);
if (res) { if (res) {
waiting_triggers &= ~match; 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 { } else {
waiting_triggers |= object->trigger; waiting_triggers |= object.trigger;
} }
scope->SetTriggers(waiting_triggers); scope->SetTriggers(waiting_triggers);
@ -306,9 +306,9 @@ const SpriteGroup *RandomizedSpriteGroup::Resolve(ResolverObject *object) const
} }
const SpriteGroup *RealSpriteGroup::Resolve(ResolverObject *object) const const SpriteGroup *RealSpriteGroup::Resolve(ResolverObject &object) const
{ {
return object->ResolveReal(this); return object.ResolveReal(this);
} }
/** /**

View File

@ -57,6 +57,7 @@ enum SpriteGroupType {
struct SpriteGroup; struct SpriteGroup;
typedef uint32 SpriteGroupID; typedef uint32 SpriteGroupID;
struct ResolverObject;
/* SPRITE_WIDTH is 24. ECS has roughly 30 sprite groups per real sprite. /* 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 * Adding an 'extra' margin would be assuming 64 sprite groups per real
@ -69,7 +70,7 @@ struct SpriteGroup : SpriteGroupPool::PoolItem<&_spritegroup_pool> {
protected: protected:
SpriteGroup(SpriteGroupType type) : type(type) {} SpriteGroup(SpriteGroupType type) : type(type) {}
/** Base sprite group resolver */ /** Base sprite group resolver */
virtual const SpriteGroup *Resolve(struct ResolverObject *object) const { return this; }; virtual const SpriteGroup *Resolve(ResolverObject &object) const { return this; };
public: public:
virtual ~SpriteGroup() {} virtual ~SpriteGroup() {}
@ -89,7 +90,7 @@ public:
* @param object information needed to resolve the group * @param object information needed to resolve the group
* @return the resolved 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); return group == NULL ? NULL : group->Resolve(object);
} }
@ -115,7 +116,7 @@ struct RealSpriteGroup : SpriteGroup {
const SpriteGroup **loading; ///< List of loading groups (can be SpriteIDs or Callback results) const SpriteGroup **loading; ///< List of loading groups (can be SpriteIDs or Callback results)
protected: protected:
const SpriteGroup *Resolve(ResolverObject *object) const; const SpriteGroup *Resolve(ResolverObject &object) const;
}; };
/* Shared by deterministic and random groups. */ /* Shared by deterministic and random groups. */
@ -204,7 +205,7 @@ struct DeterministicSpriteGroup : SpriteGroup {
const SpriteGroup *default_group; const SpriteGroup *default_group;
protected: protected:
const SpriteGroup *Resolve(ResolverObject *object) const; const SpriteGroup *Resolve(ResolverObject &object) const;
}; };
enum RandomizedSpriteGroupCompareMode { enum RandomizedSpriteGroupCompareMode {
@ -228,7 +229,7 @@ struct RandomizedSpriteGroup : SpriteGroup {
const SpriteGroup **groups; ///< Take the group with appropriate index: const SpriteGroup **groups; ///< Take the group with appropriate index:
protected: protected:
const SpriteGroup *Resolve(ResolverObject *object) const; const SpriteGroup *Resolve(ResolverObject &object) const;
}; };
@ -301,8 +302,6 @@ struct IndustryProductionSpriteGroup : SpriteGroup {
uint8 again; uint8 again;
}; };
struct ResolverObject;
/** /**
* Interface to query and set values specific to a single #VarSpriteGroupScope (action 2 scope). * Interface to query and set values specific to a single #VarSpriteGroupScope (action 2 scope).
* *
@ -310,9 +309,9 @@ struct ResolverObject;
* to different game entities from a #SpriteGroup-chain (action 1-2-3 chain). * to different game entities from a #SpriteGroup-chain (action 1-2-3 chain).
*/ */
struct ScopeResolver { struct ScopeResolver {
ResolverObject *ro; ///< Surrounding resolver object. ResolverObject &ro; ///< Surrounding resolver object.
ScopeResolver(ResolverObject *ro); ScopeResolver(ResolverObject &ro);
virtual ~ScopeResolver(); virtual ~ScopeResolver();
virtual uint32 GetRandomBits() const; virtual uint32 GetRandomBits() const;

View File

@ -270,7 +270,7 @@ TownScopeResolver *StationResolverObject::GetTown()
t = ClosestTownFromTile(this->station_scope.tile, UINT_MAX); t = ClosestTownFromTile(this->station_scope.tile, UINT_MAX);
} }
if (t == NULL) return NULL; 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; return this->town_scope;
} }
@ -296,7 +296,7 @@ TownScopeResolver *StationResolverObject::GetTown()
Slope tileh = GetTileSlope(tile); Slope tileh = GetTileSlope(tile);
bool swap = (this->axis == AXIS_Y && HasBit(tileh, CORNER_W) != HasBit(tileh, CORNER_E)); 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; break;
@ -355,7 +355,7 @@ TownScopeResolver *StationResolverObject::GetTown()
Slope tileh = GetTileSlope(tile); Slope tileh = GetTileSlope(tile);
bool swap = (axis == AXIS_Y && HasBit(tileh, CORNER_W) != HasBit(tileh, CORNER_E)); 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 case 0x68: { // Station info of nearby tiles
@ -386,7 +386,7 @@ TownScopeResolver *StationResolverObject::GetTown()
return this->st->GetNewGRFVariable(this->ro, variable, parameter, available); 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) { switch (variable) {
case 0x48: { // Accepted cargo types case 0x48: { // Accepted cargo types
@ -409,7 +409,7 @@ uint32 Station::GetNewGRFVariable(const ResolverObject *object, byte variable, b
/* Handle cargo variables with parameter, 0x60 to 0x65 and 0x69 */ /* Handle cargo variables with parameter, 0x60 to 0x65 and 0x69 */
if ((variable >= 0x60 && variable <= 0x65) || variable == 0x69) { if ((variable >= 0x60 && variable <= 0x65) || variable == 0x69) {
CargoID c = GetCargoTranslation(parameter, object->grffile); CargoID c = GetCargoTranslation(parameter, object.grffile);
if (c == CT_INVALID) { if (c == CT_INVALID) {
switch (variable) { switch (variable) {
@ -457,7 +457,7 @@ uint32 Station::GetNewGRFVariable(const ResolverObject *object, byte variable, b
return UINT_MAX; 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) { switch (variable) {
case 0x48: return 0; // Accepted cargo types case 0x48: return 0; // Accepted cargo types
@ -546,7 +546,7 @@ uint32 Waypoint::GetNewGRFVariable(const ResolverObject *object, byte variable,
StationResolverObject::StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile, StationResolverObject::StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile,
CallbackID callback, uint32 callback_param1, uint32 callback_param2) CallbackID callback, uint32 callback_param1, uint32 callback_param2)
: ResolverObject((statspec != NULL ? statspec->grf_prop.grffile : NULL), callback, callback_param1, 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 */ /* Invalidate all cached vars */
_svc.valid = 0; _svc.valid = 0;
@ -564,7 +564,7 @@ StationResolverObject::~StationResolverObject()
* @param st Instance of the station. * @param st Instance of the station.
* @param tile %Tile 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) : ScopeResolver(ro)
{ {
this->tile = tile; this->tile = tile;
@ -574,19 +574,19 @@ StationScopeResolver::StationScopeResolver(ResolverObject *ro, const StationSpec
this->axis = INVALID_AXIS; this->axis = INVALID_AXIS;
} }
static const SpriteGroup *ResolveStation(StationResolverObject *object) static const SpriteGroup *ResolveStation(StationResolverObject &object)
{ {
CargoID ctype = CT_DEFAULT_NA; 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 */ /* No station, so we are in a purchase list */
ctype = CT_PURCHASE; ctype = CT_PURCHASE;
} else if (Station::IsExpected(object->station_scope.st)) { } else if (Station::IsExpected(object.station_scope.st)) {
const Station *st = Station::From(object->station_scope.st); const Station *st = Station::From(object.station_scope.st);
/* Pick the first cargo that we have waiting */ /* Pick the first cargo that we have waiting */
const CargoSpec *cs; const CargoSpec *cs;
FOR_ALL_CARGOSPECS(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) { st->goods[cs->Index()].cargo.TotalCount() > 0) {
ctype = cs->Index(); ctype = cs->Index();
break; break;
@ -594,15 +594,15 @@ static const SpriteGroup *ResolveStation(StationResolverObject *object)
} }
} }
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) { if (group == NULL) {
ctype = CT_DEFAULT; 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; if (group == NULL) return NULL;
} }
/* Remember the cargo type we've picked */ /* Remember the cargo type we've picked */
object->station_scope.cargo_type = ctype; object.station_scope.cargo_type = ctype;
return SpriteGroup::Resolve(group, object); return SpriteGroup::Resolve(group, object);
} }
@ -618,7 +618,7 @@ static const SpriteGroup *ResolveStation(StationResolverObject *object)
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10) SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10)
{ {
StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, 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; if (group == NULL || group->type != SGT_RESULT) return 0;
return group->GetResult() - 0x42D; return group->GetResult() - 0x42D;
} }
@ -638,7 +638,7 @@ SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseS
StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, 2, layout | (edge_info << 16)); StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, 2, layout | (edge_info << 16));
ClearRegister(0x100); ClearRegister(0x100);
const SpriteGroup *group = ResolveStation(&object); const SpriteGroup *group = ResolveStation(object);
if (group == NULL || group->type != SGT_RESULT) return 0; if (group == NULL || group->type != SGT_RESULT) return 0;
return group->GetResult() + GetRegister(0x100); return group->GetResult() + GetRegister(0x100);
} }
@ -647,7 +647,7 @@ SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseS
uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile) uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile)
{ {
StationResolverObject object(statspec, st, tile, callback, param1, param2); StationResolverObject object(statspec, st, tile, callback, param1, param2);
const SpriteGroup *group = ResolveStation(&object); const SpriteGroup *group = ResolveStation(object);
if (group == NULL) return CALLBACK_FAILED; if (group == NULL) return CALLBACK_FAILED;
return group->GetCallbackResult(); return group->GetCallbackResult();
} }
@ -672,7 +672,7 @@ CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_til
(numtracks << 24) | (plat_len << 16) | (axis == AXIS_Y ? TileX(diff) << 8 | TileY(diff) : TileY(diff) << 8 | TileX(diff))); (numtracks << 24) | (plat_len << 16) | (axis == AXIS_Y ? TileX(diff) << 8 | TileY(diff) : TileY(diff) << 8 | TileX(diff)));
object.station_scope.axis = axis; object.station_scope.axis = axis;
const SpriteGroup *group = ResolveStation(&object); const SpriteGroup *group = ResolveStation(object);
uint16 cb_res = group != NULL ? group->GetCallbackResult() : CALLBACK_FAILED; uint16 cb_res = group != NULL ? group->GetCallbackResult() : CALLBACK_FAILED;
/* Failed callback means success. */ /* Failed callback means success. */
@ -1023,7 +1023,7 @@ void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigg
StationResolverObject object(ss, st, tile, CBID_RANDOM_TRIGGER, 0); StationResolverObject object(ss, st, tile, CBID_RANDOM_TRIGGER, 0);
object.trigger = trigger_bit; object.trigger = trigger_bit;
const SpriteGroup *group = ResolveStation(&object); const SpriteGroup *group = ResolveStation(object);
if (group == NULL) continue; if (group == NULL) continue;
uint32 reseed = object.GetReseedSum(); uint32 reseed = object.GetReseedSum();

View File

@ -30,7 +30,7 @@ struct StationScopeResolver : public ScopeResolver {
CargoID cargo_type; ///< Type of cargo of the station. CargoID cargo_type; ///< Type of cargo of the station.
Axis axis; ///< Station axis, used only for the slope check callback. 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 GetRandomBits() const;
/* virtual */ uint32 GetTriggers() const; /* virtual */ uint32 GetTriggers() const;

View File

@ -20,7 +20,7 @@
* @param t %Town of the scope. * @param t %Town of the scope.
* @param readonly Scope may change persistent storage of the town. * @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->t = t;
this->readonly = readonly; this->readonly = readonly;
@ -43,8 +43,8 @@ TownScopeResolver::TownScopeResolver(ResolverObject *ro, Town *t, bool readonly)
/* Check the persistent storage for the GrfID stored in register 100h. */ /* Check the persistent storage for the GrfID stored in register 100h. */
uint32 grfid = GetRegister(0x100); uint32 grfid = GetRegister(0x100);
if (grfid == 0xFFFFFFFF) { if (grfid == 0xFFFFFFFF) {
if (this->ro->grffile == NULL) return 0; if (this->ro.grffile == NULL) return 0;
grfid = this->ro->grffile->grfid; grfid = this->ro.grffile->grfid;
} }
std::list<PersistentStorage *>::iterator iter; std::list<PersistentStorage *>::iterator iter;
@ -135,14 +135,14 @@ TownScopeResolver::TownScopeResolver(ResolverObject *ro, Town *t, bool readonly)
assert(this->t != NULL); assert(this->t != NULL);
/* We can't store anything if the caller has no #GRFFile. */ /* 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. */ /* Check the persistent storage for the GrfID stored in register 100h. */
uint32 grfid = GetRegister(0x100); uint32 grfid = GetRegister(0x100);
/* A NewGRF can only write in the persistent storage associated to its own GRFID. */ /* A NewGRF can only write in the persistent storage associated to its own GRFID. */
if (grfid == 0xFFFFFFFF) grfid = this->ro->grffile->grfid; if (grfid == 0xFFFFFFFF) grfid = this->ro.grffile->grfid;
if (grfid != this->ro->grffile->grfid) return; if (grfid != this->ro.grffile->grfid) return;
/* Check if the storage exists. */ /* Check if the storage exists. */
std::list<PersistentStorage *>::iterator iter; std::list<PersistentStorage *>::iterator iter;
@ -167,7 +167,7 @@ TownScopeResolver::TownScopeResolver(ResolverObject *ro, Town *t, bool readonly)
* @param readonly Scope may change persistent storage of the town. * @param readonly Scope may change persistent storage of the town.
*/ */
TownResolverObject::TownResolverObject(const struct GRFFile *grffile, Town *t, bool readonly) TownResolverObject::TownResolverObject(const struct GRFFile *grffile, Town *t, bool readonly)
: ResolverObject(grffile), town_scope(this, t, readonly) : ResolverObject(grffile), town_scope(*this, t, readonly)
{ {
} }

View File

@ -25,7 +25,7 @@ struct TownScopeResolver : public ScopeResolver {
Town *t; ///< %Town of the scope. Town *t; ///< %Town of the scope.
bool readonly; ///< When set, persistent storage of the town is read-only, 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 uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
virtual void StorePSA(uint reg, int32 value); virtual void StorePSA(uint reg, int32 value);

View File

@ -492,7 +492,7 @@ public:
return IsAirportTile(tile) && GetStationIndex(tile) == this->index; 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; /* virtual */ void GetTileArea(TileArea *ta, StationType type) const;
}; };

View File

@ -32,7 +32,7 @@ struct Waypoint FINAL : SpecializedStation<Waypoint, true> {
return IsRailWaypointTile(tile) && GetStationIndex(tile) == this->index; 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 */ void GetTileArea(TileArea *ta, StationType type) const;