OpenTTD Source: src/newgrf_house.h Source File

OpenTTD Source 15.0-beta1

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
20 struct HouseScopeResolver : public ScopeResolver {
21 HouseID house_id;
22 TileIndex tile;
23 Town *town;
24 bool not_yet_constructed;
25 uint16_t initial_random_bits;
26 CargoTypes watched_cargo_triggers;
27 int view;
28
39 HouseScopeResolver(ResolverObject &ro, HouseID house_id, TileIndex tile, Town *town,
40 bool not_yet_constructed, uint8_t initial_random_bits, CargoTypes watched_cargo_triggers, int view)
41 : ScopeResolver(ro), house_id(house_id), tile(tile), town(town), not_yet_constructed(not_yet_constructed),
42 initial_random_bits(initial_random_bits), watched_cargo_triggers(watched_cargo_triggers), view(view)
43 {
44 }
45
46 uint32_t GetRandomBits() const override;
47 uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
48 uint32_t GetTriggers() const override;
49};
50
52 struct HouseResolverObject : public ResolverObject {
53 HouseScopeResolver house_scope;
54 TownScopeResolver town_scope;
55
56 HouseResolverObject(HouseID house_id, TileIndex tile, Town *town,
57 CallbackID callback = CBID_NO_CALLBACK, uint32_t param1 = 0, uint32_t param2 = 0,
58 bool not_yet_constructed = false, uint8_t initial_random_bits = 0, CargoTypes watched_cargo_triggers = 0, int view = 0);
59
60 ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, uint8_t relative = 0) override
61 {
62 switch (scope) {
63 case VSG_SCOPE_SELF: return &this->house_scope;
64 case VSG_SCOPE_PARENT: return &this->town_scope;
65 default: return ResolverObject::GetScope(scope, relative);
66 }
67 }
68
69 GrfSpecFeature GetFeature() const override;
70 uint32_t GetDebugID() const override;
71};
72
86 struct HouseClassMapping {
87 uint32_t grfid;
88 uint8_t class_id;
89};
90
91void ResetHouseClassIDs();
92 HouseClassID AllocateHouseClassID(uint8_t grf_class_id, uint32_t grfid);
93
94void InitializeBuildingCounts();
95void InitializeBuildingCounts(Town *t);
96void IncreaseBuildingCount(Town *t, HouseID house_id);
97void DecreaseBuildingCount(Town *t, HouseID house_id);
98std::span<const uint> GetBuildingHouseIDCounts();
99
100void DrawNewHouseTile(TileInfo *ti, HouseID house_id);
101void AnimateNewHouseTile(TileIndex tile);
102void AnimateNewHouseConstruction(TileIndex tile);
103
104uint16_t GetHouseCallback(CallbackID callback, uint32_t param1, uint32_t param2, HouseID house_id, Town *town, TileIndex tile,
105 bool not_yet_constructed = false, uint8_t initial_random_bits = 0, CargoTypes watched_cargo_triggers = 0, int view = 0);
106void WatchedCargoCallback(TileIndex tile, CargoTypes trigger_cargoes);
107
108bool CanDeleteHouse(TileIndex tile);
109
110bool NewHouseTileLoop(TileIndex tile);
111
112enum HouseTrigger {
113 /* The tile of the house has been triggered during the tileloop. */
114 HOUSE_TRIGGER_TILE_LOOP = 0x01,
115 /*
116 * The top tile of a (multitile) building has been triggered during and all
117 * the tileloop other tiles of the same building get the same random value.
118 */
119 HOUSE_TRIGGER_TILE_LOOP_TOP = 0x02,
120};
121void TriggerHouse(TileIndex t, HouseTrigger trigger);
122
123#endif /* NEWGRF_HOUSE_H */
house_type.h
declaration of basic house types and enums
HouseClassID
uint16_t HouseClassID
Classes of houses.
Definition house_type.h:14
HouseID
uint16_t HouseID
OpenTTD ID of house types.
Definition house_type.h:13
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:67
newgrf_callbacks.h
Callbacks that NewGRFs could implement.
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition newgrf_callbacks.h:20
CBID_NO_CALLBACK
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition newgrf_callbacks.h:22
DecreaseBuildingCount
void DecreaseBuildingCount(Town *t, HouseID house_id)
DecreaseBuildingCount() Decrease the number of a building when it is deleted.
Definition newgrf_house.cpp:209
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:190
WatchedCargoCallback
void WatchedCargoCallback(TileIndex tile, CargoTypes trigger_cargoes)
Run watched cargo accepted callback for a house.
Definition newgrf_house.cpp:754
GetBuildingHouseIDCounts
std::span< const uint > GetBuildingHouseIDCounts()
Get read-only span of total HouseID building counts.
Definition newgrf_house.cpp:179
InitializeBuildingCounts
void InitializeBuildingCounts()
Initialise global building counts and all town building counts.
Definition newgrf_house.cpp:163
newgrf_spritegroup.h
Action 2 handling.
VarSpriteGroupScope
VarSpriteGroupScope
Definition newgrf_spritegroup.h:97
VSG_SCOPE_SELF
@ VSG_SCOPE_SELF
Resolved object itself.
Definition newgrf_spritegroup.h:100
VSG_SCOPE_PARENT
@ VSG_SCOPE_PARENT
Related object of the resolved one.
Definition newgrf_spritegroup.h:101
newgrf_town.h
Functions to handle the town part of NewGRF towns.
HouseClassMapping
Makes class IDs unique to each GRF file.
Definition newgrf_house.h:86
HouseClassMapping::class_id
uint8_t class_id
The class id within the grf file.
Definition newgrf_house.h:88
HouseClassMapping::grfid
uint32_t grfid
The GRF ID of the file this class belongs to.
Definition newgrf_house.h:87
HouseResolverObject
Resolver object to be used for houses (feature 07 spritegroups).
Definition newgrf_house.h:52
HouseResolverObject::GetDebugID
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Definition newgrf_house.cpp:124
HouseResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition newgrf_house.cpp:119
HouseResolverObject::GetScope
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0) override
Get a resolver for the scope.
Definition newgrf_house.h:60
HouseScopeResolver
Scope resolver for houses.
Definition newgrf_house.h:20
HouseScopeResolver::view
int view
View when house does yet exist.
Definition newgrf_house.h:27
HouseScopeResolver::town
Town * town
Town of this house.
Definition newgrf_house.h:23
HouseScopeResolver::tile
TileIndex tile
Tile of this house.
Definition newgrf_house.h:22
HouseScopeResolver::watched_cargo_triggers
CargoTypes watched_cargo_triggers
Cargo types that triggered the watched cargo callback.
Definition newgrf_house.h:26
HouseScopeResolver::GetVariable
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Definition newgrf_house.cpp:373
HouseScopeResolver::HouseScopeResolver
HouseScopeResolver(ResolverObject &ro, HouseID house_id, TileIndex tile, Town *town, bool not_yet_constructed, uint8_t initial_random_bits, CargoTypes watched_cargo_triggers, int view)
Constructor of a house scope resolver.
Definition newgrf_house.h:39
HouseScopeResolver::initial_random_bits
uint16_t initial_random_bits
Random bits during construction checks.
Definition newgrf_house.h:25
HouseScopeResolver::GetRandomBits
uint32_t GetRandomBits() const override
Get a few random bits.
Definition newgrf_house.cpp:222
HouseScopeResolver::house_id
HouseID house_id
Type of house being queried.
Definition newgrf_house.h:21
HouseScopeResolver::GetTriggers
uint32_t GetTriggers() const override
Get the triggers.
Definition newgrf_house.cpp:228
HouseScopeResolver::not_yet_constructed
bool not_yet_constructed
True for construction check.
Definition newgrf_house.h:24
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition newgrf_spritegroup.h:296
ResolverObject::callback
CallbackID callback
Callback being resolved.
Definition newgrf_spritegroup.h:314
ResolverObject::GetScope
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0)
Get a resolver for the scope.
Definition newgrf_spritegroup.cpp:135
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
Definition newgrf_spritegroup.h:277
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition newgrf_spritegroup.h:278
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TileInfo
Tile information, used while rendering the tile.
Definition tile_cmd.h:43
TownScopeResolver
Scope resolver for a town.
Definition newgrf_town.h:22
Town
Town data structure.
Definition town.h:54
tile_cmd.h
Generic 'commands' that can be performed on all tiles.