# industrytype.h

Go to the documentation of this file.

    00001 /* $Id: industrytype.h 18563 2009-12-20 13:45:43Z rubidium $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef INDUSTRYTYPE_H
    00013 #define INDUSTRYTYPE_H
    00014
    00015 #include "core/enum_type.hpp"
    00016 #include "economy_type.h"
    00017 #include "map_type.h"
    00018 #include "slope_type.h"
    00019 #include "industry_type.h"
    00020 #include "landscape_type.h"
    00021 #include "tile_type.h"
    00022
    00023 enum {
    00024   CLEAN_RANDOMSOUNDS,
    00025   CLEAN_TILELSAYOUT,
    00026 };
    00027
    00028 enum IndustryLifeType {
    00029   INDUSTRYLIFE_BLACK_HOLE =      0,
    00030   INDUSTRYLIFE_EXTRACTIVE = 1 << 0,
    00031   INDUSTRYLIFE_ORGANIC    = 1 << 1,
    00032   INDUSTRYLIFE_PROCESSING = 1 << 2,
    00033 };
    00034
    00035 /* Procedures that can be run to check whether an industry may
    00036  * build at location the given to the procedure */
    00037 enum CheckProc {
    00038   CHECK_NOTHING,
    00039   CHECK_FOREST,
    00040   CHECK_REFINERY,
    00041   CHECK_FARM,
    00042   CHECK_PLANTATION,
    00043   CHECK_WATER,
    00044   CHECK_LUMBERMILL,
    00045   CHECK_BUBBLEGEN,
    00046   CHECK_OIL_RIG,
    00047   CHECK_END,
    00048 };
    00049
    00051 enum IndustryConstructionType {
    00052   ICT_UNKNOWN,
    00053   ICT_NORMAL_GAMEPLAY,
    00054   ICT_MAP_GENERATION,
    00055   ICT_SCENARIO_EDITOR
    00056 };
    00057
    00058 enum IndustryBehaviour {
    00059   INDUSTRYBEH_NONE                  =      0,
    00060   INDUSTRYBEH_PLANT_FIELDS          = 1 << 0,
    00061   INDUSTRYBEH_CUT_TREES             = 1 << 1,
    00062   INDUSTRYBEH_BUILT_ONWATER         = 1 << 2,
    00063   INDUSTRYBEH_TOWN1200_MORE         = 1 << 3,
    00064   INDUSTRYBEH_ONLY_INTOWN           = 1 << 4,
    00065   INDUSTRYBEH_ONLY_NEARTOWN         = 1 << 5,
    00066   INDUSTRYBEH_PLANT_ON_BUILT        = 1 << 6,
    00067   INDUSTRYBEH_DONT_INCR_PROD        = 1 << 7,
    00068   INDUSTRYBEH_BEFORE_1950           = 1 << 8,
    00069   INDUSTRYBEH_AFTER_1960            = 1 << 9,
    00070   INDUSTRYBEH_AI_AIRSHIP_ROUTES     = 1 << 10,
    00071   INDUSTRYBEH_AIRPLANE_ATTACKS      = 1 << 11,
    00072   INDUSTRYBEH_CHOPPER_ATTACKS       = 1 << 12,
    00073   INDUSTRYBEH_CAN_SUBSIDENCE        = 1 << 13,
    00074   /* The following flags are only used for newindustries and do no represent any normal behaviour */
    00075   INDUSTRYBEH_PROD_MULTI_HNDLING    = 1 << 14,
    00076   INDUSTRYBEH_PRODCALLBACK_RANDOM   = 1 << 15,
    00077   INDUSTRYBEH_NOBUILT_MAPCREATION   = 1 << 16,
    00078   INDUSTRYBEH_CANCLOSE_LASTINSTANCE = 1 << 17,
    00079 };
    00080 DECLARE_ENUM_AS_BIT_SET(IndustryBehaviour);
    00081
    00082 struct IndustryTileTable {
    00083   TileIndexDiffC ti;
    00084   IndustryGfx gfx;
    00085 };
    00086
    00088 struct GRFFileProps {
    00089   uint16 subst_id;
    00090   uint16 local_id;
    00091   struct SpriteGroup *spritegroup;
    00092   const struct GRFFile *grffile;
    00093   uint16 override;
    00094 };
    00095
    00099 struct IndustrySpec {
    00100   const IndustryTileTable * const *table;
    00101   byte num_table;
    00102   uint8 cost_multiplier;
    00103   uint32 removal_cost_multiplier;
    00104   uint32 prospecting_chance;
    00105   IndustryType conflicting[3];
    00106   byte check_proc;
    00107   CargoID produced_cargo[2];
    00108   byte production_rate[2];
    00109   byte minimal_cargo;
    00110
    00111   CargoID accepts_cargo[3];
    00112   uint16 input_cargo_multiplier[3][2];
    00113   IndustryLifeType life_type;
    00114   byte climate_availability;
    00115   IndustryBehaviour behaviour;
    00116   byte map_colour;
    00117   StringID name;
    00118   StringID new_industry_text;
    00119   StringID closure_text;
    00120   StringID production_up_text;
    00121   StringID production_down_text;
    00122   StringID station_name;
    00123   byte appear_ingame[NUM_LANDSCAPE];
    00124   byte appear_creation[NUM_LANDSCAPE];
    00125   uint8 number_of_sounds;
    00126   const uint8 *random_sounds;
    00127   /* Newgrf data */
    00128   uint16 callback_mask;
    00129   uint8 cleanup_flag;
    00130   bool enabled;
    00131   struct GRFFileProps grf_prop;
    00132
    00137   bool IsRawIndustry() const;
    00138
    00143   Money GetConstructionCost() const;
    00144
    00151   Money GetRemovalCost() const;
    00152 };
    00153
    00157 struct IndustryTileSpec {
    00158   CargoID accepts_cargo[3];
    00159   uint8 acceptance[3];
    00160   Slope slopes_refused;
    00161   byte anim_production;
    00162   byte anim_next;
    00163   bool anim_state;
    00164
    00165   /* Newgrf data */
    00166   uint8 callback_mask;
    00167   uint16 animation_info;
    00168   uint8 animation_speed;
    00169   uint8 animation_triggers;
    00170   uint8 animation_special_flags;
    00171   bool enabled;
    00172   struct GRFFileProps grf_prop;
    00173 };
    00174
    00175 /* industry_cmd.cpp*/
    00176 const IndustrySpec *GetIndustrySpec(IndustryType thistype);
    00177 const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx);
    00178 void ResetIndustries();
    00179
    00180 /* writable arrays of specs */
    00181 extern IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
    00182 extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
    00183
    00189 static inline IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
    00190 {
    00191   /* the 0xFF should be GFX_WATERTILE_SPECIALCHECK but for reasons of include mess,
    00192    * we'll simplify the writing.
    00193    * Basically, the first test is required since the GFX_WATERTILE_SPECIALCHECK value
    00194    * will never be assigned as a tile index and is only required in order to do some
    00195    * tests while building the industry (as in WATER REQUIRED */
    00196   if (gfx != 0xFF) {
    00197     assert(gfx < INVALID_INDUSTRYTILE);
    00198     const IndustryTileSpec *it = &_industry_tile_specs[gfx];
    00199     return it->grf_prop.override == INVALID_INDUSTRYTILE ? gfx : it->grf_prop.override;
    00200   } else {
    00201     return gfx;
    00202   }
    00203 }
    00204
    00205 extern uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame
    00206
    00210 static inline void IncIndustryTypeCount(IndustryType type)
    00211 {
    00212   assert(type < INVALID_INDUSTRYTYPE);
    00213   _industry_counts[type]++;
    00214 }
    00215
    00219 static inline void DecIndustryTypeCount(IndustryType type)
    00220 {
    00221   assert(type < INVALID_INDUSTRYTYPE);
    00222   _industry_counts[type]--;
    00223 }
    00224
    00228 static inline uint8 GetIndustryTypeCount(IndustryType type)
    00229 {
    00230   assert(type < INVALID_INDUSTRYTYPE);
    00231   return min(_industry_counts[type], 0xFF); // callback expects only a byte, so cut it
    00232 }
    00233
    00236 static inline void ResetIndustryCounts()
    00237 {
    00238   memset(&_industry_counts, 0, sizeof(_industry_counts));
    00239 }
    00240
    00241 static const uint8 IT_INVALID = 255;
    00242
    00243 #endif /* INDUSTRYTYPE_H */