Fix #10490: Allow ships to exit depots if another is not moving at the exit point...
[openttd-github.git] / src / house.h
blobc3308ea59bc54ab1175171b9dac947638947d53c
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 */
8 /** @file house.h definition of HouseSpec and accessors */
10 #ifndef HOUSE_H
11 #define HOUSE_H
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"
19 /**
20 * Simple value that indicates the house has reached the final stage of
21 * construction.
23 static const byte TOWN_HOUSE_COMPLETED = 3;
25 static const HouseID NUM_HOUSES_PER_GRF = 255; ///< Number of supported houses per NewGRF; limited to 255 to allow extending Action3 with an extended byte later on.
27 static const uint HOUSE_NO_CLASS = 0;
28 static const HouseID NEW_HOUSE_OFFSET = 110; ///< Offset for new houses.
29 static const HouseID NUM_HOUSES = 512; ///< Total number of houses.
30 static const HouseID INVALID_HOUSE_ID = 0xFFFF;
32 static const uint HOUSE_NUM_ACCEPTS = 16; ///< Max number of cargoes accepted by a tile
34 /**
35 * There can only be as many classes as there are new houses, plus one for
36 * NO_CLASS, as the original houses don't have classes.
38 static const uint HOUSE_CLASS_MAX = NUM_HOUSES - NEW_HOUSE_OFFSET + 1;
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,
56 DECLARE_ENUM_AS_BIT_SET(BuildingFlags)
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,
67 static_assert(HZB_END == 5);
69 DECLARE_POSTFIX_INCREMENT(HouseZonesBits)
71 enum HouseZones { ///< Bit Value Meaning
72 HZ_NOZNS = 0x0000, ///< 0 This is just to get rid of zeros, meaning none
73 HZ_ZON1 = 1U << HZB_TOWN_EDGE, ///< 0..4 1,2,4,8,10 which town zones the building can be built in, Zone1 been the further suburb
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, ///< center of town
78 HZ_ZONALL = 0x001F, ///< 1F This is just to englobe all above types at once
79 HZ_SUBARTC_ABOVE = 0x0800, ///< 11 800 can appear in sub-arctic climate above the snow line
80 HZ_TEMP = 0x1000, ///< 12 1000 can appear in temperate climate
81 HZ_SUBARTC_BELOW = 0x2000, ///< 13 2000 can appear in sub-arctic climate below the snow line
82 HZ_SUBTROPIC = 0x4000, ///< 14 4000 can appear in subtropical climate
83 HZ_TOYLND = 0x8000, ///< 15 8000 can appear in toyland climate
84 HZ_CLIMALL = 0xF800, ///< Bitmask of all climate bits
86 DECLARE_ENUM_AS_BIT_SET(HouseZones)
88 enum HouseExtraFlags {
89 NO_EXTRA_FLAG = 0,
90 BUILDING_IS_HISTORICAL = 1U << 0, ///< this house will only appear during town generation in random games, thus the historical
91 BUILDING_IS_PROTECTED = 1U << 1, ///< towns and AI will not remove this house, while human players will be able to
92 SYNCHRONISED_CALLBACK_1B = 1U << 2, ///< synchronized callback 1B will be performed, on multi tile houses
93 CALLBACK_1A_RANDOM_BITS = 1U << 3, ///< callback 1A needs random bits
96 DECLARE_ENUM_AS_BIT_SET(HouseExtraFlags)
98 struct HouseSpec {
99 /* Standard properties */
100 TimerGameCalendar::Year min_year; ///< introduction year of the house
101 TimerGameCalendar::Year max_year; ///< last year it can be built
102 byte population; ///< population (Zero on other tiles in multi tile house.)
103 byte removal_cost; ///< cost multiplier for removing it
104 StringID building_name; ///< building name
105 uint16_t remove_rating_decrease; ///< rating decrease if removed
106 byte mail_generation; ///< mail generation multiplier (tile based, as the acceptances below)
107 byte cargo_acceptance[HOUSE_NUM_ACCEPTS]; ///< acceptance level for the cargo slots
108 CargoID accepts_cargo[HOUSE_NUM_ACCEPTS]; ///< input cargo slots
109 CargoLabel accepts_cargo_label[HOUSE_NUM_ACCEPTS]; ///< input landscape cargo slots
110 BuildingFlags building_flags; ///< some flags that describe the house (size, stadium etc...)
111 HouseZones building_availability; ///< where can it be built (climates, zones)
112 bool enabled; ///< the house is available to build (true by default, but can be disabled by newgrf)
114 /* NewHouses properties */
115 GRFFileProps grf_prop; ///< Properties related the the grf file
116 uint16_t callback_mask; ///< Bitmask of house callbacks that have to be called
117 Colours random_colour[4]; ///< 4 "random" colours
118 byte probability; ///< Relative probability of appearing (16 is the standard value)
119 HouseExtraFlags extra_flags; ///< some more flags
120 HouseClassID class_id; ///< defines the class this house has (not grf file based)
121 AnimationInfo animation; ///< information about the animation.
122 byte processing_time; ///< Periodic refresh multiplier
123 byte minimum_life; ///< The minimum number of years this house will survive before the town rebuilds it
124 CargoTypes watched_cargoes; ///< Cargo types watched for acceptance.
126 Money GetRemovalCost() const;
128 static inline HouseSpec *Get(size_t house_id)
130 assert(house_id < NUM_HOUSES);
131 extern HouseSpec _house_specs[];
132 return &_house_specs[house_id];
137 * Do HouseID translation for NewGRFs.
138 * @param hid the HouseID to get the override for.
139 * @return the HouseID to actually work with.
141 inline HouseID GetTranslatedHouseID(HouseID hid)
143 const HouseSpec *hs = HouseSpec::Get(hid);
144 return hs->grf_prop.override == INVALID_HOUSE_ID ? hid : hs->grf_prop.override;
147 #endif /* HOUSE_H */