2005-07-24 16:12:37 +02:00
/* $Id$ */
2004-08-09 19:04:08 +02:00
# ifndef INDUSTRY_H
# define INDUSTRY_H
2006-12-03 18:27:43 +01:00
# include "oldpool.h"
2005-02-02 18:30:29 +01:00
2006-04-28 23:58:16 +02:00
typedef byte IndustryGfx ;
typedef uint8 IndustryType ;
2006-08-20 20:44:26 +02:00
enum {
INVALID_INDUSTRY = 0xFFFF ,
} ;
2006-10-23 18:35:27 +02:00
typedef enum IndustryLifeTypes {
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)
} IndustryLifeType ;
2004-08-09 19:04:08 +02:00
struct Industry {
TileIndex xy ;
byte width ; /* swapped order of w/h with town */
byte height ;
2005-11-13 14:43:55 +01:00
const Town * town ;
2006-03-27 00:23:32 +02:00
CargoID produced_cargo [ 2 ] ;
2004-08-09 19:04:08 +02:00
uint16 cargo_waiting [ 2 ] ;
byte production_rate [ 2 ] ;
2006-03-27 00:23:32 +02:00
CargoID accepts_cargo [ 3 ] ;
2004-08-09 19:04:08 +02:00
byte prod_level ;
uint16 last_mo_production [ 2 ] ;
uint16 last_mo_transported [ 2 ] ;
byte pct_transported [ 2 ] ;
uint16 total_production [ 2 ] ;
uint16 total_transported [ 2 ] ;
uint16 counter ;
byte type ;
2006-03-27 08:18:02 +02:00
byte owner ;
2006-10-24 21:19:25 +02:00
byte random_color ;
2006-08-20 20:40:57 +02:00
Year last_prod_year ;
2004-08-09 19:04:08 +02:00
byte was_cargo_delivered ;
2005-01-06 23:31:58 +01:00
2006-08-20 21:31:58 +02:00
IndustryID index ;
2004-08-09 19:04:08 +02:00
} ;
2006-04-28 23:58:16 +02:00
typedef struct IndustryTileTable {
TileIndexDiffC ti ;
IndustryGfx gfx ;
} IndustryTileTable ;
typedef struct IndustrySpec {
/** Tables with the 'layout' of different composition of GFXes */
const IndustryTileTable * const * table ;
/** Number of elements in the table */
byte num_table ;
/** Base cost multiplier*/
byte cost_multiplier ;
/** Industries this industry cannot be close to */
IndustryType conflicting [ 3 ] ;
/** index to a procedure to check for conflicting circumstances */
byte check_proc ;
CargoID produced_cargo [ 2 ] ;
byte production_rate [ 2 ] ;
/** The 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 ;
CargoID accepts_cargo [ 3 ] ;
2006-10-27 18:18:47 +02:00
IndustryLifeType life_type ; ///< This is also known as Industry production flag, in newgrf specs
2006-10-27 17:54:24 +02:00
2006-10-27 18:18:47 +02:00
byte climate_availability ; ///< Bitmask, giving landscape enums as bit position
2006-10-23 18:35:27 +02:00
2006-10-24 21:19:25 +02:00
StringID name ;
2006-04-28 23:58:16 +02:00
StringID closure_text ;
StringID production_up_text ;
StringID production_down_text ;
} IndustrySpec ;
const IndustrySpec * GetIndustrySpec ( IndustryType thistype ) ;
2006-12-03 18:27:43 +01:00
DECLARE_OLD_POOL ( Industry , Industry , 3 , 8000 )
2005-01-06 23:31:58 +01:00
2005-02-06 23:36:08 +01:00
/**
* Check if an Industry really exists .
*/
2006-08-22 17:33:35 +02:00
static inline bool IsValidIndustry ( const Industry * industry )
2005-02-06 23:36:08 +01:00
{
2006-08-22 17:33:35 +02:00
return industry - > xy ! = 0 ;
2005-02-06 23:36:08 +01:00
}
2006-12-09 15:18:08 +01:00
static inline bool IsValidIndustryID ( IndustryID index )
{
return index < GetIndustryPoolSize ( ) & & IsValidIndustry ( GetIndustry ( index ) ) ;
}
2006-08-22 22:41:26 +02:00
VARDEF int _total_industries ;
2006-12-05 14:58:20 +01:00
static inline IndustryID GetMaxIndustryIndex ( void )
2006-08-22 22:41:26 +02: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 14:58:20 +01:00
* _really_ returns the highest index . Now it just returns
2006-08-22 22:41:26 +02:00
* the next safe value we are sure about everything is below .
*/
2006-12-09 15:14:51 +01:00
return GetIndustryPoolSize ( ) - 1 ;
2006-12-05 14:58:20 +01:00
}
static inline uint GetNumIndustries ( void )
{
2006-08-22 23:17:19 +02:00
return _total_industries ;
2006-08-22 22:41:26 +02:00
}
2006-08-22 23:14:45 +02:00
/**
2006-12-09 15:18:08 +01:00
* Return a random valid industry .
2006-08-22 23:14:45 +02:00
*/
static inline Industry * GetRandomIndustry ( void )
{
2006-12-09 15:18:08 +01:00
int num = RandomRange ( GetNumIndustries ( ) ) ;
IndustryID index = INVALID_INDUSTRY ;
2006-08-22 23:14:45 +02:00
2006-12-05 14:58:20 +01:00
if ( GetNumIndustries ( ) = = 0 ) return NULL ;
2006-08-22 23:14:45 +02:00
2006-12-09 15:18:08 +01:00
while ( num > = 0 ) {
2006-08-22 23:14:45 +02:00
num - - ;
index + + ;
2006-12-09 15:18:08 +01:00
2006-08-22 23:14:45 +02:00
/* Make sure we have a valid industry */
2006-12-09 15:18:08 +01:00
while ( ! IsValidIndustryID ( index ) ) {
2006-08-22 23:14:45 +02:00
index + + ;
2006-12-09 15:18:08 +01:00
assert ( index < = GetMaxIndustryIndex ( ) ) ;
2006-08-22 23:14:45 +02:00
}
}
return GetIndustry ( index ) ;
}
2006-08-26 21:51:49 +02:00
void DestroyIndustry ( Industry * i ) ;
static inline void DeleteIndustry ( Industry * i )
{
DestroyIndustry ( i ) ;
i - > xy = 0 ;
}
2006-10-28 13:32:45 +02: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 18:30:29 +01:00
# define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0)
2006-08-15 09:07:17 +02:00
VARDEF const Industry * * _industry_sort ;
2004-08-09 19:04:08 +02:00
VARDEF bool _industry_sort_dirty ;
2005-02-02 18:30:29 +01:00
2006-04-10 18:20:47 +02:00
2004-08-09 19:04:08 +02:00
void DeleteIndustry ( Industry * is ) ;
2006-08-20 20:44:26 +02:00
void PlantRandomFarmField ( const Industry * i ) ;
2004-08-09 19:04:08 +02:00
enum {
2006-08-22 16:38:37 +02: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 23:00:56 +02:00
IT_END ,
2006-08-22 16:38:37 +02:00
IT_INVALID = 255 ,
2004-08-09 19:04:08 +02:00
} ;
2005-09-18 22:56:44 +02:00
# endif /* INDUSTRY_H */