Also scroll tile separators in the train depot
[openttd/fttd.git] / src / industrytype.h
blob79c1d074acaeeb3f5406f1ab08999c7099f3cdbd
1 /* $Id$ */
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 "slope_type.h"
16 #include "industry_type.h"
17 #include "landscape_type.h"
18 #include "cargo_type.h"
19 #include "newgrf_animation_type.h"
20 #include "newgrf_commons.h"
21 #include "map/class.h"
22 #include "map/industry.h"
24 enum IndustryCleanupType {
25 CLEAN_RANDOMSOUNDS, ///< Free the dynamically allocated sounds table
26 CLEAN_TILELAYOUT, ///< Free the dynamically allocated tile layout structure
29 /** Available types of industry lifetimes. */
30 enum IndustryLifeType {
31 INDUSTRYLIFE_BLACK_HOLE = 0, ///< Like power plants and banks
32 INDUSTRYLIFE_EXTRACTIVE = 1 << 0, ///< Like mines
33 INDUSTRYLIFE_ORGANIC = 1 << 1, ///< Like forests
34 INDUSTRYLIFE_PROCESSING = 1 << 2, ///< Like factories
37 /**
38 * Available procedures to check whether an industry may build at a given location.
39 * @see CheckNewIndustryProc, _check_new_industry_procs[]
41 enum CheckProc {
42 CHECK_NOTHING, ///< Always succeeds.
43 CHECK_FOREST, ///< %Industry should be build above snow-line in arctic climate.
44 CHECK_REFINERY, ///< %Industry should be positioned near edge of the map.
45 CHECK_FARM, ///< %Industry should be below snow-line in arctic.
46 CHECK_PLANTATION, ///< %Industry should NOT be in the desert.
47 CHECK_WATER, ///< %Industry should be in the desert.
48 CHECK_LUMBERMILL, ///< %Industry should be in the rain forest.
49 CHECK_BUBBLEGEN, ///< %Industry should be in low land.
50 CHECK_OIL_RIG, ///< Industries at sea should be positioned near edge of the map.
51 CHECK_END, ///< End marker of the industry check procedures.
54 /** How was the industry created */
55 enum IndustryConstructionType {
56 ICT_UNKNOWN, ///< in previous game version or without newindustries activated
57 ICT_NORMAL_GAMEPLAY, ///< either by user or random creation process
58 ICT_MAP_GENERATION, ///< during random map creation
59 ICT_SCENARIO_EDITOR, ///< while editing a scenario
62 /** Various industry behaviours mostly to represent original TTD specialities */
63 enum IndustryBehaviour {
64 INDUSTRYBEH_NONE = 0,
65 INDUSTRYBEH_PLANT_FIELDS = 1 << 0, ///< periodically plants fields around itself (temp and arctic farms)
66 INDUSTRYBEH_CUT_TREES = 1 << 1, ///< cuts trees and produce first output cargo from them (lumber mill)
67 INDUSTRYBEH_BUILT_ONWATER = 1 << 2, ///< is built on water (oil rig)
68 INDUSTRYBEH_TOWN1200_MORE = 1 << 3, ///< can only be built in towns larger than 1200 inhabitants (temperate bank)
69 INDUSTRYBEH_ONLY_INTOWN = 1 << 4, ///< can only be built in towns (arctic/tropic banks, water tower)
70 INDUSTRYBEH_ONLY_NEARTOWN = 1 << 5, ///< is always built near towns (toy shop)
71 INDUSTRYBEH_PLANT_ON_BUILT = 1 << 6, ///< Fields are planted around when built (all farms)
72 INDUSTRYBEH_DONT_INCR_PROD = 1 << 7, ///< do not increase production (oil wells) in the temperate climate
73 INDUSTRYBEH_BEFORE_1950 = 1 << 8, ///< can only be built before 1950 (oil wells)
74 INDUSTRYBEH_AFTER_1960 = 1 << 9, ///< can only be built after 1960 (oil rigs)
75 INDUSTRYBEH_AI_AIRSHIP_ROUTES = 1 << 10, ///< ai will attempt to establish air/ship routes to this industry (oil rig)
76 INDUSTRYBEH_AIRPLANE_ATTACKS = 1 << 11, ///< can be exploded by a military airplane (oil refinery)
77 INDUSTRYBEH_CHOPPER_ATTACKS = 1 << 12, ///< can be exploded by a military helicopter (factory)
78 INDUSTRYBEH_CAN_SUBSIDENCE = 1 << 13, ///< can cause a subsidence (coal mine, shaft that collapses)
79 /* The following flags are only used for newindustries and do no represent any normal behaviour */
80 INDUSTRYBEH_PROD_MULTI_HNDLING = 1 << 14, ///< Automatic production multiplier handling
81 INDUSTRYBEH_PRODCALLBACK_RANDOM = 1 << 15, ///< Production callback needs random bits in var 10
82 INDUSTRYBEH_NOBUILT_MAPCREATION = 1 << 16, ///< Do not force one instance of this type to appear on map generation
83 INDUSTRYBEH_CANCLOSE_LASTINSTANCE = 1 << 17, ///< Allow closing down the last instance of this type
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
92 DECLARE_ENUM_AS_BIT_SET(IndustryTileSpecialFlags)
94 struct IndustryTileTable {
95 CoordDiff ti;
96 IndustryGfx gfx;
99 /**
100 * Defines the data structure for constructing industry.
102 struct IndustrySpec {
103 const IndustryTileTable * const *table;///< List of the tiles composing the industry
104 byte num_table; ///< Number of elements in the table
105 uint8 cost_multiplier; ///< Base construction cost multiplier.
106 uint32 removal_cost_multiplier; ///< Base removal cost multiplier.
107 uint32 prospecting_chance; ///< Chance prospecting succeeds
108 IndustryType conflicting[3]; ///< Industries this industry cannot be close to
109 byte check_proc; ///< Index to a procedure to check for conflicting circumstances
110 CargoID produced_cargo[2];
111 byte production_rate[2];
113 * minimum amount of cargo transported to the stations.
114 * If the waiting cargo is less than this number, no cargo is moved to it.
116 byte minimal_cargo;
117 CargoID accepts_cargo[3]; ///< 3 accepted cargoes.
118 uint16 input_cargo_multiplier[3][2]; ///< Input cargo multipliers (multiply amount of incoming cargo for the produced cargoes)
119 IndustryLifeType life_type; ///< This is also known as Industry production flag, in newgrf specs
120 byte climate_availability; ///< Bitmask, giving landscape enums as bit position
121 IndustryBehaviour behaviour; ///< How this industry will behave, and how others entities can use it
122 byte map_colour; ///< colour used for the small map
123 StringID name; ///< Displayed name of the industry
124 StringID new_industry_text; ///< Message appearing when the industry is built
125 StringID closure_text; ///< Message appearing when the industry closes
126 StringID production_up_text; ///< Message appearing when the industry's production is increasing
127 StringID production_down_text; ///< Message appearing when the industry's production is decreasing
128 StringID station_name; ///< Default name for nearby station
129 byte appear_ingame[NUM_LANDSCAPE]; ///< Probability of appearance in game
130 byte appear_creation[NUM_LANDSCAPE]; ///< Probability of appearance during map creation
131 uint8 number_of_sounds; ///< Number of sounds available in the sounds array
132 const uint8 *random_sounds; ///< array of random sounds.
133 /* Newgrf data */
134 uint16 callback_mask; ///< Bitmask of industry callbacks that have to be called
135 uint8 cleanup_flag; ///< flags indicating which data should be freed upon cleaning up
136 bool enabled; ///< entity still available (by default true).newgrf can disable it, though
137 GRFFileProps grf_prop; ///< properties related to the grf file
139 bool IsRawIndustry() const;
140 bool IsProcessingIndustry() const;
141 Money GetConstructionCost() const;
142 Money GetRemovalCost() const;
143 bool UsesSmoothEconomy() const;
147 * Defines the data structure of each individual tile of an industry.
149 struct IndustryTileSpec {
150 CargoID accepts_cargo[3]; ///< Cargo accepted by this tile
151 uint8 acceptance[3]; ///< Level of acceptance per cargo type
152 Slope slopes_refused; ///< slope pattern on which this tile cannot be built
153 byte anim_production; ///< Animation frame to start when goods are produced
154 byte anim_next; ///< Next frame in an animation
156 * When true, the tile has to be drawn using the animation
157 * state instead of the construction state
159 bool anim_state;
160 /* Newgrf data */
161 uint8 callback_mask; ///< Bitmask of industry tile callbacks that have to be called
162 AnimationInfo animation; ///< Information about the animation (is it looping, how many loops etc)
163 IndustryTileSpecialFlags special_flags; ///< Bitmask of extra flags used by the tile
164 bool enabled; ///< entity still available (by default true).newgrf can disable it, though
165 GRFFileProps grf_prop; ///< properties related to the grf file
168 /* industry_cmd.cpp*/
169 const IndustrySpec *GetIndustrySpec(IndustryType thistype); ///< Array of industries data
170 const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx); ///< Array of industry tiles data
171 void ResetIndustries();
173 /* writable arrays of specs */
174 extern IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
175 extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
177 /* industry_gui.cpp */
178 void SortIndustryTypes();
179 /* Industry types sorted alphabetically by name. */
180 extern IndustryType _sorted_industry_types[NUM_INDUSTRYTYPES];
183 * Do industry gfx ID translation for NewGRFs.
184 * @param gfx the type to get the override for.
185 * @return the gfx to actually work with.
187 static inline IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
189 /* the 0xFF should be GFX_WATERTILE_SPECIALCHECK but for reasons of include mess,
190 * we'll simplify the writing.
191 * Basically, the first test is required since the GFX_WATERTILE_SPECIALCHECK value
192 * will never be assigned as a tile index and is only required in order to do some
193 * tests while building the industry (as in WATER REQUIRED */
194 if (gfx != 0xFF) {
195 assert(gfx < INVALID_INDUSTRYTILE);
196 const IndustryTileSpec *it = &_industry_tile_specs[gfx];
197 return it->grf_prop.override == INVALID_INDUSTRYTILE ? gfx : it->grf_prop.override;
198 } else {
199 return gfx;
204 * Get the industry graphics ID for the given industry tile
205 * @param t the tile to get the gfx for
206 * @pre IsIndustryTile(t)
207 * @return the gfx ID
209 static inline IndustryGfx GetIndustryGfx(TileIndex t)
211 assert(IsIndustryTile(t));
212 return GetTranslatedIndustryTileID(GetCleanIndustryGfx(t));
215 static const uint8 IT_INVALID = 255;
218 * The following enums are indices used to know what to draw for this industry tile.
219 * They all are pointing toward array _industry_draw_tile_data, in table/industry_land.h
220 * How to calculate the correct position ? GFXid << 2 | IndustryStage (0 to 3)
222 enum IndustryGraphics {
223 GFX_COAL_MINE_TOWER_NOT_ANIMATED = 0,
224 GFX_COAL_MINE_TOWER_ANIMATED = 1,
225 GFX_POWERPLANT_CHIMNEY = 8,
226 GFX_POWERPLANT_SPARKS = 10,
227 GFX_OILRIG_1 = 24,
228 GFX_OILRIG_2 = 25,
229 GFX_OILRIG_3 = 26,
230 GFX_OILRIG_4 = 27,
231 GFX_OILRIG_5 = 28,
232 GFX_OILWELL_NOT_ANIMATED = 29,
233 GFX_OILWELL_ANIMATED_1 = 30,
234 GFX_OILWELL_ANIMATED_2 = 31,
235 GFX_OILWELL_ANIMATED_3 = 32,
236 GFX_COPPER_MINE_TOWER_NOT_ANIMATED = 47,
237 GFX_COPPER_MINE_TOWER_ANIMATED = 48,
238 GFX_COPPER_MINE_CHIMNEY = 49,
239 GFX_GOLD_MINE_TOWER_NOT_ANIMATED = 79,
240 GFX_GOLD_MINE_TOWER_ANIMATED = 88,
241 GFX_TOY_FACTORY = 143,
242 GFX_PLASTIC_FOUNTAIN_ANIMATED_1 = 148,
243 GFX_PLASTIC_FOUNTAIN_ANIMATED_2 = 149,
244 GFX_PLASTIC_FOUNTAIN_ANIMATED_3 = 150,
245 GFX_PLASTIC_FOUNTAIN_ANIMATED_4 = 151,
246 GFX_PLASTIC_FOUNTAIN_ANIMATED_5 = 152,
247 GFX_PLASTIC_FOUNTAIN_ANIMATED_6 = 153,
248 GFX_PLASTIC_FOUNTAIN_ANIMATED_7 = 154,
249 GFX_PLASTIC_FOUNTAIN_ANIMATED_8 = 155,
250 GFX_BUBBLE_GENERATOR = 161,
251 GFX_BUBBLE_CATCHER = 162,
252 GFX_TOFFEE_QUARY = 165,
253 GFX_SUGAR_MINE_SIEVE = 174,
254 GFX_WATERTILE_SPECIALCHECK = 255, ///< not really a tile, but rather a very special check
257 IndustryType GetIndustryType(TileIndex tile);
259 #endif /* INDUSTRYTYPE_H */