OpenTTD Source  12.0-beta2
newgrf_house.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #ifndef NEWGRF_HOUSE_H
11 #define NEWGRF_HOUSE_H
12 
13 #include "newgrf_callbacks.h"
14 #include "tile_cmd.h"
15 #include "house_type.h"
16 #include "newgrf_spritegroup.h"
17 #include "newgrf_town.h"
18 
27 
42  {
43  }
44 
45  uint32 GetRandomBits() const override;
46  uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override;
47  uint32 GetTriggers() const override;
48 };
49 
52  HouseScopeResolver house_scope;
53  TownScopeResolver town_scope;
54 
55  HouseResolverObject(HouseID house_id, TileIndex tile, Town *town,
56  CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0,
57  bool not_yet_constructed = false, uint8 initial_random_bits = 0, CargoTypes watched_cargo_triggers = 0);
58 
59  ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override
60  {
61  switch (scope) {
62  case VSG_SCOPE_SELF: return &this->house_scope;
63  case VSG_SCOPE_PARENT: return &this->town_scope;
64  default: return ResolverObject::GetScope(scope, relative);
65  }
66  }
67 
68  GrfSpecFeature GetFeature() const override;
69  uint32 GetDebugID() const override;
70 };
71 
86  uint32 grfid;
87  uint8 class_id;
88 };
89 
90 HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid);
91 
92 void InitializeBuildingCounts();
93 void IncreaseBuildingCount(Town *t, HouseID house_id);
94 void DecreaseBuildingCount(Town *t, HouseID house_id);
95 
96 void DrawNewHouseTile(TileInfo *ti, HouseID house_id);
97 void AnimateNewHouseTile(TileIndex tile);
98 void AnimateNewHouseConstruction(TileIndex tile);
99 
100 uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile,
101  bool not_yet_constructed = false, uint8 initial_random_bits = 0, CargoTypes watched_cargo_triggers = 0);
102 void WatchedCargoCallback(TileIndex tile, CargoTypes trigger_cargoes);
103 
104 bool CanDeleteHouse(TileIndex tile);
105 
106 bool NewHouseTileLoop(TileIndex tile);
107 
108 enum HouseTrigger {
109  /* The tile of the house has been triggered during the tileloop. */
110  HOUSE_TRIGGER_TILE_LOOP = 0x01,
111  /*
112  * The top tile of a (multitile) building has been triggered during and all
113  * the tileloop other tiles of the same building get the same random value.
114  */
115  HOUSE_TRIGGER_TILE_LOOP_TOP = 0x02,
116 };
117 void TriggerHouse(TileIndex t, HouseTrigger trigger);
118 
119 #endif /* NEWGRF_HOUSE_H */
house_type.h
HouseResolverObject::GetDebugID
uint32 GetDebugID() const override
Get an identifier for the item being resolved.
Definition: newgrf_house.cpp:70
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
VarSpriteGroupScope
VarSpriteGroupScope
Definition: newgrf_spritegroup.h:97
HouseScopeResolver::GetTriggers
uint32 GetTriggers() const override
Get the triggers.
Definition: newgrf_house.cpp:146
HouseScopeResolver::town
Town * town
Town of this house.
Definition: newgrf_house.h:23
HouseScopeResolver::watched_cargo_triggers
CargoTypes watched_cargo_triggers
Cargo types that triggered the watched cargo callback.
Definition: newgrf_house.h:26
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:42
HouseResolverObject
Resolver object to be used for houses (feature 07 spritegroups).
Definition: newgrf_house.h:51
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:307
newgrf_callbacks.h
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition: newgrf_callbacks.h:20
VSG_SCOPE_PARENT
@ VSG_SCOPE_PARENT
Related object of the resolved one.
Definition: newgrf_spritegroup.h:101
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
Definition: newgrf_spritegroup.h:288
WatchedCargoCallback
void WatchedCargoCallback(TileIndex tile, CargoTypes trigger_cargoes)
Run watched cargo accepted callback for a house.
Definition: newgrf_house.cpp:651
HouseClassMapping::grfid
uint32 grfid
The GRF ID of the file this class belongs to.
Definition: newgrf_house.h:86
HouseScopeResolver::GetRandomBits
uint32 GetRandomBits() const override
Get a few random bits.
Definition: newgrf_house.cpp:139
VSG_SCOPE_SELF
@ VSG_SCOPE_SELF
Resolved object itself.
Definition: newgrf_spritegroup.h:100
tile_cmd.h
HouseScopeResolver::house_id
HouseID house_id
Type of house being queried.
Definition: newgrf_house.h:21
HouseScopeResolver::not_yet_constructed
bool not_yet_constructed
True for construction check.
Definition: newgrf_house.h:24
CBID_NO_CALLBACK
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition: newgrf_callbacks.h:22
HouseClassMapping::class_id
uint8 class_id
The class id within the grf file.
Definition: newgrf_house.h:87
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:107
HouseScopeResolver::GetVariable
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override
Definition: newgrf_house.cpp:293
ResolverObject::GetScope
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
Definition: newgrf_spritegroup.cpp:139
TownScopeResolver
Scope resolver for a town.
Definition: newgrf_town.h:22
HouseResolverObject::GetScope
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
Definition: newgrf_house.h:59
newgrf_spritegroup.h
newgrf_town.h
GrfSpecFeature
GrfSpecFeature
Definition: newgrf.h:66
DecreaseBuildingCount
void DecreaseBuildingCount(Town *t, HouseID house_id)
DecreaseBuildingCount() Decrease the number of a building when it is deleted.
Definition: newgrf_house.cpp:126
HouseScopeResolver::HouseScopeResolver
HouseScopeResolver(ResolverObject &ro, HouseID house_id, TileIndex tile, Town *town, bool not_yet_constructed, uint8 initial_random_bits, CargoTypes watched_cargo_triggers)
Constructor of a house scope resolver.
Definition: newgrf_house.h:38
HouseID
uint16 HouseID
OpenTTD ID of house types.
Definition: house_type.h:13
HouseScopeResolver::initial_random_bits
uint16 initial_random_bits
Random bits during construction checks.
Definition: newgrf_house.h:25
HouseResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition: newgrf_house.cpp:65
ResolverObject::callback
CallbackID callback
Callback being resolved.
Definition: newgrf_spritegroup.h:325
HouseScopeResolver
Scope resolver for houses.
Definition: newgrf_house.h:20
HouseResolverObject::HouseResolverObject
HouseResolverObject(HouseID house_id, TileIndex tile, Town *town, CallbackID callback=CBID_NO_CALLBACK, uint32 param1=0, uint32 param2=0, bool not_yet_constructed=false, uint8 initial_random_bits=0, CargoTypes watched_cargo_triggers=0)
Construct a resolver for a house.
Definition: newgrf_house.cpp:55
HouseClassID
uint16 HouseClassID
Classes of houses.
Definition: house_type.h:14
HouseScopeResolver::tile
TileIndex tile
Tile of this house.
Definition: newgrf_house.h:22
Town
Town data structure.
Definition: town.h:50
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:289
HouseClassMapping
Makes class IDs unique to each GRF file.
Definition: newgrf_house.h:85