summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2012-11-10 20:45:59 +0000
committeralberth <alberth@openttd.org>2012-11-10 20:45:59 +0000
commit4c9bea2a714da675217522c39113ba2c2c5bbee4 (patch)
treef04d63a5864e01eef76f74f0a09692a0baa880e1 /src
parent69e07c3e00180053cc087ceb1dfeb89845b79857 (diff)
downloadopenttd-4c9bea2a714da675217522c39113ba2c2c5bbee4.tar.xz
(svn r24692) -Cleanup: Cleanup final parts of the old resolver code.
Diffstat (limited to 'src')
-rw-r--r--src/newgrf_airport.cpp2
-rw-r--r--src/newgrf_airporttiles.cpp7
-rw-r--r--src/newgrf_airporttiles.h4
-rw-r--r--src/newgrf_canal.cpp2
-rw-r--r--src/newgrf_cargo.cpp5
-rw-r--r--src/newgrf_debug_gui.cpp16
-rw-r--r--src/newgrf_engine.cpp2
-rw-r--r--src/newgrf_generic.cpp2
-rw-r--r--src/newgrf_house.cpp6
-rw-r--r--src/newgrf_house.h4
-rw-r--r--src/newgrf_industries.cpp6
-rw-r--r--src/newgrf_industries.h4
-rw-r--r--src/newgrf_industrytiles.cpp6
-rw-r--r--src/newgrf_industrytiles.h4
-rw-r--r--src/newgrf_object.cpp6
-rw-r--r--src/newgrf_object.h4
-rw-r--r--src/newgrf_railtype.h2
-rw-r--r--src/newgrf_spritegroup.cpp35
-rw-r--r--src/newgrf_spritegroup.h20
-rw-r--r--src/newgrf_station.h2
-rw-r--r--src/newgrf_town.cpp172
-rw-r--r--src/newgrf_town.h7
-rw-r--r--src/table/newgrf_debug_data.h7
23 files changed, 96 insertions, 229 deletions
diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp
index f06e4c3b8..c56f097c8 100644
--- a/src/newgrf_airport.cpp
+++ b/src/newgrf_airport.cpp
@@ -41,7 +41,7 @@ struct AirportResolverObject : public ResolverObject {
{
switch (scope) {
case VSG_SCOPE_SELF: return &this->airport_scope;
- default: return &this->default_scope; // XXX return ResolverObject::GetScope(scope, relative);
+ default: return ResolverObject::GetScope(scope, relative);
}
}
diff --git a/src/newgrf_airporttiles.cpp b/src/newgrf_airporttiles.cpp
index a4030aac7..c25d0db5f 100644
--- a/src/newgrf_airporttiles.cpp
+++ b/src/newgrf_airporttiles.cpp
@@ -98,13 +98,6 @@ StationGfx GetTranslatedAirportTileID(StationGfx gfx)
return it->grf_prop.override == INVALID_AIRPORTTILE ? gfx : it->grf_prop.override;
}
-
-/* virtual */ const SpriteGroup *AirportTileResolverObject::ResolveReal(const RealSpriteGroup *group) const
-{
- /* AirportTile do not have 'real' groups. */
- return NULL;
-}
-
/**
* Based on newhouses/newindustries equivalent, but adapted for airports.
* @param parameter from callback. It's in fact a pair of coordinates
diff --git a/src/newgrf_airporttiles.h b/src/newgrf_airporttiles.h
index 0e9644ecf..8daded34f 100644
--- a/src/newgrf_airporttiles.h
+++ b/src/newgrf_airporttiles.h
@@ -39,11 +39,9 @@ struct AirportTileResolverObject : public ResolverObject {
{
switch (scope) {
case VSG_SCOPE_SELF: return &tiles_scope;
- default: return &this->default_scope; // XXX return ResolverObject::GetScope(scope, relative);
+ default: return ResolverObject::GetScope(scope, relative);
}
}
-
- /* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
};
/**
diff --git a/src/newgrf_canal.cpp b/src/newgrf_canal.cpp
index 4f5c08b14..48c1490e6 100644
--- a/src/newgrf_canal.cpp
+++ b/src/newgrf_canal.cpp
@@ -38,7 +38,7 @@ struct CanalResolverObject : public ResolverObject {
{
switch (scope) {
case VSG_SCOPE_SELF: return &this->canal_scope;
- default: return &this->default_scope; // XXX ResolverObject::GetScope(scope, relative);
+ default: return ResolverObject::GetScope(scope, relative);
}
}
diff --git a/src/newgrf_cargo.cpp b/src/newgrf_cargo.cpp
index 3511a0ec2..b084e835e 100644
--- a/src/newgrf_cargo.cpp
+++ b/src/newgrf_cargo.cpp
@@ -16,11 +16,6 @@
struct CargoResolverObject : public ResolverObject {
CargoResolverObject(const CargoSpec *cs, CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
- /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
- {
- return &this->default_scope; //XXX ResolverObject::GetScope(scope, relative);
- }
-
/* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
};
diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp
index 294ffafd4..c807b1bda 100644
--- a/src/newgrf_debug_gui.cpp
+++ b/src/newgrf_debug_gui.cpp
@@ -160,13 +160,7 @@ public:
* @param avail Return whether the variable is available.
* @return The resolved variable's value.
*/
- virtual uint Resolve(uint index, uint var, uint param, bool *avail) const
- {
- ResolverObject ro;
- memset(&ro, 0, sizeof(ro));
- this->Resolve(&ro, index);
- return ro.GetScope(ro.scope)->GetVariable(var, param, avail);
- }
+ virtual uint Resolve(uint index, uint var, uint param, bool *avail) const = 0;
/**
* Used to decide if the PSA needs a parameter or not.
@@ -201,14 +195,6 @@ public:
protected:
/**
- * Actually execute the real resolving for a given (instance) index.
- * @param ro The resolver object to fill with everything
- * needed to be able to resolve a variable.
- * @param index The (instance) index of the to-be-resolved variable.
- */
- virtual void Resolve(ResolverObject *ro, uint index) const {}
-
- /**
* Helper to make setting the strings easier.
* @param string the string to actually draw.
* @param index the (instance) index for the string.
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index b7de4341e..6a286f81e 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -408,7 +408,7 @@ static byte MapAircraftMovementAction(const Aircraft *v)
}
return &this->relative_scope;
}
- default: return &this->default_scope; // XXX ResolverObject::GetScope(scope, relative);
+ default: return ResolverObject::GetScope(scope, relative);
}
}
diff --git a/src/newgrf_generic.cpp b/src/newgrf_generic.cpp
index 2ab7b483b..9a55928cf 100644
--- a/src/newgrf_generic.cpp
+++ b/src/newgrf_generic.cpp
@@ -48,7 +48,7 @@ struct GenericResolverObject : public ResolverObject {
{
switch (scope) {
case VSG_SCOPE_SELF: return &this->generic_scope;
- default: return &this->default_scope; // XXX ResolverObject::GetScope(scope, relative);
+ default: return ResolverObject::GetScope(scope, relative);
}
}
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp
index baf2e9479..dd40ce8e5 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -411,12 +411,6 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
return UINT_MAX;
}
-/* virtual */ const SpriteGroup *HouseResolverObject::ResolveReal(const RealSpriteGroup *group) const
-{
- /* Houses do not have 'real' groups */
- return NULL;
-}
-
uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile,
bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
{
diff --git a/src/newgrf_house.h b/src/newgrf_house.h
index 7986f114e..f833f96b0 100644
--- a/src/newgrf_house.h
+++ b/src/newgrf_house.h
@@ -49,11 +49,9 @@ struct HouseResolverObject : public ResolverObject {
switch (scope) {
case VSG_SCOPE_SELF: return &this->house_scope;
case VSG_SCOPE_PARENT: return &this->town_scope;
- default: return &this->default_scope; // XXX ResolverObject::GetScope(scope, relative);
+ default: return ResolverObject::GetScope(scope, relative);
}
}
-
- /* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
};
/**
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp
index 0fea5d3e3..84f589d86 100644
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -359,12 +359,6 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
return UINT_MAX;
}
-/* virtual */ const SpriteGroup *IndustriesResolverObject::ResolveReal(const RealSpriteGroup *group) const
-{
- /* IndustryTile do not have 'real' groups */
- return NULL;
-}
-
/* virtual */ uint32 IndustriesScopeResolver::GetRandomBits() const
{
return this->industry != NULL ? this->industry->random : 0;
diff --git a/src/newgrf_industries.h b/src/newgrf_industries.h
index 3040f3555..cb1e7f21c 100644
--- a/src/newgrf_industries.h
+++ b/src/newgrf_industries.h
@@ -48,11 +48,9 @@ struct IndustriesResolverObject : public ResolverObject {
if (tsr != NULL) return tsr;
/* FALL-THROUGH */
}
- default: return &this->default_scope; // XXX ResolverObject::GetScope(scope, relative);
+ default: return ResolverObject::GetScope(scope, relative);
}
}
-
- /* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
};
/** When should the industry(tile) be triggered for random bits? */
diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp
index b641bfe90..e778a3ac7 100644
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -99,12 +99,6 @@ uint32 GetRelativePosition(TileIndex tile, TileIndex ind_tile)
return UINT_MAX;
}
-/* virtual */ const SpriteGroup *IndustryTileResolverObject::ResolveReal(const RealSpriteGroup *group) const
-{
- /* IndustryTile do not have 'real' groups. Or do they?? */
- return NULL;
-}
-
/* virtual */ uint32 IndustryTileScopeResolver::GetRandomBits() const
{
assert(this->industry != NULL && IsValidTile(this->tile));
diff --git a/src/newgrf_industrytiles.h b/src/newgrf_industrytiles.h
index 21bb4cd15..dc8fb238f 100644
--- a/src/newgrf_industrytiles.h
+++ b/src/newgrf_industrytiles.h
@@ -40,11 +40,9 @@ struct IndustryTileResolverObject : public ResolverObject {
switch (scope) {
case VSG_SCOPE_SELF: return &indtile_scope;
case VSG_SCOPE_PARENT: return &ind_scope;
- default: return &this->default_scope; // XXX ResolverObject::GetScope(scope, relative);
+ default: return ResolverObject::GetScope(scope, relative);
}
}
-
- /* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
};
bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds);
diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp
index f09e94b3b..4c1c46149 100644
--- a/src/newgrf_object.cpp
+++ b/src/newgrf_object.cpp
@@ -337,12 +337,6 @@ unhandled:
return UINT_MAX;
}
-/* virtual */ const SpriteGroup *ObjectResolverObject::ResolveReal(const RealSpriteGroup *group) const
-{
- /* Objects do not have 'real' groups */
- return NULL;
-}
-
/**
* Get the object's sprite group.
* @param spec The specification to get the sprite group from.
diff --git a/src/newgrf_object.h b/src/newgrf_object.h
index c1b79959d..a1adbb662 100644
--- a/src/newgrf_object.h
+++ b/src/newgrf_object.h
@@ -124,12 +124,10 @@ struct ObjectResolverObject : public ResolverObject {
/* FALL-THROUGH */
}
- default: return &this->default_scope; // XXX return &ResolverObject::GetScope(scope, relative);
+ default: return ResolverObject::GetScope(scope, relative);
}
}
- const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
-
private:
TownScopeResolver *GetTown();
};
diff --git a/src/newgrf_railtype.h b/src/newgrf_railtype.h
index 93677f58d..9224ce9e5 100644
--- a/src/newgrf_railtype.h
+++ b/src/newgrf_railtype.h
@@ -37,7 +37,7 @@ struct RailTypeResolverObject : public ResolverObject {
{
switch (scope) {
case VSG_SCOPE_SELF: return &this->railtype_scope;
- default: return &this->default_scope; // XXX ResolverObject::GetScope(scope, relative);
+ default: return ResolverObject::GetScope(scope, relative);
}
}
diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp
index 491d1bef7..517cc885d 100644
--- a/src/newgrf_spritegroup.cpp
+++ b/src/newgrf_spritegroup.cpp
@@ -116,37 +116,8 @@ ScopeResolver::~ScopeResolver() {}
/* virtual */ void ScopeResolver::StorePSA(uint reg, int32 value) {}
-TempScopeResolver::TempScopeResolver(ResolverObject *ro) : ScopeResolver(ro) {}
-
-/* virtual */ uint32 TempScopeResolver::GetRandomBits() const
-{
- return this->ro->GetRandomBits(this->ro);
-}
-
-/* virtual */ uint32 TempScopeResolver::GetTriggers() const
-{
- return this->ro->GetTriggers(this->ro);
-}
-
-/* virtual */ void TempScopeResolver::SetTriggers(int triggers) const
-{
- this->ro->SetTriggers(this->ro, triggers);
-}
-
-/* virtual */ uint32 TempScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
-{
- return this->ro->GetVariable(this->ro, variable, parameter, available);
-}
-
-/* virtual */ void TempScopeResolver::StorePSA(uint reg, int32 value)
-{
- if (this->ro->StorePSA != NULL) this->ro->StorePSA(this->ro, reg, value);
-}
-
-ResolverObject::ResolverObject() : default_scope(this), temp_scope(this) {} // XXX Temporary
-
ResolverObject::ResolverObject(const GRFFile *grffile, CallbackID callback, uint32 callback_param1, uint32 callback_param2)
- : default_scope(this), temp_scope(this)
+ : default_scope(this)
{
this->callback = callback;
this->callback_param1 = callback_param1;
@@ -160,7 +131,7 @@ ResolverObject::~ResolverObject() {}
/* virtual */ const SpriteGroup *ResolverObject::ResolveReal(const RealSpriteGroup *group) const
{
- return this->ResolveRealMethod(this, group);
+ return NULL;
}
/**
@@ -171,7 +142,7 @@ ResolverObject::~ResolverObject() {}
*/
/* virtual */ ScopeResolver *ResolverObject::GetScope(VarSpriteGroupScope scope, byte relative)
{
- return &this->temp_scope;
+ return &this->default_scope;
}
/**
diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h
index 6516a8eb3..ac2f939b2 100644
--- a/src/newgrf_spritegroup.h
+++ b/src/newgrf_spritegroup.h
@@ -317,24 +317,11 @@ struct ScopeResolver {
virtual void StorePSA(uint reg, int32 value);
};
-struct TempScopeResolver : public ScopeResolver {
- TempScopeResolver(ResolverObject *ro);
-
- virtual uint32 GetRandomBits() const;
- virtual uint32 GetTriggers() const;
- virtual void SetTriggers(int triggers) const;
-
- virtual uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
- virtual void StorePSA(uint reg, int32 value);
-};
-
struct ResolverObject {
- ResolverObject();
ResolverObject(const GRFFile *grffile, CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
virtual ~ResolverObject();
ScopeResolver default_scope; ///< Default implementation of the grf scope.
- TempScopeResolver temp_scope; ///< Temporary scope resolver to refer back to the methods of #ResolverObject.
CallbackID callback;
uint32 callback_param1;
@@ -350,13 +337,6 @@ struct ResolverObject {
const GRFFile *grffile; ///< GRFFile the resolved SpriteGroup belongs to
- uint32 (*GetRandomBits)(const struct ResolverObject*);
- uint32 (*GetTriggers)(const struct ResolverObject*);
- void (*SetTriggers)(const struct ResolverObject*, int);
- uint32 (*GetVariable)(const struct ResolverObject *object, byte variable, uint32 parameter, bool *available);
- const SpriteGroup *(*ResolveRealMethod)(const struct ResolverObject*, const RealSpriteGroup*);
- void (*StorePSA)(struct ResolverObject*, uint, int32);
-
virtual const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
virtual ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0);
diff --git a/src/newgrf_station.h b/src/newgrf_station.h
index c2934700a..ee7757376 100644
--- a/src/newgrf_station.h
+++ b/src/newgrf_station.h
@@ -61,7 +61,7 @@ struct StationResolverObject : public ResolverObject {
}
default:
- return &this->default_scope; // XXX ResolverObject::GetScope(scope, relative);
+ return ResolverObject::GetScope(scope, relative);
}
}
diff --git a/src/newgrf_town.cpp b/src/newgrf_town.cpp
index 7aab35f31..64514d3e6 100644
--- a/src/newgrf_town.cpp
+++ b/src/newgrf_town.cpp
@@ -22,41 +22,27 @@ TownScopeResolver::TownScopeResolver(ResolverObject *ro, Town *t, bool readonly)
/* virtual */ uint32 TownScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
{
- return TownGetVariable(variable, parameter, available, this->t, this->ro->grffile);
-}
-
-/**
- * This function implements the town variables that newGRF defines.
- * @param variable that is queried
- * @param parameter unused
- * @param available will return false if ever the variable asked for does not exist
- * @param t is of course the town we are inquiring
- * @param caller_grffile #GRFFile of the entity asking for a town variable.
- * @return the value stored in the corresponding variable
- */
-uint32 TownGetVariable(byte variable, uint32 parameter, bool *available, Town *t, const GRFFile *caller_grffile)
-{
switch (variable) {
/* Larger towns */
case 0x40:
if (_settings_game.economy.larger_towns == 0) return 2;
- if (t->larger_town) return 1;
+ if (this->t->larger_town) return 1;
return 0;
/* Town index */
- case 0x41: return t->index;
+ case 0x41: return this->t->index;
/* 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 (caller_grffile == NULL) return 0;
- grfid = caller_grffile->grfid;
+ if (this->ro->grffile == NULL) return 0;
+ grfid = this->ro->grffile->grfid;
}
std::list<PersistentStorage *>::iterator iter;
- for (iter = t->psa_list.begin(); iter != t->psa_list.end(); iter++) {
+ for (iter = this->t->psa_list.begin(); iter != this->t->psa_list.end(); iter++) {
if ((*iter)->grfid == grfid) return (*iter)->GetValue(parameter);
}
@@ -64,71 +50,71 @@ uint32 TownGetVariable(byte variable, uint32 parameter, bool *available, Town *t
}
/* Town properties */
- case 0x80: return t->xy;
- case 0x81: return GB(t->xy, 8, 8);
- case 0x82: return ClampToU16(t->cache.population);
- case 0x83: return GB(ClampToU16(t->cache.population), 8, 8);
- case 0x8A: return t->grow_counter;
- case 0x92: return t->flags; // In original game, 0x92 and 0x93 are really one word. Since flags is a byte, this is to adjust
+ case 0x80: return this->t->xy;
+ case 0x81: return GB(this->t->xy, 8, 8);
+ case 0x82: return ClampToU16(this->t->cache.population);
+ case 0x83: return GB(ClampToU16(this->t->cache.population), 8, 8);
+ case 0x8A: return this->t->grow_counter;
+ case 0x92: return this->t->flags; // In original game, 0x92 and 0x93 are really one word. Since flags is a byte, this is to adjust
case 0x93: return 0;
- case 0x94: return ClampToU16(t->cache.squared_town_zone_radius[0]);
- case 0x95: return GB(ClampToU16(t->cache.squared_town_zone_radius[0]), 8, 8);
- case 0x96: return ClampToU16(t->cache.squared_town_zone_radius[1]);
- case 0x97: return GB(ClampToU16(t->cache.squared_town_zone_radius[1]), 8, 8);
- case 0x98: return ClampToU16(t->cache.squared_town_zone_radius[2]);
- case 0x99: return GB(ClampToU16(t->cache.squared_town_zone_radius[2]), 8, 8);
- case 0x9A: return ClampToU16(t->cache.squared_town_zone_radius[3]);
- case 0x9B: return GB(ClampToU16(t->cache.squared_town_zone_radius[3]), 8, 8);
- case 0x9C: return ClampToU16(t->cache.squared_town_zone_radius[4]);
- case 0x9D: return GB(ClampToU16(t->cache.squared_town_zone_radius[4]), 8, 8);
- case 0x9E: return t->ratings[0];
- case 0x9F: return GB(t->ratings[0], 8, 8);
- case 0xA0: return t->ratings[1];
- case 0xA1: return GB(t->ratings[1], 8, 8);
- case 0xA2: return t->ratings[2];
- case 0xA3: return GB(t->ratings[2], 8, 8);
- case 0xA4: return t->ratings[3];
- case 0xA5: return GB(t->ratings[3], 8, 8);
- case 0xA6: return t->ratings[4];
- case 0xA7: return GB(t->ratings[4], 8, 8);
- case 0xA8: return t->ratings[5];
- case 0xA9: return GB(t->ratings[5], 8, 8);
- case 0xAA: return t->ratings[6];
- case 0xAB: return GB(t->ratings[6], 8, 8);
- case 0xAC: return t->ratings[7];
- case 0xAD: return GB(t->ratings[7], 8, 8);
- case 0xAE: return t->have_ratings;
- case 0xB2: return t->statues;
- case 0xB6: return ClampToU16(t->cache.num_houses);
- case 0xB9: return t->growth_rate & (~TOWN_GROW_RATE_CUSTOM);
- case 0xBA: return ClampToU16(t->supplied[CT_PASSENGERS].new_max);
- case 0xBB: return GB(ClampToU16(t->supplied[CT_PASSENGERS].new_max), 8, 8);
- case 0xBC: return ClampToU16(t->supplied[CT_MAIL].new_max);
- case 0xBD: return GB(ClampToU16(t->supplied[CT_MAIL].new_max), 8, 8);
- case 0xBE: return ClampToU16(t->supplied[CT_PASSENGERS].new_act);
- case 0xBF: return GB(ClampToU16(t->supplied[CT_PASSENGERS].new_act), 8, 8);
- case 0xC0: return ClampToU16(t->supplied[CT_MAIL].new_act);
- case 0xC1: return GB(ClampToU16(t->supplied[CT_MAIL].new_act), 8, 8);
- case 0xC2: return ClampToU16(t->supplied[CT_PASSENGERS].old_max);
- case 0xC3: return GB(ClampToU16(t->supplied[CT_PASSENGERS].old_max), 8, 8);
- case 0xC4: return ClampToU16(t->supplied[CT_MAIL].old_max);
- case 0xC5: return GB(ClampToU16(t->supplied[CT_MAIL].old_max), 8, 8);
- case 0xC6: return ClampToU16(t->supplied[CT_PASSENGERS].old_act);
- case 0xC7: return GB(ClampToU16(t->supplied[CT_PASSENGERS].old_act), 8, 8);
- case 0xC8: return ClampToU16(t->supplied[CT_MAIL].old_act);
- case 0xC9: return GB(ClampToU16(t->supplied[CT_MAIL].old_act), 8, 8);
- case 0xCA: return t->GetPercentTransported(CT_PASSENGERS);
- case 0xCB: return t->GetPercentTransported(CT_MAIL);
- case 0xCC: return t->received[TE_FOOD].new_act;
- case 0xCD: return GB(t->received[TE_FOOD].new_act, 8, 8);
- case 0xCE: return t->received[TE_WATER].new_act;
- case 0xCF: return GB(t->received[TE_WATER].new_act, 8, 8);
- case 0xD0: return t->received[TE_FOOD].old_act;
- case 0xD1: return GB(t->received[TE_FOOD].old_act, 8, 8);
- case 0xD2: return t->received[TE_WATER].old_act;
- case 0xD3: return GB(t->received[TE_WATER].old_act, 8, 8);
- case 0xD4: return t->road_build_months;
- case 0xD5: return t->fund_buildings_months;
+ case 0x94: return ClampToU16(this->t->cache.squared_town_zone_radius[0]);
+ case 0x95: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[0]), 8, 8);
+ case 0x96: return ClampToU16(this->t->cache.squared_town_zone_radius[1]);
+ case 0x97: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[1]), 8, 8);
+ case 0x98: return ClampToU16(this->t->cache.squared_town_zone_radius[2]);
+ case 0x99: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[2]), 8, 8);
+ case 0x9A: return ClampToU16(this->t->cache.squared_town_zone_radius[3]);
+ case 0x9B: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[3]), 8, 8);
+ case 0x9C: return ClampToU16(this->t->cache.squared_town_zone_radius[4]);
+ case 0x9D: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[4]), 8, 8);
+ case 0x9E: return this->t->ratings[0];
+ case 0x9F: return GB(this->t->ratings[0], 8, 8);
+ case 0xA0: return this->t->ratings[1];
+ case 0xA1: return GB(this->t->ratings[1], 8, 8);
+ case 0xA2: return this->t->ratings[2];
+ case 0xA3: return GB(this->t->ratings[2], 8, 8);
+ case 0xA4: return this->t->ratings[3];
+ case 0xA5: return GB(this->t->ratings[3], 8, 8);
+ case 0xA6: return this->t->ratings[4];
+ case 0xA7: return GB(this->t->ratings[4], 8, 8);
+ case 0xA8: return this->t->ratings[5];
+ case 0xA9: return GB(this->t->ratings[5], 8, 8);
+ case 0xAA: return this->t->ratings[6];
+ case 0xAB: return GB(this->t->ratings[6], 8, 8);
+ case 0xAC: return this->t->ratings[7];
+ case 0xAD: return GB(this->t->ratings[7], 8, 8);
+ case 0xAE: return this->t->have_ratings;
+ case 0xB2: return this->t->statues;
+ case 0xB6: return ClampToU16(this->t->cache.num_houses);
+ case 0xB9: return this->t->growth_rate & (~TOWN_GROW_RATE_CUSTOM);
+ case 0xBA: return ClampToU16(this->t->supplied[CT_PASSENGERS].new_max);
+ case 0xBB: return GB(ClampToU16(this->t->supplied[CT_PASSENGERS].new_max), 8, 8);
+ case 0xBC: return ClampToU16(this->t->supplied[CT_MAIL].new_max);
+ case 0xBD: return GB(ClampToU16(this->t->supplied[CT_MAIL].new_max), 8, 8);
+ case 0xBE: return ClampToU16(this->t->supplied[CT_PASSENGERS].new_act);
+ case 0xBF: return GB(ClampToU16(this->t->supplied[CT_PASSENGERS].new_act), 8, 8);
+ case 0xC0: return ClampToU16(this->t->supplied[CT_MAIL].new_act);
+ case 0xC1: return GB(ClampToU16(this->t->supplied[CT_MAIL].new_act), 8, 8);
+ case 0xC2: return ClampToU16(this->t->supplied[CT_PASSENGERS].old_max);
+ case 0xC3: return GB(ClampToU16(this->t->supplied[CT_PASSENGERS].old_max), 8, 8);
+ case 0xC4: return ClampToU16(this->t->supplied[CT_MAIL].old_max);
+ case 0xC5: return GB(ClampToU16(this->t->supplied[CT_MAIL].old_max), 8, 8);
+ case 0xC6: return ClampToU16(this->t->supplied[CT_PASSENGERS].old_act);
+ case 0xC7: return GB(ClampToU16(this->t->supplied[CT_PASSENGERS].old_act), 8, 8);
+ case 0xC8: return ClampToU16(this->t->supplied[CT_MAIL].old_act);
+ case 0xC9: return GB(ClampToU16(this->t->supplied[CT_MAIL].old_act), 8, 8);
+ case 0xCA: return this->t->GetPercentTransported(CT_PASSENGERS);
+ case 0xCB: return this->t->GetPercentTransported(CT_MAIL);
+ case 0xCC: return this->t->received[TE_FOOD].new_act;
+ case 0xCD: return GB(this->t->received[TE_FOOD].new_act, 8, 8);
+ case 0xCE: return this->t->received[TE_WATER].new_act;
+ case 0xCF: return GB(this->t->received[TE_WATER].new_act, 8, 8);
+ case 0xD0: return this->t->received[TE_FOOD].old_act;
+ case 0xD1: return GB(this->t->received[TE_FOOD].old_act, 8, 8);
+ case 0xD2: return this->t->received[TE_WATER].old_act;
+ case 0xD3: return GB(this->t->received[TE_WATER].old_act, 8, 8);
+ case 0xD4: return this->t->road_build_months;
+ case 0xD5: return this->t->fund_buildings_months;
}
DEBUG(grf, 1, "Unhandled town variable 0x%X", variable);
@@ -140,29 +126,17 @@ uint32 TownGetVariable(byte variable, uint32 parameter, bool *available, Town *t
/* virtual */ void TownScopeResolver::StorePSA(uint pos, int32 value)
{
if (this->readonly) return;
- TownStorePSA(this->t, this->ro->grffile, pos, value);
-}
-/**
- * Store a value in town persistent storage.
- * @param t Town owning the persistent storage.
- * @param caller_grffile #GRFFile of the entity that wants to use the storage.
- * @param pos Position to write at.
- * @param value Value to write.
- * @return the value stored in the corresponding variable
- */
-void TownStorePSA(Town *t, const GRFFile *caller_grffile, uint pos, int32 value)
-{
- assert(t != NULL);
+ assert(this->t != NULL);
/* We can't store anything if the caller has no #GRFFile. */
- if (caller_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 = caller_grffile->grfid;
- if (grfid != caller_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;
diff --git a/src/newgrf_town.h b/src/newgrf_town.h
index af79e0141..cd090a7ac 100644
--- a/src/newgrf_town.h
+++ b/src/newgrf_town.h
@@ -18,10 +18,7 @@
/* Currently there is no direct town resolver; we only need to get town
* variable results from inside stations, house tiles and industries,
* and to check the town's persistent storage.
- * XXX Remove the functions. */
-uint32 TownGetVariable(byte variable, uint32 parameter, bool *available, Town *t, const struct GRFFile *caller_grffile);
-void TownStorePSA(Town *t, const struct GRFFile *caller_grffile, uint pos, int32 value);
-
+ */
struct TownScopeResolver : public ScopeResolver {
Town *t;
bool readonly;
@@ -41,7 +38,7 @@ struct TownResolverObject : public ResolverObject {
{
switch (scope) {
case VSG_SCOPE_SELF: return &town_scope;
- default: return &this->default_scope; // XXX return ResolverObject::GetScope(scope, relative);
+ default: return ResolverObject::GetScope(scope, relative);
}
}
};
diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h
index 3cd9501d2..4446d7605 100644
--- a/src/table/newgrf_debug_data.h
+++ b/src/table/newgrf_debug_data.h
@@ -491,10 +491,15 @@ class NIHTown : public NIHelper {
const void *GetSpec(uint index) const { return NULL; }
void SetStringParameters(uint index) const { this->SetSimpleStringParameters(STR_TOWN_NAME, index); }
uint32 GetGRFID(uint index) const { return 0; }
- uint Resolve(uint index, uint var, uint param, bool *avail) const { return TownGetVariable(var, param, avail, Town::Get(index), NULL); }
bool PSAWithParameter() const { return true; }
uint GetPSASize(uint index, uint32 grfid) const { return cpp_lengthof(PersistentStorage, storage); }
+ /* virtual */ uint Resolve(uint index, uint var, uint param, bool *avail) const
+ {
+ TownResolverObject ro(NULL, Town::Get(index), true);
+ return ro.GetScope(ro.scope)->GetVariable(var, param, avail);
+ }
+
const int32 *GetPSAFirstPosition(uint index, uint32 grfid) const
{
Town *t = Town::Get(index);