OpenTTD

house.h
Go to the documentation of this file.
1 /* $Id: house.h 25839 2013-10-12 16:34:04Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef HOUSE_H
13 #define HOUSE_H
14
15 #include "cargo_type.h"
16 #include "date_type.h"
17 #include "house_type.h"
18 #include "newgrf_animation_type.h"
19 #include "newgrf_commons.h"
20
25 static const byte TOWN_HOUSE_COMPLETED = 3;
26
27 static const HouseID NUM_HOUSES_PER_GRF = 255;
28
29 static const uint HOUSE_NO_CLASS = 0;
30 static const HouseID NEW_HOUSE_OFFSET = 110;
31 static const HouseID NUM_HOUSES = 512;
32 static const HouseID INVALID_HOUSE_ID = 0xFFFF;
33
38 static const uint HOUSE_CLASS_MAX = NUM_HOUSES - NEW_HOUSE_OFFSET + 1;
39
40 enum BuildingFlags {
41 TILE_NO_FLAG = 0,
42 TILE_SIZE_1x1 = 1U << 0,
43 TILE_NOT_SLOPED = 1U << 1,
44 TILE_SIZE_2x1 = 1U << 2,
45 TILE_SIZE_1x2 = 1U << 3,
46 TILE_SIZE_2x2 = 1U << 4,
47 BUILDING_IS_ANIMATED = 1U << 5,
48 BUILDING_IS_CHURCH = 1U << 6,
49 BUILDING_IS_STADIUM = 1U << 7,
50 BUILDING_HAS_1_TILE = TILE_SIZE_1x1 | TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
51 BUILDING_HAS_2_TILES = TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
52 BUILDING_2_TILES_X = TILE_SIZE_2x1 | TILE_SIZE_2x2,
53 BUILDING_2_TILES_Y = TILE_SIZE_1x2 | TILE_SIZE_2x2,
54 BUILDING_HAS_4_TILES = TILE_SIZE_2x2,
55 };
56 DECLARE_ENUM_AS_BIT_SET(BuildingFlags)
57
58 enum HouseZonesBits {
59 HZB_BEGIN = 0,
60 HZB_TOWN_EDGE = 0,
61 HZB_TOWN_OUTSKIRT,
62 HZB_TOWN_OUTER_SUBURB,
63 HZB_TOWN_INNER_SUBURB,
64 HZB_TOWN_CENTRE,
65 HZB_END,
66 };
67 assert_compile(HZB_END == 5);
68
69 DECLARE_POSTFIX_INCREMENT(HouseZonesBits)
70
71 enum HouseZones {
72 HZ_NOZNS = 0x0000,
73 HZ_ZON1 = 1U << HZB_TOWN_EDGE,
74 HZ_ZON2 = 1U << HZB_TOWN_OUTSKIRT,
75 HZ_ZON3 = 1U << HZB_TOWN_OUTER_SUBURB,
76 HZ_ZON4 = 1U << HZB_TOWN_INNER_SUBURB,
77 HZ_ZON5 = 1U << HZB_TOWN_CENTRE,
78 HZ_ZONALL = 0x001F,
79 HZ_SUBARTC_ABOVE = 0x0800,
80 HZ_TEMP = 0x1000,
81 HZ_SUBARTC_BELOW = 0x2000,
82 HZ_SUBTROPIC = 0x4000,
83 HZ_TOYLND = 0x8000,
84 HZ_CLIMALL = 0xF800,
85 };
86 DECLARE_ENUM_AS_BIT_SET(HouseZones)
87
88 enum HouseExtraFlags {
89 NO_EXTRA_FLAG = 0,
90 BUILDING_IS_HISTORICAL = 1U << 0,
91 BUILDING_IS_PROTECTED = 1U << 1,
92 SYNCHRONISED_CALLBACK_1B = 1U << 2,
93 CALLBACK_1A_RANDOM_BITS = 1U << 3,
94 };
95
96 DECLARE_ENUM_AS_BIT_SET(HouseExtraFlags)
97
98 struct HouseSpec {
99 /* Standard properties */
100 Year min_year;
101 Year max_year;
102 byte population;
103 byte removal_cost;
104 StringID building_name;
105 uint16 remove_rating_decrease;
106 byte mail_generation;
107 byte cargo_acceptance[3];
108 CargoID accepts_cargo[3];
109 BuildingFlags building_flags;
110 HouseZones building_availability;
111 bool enabled;
112
113 /* NewHouses properties */
114 GRFFileProps grf_prop;
115 uint16 callback_mask;
116 byte random_colour[4];
117 byte probability;
118 HouseExtraFlags extra_flags;
119 HouseClassID class_id;
120 AnimationInfo animation;
121 byte processing_time;
122 byte minimum_life;
123 uint32 watched_cargoes;
124
125 Money GetRemovalCost() const;
126
127 static inline HouseSpec *Get(size_t house_id)
128 {
129 assert(house_id < NUM_HOUSES);
130 extern HouseSpec _house_specs[];
131 return &_house_specs[house_id];
132 }
133 };
134
140 static inline HouseID GetTranslatedHouseID(HouseID hid)
141 {
142 const HouseSpec *hs = HouseSpec::Get(hid);
143 return hs->grf_prop.override == INVALID_HOUSE_ID ? hid : hs->grf_prop.override;
144 }
145
146 #endif /* HOUSE_H */
HouseSpec::enabled
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
Definition: house.h:111
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:31
HouseSpec::probability
byte probability
Relative probability of appearing (16 is the standard value)
Definition: house.h:117
HZ_NOZNS
Bit Value Meaning.
Definition: house.h:72
TOWN_HOUSE_COMPLETED
static const byte TOWN_HOUSE_COMPLETED
Simple value that indicates the house has reached the final stage of construction.
Definition: house.h:25
SYNCHRONISED_CALLBACK_1B
synchronized callback 1B will be performed, on multi tile houses
Definition: house.h:92
house_type.h
declaration of basic house types and enums
HouseClassID
uint16 HouseClassID
Classes of houses.
Definition: house_type.h:16
newgrf_animation_type.h
Definitions related to NewGRF animation.
HouseSpec::removal_cost
byte removal_cost
cost multiplier for removing it
Definition: house.h:103
GetTranslatedHouseID
static HouseID GetTranslatedHouseID(HouseID hid)
Do HouseID translation for NewGRFs.
Definition: house.h:140
Year
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:20
HouseSpec::callback_mask
uint16 callback_mask
Bitmask of house callbacks that have to be called.
Definition: house.h:115
HouseID
uint16 HouseID
OpenTTD ID of house types.
Definition: house_type.h:15
cargo_type.h
Types related to cargoes...
NUM_HOUSES
static const HouseID NUM_HOUSES
Total number of houses.
Definition: house.h:31
HouseZones
HouseZones
Definition: house.h:71
BUILDING_IS_HISTORICAL
this house will only appear during town generation in random games, thus the historical ...
Definition: house.h:90
HouseSpec::building_availability
HouseZones building_availability
where can it be built (climates, zones)
Definition: house.h:110
HouseSpec::population
byte population
population (Zero on other tiles in multi tile house.)
Definition: house.h:102
NUM_HOUSES_PER_GRF
static const HouseID NUM_HOUSES_PER_GRF
Number of supported houses per NewGRF; limited to 255 to allow extending Action3 with an extended byt...
Definition: house.h:27
HouseSpec::mail_generation
byte mail_generation
mail generation multiplier (tile based, as the acceptances below)
Definition: house.h:106
HouseSpec::class_id
HouseClassID class_id
defines the class this house has (not grf file based)
Definition: house.h:119
GRFFileProps
Data related to the handling of grf files.
Definition: newgrf_commons.h:325
HouseSpec::processing_time
byte processing_time
Periodic refresh multiplier.
Definition: house.h:121
HouseSpec::building_name
StringID building_name
building name
Definition: house.h:104
HouseSpec::max_year
Year max_year
last year it can be built
Definition: house.h:101
HZ_CLIMALL
Bitmask of all climate bits.
Definition: house.h:84
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
HZ_TEMP
12 1000 can appear in temperate climate
Definition: house.h:80
HouseSpec::building_flags
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
Definition: house.h:109
HouseSpec::watched_cargoes
uint32 watched_cargoes
Cargo types watched for acceptance.
Definition: house.h:123
GRFFileProps::override
uint16 override
id of the entity been replaced by
Definition: newgrf_commons.h:333
HouseExtraFlags
HouseExtraFlags
Definition: house.h:88
HZ_SUBTROPIC
14 4000 can appear in subtropical climate
Definition: house.h:82
HZ_SUBARTC_BELOW
13 2000 can appear in sub-arctic climate below the snow line
Definition: house.h:81
HouseSpec
Definition: house.h:98
HZ_ZONALL
1F This is just to englobe all above types at once
Definition: house.h:78
HZ_TOYLND
15 8000 can appear in toyland climate
Definition: house.h:83
HouseSpec::extra_flags
HouseExtraFlags extra_flags
some more flags
Definition: house.h:118
HouseSpec::minimum_life
byte minimum_life
The minimum number of years this house will survive before the town rebuilds it.
Definition: house.h:122
HOUSE_CLASS_MAX
static const uint HOUSE_CLASS_MAX
There can only be as many classes as there are new houses, plus one for NO_CLASS, as the original hou...
Definition: house.h:38
HouseSpec::remove_rating_decrease
uint16 remove_rating_decrease
rating decrease if removed
Definition: house.h:105
HouseSpec::min_year
Year min_year
introduction year of the house
Definition: house.h:100
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:73
BUILDING_IS_PROTECTED
towns and AI will not remove this house, while human players will be able to
Definition: house.h:91
CALLBACK_1A_RANDOM_BITS
callback 1A needs random bits
Definition: house.h:93
NEW_HOUSE_OFFSET
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
Definition: house.h:30
HouseSpec::animation
AnimationInfo animation
information about the animation.
Definition: house.h:120
date_type.h
Types related to the dates in OpenTTD.
newgrf_commons.h
This file simplyfies and embeds a common mechanism of loading/saving and mapping of grf entities...
AnimationInfo
Information about animation.
Definition: newgrf_animation_type.h:20
HouseSpec::grf_prop
GRFFileProps grf_prop
Properties related the the grf file.
Definition: house.h:114
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
DECLARE_POSTFIX_INCREMENT
#define DECLARE_POSTFIX_INCREMENT(type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:16
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
HZ_ZON5
center of town
Definition: house.h:77
HZ_SUBARTC_ABOVE
11 800 can appear in sub-arctic climate above the snow line
Definition: house.h:79