Fix #8316: Make sort industries by production and transported with a cargo filter...
[openttd-github.git] / src / industrytype.h
blobd5f1ba96a7be828d103f1b9006e340316a427726
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 industrytype.h %Industry type specs. */
10 #ifndef INDUSTRYTYPE_H
11 #define INDUSTRYTYPE_H
13 #include <array>
14 #include <vector>
15 #include "map_type.h"
16 #include "slope_type.h"
17 #include "industry_type.h"
18 #include "landscape_type.h"
19 #include "cargo_type.h"
20 #include "newgrf_animation_type.h"
21 #include "newgrf_commons.h"
23 enum IndustryCleanupType {
24 CLEAN_RANDOMSOUNDS, ///< Free the dynamically allocated sounds table
27 /** Available types of industry lifetimes. */
28 enum IndustryLifeType {
29 INDUSTRYLIFE_BLACK_HOLE = 0, ///< Like power plants and banks
30 INDUSTRYLIFE_EXTRACTIVE = 1 << 0, ///< Like mines
31 INDUSTRYLIFE_ORGANIC = 1 << 1, ///< Like forests
32 INDUSTRYLIFE_PROCESSING = 1 << 2, ///< Like factories
35 /**
36 * Available procedures to check whether an industry may build at a given location.
37 * @see CheckNewIndustryProc, _check_new_industry_procs[]
39 enum CheckProc {
40 CHECK_NOTHING, ///< Always succeeds.
41 CHECK_FOREST, ///< %Industry should be build above snow-line in arctic climate.
42 CHECK_REFINERY, ///< %Industry should be positioned near edge of the map.
43 CHECK_FARM, ///< %Industry should be below snow-line in arctic.
44 CHECK_PLANTATION, ///< %Industry should NOT be in the desert.
45 CHECK_WATER, ///< %Industry should be in the desert.
46 CHECK_LUMBERMILL, ///< %Industry should be in the rain forest.
47 CHECK_BUBBLEGEN, ///< %Industry should be in low land.
48 CHECK_OIL_RIG, ///< Industries at sea should be positioned near edge of the map.
49 CHECK_END, ///< End marker of the industry check procedures.
52 /** How was the industry created */
53 enum IndustryConstructionType {
54 ICT_UNKNOWN, ///< in previous game version or without newindustries activated
55 ICT_NORMAL_GAMEPLAY, ///< either by user or random creation process
56 ICT_MAP_GENERATION, ///< during random map creation
57 ICT_SCENARIO_EDITOR, ///< while editing a scenario
60 /** Various industry behaviours mostly to represent original TTD specialities */
61 enum IndustryBehaviour {
62 INDUSTRYBEH_NONE = 0,
63 INDUSTRYBEH_PLANT_FIELDS = 1 << 0, ///< periodically plants fields around itself (temp and arctic farms)
64 INDUSTRYBEH_CUT_TREES = 1 << 1, ///< cuts trees and produce first output cargo from them (lumber mill)
65 INDUSTRYBEH_BUILT_ONWATER = 1 << 2, ///< is built on water (oil rig)
66 INDUSTRYBEH_TOWN1200_MORE = 1 << 3, ///< can only be built in towns larger than 1200 inhabitants (temperate bank)
67 INDUSTRYBEH_ONLY_INTOWN = 1 << 4, ///< can only be built in towns (arctic/tropic banks, water tower)
68 INDUSTRYBEH_ONLY_NEARTOWN = 1 << 5, ///< is always built near towns (toy shop)
69 INDUSTRYBEH_PLANT_ON_BUILT = 1 << 6, ///< Fields are planted around when built (all farms)
70 INDUSTRYBEH_DONT_INCR_PROD = 1 << 7, ///< do not increase production (oil wells) in the temperate climate
71 INDUSTRYBEH_BEFORE_1950 = 1 << 8, ///< can only be built before 1950 (oil wells)
72 INDUSTRYBEH_AFTER_1960 = 1 << 9, ///< can only be built after 1960 (oil rigs)
73 INDUSTRYBEH_AI_AIRSHIP_ROUTES = 1 << 10, ///< ai will attempt to establish air/ship routes to this industry (oil rig)
74 INDUSTRYBEH_AIRPLANE_ATTACKS = 1 << 11, ///< can be exploded by a military airplane (oil refinery)
75 INDUSTRYBEH_CHOPPER_ATTACKS = 1 << 12, ///< can be exploded by a military helicopter (factory)
76 INDUSTRYBEH_CAN_SUBSIDENCE = 1 << 13, ///< can cause a subsidence (coal mine, shaft that collapses)
77 /* The following flags are only used for newindustries and do no represent any normal behaviour */
78 INDUSTRYBEH_PROD_MULTI_HNDLING = 1 << 14, ///< Automatic production multiplier handling
79 INDUSTRYBEH_PRODCALLBACK_RANDOM = 1 << 15, ///< Production callback needs random bits in var 10
80 INDUSTRYBEH_NOBUILT_MAPCREATION = 1 << 16, ///< Do not force one instance of this type to appear on map generation
81 INDUSTRYBEH_CANCLOSE_LASTINSTANCE = 1 << 17, ///< Allow closing down the last instance of this type
82 INDUSTRYBEH_CARGOTYPES_UNLIMITED = 1 << 18, ///< Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types
83 INDUSTRYBEH_NO_PAX_PROD_CLAMP = 1 << 19, ///< Do not clamp production of passengers. (smooth economy only)
85 DECLARE_ENUM_AS_BIT_SET(IndustryBehaviour)
87 /** Flags for miscellaneous industry tile specialities */
88 enum IndustryTileSpecialFlags {
89 INDTILE_SPECIAL_NONE = 0,
90 INDTILE_SPECIAL_NEXTFRAME_RANDOMBITS = 1 << 0, ///< Callback 0x26 needs random bits
91 INDTILE_SPECIAL_ACCEPTS_ALL_CARGO = 1 << 1, ///< Tile always accepts all cargoes the associated industry accepts
93 DECLARE_ENUM_AS_BIT_SET(IndustryTileSpecialFlags)
95 /** Definition of one tile in an industry tile layout */
96 struct IndustryTileLayoutTile {
97 TileIndexDiffC ti;
98 IndustryGfx gfx;
101 /** A complete tile layout for an industry is a list of tiles */
102 using IndustryTileLayout = std::vector<IndustryTileLayoutTile>;
105 * Defines the data structure for constructing industry.
107 struct IndustrySpec {
108 std::vector<IndustryTileLayout> layouts; ///< List of possible tile layouts for the industry
109 uint8 cost_multiplier; ///< Base construction cost multiplier.
110 uint32 removal_cost_multiplier; ///< Base removal cost multiplier.
111 uint32 prospecting_chance; ///< Chance prospecting succeeds
112 IndustryType conflicting[3]; ///< Industries this industry cannot be close to
113 byte check_proc; ///< Index to a procedure to check for conflicting circumstances
114 CargoID produced_cargo[INDUSTRY_NUM_OUTPUTS];
115 byte production_rate[INDUSTRY_NUM_OUTPUTS];
117 * minimum amount of cargo transported to the stations.
118 * If the waiting cargo is less than this number, no cargo is moved to it.
120 byte minimal_cargo;
121 CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]; ///< 16 accepted cargoes.
122 uint16 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 number_of_sounds; ///< Number of sounds available in the sounds array
136 const uint8 *random_sounds; ///< array of random sounds.
137 /* Newgrf data */
138 uint16 callback_mask; ///< Bitmask of industry callbacks that have to be called
139 uint8 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;
149 ~IndustrySpec();
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 CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]; ///< Cargo accepted by this tile
158 int8 acceptance[INDUSTRY_NUM_INPUTS]; ///< Level of acceptance per cargo type (signed, may be negative!)
159 Slope slopes_refused; ///< slope pattern on which this tile cannot be built
160 byte anim_production; ///< Animation frame to start when goods are produced
161 byte anim_next; ///< Next frame in an animation
163 * When true, the tile has to be drawn using the animation
164 * state instead of the construction state
166 bool anim_state;
167 /* Newgrf data */
168 uint8 callback_mask; ///< Bitmask of industry tile callbacks that have to be called
169 AnimationInfo animation; ///< Information about the animation (is it looping, how many loops etc)
170 IndustryTileSpecialFlags special_flags; ///< Bitmask of extra flags used by the tile
171 bool enabled; ///< entity still available (by default true).newgrf can disable it, though
172 GRFFileProps grf_prop; ///< properties related to the grf file
175 /* industry_cmd.cpp*/
176 const IndustrySpec *GetIndustrySpec(IndustryType thistype); ///< Array of industries data
177 const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx); ///< Array of industry tiles data
178 void ResetIndustries();
180 /* writable arrays of specs */
181 extern IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
182 extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
184 /* industry_gui.cpp */
185 void SortIndustryTypes();
186 /* Industry types sorted alphabetically by name. */
187 extern std::array<IndustryType, NUM_INDUSTRYTYPES> _sorted_industry_types;
190 * Do industry gfx ID translation for NewGRFs.
191 * @param gfx the type to get the override for.
192 * @return the gfx to actually work with.
194 static inline IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
196 /* the 0xFF should be GFX_WATERTILE_SPECIALCHECK but for reasons of include mess,
197 * we'll simplify the writing.
198 * Basically, the first test is required since the GFX_WATERTILE_SPECIALCHECK value
199 * will never be assigned as a tile index and is only required in order to do some
200 * tests while building the industry (as in WATER REQUIRED */
201 if (gfx != 0xFF) {
202 assert(gfx < INVALID_INDUSTRYTILE);
203 const IndustryTileSpec *it = &_industry_tile_specs[gfx];
204 return it->grf_prop.override == INVALID_INDUSTRYTILE ? gfx : it->grf_prop.override;
205 } else {
206 return gfx;
210 static const uint8 IT_INVALID = 255;
212 #endif /* INDUSTRYTYPE_H */