OpenTTD Source: src/house.h Source File

OpenTTD Source 15.0-beta1

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"
14#include "timer/timer_game_calendar.h"
15#include "house_type.h"
16#include "newgrf_animation_type.h"
17#include "newgrf_commons.h"
18
23 static const uint8_t TOWN_HOUSE_COMPLETED = 3;
24
25static const uint HOUSE_NO_CLASS = 0;
26 static const HouseID NEW_HOUSE_OFFSET = 110;
27 static const HouseID NUM_HOUSES = 4096;
28static const HouseID INVALID_HOUSE_ID = UINT16_MAX;
29
30 static const HouseID NUM_HOUSES_PER_GRF = NUM_HOUSES;
31
32 static const uint HOUSE_NUM_ACCEPTS = 16;
33 static const uint HOUSE_ORIGINAL_NUM_ACCEPTS = 3;
34
35enum BuildingFlags : uint8_t {
36 TILE_NO_FLAG = 0,
37 TILE_SIZE_1x1 = 1U << 0,
38 TILE_NOT_SLOPED = 1U << 1,
39 TILE_SIZE_2x1 = 1U << 2,
40 TILE_SIZE_1x2 = 1U << 3,
41 TILE_SIZE_2x2 = 1U << 4,
42 BUILDING_IS_ANIMATED = 1U << 5,
43 BUILDING_IS_CHURCH = 1U << 6,
44 BUILDING_IS_STADIUM = 1U << 7,
45 BUILDING_HAS_1_TILE = TILE_SIZE_1x1 | TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
46 BUILDING_HAS_2_TILES = TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
47 BUILDING_2_TILES_X = TILE_SIZE_2x1 | TILE_SIZE_2x2,
48 BUILDING_2_TILES_Y = TILE_SIZE_1x2 | TILE_SIZE_2x2,
49 BUILDING_HAS_4_TILES = TILE_SIZE_2x2,
50};
51 DECLARE_ENUM_AS_BIT_SET(BuildingFlags)
52
53enum HouseZonesBits : uint8_t {
54 HZB_BEGIN = 0,
55 HZB_TOWN_EDGE = 0,
56 HZB_TOWN_OUTSKIRT,
57 HZB_TOWN_OUTER_SUBURB,
58 HZB_TOWN_INNER_SUBURB,
59 HZB_TOWN_CENTRE,
60 HZB_END,
61};
62static_assert(HZB_END == 5);
63
64 DECLARE_POSTFIX_INCREMENT(HouseZonesBits)
65
66enum HouseZones : uint16_t {
67 HZ_NOZNS = 0x0000,
68 HZ_ZON1 = 1U << HZB_TOWN_EDGE,
69 HZ_ZON2 = 1U << HZB_TOWN_OUTSKIRT,
70 HZ_ZON3 = 1U << HZB_TOWN_OUTER_SUBURB,
71 HZ_ZON4 = 1U << HZB_TOWN_INNER_SUBURB,
72 HZ_ZON5 = 1U << HZB_TOWN_CENTRE,
73 HZ_ZONALL = 0x001F,
74 HZ_SUBARTC_ABOVE = 0x0800,
75 HZ_TEMP = 0x1000,
76 HZ_SUBARTC_BELOW = 0x2000,
77 HZ_SUBTROPIC = 0x4000,
78 HZ_TOYLND = 0x8000,
79 HZ_CLIMALL = 0xF800,
80};
81 DECLARE_ENUM_AS_BIT_SET(HouseZones)
82
83enum HouseExtraFlags : uint8_t {
84 NO_EXTRA_FLAG = 0,
85 BUILDING_IS_HISTORICAL = 1U << 0,
86 BUILDING_IS_PROTECTED = 1U << 1,
87 SYNCHRONISED_CALLBACK_1B = 1U << 2,
88 CALLBACK_1A_RANDOM_BITS = 1U << 3,
89};
90
91 DECLARE_ENUM_AS_BIT_SET(HouseExtraFlags)
92
93struct HouseSpec {
94 /* Standard properties */
95 TimerGameCalendar::Year min_year;
96 TimerGameCalendar::Year max_year;
97 uint8_t population;
98 uint8_t removal_cost;
99 StringID building_name;
100 uint16_t remove_rating_decrease;
101 uint8_t mail_generation;
102 uint8_t cargo_acceptance[HOUSE_NUM_ACCEPTS];
103 CargoID accepts_cargo[HOUSE_NUM_ACCEPTS];
104 BuildingFlags building_flags;
105 HouseZones building_availability;
106 bool enabled;
107
108 /* NewHouses properties */
109 GRFFileProps grf_prop;
110 uint16_t callback_mask;
111 Colours random_colour[4];
112 uint8_t probability;
113 HouseExtraFlags extra_flags;
114 HouseClassID class_id;
115 AnimationInfo animation;
116 uint8_t processing_time;
117 uint8_t minimum_life;
118 CargoTypes watched_cargoes;
119
120 CargoLabel accepts_cargo_label[HOUSE_ORIGINAL_NUM_ACCEPTS];
121
122 HouseID Index() const;
123 Money GetRemovalCost() const;
124
125 static std::vector<HouseSpec> &Specs();
126 static HouseSpec *Get(size_t house_id);
127};
128
134 inline HouseID GetTranslatedHouseID(HouseID hid)
135{
136 const HouseSpec *hs = HouseSpec::Get(hid);
137 return hs->grf_prop.override == INVALID_HOUSE_ID ? hid : hs->grf_prop.override;
138}
139
140void ShowBuildHousePicker(struct Window *);
141
142#endif /* HOUSE_H */
cargo_type.h
Types related to cargoes...
CargoID
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:22
OverflowSafeInt< int64_t >
DECLARE_ENUM_AS_BIT_SET
#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:35
DECLARE_POSTFIX_INCREMENT
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
Definition enum_type.hpp:18
NUM_HOUSES
static const HouseID NUM_HOUSES
Total number of houses.
Definition house.h:27
NEW_HOUSE_OFFSET
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
Definition house.h:26
GetTranslatedHouseID
HouseID GetTranslatedHouseID(HouseID hid)
Do HouseID translation for NewGRFs.
Definition house.h:134
NUM_HOUSES_PER_GRF
static const HouseID NUM_HOUSES_PER_GRF
Number of supported houses per NewGRF.
Definition house.h:30
HOUSE_NUM_ACCEPTS
static const uint HOUSE_NUM_ACCEPTS
Max number of cargoes accepted by a tile.
Definition house.h:32
TOWN_HOUSE_COMPLETED
static const uint8_t TOWN_HOUSE_COMPLETED
Simple value that indicates the house has reached the final stage of construction.
Definition house.h:23
HOUSE_ORIGINAL_NUM_ACCEPTS
static const uint HOUSE_ORIGINAL_NUM_ACCEPTS
Original number of accepted cargo types.
Definition house.h:33
HouseZones
HouseZones
Definition house.h:66
HZ_SUBARTC_BELOW
@ HZ_SUBARTC_BELOW
13 2000 can appear in sub-arctic climate below the snow line
Definition house.h:76
HZ_ZONALL
@ HZ_ZONALL
1F This is just to englobe all above types at once
Definition house.h:73
HZ_CLIMALL
@ HZ_CLIMALL
Bitmask of all climate bits.
Definition house.h:79
HZ_TEMP
@ HZ_TEMP
12 1000 can appear in temperate climate
Definition house.h:75
HZ_TOYLND
@ HZ_TOYLND
15 8000 can appear in toyland climate
Definition house.h:78
HZ_ZON5
@ HZ_ZON5
center of town
Definition house.h:72
HZ_SUBTROPIC
@ HZ_SUBTROPIC
14 4000 can appear in subtropical climate
Definition house.h:77
HZ_SUBARTC_ABOVE
@ HZ_SUBARTC_ABOVE
11 800 can appear in sub-arctic climate above the snow line
Definition house.h:74
HZ_ZON1
@ 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:68
HZ_NOZNS
@ HZ_NOZNS
0 This is just to get rid of zeros, meaning none
Definition house.h:67
HouseExtraFlags
HouseExtraFlags
Definition house.h:83
BUILDING_IS_HISTORICAL
@ BUILDING_IS_HISTORICAL
this house will only appear during town generation in random games, thus the historical
Definition house.h:85
BUILDING_IS_PROTECTED
@ BUILDING_IS_PROTECTED
towns and AI will not remove this house, while human players will be able to
Definition house.h:86
SYNCHRONISED_CALLBACK_1B
@ SYNCHRONISED_CALLBACK_1B
synchronized callback 1B will be performed, on multi tile houses
Definition house.h:87
CALLBACK_1A_RANDOM_BITS
@ CALLBACK_1A_RANDOM_BITS
callback 1A needs random bits
Definition house.h:88
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
newgrf_animation_type.h
Definitions related to NewGRF animation.
newgrf_commons.h
This file simplyfies and embeds a common mechanism of loading/saving and mapping of grf entities.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:16
AnimationInfo
Information about animation.
Definition newgrf_animation_type.h:18
GRFFileProps
Data related to the handling of grf files.
Definition newgrf_commons.h:324
GRFFileProps::override
uint16_t override
id of the entity been replaced by
Definition newgrf_commons.h:329
HouseSpec
Definition house.h:93
HouseSpec::probability
uint8_t probability
Relative probability of appearing (16 is the standard value)
Definition house.h:112
HouseSpec::watched_cargoes
CargoTypes watched_cargoes
Cargo types watched for acceptance.
Definition house.h:118
HouseSpec::removal_cost
uint8_t removal_cost
cost multiplier for removing it
Definition house.h:98
HouseSpec::mail_generation
uint8_t mail_generation
mail generation multiplier (tile based, as the acceptances below)
Definition house.h:101
HouseSpec::enabled
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
Definition house.h:106
HouseSpec::Get
static HouseSpec * Get(size_t house_id)
Get the spec for a house ID.
Definition newgrf_house.cpp:69
HouseSpec::building_flags
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
Definition house.h:104
HouseSpec::animation
AnimationInfo animation
information about the animation.
Definition house.h:115
HouseSpec::max_year
TimerGameCalendar::Year max_year
last year it can be built
Definition house.h:96
HouseSpec::processing_time
uint8_t processing_time
Periodic refresh multiplier.
Definition house.h:116
HouseSpec::remove_rating_decrease
uint16_t remove_rating_decrease
rating decrease if removed
Definition house.h:100
HouseSpec::population
uint8_t population
population (Zero on other tiles in multi tile house.)
Definition house.h:97
HouseSpec::extra_flags
HouseExtraFlags extra_flags
some more flags
Definition house.h:113
HouseSpec::min_year
TimerGameCalendar::Year min_year
introduction year of the house
Definition house.h:95
HouseSpec::class_id
HouseClassID class_id
defines the class this house has (not grf file based)
Definition house.h:114
HouseSpec::building_name
StringID building_name
building name
Definition house.h:99
HouseSpec::minimum_life
uint8_t minimum_life
The minimum number of years this house will survive before the town rebuilds it.
Definition house.h:117
HouseSpec::grf_prop
GRFFileProps grf_prop
Properties related the the grf file.
Definition house.h:109
HouseSpec::callback_mask
uint16_t callback_mask
Bitmask of house callbacks that have to be called.
Definition house.h:110
HouseSpec::building_availability
HouseZones building_availability
where can it be built (climates, zones)
Definition house.h:105
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:150
Window
Data structure for an opened window.
Definition window_gui.h:273
timer_game_calendar.h
Definition of the game-calendar-timer.