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