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/>.
8 /** @file industrytype.h %Industry type specs. */
10 #ifndef INDUSTRYTYPE_H
11 #define INDUSTRYTYPE_H
14 #include "slope_type.h"
15 #include "industry_type.h"
16 #include "landscape_type.h"
17 #include "cargo_type.h"
18 #include "newgrf_animation_type.h"
19 #include "newgrf_commons.h"
21 /** Available types of industry lifetimes. */
22 enum IndustryLifeType
{
23 INDUSTRYLIFE_BLACK_HOLE
= 0, ///< Like power plants and banks
24 INDUSTRYLIFE_EXTRACTIVE
= 1 << 0, ///< Like mines
25 INDUSTRYLIFE_ORGANIC
= 1 << 1, ///< Like forests
26 INDUSTRYLIFE_PROCESSING
= 1 << 2, ///< Like factories
30 * Available procedures to check whether an industry may build at a given location.
31 * @see CheckNewIndustryProc, _check_new_industry_procs[]
34 CHECK_NOTHING
, ///< Always succeeds.
35 CHECK_FOREST
, ///< %Industry should be build above snow-line in arctic climate.
36 CHECK_REFINERY
, ///< %Industry should be positioned near edge of the map.
37 CHECK_FARM
, ///< %Industry should be below snow-line in arctic.
38 CHECK_PLANTATION
, ///< %Industry should NOT be in the desert.
39 CHECK_WATER
, ///< %Industry should be in the desert.
40 CHECK_LUMBERMILL
, ///< %Industry should be in the rain forest.
41 CHECK_BUBBLEGEN
, ///< %Industry should be in low land.
42 CHECK_OIL_RIG
, ///< Industries at sea should be positioned near edge of the map.
43 CHECK_END
, ///< End marker of the industry check procedures.
46 /** How was the industry created */
47 enum IndustryConstructionType
{
48 ICT_UNKNOWN
, ///< in previous game version or without newindustries activated
49 ICT_NORMAL_GAMEPLAY
, ///< either by user or random creation process
50 ICT_MAP_GENERATION
, ///< during random map creation
51 ICT_SCENARIO_EDITOR
, ///< while editing a scenario
54 /** Various industry behaviours mostly to represent original TTD specialities */
55 enum IndustryBehaviour
{
57 INDUSTRYBEH_PLANT_FIELDS
= 1 << 0, ///< periodically plants fields around itself (temp and arctic farms)
58 INDUSTRYBEH_CUT_TREES
= 1 << 1, ///< cuts trees and produce first output cargo from them (lumber mill)
59 INDUSTRYBEH_BUILT_ONWATER
= 1 << 2, ///< is built on water (oil rig)
60 INDUSTRYBEH_TOWN1200_MORE
= 1 << 3, ///< can only be built in towns larger than 1200 inhabitants (temperate bank)
61 INDUSTRYBEH_ONLY_INTOWN
= 1 << 4, ///< can only be built in towns (arctic/tropic banks, water tower)
62 INDUSTRYBEH_ONLY_NEARTOWN
= 1 << 5, ///< is always built near towns (toy shop)
63 INDUSTRYBEH_PLANT_ON_BUILT
= 1 << 6, ///< Fields are planted around when built (all farms)
64 INDUSTRYBEH_DONT_INCR_PROD
= 1 << 7, ///< do not increase production (oil wells) in the temperate climate
65 INDUSTRYBEH_BEFORE_1950
= 1 << 8, ///< can only be built before 1950 (oil wells)
66 INDUSTRYBEH_AFTER_1960
= 1 << 9, ///< can only be built after 1960 (oil rigs)
67 INDUSTRYBEH_AI_AIRSHIP_ROUTES
= 1 << 10, ///< ai will attempt to establish air/ship routes to this industry (oil rig)
68 INDUSTRYBEH_AIRPLANE_ATTACKS
= 1 << 11, ///< can be exploded by a military airplane (oil refinery)
69 INDUSTRYBEH_CHOPPER_ATTACKS
= 1 << 12, ///< can be exploded by a military helicopter (factory)
70 INDUSTRYBEH_CAN_SUBSIDENCE
= 1 << 13, ///< can cause a subsidence (coal mine, shaft that collapses)
71 /* The following flags are only used for newindustries and do no represent any normal behaviour */
72 INDUSTRYBEH_PROD_MULTI_HNDLING
= 1 << 14, ///< Automatic production multiplier handling
73 INDUSTRYBEH_PRODCALLBACK_RANDOM
= 1 << 15, ///< Production callback needs random bits in var 10
74 INDUSTRYBEH_NOBUILT_MAPCREATION
= 1 << 16, ///< Do not force one instance of this type to appear on map generation
75 INDUSTRYBEH_CANCLOSE_LASTINSTANCE
= 1 << 17, ///< Allow closing down the last instance of this type
76 INDUSTRYBEH_CARGOTYPES_UNLIMITED
= 1 << 18, ///< Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types
77 INDUSTRYBEH_NO_PAX_PROD_CLAMP
= 1 << 19, ///< Do not clamp production of passengers. (smooth economy only)
79 DECLARE_ENUM_AS_BIT_SET(IndustryBehaviour
)
81 /** Flags for miscellaneous industry tile specialities */
82 enum IndustryTileSpecialFlags
{
83 INDTILE_SPECIAL_NONE
= 0,
84 INDTILE_SPECIAL_NEXTFRAME_RANDOMBITS
= 1 << 0, ///< Callback 0x26 needs random bits
85 INDTILE_SPECIAL_ACCEPTS_ALL_CARGO
= 1 << 1, ///< Tile always accepts all cargoes the associated industry accepts
87 DECLARE_ENUM_AS_BIT_SET(IndustryTileSpecialFlags
)
89 /** Definition of one tile in an industry tile layout */
90 struct IndustryTileLayoutTile
{
95 /** A complete tile layout for an industry is a list of tiles */
96 using IndustryTileLayout
= std::vector
<IndustryTileLayoutTile
>;
99 * Defines the data structure for constructing industry.
101 struct IndustrySpec
{
102 std::vector
<IndustryTileLayout
> layouts
; ///< List of possible tile layouts for the industry
103 uint8_t cost_multiplier
; ///< Base construction cost multiplier.
104 uint32_t removal_cost_multiplier
; ///< Base removal cost multiplier.
105 uint32_t prospecting_chance
; ///< Chance prospecting succeeds
106 IndustryType conflicting
[3]; ///< Industries this industry cannot be close to
107 uint8_t check_proc
; ///< Index to a procedure to check for conflicting circumstances
108 std::array
<CargoID
, INDUSTRY_NUM_OUTPUTS
> produced_cargo
;
109 std::variant
<CargoLabel
, MixedCargoType
> produced_cargo_label
[INDUSTRY_NUM_OUTPUTS
];
110 uint8_t production_rate
[INDUSTRY_NUM_OUTPUTS
];
112 * minimum amount of cargo transported to the stations.
113 * If the waiting cargo is less than this number, no cargo is moved to it.
115 uint8_t minimal_cargo
;
116 std::array
<CargoID
, INDUSTRY_NUM_INPUTS
> accepts_cargo
; ///< 16 accepted cargoes.
117 std::variant
<CargoLabel
, MixedCargoType
> accepts_cargo_label
[INDUSTRY_NUM_INPUTS
];
118 uint16_t input_cargo_multiplier
[INDUSTRY_NUM_INPUTS
][INDUSTRY_NUM_OUTPUTS
]; ///< Input cargo multipliers (multiply amount of incoming cargo for the produced cargoes)
119 IndustryLifeType life_type
; ///< This is also known as Industry production flag, in newgrf specs
120 uint8_t climate_availability
; ///< Bitmask, giving landscape enums as bit position
121 IndustryBehaviour behaviour
; ///< How this industry will behave, and how others entities can use it
122 uint8_t map_colour
; ///< colour used for the small map
123 StringID name
; ///< Displayed name of the industry
124 StringID new_industry_text
; ///< Message appearing when the industry is built
125 StringID closure_text
; ///< Message appearing when the industry closes
126 StringID production_up_text
; ///< Message appearing when the industry's production is increasing
127 StringID production_down_text
; ///< Message appearing when the industry's production is decreasing
128 StringID station_name
; ///< Default name for nearby station
129 uint8_t appear_ingame
[NUM_LANDSCAPE
]; ///< Probability of appearance in game
130 uint8_t appear_creation
[NUM_LANDSCAPE
]; ///< Probability of appearance during map creation
132 uint16_t callback_mask
; ///< Bitmask of industry callbacks that have to be called
133 bool enabled
; ///< entity still available (by default true).newgrf can disable it, though
134 GRFFileProps grf_prop
; ///< properties related to the grf file
135 std::vector
<uint8_t> random_sounds
; ///< Random sounds;
137 bool IsRawIndustry() const;
138 bool IsProcessingIndustry() const;
139 Money
GetConstructionCost() const;
140 Money
GetRemovalCost() const;
141 bool UsesOriginalEconomy() const;
145 * Defines the data structure of each individual tile of an industry.
146 * @note A tile can at most accept 3 types of cargo, even if an industry as a whole can accept more types.
148 struct IndustryTileSpec
{
149 std::array
<CargoID
, INDUSTRY_NUM_INPUTS
> accepts_cargo
; ///< Cargo accepted by this tile
150 std::array
<std::variant
<CargoLabel
, MixedCargoType
>, INDUSTRY_NUM_INPUTS
> accepts_cargo_label
;
151 std::array
<int8_t, INDUSTRY_NUM_INPUTS
> acceptance
; ///< Level of acceptance per cargo type (signed, may be negative!)
152 Slope slopes_refused
; ///< slope pattern on which this tile cannot be built
153 uint8_t anim_production
; ///< Animation frame to start when goods are produced
154 uint8_t anim_next
; ///< Next frame in an animation
156 * When true, the tile has to be drawn using the animation
157 * state instead of the construction state
161 uint8_t callback_mask
; ///< Bitmask of industry tile callbacks that have to be called
162 AnimationInfo animation
; ///< Information about the animation (is it looping, how many loops etc)
163 IndustryTileSpecialFlags special_flags
; ///< Bitmask of extra flags used by the tile
164 bool enabled
; ///< entity still available (by default true).newgrf can disable it, though
165 GRFFileProps grf_prop
; ///< properties related to the grf file
168 /* industry_cmd.cpp*/
169 const IndustrySpec
*GetIndustrySpec(IndustryType thistype
); ///< Array of industries data
170 const IndustryTileSpec
*GetIndustryTileSpec(IndustryGfx gfx
); ///< Array of industry tiles data
171 void ResetIndustries();
173 /* writable arrays of specs */
174 extern IndustrySpec _industry_specs
[NUM_INDUSTRYTYPES
];
175 extern IndustryTileSpec _industry_tile_specs
[NUM_INDUSTRYTILES
];
177 /* industry_gui.cpp */
178 void SortIndustryTypes();
179 /* Industry types sorted alphabetically by name. */
180 extern std::array
<IndustryType
, NUM_INDUSTRYTYPES
> _sorted_industry_types
;
183 * Do industry gfx ID translation for NewGRFs.
184 * @param gfx the type to get the override for.
185 * @return the gfx to actually work with.
187 inline IndustryGfx
GetTranslatedIndustryTileID(IndustryGfx gfx
)
189 /* the 0xFF should be GFX_WATERTILE_SPECIALCHECK but for reasons of include mess,
190 * we'll simplify the writing.
191 * Basically, the first test is required since the GFX_WATERTILE_SPECIALCHECK value
192 * will never be assigned as a tile index and is only required in order to do some
193 * tests while building the industry (as in WATER REQUIRED */
195 assert(gfx
< INVALID_INDUSTRYTILE
);
196 const IndustryTileSpec
*it
= &_industry_tile_specs
[gfx
];
197 return it
->grf_prop
.override
== INVALID_INDUSTRYTILE
? gfx
: it
->grf_prop
.override
;
203 static const uint8_t IT_INVALID
= 255;
205 #endif /* INDUSTRYTYPE_H */