src/industry.h
author translators
Sun, 30 Nov 2008 18:46:32 +0000
changeset 10395 6fe57f7c5d8d
parent 10146 cfea97f96067
permissions -rw-r--r--
(svn r14646) -Update: WebTranslator2 update to 2008-11-30 18:46:24
esperanto - 4 fixed by Athaba (4)
finnish - 1 changed by SuomiPoika (1)
indonesian - 16 fixed, 4 changed by fanioz (20)
korean - 1 fixed by dlunch (1)
lithuanian - 57 fixed, 20 changed by Enternald (77)
macedonian - 140 fixed, 1 changed by simonkoco (34), zharko (107)
persian - 21 fixed by ali sattari (21)
serbian - 5 fixed by dejac (5)
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
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8959
diff changeset
     3
/** @file industry.h Base of all industries. */
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
     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"
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 7978
diff changeset
     9
#include "core/random_func.hpp"
7610
13b7d9e247d2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 7608
diff changeset
    10
#include "newgrf_storage.h"
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 7978
diff changeset
    11
#include "cargo_type.h"
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 7978
diff changeset
    12
#include "economy_type.h"
8139
4e91c448c409 (svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents: 8138
diff changeset
    13
#include "map_type.h"
8138
dbfdc08fa6b9 (svn r11700) -Codechange: reduce the amount of unnecessary includes.
rubidium
parents: 8119
diff changeset
    14
#include "slope_type.h"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8139
diff changeset
    15
#include "date_type.h"
8213
7bdd7593eb9b (svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents: 8140
diff changeset
    16
#include "town_type.h"
7bdd7593eb9b (svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents: 8140
diff changeset
    17
#include "industry_type.h"
9126
5648d696456b (svn r12986) -Codechange: move the landscape and transport related types from openttd.h to their own headers.
rubidium
parents: 9111
diff changeset
    18
#include "landscape_type.h"
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    19
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
    20
enum {
6743
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
    21
	INVALID_INDUSTRY       = 0xFFFF,
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
    22
	NEW_INDUSTRYOFFSET     = 37,                         ///< original number of industries
7654
533a9c9a5e83 (svn r11185) -Codechange: prepare some more code for the introduction of NewIndustries. Patch by Belugas.
rubidium
parents: 7645
diff changeset
    23
	NUM_INDUSTRYTYPES      = 64,                         ///< total number of industries, new and old
6743
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
    24
	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
    25
	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
    26
	INVALID_INDUSTRYTYPE   = NUM_INDUSTRYTYPES,          ///< one above amount is considered invalid
7654
533a9c9a5e83 (svn r11185) -Codechange: prepare some more code for the introduction of NewIndustries. Patch by Belugas.
rubidium
parents: 7645
diff changeset
    27
	NUM_INDUSTRYTILES      = 512,                        ///< total number of industry tiles, new and old
6743
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
    28
	INVALID_INDUSTRYTILE   = NUM_INDUSTRYTILES,          ///< one above amount is considered invalid
7291
5e5bc8463be7 (svn r10639) -Codechange: Give meaninfull name to a magic number
belugas
parents: 7259
diff changeset
    29
	INDUSTRY_COMPLETED     = 3,                          ///< final stage of industry construction.
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
    30
};
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
    31
6765
50903afa1a48 (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 6743
diff changeset
    32
enum {
50903afa1a48 (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 6743
diff changeset
    33
	CLEAN_RANDOMSOUNDS,    ///< Free the dynamically allocated sounds table
50903afa1a48 (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 6743
diff changeset
    34
	CLEAN_TILELSAYOUT,     ///< Free the dynamically allocated tile layout structure
50903afa1a48 (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 6743
diff changeset
    35
};
50903afa1a48 (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 6743
diff changeset
    36
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    37
enum IndustryLifeType {
7144
8e73641511f3 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7132
diff changeset
    38
	INDUSTRYLIFE_BLACK_HOLE =      0, ///< Like power plants and banks
8e73641511f3 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7132
diff changeset
    39
	INDUSTRYLIFE_EXTRACTIVE = 1 << 0, ///< Like mines
8e73641511f3 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7132
diff changeset
    40
	INDUSTRYLIFE_ORGANIC    = 1 << 1, ///< Like forests
8e73641511f3 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7132
diff changeset
    41
	INDUSTRYLIFE_PROCESSING = 1 << 2, ///< Like factories
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    42
};
4924
b6fa01b5a80d (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    43
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
    44
/* 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
    45
 * 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
    46
enum CheckProc {
7173
64d122c20efb (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7165
diff changeset
    47
	CHECK_NOTHING,
64d122c20efb (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7165
diff changeset
    48
	CHECK_FOREST,
64d122c20efb (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7165
diff changeset
    49
	CHECK_REFINERY,
64d122c20efb (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7165
diff changeset
    50
	CHECK_FARM,
64d122c20efb (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7165
diff changeset
    51
	CHECK_PLANTATION,
64d122c20efb (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7165
diff changeset
    52
	CHECK_WATER,
64d122c20efb (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7165
diff changeset
    53
	CHECK_LUMBERMILL,
64d122c20efb (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7165
diff changeset
    54
	CHECK_BUBBLEGEN,
64d122c20efb (svn r10447) -Codechange: Don't need to specify values on an enum when those values are contiguous
belugas
parents: 7165
diff changeset
    55
	CHECK_OIL_RIG,
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
    56
	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
    57
};
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
    58
7259
abefcd6ff972 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7229
diff changeset
    59
/** How was the industry created */
7186
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
    60
enum IndustryConstructionType {
7259
abefcd6ff972 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7229
diff changeset
    61
	ICT_UNKNOWN,          ///< in previous game version or without newindustries activated
abefcd6ff972 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7229
diff changeset
    62
	ICT_NORMAL_GAMEPLAY,  ///< either by user or random creation proccess
abefcd6ff972 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7229
diff changeset
    63
	ICT_MAP_GENERATION,   ///< during random map creation
abefcd6ff972 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7229
diff changeset
    64
	ICT_SCENARIO_EDITOR   ///< while scenarion edition
abefcd6ff972 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7229
diff changeset
    65
};
abefcd6ff972 (svn r10570) -Codechange: Add enum required for Callback 0x22: CBID_INDUSTRY_AVAILABLE
belugas
parents: 7229
diff changeset
    66
7757
3e63b119a5bf (svn r11302) -Fix (r9520): typo
glx
parents: 7654
diff changeset
    67
enum IndustryBehaviour {
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
    68
	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
    69
	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
    70
	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
    71
	INDUSTRYBEH_BUILT_ONWATER         = 1 << 2,  ///< is built on water (oil rig)
9950
2a0d0769c0e3 (svn r14105) -Fix: Some typos that are more grammatical errors, as it seems.
belugas
parents: 9306
diff changeset
    72
	INDUSTRYBEH_TOWN1200_MORE         = 1 << 3,  ///< can only be built in towns larger than 1200 inhabitants (temperate bank)
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
    73
	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
    74
	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
    75
	INDUSTRYBEH_PLANT_ON_BUILT        = 1 << 6,  ///< Fields are planted around when built (all farms)
7132
0af71cb216ff (svn r10406) -Fix [FS#968]: only industries in the temperate climate should be affected by the "do not increase production" flag.
rubidium
parents: 7107
diff changeset
    76
	INDUSTRYBEH_DONT_INCR_PROD        = 1 << 7,  ///< do not increase production (oil wells) in the temperate climate
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
    77
	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
    78
	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
    79
	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
    80
	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
    81
	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
    82
	INDUSTRYBEH_CAN_SUBSIDENCE        = 1 << 13, ///< can cause a subsidence (coal mine, shaft that collapses)
7614
edf90d673e04 (svn r11143) -Fix: the random bits were not set for the production callback when the NewGRF asked for it.
rubidium
parents: 7610
diff changeset
    83
	/* The following flags are only used for newindustries and do no represent any normal behaviour */
edf90d673e04 (svn r11143) -Fix: the random bits were not set for the production callback when the NewGRF asked for it.
rubidium
parents: 7610
diff changeset
    84
	INDUSTRYBEH_PROD_MULTI_HNDLING    = 1 << 14, ///< Automatic production multiplier handling
edf90d673e04 (svn r11143) -Fix: the random bits were not set for the production callback when the NewGRF asked for it.
rubidium
parents: 7610
diff changeset
    85
	INDUSTRYBEH_PRODCALLBACK_RANDOM   = 1 << 15, ///< Production callback needs random bits in var 10
edf90d673e04 (svn r11143) -Fix: the random bits were not set for the production callback when the NewGRF asked for it.
rubidium
parents: 7610
diff changeset
    86
	INDUSTRYBEH_NOBUILT_MAPCREATION   = 1 << 16, ///< Do not force one instance of this type to appear on map generation
7608
7c091bba8741 (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: 7496
diff changeset
    87
	INDUSTRYBEH_CANCLOSE_LASTINSTANCE = 1 << 17, ///< Allow closing down the last instance of this type
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
    88
};
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
    89
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
    90
7757
3e63b119a5bf (svn r11302) -Fix (r9520): typo
glx
parents: 7654
diff changeset
    91
DECLARE_ENUM_AS_BIT_SET(IndustryBehaviour);
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
    92
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7337
diff changeset
    93
DECLARE_OLD_POOL(Industry, Industry, 3, 8000)
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7337
diff changeset
    94
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
    95
/**
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
    96
 * 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
    97
 */
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7337
diff changeset
    98
struct Industry : PoolItem<Industry, IndustryID, &_Industry_pool> {
7610
13b7d9e247d2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 7608
diff changeset
    99
	typedef PersistentStorageArray<uint32, 16> PersistentStorage;
13b7d9e247d2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 7608
diff changeset
   100
6819
f986f54e2660 (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: 6815
diff changeset
   101
	TileIndex xy;                       ///< coordinates of the primary tile the industry is built one
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
   102
	byte width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
	byte height;
6819
f986f54e2660 (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: 6815
diff changeset
   104
	const Town *town;                   ///< Nearest town
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7639
diff changeset
   105
	CargoID produced_cargo[2];          ///< 2 production cargo slots
7165
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7144
diff changeset
   106
	uint16 produced_cargo_waiting[2];   ///< amount of cargo produced per cargo
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7144
diff changeset
   107
	uint16 incoming_cargo_waiting[3];   ///< incoming cargo waiting to be processed
6819
f986f54e2660 (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: 6815
diff changeset
   108
	byte production_rate[2];            ///< production rate for each cargo
f986f54e2660 (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: 6815
diff changeset
   109
	byte prod_level;                    ///< general production level
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7639
diff changeset
   110
	CargoID accepts_cargo[3];           ///< 3 input cargo slots
6819
f986f54e2660 (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: 6815
diff changeset
   111
	uint16 this_month_production[2];    ///< stats of this month's production per cargo
f986f54e2660 (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: 6815
diff changeset
   112
	uint16 this_month_transported[2];   ///< stats of this month's transport per cargo
f986f54e2660 (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: 6815
diff changeset
   113
	byte last_month_pct_transported[2]; ///< percentage transported per cargo in the last full month
f986f54e2660 (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: 6815
diff changeset
   114
	uint16 last_month_production[2];    ///< total units produced per cargo in the last full month
f986f54e2660 (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: 6815
diff changeset
   115
	uint16 last_month_transported[2];   ///< total units transported per cargo in the last full month
f986f54e2660 (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: 6815
diff changeset
   116
	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
   117
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7291
diff changeset
   118
	IndustryType type;                  ///< type of industry.
6819
f986f54e2660 (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: 6815
diff changeset
   119
	OwnerByte owner;                    ///< owner of the industry.  Which SHOULD always be (imho) OWNER_NONE
f986f54e2660 (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: 6815
diff changeset
   120
	byte random_color;                  ///< randomized colour of the industry, for display purpose
f986f54e2660 (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: 6815
diff changeset
   121
	Year last_prod_year;                ///< last year of production
f986f54e2660 (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: 6815
diff changeset
   122
	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
   123
7186
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
   124
	OwnerByte founder;                  ///< Founder of the industry
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
   125
	Date construction_date;             ///< Date of the construction of the industry
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
   126
	uint8 construction_type;            ///< Way the industry was constructed (@see IndustryConstructionType)
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
   127
	Date last_cargo_accepted_at;        ///< Last day cargo was accepted by this industry
7445
4d96e6e94d88 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7390
diff changeset
   128
	byte selected_layout;               ///< Which tile layout was used when creating the industry
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7337
diff changeset
   129
7860
5cdd0d914013 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 7757
diff changeset
   130
	byte random_triggers;               ///< Triggers for the random
5cdd0d914013 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 7757
diff changeset
   131
	uint16 random;                      ///< Random value used for randomisation of all kinds of things
5cdd0d914013 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 7757
diff changeset
   132
7610
13b7d9e247d2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 7608
diff changeset
   133
	PersistentStorage psa;              ///< Persistent storage for NewGRF industries.
13b7d9e247d2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 7608
diff changeset
   134
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7337
diff changeset
   135
	Industry(TileIndex tile = 0) : xy(tile) {}
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7337
diff changeset
   136
	~Industry();
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7337
diff changeset
   137
7496
49cec492627b (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: 7473
diff changeset
   138
	inline bool IsValid() const { return this->xy != 0; }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   141
struct IndustryTileTable {
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   142
	TileIndexDiffC ti;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   143
	IndustryGfx gfx;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   144
};
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   145
6675
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   146
/** 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
   147
struct GRFFileProps {
7460
78e4e3c62f91 (svn r10961) -Codechange: Flag default substitutes of industry/tiles with a value that cannot be legal.
belugas
parents: 7445
diff changeset
   148
	uint16 subst_id;
6675
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   149
	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
   150
	struct SpriteGroup *spritegroup;      ///< pointer to the different sprites of the industry
6848
b13a56180454 (svn r10088) -Codechange: A typo and a code-style
belugas
parents: 6839
diff changeset
   151
	const struct GRFFile *grffile;        ///< grf file that introduced this industry
7107
3d6853f36dea (svn r10379) -Codechange: silence a compiler warning (which was right) about a variable too little for what's been asked to do
belugas
parents: 6848
diff changeset
   152
	uint16 override;                      ///< id of the entity been replaced by
6675
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   153
};
1c318230fd5b (svn r9906) -Codechange: Add common properties for both industry and industry tiles specs
belugas
parents: 6655
diff changeset
   154
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
   155
/**
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
   156
 * 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
   157
 */
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   158
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
   159
	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
   160
	byte num_table;                       ///< Number of elements in the table
7978
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7860
diff changeset
   161
	uint8 cost_multiplier;                ///< Base construction cost multiplier.
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7860
diff changeset
   162
	uint32 removal_cost_multiplier;       ///< Base removal cost multiplier.
7177
f9796d5be926 (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: 7173
diff changeset
   163
	uint16 raw_industry_cost_multiplier;  ///< Multiplier for the raw industries cost
f9796d5be926 (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: 7173
diff changeset
   164
	uint32 prospecting_chance;            ///< Chance prospecting succeeds
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
   165
	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
   166
	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
   167
	CargoID produced_cargo[2];
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   168
	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
   169
	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
   170
	                                      ///< 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
   171
	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
   172
	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
   173
	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
   174
	byte climate_availability;            ///< Bitmask, giving landscape enums as bit position
7757
3e63b119a5bf (svn r11302) -Fix (r9520): typo
glx
parents: 7654
diff changeset
   175
	IndustryBehaviour 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
   176
	byte map_colour;                      ///< colour used for the small map
8959
636d242edd89 (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 8470
diff changeset
   177
	StringID name;                        ///< Displayed name of the industry
636d242edd89 (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 8470
diff changeset
   178
	StringID new_industry_text;           ///< Message appearing when the industry is built
636d242edd89 (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 8470
diff changeset
   179
	StringID closure_text;                ///< Message appearing when the industry closes
636d242edd89 (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 8470
diff changeset
   180
	StringID production_up_text;          ///< Message appearing when the industry's production is increasing
636d242edd89 (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 8470
diff changeset
   181
	StringID production_down_text;        ///< Message appearing when the industry's production is decreasing
636d242edd89 (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 8470
diff changeset
   182
	StringID station_name;                ///< Default name for nearby station
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
   183
	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
   184
	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
   185
	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
   186
	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
   187
	/* 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
   188
	uint16 callback_flags;                ///< Flags telling which grf callback is set
6765
50903afa1a48 (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 6743
diff changeset
   189
	uint8 cleanup_flag;                   ///< flags indicating which data should be freed upon cleaning up
6741
bdd53720536f (svn r9974) -Codechange: Remove the enabled member of GRFFileProps, since it'snot really grf related
belugas
parents: 6736
diff changeset
   190
	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
   191
	struct GRFFileProps grf_prop;         ///< properties related the the grf file
7185
1b6b21b69c2d (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: 7177
diff changeset
   192
1b6b21b69c2d (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: 7177
diff changeset
   193
	/**
1b6b21b69c2d (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: 7177
diff changeset
   194
	 * Is an industry with the spec a raw industry?
1b6b21b69c2d (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: 7177
diff changeset
   195
	 * @return true if it should be handled as a raw industry
1b6b21b69c2d (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: 7177
diff changeset
   196
	 */
1b6b21b69c2d (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: 7177
diff changeset
   197
	bool IsRawIndustry() const;
1b6b21b69c2d (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: 7177
diff changeset
   198
1b6b21b69c2d (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: 7177
diff changeset
   199
	/**
1b6b21b69c2d (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: 7177
diff changeset
   200
	 * Get the cost for constructing this industry
1b6b21b69c2d (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: 7177
diff changeset
   201
	 * @return the cost (inflation corrected etc)
1b6b21b69c2d (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: 7177
diff changeset
   202
	 */
1b6b21b69c2d (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: 7177
diff changeset
   203
	Money GetConstructionCost() const;
7978
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7860
diff changeset
   204
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7860
diff changeset
   205
	/**
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7860
diff changeset
   206
	 * Get the cost for removing this industry
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7860
diff changeset
   207
	 * Take note that the cost will always be zero for non-grf industries.
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7860
diff changeset
   208
	 * Only if the grf author did specified a cost will it be applicable.
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7860
diff changeset
   209
	 * @return the cost (inflation corrected etc)
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7860
diff changeset
   210
	 */
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7860
diff changeset
   211
	Money GetRemovalCost() const;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   212
};
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   213
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
   214
/**
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
   215
 * 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
   216
 */
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   217
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
   218
	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
   219
	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
   220
	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
   221
	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
   222
	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
   223
	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
   224
	                                      ///< 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
   225
	/* Newgrf data */
6743
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
   226
	uint8 callback_flags;                 ///< Flags telling which grf callback is set
7229
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7186
diff changeset
   227
	uint16 animation_info;                ///< Information about the animation (is it looping, how many loops etc)
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7186
diff changeset
   228
	uint8 animation_speed;                ///< The speed of the animation
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7186
diff changeset
   229
	uint8 animation_triggers;             ///< When to start the animation
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7186
diff changeset
   230
	uint8 animation_special_flags;        ///< Extra flags to influence the animation
6741
bdd53720536f (svn r9974) -Codechange: Remove the enabled member of GRFFileProps, since it'snot really grf related
belugas
parents: 6736
diff changeset
   231
	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
   232
	struct GRFFileProps grf_prop;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   233
};
6092
53c6b9b18d0b (svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents: 5587
diff changeset
   234
6637
5a8e524c14f4 (svn r9868) -Codechange: bring external declaration of functions togueter and adjust a comment
belugas
parents: 6636
diff changeset
   235
/* industry_cmd.cpp*/
6743
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
   236
const IndustrySpec *GetIndustrySpec(IndustryType thistype);    ///< Array of industries data
7462
74a281f80498 (svn r10963) -Revert(10700): Although the idea was good, it was more prone of errors than usefull.
belugas
parents: 7460
diff changeset
   237
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
   238
void ResetIndustries();
5a8e524c14f4 (svn r9868) -Codechange: bring external declaration of functions togueter and adjust a comment
belugas
parents: 6636
diff changeset
   239
void PlantRandomFarmField(const Industry *i);
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
   240
6743
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
   241
/* writable arrays of specs */
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6741
diff changeset
   242
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
   243
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
   244
7467
e586e63fc58e (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: 7462
diff changeset
   245
static inline IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
e586e63fc58e (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: 7462
diff changeset
   246
{
7473
3dfe8243a870 (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: 7467
diff changeset
   247
	/* the 0xFF should be GFX_WATERTILE_SPECIALCHECK but for reasons of include mess,
3dfe8243a870 (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: 7467
diff changeset
   248
	 * we'll simplify the writing.
3dfe8243a870 (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: 7467
diff changeset
   249
	 * Basically, the first test is required since the GFX_WATERTILE_SPECIALCHECK value
3dfe8243a870 (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: 7467
diff changeset
   250
	 * will never be assigned as a tile index and is only required in order to do some
3dfe8243a870 (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: 7467
diff changeset
   251
	 * tests while building the industry (as in WATER REQUIRED */
3dfe8243a870 (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: 7467
diff changeset
   252
	if (gfx != 0xFF) {
3dfe8243a870 (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: 7467
diff changeset
   253
		assert(gfx < INVALID_INDUSTRYTILE);
3dfe8243a870 (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: 7467
diff changeset
   254
		const IndustryTileSpec *it = &_industry_tile_specs[gfx];
3dfe8243a870 (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: 7467
diff changeset
   255
		return it->grf_prop.override == INVALID_INDUSTRYTILE ? gfx : it->grf_prop.override;
3dfe8243a870 (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: 7467
diff changeset
   256
	} else {
3dfe8243a870 (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: 7467
diff changeset
   257
		return gfx;
3dfe8243a870 (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: 7467
diff changeset
   258
	}
7467
e586e63fc58e (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: 7462
diff changeset
   259
}
e586e63fc58e (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: 7462
diff changeset
   260
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
   261
/* 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
   262
void BuildIndustriesLegend();
10146
cfea97f96067 (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas
parents: 9950
diff changeset
   263
/* industry_cmd.cpp */
cfea97f96067 (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas
parents: 9950
diff changeset
   264
void SetIndustryDailyChanges();
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
   265
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
   266
/**
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
   267
 * 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
   268
 * @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
   269
 * @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
   270
 */
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
   271
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
   272
{
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7337
diff changeset
   273
	return index < GetIndustryPoolSize() && GetIndustry(index)->IsValid();
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
   274
}
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
   275
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   276
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   277
static inline IndustryID GetMaxIndustryIndex()
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   278
{
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   279
	/* 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
   280
	 *  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
   281
	 *  _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
   282
	 *  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
   283
	 */
5298
46eabcb5c2b2 (svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
rubidium
parents: 5247
diff changeset
   284
	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
   285
}
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
   286
6839
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6825
diff changeset
   287
extern int _total_industries;  // general counter
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6825
diff changeset
   288
extern uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6825
diff changeset
   289
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   290
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
   291
{
4357
aaba385fa723 (svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
truelight
parents: 4356
diff changeset
   292
	return _total_industries;
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   293
}
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   294
6824
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   295
/** Increment the count of industries for this type
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   296
 * @param type IndustryType to increment
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   297
 * @pre type < INVALID_INDUSTRYTYPE */
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   298
static inline void IncIndustryTypeCount(IndustryType type)
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   299
{
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   300
	assert(type < INVALID_INDUSTRYTYPE);
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   301
	_industry_counts[type]++;
6839
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6825
diff changeset
   302
	_total_industries++;
6824
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   303
}
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   304
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   305
/** Decrement the count of industries for this type
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   306
 * @param type IndustryType to decrement
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   307
 * @pre type < INVALID_INDUSTRYTYPE */
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   308
static inline void DecIndustryTypeCount(IndustryType type)
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   309
{
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   310
	assert(type < INVALID_INDUSTRYTYPE);
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   311
	_industry_counts[type]--;
6839
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6825
diff changeset
   312
	_total_industries--;
6824
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   313
}
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   314
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   315
/** get the count of industries for this type
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   316
 * @param type IndustryType to query
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   317
 * @pre type < INVALID_INDUSTRYTYPE */
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   318
static inline uint8 GetIndustryTypeCount(IndustryType type)
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   319
{
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   320
	assert(type < INVALID_INDUSTRYTYPE);
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   321
	return min(_industry_counts[type], 0xFF); // callback expects only a byte, so cut it
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   322
}
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   323
6839
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6825
diff changeset
   324
/** Resets both the total_industries and the _industry_counts
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6825
diff changeset
   325
 * This way, we centralize all counts activities */
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6825
diff changeset
   326
static inline void ResetIndustryCounts()
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6825
diff changeset
   327
{
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6825
diff changeset
   328
	_total_industries = 0;
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6825
diff changeset
   329
	memset(&_industry_counts, 0, sizeof(_industry_counts));
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6825
diff changeset
   330
}
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6825
diff changeset
   331
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
   332
/**
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
   333
 * 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
   334
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   335
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
   336
{
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
   337
	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
   338
	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
   339
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
   340
	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
   341
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
   342
	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
   343
		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
   344
		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
   345
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
   346
		/* 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
   347
		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
   348
			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
   349
			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
   350
		}
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
   351
	}
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
   352
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
   353
	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
   354
}
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
   355
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7337
diff changeset
   356
#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
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
   357
#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
   358
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7291
diff changeset
   359
static const uint8 IT_INVALID = 255;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
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
   361
#endif /* INDUSTRY_H */