OpenTTD Source: src/house.h Source File

OpenTTD Source 15.0-RC2

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
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_badge_type.h"
18#include "newgrf_callbacks.h"
19#include "newgrf_commons.h"
20
25 static const uint8_t TOWN_HOUSE_COMPLETED = 3;
26
27static const uint HOUSE_NO_CLASS = 0;
28 static const HouseID NEW_HOUSE_OFFSET = 110;
29 static const HouseID NUM_HOUSES = 4096;
30static const HouseID INVALID_HOUSE_ID = UINT16_MAX;
31
32 static const HouseID NUM_HOUSES_PER_GRF = NUM_HOUSES;
33
34 static const uint HOUSE_NUM_ACCEPTS = 16;
35 static const uint HOUSE_ORIGINAL_NUM_ACCEPTS = 3;
36
37enum class BuildingFlag : uint8_t {
38 Size1x1 = 0,
39 NotSloped = 1,
40 Size2x1 = 2,
41 Size1x2 = 3,
42 Size2x2 = 4,
43 IsAnimated = 5,
44 IsChurch = 6,
45 IsStadium = 7,
46};
47using BuildingFlags = EnumBitSet<BuildingFlag, uint8_t>;
48
49static constexpr BuildingFlags BUILDING_HAS_1_TILE = {BuildingFlag::Size1x1, BuildingFlag::Size2x1, BuildingFlag::Size1x2, BuildingFlag::Size2x2};
50static constexpr BuildingFlags BUILDING_HAS_2_TILES = {BuildingFlag::Size2x1, BuildingFlag::Size1x2, BuildingFlag::Size2x2};
51static constexpr BuildingFlags BUILDING_2_TILES_X = {BuildingFlag::Size2x1, BuildingFlag::Size2x2};
52static constexpr BuildingFlags BUILDING_2_TILES_Y = {BuildingFlag::Size1x2, BuildingFlag::Size2x2};
53static constexpr BuildingFlags BUILDING_HAS_4_TILES = {BuildingFlag::Size2x2};
54
55 enum class HouseZone : uint8_t {
56 TownEdge = 0,
57 TownOutskirt = 1,
58 TownOuterSuburb = 2,
59 TownInnerSuburb = 3,
60 TownCentre = 4,
61 TownEnd,
62
63 ClimateSubarcticAboveSnow = 11,
64 ClimateTemperate = 12,
65 ClimateSubarcticBelowSnow = 13,
66 ClimateSubtropic = 14,
67 ClimateToyland = 15,
68};
69using HouseZones = EnumBitSet<HouseZone, uint16_t>;
70
71static constexpr uint NUM_HOUSE_ZONES = to_underlying(HouseZone::TownEnd);
72static_assert(NUM_HOUSE_ZONES == 5);
73
74static constexpr HouseZones HZ_ZONE_ALL = {
75 HouseZone::TownEdge,
76 HouseZone::TownOutskirt,
77 HouseZone::TownOuterSuburb,
78 HouseZone::TownInnerSuburb,
79 HouseZone::TownCentre,
80};
81
82static constexpr HouseZones HZ_CLIMATE_ALL = {
83 HouseZone::ClimateSubarcticAboveSnow,
84 HouseZone::ClimateTemperate,
85 HouseZone::ClimateSubarcticBelowSnow,
86 HouseZone::ClimateSubtropic,
87 HouseZone::ClimateToyland,
88};
89
90 enum class HouseExtraFlag : uint8_t {
91 BuildingIsHistorical = 0,
92 BuildingIsProtected = 1,
93 SynchronisedCallback1B = 2,
94 Callback1ARandomBits = 3,
95};
96using HouseExtraFlags = EnumBitSet<HouseExtraFlag, uint8_t>;
97
98 struct HouseSpec {
99 /* Standard properties */
100 TimerGameCalendar::Year min_year;
101 TimerGameCalendar::Year max_year;
102 uint8_t population;
103 uint8_t removal_cost;
104 StringID building_name;
105 uint16_t remove_rating_decrease;
106 uint8_t mail_generation;
107 uint8_t cargo_acceptance[HOUSE_NUM_ACCEPTS];
108 CargoType accepts_cargo[HOUSE_NUM_ACCEPTS];
109 BuildingFlags building_flags;
110 HouseZones building_availability;
111 bool enabled;
112
113 /* NewHouses properties */
114 SubstituteGRFFileProps grf_prop;
115 HouseCallbackMasks callback_mask;
116 Colours random_colour[4];
117 uint8_t probability;
118 HouseExtraFlags extra_flags{};
119 HouseClassID class_id;
120 AnimationInfo<void> animation;
121 uint8_t processing_time;
122 uint8_t minimum_life;
123 CargoTypes watched_cargoes;
124 std::vector<BadgeID> badges;
125
126 CargoLabel accepts_cargo_label[HOUSE_ORIGINAL_NUM_ACCEPTS];
127
128 HouseID Index() const;
129 Money GetRemovalCost() const;
130
131 static std::vector<HouseSpec> &Specs();
132 static HouseSpec *Get(size_t house_id);
133};
134
140 inline HouseID GetTranslatedHouseID(HouseID hid)
141{
142 const HouseSpec *hs = HouseSpec::Get(hid);
143 return hs->grf_prop.override_id == INVALID_HOUSE_ID ? hid : hs->grf_prop.override_id;
144}
145
146void ShowBuildHousePicker(struct Window *);
147 HouseZones GetClimateMaskForLandscape();
148
149#endif /* HOUSE_H */
cargo_type.h
Types related to cargoes...
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
EnumBitSet< BuildingFlag, uint8_t >
OverflowSafeInt< int64_t >
to_underlying
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
HouseExtraFlag
Definition house.h:90
HouseExtraFlag::SynchronisedCallback1B
@ SynchronisedCallback1B
synchronized callback 1B will be performed, on multi tile houses
HouseExtraFlag::Callback1ARandomBits
@ Callback1ARandomBits
callback 1A needs random bits
HouseExtraFlag::BuildingIsHistorical
@ BuildingIsHistorical
this house will only appear during town generation in random games, thus the historical
HouseExtraFlag::BuildingIsProtected
@ BuildingIsProtected
towns and AI will not remove this house, while human players will be able to
GetClimateMaskForLandscape
HouseZones GetClimateMaskForLandscape()
Get the HouseZones climate mask for the current landscape type.
Definition town_cmd.cpp:2357
NUM_HOUSES
static const HouseID NUM_HOUSES
Total number of houses.
Definition house.h:29
NEW_HOUSE_OFFSET
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
Definition house.h:28
GetTranslatedHouseID
HouseID GetTranslatedHouseID(HouseID hid)
Do HouseID translation for NewGRFs.
Definition house.h:140
NUM_HOUSES_PER_GRF
static const HouseID NUM_HOUSES_PER_GRF
Number of supported houses per NewGRF.
Definition house.h:32
HOUSE_NUM_ACCEPTS
static const uint HOUSE_NUM_ACCEPTS
Max number of cargoes accepted by a tile.
Definition house.h:34
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:25
HOUSE_ORIGINAL_NUM_ACCEPTS
static const uint HOUSE_ORIGINAL_NUM_ACCEPTS
Original number of accepted cargo types.
Definition house.h:35
HouseZone
HouseZone
Definition house.h:55
HouseZone::ClimateSubarcticAboveSnow
@ ClimateSubarcticAboveSnow
Building can appear in sub-arctic climate above the snow line.
HouseZone::ClimateSubarcticBelowSnow
@ ClimateSubarcticBelowSnow
Building can appear in sub-arctic climate below the snow line.
HouseZone::ClimateTemperate
@ ClimateTemperate
Building can appear in temperate climate.
HouseZone::ClimateToyland
@ ClimateToyland
Building can appear in toyland climate.
HouseZone::ClimateSubtropic
@ ClimateSubtropic
Building can appear in subtropical climate.
house_type.h
declaration of basic house types and enums
HouseClassID
uint16_t HouseClassID
Classes of houses.
Definition house_type.h:16
HouseID
uint16_t HouseID
OpenTTD ID of house types.
Definition house_type.h:15
newgrf_animation_type.h
Definitions related to NewGRF animation.
newgrf_badge_type.h
Types related to NewGRF badges.
newgrf_callbacks.h
Callbacks that NewGRFs could implement.
newgrf_commons.h
This file simplifies 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:19
AnimationInfo
Information about animation.
Definition newgrf_animation_type.h:21
HouseSpec
Definition house.h:98
HouseSpec::accepts_cargo
CargoType accepts_cargo[HOUSE_NUM_ACCEPTS]
input cargo slots
Definition house.h:108
HouseSpec::grf_prop
SubstituteGRFFileProps grf_prop
Properties related the the grf file.
Definition house.h:114
HouseSpec::probability
uint8_t probability
Relative probability of appearing (16 is the standard value)
Definition house.h:117
HouseSpec::watched_cargoes
CargoTypes watched_cargoes
Cargo types watched for acceptance.
Definition house.h:123
HouseSpec::removal_cost
uint8_t removal_cost
cost multiplier for removing it
Definition house.h:103
HouseSpec::mail_generation
uint8_t mail_generation
mail generation multiplier (tile based, as the acceptances below)
Definition house.h:106
HouseSpec::enabled
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
Definition house.h:111
HouseSpec::accepts_cargo_label
CargoLabel accepts_cargo_label[HOUSE_ORIGINAL_NUM_ACCEPTS]
input landscape cargo slots
Definition house.h:126
HouseSpec::GetRemovalCost
Money GetRemovalCost() const
Get the cost for removing this house.
Definition town_cmd.cpp:232
HouseSpec::Get
static HouseSpec * Get(size_t house_id)
Get the spec for a house ID.
Definition newgrf_house.cpp:70
HouseSpec::building_flags
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
Definition house.h:109
HouseSpec::max_year
TimerGameCalendar::Year max_year
last year it can be built
Definition house.h:101
HouseSpec::processing_time
uint8_t processing_time
Periodic refresh multiplier.
Definition house.h:121
HouseSpec::callback_mask
HouseCallbackMasks callback_mask
Bitmask of house callbacks that have to be called.
Definition house.h:115
HouseSpec::remove_rating_decrease
uint16_t remove_rating_decrease
rating decrease if removed
Definition house.h:105
HouseSpec::population
uint8_t population
population (Zero on other tiles in multi tile house.)
Definition house.h:102
HouseSpec::extra_flags
HouseExtraFlags extra_flags
some more flags
Definition house.h:118
HouseSpec::cargo_acceptance
uint8_t cargo_acceptance[HOUSE_NUM_ACCEPTS]
acceptance level for the cargo slots
Definition house.h:107
HouseSpec::min_year
TimerGameCalendar::Year min_year
introduction year of the house
Definition house.h:100
HouseSpec::Index
HouseID Index() const
Gets the index of this spec.
Definition newgrf_house.cpp:60
HouseSpec::class_id
HouseClassID class_id
defines the class this house has (not grf file based)
Definition house.h:119
HouseSpec::animation
AnimationInfo< void > animation
information about the animation.
Definition house.h:120
HouseSpec::building_name
StringID building_name
building name
Definition house.h:104
HouseSpec::minimum_life
uint8_t minimum_life
The minimum number of years this house will survive before the town rebuilds it.
Definition house.h:122
HouseSpec::random_colour
Colours random_colour[4]
4 "random" colours
Definition house.h:116
HouseSpec::building_availability
HouseZones building_availability
where can it be built (climates, zones)
Definition house.h:110
HouseSpec::Specs
static std::vector< HouseSpec > & Specs()
Get a reference to all HouseSpecs.
Definition newgrf_house.cpp:51
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:130
SubstituteGRFFileProps
NewGRF entities which can replace default entities.
Definition newgrf_commons.h:464
SubstituteGRFFileProps::override_id
uint16_t override_id
id of the entity been replaced by
Definition newgrf_commons.h:469
Window
Data structure for an opened window.
Definition window_gui.h:274
timer_game_calendar.h
Definition of the game-calendar-timer.