src/industry.h
author glx
Tue, 12 Jun 2007 18:02:11 +0000
branchnoai
changeset 9626 79f2b5a0cdd7
parent 9625 3301b1b3889c
child 9631 8a2d1c2ceb88
permissions -rw-r--r--
(svn r10118) [NoAI] -Sync with trunk r10015:r10096
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 1330
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 1330
diff changeset
     2
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
     3
/** @file industry.h */
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#ifndef INDUSTRY_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#define INDUSTRY_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
5216
d581e4db95b6 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4976
diff changeset
     8
#include "oldpool.h"
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
     9
#include "helpers.hpp"
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
    10
3689
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    11
typedef byte IndustryGfx;
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    12
typedef uint8 IndustryType;
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    13
4328
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
    14
enum {
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    15
	INVALID_INDUSTRY       = 0xFFFF,
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    16
	NEW_INDUSTRYOFFSET     = 37,                         ///< original number of industries
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    17
	NUM_INDUSTRYTYPES      = 37,                         ///< total number of industries, new and old
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    18
	INDUSTRYTILE_NOANIM    = 0xFF,                       ///< flag to mark industry tiles as having no animation
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    19
	NEW_INDUSTRYTILEOFFSET = 175,                        ///< original number of tiles
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    20
	INVALID_INDUSTRYTYPE   = NUM_INDUSTRYTYPES,          ///< one above amount is considered invalid
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    21
	NUM_INDUSTRYTILES      = NEW_INDUSTRYTILEOFFSET,     ///< total number of industry tiles, new and old
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    22
	INVALID_INDUSTRYTILE   = NUM_INDUSTRYTILES,          ///< one above amount is considered invalid
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    23
};
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    24
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    25
enum {
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    26
	CLEAN_RANDOMSOUNDS,    ///< Free the dynamically allocated sounds table
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    27
	CLEAN_TILELSAYOUT,     ///< Free the dynamically allocated tile layout structure
4328
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
    28
};
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
    29
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    30
enum IndustryLifeType {
4924
6e29520a0ba8 (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    31
	INDUSTRYLIFE_NOT_CLOSABLE,     ///< Industry can never close
6e29520a0ba8 (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    32
	INDUSTRYLIFE_PRODUCTION,       ///< Industry can close and change of production
6e29520a0ba8 (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    33
	INDUSTRYLIFE_CLOSABLE,         ///< Industry can only close (no production change)
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    34
};
4924
6e29520a0ba8 (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    35
9599
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    36
/* Procedures that can be run to check whether an industry may
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    37
 * build at location the given to the procedure */
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    38
enum CheckProc {
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    39
	CHECK_NOTHING    = 0,
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    40
	CHECK_FOREST     = 1,
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    41
	CHECK_REFINERY   = 2,
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    42
	CHECK_FARM       = 3,
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    43
	CHECK_PLANTATION = 4,
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    44
	CHECK_WATER      = 5,
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    45
	CHECK_LUMBERMILL = 6,
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    46
	CHECK_BUBBLEGEN  = 7,
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    47
	CHECK_OIL_RIG    = 8,
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    48
	CHECK_END,
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    49
};
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
    50
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    51
enum IndustyBehaviour {
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    52
	INDUSTRYBEH_NONE                  =      0,
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    53
	INDUSTRYBEH_PLANT_FIELDS          = 1 << 0,  ///< periodically plants fileds around itself (temp and artic farms)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    54
	INDUSTRYBEH_CUT_TREES             = 1 << 1,  ///< cuts trees and produce first output cargo from them (lumber mill)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    55
	INDUSTRYBEH_BUILT_ONWATER         = 1 << 2,  ///< is built on water (oil rig)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    56
	INDUSTRYBEH_TOWN1200_MORE         = 1 << 3,  ///< can only be built in towns larger then 1200 inhabitants (temperate bank)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    57
	INDUSTRYBEH_ONLY_INTOWN           = 1 << 4,  ///< can only be built in towns (arctic/tropic banks, water tower)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    58
	INDUSTRYBEH_ONLY_NEARTOWN         = 1 << 5,  ///< is always built near towns (toy shop)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    59
	INDUSTRYBEH_PLANT_ON_BUILT        = 1 << 6,  ///< Fields are planted around when built (all farms)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    60
	INDUSTRYBEH_DONT_INCR_PROD        = 1 << 7,  ///< do not increase production (oil wells)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    61
	INDUSTRYBEH_BEFORE_1950           = 1 << 8,  ///< can only be built before 1950 (oil wells)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    62
	INDUSTRYBEH_AFTER_1960            = 1 << 9,  ///< can only be built after 1960 (oil rigs)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    63
	INDUSTRYBEH_AI_AIRSHIP_ROUTES     = 1 << 10, ///< ai will attempt to establish air/ship routes to this industry (oil rig)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    64
	INDUSTRYBEH_AIRPLANE_ATTACKS      = 1 << 11, ///< can be exploded by a military airplane (oil refinery)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    65
	INDUSTRYBEH_CHOPPER_ATTACKS       = 1 << 12, ///< can be exploded by a military helicopter (factory)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    66
	INDUSTRYBEH_CAN_SUBSIDENCE        = 1 << 13, ///< can cause a subsidence (coal mine, shaft that collapses)
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    67
};
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    68
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    69
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    70
DECLARE_ENUM_AS_BIT_SET(IndustyBehaviour);
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
    71
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
    72
/**
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
    73
 * Defines the internal data of a functionnal industry
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
    74
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
struct Industry {
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    76
	TileIndex xy;                       ///< coordinates of the primary tile the industry is built one
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
    77
	byte width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
	byte height;
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    79
	const Town *town;                   ///< Nearest town
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    80
	uint16 cargo_waiting[2];            ///< amount of cargo produced per cargo
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    81
	byte production_rate[2];            ///< production rate for each cargo
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    82
	byte prod_level;                    ///< general production level
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    83
	uint16 this_month_production[2];    ///< stats of this month's production per cargo
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    84
	uint16 this_month_transported[2];   ///< stats of this month's transport per cargo
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    85
	byte last_month_pct_transported[2]; ///< percentage transported per cargo in the last full month
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    86
	uint16 last_month_production[2];    ///< total units produced per cargo in the last full month
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    87
	uint16 last_month_transported[2];   ///< total units transported per cargo in the last full month
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    88
	uint16 counter;                     ///< used for animation and/or production (if available cargo)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    90
	IndustryType type;                  ///< type of industry. see IT_COAL_MINE and others
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    91
	OwnerByte owner;                    ///< owner of the industry.  Which SHOULD always be (imho) OWNER_NONE
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    92
	byte random_color;                  ///< randomized colour of the industry, for display purpose
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    93
	Year last_prod_year;                ///< last year of production
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    94
	byte was_cargo_delivered;           ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 830
diff changeset
    95
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
    96
	IndustryID index;                   ///< index of the industry in the pool of industries
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    99
struct IndustryTileTable {
3689
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   100
	TileIndexDiffC ti;
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   101
	IndustryGfx gfx;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   102
};
3689
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   103
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   104
/** Data related to the handling of grf files.  Common to both industry and industry tile */
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   105
struct GRFFileProps {
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   106
	uint8 subst_id;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   107
	uint16 local_id;                      ///< id defined by the grf file for this industry
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   108
	struct SpriteGroup *spritegroup;      ///< pointer to the different sprites of the industry
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   109
	const struct GRFFile *grffile;        ///< grf file that introduced this industry
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   110
	uint8 override;                       ///< id of the entity been replaced by
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   111
};
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   112
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   113
/**
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   114
 * Defines the data structure for constructing industry.
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   115
 */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   116
struct IndustrySpec {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   117
	const IndustryTileTable *const *table;///< List of the tiles composing the industry
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   118
	byte num_table;                       ///< Number of elements in the table
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   119
	uint16 cost_multiplier;               ///< Base cost multiplier.
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   120
	IndustryType conflicting[3];          ///< Industries this industry cannot be close to
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   121
	byte check_proc;                      ///< Index to a procedure to check for conflicting circumstances
3689
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   122
	CargoID produced_cargo[2];
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   123
	byte production_rate[2];
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   124
	byte minimal_cargo;                   ///< minimum amount of cargo transported to the stations
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   125
	                                      ///< If the waiting cargo is less than this number, no cargo is moved to it
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   126
	CargoID accepts_cargo[3];             ///< 3 accepted cargos
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   127
	uint16 input_cargo_multiplier[3][2];  ///< Input cargo multipliers (multiply amount of incoming cargo for the produced cargos)
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   128
	IndustryLifeType life_type;           ///< This is also known as Industry production flag, in newgrf specs
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   129
	byte climate_availability;            ///< Bitmask, giving landscape enums as bit position
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
   130
	IndustyBehaviour behaviour;           ///< How this industry will behave, and how others entities can use it
9599
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
   131
	byte map_colour;                      ///< colour used for the small map
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   132
	StringID name;                        ///< Displayed name of the industry
6592
fe9298ade0a8 (svn r9075) -Codechange: Cleanup of industry_cmd (Step-7). Small step that is. The new industry messages do not need a series of tests. Only one property to use.
belugas
parents: 6574
diff changeset
   133
	StringID new_industry_text;           ///< Message appearing when the industry is built
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   134
	StringID closure_text;                ///< Message appearing when the industry closes
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   135
	StringID production_up_text;          ///< Message appearing when the industry's production is increasing
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   136
	StringID production_down_text;        ///< Message appearing when the industry's production is decreasing
9574
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
   137
	byte appear_ingame[NUM_LANDSCAPE];    ///< Probability of appearance in game
698395509d12 (svn r9575) [NoAI] -Sync with trunk r9504:9574
glx
parents: 9403
diff changeset
   138
	byte appear_creation[NUM_LANDSCAPE];  ///< Probability of appearance during map creation
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   139
	uint8 number_of_sounds;               ///< Number of sounds available in the sounds array
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   140
	const uint8 *random_sounds;           ///< array of random sounds.
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   141
	/* Newgrf data */
9599
949374e83b78 (svn r9632) [NoAI] -Sync with trunk r9574:9631.
rubidium
parents: 9574
diff changeset
   142
	uint16 callback_flags;                ///< Flags telling which grf callback is set
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
   143
	uint8 cleanup_flag;                   ///< flags indicating which data should be freed upon cleaning up
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
   144
	bool enabled;                         ///< entity still avaible (by default true).newgrf can disable it, though
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   145
	struct GRFFileProps grf_prop;         ///< properties related the the grf file
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   146
};
3689
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   147
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   148
/**
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   149
 * Defines the data structure of each indivudual tile of an industry.
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   150
 */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   151
struct IndustryTileSpec {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   152
	CargoID accepts_cargo[3];             ///< Cargo accepted by this tile
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
   153
	uint8 acceptance[3];                  ///< Level of aceptance per cargo type
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   154
	Slope slopes_refused;                 ///< slope pattern on which this tile cannot be built
9403
0a2377009af4 (svn r9200) [NoAI] -Sync with trunk r9138:9198.
rubidium
parents: 6592
diff changeset
   155
	byte anim_production;                 ///< Animation frame to start when goods are produced
0a2377009af4 (svn r9200) [NoAI] -Sync with trunk r9138:9198.
rubidium
parents: 6592
diff changeset
   156
	byte anim_next;                       ///< Next frame in an animation
0a2377009af4 (svn r9200) [NoAI] -Sync with trunk r9138:9198.
rubidium
parents: 6592
diff changeset
   157
	bool anim_state;                      ///< When true, the tile has to be drawn using the animation
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   158
	                                      ///< state instead of the construction state
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   159
	/* Newgrf data */
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
   160
	uint8 callback_flags;                 ///< Flags telling which grf callback is set
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
   161
	bool enabled;                         ///< entity still avaible (by default true).newgrf can disable it, though
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   162
	struct GRFFileProps grf_prop;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   163
};
6418
a80dba2d8243 (svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents: 5838
diff changeset
   164
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   165
/* industry_cmd.cpp*/
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
   166
const IndustrySpec *GetIndustrySpec(IndustryType thistype);    ///< Array of industries data
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
   167
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx);  ///< Array of industry tiles data
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   168
void ResetIndustries();
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   169
void PlantRandomFarmField(const Industry *i);
3689
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   170
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
   171
/* writable arrays of specs */
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
   172
extern IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
   173
extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
   174
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   175
/* smallmap_gui.cpp */
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   176
void BuildIndustriesLegend();
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   177
5216
d581e4db95b6 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4976
diff changeset
   178
DECLARE_OLD_POOL(Industry, Industry, 3, 8000)
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 830
diff changeset
   179
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
   180
/**
1330
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1267
diff changeset
   181
 * Check if an Industry really exists.
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   182
 * @param industry to check
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   183
 * @return true if position is a valid one
1330
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1267
diff changeset
   184
 */
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   185
static inline bool IsValidIndustry(const Industry *industry)
1330
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1267
diff changeset
   186
{
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   187
	return industry->xy != 0;
1330
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1267
diff changeset
   188
}
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1267
diff changeset
   189
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   190
/**
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   191
 * Check if an Industry exists whithin the pool of industries
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   192
 * @param index of the desired industry
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   193
 * @return true if it is inside the pool
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   194
 */
5299
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   195
static inline bool IsValidIndustryID(IndustryID index)
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   196
{
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   197
	return index < GetIndustryPoolSize() && IsValidIndustry(GetIndustry(index));
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   198
}
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   199
4354
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   200
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   201
static inline IndustryID GetMaxIndustryIndex()
4354
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   202
{
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   203
	/* TODO - This isn't the real content of the function, but
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   204
	 *  with the new pool-system this will be replaced with one that
5247
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   205
	 *  _really_ returns the highest index. Now it just returns
4354
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   206
	 *  the next safe value we are sure about everything is below.
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   207
	 */
5298
6d4c150bdd94 (svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
rubidium
parents: 5247
diff changeset
   208
	return GetIndustryPoolSize() - 1;
5247
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   209
}
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   210
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   211
extern int _total_industries;  // general counter
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   212
extern uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   213
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   214
static inline uint GetNumIndustries()
5247
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   215
{
4357
3d72606e9192 (svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
truelight
parents: 4356
diff changeset
   216
	return _total_industries;
4354
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   217
}
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   218
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   219
/** Increment the count of industries for this type
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   220
 * @param type IndustryType to increment
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   221
 * @pre type < INVALID_INDUSTRYTYPE */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   222
static inline void IncIndustryTypeCount(IndustryType type)
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   223
{
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   224
	assert(type < INVALID_INDUSTRYTYPE);
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   225
	_industry_counts[type]++;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   226
	_total_industries++;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   227
}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   228
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   229
/** Decrement the count of industries for this type
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   230
 * @param type IndustryType to decrement
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   231
 * @pre type < INVALID_INDUSTRYTYPE */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   232
static inline void DecIndustryTypeCount(IndustryType type)
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   233
{
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   234
	assert(type < INVALID_INDUSTRYTYPE);
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   235
	_industry_counts[type]--;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   236
	_total_industries--;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   237
}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   238
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   239
/** get the count of industries for this type
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   240
 * @param type IndustryType to query
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   241
 * @pre type < INVALID_INDUSTRYTYPE */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   242
static inline uint8 GetIndustryTypeCount(IndustryType type)
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   243
{
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   244
	assert(type < INVALID_INDUSTRYTYPE);
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   245
	return min(_industry_counts[type], 0xFF); // callback expects only a byte, so cut it
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   246
}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   247
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   248
/** Resets both the total_industries and the _industry_counts
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   249
 * This way, we centralize all counts activities */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   250
static inline void ResetIndustryCounts()
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   251
{
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   252
	_total_industries = 0;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   253
	memset(&_industry_counts, 0, sizeof(_industry_counts));
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   254
}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   255
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   256
/**
5299
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   257
 * Return a random valid industry.
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   258
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   259
static inline Industry *GetRandomIndustry()
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   260
{
5299
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   261
	int num = RandomRange(GetNumIndustries());
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   262
	IndustryID index = INVALID_INDUSTRY;
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   263
5247
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   264
	if (GetNumIndustries() == 0) return NULL;
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   265
5299
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   266
	while (num >= 0) {
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   267
		num--;
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   268
		index++;
5299
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   269
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   270
		/* Make sure we have a valid industry */
5299
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   271
		while (!IsValidIndustryID(index)) {
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   272
			index++;
5299
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   273
			assert(index <= GetMaxIndustryIndex());
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   274
		}
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   275
	}
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   276
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   277
	return GetIndustry(index);
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   278
}
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   279
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   280
void DestroyIndustry(Industry *i);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   281
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   282
static inline void DeleteIndustry(Industry *i)
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   283
{
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   284
	DestroyIndustry(i);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   285
	i->xy = 0;
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   286
}
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   287
4976
a0d7f63c35b5 (svn r6979) Use the pool macros for the Industry pool
tron
parents: 4966
diff changeset
   288
#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))
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
   289
#define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0)
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
   290
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   291
extern const Industry **_industry_sort;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   292
extern bool _industry_sort_dirty;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 830
diff changeset
   293
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
enum {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   295
	IT_COAL_MINE           =   0,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   296
	IT_POWER_STATION       =   1,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   297
	IT_SAWMILL             =   2,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   298
	IT_FOREST              =   3,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   299
	IT_OIL_REFINERY        =   4,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   300
	IT_OIL_RIG             =   5,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   301
	IT_FACTORY             =   6,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   302
	IT_PRINTING_WORKS      =   7,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   303
	IT_STEEL_MILL          =   8,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   304
	IT_FARM                =   9,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   305
	IT_COPPER_MINE         =  10,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   306
	IT_OIL_WELL            =  11,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   307
	IT_BANK_TEMP           =  12,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   308
	IT_FOOD_PROCESS        =  13,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   309
	IT_PAPER_MILL          =  14,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   310
	IT_GOLD_MINE           =  15,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   311
	IT_BANK_TROPIC_ARCTIC  =  16,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   312
	IT_DIAMOND_MINE        =  17,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   313
	IT_IRON_MINE           =  18,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   314
	IT_FRUIT_PLANTATION    =  19,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   315
	IT_RUBBER_PLANTATION   =  20,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   316
	IT_WATER_SUPPLY        =  21,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   317
	IT_WATER_TOWER         =  22,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   318
	IT_FACTORY_2           =  23,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   319
	IT_FARM_2              =  24,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   320
	IT_LUMBER_MILL         =  25,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   321
	IT_COTTON_CANDY        =  26,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   322
	IT_CANDY_FACTORY       =  27,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   323
	IT_BATTERY_FARM        =  28,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   324
	IT_COLA_WELLS          =  29,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   325
	IT_TOY_SHOP            =  30,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   326
	IT_TOY_FACTORY         =  31,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   327
	IT_PLASTIC_FOUNTAINS   =  32,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   328
	IT_FIZZY_DRINK_FACTORY =  33,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   329
	IT_BUBBLE_GENERATOR    =  34,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   330
	IT_TOFFEE_QUARRY       =  35,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   331
	IT_SUGAR_MINE          =  36,
3499
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   332
	IT_END,
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   333
	IT_INVALID             = 255,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2186
diff changeset
   336
#endif /* INDUSTRY_H */