OpenTTD Source 20241224-master-gf74b0cf984
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 <http://www.gnu.org/licenses/>.
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"
19#include "newgrf_commons.h"
20
28
45
53
80
81
88
89
92 IndustryGfx gfx;
93};
94
96using IndustryTileLayout = std::vector<IndustryTileLayoutTile>;
97
102 std::vector<IndustryTileLayout> layouts;
106 IndustryType conflicting[3];
107 uint8_t check_proc;
108 std::array<CargoID, INDUSTRY_NUM_OUTPUTS> produced_cargo;
109 uint8_t production_rate[INDUSTRY_NUM_OUTPUTS];
115 std::array<CargoID, INDUSTRY_NUM_INPUTS> accepts_cargo;
120 uint8_t map_colour;
127 uint8_t appear_ingame[NUM_LANDSCAPE];
128 uint8_t appear_creation[NUM_LANDSCAPE];
129 /* Newgrf data */
130 uint16_t callback_mask;
131 bool enabled;
133 std::vector<uint8_t> random_sounds;
134
135 std::array<std::variant<CargoLabel, MixedCargoType>, INDUSTRY_ORIGINAL_NUM_OUTPUTS> produced_cargo_label;
136 std::array<std::variant<CargoLabel, MixedCargoType>, INDUSTRY_ORIGINAL_NUM_INPUTS> accepts_cargo_label;
137
138 bool IsRawIndustry() const;
139 bool IsProcessingIndustry() const;
141 Money GetRemovalCost() const;
142 bool UsesOriginalEconomy() const;
143};
144
150 std::array<CargoID, INDUSTRY_NUM_INPUTS> accepts_cargo;
151 std::array<int8_t, INDUSTRY_NUM_INPUTS> acceptance;
154 uint8_t anim_next;
160 /* Newgrf data */
164 bool enabled;
166
167 std::array<std::variant<CargoLabel, MixedCargoType>, INDUSTRY_ORIGINAL_NUM_INPUTS> accepts_cargo_label;
168};
169
170/* industry_cmd.cpp*/
171const IndustrySpec *GetIndustrySpec(IndustryType thistype);
172const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx);
173void ResetIndustries();
174
175/* writable arrays of specs */
176extern IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
177extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
178
179/* industry_gui.cpp */
180void SortIndustryTypes();
181/* Industry types sorted alphabetically by name. */
182extern std::array<IndustryType, NUM_INDUSTRYTYPES> _sorted_industry_types;
183
189inline IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
190{
191 /* the 0xFF should be GFX_WATERTILE_SPECIALCHECK but for reasons of include mess,
192 * we'll simplify the writing.
193 * Basically, the first test is required since the GFX_WATERTILE_SPECIALCHECK value
194 * will never be assigned as a tile index and is only required in order to do some
195 * tests while building the industry (as in WATER REQUIRED */
196 if (gfx != 0xFF) {
197 assert(gfx < INVALID_INDUSTRYTILE);
198 const IndustryTileSpec *it = &_industry_tile_specs[gfx];
199 return it->grf_prop.override == INVALID_INDUSTRYTILE ? gfx : it->grf_prop.override;
200 } else {
201 return gfx;
202 }
203}
204
205static const uint8_t IT_INVALID = 255;
206
207#endif /* INDUSTRYTYPE_H */
Types related to cargoes...
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
Operators to allow to work with enum as with type safe bit set in C++.
Definition enum_type.hpp:35
Types related to the industry.
static const int INDUSTRY_ORIGINAL_NUM_INPUTS
Original number of accepted cargo types.
static const int INDUSTRY_NUM_OUTPUTS
Number of cargo types an industry can produce.
static const int INDUSTRY_NUM_INPUTS
Number of cargo types an industry can accept.
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
static const IndustryGfx INVALID_INDUSTRYTILE
one above amount is considered invalid
static const int INDUSTRY_ORIGINAL_NUM_OUTPUTS
Original number of produced cargo types.
static const IndustryGfx NUM_INDUSTRYTILES
total number of industry tiles, new and old
IndustryLifeType
Available types of industry lifetimes.
@ INDUSTRYLIFE_EXTRACTIVE
Like mines.
@ INDUSTRYLIFE_BLACK_HOLE
Like power plants and banks.
@ INDUSTRYLIFE_PROCESSING
Like factories.
@ INDUSTRYLIFE_ORGANIC
Like forests.
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Array of industries data.
IndustryConstructionType
How was the industry created.
@ ICT_UNKNOWN
in previous game version or without newindustries activated
@ ICT_MAP_GENERATION
during random map creation
@ ICT_NORMAL_GAMEPLAY
either by user or random creation process
@ ICT_SCENARIO_EDITOR
while editing a scenario
CheckProc
Available procedures to check whether an industry may build at a given location.
@ CHECK_REFINERY
Industry should be positioned near edge of the map.
@ CHECK_END
End marker of the industry check procedures.
@ CHECK_PLANTATION
Industry should NOT be in the desert.
@ CHECK_OIL_RIG
Industries at sea should be positioned near edge of the map.
@ CHECK_LUMBERMILL
Industry should be in the rain forest.
@ CHECK_WATER
Industry should be in the desert.
@ CHECK_BUBBLEGEN
Industry should be in low land.
@ CHECK_FOREST
Industry should be build above snow-line in arctic climate.
@ CHECK_FARM
Industry should be below snow-line in arctic.
@ CHECK_NOTHING
Always succeeds.
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Array of industry tiles data.
IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
Do industry gfx ID translation for NewGRFs.
std::vector< IndustryTileLayoutTile > IndustryTileLayout
A complete tile layout for an industry is a list of tiles.
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
IndustryBehaviour
Various industry behaviours mostly to represent original TTD specialities.
@ INDUSTRYBEH_PROD_MULTI_HNDLING
Automatic production multiplier handling.
@ INDUSTRYBEH_CAN_SUBSIDENCE
can cause a subsidence (coal mine, shaft that collapses)
@ INDUSTRYBEH_AIRPLANE_ATTACKS
can be exploded by a military airplane (oil refinery)
@ INDUSTRYBEH_CHOPPER_ATTACKS
can be exploded by a military helicopter (factory)
@ INDUSTRYBEH_DONT_INCR_PROD
do not increase production (oil wells) in the temperate climate
@ INDUSTRYBEH_PLANT_ON_BUILT
Fields are planted around when built (all farms)
@ INDUSTRYBEH_CARGOTYPES_UNLIMITED
Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types.
@ INDUSTRYBEH_NO_PAX_PROD_CLAMP
Do not clamp production of passengers. (smooth economy only)
@ INDUSTRYBEH_PRODCALLBACK_RANDOM
Production callback needs random bits in var 10.
@ INDUSTRYBEH_AFTER_1960
can only be built after 1960 (oil rigs)
@ INDUSTRYBEH_CUT_TREES
cuts trees and produce first output cargo from them (lumber mill)
@ INDUSTRYBEH_BUILT_ONWATER
is built on water (oil rig)
@ INDUSTRYBEH_PLANT_FIELDS
periodically plants fields around itself (temp and arctic farms)
@ INDUSTRYBEH_CANCLOSE_LASTINSTANCE
Allow closing down the last instance of this type.
@ INDUSTRYBEH_ONLY_NEARTOWN
is always built near towns (toy shop)
@ INDUSTRYBEH_TOWN1200_MORE
can only be built in towns larger than 1200 inhabitants (temperate bank)
@ INDUSTRYBEH_ONLY_INTOWN
can only be built in towns (arctic/tropic banks, water tower)
@ INDUSTRYBEH_BEFORE_1950
can only be built before 1950 (oil wells)
@ INDUSTRYBEH_AI_AIRSHIP_ROUTES
ai will attempt to establish air/ship routes to this industry (oil rig)
@ INDUSTRYBEH_NOBUILT_MAPCREATION
Do not force one instance of this type to appear on map generation.
void ResetIndustries()
This function initialize the spec arrays of both industry and industry tiles.
IndustryTileSpecialFlags
Flags for miscellaneous industry tile specialities.
@ INDTILE_SPECIAL_ACCEPTS_ALL_CARGO
Tile always accepts all cargoes the associated industry accepts.
@ INDTILE_SPECIAL_NEXTFRAME_RANDOMBITS
Callback 0x26 needs random bits.
void SortIndustryTypes()
Initialize the list of sorted industry types.
Types related to the landscape.
Types related to maps.
Definitions related to NewGRF animation.
This file simplyfies and embeds a common mechanism of loading/saving and mapping of grf entities.
Definitions of a slope.
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Information about animation.
Data related to the handling of grf files.
uint16_t override
id of the entity been replaced by
Defines the data structure for constructing industry.
bool IsProcessingIndustry() const
Is an industry with the spec a processing industry?
std::vector< uint8_t > random_sounds
Random sounds;.
uint16_t callback_mask
Bitmask of industry callbacks that have to be called.
Money GetRemovalCost() const
Get the cost for removing this industry Take note that the cost will always be zero for non-grf indus...
uint8_t appear_creation[NUM_LANDSCAPE]
Probability of appearance during map creation.
std::array< CargoID, INDUSTRY_NUM_INPUTS > accepts_cargo
16 accepted cargoes.
bool UsesOriginalEconomy() const
Determines whether this industrytype uses standard/newgrf production changes.
uint8_t minimal_cargo
minimum amount of cargo transported to the stations.
uint32_t removal_cost_multiplier
Base removal cost multiplier.
uint32_t prospecting_chance
Chance prospecting succeeds.
StringID production_up_text
Message appearing when the industry's production is increasing.
StringID name
Displayed name of the industry.
uint8_t climate_availability
Bitmask, giving landscape enums as bit position.
std::array< std::variant< CargoLabel, MixedCargoType >, INDUSTRY_ORIGINAL_NUM_INPUTS > accepts_cargo_label
Cargo labels of accepted cargo for default industries.
uint8_t cost_multiplier
Base construction cost multiplier.
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
uint16_t input_cargo_multiplier[INDUSTRY_NUM_INPUTS][INDUSTRY_NUM_OUTPUTS]
Input cargo multipliers (multiply amount of incoming cargo for the produced cargoes)
bool IsRawIndustry() const
Is an industry with the spec a raw industry?
IndustryType conflicting[3]
Industries this industry cannot be close to.
uint8_t appear_ingame[NUM_LANDSCAPE]
Probability of appearance in game.
GRFFileProps grf_prop
properties related to the grf file
StringID production_down_text
Message appearing when the industry's production is decreasing.
StringID station_name
Default name for nearby station.
IndustryLifeType life_type
This is also known as Industry production flag, in newgrf specs.
StringID closure_text
Message appearing when the industry closes.
StringID new_industry_text
Message appearing when the industry is built.
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
bool enabled
entity still available (by default true).newgrf can disable it, though
Money GetConstructionCost() const
Get the cost for constructing this industry.
uint8_t map_colour
colour used for the small map
uint8_t check_proc
Index to a procedure to check for conflicting circumstances.
std::array< std::variant< CargoLabel, MixedCargoType >, INDUSTRY_ORIGINAL_NUM_OUTPUTS > produced_cargo_label
Cargo labels of produced cargo for default industries.
Definition of one tile in an industry tile layout.
Defines the data structure of each individual tile of an industry.
uint8_t anim_next
Next frame in an animation.
IndustryTileSpecialFlags special_flags
Bitmask of extra flags used by the tile.
std::array< CargoID, INDUSTRY_NUM_INPUTS > accepts_cargo
Cargo accepted by this tile.
GRFFileProps grf_prop
properties related to the grf file
Slope slopes_refused
slope pattern on which this tile cannot be built
AnimationInfo animation
Information about the animation (is it looping, how many loops etc)
std::array< std::variant< CargoLabel, MixedCargoType >, INDUSTRY_ORIGINAL_NUM_INPUTS > accepts_cargo_label
Cargo labels of accepted cargo for default industry tiles.
std::array< int8_t, INDUSTRY_NUM_INPUTS > acceptance
Level of acceptance per cargo type (signed, may be negative!)
uint8_t callback_mask
Bitmask of industry tile callbacks that have to be called.
bool enabled
entity still available (by default true).newgrf can disable it, though
bool anim_state
When true, the tile has to be drawn using the animation state instead of the construction state.
uint8_t anim_production
Animation frame to start when goods are produced.
A pair-construct of a TileIndexDiff.
Definition map_type.h:31