2009-08-30 11:40:01 +00:00
/*
* This file is part of OpenTTD .
* 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.
* 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 .
* 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/>.
*/
2012-01-01 17:22:32 +00:00
/** @file industrytype.h %Industry type specs. */
2009-08-30 11:40:01 +00:00
# ifndef INDUSTRYTYPE_H
# define INDUSTRYTYPE_H
2019-04-13 21:46:11 +00:00
# include <array>
2019-10-04 19:26:44 +00:00
# include <vector>
2009-08-30 11:40:01 +00:00
# include "map_type.h"
# include "slope_type.h"
# include "industry_type.h"
# include "landscape_type.h"
2010-01-15 16:41:15 +00:00
# include "cargo_type.h"
2010-08-26 15:31:40 +00:00
# include "newgrf_animation_type.h"
2010-02-22 14:15:48 +00:00
# include "newgrf_commons.h"
2009-08-30 11:40:01 +00:00
2010-05-13 09:44:44 +00:00
enum IndustryCleanupType {
2009-08-30 11:40:01 +00:00
CLEAN_RANDOMSOUNDS , ///< Free the dynamically allocated sounds table
} ;
2010-02-15 09:49:10 +00:00
/** Available types of industry lifetimes. */
2009-08-30 11:40:01 +00:00
enum IndustryLifeType {
INDUSTRYLIFE_BLACK_HOLE = 0 , ///< Like power plants and banks
INDUSTRYLIFE_EXTRACTIVE = 1 < < 0 , ///< Like mines
INDUSTRYLIFE_ORGANIC = 1 < < 1 , ///< Like forests
INDUSTRYLIFE_PROCESSING = 1 < < 2 , ///< Like factories
} ;
2010-08-01 19:22:34 +00:00
/**
* Available procedures to check whether an industry may build at a given location .
2010-02-15 09:49:10 +00:00
* @ see CheckNewIndustryProc , _check_new_industry_procs [ ]
*/
2009-08-30 11:40:01 +00:00
enum CheckProc {
2010-02-15 09:49:10 +00:00
CHECK_NOTHING , ///< Always succeeds.
CHECK_FOREST , ///< %Industry should be build above snow-line in arctic climate.
CHECK_REFINERY , ///< %Industry should be positioned near edge of the map.
CHECK_FARM , ///< %Industry should be below snow-line in arctic.
CHECK_PLANTATION , ///< %Industry should NOT be in the desert.
CHECK_WATER , ///< %Industry should be in the desert.
CHECK_LUMBERMILL , ///< %Industry should be in the rain forest.
CHECK_BUBBLEGEN , ///< %Industry should be in low land.
CHECK_OIL_RIG , ///< Industries at sea should be positioned near edge of the map.
CHECK_END , ///< End marker of the industry check procedures.
2009-08-30 11:40:01 +00:00
} ;
/** How was the industry created */
enum IndustryConstructionType {
ICT_UNKNOWN , ///< in previous game version or without newindustries activated
2010-11-20 13:33:24 +00:00
ICT_NORMAL_GAMEPLAY , ///< either by user or random creation process
2009-08-30 11:40:01 +00:00
ICT_MAP_GENERATION , ///< during random map creation
2011-12-19 17:48:04 +00:00
ICT_SCENARIO_EDITOR , ///< while editing a scenario
2009-08-30 11:40:01 +00:00
} ;
2010-02-07 12:04:44 +00:00
/** Various industry behaviours mostly to represent original TTD specialities */
2009-08-30 11:40:01 +00:00
enum IndustryBehaviour {
INDUSTRYBEH_NONE = 0 ,
2010-11-20 13:33:24 +00:00
INDUSTRYBEH_PLANT_FIELDS = 1 < < 0 , ///< periodically plants fields around itself (temp and arctic farms)
2009-08-30 11:40:01 +00:00
INDUSTRYBEH_CUT_TREES = 1 < < 1 , ///< cuts trees and produce first output cargo from them (lumber mill)
INDUSTRYBEH_BUILT_ONWATER = 1 < < 2 , ///< is built on water (oil rig)
INDUSTRYBEH_TOWN1200_MORE = 1 < < 3 , ///< can only be built in towns larger than 1200 inhabitants (temperate bank)
INDUSTRYBEH_ONLY_INTOWN = 1 < < 4 , ///< can only be built in towns (arctic/tropic banks, water tower)
INDUSTRYBEH_ONLY_NEARTOWN = 1 < < 5 , ///< is always built near towns (toy shop)
INDUSTRYBEH_PLANT_ON_BUILT = 1 < < 6 , ///< Fields are planted around when built (all farms)
INDUSTRYBEH_DONT_INCR_PROD = 1 < < 7 , ///< do not increase production (oil wells) in the temperate climate
INDUSTRYBEH_BEFORE_1950 = 1 < < 8 , ///< can only be built before 1950 (oil wells)
INDUSTRYBEH_AFTER_1960 = 1 < < 9 , ///< can only be built after 1960 (oil rigs)
INDUSTRYBEH_AI_AIRSHIP_ROUTES = 1 < < 10 , ///< ai will attempt to establish air/ship routes to this industry (oil rig)
INDUSTRYBEH_AIRPLANE_ATTACKS = 1 < < 11 , ///< can be exploded by a military airplane (oil refinery)
INDUSTRYBEH_CHOPPER_ATTACKS = 1 < < 12 , ///< can be exploded by a military helicopter (factory)
INDUSTRYBEH_CAN_SUBSIDENCE = 1 < < 13 , ///< can cause a subsidence (coal mine, shaft that collapses)
/* The following flags are only used for newindustries and do no represent any normal behaviour */
INDUSTRYBEH_PROD_MULTI_HNDLING = 1 < < 14 , ///< Automatic production multiplier handling
INDUSTRYBEH_PRODCALLBACK_RANDOM = 1 < < 15 , ///< Production callback needs random bits in var 10
INDUSTRYBEH_NOBUILT_MAPCREATION = 1 < < 16 , ///< Do not force one instance of this type to appear on map generation
INDUSTRYBEH_CANCLOSE_LASTINSTANCE = 1 < < 17 , ///< Allow closing down the last instance of this type
2018-07-26 17:29:54 +00:00
INDUSTRYBEH_CARGOTYPES_UNLIMITED = 1 < < 18 , ///< Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types
2021-01-18 21:42:10 +00:00
INDUSTRYBEH_NO_PAX_PROD_CLAMP = 1 < < 19 , ///< Do not clamp production of passengers. (smooth economy only)
2009-08-30 11:40:01 +00:00
} ;
2010-03-23 22:25:43 +00:00
DECLARE_ENUM_AS_BIT_SET ( IndustryBehaviour )
2009-08-30 11:40:01 +00:00
2010-02-07 12:04:44 +00:00
/** Flags for miscellaneous industry tile specialities */
enum IndustryTileSpecialFlags {
INDTILE_SPECIAL_NONE = 0 ,
INDTILE_SPECIAL_NEXTFRAME_RANDOMBITS = 1 < < 0 , ///< Callback 0x26 needs random bits
2018-07-26 17:29:54 +00:00
INDTILE_SPECIAL_ACCEPTS_ALL_CARGO = 1 < < 1 , ///< Tile always accepts all cargoes the associated industry accepts
2010-02-07 12:04:44 +00:00
} ;
2010-03-23 22:25:43 +00:00
DECLARE_ENUM_AS_BIT_SET ( IndustryTileSpecialFlags )
2010-02-07 12:04:44 +00:00
2019-10-04 19:26:44 +00:00
/** Definition of one tile in an industry tile layout */
struct IndustryTileLayoutTile {
2009-08-30 11:40:01 +00:00
TileIndexDiffC ti ;
IndustryGfx gfx ;
} ;
2019-10-04 19:26:44 +00:00
/** A complete tile layout for an industry is a list of tiles */
using IndustryTileLayout = std : : vector < IndustryTileLayoutTile > ;
2009-08-30 11:40:01 +00:00
/**
* Defines the data structure for constructing industry .
*/
struct IndustrySpec {
2019-10-04 19:26:44 +00:00
std : : vector < IndustryTileLayout > layouts ; ///< List of possible tile layouts for the industry
2022-05-31 23:30:21 +00:00
std : : vector < uint64 > layout_anim_masks ; ///< Animation inhibit masks for tile layouts for the industry
2018-07-25 17:20:17 +00:00
uint8 cost_multiplier ; ///< Base construction cost multiplier.
uint32 removal_cost_multiplier ; ///< Base removal cost multiplier.
uint32 prospecting_chance ; ///< Chance prospecting succeeds
IndustryType conflicting [ 3 ] ; ///< Industries this industry cannot be close to
byte check_proc ; ///< Index to a procedure to check for conflicting circumstances
CargoID produced_cargo [ INDUSTRY_NUM_OUTPUTS ] ;
byte production_rate [ INDUSTRY_NUM_OUTPUTS ] ;
2011-12-19 17:40:54 +00:00
/**
* minimum amount of cargo transported to the stations .
* If the waiting cargo is less than this number , no cargo is moved to it .
*/
byte minimal_cargo ;
2018-07-25 17:20:17 +00:00
CargoID accepts_cargo [ INDUSTRY_NUM_INPUTS ] ; ///< 16 accepted cargoes.
uint16 input_cargo_multiplier [ INDUSTRY_NUM_INPUTS ] [ INDUSTRY_NUM_OUTPUTS ] ; ///< Input cargo multipliers (multiply amount of incoming cargo for the produced cargoes)
IndustryLifeType life_type ; ///< This is also known as Industry production flag, in newgrf specs
byte climate_availability ; ///< Bitmask, giving landscape enums as bit position
IndustryBehaviour behaviour ; ///< How this industry will behave, and how others entities can use it
byte map_colour ; ///< colour used for the small map
StringID name ; ///< Displayed name of the industry
StringID new_industry_text ; ///< Message appearing when the industry is built
StringID closure_text ; ///< Message appearing when the industry closes
StringID production_up_text ; ///< Message appearing when the industry's production is increasing
StringID production_down_text ; ///< Message appearing when the industry's production is decreasing
StringID station_name ; ///< Default name for nearby station
byte appear_ingame [ NUM_LANDSCAPE ] ; ///< Probability of appearance in game
byte appear_creation [ NUM_LANDSCAPE ] ; ///< Probability of appearance during map creation
uint8 number_of_sounds ; ///< Number of sounds available in the sounds array
const uint8 * random_sounds ; ///< array of random sounds.
2009-08-30 11:40:01 +00:00
/* Newgrf data */
2018-07-25 17:20:17 +00:00
uint16 callback_mask ; ///< Bitmask of industry callbacks that have to be called
uint8 cleanup_flag ; ///< flags indicating which data should be freed upon cleaning up
bool enabled ; ///< entity still available (by default true).newgrf can disable it, though
GRFFileProps grf_prop ; ///< properties related to the grf file
2009-08-30 11:40:01 +00:00
bool IsRawIndustry ( ) const ;
2012-09-08 12:14:00 +00:00
bool IsProcessingIndustry ( ) const ;
2009-08-30 11:40:01 +00:00
Money GetConstructionCost ( ) const ;
Money GetRemovalCost ( ) const ;
2020-12-14 22:35:07 +00:00
bool UsesOriginalEconomy ( ) const ;
2019-10-04 19:26:44 +00:00
~ IndustrySpec ( ) ;
2009-08-30 11:40:01 +00:00
} ;
/**
2013-01-08 22:46:42 +00:00
* Defines the data structure of each individual tile of an industry .
2018-07-25 17:20:17 +00:00
* @ note A tile can at most accept 3 types of cargo , even if an industry as a whole can accept more types .
2009-08-30 11:40:01 +00:00
*/
struct IndustryTileSpec {
2018-07-26 17:29:54 +00:00
CargoID accepts_cargo [ INDUSTRY_NUM_INPUTS ] ; ///< Cargo accepted by this tile
int8 acceptance [ INDUSTRY_NUM_INPUTS ] ; ///< Level of acceptance per cargo type (signed, may be negative!)
2009-08-30 11:40:01 +00:00
Slope slopes_refused ; ///< slope pattern on which this tile cannot be built
byte anim_production ; ///< Animation frame to start when goods are produced
byte anim_next ; ///< Next frame in an animation
2011-12-19 17:40:54 +00:00
/**
* When true , the tile has to be drawn using the animation
* state instead of the construction state
*/
bool anim_state ;
2009-08-30 11:40:01 +00:00
/* Newgrf data */
2009-09-14 12:22:57 +00:00
uint8 callback_mask ; ///< Bitmask of industry tile callbacks that have to be called
2010-08-26 15:31:40 +00:00
AnimationInfo animation ; ///< Information about the animation (is it looping, how many loops etc)
2010-02-07 12:04:44 +00:00
IndustryTileSpecialFlags special_flags ; ///< Bitmask of extra flags used by the tile
2010-11-20 13:33:24 +00:00
bool enabled ; ///< entity still available (by default true).newgrf can disable it, though
GRFFileProps grf_prop ; ///< properties related to the grf file
2009-08-30 11:40:01 +00:00
} ;
/* industry_cmd.cpp*/
const IndustrySpec * GetIndustrySpec ( IndustryType thistype ) ; ///< Array of industries data
const IndustryTileSpec * GetIndustryTileSpec ( IndustryGfx gfx ) ; ///< Array of industry tiles data
void ResetIndustries ( ) ;
/* writable arrays of specs */
extern IndustrySpec _industry_specs [ NUM_INDUSTRYTYPES ] ;
extern IndustryTileSpec _industry_tile_specs [ NUM_INDUSTRYTILES ] ;
2010-03-28 12:25:09 +00:00
/* industry_gui.cpp */
void SortIndustryTypes ( ) ;
/* Industry types sorted alphabetically by name. */
2019-04-13 21:46:11 +00:00
extern std : : array < IndustryType , NUM_INDUSTRYTYPES > _sorted_industry_types ;
2010-03-28 12:25:09 +00:00
2009-12-20 13:45:43 +00:00
/**
* Do industry gfx ID translation for NewGRFs .
* @ param gfx the type to get the override for .
* @ return the gfx to actually work with .
*/
2009-08-30 11:40:01 +00:00
static inline IndustryGfx GetTranslatedIndustryTileID ( IndustryGfx gfx )
{
/* the 0xFF should be GFX_WATERTILE_SPECIALCHECK but for reasons of include mess,
* we ' ll simplify the writing .
* Basically , the first test is required since the GFX_WATERTILE_SPECIALCHECK value
* will never be assigned as a tile index and is only required in order to do some
* tests while building the industry ( as in WATER REQUIRED */
if ( gfx ! = 0xFF ) {
2022-10-22 11:34:54 +00:00
dbg_assert ( gfx < INVALID_INDUSTRYTILE ) ;
2009-08-30 11:40:01 +00:00
const IndustryTileSpec * it = & _industry_tile_specs [ gfx ] ;
return it - > grf_prop . override = = INVALID_INDUSTRYTILE ? gfx : it - > grf_prop . override ;
} else {
return gfx ;
}
}
static const uint8 IT_INVALID = 255 ;
# endif /* INDUSTRYTYPE_H */