OpenTTD Source 20260721-master-g25ec12c62d
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
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
20struct HouseScopeResolver : public ScopeResolver {
27 int view;
28
46
47 uint32_t GetRandomBits() const override;
48 uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
49 uint32_t GetRandomTriggers() const override;
50};
51
53struct HouseResolverObject : public SpecializedResolverObject<HouseRandomTriggers> {
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_t param1 = 0, uint32_t param2 = 0,
59 bool not_yet_constructed = false, uint8_t initial_random_bits = 0, CargoTypes watched_cargo_triggers = {}, int view = 0);
60
62 {
63 switch (scope) {
64 case VarSpriteGroupScope::Self: return &this->house_scope;
65 case VarSpriteGroupScope::Parent: return &this->town_scope;
66 default: return ResolverObject::GetScope(scope, relative);
67 }
68 }
69
70 GrfSpecFeature GetFeature() const override;
71 uint32_t GetDebugID() const override;
72};
73
91
92void ResetHouseClassIDs();
93HouseClassID AllocateHouseClassID(uint8_t grf_class_id, GrfID grfid);
94
97void IncreaseBuildingCount(Town *t, HouseID house_id);
98void DecreaseBuildingCount(Town *t, HouseID house_id);
99std::span<const uint> GetBuildingHouseIDCounts();
100
101void DrawNewHouseTile(TileInfo *ti, HouseID house_id);
102void DrawNewHouseTileInGUI(int x, int y, const HouseSpec *spec, HouseID house_id, int view);
103void AnimateNewHouseTile(TileIndex tile);
104/* see also: void TriggerHouseAnimation_TileLoop(TileIndex tile, uint16_t random_bits) */
105void TriggerHouseAnimation_ConstructionStageChanged(TileIndex tile, bool first_call);
107
108uint16_t GetHouseCallback(CallbackID callback, uint32_t param1, uint32_t param2, HouseID house_id, Town *town, TileIndex tile, std::span<int32_t> regs100 = {},
109 bool not_yet_constructed = false, uint8_t initial_random_bits = 0, CargoTypes watched_cargo_triggers = {}, int view = 0);
110
111bool CanDeleteHouse(TileIndex tile);
112
113bool NewHouseTileLoop(TileIndex tile);
114
115void TriggerHouseRandomisation(TileIndex t, HouseRandomTrigger trigger);
116
117#endif /* NEWGRF_HOUSE_H */
EnumBitSet< CargoType, uint64_t > CargoTypes
Bitset of CargoType elements.
Definition cargo_type.h:113
Declaration of basic house types and enums.
HouseRandomTrigger
Randomisation triggers for houses.
Definition house_type.h:21
uint16_t HouseClassID
Classes of houses.
Definition house_type.h:16
uint16_t HouseID
OpenTTD ID of house types.
Definition house_type.h:15
GrfSpecFeature
Definition newgrf.h:78
Callbacks that NewGRFs could implement.
CallbackID
List of implemented NewGRF callbacks.
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
void DecreaseBuildingCount(Town *t, HouseID house_id)
DecreaseBuildingCount() Decrease the number of a building when it is deleted.
void IncreaseBuildingCount(Town *t, HouseID house_id)
IncreaseBuildingCount() Increase the count of a building when it has been added by a town.
std::span< const uint > GetBuildingHouseIDCounts()
Get read-only span of total HouseID building counts.
void DrawNewHouseTileInGUI(int x, int y, const HouseSpec *spec, HouseID house_id, int view)
Draw representation of a house tile for GUI purposes.
uint16_t GetHouseCallback(CallbackID callback, uint32_t param1, uint32_t param2, HouseID house_id, Town *town, TileIndex tile, std::span< int32_t > regs100={}, bool not_yet_constructed=false, uint8_t initial_random_bits=0, CargoTypes watched_cargo_triggers={}, int view=0)
Get the result of a house callback.
HouseClassID AllocateHouseClassID(uint8_t grf_class_id, GrfID grfid)
Allocate a house class for the given NewGRF and ID.
void InitializeBuildingCounts()
Initialise global building counts and all town building counts.
void TriggerHouseAnimation_WatchedCargoAccepted(TileIndex tile, CargoTypes trigger_cargoes)
Run watched cargo accepted callback for a house.
Action 2 handling.
VarSpriteGroupScope
Shared by deterministic and random groups.
@ Parent
Related object of the resolved one.
@ Self
Resolved object itself.
Functions to handle the town part of NewGRF towns.
Label< struct GrfIDTag > GrfID
The unique identifier of a NewGRF.
Definition newgrf_type.h:17
Makes class IDs unique to each GRF file.
GrfID grfid
The GRF ID of the file this class belongs to.
uint8_t class_id
The class id within the grf file.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VarSpriteGroupScope::Self, uint8_t relative=0) override
Get a resolver for the scope.
HouseResolverObject(HouseID house_id, TileIndex tile, Town *town, CallbackID callback=CBID_NO_CALLBACK, uint32_t param1=0, uint32_t param2=0, bool not_yet_constructed=false, uint8_t initial_random_bits=0, CargoTypes watched_cargo_triggers={}, int view=0)
Construct a resolver for a house.
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Scope resolver for houses.
int view
View when house does yet exist.
Town * town
Town of this house.
TileIndex tile
Tile of this house.
CargoTypes watched_cargo_triggers
Cargo types that triggered the watched cargo callback.
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
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.
uint16_t initial_random_bits
Random bits during construction checks.
uint32_t GetRandomBits() const override
Get a few random bits.
HouseID house_id
Type of house being queried.
uint32_t GetRandomTriggers() const override
Get the triggers.
bool not_yet_constructed
True for construction check.
Interface for SpriteGroup-s to access the gamestate.
CallbackID callback
Callback being resolved.
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VarSpriteGroupScope::Self, uint8_t relative=0)
Get a resolver for the scope.
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
ResolverObject & ro
Surrounding resolver object.
Specialization of ResolverObject with type-safe access to RandomTriggers.
Tile information, used while rendering the tile.
Definition tile_cmd.h:34
Scope resolver for a town.
Definition newgrf_town.h:22
Town data structure.
Definition town.h:64
Generic 'commands' that can be performed on all tiles.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92