src/industry.h
author rubidium
Thu, 31 May 2007 15:15:00 +0000
changeset 6764 d09d8d618a07
parent 6743 e84a3b89d46b
child 6765 50903afa1a48
permissions -rw-r--r--
(svn r9999) -Feature: make it possible to disallow busses and lorries to go a specific way on straight pieces of road.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 1330
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 1330
diff changeset
     2
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
     3
/** @file industry.h */
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
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
8bd14ee39af2 (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"
6390
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
     9
#include "helpers.hpp"
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
    10
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    11
typedef byte IndustryGfx;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    12
typedef uint8 IndustryType;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    13
4328
1b3940c35724 (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 {
6743
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
    15
	INVALID_INDUSTRY       = 0xFFFF,
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
    16
	NEW_INDUSTRYOFFSET     = 37,                         ///< original number of industries
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
    17
	NUM_INDUSTRYTYPES      = 37,                         ///< total number of industries, new and old
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
    18
	INDUSTRYTILE_NOANIM    = 0xFF,                       ///< flag to mark industry tiles as having no animation
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
    19
	NEW_INDUSTRYTILEOFFSET = 175,                        ///< original number of tiles
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
    20
	INVALID_INDUSTRYTYPE   = NUM_INDUSTRYTYPES,          ///< one above amount is considered invalid
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
    21
	NUM_INDUSTRYTILES      = NEW_INDUSTRYTILEOFFSET,     ///< total number of industry tiles, new and old
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
    22
	INVALID_INDUSTRYTILE   = NUM_INDUSTRYTILES,          ///< one above amount is considered invalid
4328
1b3940c35724 (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
    23
};
1b3940c35724 (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
    24
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    25
enum IndustryLifeType {
4924
b6fa01b5a80d (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    26
	INDUSTRYLIFE_NOT_CLOSABLE,     ///< Industry can never close
b6fa01b5a80d (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    27
	INDUSTRYLIFE_PRODUCTION,       ///< Industry can close and change of production
b6fa01b5a80d (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    28
	INDUSTRYLIFE_CLOSABLE,         ///< Industry can only close (no production change)
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    29
};
4924
b6fa01b5a80d (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    30
6440
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    31
/* Procedures that can be run to check whether an industry may
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    32
 * build at location the given to the procedure */
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    33
enum CheckProc {
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    34
	CHECK_NOTHING    = 0,
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    35
	CHECK_FOREST     = 1,
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    36
	CHECK_REFINERY   = 2,
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    37
	CHECK_FARM       = 3,
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    38
	CHECK_PLANTATION = 4,
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    39
	CHECK_WATER      = 5,
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    40
	CHECK_LUMBERMILL = 6,
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    41
	CHECK_BUBBLEGEN  = 7,
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    42
	CHECK_OIL_RIG    = 8,
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    43
	CHECK_END,
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    44
};
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
    45
6390
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    46
enum IndustyBehaviour {
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    47
	INDUSTRYBEH_NONE                  =      0,
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    48
	INDUSTRYBEH_PLANT_FIELDS          = 1 << 0,  ///< periodically plants fileds around itself (temp and artic farms)
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    49
	INDUSTRYBEH_CUT_TREES             = 1 << 1,  ///< cuts trees and produce first output cargo from them (lumber mill)
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    50
	INDUSTRYBEH_BUILT_ONWATER         = 1 << 2,  ///< is built on water (oil rig)
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    51
	INDUSTRYBEH_TOWN1200_MORE         = 1 << 3,  ///< can only be built in towns larger then 1200 inhabitants (temperate bank)
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    52
	INDUSTRYBEH_ONLY_INTOWN           = 1 << 4,  ///< can only be built in towns (arctic/tropic banks, water tower)
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    53
	INDUSTRYBEH_ONLY_NEARTOWN         = 1 << 5,  ///< is always built near towns (toy shop)
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    54
	INDUSTRYBEH_PLANT_ON_BUILT        = 1 << 6,  ///< Fields are planted around when built (all farms)
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    55
	INDUSTRYBEH_DONT_INCR_PROD        = 1 << 7,  ///< do not increase production (oil wells)
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    56
	INDUSTRYBEH_BEFORE_1950           = 1 << 8,  ///< can only be built before 1950 (oil wells)
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    57
	INDUSTRYBEH_AFTER_1960            = 1 << 9,  ///< can only be built after 1960 (oil rigs)
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    58
	INDUSTRYBEH_AI_AIRSHIP_ROUTES     = 1 << 10, ///< ai will attempt to establish air/ship routes to this industry (oil rig)
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    59
	INDUSTRYBEH_AIRPLANE_ATTACKS      = 1 << 11, ///< can be exploded by a military airplane (oil refinery)
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    60
	INDUSTRYBEH_CHOPPER_ATTACKS       = 1 << 12, ///< can be exploded by a military helicopter (factory)
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    61
	INDUSTRYBEH_CAN_SUBSIDENCE        = 1 << 13, ///< can cause a subsidence (coal mine, shaft that collapses)
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    62
};
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    63
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    64
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    65
DECLARE_ENUM_AS_BIT_SET(IndustyBehaviour);
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
    66
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    67
/**
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    68
 * Defines the internal data of a functionnal industry
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    69
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
struct Industry {
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    71
	TileIndex xy;                   ///< coordinates of the primary tile the industry is built one
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    72
	byte width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
	byte height;
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    74
	const Town* town;               ///< Nearest town
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    75
	uint16 cargo_waiting[2];        ///< amount of cargo produced per cargo
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    76
	byte production_rate[2];        ///< production rate for each cargo
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    77
	byte prod_level;                ///< general production level
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    78
	uint16 last_mo_production[2];   ///< stats of last month production per cargo
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    79
	uint16 last_mo_transported[2];  ///< stats of last month transport per cargo
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    80
	byte pct_transported[2];        ///< percentage transported per cargo
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    81
	uint16 total_production[2];     ///< total units produced per cargo
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    82
	uint16 total_transported[2];    ///< total units transported per cargo
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    83
	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
    84
6639
d9e4445b518d (svn r9870) -Codechange: Silence two compiler warnings and give proper type to the "type" member of industry struct
belugas
parents: 6637
diff changeset
    85
	IndustryType type;              ///< type of industry. see IT_COAL_MINE and others
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    86
	OwnerByte owner;                ///< owner of the industry.  Which SHOULD always be (imho) OWNER_NONE
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    87
	byte random_color;              ///< randomized colour of the industry, for display purpose
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    88
	Year last_prod_year;            ///< last year of production
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    89
	byte was_cargo_delivered;       ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 830
diff changeset
    90
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
    91
	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
    92
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    94
struct IndustryTileTable {
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    95
	TileIndexDiffC ti;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    96
	IndustryGfx gfx;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    97
};
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    98
6675
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
    99
/** Data related to the handling of grf files.  Common to both industry and industry tile */
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   100
struct GRFFileProps {
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   101
	uint8 subst_id;
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   102
	uint16 local_id;                      ///< id defined by the grf file for this industry
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   103
	struct SpriteGroup *spritegroup;      ///< pointer to the different sprites of the industry
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   104
	const struct GRFFile *grffile;        ///< grf file that introduced this house
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   105
	uint8 override;                       ///< id of the entity been replaced by
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   106
};
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   107
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   108
/**
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   109
 * Defines the data structure for constructing industry.
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   110
 */
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   111
struct IndustrySpec {
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   112
	const IndustryTileTable *const *table;///< List of the tiles composing the industry
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   113
	byte num_table;                       ///< Number of elements in the table
6440
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
   114
	byte cost_multiplier;                 ///< Base cost multiplier. Watch out for this one, << 5  VS << 8
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   115
	IndustryType conflicting[3];          ///< Industries this industry cannot be close to
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   116
	byte check_proc;                      ///< Index to a procedure to check for conflicting circumstances
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   117
	CargoID produced_cargo[2];
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   118
	byte production_rate[2];
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   119
	byte minimal_cargo;                   ///< minimum amount of cargo transported to the stations
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   120
	                                      ///< If the waiting cargo is less than this number, no cargo is moved to it
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   121
	CargoID accepts_cargo[3];             ///< 3 accepted cargos
6635
73064d1771ed (svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later.
rubidium
parents: 6533
diff changeset
   122
	uint16 input_cargo_multiplier[3][2];  ///< Input cargo multipliers (multiply amount of incoming cargo for the produced cargos)
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   123
	IndustryLifeType life_type;           ///< This is also known as Industry production flag, in newgrf specs
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   124
	byte climate_availability;            ///< Bitmask, giving landscape enums as bit position
6390
802629b3c7f1 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6307
diff changeset
   125
	IndustyBehaviour behaviour;           ///< How this industry will behave, and how others entities can use it
6440
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
   126
	byte map_colour;                      ///< colour used for the small map
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   127
	StringID name;                        ///< Displayed name of the industry
6266
fd42b0893130 (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: 6248
diff changeset
   128
	StringID new_industry_text;           ///< Message appearing when the industry is built
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   129
	StringID closure_text;                ///< Message appearing when the industry closes
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   130
	StringID production_up_text;          ///< Message appearing when the industry's production is increasing
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   131
	StringID production_down_text;        ///< Message appearing when the industry's production is decreasing
6414
3eaf5e612aa4 (svn r9550) -Codechange: Add notion and data of industry appearing chances, both in game and in creation mode.
belugas
parents: 6390
diff changeset
   132
	byte appear_ingame[NUM_LANDSCAPE];    ///< Probability of appearance in game
3eaf5e612aa4 (svn r9550) -Codechange: Add notion and data of industry appearing chances, both in game and in creation mode.
belugas
parents: 6390
diff changeset
   133
	byte appear_creation[NUM_LANDSCAPE];  ///< Probability of appearance during map creation
6655
3d46f5ba9b6e (svn r9886) -Codechange: Cleanup of industries (Step-13). Include the sounds table into the industry's spec.
belugas
parents: 6639
diff changeset
   134
	uint8 number_of_sounds;               ///< Number of sounds available in the sounds array
3d46f5ba9b6e (svn r9886) -Codechange: Cleanup of industries (Step-13). Include the sounds table into the industry's spec.
belugas
parents: 6639
diff changeset
   135
	const uint8 *random_sounds;           ///< array of random sounds.
6675
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   136
	/* Newgrf data */
6440
862590c931fb (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6414
diff changeset
   137
	uint16 callback_flags;                ///< Flags telling which grf callback is set
6741
bdd53720536f (svn r9974) -Codechange: Remove the enabled member of GRFFileProps, since it'snot really grf related
belugas
parents: 6736
diff changeset
   138
	bool enabled;                         ///< entity still avaible (by default true).newgrf can disable it, though
6675
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   139
	struct GRFFileProps grf_prop;         ///< properties related the the grf file
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   140
};
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   141
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   142
/**
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   143
 * Defines the data structure of each indivudual tile of an industry.
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   144
 */
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   145
struct IndustryTileSpec {
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   146
	CargoID accepts_cargo[3];             ///< Cargo accepted by this tile
6736
9f55d5e22875 (svn r9969) -Codechange: Cleanup of industries (Step-14). Remove hardcoded-run-time tile acceptance and put in corresponding tile
belugas
parents: 6675
diff changeset
   147
	uint8 acceptance[3];                  ///< Level of aceptance per cargo type
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   148
	Slope slopes_refused;                 ///< slope pattern on which this tile cannot be built
6305
185ebf766d4e (svn r9162) -Codechange: Cleanup of industry_cmd (Step-8). Gather tile animation data into IndustryTileSpec array
belugas
parents: 6266
diff changeset
   149
	byte anim_production;                 ///< Animation frame to start when goods are produced
185ebf766d4e (svn r9162) -Codechange: Cleanup of industry_cmd (Step-8). Gather tile animation data into IndustryTileSpec array
belugas
parents: 6266
diff changeset
   150
	byte anim_next;                       ///< Next frame in an animation
185ebf766d4e (svn r9162) -Codechange: Cleanup of industry_cmd (Step-8). Gather tile animation data into IndustryTileSpec array
belugas
parents: 6266
diff changeset
   151
	bool anim_state;                      ///< When true, the tile has to be drawn using the animation
6637
5a8e524c14f4 (svn r9868) -Codechange: bring external declaration of functions togueter and adjust a comment
belugas
parents: 6636
diff changeset
   152
	                                      ///< state instead of the construction state
6675
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   153
	/* Newgrf data */
6743
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
   154
	uint8 callback_flags;                 ///< Flags telling which grf callback is set
6741
bdd53720536f (svn r9974) -Codechange: Remove the enabled member of GRFFileProps, since it'snot really grf related
belugas
parents: 6736
diff changeset
   155
	bool enabled;                         ///< entity still avaible (by default true).newgrf can disable it, though
6675
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   156
	struct GRFFileProps grf_prop;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   157
};
6092
53c6b9b18d0b (svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents: 5587
diff changeset
   158
6637
5a8e524c14f4 (svn r9868) -Codechange: bring external declaration of functions togueter and adjust a comment
belugas
parents: 6636
diff changeset
   159
/* industry_cmd.cpp*/
6743
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
   160
const IndustrySpec *GetIndustrySpec(IndustryType thistype);    ///< Array of industries data
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
   161
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx);  ///< Array of industry tiles data
6637
5a8e524c14f4 (svn r9868) -Codechange: bring external declaration of functions togueter and adjust a comment
belugas
parents: 6636
diff changeset
   162
void ResetIndustries();
5a8e524c14f4 (svn r9868) -Codechange: bring external declaration of functions togueter and adjust a comment
belugas
parents: 6636
diff changeset
   163
void PlantRandomFarmField(const Industry *i);
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   164
6743
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
   165
/* writable arrays of specs */
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
   166
extern IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
   167
extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
   168
6533
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6493
diff changeset
   169
/* smallmap_gui.cpp */
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6493
diff changeset
   170
void BuildIndustriesLegend();
8be3ef428116 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 6493
diff changeset
   171
5216
8bd14ee39af2 (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
   172
DECLARE_OLD_POOL(Industry, Industry, 3, 8000)
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 830
diff changeset
   173
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
   174
/**
1330
5d76a0522a11 (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
   175
 * Check if an Industry really exists.
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   176
 * @param industry to check
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   177
 * @return true if position is a valid one
1330
5d76a0522a11 (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
   178
 */
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   179
static inline bool IsValidIndustry(const Industry *industry)
1330
5d76a0522a11 (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
   180
{
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   181
	return industry->xy != 0;
1330
5d76a0522a11 (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
   182
}
5d76a0522a11 (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
   183
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   184
/**
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   185
 * Check if an Industry exists whithin the pool of industries
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   186
 * @param index of the desired industry
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   187
 * @return true if it is inside the pool
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   188
 */
5299
cf162c141e2f (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
   189
static inline bool IsValidIndustryID(IndustryID index)
cf162c141e2f (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
   190
{
cf162c141e2f (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
   191
	return index < GetIndustryPoolSize() && IsValidIndustry(GetIndustry(index));
cf162c141e2f (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
   192
}
cf162c141e2f (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
   193
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   194
VARDEF int _total_industries; //general counter
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   195
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   196
static inline IndustryID GetMaxIndustryIndex()
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   197
{
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   198
	/* TODO - This isn't the real content of the function, but
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   199
	 *  with the new pool-system this will be replaced with one that
5247
1f982de55b88 (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
   200
	 *  _really_ returns the highest index. Now it just returns
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   201
	 *  the next safe value we are sure about everything is below.
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   202
	 */
5298
46eabcb5c2b2 (svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
rubidium
parents: 5247
diff changeset
   203
	return GetIndustryPoolSize() - 1;
5247
1f982de55b88 (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
   204
}
1f982de55b88 (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
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   206
static inline uint GetNumIndustries()
5247
1f982de55b88 (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
   207
{
4357
aaba385fa723 (svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
truelight
parents: 4356
diff changeset
   208
	return _total_industries;
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   209
}
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   210
4356
ec4e13f21cd0 (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
   211
/**
5299
cf162c141e2f (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
   212
 * Return a random valid industry.
4356
ec4e13f21cd0 (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
   213
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   214
static inline Industry *GetRandomIndustry()
4356
ec4e13f21cd0 (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
   215
{
5299
cf162c141e2f (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
   216
	int num = RandomRange(GetNumIndustries());
cf162c141e2f (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
   217
	IndustryID index = INVALID_INDUSTRY;
4356
ec4e13f21cd0 (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
   218
5247
1f982de55b88 (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
   219
	if (GetNumIndustries() == 0) return NULL;
4356
ec4e13f21cd0 (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
   220
5299
cf162c141e2f (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
   221
	while (num >= 0) {
4356
ec4e13f21cd0 (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
   222
		num--;
ec4e13f21cd0 (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
   223
		index++;
5299
cf162c141e2f (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
   224
4356
ec4e13f21cd0 (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
   225
		/* Make sure we have a valid industry */
5299
cf162c141e2f (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
   226
		while (!IsValidIndustryID(index)) {
4356
ec4e13f21cd0 (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
   227
			index++;
5299
cf162c141e2f (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
   228
			assert(index <= GetMaxIndustryIndex());
4356
ec4e13f21cd0 (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
   229
		}
ec4e13f21cd0 (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
   230
	}
ec4e13f21cd0 (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
   231
ec4e13f21cd0 (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
   232
	return GetIndustry(index);
ec4e13f21cd0 (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
   233
}
ec4e13f21cd0 (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
   234
4403
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   235
void DestroyIndustry(Industry *i);
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   236
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   237
static inline void DeleteIndustry(Industry *i)
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   238
{
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   239
	DestroyIndustry(i);
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   240
	i->xy = 0;
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   241
}
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   242
4976
2e3d5e8ec510 (svn r6979) Use the pool macros for the Industry pool
tron
parents: 4966
diff changeset
   243
#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
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
   244
#define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0)
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
   245
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 3689
diff changeset
   246
VARDEF const Industry** _industry_sort;
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
   247
VARDEF bool _industry_sort_dirty;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 830
diff changeset
   248
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
enum {
4344
7e123fec5b0b (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
   250
	IT_COAL_MINE           =   0,
7e123fec5b0b (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
   251
	IT_POWER_STATION       =   1,
7e123fec5b0b (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
   252
	IT_SAWMILL             =   2,
7e123fec5b0b (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
   253
	IT_FOREST              =   3,
7e123fec5b0b (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
   254
	IT_OIL_REFINERY        =   4,
7e123fec5b0b (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
   255
	IT_OIL_RIG             =   5,
7e123fec5b0b (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
   256
	IT_FACTORY             =   6,
7e123fec5b0b (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
   257
	IT_PRINTING_WORKS      =   7,
7e123fec5b0b (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
   258
	IT_STEEL_MILL          =   8,
7e123fec5b0b (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
   259
	IT_FARM                =   9,
7e123fec5b0b (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
   260
	IT_COPPER_MINE         =  10,
7e123fec5b0b (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
   261
	IT_OIL_WELL            =  11,
7e123fec5b0b (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
   262
	IT_BANK_TEMP           =  12,
7e123fec5b0b (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
   263
	IT_FOOD_PROCESS        =  13,
7e123fec5b0b (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
   264
	IT_PAPER_MILL          =  14,
7e123fec5b0b (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
   265
	IT_GOLD_MINE           =  15,
7e123fec5b0b (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
   266
	IT_BANK_TROPIC_ARCTIC  =  16,
7e123fec5b0b (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
   267
	IT_DIAMOND_MINE        =  17,
7e123fec5b0b (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
   268
	IT_IRON_MINE           =  18,
7e123fec5b0b (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
   269
	IT_FRUIT_PLANTATION    =  19,
7e123fec5b0b (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
   270
	IT_RUBBER_PLANTATION   =  20,
7e123fec5b0b (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
   271
	IT_WATER_SUPPLY        =  21,
7e123fec5b0b (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
   272
	IT_WATER_TOWER         =  22,
7e123fec5b0b (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
   273
	IT_FACTORY_2           =  23,
7e123fec5b0b (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
   274
	IT_FARM_2              =  24,
7e123fec5b0b (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
   275
	IT_LUMBER_MILL         =  25,
7e123fec5b0b (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
   276
	IT_COTTON_CANDY        =  26,
7e123fec5b0b (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
   277
	IT_CANDY_FACTORY       =  27,
7e123fec5b0b (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
   278
	IT_BATTERY_FARM        =  28,
7e123fec5b0b (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
   279
	IT_COLA_WELLS          =  29,
7e123fec5b0b (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
   280
	IT_TOY_SHOP            =  30,
7e123fec5b0b (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
   281
	IT_TOY_FACTORY         =  31,
7e123fec5b0b (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
   282
	IT_PLASTIC_FOUNTAINS   =  32,
7e123fec5b0b (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
   283
	IT_FIZZY_DRINK_FACTORY =  33,
7e123fec5b0b (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
   284
	IT_BUBBLE_GENERATOR    =  34,
7e123fec5b0b (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
   285
	IT_TOFFEE_QUARRY       =  35,
7e123fec5b0b (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
   286
	IT_SUGAR_MINE          =  36,
3499
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   287
	IT_END,
4344
7e123fec5b0b (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
   288
	IT_INVALID             = 255,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2186
diff changeset
   291
#endif /* INDUSTRY_H */