Changeset - r19724:343db83218d4
[Not reviewed]
master
0 4 0
alberth - 12 years ago 2012-11-10 20:38:46
alberth@openttd.org
(svn r24679) -Codechange: Add resolver classes for towns.
4 files changed with 55 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/newgrf_spritegroup.cpp
Show inline comments
 
@@ -143,9 +143,10 @@ TempScopeResolver::TempScopeResolver(Res
 
	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;
src/newgrf_spritegroup.h
Show inline comments
 
@@ -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;
src/newgrf_town.cpp
Show inline comments
 
@@ -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, ui
 
	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
 
	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)
 
{
 
}
 

	
src/newgrf_town.h
Show inline comments
 
@@ -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 */
0 comments (0 inline, 0 general)