src/industry.h
author rubidium
Sat, 22 Sep 2007 13:56:38 +0000
changeset 8106 9f527cc360cf
parent 8104 a792a30af2c8
child 8110 120abf2bfe82
permissions -rw-r--r--
(svn r11139) -Codechange: add support for persistent storage for NewGRFs.
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"
6886
742e1d75f442 (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: 6633
diff changeset
     9
#include "helpers.hpp"
8106
9f527cc360cf (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 8104
diff changeset
    10
#include "newgrf_storage.h"
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
    11
3689
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    12
typedef byte IndustryGfx;
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    13
typedef uint8 IndustryType;
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    14
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
    15
enum {
7239
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7237
diff changeset
    16
	INVALID_INDUSTRY       = 0xFFFF,
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7237
diff changeset
    17
	NEW_INDUSTRYOFFSET     = 37,                         ///< original number of industries
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7237
diff changeset
    18
	NUM_INDUSTRYTYPES      = 37,                         ///< total number of industries, new and old
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7237
diff changeset
    19
	INDUSTRYTILE_NOANIM    = 0xFF,                       ///< flag to mark industry tiles as having no animation
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7237
diff changeset
    20
	NEW_INDUSTRYTILEOFFSET = 175,                        ///< original number of tiles
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7237
diff changeset
    21
	INVALID_INDUSTRYTYPE   = NUM_INDUSTRYTYPES,          ///< one above amount is considered invalid
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7237
diff changeset
    22
	NUM_INDUSTRYTILES      = NEW_INDUSTRYTILEOFFSET,     ///< total number of industry tiles, new and old
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7237
diff changeset
    23
	INVALID_INDUSTRYTILE   = NUM_INDUSTRYTILES,          ///< one above amount is considered invalid
7787
6e0b6ea38850 (svn r10639) -Codechange: Give meaninfull name to a magic number
belugas
parents: 7755
diff changeset
    24
	INDUSTRY_COMPLETED     = 3,                          ///< final stage of industry construction.
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
    25
};
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
    26
7261
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7239
diff changeset
    27
enum {
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7239
diff changeset
    28
	CLEAN_RANDOMSOUNDS,    ///< Free the dynamically allocated sounds table
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7239
diff changeset
    29
	CLEAN_TILELSAYOUT,     ///< Free the dynamically allocated tile layout structure
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7239
diff changeset
    30
};
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7239
diff changeset
    31
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    32
enum IndustryLifeType {
7640
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
    33
	INDUSTRYLIFE_BLACK_HOLE =      0, ///< Like power plants and banks
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
    34
	INDUSTRYLIFE_EXTRACTIVE = 1 << 0, ///< Like mines
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
    35
	INDUSTRYLIFE_ORGANIC    = 1 << 1, ///< Like forests
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
    36
	INDUSTRYLIFE_PROCESSING = 1 << 2, ///< Like factories
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    37
};
4924
6e29520a0ba8 (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    38
6936
2d7a50c26df4 (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6910
diff changeset
    39
/* Procedures that can be run to check whether an industry may
2d7a50c26df4 (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6910
diff changeset
    40
 * build at location the given to the procedure */
2d7a50c26df4 (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6910
diff changeset
    41
enum CheckProc {
7669
c000600d3025 (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7661
diff changeset
    42
	CHECK_NOTHING,
c000600d3025 (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7661
diff changeset
    43
	CHECK_FOREST,
c000600d3025 (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7661
diff changeset
    44
	CHECK_REFINERY,
c000600d3025 (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7661
diff changeset
    45
	CHECK_FARM,
c000600d3025 (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7661
diff changeset
    46
	CHECK_PLANTATION,
c000600d3025 (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7661
diff changeset
    47
	CHECK_WATER,
c000600d3025 (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7661
diff changeset
    48
	CHECK_LUMBERMILL,
c000600d3025 (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7661
diff changeset
    49
	CHECK_BUBBLEGEN,
c000600d3025 (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7661
diff changeset
    50
	CHECK_OIL_RIG,
6936
2d7a50c26df4 (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6910
diff changeset
    51
	CHECK_END,
2d7a50c26df4 (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6910
diff changeset
    52
};
2d7a50c26df4 (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6910
diff changeset
    53
7755
517d6b2b2ca2 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7725
diff changeset
    54
/** How was the industry created */
7682
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
    55
enum IndustryConstructionType {
7755
517d6b2b2ca2 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7725
diff changeset
    56
	ICT_UNKNOWN,          ///< in previous game version or without newindustries activated
517d6b2b2ca2 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7725
diff changeset
    57
	ICT_NORMAL_GAMEPLAY,  ///< either by user or random creation proccess
517d6b2b2ca2 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7725
diff changeset
    58
	ICT_MAP_GENERATION,   ///< during random map creation
517d6b2b2ca2 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7725
diff changeset
    59
	ICT_SCENARIO_EDITOR   ///< while scenarion edition
517d6b2b2ca2 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7725
diff changeset
    60
};
517d6b2b2ca2 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7725
diff changeset
    61
517d6b2b2ca2 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7725
diff changeset
    62
/** From where is callback CBID_INDUSTRY_AVAILABLE been called */
517d6b2b2ca2 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7725
diff changeset
    63
enum IndustryAvailabilityCallType {
517d6b2b2ca2 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7725
diff changeset
    64
	IACT_MAPGENERATION,   ///< during random map generation
517d6b2b2ca2 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7725
diff changeset
    65
	IACT_RANDOMCREATION,  ///< during creation of random ingame industry
517d6b2b2ca2 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7725
diff changeset
    66
	IACT_USERCREATION,    ///< from the Fund/build window
7682
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
    67
};
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
    68
6886
742e1d75f442 (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: 6633
diff changeset
    69
enum IndustyBehaviour {
742e1d75f442 (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: 6633
diff changeset
    70
	INDUSTRYBEH_NONE                  =      0,
742e1d75f442 (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: 6633
diff changeset
    71
	INDUSTRYBEH_PLANT_FIELDS          = 1 << 0,  ///< periodically plants fileds around itself (temp and artic farms)
742e1d75f442 (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: 6633
diff changeset
    72
	INDUSTRYBEH_CUT_TREES             = 1 << 1,  ///< cuts trees and produce first output cargo from them (lumber mill)
742e1d75f442 (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: 6633
diff changeset
    73
	INDUSTRYBEH_BUILT_ONWATER         = 1 << 2,  ///< is built on water (oil rig)
742e1d75f442 (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: 6633
diff changeset
    74
	INDUSTRYBEH_TOWN1200_MORE         = 1 << 3,  ///< can only be built in towns larger then 1200 inhabitants (temperate bank)
742e1d75f442 (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: 6633
diff changeset
    75
	INDUSTRYBEH_ONLY_INTOWN           = 1 << 4,  ///< can only be built in towns (arctic/tropic banks, water tower)
742e1d75f442 (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: 6633
diff changeset
    76
	INDUSTRYBEH_ONLY_NEARTOWN         = 1 << 5,  ///< is always built near towns (toy shop)
742e1d75f442 (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: 6633
diff changeset
    77
	INDUSTRYBEH_PLANT_ON_BUILT        = 1 << 6,  ///< Fields are planted around when built (all farms)
7628
8ec5bb2fe24d (svn r10406) -Fix [FS#968]: only industries in the temperate climate should be affected by the "do not increase production" flag.
rubidium
parents: 7603
diff changeset
    78
	INDUSTRYBEH_DONT_INCR_PROD        = 1 << 7,  ///< do not increase production (oil wells) in the temperate climate
6886
742e1d75f442 (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: 6633
diff changeset
    79
	INDUSTRYBEH_BEFORE_1950           = 1 << 8,  ///< can only be built before 1950 (oil wells)
742e1d75f442 (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: 6633
diff changeset
    80
	INDUSTRYBEH_AFTER_1960            = 1 << 9,  ///< can only be built after 1960 (oil rigs)
742e1d75f442 (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: 6633
diff changeset
    81
	INDUSTRYBEH_AI_AIRSHIP_ROUTES     = 1 << 10, ///< ai will attempt to establish air/ship routes to this industry (oil rig)
742e1d75f442 (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: 6633
diff changeset
    82
	INDUSTRYBEH_AIRPLANE_ATTACKS      = 1 << 11, ///< can be exploded by a military airplane (oil refinery)
742e1d75f442 (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: 6633
diff changeset
    83
	INDUSTRYBEH_CHOPPER_ATTACKS       = 1 << 12, ///< can be exploded by a military helicopter (factory)
742e1d75f442 (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: 6633
diff changeset
    84
	INDUSTRYBEH_CAN_SUBSIDENCE        = 1 << 13, ///< can cause a subsidence (coal mine, shaft that collapses)
8104
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 7992
diff changeset
    85
	INDUSTRYBEH_CANCLOSE_LASTINSTANCE = 1 << 17, ///< Allow closing down the last instance of this type
6886
742e1d75f442 (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: 6633
diff changeset
    86
};
742e1d75f442 (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: 6633
diff changeset
    87
742e1d75f442 (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: 6633
diff changeset
    88
742e1d75f442 (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: 6633
diff changeset
    89
DECLARE_ENUM_AS_BIT_SET(IndustyBehaviour);
742e1d75f442 (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: 6633
diff changeset
    90
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7833
diff changeset
    91
struct Industry;
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7833
diff changeset
    92
DECLARE_OLD_POOL(Industry, Industry, 3, 8000)
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7833
diff changeset
    93
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
    94
/**
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
    95
 * 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
    96
 */
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7833
diff changeset
    97
struct Industry : PoolItem<Industry, IndustryID, &_Industry_pool> {
8106
9f527cc360cf (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 8104
diff changeset
    98
	typedef PersistentStorageArray<uint32, 16> PersistentStorage;
9f527cc360cf (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 8104
diff changeset
    99
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   100
	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
   101
	byte width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	byte height;
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   103
	const Town *town;                   ///< Nearest town
7661
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7640
diff changeset
   104
	uint16 produced_cargo_waiting[2];   ///< amount of cargo produced per cargo
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7640
diff changeset
   105
	uint16 incoming_cargo_waiting[3];   ///< incoming cargo waiting to be processed
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   106
	byte production_rate[2];            ///< production rate for each cargo
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   107
	byte prod_level;                    ///< general production level
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   108
	uint16 this_month_production[2];    ///< stats of this month's production per cargo
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   109
	uint16 this_month_transported[2];   ///< stats of this month's transport per cargo
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   110
	byte last_month_pct_transported[2]; ///< percentage transported per cargo in the last full month
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   111
	uint16 last_month_production[2];    ///< total units produced per cargo in the last full month
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   112
	uint16 last_month_transported[2];   ///< total units transported per cargo in the last full month
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   113
	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
   114
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7787
diff changeset
   115
	IndustryType type;                  ///< type of industry.
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   116
	OwnerByte owner;                    ///< owner of the industry.  Which SHOULD always be (imho) OWNER_NONE
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   117
	byte random_color;                  ///< randomized colour of the industry, for display purpose
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   118
	Year last_prod_year;                ///< last year of production
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   119
	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
   120
7682
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
   121
	OwnerByte founder;                  ///< Founder of the industry
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
   122
	Date construction_date;             ///< Date of the construction of the industry
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
   123
	uint8 construction_type;            ///< Way the industry was constructed (@see IndustryConstructionType)
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
   124
	Date last_cargo_accepted_at;        ///< Last day cargo was accepted by this industry
7941
ddf9d11e6df8 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7886
diff changeset
   125
	byte selected_layout;               ///< Which tile layout was used when creating the industry
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7833
diff changeset
   126
8106
9f527cc360cf (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 8104
diff changeset
   127
	PersistentStorage psa;              ///< Persistent storage for NewGRF industries.
9f527cc360cf (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 8104
diff changeset
   128
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7833
diff changeset
   129
	Industry(TileIndex tile = 0) : xy(tile) {}
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7833
diff changeset
   130
	~Industry();
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7833
diff changeset
   131
7992
8ac3fcd8d570 (svn r11009) -Codechange: unvirtualise IsValid as that isn't needed with templates. This gives up to 10% performance increase in games with lots of vehicles.
rubidium
parents: 7969
diff changeset
   132
	inline bool IsValid() const { return this->xy != 0; }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   135
struct IndustryTileTable {
3689
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   136
	TileIndexDiffC ti;
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   137
	IndustryGfx gfx;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   138
};
3689
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   139
7171
87515d9cb3e6 (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 7151
diff changeset
   140
/** Data related to the handling of grf files.  Common to both industry and industry tile */
87515d9cb3e6 (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 7151
diff changeset
   141
struct GRFFileProps {
7956
4c3c40297b9b (svn r10961) -Codechange: Flag default substitutes of industry/tiles with a value that cannot be legal.
belugas
parents: 7941
diff changeset
   142
	uint16 subst_id;
7171
87515d9cb3e6 (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 7151
diff changeset
   143
	uint16 local_id;                      ///< id defined by the grf file for this industry
87515d9cb3e6 (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 7151
diff changeset
   144
	struct SpriteGroup *spritegroup;      ///< pointer to the different sprites of the industry
7344
72e3e8607419 (svn r10088) -Codechange: A typo and a code-style
belugas
parents: 7335
diff changeset
   145
	const struct GRFFile *grffile;        ///< grf file that introduced this industry
7603
b79d8772d069 (svn r10379) -Codechange: silence a compiler warning (which was right) about a variable too little for what's been asked to do
belugas
parents: 7344
diff changeset
   146
	uint16 override;                      ///< id of the entity been replaced by
7171
87515d9cb3e6 (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 7151
diff changeset
   147
};
87515d9cb3e6 (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 7151
diff changeset
   148
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
   149
/**
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
 * 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
   151
 */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   152
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
   153
	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
   154
	byte num_table;                       ///< Number of elements in the table
7673
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7669
diff changeset
   155
	uint8 cost_multiplier;                ///< Base cost multiplier.
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7669
diff changeset
   156
	uint16 raw_industry_cost_multiplier;  ///< Multiplier for the raw industries cost
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7669
diff changeset
   157
	uint32 prospecting_chance;            ///< Chance prospecting succeeds
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
   158
	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
   159
	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
   160
	CargoID produced_cargo[2];
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   161
	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
   162
	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
   163
	                                      ///< 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
   164
	CargoID accepts_cargo[3];             ///< 3 accepted cargos
7131
d4904a021b9e (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: 7029
diff changeset
   165
	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
   166
	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
   167
	byte climate_availability;            ///< Bitmask, giving landscape enums as bit position
6886
742e1d75f442 (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: 6633
diff changeset
   168
	IndustyBehaviour behaviour;           ///< How this industry will behave, and how others entities can use it
6936
2d7a50c26df4 (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6910
diff changeset
   169
	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
   170
	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
   171
	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
   172
	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
   173
	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
   174
	StringID production_down_text;        ///< Message appearing when the industry's production is decreasing
6910
31f7a3d4547b (svn r9550) -Codechange: Add notion and data of industry appearing chances, both in game and in creation mode.
belugas
parents: 6886
diff changeset
   175
	byte appear_ingame[NUM_LANDSCAPE];    ///< Probability of appearance in game
31f7a3d4547b (svn r9550) -Codechange: Add notion and data of industry appearing chances, both in game and in creation mode.
belugas
parents: 6886
diff changeset
   176
	byte appear_creation[NUM_LANDSCAPE];  ///< Probability of appearance during map creation
7151
d811c3f808bd (svn r9886) -Codechange: Cleanup of industries (Step-13). Include the sounds table into the industry's spec.
belugas
parents: 7135
diff changeset
   177
	uint8 number_of_sounds;               ///< Number of sounds available in the sounds array
d811c3f808bd (svn r9886) -Codechange: Cleanup of industries (Step-13). Include the sounds table into the industry's spec.
belugas
parents: 7135
diff changeset
   178
	const uint8 *random_sounds;           ///< array of random sounds.
7171
87515d9cb3e6 (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 7151
diff changeset
   179
	/* Newgrf data */
6936
2d7a50c26df4 (svn r9577) -Codechange: Add notion and data for industry map colour, used in the smallmap_gui. Not used yet.
belugas
parents: 6910
diff changeset
   180
	uint16 callback_flags;                ///< Flags telling which grf callback is set
7261
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7239
diff changeset
   181
	uint8 cleanup_flag;                   ///< flags indicating which data should be freed upon cleaning up
7237
f713f0dc725c (svn r9974) -Codechange: Remove the enabled member of GRFFileProps, since it'snot really grf related
belugas
parents: 7232
diff changeset
   182
	bool enabled;                         ///< entity still avaible (by default true).newgrf can disable it, though
7171
87515d9cb3e6 (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 7151
diff changeset
   183
	struct GRFFileProps grf_prop;         ///< properties related the the grf file
7681
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
   184
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
   185
	/**
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
   186
	 * Is an industry with the spec a raw industry?
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
   187
	 * @return true if it should be handled as a raw industry
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
   188
	 */
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
   189
	bool IsRawIndustry() const;
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
   190
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
   191
	/**
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
   192
	 * Get the cost for constructing this industry
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
   193
	 * @return the cost (inflation corrected etc)
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
   194
	 */
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
   195
	Money GetConstructionCost() const;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   196
};
3689
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   197
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
   198
/**
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
   199
 * 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
   200
 */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   201
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
   202
	CargoID accepts_cargo[3];             ///< Cargo accepted by this tile
7232
2476045c6aed (svn r9969) -Codechange: Cleanup of industries (Step-14). Remove hardcoded-run-time tile acceptance and put in corresponding tile
belugas
parents: 7171
diff changeset
   203
	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
   204
	Slope slopes_refused;                 ///< slope pattern on which this tile cannot be built
6631
dc3480a670cc (svn r9162) -Codechange: Cleanup of industry_cmd (Step-8). Gather tile animation data into IndustryTileSpec array
belugas
parents: 6592
diff changeset
   205
	byte anim_production;                 ///< Animation frame to start when goods are produced
dc3480a670cc (svn r9162) -Codechange: Cleanup of industry_cmd (Step-8). Gather tile animation data into IndustryTileSpec array
belugas
parents: 6592
diff changeset
   206
	byte anim_next;                       ///< Next frame in an animation
dc3480a670cc (svn r9162) -Codechange: Cleanup of industry_cmd (Step-8). Gather tile animation data into IndustryTileSpec array
belugas
parents: 6592
diff changeset
   207
	bool anim_state;                      ///< When true, the tile has to be drawn using the animation
7133
fe36226cf557 (svn r9868) -Codechange: bring external declaration of functions togueter and adjust a comment
belugas
parents: 7132
diff changeset
   208
	                                      ///< state instead of the construction state
7171
87515d9cb3e6 (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 7151
diff changeset
   209
	/* Newgrf data */
7239
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7237
diff changeset
   210
	uint8 callback_flags;                 ///< Flags telling which grf callback is set
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7682
diff changeset
   211
	uint16 animation_info;                ///< Information about the animation (is it looping, how many loops etc)
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7682
diff changeset
   212
	uint8 animation_speed;                ///< The speed of the animation
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7682
diff changeset
   213
	uint8 animation_triggers;             ///< When to start the animation
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7682
diff changeset
   214
	uint8 animation_special_flags;        ///< Extra flags to influence the animation
7237
f713f0dc725c (svn r9974) -Codechange: Remove the enabled member of GRFFileProps, since it'snot really grf related
belugas
parents: 7232
diff changeset
   215
	bool enabled;                         ///< entity still avaible (by default true).newgrf can disable it, though
7171
87515d9cb3e6 (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 7151
diff changeset
   216
	struct GRFFileProps grf_prop;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   217
};
6418
a80dba2d8243 (svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents: 5838
diff changeset
   218
7133
fe36226cf557 (svn r9868) -Codechange: bring external declaration of functions togueter and adjust a comment
belugas
parents: 7132
diff changeset
   219
/* industry_cmd.cpp*/
7239
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7237
diff changeset
   220
const IndustrySpec *GetIndustrySpec(IndustryType thistype);    ///< Array of industries data
7958
86754174b58f (svn r10963) -Revert(10700): Although the idea was good, it was more prone of errors than usefull.
belugas
parents: 7956
diff changeset
   221
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx);  ///< Array of industry tiles data
7133
fe36226cf557 (svn r9868) -Codechange: bring external declaration of functions togueter and adjust a comment
belugas
parents: 7132
diff changeset
   222
void ResetIndustries();
fe36226cf557 (svn r9868) -Codechange: bring external declaration of functions togueter and adjust a comment
belugas
parents: 7132
diff changeset
   223
void PlantRandomFarmField(const Industry *i);
3689
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   224
7239
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7237
diff changeset
   225
/* writable arrays of specs */
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7237
diff changeset
   226
extern IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7237
diff changeset
   227
extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7237
diff changeset
   228
7963
e04dbb203f3e (svn r10972) -Codechange: Implement the counterpart(GetTranslatedIndustryTileID) of getindustileid of TTDPatch. This allows to ensure that the ID of a tile (taken out of the map or not) is still a valid one regarding the possible override it may have been flagged to.
belugas
parents: 7958
diff changeset
   229
static inline IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
e04dbb203f3e (svn r10972) -Codechange: Implement the counterpart(GetTranslatedIndustryTileID) of getindustileid of TTDPatch. This allows to ensure that the ID of a tile (taken out of the map or not) is still a valid one regarding the possible override it may have been flagged to.
belugas
parents: 7958
diff changeset
   230
{
7969
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
   231
	/* the 0xFF should be GFX_WATERTILE_SPECIALCHECK but for reasons of include mess,
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
   232
	 * we'll simplify the writing.
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
   233
	 * Basically, the first test is required since the GFX_WATERTILE_SPECIALCHECK value
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
   234
	 * will never be assigned as a tile index and is only required in order to do some
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
   235
	 * tests while building the industry (as in WATER REQUIRED */
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
   236
	if (gfx != 0xFF) {
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
   237
		assert(gfx < INVALID_INDUSTRYTILE);
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
   238
		const IndustryTileSpec *it = &_industry_tile_specs[gfx];
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
   239
		return it->grf_prop.override == INVALID_INDUSTRYTILE ? gfx : it->grf_prop.override;
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
   240
	} else {
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
   241
		return gfx;
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
   242
	}
7963
e04dbb203f3e (svn r10972) -Codechange: Implement the counterpart(GetTranslatedIndustryTileID) of getindustileid of TTDPatch. This allows to ensure that the ID of a tile (taken out of the map or not) is still a valid one regarding the possible override it may have been flagged to.
belugas
parents: 7958
diff changeset
   243
}
e04dbb203f3e (svn r10972) -Codechange: Implement the counterpart(GetTranslatedIndustryTileID) of getindustileid of TTDPatch. This allows to ensure that the ID of a tile (taken out of the map or not) is still a valid one regarding the possible override it may have been flagged to.
belugas
parents: 7958
diff changeset
   244
7029
209e4b2e1180 (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: 6989
diff changeset
   245
/* smallmap_gui.cpp */
209e4b2e1180 (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: 6989
diff changeset
   246
void BuildIndustriesLegend();
209e4b2e1180 (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: 6989
diff changeset
   247
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
   248
/**
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
   249
 * 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
   250
 * @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
   251
 * @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
   252
 */
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
   253
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
   254
{
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7833
diff changeset
   255
	return index < GetIndustryPoolSize() && GetIndustry(index)->IsValid();
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
   256
}
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
4354
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   258
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   259
static inline IndustryID GetMaxIndustryIndex()
4354
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   260
{
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   261
	/* 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
   262
	 *  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
   263
	 *  _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
   264
	 *  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
   265
	 */
5298
6d4c150bdd94 (svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
rubidium
parents: 5247
diff changeset
   266
	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
   267
}
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
   268
7335
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7321
diff changeset
   269
extern int _total_industries;  // general counter
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7321
diff changeset
   270
extern uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7321
diff changeset
   271
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   272
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
   273
{
4357
3d72606e9192 (svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
truelight
parents: 4356
diff changeset
   274
	return _total_industries;
4354
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   275
}
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   276
7320
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   277
/** Increment the count of industries for this type
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   278
 * @param type IndustryType to increment
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   279
 * @pre type < INVALID_INDUSTRYTYPE */
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   280
static inline void IncIndustryTypeCount(IndustryType type)
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   281
{
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   282
	assert(type < INVALID_INDUSTRYTYPE);
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   283
	_industry_counts[type]++;
7335
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7321
diff changeset
   284
	_total_industries++;
7320
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   285
}
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   286
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   287
/** Decrement the count of industries for this type
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   288
 * @param type IndustryType to decrement
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   289
 * @pre type < INVALID_INDUSTRYTYPE */
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   290
static inline void DecIndustryTypeCount(IndustryType type)
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   291
{
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   292
	assert(type < INVALID_INDUSTRYTYPE);
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   293
	_industry_counts[type]--;
7335
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7321
diff changeset
   294
	_total_industries--;
7320
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   295
}
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   296
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   297
/** get the count of industries for this type
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   298
 * @param type IndustryType to query
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   299
 * @pre type < INVALID_INDUSTRYTYPE */
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   300
static inline uint8 GetIndustryTypeCount(IndustryType type)
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   301
{
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   302
	assert(type < INVALID_INDUSTRYTYPE);
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   303
	return min(_industry_counts[type], 0xFF); // callback expects only a byte, so cut it
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   304
}
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   305
7335
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7321
diff changeset
   306
/** Resets both the total_industries and the _industry_counts
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7321
diff changeset
   307
 * This way, we centralize all counts activities */
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7321
diff changeset
   308
static inline void ResetIndustryCounts()
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7321
diff changeset
   309
{
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7321
diff changeset
   310
	_total_industries = 0;
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7321
diff changeset
   311
	memset(&_industry_counts, 0, sizeof(_industry_counts));
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7321
diff changeset
   312
}
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7321
diff changeset
   313
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
   314
/**
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
   315
 * 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
   316
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   317
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
   318
{
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
   319
	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
   320
	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
   321
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
   322
	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
   323
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
   324
	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
   325
		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
   326
		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
   327
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
   328
		/* 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
   329
		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
   330
			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
   331
			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
   332
		}
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
   333
	}
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
   334
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
   335
	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
   336
}
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
   337
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7833
diff changeset
   338
#define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) if (i->IsValid())
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
   339
#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
   340
7320
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   341
extern const Industry **_industry_sort;
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   342
extern bool _industry_sort_dirty;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 830
diff changeset
   343
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7787
diff changeset
   344
static const uint8 IT_INVALID = 255;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
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
   346
#endif /* INDUSTRY_H */