mirror of https://github.com/OpenTTD/OpenTTD
(svn r24679) -Codechange: Add resolver classes for towns.
parent
438495b433
commit
b985c4c0f8
|
@ -143,9 +143,10 @@ TempScopeResolver::TempScopeResolver(ResolverObject *ro) : ScopeResolver(ro) {}
|
||||||
if (this->ro->StorePSA != NULL) this->ro->StorePSA(this->ro, reg, value);
|
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 = callback;
|
||||||
this->callback_param1 = callback_param1;
|
this->callback_param1 = callback_param1;
|
||||||
|
|
|
@ -333,6 +333,7 @@ struct ResolverObject {
|
||||||
ResolverObject(const GRFFile *grffile, CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
|
ResolverObject(const GRFFile *grffile, CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
|
||||||
virtual ~ResolverObject();
|
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.
|
TempScopeResolver temp_scope; ///< Temporary scope resolver to refer back to the methods of #ResolverObject.
|
||||||
|
|
||||||
CallbackID callback;
|
CallbackID callback;
|
||||||
|
|
|
@ -12,7 +12,18 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "town.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.
|
* 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;
|
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.
|
* Store a value in town persistent storage.
|
||||||
* @param t Town owning the 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);
|
psa->StoreValue(pos, value);
|
||||||
t->psa_list.push_back(psa);
|
t->psa_list.push_back(psa);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TownResolverObject::TownResolverObject(const struct GRFFile *grffile, Town *t, bool readonly)
|
||||||
|
: ResolverObject(grffile), town_scope(this, t, readonly)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,37 @@
|
||||||
#define NEWGRF_TOWN_H
|
#define NEWGRF_TOWN_H
|
||||||
|
|
||||||
#include "town_type.h"
|
#include "town_type.h"
|
||||||
|
#include "newgrf_spritegroup.h"
|
||||||
|
|
||||||
/* Currently there is no direct town resolver; we only need to get town
|
/* Currently there is no direct town resolver; we only need to get town
|
||||||
* variable results from inside stations, house tiles and industries,
|
* 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);
|
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);
|
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 */
|
#endif /* NEWGRF_TOWN_H */
|
||||||
|
|
Loading…
Reference in New Issue