OpenTTD Source 20260206-master-g4d4e37dbf1
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 HOUSE_H
11#define HOUSE_H
12
13#include "cargo_type.h"
15#include "house_type.h"
17#include "newgrf_badge_type.h"
18#include "newgrf_callbacks.h"
19#include "newgrf_commons.h"
20
25static const uint8_t TOWN_HOUSE_COMPLETED = 3;
26
27static const uint HOUSE_NO_CLASS = 0;
28static const HouseID NEW_HOUSE_OFFSET = 110;
29static const HouseID NUM_HOUSES = 4096;
30static const HouseID INVALID_HOUSE_ID = UINT16_MAX;
31
33
34static const uint HOUSE_NUM_ACCEPTS = 16;
35static const uint HOUSE_ORIGINAL_NUM_ACCEPTS = 3;
36
38enum class BuildingFlag : uint8_t {
39 Size1x1 = 0,
41 Size2x1 = 2,
42 Size1x2 = 3,
43 Size2x2 = 4,
47};
48using BuildingFlags = EnumBitSet<BuildingFlag, uint8_t>;
49
50static constexpr BuildingFlags BUILDING_HAS_1_TILE = {BuildingFlag::Size1x1, BuildingFlag::Size2x1, BuildingFlag::Size1x2, BuildingFlag::Size2x2};
51static constexpr BuildingFlags BUILDING_HAS_2_TILES = {BuildingFlag::Size2x1, BuildingFlag::Size1x2, BuildingFlag::Size2x2};
52static constexpr BuildingFlags BUILDING_2_TILES_X = {BuildingFlag::Size2x1, BuildingFlag::Size2x2};
53static constexpr BuildingFlags BUILDING_2_TILES_Y = {BuildingFlag::Size1x2, BuildingFlag::Size2x2};
54static constexpr BuildingFlags BUILDING_HAS_4_TILES = {BuildingFlag::Size2x2};
55
71using HouseZones = EnumBitSet<HouseZone, uint16_t>;
72
73static constexpr uint NUM_HOUSE_ZONES = to_underlying(HouseZone::TownEnd);
74static_assert(NUM_HOUSE_ZONES == 5);
75
76static constexpr HouseZones HZ_ZONE_ALL = {
82};
83
84static constexpr HouseZones HZ_CLIMATE_ALL = {
90};
91
98using HouseExtraFlags = EnumBitSet<HouseExtraFlag, uint8_t>;
99
100struct HouseSpec {
101 /* Standard properties */
102 TimerGameCalendar::Year min_year;
103 TimerGameCalendar::Year max_year;
104 uint8_t population;
105 uint8_t removal_cost;
111 BuildingFlags building_flags;
113 bool enabled;
114
115 /* NewHouses properties */
117 HouseCallbackMasks callback_mask;
118 Colours random_colour[4];
119 uint8_t probability;
120 HouseExtraFlags extra_flags{};
124 uint8_t minimum_life;
125 CargoTypes watched_cargoes;
126 std::vector<BadgeID> badges;
127
129
130 HouseID Index() const;
131 Money GetRemovalCost() const;
132
133 static std::vector<HouseSpec> &Specs();
134 static HouseSpec *Get(size_t house_id);
135};
136
143{
144 const HouseSpec *hs = HouseSpec::Get(hid);
145 return hs->grf_prop.override_id == INVALID_HOUSE_ID ? hid : hs->grf_prop.override_id;
146}
147
148void ShowBuildHousePicker(struct Window *);
149HouseZones GetClimateMaskForLandscape();
150
151#endif /* HOUSE_H */
Types related to cargoes...
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
StrongType::Typedef< uint32_t, struct CargoLabelTag, StrongType::Compare > CargoLabel
Globally unique label of a cargo type.
Definition cargo_type.h:16
Enum-as-bit-set wrapper.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:17
HouseExtraFlag
Definition house.h:92
@ SynchronisedCallback1B
synchronized callback 1B will be performed, on multi tile houses
Definition house.h:95
@ Callback1ARandomBits
callback 1A needs random bits
Definition house.h:96
@ BuildingIsHistorical
this house will only appear during town generation in random games, thus the historical
Definition house.h:93
@ BuildingIsProtected
towns and AI will not remove this house, while human players will be able to
Definition house.h:94
HouseZones GetClimateMaskForLandscape()
Get the HouseZones climate mask for the current landscape type.
static const HouseID NUM_HOUSES
Total number of houses.
Definition house.h:29
BuildingFlag
Flags describing the layout and purpose of a building.
Definition house.h:38
@ Size1x1
The building is a single tile.
Definition house.h:39
@ Size2x2
The building is 2x2 tiles.
Definition house.h:43
@ IsAnimated
The building uses animation.
Definition house.h:44
@ NotSloped
The building can only be built on flat land; when not set foundations are placed.
Definition house.h:40
@ Size2x1
The building is 2x1 tiles, i.e. wider on the X-axis.
Definition house.h:41
@ IsChurch
The building functions as a church, i.e. only one can be built in a town.
Definition house.h:45
@ IsStadium
The building functions as a stadium, i.e. only one can be built in a town.
Definition house.h:46
@ Size1x2
The building is 1x2 tiles, i.e. wider on the Y-axis.
Definition house.h:42
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
Definition house.h:28
HouseID GetTranslatedHouseID(HouseID hid)
Do HouseID translation for NewGRFs.
Definition house.h:142
static const HouseID NUM_HOUSES_PER_GRF
Number of supported houses per NewGRF.
Definition house.h:32
static const uint HOUSE_NUM_ACCEPTS
Max number of cargoes accepted by a tile.
Definition house.h:34
static const uint8_t TOWN_HOUSE_COMPLETED
Simple value that indicates the house has reached the final stage of construction.
Definition house.h:25
static const uint HOUSE_ORIGINAL_NUM_ACCEPTS
Original number of accepted cargo types.
Definition house.h:35
HouseZone
Concentric rings of zoning around the centre of a town.
Definition house.h:57
@ TownOuterSuburb
Outer suburbs; roads with pavement.
Definition house.h:60
@ ClimateSubarcticAboveSnow
Building can appear in sub-arctic climate above the snow line.
Definition house.h:65
@ ClimateSubarcticBelowSnow
Building can appear in sub-arctic climate below the snow line.
Definition house.h:67
@ TownInnerSuburb
Inner suburbs; roads with pavement and trees.
Definition house.h:61
@ TownOutskirt
Outskirts of a town; roads without pavement.
Definition house.h:59
@ TownEdge
Edge of the town; roads without pavement.
Definition house.h:58
@ TownCentre
Centre of town; roads with pavement and streetlights.
Definition house.h:62
@ ClimateTemperate
Building can appear in temperate climate.
Definition house.h:66
@ ClimateToyland
Building can appear in toyland climate.
Definition house.h:69
@ ClimateSubtropic
Building can appear in subtropical climate.
Definition house.h:68
Declaration of basic house types and enums.
uint16_t HouseClassID
Classes of houses.
Definition house_type.h:16
uint16_t HouseID
OpenTTD ID of house types.
Definition house_type.h:15
Definitions related to NewGRF animation.
Types related to NewGRF badges.
Callbacks that NewGRFs could implement.
This file simplifies and embeds a common mechanism of loading/saving and mapping of grf entities.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Information about animation.
CargoType accepts_cargo[HOUSE_NUM_ACCEPTS]
input cargo slots
Definition house.h:110
SubstituteGRFFileProps grf_prop
Properties related the the grf file.
Definition house.h:116
uint8_t probability
Relative probability of appearing (16 is the standard value).
Definition house.h:119
CargoTypes watched_cargoes
Cargo types watched for acceptance.
Definition house.h:125
uint8_t removal_cost
cost multiplier for removing it
Definition house.h:105
uint8_t mail_generation
mail generation multiplier (tile based, as the acceptances below)
Definition house.h:108
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
Definition house.h:113
CargoLabel accepts_cargo_label[HOUSE_ORIGINAL_NUM_ACCEPTS]
input landscape cargo slots
Definition house.h:128
Money GetRemovalCost() const
Get the cost for removing this house.
Definition town_cmd.cpp:232
static HouseSpec * Get(size_t house_id)
Get the spec for a house ID.
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
Definition house.h:111
TimerGameCalendar::Year max_year
last year it can be built
Definition house.h:103
uint8_t processing_time
Periodic refresh multiplier.
Definition house.h:123
HouseCallbackMasks callback_mask
Bitmask of house callbacks that have to be called.
Definition house.h:117
uint16_t remove_rating_decrease
rating decrease if removed
Definition house.h:107
uint8_t population
population (Zero on other tiles in multi tile house.)
Definition house.h:104
HouseExtraFlags extra_flags
some more flags
Definition house.h:120
uint8_t cargo_acceptance[HOUSE_NUM_ACCEPTS]
acceptance level for the cargo slots
Definition house.h:109
TimerGameCalendar::Year min_year
introduction year of the house
Definition house.h:102
HouseID Index() const
Gets the index of this spec.
HouseClassID class_id
defines the class this house has (not grf file based)
Definition house.h:121
AnimationInfo< void > animation
information about the animation.
Definition house.h:122
StringID building_name
building name
Definition house.h:106
uint8_t minimum_life
The minimum number of years this house will survive before the town rebuilds it.
Definition house.h:124
Colours random_colour[4]
4 "random" colours
Definition house.h:118
HouseZones building_availability
where can it be built (climates, zones)
Definition house.h:112
static std::vector< HouseSpec > & Specs()
Get a reference to all HouseSpecs.
NewGRF entities which can replace default entities.
uint16_t override_id
id of the entity been replaced by
Data structure for an opened window.
Definition window_gui.h:274
Definition of the game-calendar-timer.