2005-07-24 14:12:37 +00:00
/* $Id$ */
2007-03-03 04:04:22 +00:00
/** @file industry.h */
2004-08-09 17:04:08 +00:00
# ifndef INDUSTRY_H
# define INDUSTRY_H
2006-12-03 17:27:43 +00:00
# include "oldpool.h"
2007-03-28 20:06:28 +00:00
# include "helpers.hpp"
2005-02-02 17:30:29 +00:00
2006-04-28 21:58:16 +00:00
typedef byte IndustryGfx ;
typedef uint8 IndustryType ;
2006-08-20 18:44:26 +00:00
enum {
INVALID_INDUSTRY = 0xFFFF ,
2007-04-19 14:50:01 +00:00
NUM_INDUSTRYTYPES = 37 ,
2007-03-15 01:17:20 +00:00
INDUTILE_NOANIM = 0xFF , ///< flag to mark industry tiles as having no animation
2006-08-20 18:44:26 +00:00
} ;
2007-03-07 12:11:48 +00:00
enum IndustryLifeType {
2006-10-23 16:35:27 +00:00
INDUSTRYLIFE_NOT_CLOSABLE , ///< Industry can never close
INDUSTRYLIFE_PRODUCTION , ///< Industry can close and change of production
INDUSTRYLIFE_CLOSABLE , ///< Industry can only close (no production change)
2007-03-07 12:11:48 +00:00
} ;
2006-10-23 16:35:27 +00:00
2007-04-09 01:08:11 +00:00
/* Procedures that can be run to check whether an industry may
* build at location the given to the procedure */
enum CheckProc {
CHECK_NOTHING = 0 ,
CHECK_FOREST = 1 ,
CHECK_REFINERY = 2 ,
CHECK_FARM = 3 ,
CHECK_PLANTATION = 4 ,
CHECK_WATER = 5 ,
CHECK_LUMBERMILL = 6 ,
CHECK_BUBBLEGEN = 7 ,
CHECK_OIL_RIG = 8 ,
CHECK_END ,
} ;
2007-03-28 20:06:28 +00:00
enum IndustyBehaviour {
INDUSTRYBEH_NONE = 0 ,
INDUSTRYBEH_PLANT_FIELDS = 1 < < 0 , ///< periodically plants fileds around itself (temp and artic farms)
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 then 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)
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)
} ;
DECLARE_ENUM_AS_BIT_SET ( IndustyBehaviour ) ;
2007-03-03 04:04:22 +00:00
/**
* Defines the internal data of a functionnal industry
*/
2004-08-09 17:04:08 +00:00
struct Industry {
2007-03-03 04:04:22 +00:00
TileIndex xy ; ///< coordinates of the primary tile the industry is built one
byte width ;
2004-08-09 17:04:08 +00:00
byte height ;
2007-03-03 04:04:22 +00:00
const Town * town ; ///< Nearest town
uint16 cargo_waiting [ 2 ] ; ///< amount of cargo produced per cargo
byte production_rate [ 2 ] ; ///< production rate for each cargo
byte prod_level ; ///< general production level
uint16 last_mo_production [ 2 ] ; ///< stats of last month production per cargo
uint16 last_mo_transported [ 2 ] ; ///< stats of last month transport per cargo
byte pct_transported [ 2 ] ; ///< percentage transported per cargo
uint16 total_production [ 2 ] ; ///< total units produced per cargo
uint16 total_transported [ 2 ] ; ///< total units transported per cargo
uint16 counter ; ///< used for animation and/or production (if available cargo)
2007-05-18 17:55:07 +00:00
IndustryType type ; ///< type of industry. see IT_COAL_MINE and others
2007-03-03 04:04:22 +00:00
OwnerByte owner ; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE
byte random_color ; ///< randomized colour of the industry, for display purpose
Year last_prod_year ; ///< last year of production
byte was_cargo_delivered ; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
IndustryID index ; ///< index of the industry in the pool of industries
2004-08-09 17:04:08 +00:00
} ;
2007-03-07 12:11:48 +00:00
struct IndustryTileTable {
2006-04-28 21:58:16 +00:00
TileIndexDiffC ti ;
IndustryGfx gfx ;
2007-03-07 12:11:48 +00:00
} ;
2006-04-28 21:58:16 +00:00
2007-03-03 04:04:22 +00:00
/**
* Defines the data structure for constructing industry .
*/
2007-03-07 12:11:48 +00:00
struct IndustrySpec {
2007-03-03 04:04:22 +00:00
const IndustryTileTable * const * table ; ///< List of the tiles composing the industry
byte num_table ; ///< Number of elements in the table
2007-04-09 01:08:11 +00:00
byte cost_multiplier ; ///< Base cost multiplier. Watch out for this one, << 5 VS << 8
2007-03-03 04:04:22 +00:00
IndustryType conflicting [ 3 ] ; ///< Industries this industry cannot be close to
byte check_proc ; ///< Index to a procedure to check for conflicting circumstances
2006-04-28 21:58:16 +00:00
CargoID produced_cargo [ 2 ] ;
byte production_rate [ 2 ] ;
2007-03-03 04:04:22 +00:00
byte minimal_cargo ; ///< minimum amount of cargo transported to the stations
///< If the waiting cargo is less than this number, no cargo is moved to it
CargoID accepts_cargo [ 3 ] ; ///< 3 accepted cargos
2007-05-17 20:19:55 +00:00
uint16 input_cargo_multiplier [ 3 ] [ 2 ] ; ///< Input cargo multipliers (multiply amount of incoming cargo for the produced cargos)
2007-03-03 04:04:22 +00:00
IndustryLifeType life_type ; ///< This is also known as Industry production flag, in newgrf specs
byte climate_availability ; ///< Bitmask, giving landscape enums as bit position
2007-03-28 20:06:28 +00:00
IndustyBehaviour behaviour ; ///< How this industry will behave, and how others entities can use it
2007-04-09 01:08:11 +00:00
byte map_colour ; ///< colour used for the small map
2007-03-03 04:04:22 +00:00
StringID name ; ///< Displayed name of the industry
2007-03-09 02:04:07 +00:00
StringID new_industry_text ; ///< Message appearing when the industry is built
2007-03-03 04:04:22 +00:00
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
2007-04-03 00:13:59 +00:00
byte appear_ingame [ NUM_LANDSCAPE ] ; ///< Probability of appearance in game
byte appear_creation [ NUM_LANDSCAPE ] ; ///< Probability of appearance during map creation
2007-04-09 01:08:11 +00:00
/* Newgrf stuff coming in */
uint16 callback_flags ; ///< Flags telling which grf callback is set
byte subst_id ;
uint32 grfid ;
byte override ;
2007-03-07 12:11:48 +00:00
} ;
2006-04-28 21:58:16 +00:00
2007-03-03 04:04:22 +00:00
/**
* Defines the data structure of each indivudual tile of an industry .
*/
2007-03-07 12:11:48 +00:00
struct IndustryTileSpec {
2007-03-03 04:04:22 +00:00
CargoID accepts_cargo [ 3 ] ; ///< Cargo accepted by this tile
Slope slopes_refused ; ///< slope pattern on which this tile cannot be built
2007-03-14 02:52:50 +00:00
byte anim_production ; ///< Animation frame to start when goods are produced
byte anim_next ; ///< Next frame in an animation
bool anim_state ; ///< When true, the tile has to be drawn using the animation
2007-05-18 14:34:15 +00:00
///< state instead of the construction state
2007-03-07 12:11:48 +00:00
} ;
2007-02-21 02:22:43 +00:00
2007-05-18 14:34:15 +00:00
/* industry_cmd.cpp*/
2007-03-03 04:04:22 +00:00
const IndustrySpec * GetIndustrySpec ( IndustryType thistype ) ; ///< Array of industries default data
const IndustryTileSpec * GetIndustryTileSpec ( IndustryGfx gfx ) ; ///< Array of industry tiles default data
2007-05-18 14:34:15 +00:00
void ResetIndustries ( ) ;
void PlantRandomFarmField ( const Industry * i ) ;
2006-04-28 21:58:16 +00:00
2007-04-26 20:20:12 +00:00
/* smallmap_gui.cpp */
void BuildIndustriesLegend ( ) ;
2006-12-03 17:27:43 +00:00
DECLARE_OLD_POOL ( Industry , Industry , 3 , 8000 )
2005-01-06 22:31:58 +00:00
2005-02-06 22:36:08 +00:00
/**
* Check if an Industry really exists .
2007-03-03 04:04:22 +00:00
* @ param industry to check
* @ return true if position is a valid one
2005-02-06 22:36:08 +00:00
*/
2006-08-22 15:33:35 +00:00
static inline bool IsValidIndustry ( const Industry * industry )
2005-02-06 22:36:08 +00:00
{
2006-08-22 15:33:35 +00:00
return industry - > xy ! = 0 ;
2005-02-06 22:36:08 +00:00
}
2007-03-03 04:04:22 +00:00
/**
* Check if an Industry exists whithin the pool of industries
* @ param index of the desired industry
* @ return true if it is inside the pool
*/
2006-12-09 14:18:08 +00:00
static inline bool IsValidIndustryID ( IndustryID index )
{
return index < GetIndustryPoolSize ( ) & & IsValidIndustry ( GetIndustry ( index ) ) ;
}
2007-03-03 04:04:22 +00:00
VARDEF int _total_industries ; //general counter
2006-08-22 20:41:26 +00:00
2007-03-07 11:47:46 +00:00
static inline IndustryID GetMaxIndustryIndex ( )
2006-08-22 20:41:26 +00:00
{
/* TODO - This isn't the real content of the function, but
* with the new pool - system this will be replaced with one that
2006-12-05 13:58:20 +00:00
* _really_ returns the highest index . Now it just returns
2006-08-22 20:41:26 +00:00
* the next safe value we are sure about everything is below .
*/
2006-12-09 14:14:51 +00:00
return GetIndustryPoolSize ( ) - 1 ;
2006-12-05 13:58:20 +00:00
}
2007-03-07 11:47:46 +00:00
static inline uint GetNumIndustries ( )
2006-12-05 13:58:20 +00:00
{
2006-08-22 21:17:19 +00:00
return _total_industries ;
2006-08-22 20:41:26 +00:00
}
2006-08-22 21:14:45 +00:00
/**
2006-12-09 14:18:08 +00:00
* Return a random valid industry .
2006-08-22 21:14:45 +00:00
*/
2007-03-07 11:47:46 +00:00
static inline Industry * GetRandomIndustry ( )
2006-08-22 21:14:45 +00:00
{
2006-12-09 14:18:08 +00:00
int num = RandomRange ( GetNumIndustries ( ) ) ;
IndustryID index = INVALID_INDUSTRY ;
2006-08-22 21:14:45 +00:00
2006-12-05 13:58:20 +00:00
if ( GetNumIndustries ( ) = = 0 ) return NULL ;
2006-08-22 21:14:45 +00:00
2006-12-09 14:18:08 +00:00
while ( num > = 0 ) {
2006-08-22 21:14:45 +00:00
num - - ;
index + + ;
2006-12-09 14:18:08 +00:00
2006-08-22 21:14:45 +00:00
/* Make sure we have a valid industry */
2006-12-09 14:18:08 +00:00
while ( ! IsValidIndustryID ( index ) ) {
2006-08-22 21:14:45 +00:00
index + + ;
2006-12-09 14:18:08 +00:00
assert ( index < = GetMaxIndustryIndex ( ) ) ;
2006-08-22 21:14:45 +00:00
}
}
return GetIndustry ( index ) ;
}
2006-08-26 19:51:49 +00:00
void DestroyIndustry ( Industry * i ) ;
static inline void DeleteIndustry ( Industry * i )
{
DestroyIndustry ( i ) ;
i - > xy = 0 ;
}
2006-10-28 11:32:45 +00:00
# define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) if (IsValidIndustry(i))
2005-02-02 17:30:29 +00:00
# define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0)
2006-08-15 07:07:17 +00:00
VARDEF const Industry * * _industry_sort ;
2004-08-09 17:04:08 +00:00
VARDEF bool _industry_sort_dirty ;
2005-02-02 17:30:29 +00:00
2004-08-09 17:04:08 +00:00
enum {
2006-08-22 14:38:37 +00:00
IT_COAL_MINE = 0 ,
IT_POWER_STATION = 1 ,
IT_SAWMILL = 2 ,
IT_FOREST = 3 ,
IT_OIL_REFINERY = 4 ,
IT_OIL_RIG = 5 ,
IT_FACTORY = 6 ,
IT_PRINTING_WORKS = 7 ,
IT_STEEL_MILL = 8 ,
IT_FARM = 9 ,
IT_COPPER_MINE = 10 ,
IT_OIL_WELL = 11 ,
IT_BANK_TEMP = 12 ,
IT_FOOD_PROCESS = 13 ,
IT_PAPER_MILL = 14 ,
IT_GOLD_MINE = 15 ,
IT_BANK_TROPIC_ARCTIC = 16 ,
IT_DIAMOND_MINE = 17 ,
IT_IRON_MINE = 18 ,
IT_FRUIT_PLANTATION = 19 ,
IT_RUBBER_PLANTATION = 20 ,
IT_WATER_SUPPLY = 21 ,
IT_WATER_TOWER = 22 ,
IT_FACTORY_2 = 23 ,
IT_FARM_2 = 24 ,
IT_LUMBER_MILL = 25 ,
IT_COTTON_CANDY = 26 ,
IT_CANDY_FACTORY = 27 ,
IT_BATTERY_FARM = 28 ,
IT_COLA_WELLS = 29 ,
IT_TOY_SHOP = 30 ,
IT_TOY_FACTORY = 31 ,
IT_PLASTIC_FOUNTAINS = 32 ,
IT_FIZZY_DRINK_FACTORY = 33 ,
IT_BUBBLE_GENERATOR = 34 ,
IT_TOFFEE_QUARRY = 35 ,
IT_SUGAR_MINE = 36 ,
2006-04-10 21:00:56 +00:00
IT_END ,
2006-08-22 14:38:37 +00:00
IT_INVALID = 255 ,
2004-08-09 17:04:08 +00:00
} ;
2005-09-18 20:56:44 +00:00
# endif /* INDUSTRY_H */