4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file newgrf_town.h Functions to handle the town part of NewGRF towns. */
15 #include "town_type.h"
16 #include "newgrf_spritegroup.h"
19 * Scope resolver for a town.
20 * @note Currently there is no direct town resolver; we only need to get town
21 * variable results from inside stations, house tiles and industries,
22 * and to check the town's persistent storage.
24 struct TownScopeResolver
: public ScopeResolver
{
25 const GRFFile
*const grffile
; ///< GRFFile the resolved SpriteGroup belongs to.
26 Town
*t
; ///< %Town of the scope.
27 bool readonly
; ///< When set, persistent storage of the town is read-only,
29 TownScopeResolver (const GRFFile
*grffile
, Town
*t
, bool readonly
);
31 virtual uint32
GetVariable(byte variable
, uint32 parameter
, bool *available
) const;
32 virtual void StorePSA(uint reg
, int32 value
);
36 * Fake scope resolver for a nonexistent town.
38 * The purpose of this class is to provide a house resolver for a given house
39 * type but not an actual house instantiation. We need this when e.g. drawing
40 * houses in the GUI to keep backward compatibility with GRFs that were
41 * created before this functionality. When querying house sprites, certain
42 * GRFs may read various town variables e.g. the population. Since the
43 * building doesn't exist and is not bound to any town we have no real values
44 * that we can return. Instead of failing, this resolver will return fake
47 struct FakeTownScopeResolver
: public ScopeResolver
{
48 FakeTownScopeResolver() : ScopeResolver()
51 virtual uint32
GetVariable(byte variable
, uint32 parameter
, bool *available
) const;
54 /** Resolver of town properties. */
55 struct TownResolverObject
: public ResolverObject
{
56 TownScopeResolver town_scope
; ///< Scope resolver specific for towns.
58 TownResolverObject(const struct GRFFile
*grffile
, Town
*t
, bool readonly
);
60 /* virtual */ ScopeResolver
*GetScope(VarSpriteGroupScope scope
= VSG_SCOPE_SELF
, byte relative
= 0)
63 case VSG_SCOPE_SELF
: return &town_scope
;
64 default: return ResolverObject::GetScope(scope
, relative
);
69 #endif /* NEWGRF_TOWN_H */