2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file industry.h Base of all industries. */
|
2007-03-03 04:04:22 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#ifndef INDUSTRY_H
|
|
|
|
#define INDUSTRY_H
|
|
|
|
|
2009-05-22 15:13:50 +00:00
|
|
|
#include "core/pool.hpp"
|
2007-12-21 22:50:51 +00:00
|
|
|
#include "core/random_func.hpp"
|
2007-09-22 13:56:38 +00:00
|
|
|
#include "newgrf_storage.h"
|
2007-12-21 22:50:51 +00:00
|
|
|
#include "cargo_type.h"
|
|
|
|
#include "economy_type.h"
|
2007-12-26 11:45:43 +00:00
|
|
|
#include "map_type.h"
|
2007-12-25 23:42:52 +00:00
|
|
|
#include "slope_type.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_type.h"
|
2008-01-07 14:02:26 +00:00
|
|
|
#include "town_type.h"
|
|
|
|
#include "industry_type.h"
|
2008-05-07 09:07:19 +00:00
|
|
|
#include "landscape_type.h"
|
2006-04-28 21:58:16 +00:00
|
|
|
|
2006-08-20 18:44:26 +00:00
|
|
|
enum {
|
2007-05-29 17:41:59 +00:00
|
|
|
INVALID_INDUSTRY = 0xFFFF,
|
|
|
|
NEW_INDUSTRYOFFSET = 37, ///< original number of industries
|
2007-09-28 21:24:25 +00:00
|
|
|
NUM_INDUSTRYTYPES = 64, ///< total number of industries, new and old
|
2007-05-29 17:41:59 +00:00
|
|
|
INDUSTRYTILE_NOANIM = 0xFF, ///< flag to mark industry tiles as having no animation
|
|
|
|
NEW_INDUSTRYTILEOFFSET = 175, ///< original number of tiles
|
|
|
|
INVALID_INDUSTRYTYPE = NUM_INDUSTRYTYPES, ///< one above amount is considered invalid
|
2007-09-28 21:24:25 +00:00
|
|
|
NUM_INDUSTRYTILES = 512, ///< total number of industry tiles, new and old
|
2007-05-29 17:41:59 +00:00
|
|
|
INVALID_INDUSTRYTILE = NUM_INDUSTRYTILES, ///< one above amount is considered invalid
|
2007-07-20 17:14:03 +00:00
|
|
|
INDUSTRY_COMPLETED = 3, ///< final stage of industry construction.
|
2006-08-20 18:44:26 +00:00
|
|
|
};
|
|
|
|
|
2007-05-31 15:40:36 +00:00
|
|
|
enum {
|
|
|
|
CLEAN_RANDOMSOUNDS, ///< Free the dynamically allocated sounds table
|
|
|
|
CLEAN_TILELSAYOUT, ///< Free the dynamically allocated tile layout structure
|
|
|
|
};
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum IndustryLifeType {
|
2007-07-03 19:16:34 +00:00
|
|
|
INDUSTRYLIFE_BLACK_HOLE = 0, ///< Like power plants and banks
|
|
|
|
INDUSTRYLIFE_EXTRACTIVE = 1 << 0, ///< Like mines
|
|
|
|
INDUSTRYLIFE_ORGANIC = 1 << 1, ///< Like forests
|
|
|
|
INDUSTRYLIFE_PROCESSING = 1 << 2, ///< Like factories
|
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 {
|
2007-07-05 16:26:56 +00:00
|
|
|
CHECK_NOTHING,
|
|
|
|
CHECK_FOREST,
|
|
|
|
CHECK_REFINERY,
|
|
|
|
CHECK_FARM,
|
|
|
|
CHECK_PLANTATION,
|
|
|
|
CHECK_WATER,
|
|
|
|
CHECK_LUMBERMILL,
|
|
|
|
CHECK_BUBBLEGEN,
|
|
|
|
CHECK_OIL_RIG,
|
2007-04-09 01:08:11 +00:00
|
|
|
CHECK_END,
|
|
|
|
};
|
|
|
|
|
2007-07-15 00:03:17 +00:00
|
|
|
/** How was the industry created */
|
2007-07-07 08:53:19 +00:00
|
|
|
enum IndustryConstructionType {
|
2007-07-15 00:03:17 +00:00
|
|
|
ICT_UNKNOWN, ///< in previous game version or without newindustries activated
|
|
|
|
ICT_NORMAL_GAMEPLAY, ///< either by user or random creation proccess
|
|
|
|
ICT_MAP_GENERATION, ///< during random map creation
|
|
|
|
ICT_SCENARIO_EDITOR ///< while scenarion edition
|
|
|
|
};
|
|
|
|
|
2007-10-19 21:14:38 +00:00
|
|
|
enum IndustryBehaviour {
|
2007-03-28 20:06:28 +00:00
|
|
|
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)
|
2008-08-20 01:38:12 +00:00
|
|
|
INDUSTRYBEH_TOWN1200_MORE = 1 << 3, ///< can only be built in towns larger than 1200 inhabitants (temperate bank)
|
2007-03-28 20:06:28 +00:00
|
|
|
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)
|
2007-07-01 17:21:25 +00:00
|
|
|
INDUSTRYBEH_DONT_INCR_PROD = 1 << 7, ///< do not increase production (oil wells) in the temperate climate
|
2007-03-28 20:06:28 +00:00
|
|
|
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)
|
2007-09-22 23:14:32 +00:00
|
|
|
/* The following flags are only used for newindustries and do no represent any normal behaviour */
|
|
|
|
INDUSTRYBEH_PROD_MULTI_HNDLING = 1 << 14, ///< Automatic production multiplier handling
|
|
|
|
INDUSTRYBEH_PRODCALLBACK_RANDOM = 1 << 15, ///< Production callback needs random bits in var 10
|
|
|
|
INDUSTRYBEH_NOBUILT_MAPCREATION = 1 << 16, ///< Do not force one instance of this type to appear on map generation
|
2007-09-22 00:59:27 +00:00
|
|
|
INDUSTRYBEH_CANCLOSE_LASTINSTANCE = 1 << 17, ///< Allow closing down the last instance of this type
|
2007-03-28 20:06:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-10-19 21:14:38 +00:00
|
|
|
DECLARE_ENUM_AS_BIT_SET(IndustryBehaviour);
|
2007-03-28 20:06:28 +00:00
|
|
|
|
2009-05-22 15:13:50 +00:00
|
|
|
typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
|
|
|
|
extern IndustryPool _industry_pool;
|
2007-08-02 23:21:52 +00:00
|
|
|
|
2007-03-03 04:04:22 +00:00
|
|
|
/**
|
|
|
|
* Defines the internal data of a functionnal industry
|
|
|
|
*/
|
2009-05-22 15:13:50 +00:00
|
|
|
struct Industry : IndustryPool::PoolItem<&_industry_pool> {
|
2007-09-22 13:56:38 +00:00
|
|
|
typedef PersistentStorageArray<uint32, 16> PersistentStorage;
|
|
|
|
|
2007-06-07 14:38:45 +00:00
|
|
|
TileIndex xy; ///< coordinates of the primary tile the industry is built one
|
2007-03-03 04:04:22 +00:00
|
|
|
byte width;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte height;
|
2007-06-07 14:38:45 +00:00
|
|
|
const Town *town; ///< Nearest town
|
2007-09-27 21:39:13 +00:00
|
|
|
CargoID produced_cargo[2]; ///< 2 production cargo slots
|
2007-07-04 18:27:21 +00:00
|
|
|
uint16 produced_cargo_waiting[2]; ///< amount of cargo produced per cargo
|
|
|
|
uint16 incoming_cargo_waiting[3]; ///< incoming cargo waiting to be processed
|
2007-06-07 14:38:45 +00:00
|
|
|
byte production_rate[2]; ///< production rate for each cargo
|
|
|
|
byte prod_level; ///< general production level
|
2007-09-27 21:39:13 +00:00
|
|
|
CargoID accepts_cargo[3]; ///< 3 input cargo slots
|
2007-06-07 14:38:45 +00:00
|
|
|
uint16 this_month_production[2]; ///< stats of this month's production per cargo
|
|
|
|
uint16 this_month_transported[2]; ///< stats of this month's transport per cargo
|
|
|
|
byte last_month_pct_transported[2]; ///< percentage transported per cargo in the last full month
|
|
|
|
uint16 last_month_production[2]; ///< total units produced per cargo in the last full month
|
|
|
|
uint16 last_month_transported[2]; ///< total units transported per cargo in the last full month
|
|
|
|
uint16 counter; ///< used for animation and/or production (if available cargo)
|
|
|
|
|
2007-07-24 19:56:43 +00:00
|
|
|
IndustryType type; ///< type of industry.
|
2007-06-07 14:38:45 +00:00
|
|
|
OwnerByte owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE
|
2009-02-09 02:57:15 +00:00
|
|
|
byte random_colour; ///< randomized colour of the industry, for display purpose
|
2007-06-07 14:38:45 +00:00
|
|
|
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
|
|
|
|
|
2007-07-07 08:53:19 +00:00
|
|
|
OwnerByte founder; ///< Founder of the industry
|
|
|
|
Date construction_date; ///< Date of the construction of the industry
|
|
|
|
uint8 construction_type; ///< Way the industry was constructed (@see IndustryConstructionType)
|
|
|
|
Date last_cargo_accepted_at; ///< Last day cargo was accepted by this industry
|
2007-08-15 00:49:34 +00:00
|
|
|
byte selected_layout; ///< Which tile layout was used when creating the industry
|
2007-08-02 23:21:52 +00:00
|
|
|
|
2007-11-11 17:56:37 +00:00
|
|
|
byte random_triggers; ///< Triggers for the random
|
|
|
|
uint16 random; ///< Random value used for randomisation of all kinds of things
|
|
|
|
|
2007-09-22 13:56:38 +00:00
|
|
|
PersistentStorage psa; ///< Persistent storage for NewGRF industries.
|
|
|
|
|
2009-01-03 16:06:58 +00:00
|
|
|
Industry(TileIndex tile = INVALID_TILE) : xy(tile) {}
|
2007-08-02 23:21:52 +00:00
|
|
|
~Industry();
|
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-05-24 01:12:00 +00:00
|
|
|
/** Data related to the handling of grf files. Common to both industry and industry tile */
|
|
|
|
struct GRFFileProps {
|
2007-08-22 00:52:25 +00:00
|
|
|
uint16 subst_id;
|
2007-05-24 01:12:00 +00:00
|
|
|
uint16 local_id; ///< id defined by the grf file for this industry
|
|
|
|
struct SpriteGroup *spritegroup; ///< pointer to the different sprites of the industry
|
2007-06-10 23:40:29 +00:00
|
|
|
const struct GRFFile *grffile; ///< grf file that introduced this industry
|
2007-06-28 19:03:14 +00:00
|
|
|
uint16 override; ///< id of the entity been replaced by
|
2007-05-24 01:12:00 +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 {
|
2009-03-15 16:04:39 +00:00
|
|
|
const IndustryTileTable * const *table;///< List of the tiles composing the industry
|
2007-03-03 04:04:22 +00:00
|
|
|
byte num_table; ///< Number of elements in the table
|
2007-11-27 17:13:49 +00:00
|
|
|
uint8 cost_multiplier; ///< Base construction cost multiplier.
|
|
|
|
uint32 removal_cost_multiplier; ///< Base removal cost multiplier.
|
2007-07-06 07:24:10 +00:00
|
|
|
uint16 raw_industry_cost_multiplier; ///< Multiplier for the raw industries cost
|
|
|
|
uint32 prospecting_chance; ///< Chance prospecting succeeds
|
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-10-19 21:14:38 +00:00
|
|
|
IndustryBehaviour 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
|
2008-04-17 11:47:22 +00:00
|
|
|
StringID name; ///< Displayed name of the industry
|
|
|
|
StringID new_industry_text; ///< Message appearing when the industry is built
|
|
|
|
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
|
|
|
|
StringID station_name; ///< Default name for nearby station
|
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-05-20 00:50:06 +00:00
|
|
|
uint8 number_of_sounds; ///< Number of sounds available in the sounds array
|
|
|
|
const uint8 *random_sounds; ///< array of random sounds.
|
2007-05-24 01:12:00 +00:00
|
|
|
/* Newgrf data */
|
2007-04-09 01:08:11 +00:00
|
|
|
uint16 callback_flags; ///< Flags telling which grf callback is set
|
2007-05-31 15:40:36 +00:00
|
|
|
uint8 cleanup_flag; ///< flags indicating which data should be freed upon cleaning up
|
2007-05-29 14:32:46 +00:00
|
|
|
bool enabled; ///< entity still avaible (by default true).newgrf can disable it, though
|
2007-05-24 01:12:00 +00:00
|
|
|
struct GRFFileProps grf_prop; ///< properties related the the grf file
|
2007-07-06 22:33:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is an industry with the spec a raw industry?
|
|
|
|
* @return true if it should be handled as a raw industry
|
|
|
|
*/
|
|
|
|
bool IsRawIndustry() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the cost for constructing this industry
|
|
|
|
* @return the cost (inflation corrected etc)
|
|
|
|
*/
|
|
|
|
Money GetConstructionCost() const;
|
2007-11-27 17:13:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the cost for removing this industry
|
|
|
|
* Take note that the cost will always be zero for non-grf industries.
|
|
|
|
* Only if the grf author did specified a cost will it be applicable.
|
|
|
|
* @return the cost (inflation corrected etc)
|
|
|
|
*/
|
|
|
|
Money GetRemovalCost() const;
|
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
|
2007-05-29 00:15:34 +00:00
|
|
|
uint8 acceptance[3]; ///< Level of aceptance per cargo type
|
2007-03-03 04:04:22 +00:00
|
|
|
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-05-24 01:12:00 +00:00
|
|
|
/* Newgrf data */
|
2007-05-29 17:41:59 +00:00
|
|
|
uint8 callback_flags; ///< Flags telling which grf callback is set
|
2007-07-11 15:03:29 +00:00
|
|
|
uint16 animation_info; ///< Information about the animation (is it looping, how many loops etc)
|
|
|
|
uint8 animation_speed; ///< The speed of the animation
|
|
|
|
uint8 animation_triggers; ///< When to start the animation
|
|
|
|
uint8 animation_special_flags; ///< Extra flags to influence the animation
|
2007-05-29 14:32:46 +00:00
|
|
|
bool enabled; ///< entity still avaible (by default true).newgrf can disable it, though
|
2007-05-24 01:12:00 +00:00
|
|
|
struct GRFFileProps grf_prop;
|
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-05-29 17:41:59 +00:00
|
|
|
const IndustrySpec *GetIndustrySpec(IndustryType thistype); ///< Array of industries data
|
2007-08-22 01:16:08 +00:00
|
|
|
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx); ///< Array of industry tiles data
|
2007-05-18 14:34:15 +00:00
|
|
|
void ResetIndustries();
|
|
|
|
void PlantRandomFarmField(const Industry *i);
|
2006-04-28 21:58:16 +00:00
|
|
|
|
2008-12-26 19:37:50 +00:00
|
|
|
void ReleaseDisastersTargetingIndustry(IndustryID);
|
|
|
|
|
2007-05-29 17:41:59 +00:00
|
|
|
/* writable arrays of specs */
|
|
|
|
extern IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
|
|
|
|
extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
|
|
|
|
|
2007-08-24 00:23:35 +00:00
|
|
|
static inline IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
|
|
|
|
{
|
2007-08-26 00:23:32 +00:00
|
|
|
/* the 0xFF should be GFX_WATERTILE_SPECIALCHECK but for reasons of include mess,
|
|
|
|
* we'll simplify the writing.
|
|
|
|
* Basically, the first test is required since the GFX_WATERTILE_SPECIALCHECK value
|
|
|
|
* will never be assigned as a tile index and is only required in order to do some
|
|
|
|
* tests while building the industry (as in WATER REQUIRED */
|
|
|
|
if (gfx != 0xFF) {
|
|
|
|
assert(gfx < INVALID_INDUSTRYTILE);
|
|
|
|
const IndustryTileSpec *it = &_industry_tile_specs[gfx];
|
|
|
|
return it->grf_prop.override == INVALID_INDUSTRYTILE ? gfx : it->grf_prop.override;
|
|
|
|
} else {
|
|
|
|
return gfx;
|
|
|
|
}
|
2007-08-24 00:23:35 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 20:20:12 +00:00
|
|
|
/* smallmap_gui.cpp */
|
|
|
|
void BuildIndustriesLegend();
|
2008-09-15 17:18:22 +00:00
|
|
|
/* industry_cmd.cpp */
|
|
|
|
void SetIndustryDailyChanges();
|
2007-04-26 20:20:12 +00:00
|
|
|
|
2007-06-10 01:25:21 +00:00
|
|
|
extern uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame
|
|
|
|
|
2007-06-08 15:48:48 +00:00
|
|
|
/** Increment the count of industries for this type
|
|
|
|
* @param type IndustryType to increment
|
|
|
|
* @pre type < INVALID_INDUSTRYTYPE */
|
|
|
|
static inline void IncIndustryTypeCount(IndustryType type)
|
|
|
|
{
|
|
|
|
assert(type < INVALID_INDUSTRYTYPE);
|
|
|
|
_industry_counts[type]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Decrement the count of industries for this type
|
|
|
|
* @param type IndustryType to decrement
|
|
|
|
* @pre type < INVALID_INDUSTRYTYPE */
|
|
|
|
static inline void DecIndustryTypeCount(IndustryType type)
|
|
|
|
{
|
|
|
|
assert(type < INVALID_INDUSTRYTYPE);
|
|
|
|
_industry_counts[type]--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** get the count of industries for this type
|
|
|
|
* @param type IndustryType to query
|
|
|
|
* @pre type < INVALID_INDUSTRYTYPE */
|
|
|
|
static inline uint8 GetIndustryTypeCount(IndustryType type)
|
|
|
|
{
|
|
|
|
assert(type < INVALID_INDUSTRYTYPE);
|
|
|
|
return min(_industry_counts[type], 0xFF); // callback expects only a byte, so cut it
|
|
|
|
}
|
|
|
|
|
2007-06-10 01:25:21 +00:00
|
|
|
/** Resets both the total_industries and the _industry_counts
|
|
|
|
* This way, we centralize all counts activities */
|
|
|
|
static inline void ResetIndustryCounts()
|
|
|
|
{
|
|
|
|
memset(&_industry_counts, 0, sizeof(_industry_counts));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-05-22 15:23:47 +00:00
|
|
|
if (Industry::GetNumItems() == 0) return NULL;
|
2006-08-22 21:14:45 +00:00
|
|
|
|
2009-05-22 15:23:47 +00:00
|
|
|
int num = RandomRange((uint16)Industry::GetNumItems());
|
|
|
|
IndustryID index = INVALID_INDUSTRY;
|
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 */
|
2009-05-17 01:00:56 +00:00
|
|
|
while (!Industry::IsValidID(index)) {
|
2006-08-22 21:14:45 +00:00
|
|
|
index++;
|
2009-05-17 11:17:53 +00:00
|
|
|
assert(index < Industry::GetPoolSize());
|
2006-08-22 21:14:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
return Industry::Get(index);
|
2006-08-22 21:14:45 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 14:23:36 +00:00
|
|
|
#define FOR_ALL_INDUSTRIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Industry, industry_index, var, start)
|
|
|
|
#define FOR_ALL_INDUSTRIES(var) FOR_ALL_INDUSTRIES_FROM(var, 0)
|
2005-02-02 17:30:29 +00:00
|
|
|
|
2007-07-24 19:56:43 +00:00
|
|
|
static const uint8 IT_INVALID = 255;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
#endif /* INDUSTRY_H */
|