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
 
@@ -140,15 +140,16 @@ TempScopeResolver::TempScopeResolver(Res
 

	
 
/* virtual */ void TempScopeResolver::StorePSA(uint reg, int32 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_param1 = callback_param1;
 
	this->callback_param2 = callback_param2;
 
	this->ResetState();
 

	
src/newgrf_spritegroup.h
Show inline comments
 
@@ -330,12 +330,13 @@ struct TempScopeResolver : public ScopeR
 

	
 
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;
 
	uint32 callback_param2;
 

	
src/newgrf_town.cpp
Show inline comments
 
@@ -9,13 +9,24 @@
 

	
 
/** @file newgrf_town.cpp Implementation of the town part of NewGRF houses. */
 

	
 
#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.
 
 * @param variable that is queried
 
 * @param parameter unused
 
 * @param available will return false if ever the variable asked for does not exist
 
@@ -123,12 +134,18 @@ uint32 TownGetVariable(byte variable, ui
 
	DEBUG(grf, 1, "Unhandled town variable 0x%X", variable);
 

	
 
	*available = false;
 
	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.
 
 * @param caller_grffile #GRFFile of the entity that wants to use the storage.
 
 * @param pos Position to write at.
 
 * @param value Value to write.
 
@@ -159,6 +176,12 @@ void TownStorePSA(Town *t, const GRFFile
 
	/* Create a new storage. */
 
	assert(PersistentStorage::CanAllocateItem());
 
	PersistentStorage *psa = new PersistentStorage(grfid);
 
	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
 
@@ -10,14 +10,40 @@
 
/** @file newgrf_town.h Functions to handle the town part of NewGRF towns. */
 

	
 
#ifndef NEWGRF_TOWN_H
 
#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)