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