Translations update
[openttd/fttd.git] / src / newgrf_house.h
blobb42b60f2a9612dee60eacf7a14b144cdcc861ce1
1 /* $Id$ */
3 /*
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/>.
8 */
10 /** @file newgrf_house.h Functions related to NewGRF houses. */
12 #ifndef NEWGRF_HOUSE_H
13 #define NEWGRF_HOUSE_H
15 #include "newgrf_callbacks.h"
16 #include "tile_cmd.h"
17 #include "house_type.h"
18 #include "newgrf_spritegroup.h"
19 #include "newgrf_town.h"
20 #include "gfx_func.h"
22 /** Scope resolver for houses. */
23 struct HouseScopeResolver : public ScopeResolver {
24 const GRFFile *const grffile; ///< GRFFile the resolved SpriteGroup belongs to.
26 HouseID house_id; ///< Type of house being queried.
27 TileIndex tile; ///< Tile of this house.
28 Town *town; ///< Town of this house.
29 bool not_yet_constructed; ///< True for construction check.
30 uint16 initial_random_bits; ///< Random bits during construction checks.
31 uint32 watched_cargo_triggers; ///< Cargo types that triggered the watched cargo callback.
33 HouseScopeResolver (const GRFFile *grffile, HouseID house_id, TileIndex tile, Town *town,
34 bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers);
36 /* virtual */ uint32 GetRandomBits() const;
37 /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
38 /* virtual */ uint32 GetTriggers() const;
39 /* virtual */ void SetTriggers(int triggers) const;
42 /**
43 * Fake scope resolver for nonexistent houses.
45 * The purpose of this class is to provide a house resolver for a given house
46 * type but not an actual house instantiation. We need this when e.g. drawing
47 * houses in the GUI to keep backward compatibility with GRFs that were
48 * created before this functionality. When querying house sprites, certain
49 * GRFs may read various house variables e.g. the town zone where the
50 * building is located or the XY coordinates. Since the building doesn't
51 * exist we have no real values that we can return. Instead of failing, this
52 * resolver will return fake values.
54 struct FakeHouseScopeResolver : public ScopeResolver {
55 const HouseSpec *hs; ///< HouseSpec of house being queried.
57 FakeHouseScopeResolver (const HouseSpec *hs)
58 : ScopeResolver(), hs(hs)
59 { }
61 /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
64 /** Resolver object to be used for houses (feature 07 spritegroups). */
65 struct HouseResolverObject : public ResolverObject {
66 HouseScopeResolver house_scope;
67 TownScopeResolver town_scope;
69 const SpriteGroup *root_spritegroup; ///< Root SpriteGroup to use for resolving
71 HouseResolverObject(HouseID house_id, TileIndex tile, Town *town,
72 CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0,
73 bool not_yet_constructed = false, uint8 initial_random_bits = 0, uint32 watched_cargo_triggers = 0);
75 /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
77 switch (scope) {
78 case VSG_SCOPE_SELF: return &this->house_scope;
79 case VSG_SCOPE_PARENT: return &this->town_scope;
80 default: return ResolverObject::GetScope(scope, relative);
84 /**
85 * Resolve SpriteGroup.
86 * @return Result spritegroup.
88 const SpriteGroup *Resolve()
90 return SpriteGroup::Resolve (this->root_spritegroup, *this);
94 /** Fake resolver object to be used for houses (feature 07 spritegroups). */
95 struct FakeHouseResolverObject : public ResolverObject {
96 FakeHouseScopeResolver house_scope;
97 FakeTownScopeResolver town_scope;
99 FakeHouseResolverObject (const HouseSpec *hs,
100 CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0);
102 ScopeResolver *GetScope (VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) OVERRIDE
104 switch (scope) {
105 case VSG_SCOPE_SELF: return &this->house_scope;
106 case VSG_SCOPE_PARENT: return &this->town_scope;
107 default: return ResolverObject::GetScope (scope, relative);
113 * Makes class IDs unique to each GRF file.
114 * Houses can be assigned class IDs which are only comparable within the GRF
115 * file they were defined in. This mapping ensures that if two houses have the
116 * same class as defined by the GRF file, the classes are different within the
117 * game. An array of HouseClassMapping structs is created, and the array index
118 * of the struct that matches both the GRF ID and the class ID is the class ID
119 * used in the game.
121 * Although similar to the HouseIDMapping struct above, this serves a different
122 * purpose. Since the class ID is not saved anywhere, this mapping does not
123 * need to be persistent; it just needs to keep class ids unique.
125 struct HouseClassMapping {
126 uint32 grfid; ///< The GRF ID of the file this class belongs to
127 uint8 class_id; ///< The class id within the grf file
130 HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid);
132 void InitializeBuildingCounts();
133 void IncreaseBuildingCount(Town *t, HouseID house_id);
134 void DecreaseBuildingCount(Town *t, HouseID house_id);
136 void DrawNewHouseTile(TileInfo *ti, HouseID house_id);
137 void DrawNewHouseTileInGUI (BlitArea *dpi, int x, int y, HouseID house_id, bool ground);
138 void AnimateNewHouseTile(TileIndex tile);
139 void AnimateNewHouseConstruction(TileIndex tile);
141 uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile,
142 bool not_yet_constructed = false, uint8 initial_random_bits = 0, uint32 watched_cargo_triggers = 0);
143 uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id);
145 void WatchedCargoCallback(TileIndex tile, uint32 trigger_cargoes);
147 bool CanDeleteHouse(TileIndex tile);
149 bool NewHouseTileLoop(TileIndex tile);
151 enum HouseTrigger {
152 /* The tile of the house has been triggered during the tileloop. */
153 HOUSE_TRIGGER_TILE_LOOP = 0x01,
155 * The top tile of a (multitile) building has been triggered during and all
156 * the tileloop other tiles of the same building get the same random value.
158 HOUSE_TRIGGER_TILE_LOOP_TOP = 0x02,
160 void TriggerHouse(TileIndex t, HouseTrigger trigger);
162 #endif /* NEWGRF_HOUSE_H */