summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2012-11-10 20:38:46 +0000
committeralberth <alberth@openttd.org>2012-11-10 20:38:46 +0000
commitb985c4c0f8f0428f1d036e66ec919e33063bb32c (patch)
tree4503b67df89b900337572d62bc051b2dc96505bb
parent438495b433f5b4d3ce81f8efc7d655d2337582fe (diff)
downloadopenttd-b985c4c0f8f0428f1d036e66ec919e33063bb32c.tar.xz
(svn r24679) -Codechange: Add resolver classes for towns.
-rw-r--r--src/newgrf_spritegroup.cpp5
-rw-r--r--src/newgrf_spritegroup.h1
-rw-r--r--src/newgrf_town.cpp25
-rw-r--r--src/newgrf_town.h28
4 files changed, 55 insertions, 4 deletions
diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp
index 75bd30337..491d1bef7 100644
--- a/src/newgrf_spritegroup.cpp
+++ b/src/newgrf_spritegroup.cpp
@@ -143,9 +143,10 @@ TempScopeResolver::TempScopeResolver(ResolverObject *ro) : ScopeResolver(ro) {}
if (this->ro->StorePSA != NULL) this->ro->StorePSA(this->ro, reg, value);
}
-ResolverObject::ResolverObject() : temp_scope(this) {} // XXX Temporary
+ResolverObject::ResolverObject() : default_scope(this), temp_scope(this) {} // XXX Temporary
-ResolverObject::ResolverObject(const GRFFile *grffile, CallbackID callback, uint32 callback_param1, uint32 callback_param2) : temp_scope(this)
+ResolverObject::ResolverObject(const GRFFile *grffile, CallbackID callback, uint32 callback_param1, uint32 callback_param2)
+ : default_scope(this), temp_scope(this)
{
this->callback = callback;
this->callback_param1 = callback_param1;
diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h
index c70901622..9461be0c8 100644
--- a/src/newgrf_spritegroup.h
+++ b/src/newgrf_spritegroup.h
@@ -333,6 +333,7 @@ struct 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;
diff --git a/src/newgrf_town.cpp b/src/newgrf_town.cpp
index 5017dcec4..7aab35f31 100644
--- a/src/newgrf_town.cpp
+++ b/src/newgrf_town.cpp
@@ -12,7 +12,18 @@
#include "stdafx.h"
#include "debug.h"
#include "town.h"
-#include "newgrf_spritegroup.h"
+#include "newgrf_town.h"
+
+TownScopeResolver::TownScopeResolver(ResolverObject *ro, Town *t, bool readonly) : ScopeResolver(ro)
+{
+ this->t = t;
+ this->readonly = readonly;
+}
+
+/* virtual */ uint32 TownScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
+{
+ return TownGetVariable(variable, parameter, available, this->t, this->ro->grffile);
+}
/**
* This function implements the town variables that newGRF defines.
@@ -126,6 +137,12 @@ uint32 TownGetVariable(byte variable, uint32 parameter, bool *available, Town *t
return UINT_MAX;
}
+/* 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.
@@ -162,3 +179,9 @@ void TownStorePSA(Town *t, const GRFFile *caller_grffile, uint pos, int32 value)
psa->StoreValue(pos, value);
t->psa_list.push_back(psa);
}
+
+TownResolverObject::TownResolverObject(const struct GRFFile *grffile, Town *t, bool readonly)
+ : ResolverObject(grffile), town_scope(this, t, readonly)
+{
+}
+
diff --git a/src/newgrf_town.h b/src/newgrf_town.h
index 659de7691..af79e0141 100644
--- a/src/newgrf_town.h
+++ b/src/newgrf_town.h
@@ -13,11 +13,37 @@
#define NEWGRF_TOWN_H
#include "town_type.h"
+#include "newgrf_spritegroup.h"
/* 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. */
+ * 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;
+
+ TownScopeResolver(ResolverObject *ro, Town *t, bool readonly);
+
+ virtual uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
+ virtual void StorePSA(uint reg, int32 value);
+};
+
+struct TownResolverObject : public ResolverObject {
+ TownScopeResolver town_scope;
+
+ TownResolverObject(const struct GRFFile *grffile, Town *t, bool readonly);
+
+ /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
+ {
+ switch (scope) {
+ case VSG_SCOPE_SELF: return &town_scope;
+ default: return &this->default_scope; // XXX return ResolverObject::GetScope(scope, relative);
+ }
+ }
+};
+
#endif /* NEWGRF_TOWN_H */