OpenTTD Source 20250205-master-gfd85ab1e2c
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 HOUSE_H
11#define HOUSE_H
12
13#include "cargo_type.h"
15#include "house_type.h"
17#include "newgrf_callbacks.h"
18#include "newgrf_commons.h"
19
24static const uint8_t TOWN_HOUSE_COMPLETED = 3;
25
26static const uint HOUSE_NO_CLASS = 0;
27static const HouseID NEW_HOUSE_OFFSET = 110;
28static const HouseID NUM_HOUSES = 4096;
29static const HouseID INVALID_HOUSE_ID = UINT16_MAX;
30
32
33static const uint HOUSE_NUM_ACCEPTS = 16;
34static const uint HOUSE_ORIGINAL_NUM_ACCEPTS = 3;
35
36enum class BuildingFlag : uint8_t {
37 Size1x1 = 0,
38 NotSloped = 1,
39 Size2x1 = 2,
40 Size1x2 = 3,
41 Size2x2 = 4,
42 IsAnimated = 5,
43 IsChurch = 6,
44 IsStadium = 7,
45};
47
48static constexpr BuildingFlags BUILDING_HAS_1_TILE = {BuildingFlag::Size1x1, BuildingFlag::Size2x1, BuildingFlag::Size1x2, BuildingFlag::Size2x2};
49static constexpr BuildingFlags BUILDING_HAS_2_TILES = {BuildingFlag::Size2x1, BuildingFlag::Size1x2, BuildingFlag::Size2x2};
50static constexpr BuildingFlags BUILDING_2_TILES_X = {BuildingFlag::Size2x1, BuildingFlag::Size2x2};
51static constexpr BuildingFlags BUILDING_2_TILES_Y = {BuildingFlag::Size1x2, BuildingFlag::Size2x2};
52static constexpr BuildingFlags BUILDING_HAS_4_TILES = {BuildingFlag::Size2x2};
53
54enum HouseZonesBits : uint8_t {
55 HZB_BEGIN = 0,
56 HZB_TOWN_EDGE = 0,
57 HZB_TOWN_OUTSKIRT,
58 HZB_TOWN_OUTER_SUBURB,
59 HZB_TOWN_INNER_SUBURB,
60 HZB_TOWN_CENTRE,
61 HZB_END,
62};
63static_assert(HZB_END == 5);
64
66
67enum HouseZones : uint16_t {
68 HZ_NOZNS = 0x0000,
69 HZ_ZON1 = 1U << HZB_TOWN_EDGE,
70 HZ_ZON2 = 1U << HZB_TOWN_OUTSKIRT,
71 HZ_ZON3 = 1U << HZB_TOWN_OUTER_SUBURB,
72 HZ_ZON4 = 1U << HZB_TOWN_INNER_SUBURB,
73 HZ_ZON5 = 1U << HZB_TOWN_CENTRE,
74 HZ_ZONALL = 0x001F,
76 HZ_TEMP = 0x1000,
78 HZ_SUBTROPIC = 0x4000,
79 HZ_TOYLND = 0x8000,
80 HZ_CLIMALL = 0xF800,
81};
83
91
127
134{
135 const HouseSpec *hs = HouseSpec::Get(hid);
136 return hs->grf_prop.override == INVALID_HOUSE_ID ? hid : hs->grf_prop.override;
137}
138
139void ShowBuildHousePicker(struct Window *);
140
141#endif /* HOUSE_H */
Types related to cargoes...
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:22
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
Operators to allow to work with enum as with type safe bit set in C++.
Definition enum_type.hpp:68
#define DECLARE_INCREMENT_DECREMENT_OPERATORS(enum_type)
For some enums it is useful to have pre/post increment/decrement operators.
Definition enum_type.hpp:61
HouseExtraFlag
Definition house.h:84
@ SynchronisedCallback1B
synchronized callback 1B will be performed, on multi tile houses
@ Callback1ARandomBits
callback 1A needs random bits
@ BuildingIsHistorical
this house will only appear during town generation in random games, thus the historical
@ BuildingIsProtected
towns and AI will not remove this house, while human players will be able to
static const HouseID NUM_HOUSES
Total number of houses.
Definition house.h:28
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
Definition house.h:27
HouseID GetTranslatedHouseID(HouseID hid)
Do HouseID translation for NewGRFs.
Definition house.h:133
static const HouseID NUM_HOUSES_PER_GRF
Number of supported houses per NewGRF.
Definition house.h:31
static const uint HOUSE_NUM_ACCEPTS
Max number of cargoes accepted by a tile.
Definition house.h:33
static const uint8_t TOWN_HOUSE_COMPLETED
Simple value that indicates the house has reached the final stage of construction.
Definition house.h:24
static const uint HOUSE_ORIGINAL_NUM_ACCEPTS
Original number of accepted cargo types.
Definition house.h:34
HouseZones
Definition house.h:67
@ HZ_SUBARTC_BELOW
13 2000 can appear in sub-arctic climate below the snow line
Definition house.h:77
@ HZ_ZONALL
1F This is just to englobe all above types at once
Definition house.h:74
@ HZ_CLIMALL
Bitmask of all climate bits.
Definition house.h:80
@ HZ_TEMP
12 1000 can appear in temperate climate
Definition house.h:76
@ HZ_TOYLND
15 8000 can appear in toyland climate
Definition house.h:79
@ HZ_ZON5
center of town
Definition house.h:73
@ HZ_SUBTROPIC
14 4000 can appear in subtropical climate
Definition house.h:78
@ HZ_SUBARTC_ABOVE
11 800 can appear in sub-arctic climate above the snow line
Definition house.h:75
@ HZ_ZON1
0..4 1,2,4,8,10 which town zones the building can be built in, Zone1 been the further suburb
Definition house.h:69
@ HZ_NOZNS
0 This is just to get rid of zeros, meaning none
Definition house.h:68
declaration of basic house types and enums
uint16_t HouseClassID
Classes of houses.
Definition house_type.h:14
uint16_t HouseID
OpenTTD ID of house types.
Definition house_type.h:13
Definitions related to NewGRF animation.
Callbacks that NewGRFs could implement.
This file simplyfies 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.
Data related to the handling of grf files.
uint16_t override
id of the entity been replaced by
CargoType accepts_cargo[HOUSE_NUM_ACCEPTS]
input cargo slots
Definition house.h:102
uint8_t probability
Relative probability of appearing (16 is the standard value)
Definition house.h:111
CargoTypes watched_cargoes
Cargo types watched for acceptance.
Definition house.h:117
uint8_t removal_cost
cost multiplier for removing it
Definition house.h:97
uint8_t mail_generation
mail generation multiplier (tile based, as the acceptances below)
Definition house.h:100
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
Definition house.h:105
CargoLabel accepts_cargo_label[HOUSE_ORIGINAL_NUM_ACCEPTS]
input landscape cargo slots
Definition house.h:119
Money GetRemovalCost() const
Get the cost for removing this house.
Definition town_cmd.cpp:225
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:103
AnimationInfo animation
information about the animation.
Definition house.h:114
TimerGameCalendar::Year max_year
last year it can be built
Definition house.h:95
uint8_t processing_time
Periodic refresh multiplier.
Definition house.h:115
HouseCallbackMasks callback_mask
Bitmask of house callbacks that have to be called.
Definition house.h:109
uint16_t remove_rating_decrease
rating decrease if removed
Definition house.h:99
uint8_t population
population (Zero on other tiles in multi tile house.)
Definition house.h:96
HouseExtraFlags extra_flags
some more flags
Definition house.h:112
uint8_t cargo_acceptance[HOUSE_NUM_ACCEPTS]
acceptance level for the cargo slots
Definition house.h:101
TimerGameCalendar::Year min_year
introduction year of the house
Definition house.h:94
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:113
StringID building_name
building name
Definition house.h:98
uint8_t minimum_life
The minimum number of years this house will survive before the town rebuilds it.
Definition house.h:116
GRFFileProps grf_prop
Properties related the the grf file.
Definition house.h:108
Colours random_colour[4]
4 "random" colours
Definition house.h:110
HouseZones building_availability
where can it be built (climates, zones)
Definition house.h:104
static std::vector< HouseSpec > & Specs()
Get a reference to all HouseSpecs.
Templated helper to make a type-safe 'typedef' representing a single POD value.
Data structure for an opened window.
Definition window_gui.h:272
Definition of the game-calendar-timer.