OpenTTD Source: src/industrytype.h Source File

OpenTTD Source 15.0-RC2

industrytype.h
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef INDUSTRYTYPE_H
11#define INDUSTRYTYPE_H
12
13#include "map_type.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_badge_type.h"
20#include "newgrf_callbacks.h"
21#include "newgrf_commons.h"
22
24 enum class IndustryLifeType : uint8_t {
25 Extractive = 0,
26 Organic = 1,
27 Processing = 2,
28};
29using IndustryLifeTypes = EnumBitSet<IndustryLifeType, uint8_t>;
30
31 static constexpr IndustryLifeTypes INDUSTRYLIFE_BLACK_HOLE{};
32
37 enum CheckProc : uint8_t {
38 CHECK_NOTHING,
39 CHECK_FOREST,
40 CHECK_REFINERY,
41 CHECK_FARM,
42 CHECK_PLANTATION,
43 CHECK_WATER,
44 CHECK_LUMBERMILL,
45 CHECK_BUBBLEGEN,
46 CHECK_OIL_RIG,
47 CHECK_END,
48};
49
51 enum IndustryConstructionType : uint8_t {
52 ICT_UNKNOWN,
53 ICT_NORMAL_GAMEPLAY,
54 ICT_MAP_GENERATION,
55 ICT_SCENARIO_EDITOR,
56};
57
59 enum class IndustryBehaviour : uint8_t {
60 PlantFields = 0,
61 CutTrees = 1,
62 BuiltOnWater = 2,
63 Town1200More = 3,
64 OnlyInTown = 4,
65 OnlyNearTown = 5,
66 PlantOnBuild = 6,
67 DontIncrProd = 7,
68 Before1950 = 8,
69 After1960 = 9,
70 AIAirShipRoutes = 10,
71 AirplaneAttacks = 11,
72 ChopperAttacks = 12,
73 CanSubsidence = 13,
74 /* The following flags are only used for newindustries and do no represent any normal behaviour */
75 ProdMultiHandling = 14,
76 ProdCallbackRandom = 15,
77 NoBuildMapCreation = 16,
78 CanCloseLastInstance = 17,
79 CargoTypesUnlimited = 18,
80 NoPaxProdClamp = 19,
81};
82using IndustryBehaviours = EnumBitSet<IndustryBehaviour, uint32_t>;
83
85 enum class IndustryTileSpecialFlag : uint8_t {
86 NextFrameRandomBits = 0,
87 AcceptsAllCargo = 1,
88};
89using IndustryTileSpecialFlags = EnumBitSet<IndustryTileSpecialFlag, uint8_t>;
90
92 struct IndustryTileLayoutTile {
93 TileIndexDiffC ti;
94 IndustryGfx gfx;
95};
96
98 using IndustryTileLayout = std::vector<IndustryTileLayoutTile>;
99
103 struct IndustrySpec {
104 std::vector<IndustryTileLayout> layouts;
105 uint8_t cost_multiplier;
106 uint32_t removal_cost_multiplier;
107 uint32_t prospecting_chance;
108 IndustryType conflicting[3];
109 uint8_t check_proc;
110 std::array<CargoType, INDUSTRY_NUM_OUTPUTS> produced_cargo;
111 uint8_t production_rate[INDUSTRY_NUM_OUTPUTS];
116 uint8_t minimal_cargo;
117 std::array<CargoType, INDUSTRY_NUM_INPUTS> accepts_cargo;
118 uint16_t input_cargo_multiplier[INDUSTRY_NUM_INPUTS][INDUSTRY_NUM_OUTPUTS];
119 IndustryLifeTypes life_type;
120 LandscapeTypes climate_availability;
121 IndustryBehaviours behaviour;
122 PixelColour map_colour;
123 StringID name;
124 StringID new_industry_text;
125 StringID closure_text;
126 StringID production_up_text;
127 StringID production_down_text;
128 StringID station_name;
129 uint8_t appear_ingame[NUM_LANDSCAPE];
130 uint8_t appear_creation[NUM_LANDSCAPE];
131 /* Newgrf data */
132 IndustryCallbackMasks callback_mask;
133 bool enabled;
134 SubstituteGRFFileProps grf_prop;
135 std::vector<uint8_t> random_sounds;
136 std::vector<BadgeID> badges;
137
138 std::array<std::variant<CargoLabel, MixedCargoType>, INDUSTRY_ORIGINAL_NUM_OUTPUTS> produced_cargo_label;
139 std::array<std::variant<CargoLabel, MixedCargoType>, INDUSTRY_ORIGINAL_NUM_INPUTS> accepts_cargo_label;
140
141 bool IsRawIndustry() const;
142 bool IsProcessingIndustry() const;
143 Money GetConstructionCost() const;
144 Money GetRemovalCost() const;
145 bool UsesOriginalEconomy() const;
146};
147
152 struct IndustryTileSpec {
153 std::array<CargoType, INDUSTRY_NUM_INPUTS> accepts_cargo;
154 std::array<int8_t, INDUSTRY_NUM_INPUTS> acceptance;
155 Slope slopes_refused;
156 uint8_t anim_production;
157 uint8_t anim_next;
162 bool anim_state;
163 /* Newgrf data */
164 IndustryTileCallbackMasks callback_mask;
165 AnimationInfo<IndustryAnimationTriggers> animation;
166 IndustryTileSpecialFlags special_flags;
167 bool enabled;
168 SubstituteGRFFileProps grf_prop;
169 std::vector<BadgeID> badges;
170
171 std::array<std::variant<CargoLabel, MixedCargoType>, INDUSTRY_ORIGINAL_NUM_INPUTS> accepts_cargo_label;
172};
173
174/* industry_cmd.cpp*/
175const IndustrySpec *GetIndustrySpec(IndustryType thistype);
176const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx);
177void ResetIndustries();
178
179/* writable arrays of specs */
180extern IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
181extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
182
183/* industry_gui.cpp */
184void SortIndustryTypes();
185/* Industry types sorted alphabetically by name. */
186extern std::array<IndustryType, NUM_INDUSTRYTYPES> _sorted_industry_types;
187
193 inline IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
194{
195 /* the 0xFF should be GFX_WATERTILE_SPECIALCHECK but for reasons of include mess,
196 * we'll simplify the writing.
197 * Basically, the first test is required since the GFX_WATERTILE_SPECIALCHECK value
198 * will never be assigned as a tile index and is only required in order to do some
199 * tests while building the industry (as in WATER REQUIRED */
200 if (gfx != 0xFF) {
201 assert(gfx < NUM_INDUSTRYTILES);
202 const IndustryTileSpec *it = &_industry_tile_specs[gfx];
203 return it->grf_prop.override_id == INVALID_INDUSTRYTILE ? gfx : it->grf_prop.override_id;
204 } else {
205 return gfx;
206 }
207}
208
209#endif /* INDUSTRYTYPE_H */
cargo_type.h
Types related to cargoes...
EnumBitSet< IndustryLifeType, uint8_t >
OverflowSafeInt< int64_t >
industry_type.h
Types related to the industry.
INDUSTRY_ORIGINAL_NUM_INPUTS
static const int INDUSTRY_ORIGINAL_NUM_INPUTS
Original number of accepted cargo types.
Definition industry_type.h:59
INDUSTRY_NUM_OUTPUTS
static const int INDUSTRY_NUM_OUTPUTS
Number of cargo types an industry can produce.
Definition industry_type.h:58
INDUSTRY_NUM_INPUTS
static const int INDUSTRY_NUM_INPUTS
Number of cargo types an industry can accept.
Definition industry_type.h:57
NUM_INDUSTRYTYPES
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like IT_...
Definition industry_type.h:45
INVALID_INDUSTRYTILE
static const IndustryGfx INVALID_INDUSTRYTILE
one above amount is considered invalid
Definition industry_type.h:53
INDUSTRY_ORIGINAL_NUM_OUTPUTS
static const int INDUSTRY_ORIGINAL_NUM_OUTPUTS
Original number of produced cargo types.
Definition industry_type.h:60
NUM_INDUSTRYTILES
static const IndustryGfx NUM_INDUSTRYTILES
total number of industry tiles, new and old
Definition industry_type.h:52
IndustryBehaviour
IndustryBehaviour
Various industry behaviours mostly to represent original TTD specialities.
Definition industrytype.h:59
IndustryBehaviour::AirplaneAttacks
@ AirplaneAttacks
can be exploded by a military airplane (oil refinery)
IndustryBehaviour::ProdCallbackRandom
@ ProdCallbackRandom
Production callback needs random bits in var 10.
IndustryBehaviour::NoBuildMapCreation
@ NoBuildMapCreation
Do not force one instance of this type to appear on map generation.
IndustryBehaviour::CutTrees
@ CutTrees
cuts trees and produce first output cargo from them (lumber mill)
IndustryBehaviour::PlantOnBuild
@ PlantOnBuild
Fields are planted around when built (all farms)
IndustryBehaviour::Before1950
@ Before1950
can only be built before 1950 (oil wells)
IndustryBehaviour::BuiltOnWater
@ BuiltOnWater
is built on water (oil rig)
IndustryBehaviour::DontIncrProd
@ DontIncrProd
do not increase production (oil wells) in the temperate climate
IndustryBehaviour::AIAirShipRoutes
@ AIAirShipRoutes
ai will attempt to establish air/ship routes to this industry (oil rig)
IndustryBehaviour::CargoTypesUnlimited
@ CargoTypesUnlimited
Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types.
IndustryBehaviour::After1960
@ After1960
can only be built after 1960 (oil rigs)
IndustryBehaviour::CanSubsidence
@ CanSubsidence
can cause a subsidence (coal mine, shaft that collapses)
IndustryBehaviour::OnlyInTown
@ OnlyInTown
can only be built in towns (arctic/tropic banks, water tower)
IndustryBehaviour::ProdMultiHandling
@ ProdMultiHandling
Automatic production multiplier handling.
IndustryBehaviour::PlantFields
@ PlantFields
periodically plants fields around itself (temp and arctic farms)
IndustryBehaviour::Town1200More
@ Town1200More
can only be built in towns larger than 1200 inhabitants (temperate bank)
IndustryBehaviour::ChopperAttacks
@ ChopperAttacks
can be exploded by a military helicopter (factory)
IndustryBehaviour::NoPaxProdClamp
@ NoPaxProdClamp
Do not clamp production of passengers. (smooth economy only)
IndustryBehaviour::CanCloseLastInstance
@ CanCloseLastInstance
Allow closing down the last instance of this type.
IndustryBehaviour::OnlyNearTown
@ OnlyNearTown
is always built near towns (toy shop)
GetIndustrySpec
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Array of industries data.
Definition industry_cmd.cpp:126
GetIndustryTileSpec
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Array of industry tiles data.
Definition industry_cmd.cpp:140
IndustryTileSpecialFlag
IndustryTileSpecialFlag
Flags for miscellaneous industry tile specialities.
Definition industrytype.h:85
IndustryTileSpecialFlag::NextFrameRandomBits
@ NextFrameRandomBits
Callback 0x26 needs random bits.
IndustryTileSpecialFlag::AcceptsAllCargo
@ AcceptsAllCargo
Tile always accepts all cargoes the associated industry accepts.
IndustryLifeType
IndustryLifeType
Available types of industry lifetimes.
Definition industrytype.h:24
IndustryLifeType::Processing
@ Processing
Like factories.
IndustryLifeType::Organic
@ Organic
Like forests.
IndustryLifeType::Extractive
@ Extractive
Like mines.
GetTranslatedIndustryTileID
IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
Do industry gfx ID translation for NewGRFs.
Definition industrytype.h:193
IndustryTileLayout
std::vector< IndustryTileLayoutTile > IndustryTileLayout
A complete tile layout for an industry is a list of tiles.
Definition industrytype.h:98
CheckProc
CheckProc
Available procedures to check whether an industry may build at a given location.
Definition industrytype.h:37
CHECK_REFINERY
@ CHECK_REFINERY
Industry should be positioned near edge of the map.
Definition industrytype.h:40
CHECK_END
@ CHECK_END
End marker of the industry check procedures.
Definition industrytype.h:47
CHECK_PLANTATION
@ CHECK_PLANTATION
Industry should NOT be in the desert.
Definition industrytype.h:42
CHECK_OIL_RIG
@ CHECK_OIL_RIG
Industries at sea should be positioned near edge of the map.
Definition industrytype.h:46
CHECK_LUMBERMILL
@ CHECK_LUMBERMILL
Industry should be in the rainforest.
Definition industrytype.h:44
CHECK_WATER
@ CHECK_WATER
Industry should be in the desert.
Definition industrytype.h:43
CHECK_BUBBLEGEN
@ CHECK_BUBBLEGEN
Industry should be in low land.
Definition industrytype.h:45
CHECK_FOREST
@ CHECK_FOREST
Industry should be build above snow-line in arctic climate.
Definition industrytype.h:39
CHECK_FARM
@ CHECK_FARM
Industry should be below snow-line in arctic.
Definition industrytype.h:41
CHECK_NOTHING
@ CHECK_NOTHING
Always succeeds.
Definition industrytype.h:38
_sorted_industry_types
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
Definition industry_gui.cpp:235
ResetIndustries
void ResetIndustries()
This function initialize the spec arrays of both industry and industry tiles.
Definition industry_cmd.cpp:83
IndustryConstructionType
IndustryConstructionType
How was the industry created.
Definition industrytype.h:51
ICT_UNKNOWN
@ ICT_UNKNOWN
in previous game version or without newindustries activated
Definition industrytype.h:52
ICT_MAP_GENERATION
@ ICT_MAP_GENERATION
during random map creation
Definition industrytype.h:54
ICT_NORMAL_GAMEPLAY
@ ICT_NORMAL_GAMEPLAY
either by user or random creation process
Definition industrytype.h:53
ICT_SCENARIO_EDITOR
@ ICT_SCENARIO_EDITOR
while editing a scenario
Definition industrytype.h:55
INDUSTRYLIFE_BLACK_HOLE
static constexpr IndustryLifeTypes INDUSTRYLIFE_BLACK_HOLE
Like power plants and banks.
Definition industrytype.h:31
SortIndustryTypes
void SortIndustryTypes()
Initialize the list of sorted industry types.
Definition industry_gui.cpp:249
landscape_type.h
Types related to the landscape.
map_type.h
Types related to maps.
newgrf_animation_type.h
Definitions related to NewGRF animation.
newgrf_badge_type.h
Types related to NewGRF badges.
newgrf_callbacks.h
Callbacks that NewGRFs could implement.
newgrf_commons.h
This file simplifies and embeds a common mechanism of loading/saving and mapping of grf entities.
slope_type.h
Definitions of a slope.
Slope
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
AnimationInfo
Information about animation.
Definition newgrf_animation_type.h:21
IndustrySpec
Defines the data structure for constructing industry.
Definition industrytype.h:103
IndustrySpec::callback_mask
IndustryCallbackMasks callback_mask
Bitmask of industry callbacks that have to be called.
Definition industrytype.h:132
IndustrySpec::IsProcessingIndustry
bool IsProcessingIndustry() const
Is an industry with the spec a processing industry?
Definition industry_cmd.cpp:3191
IndustrySpec::random_sounds
std::vector< uint8_t > random_sounds
Random sounds;.
Definition industrytype.h:135
IndustrySpec::GetRemovalCost
Money GetRemovalCost() const
Get the cost for removing this industry Take note that the cost will always be zero for non-grf indus...
Definition industry_cmd.cpp:3215
IndustrySpec::accepts_cargo
std::array< CargoType, INDUSTRY_NUM_INPUTS > accepts_cargo
16 accepted cargoes.
Definition industrytype.h:117
IndustrySpec::appear_creation
uint8_t appear_creation[NUM_LANDSCAPE]
Probability of appearance during map creation.
Definition industrytype.h:130
IndustrySpec::UsesOriginalEconomy
bool UsesOriginalEconomy() const
Determines whether this industrytype uses standard/newgrf production changes.
Definition industry_cmd.cpp:3224
IndustrySpec::climate_availability
LandscapeTypes climate_availability
Bitmask, giving landscape enums as bit position.
Definition industrytype.h:120
IndustrySpec::minimal_cargo
uint8_t minimal_cargo
minimum amount of cargo transported to the stations.
Definition industrytype.h:116
IndustrySpec::removal_cost_multiplier
uint32_t removal_cost_multiplier
Base removal cost multiplier.
Definition industrytype.h:106
IndustrySpec::prospecting_chance
uint32_t prospecting_chance
Chance prospecting succeeds.
Definition industrytype.h:107
IndustrySpec::production_up_text
StringID production_up_text
Message appearing when the industry's production is increasing.
Definition industrytype.h:126
IndustrySpec::grf_prop
SubstituteGRFFileProps grf_prop
properties related to the grf file
Definition industrytype.h:134
IndustrySpec::name
StringID name
Displayed name of the industry.
Definition industrytype.h:123
IndustrySpec::accepts_cargo_label
std::array< std::variant< CargoLabel, MixedCargoType >, INDUSTRY_ORIGINAL_NUM_INPUTS > accepts_cargo_label
Cargo labels of accepted cargo for default industries.
Definition industrytype.h:139
IndustrySpec::cost_multiplier
uint8_t cost_multiplier
Base construction cost multiplier.
Definition industrytype.h:105
IndustrySpec::input_cargo_multiplier
uint16_t input_cargo_multiplier[INDUSTRY_NUM_INPUTS][INDUSTRY_NUM_OUTPUTS]
Input cargo multipliers (multiply amount of incoming cargo for the produced cargoes)
Definition industrytype.h:118
IndustrySpec::IsRawIndustry
bool IsRawIndustry() const
Is an industry with the spec a raw industry?
Definition industry_cmd.cpp:3182
IndustrySpec::conflicting
IndustryType conflicting[3]
Industries this industry cannot be close to.
Definition industrytype.h:108
IndustrySpec::appear_ingame
uint8_t appear_ingame[NUM_LANDSCAPE]
Probability of appearance in game.
Definition industrytype.h:129
IndustrySpec::production_down_text
StringID production_down_text
Message appearing when the industry's production is decreasing.
Definition industrytype.h:127
IndustrySpec::station_name
StringID station_name
Default name for nearby station.
Definition industrytype.h:128
IndustrySpec::behaviour
IndustryBehaviours behaviour
How this industry will behave, and how others entities can use it.
Definition industrytype.h:121
IndustrySpec::closure_text
StringID closure_text
Message appearing when the industry closes.
Definition industrytype.h:125
IndustrySpec::new_industry_text
StringID new_industry_text
Message appearing when the industry is built.
Definition industrytype.h:124
IndustrySpec::layouts
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
Definition industrytype.h:104
IndustrySpec::enabled
bool enabled
entity still available (by default true).newgrf can disable it, though
Definition industrytype.h:133
IndustrySpec::GetConstructionCost
Money GetConstructionCost() const
Get the cost for constructing this industry.
Definition industry_cmd.cpp:3202
IndustrySpec::life_type
IndustryLifeTypes life_type
This is also known as Industry production flag, in newgrf specs.
Definition industrytype.h:119
IndustrySpec::check_proc
uint8_t check_proc
Index to a procedure to check for conflicting circumstances.
Definition industrytype.h:109
IndustrySpec::produced_cargo_label
std::array< std::variant< CargoLabel, MixedCargoType >, INDUSTRY_ORIGINAL_NUM_OUTPUTS > produced_cargo_label
Cargo labels of produced cargo for default industries.
Definition industrytype.h:138
IndustrySpec::map_colour
PixelColour map_colour
colour used for the small map
Definition industrytype.h:122
IndustryTileLayoutTile
Definition of one tile in an industry tile layout.
Definition industrytype.h:92
IndustryTileSpec
Defines the data structure of each individual tile of an industry.
Definition industrytype.h:152
IndustryTileSpec::anim_next
uint8_t anim_next
Next frame in an animation.
Definition industrytype.h:157
IndustryTileSpec::special_flags
IndustryTileSpecialFlags special_flags
Bitmask of extra flags used by the tile.
Definition industrytype.h:166
IndustryTileSpec::slopes_refused
Slope slopes_refused
slope pattern on which this tile cannot be built
Definition industrytype.h:155
IndustryTileSpec::accepts_cargo_label
std::array< std::variant< CargoLabel, MixedCargoType >, INDUSTRY_ORIGINAL_NUM_INPUTS > accepts_cargo_label
Cargo labels of accepted cargo for default industry tiles.
Definition industrytype.h:171
IndustryTileSpec::animation
AnimationInfo< IndustryAnimationTriggers > animation
Information about the animation (is it looping, how many loops etc)
Definition industrytype.h:165
IndustryTileSpec::acceptance
std::array< int8_t, INDUSTRY_NUM_INPUTS > acceptance
Level of acceptance per cargo type (signed, may be negative!)
Definition industrytype.h:154
IndustryTileSpec::grf_prop
SubstituteGRFFileProps grf_prop
properties related to the grf file
Definition industrytype.h:168
IndustryTileSpec::enabled
bool enabled
entity still available (by default true).newgrf can disable it, though
Definition industrytype.h:167
IndustryTileSpec::anim_state
bool anim_state
When true, the tile has to be drawn using the animation state instead of the construction stage.
Definition industrytype.h:162
IndustryTileSpec::callback_mask
IndustryTileCallbackMasks callback_mask
Bitmask of industry tile callbacks that have to be called.
Definition industrytype.h:164
IndustryTileSpec::accepts_cargo
std::array< CargoType, INDUSTRY_NUM_INPUTS > accepts_cargo
Cargo accepted by this tile.
Definition industrytype.h:153
IndustryTileSpec::anim_production
uint8_t anim_production
Animation frame to start when goods are produced.
Definition industrytype.h:156
PixelColour
Colour for pixel/line drawing.
Definition gfx_type.h:405
SubstituteGRFFileProps
NewGRF entities which can replace default entities.
Definition newgrf_commons.h:464
SubstituteGRFFileProps::override_id
uint16_t override_id
id of the entity been replaced by
Definition newgrf_commons.h:469
TileIndexDiffC
A pair-construct of a TileIndexDiff.
Definition map_type.h:31