OpenTTD

newgrf_house.h
Go to the documentation of this file.
1 /* $Id: newgrf_house.h 27984 2018-03-11 13:19:41Z frosch $ */
2
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 */
9
12 #ifndef NEWGRF_HOUSE_H
13 #define NEWGRF_HOUSE_H
14
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
22 struct HouseScopeResolver : public ScopeResolver {
23 HouseID house_id;
24 TileIndex tile;
25 Town *town;
26 bool not_yet_constructed;
27 uint16 initial_random_bits;
28 uint32 watched_cargo_triggers;
29
40 HouseScopeResolver(ResolverObject &ro, HouseID house_id, TileIndex tile, Town *town,
41 bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
42 : ScopeResolver(ro), house_id(house_id), tile(tile), town(town), not_yet_constructed(not_yet_constructed),
43 initial_random_bits(initial_random_bits), watched_cargo_triggers(watched_cargo_triggers)
44 {
45 }
46
47 /* virtual */ uint32 GetRandomBits() const;
48 /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
49 /* virtual */ uint32 GetTriggers() const;
50 };
51
53 struct HouseResolverObject : public ResolverObject {
54 HouseScopeResolver house_scope;
55 TownScopeResolver town_scope;
56
57 HouseResolverObject(HouseID house_id, TileIndex tile, Town *town,
58 CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0,
59 bool not_yet_constructed = false, uint8 initial_random_bits = 0, uint32 watched_cargo_triggers = 0);
60
61 /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
62 {
63 switch (scope) {
64 case VSG_SCOPE_SELF: return &this->house_scope;
65 case VSG_SCOPE_PARENT: return &this->town_scope;
66 default: return ResolverObject::GetScope(scope, relative);
67 }
68 }
69 };
70
84 struct HouseClassMapping {
85 uint32 grfid;
86 uint8 class_id;
87 };
88
89 HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid);
90
91 void InitializeBuildingCounts();
92 void IncreaseBuildingCount(Town *t, HouseID house_id);
93 void DecreaseBuildingCount(Town *t, HouseID house_id);
94
95 void DrawNewHouseTile(TileInfo *ti, HouseID house_id);
96 void AnimateNewHouseTile(TileIndex tile);
97 void AnimateNewHouseConstruction(TileIndex tile);
98
99 uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile,
100 bool not_yet_constructed = false, uint8 initial_random_bits = 0, uint32 watched_cargo_triggers = 0);
101 void WatchedCargoCallback(TileIndex tile, uint32 trigger_cargoes);
102
103 bool CanDeleteHouse(TileIndex tile);
104
105 bool NewHouseTileLoop(TileIndex tile);
106
107 enum HouseTrigger {
108 /* The tile of the house has been triggered during the tileloop. */
109 HOUSE_TRIGGER_TILE_LOOP = 0x01,
110 /*
111 * The top tile of a (multitile) building has been triggered during and all
112 * the tileloop other tiles of the same building get the same random value.
113 */
114 HOUSE_TRIGGER_TILE_LOOP_TOP = 0x02,
115 };
116 void TriggerHouse(TileIndex t, HouseTrigger trigger);
117
118 #endif /* NEWGRF_HOUSE_H */
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope)...
Definition: newgrf_spritegroup.h:291
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:44
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:292
VarSpriteGroupScope
VarSpriteGroupScope
Definition: newgrf_spritegroup.h:100
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:310
house_type.h
declaration of basic house types and enums
HouseScopeResolver::town
Town * town
Town of this house.
Definition: newgrf_house.h:25
HouseClassID
uint16 HouseClassID
Classes of houses.
Definition: house_type.h:16
HouseClassMapping
Makes class IDs unique to each GRF file.
Definition: newgrf_house.h:84
HouseScopeResolver::GetRandomBits
uint32 GetRandomBits() const
Get a few random bits.
Definition: newgrf_house.cpp:136
CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition: newgrf_callbacks.h:24
ResolverObject::GetScope
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
Definition: newgrf_spritegroup.cpp:142
HouseResolverObject
Resolver object to be used for houses (feature 07 spritegroups).
Definition: newgrf_house.h:53
HouseScopeResolver::initial_random_bits
uint16 initial_random_bits
Random bits during construction checks.
Definition: newgrf_house.h:27
HouseID
uint16 HouseID
OpenTTD ID of house types.
Definition: house_type.h:15
newgrf_callbacks.h
Callbacks that NewGRFs could implement.
newgrf_spritegroup.h
Action 2 handling.
HouseScopeResolver::house_id
HouseID house_id
Type of house being queried.
Definition: newgrf_house.h:23
HouseScopeResolver::HouseScopeResolver
HouseScopeResolver(ResolverObject &ro, HouseID house_id, TileIndex tile, Town *town, bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
Constructor of a house scope resolver.
Definition: newgrf_house.h:40
HouseScopeResolver
Scope resolver for houses.
Definition: newgrf_house.h:22
TownScopeResolver
Scope resolver for a town.
Definition: newgrf_town.h:24
HouseScopeResolver::watched_cargo_triggers
uint32 watched_cargo_triggers
Cargo types that triggered the watched cargo callback.
Definition: newgrf_house.h:28
HouseScopeResolver::GetTriggers
uint32 GetTriggers() const
Get the triggers.
Definition: newgrf_house.cpp:143
HouseScopeResolver::not_yet_constructed
bool not_yet_constructed
True for construction check.
Definition: newgrf_house.h:26
VSG_SCOPE_SELF
Resolved object itself.
Definition: newgrf_spritegroup.h:103
DecreaseBuildingCount
void DecreaseBuildingCount(Town *t, HouseID house_id)
DecreaseBuildingCount() Decrease the number of a building when it is deleted.
Definition: newgrf_house.cpp:121
HouseClassMapping::class_id
uint8 class_id
The class id within the grf file.
Definition: newgrf_house.h:86
IncreaseBuildingCount
void IncreaseBuildingCount(Town *t, HouseID house_id)
IncreaseBuildingCount() Increase the count of a building when it has been added by a town...
Definition: newgrf_house.cpp:100
HouseScopeResolver::tile
TileIndex tile
Tile of this house.
Definition: newgrf_house.h:24
HouseResolverObject::GetScope
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
Definition: newgrf_house.h:61
WatchedCargoCallback
void WatchedCargoCallback(TileIndex tile, uint32 trigger_cargoes)
Run watched cargo accepted callback for a house.
Definition: newgrf_house.cpp:649
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
VSG_SCOPE_PARENT
Related object of the resolved one.
Definition: newgrf_spritegroup.h:104
Town
Town data structure.
Definition: town.h:55
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition: newgrf_callbacks.h:22
newgrf_town.h
Functions to handle the town part of NewGRF towns.
HouseClassMapping::grfid
uint32 grfid
The GRF ID of the file this class belongs to.
Definition: newgrf_house.h:85
HouseScopeResolver::GetVariable
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Definition: newgrf_house.cpp:290
tile_cmd.h
Generic &#39;commands&#39; that can be performed on all tiles.