author | KUDr |
Mon, 26 Mar 2007 22:15:38 +0000 | |
branch | cpp_gui |
changeset 6303 | 84c215fc8eb8 |
parent 6298 | c30fe89622df |
child 6307 | f40e88cff863 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
3 |
/** @file industry.h */ |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
4 |
|
0 | 5 |
#ifndef INDUSTRY_H |
6 |
#define INDUSTRY_H |
|
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" |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1220
diff
changeset
|
9 |
|
3689
db67c356f44b
(svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents:
3499
diff
changeset
|
10 |
typedef byte IndustryGfx; |
db67c356f44b
(svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents:
3499
diff
changeset
|
11 |
typedef uint8 IndustryType; |
db67c356f44b
(svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents:
3499
diff
changeset
|
12 |
|
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
|
13 |
enum { |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4326
diff
changeset
|
14 |
INVALID_INDUSTRY = 0xFFFF, |
6303 | 15 |
INDUTILE_NOANIM = 0xFF, ///< flag to mark industry tiles as having no animation |
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
|
16 |
}; |
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
|
17 |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6285
diff
changeset
|
18 |
enum IndustryLifeType { |
4924
6e29520a0ba8
(svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents:
4403
diff
changeset
|
19 |
INDUSTRYLIFE_NOT_CLOSABLE, ///< Industry can never close |
6e29520a0ba8
(svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents:
4403
diff
changeset
|
20 |
INDUSTRYLIFE_PRODUCTION, ///< Industry can close and change of production |
6e29520a0ba8
(svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents:
4403
diff
changeset
|
21 |
INDUSTRYLIFE_CLOSABLE, ///< Industry can only close (no production change) |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6285
diff
changeset
|
22 |
}; |
4924
6e29520a0ba8
(svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents:
4403
diff
changeset
|
23 |
|
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
24 |
/** |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
25 |
* Defines the internal data of a functionnal industry |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
26 |
*/ |
0 | 27 |
struct Industry { |
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
28 |
TileIndex xy; ///< coordinates of the primary tile the industry is built one |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
29 |
byte width; |
0 | 30 |
byte height; |
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
31 |
const Town* town; ///< Nearest town |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
32 |
CargoID produced_cargo[2]; ///< 2 production cargo slots |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
33 |
uint16 cargo_waiting[2]; ///< amount of cargo produced per cargo |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
34 |
byte production_rate[2]; ///< production rate for each cargo |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
35 |
CargoID accepts_cargo[3]; ///< 3 input cargo slots |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
36 |
byte prod_level; ///< general production level |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
37 |
uint16 last_mo_production[2]; ///< stats of last month production per cargo |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
38 |
uint16 last_mo_transported[2]; ///< stats of last month transport per cargo |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
39 |
byte pct_transported[2]; ///< percentage transported per cargo |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
40 |
uint16 total_production[2]; ///< total units produced per cargo |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
41 |
uint16 total_transported[2]; ///< total units transported per cargo |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
42 |
uint16 counter; ///< used for animation and/or production (if available cargo) |
0 | 43 |
|
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
44 |
byte type; ///< type of industry. see IT_COAL_MINE and others |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
45 |
OwnerByte owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
46 |
byte random_color; ///< randomized colour of the industry, for display purpose |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
47 |
Year last_prod_year; ///< last year of production |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
48 |
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
|
49 |
|
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
50 |
IndustryID index; ///< index of the industry in the pool of industries |
0 | 51 |
}; |
52 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6285
diff
changeset
|
53 |
struct IndustryTileTable { |
3689
db67c356f44b
(svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents:
3499
diff
changeset
|
54 |
TileIndexDiffC ti; |
db67c356f44b
(svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents:
3499
diff
changeset
|
55 |
IndustryGfx gfx; |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6285
diff
changeset
|
56 |
}; |
3689
db67c356f44b
(svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents:
3499
diff
changeset
|
57 |
|
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
58 |
/** |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
59 |
* Defines the data structure for constructing industry. |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
60 |
*/ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6285
diff
changeset
|
61 |
struct IndustrySpec { |
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
62 |
const IndustryTileTable *const *table;///< List of the tiles composing the industry |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
63 |
byte num_table; ///< Number of elements in the table |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
64 |
byte cost_multiplier; ///< Base cost multiplier*/ |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
65 |
IndustryType conflicting[3]; ///< Industries this industry cannot be close to |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
66 |
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
|
67 |
CargoID produced_cargo[2]; |
db67c356f44b
(svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents:
3499
diff
changeset
|
68 |
byte production_rate[2]; |
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
69 |
byte minimal_cargo; ///< minimum amount of cargo transported to the stations |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
70 |
///< If the waiting cargo is less than this number, no cargo is moved to it |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
71 |
CargoID accepts_cargo[3]; ///< 3 accepted cargos |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
72 |
IndustryLifeType life_type; ///< This is also known as Industry production flag, in newgrf specs |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
73 |
byte climate_availability; ///< Bitmask, giving landscape enums as bit position |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
74 |
StringID name; ///< Displayed name of the industry |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6285
diff
changeset
|
75 |
StringID new_industry_text; ///< Message appearing when the industry is built |
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
76 |
StringID closure_text; ///< Message appearing when the industry closes |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
77 |
StringID production_up_text; ///< Message appearing when the industry's production is increasing |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
78 |
StringID production_down_text; ///< Message appearing when the industry's production is decreasing |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6285
diff
changeset
|
79 |
}; |
3689
db67c356f44b
(svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents:
3499
diff
changeset
|
80 |
|
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
81 |
/** |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
82 |
* Defines the data structure of each indivudual tile of an industry. |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
83 |
*/ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6285
diff
changeset
|
84 |
struct IndustryTileSpec { |
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
85 |
CargoID accepts_cargo[3]; ///< Cargo accepted by this tile |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
86 |
Slope slopes_refused; ///< slope pattern on which this tile cannot be built |
6303 | 87 |
byte anim_production; ///< Animation frame to start when goods are produced |
88 |
byte anim_next; ///< Next frame in an animation |
|
89 |
bool anim_state; ///< When true, the tile has to be drawn using the animation |
|
90 |
///< state instead of the construction state |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6285
diff
changeset
|
91 |
}; |
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
5838
diff
changeset
|
92 |
|
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
93 |
const IndustrySpec *GetIndustrySpec(IndustryType thistype); ///< Array of industries default data |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
94 |
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx); ///< Array of industry tiles default data |
3689
db67c356f44b
(svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents:
3499
diff
changeset
|
95 |
|
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
|
96 |
DECLARE_OLD_POOL(Industry, Industry, 3, 8000) |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
830
diff
changeset
|
97 |
|
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1220
diff
changeset
|
98 |
/** |
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1267
diff
changeset
|
99 |
* Check if an Industry really exists. |
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
100 |
* @param industry to check |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
101 |
* @return true if position is a valid one |
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1267
diff
changeset
|
102 |
*/ |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
103 |
static inline bool IsValidIndustry(const Industry *industry) |
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1267
diff
changeset
|
104 |
{ |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
105 |
return industry->xy != 0; |
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1267
diff
changeset
|
106 |
} |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1267
diff
changeset
|
107 |
|
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
108 |
/** |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
109 |
* Check if an Industry exists whithin the pool of industries |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
110 |
* @param index of the desired industry |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
111 |
* @return true if it is inside the pool |
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
112 |
*/ |
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
|
113 |
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
|
114 |
{ |
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
|
115 |
return index < GetIndustryPoolSize() && IsValidIndustry(GetIndustry(index)); |
5d613241ee5e
(svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents:
5298
diff
changeset
|
116 |
} |
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
|
117 |
|
6285
187e3ef04cc9
(svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents:
6268
diff
changeset
|
118 |
VARDEF int _total_industries; //general counter |
4354
684ab9249dae
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4346
diff
changeset
|
119 |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6285
diff
changeset
|
120 |
static inline IndustryID GetMaxIndustryIndex() |
4354
684ab9249dae
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4346
diff
changeset
|
121 |
{ |
684ab9249dae
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4346
diff
changeset
|
122 |
/* 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
|
123 |
* 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
|
124 |
* _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
|
125 |
* 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
|
126 |
*/ |
5298
6d4c150bdd94
(svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
rubidium
parents:
5247
diff
changeset
|
127 |
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
|
128 |
} |
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
|
129 |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6285
diff
changeset
|
130 |
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
|
131 |
{ |
4357
3d72606e9192
(svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
truelight
parents:
4356
diff
changeset
|
132 |
return _total_industries; |
4354
684ab9249dae
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4346
diff
changeset
|
133 |
} |
684ab9249dae
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4346
diff
changeset
|
134 |
|
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
|
135 |
/** |
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
|
136 |
* 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
|
137 |
*/ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6285
diff
changeset
|
138 |
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
|
139 |
{ |
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
|
140 |
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
|
141 |
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
|
142 |
|
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
|
143 |
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
|
144 |
|
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
|
145 |
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
|
146 |
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
|
147 |
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
|
148 |
|
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
|
149 |
/* 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
|
150 |
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
|
151 |
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
|
152 |
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
|
153 |
} |
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
|
154 |
} |
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
|
155 |
|
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
|
156 |
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
|
157 |
} |
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
|
158 |
|
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
159 |
void DestroyIndustry(Industry *i); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
160 |
|
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
161 |
static inline void DeleteIndustry(Industry *i) |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
162 |
{ |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
163 |
DestroyIndustry(i); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
164 |
i->xy = 0; |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
165 |
} |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
166 |
|
4976
a0d7f63c35b5
(svn r6979) Use the pool macros for the Industry pool
tron
parents:
4966
diff
changeset
|
167 |
#define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) if (IsValidIndustry(i)) |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1220
diff
changeset
|
168 |
#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
|
169 |
|
4277
3539bd14f023
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
3689
diff
changeset
|
170 |
VARDEF const Industry** _industry_sort; |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1220
diff
changeset
|
171 |
VARDEF bool _industry_sort_dirty; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
830
diff
changeset
|
172 |
|
3496
2775485abdf6
(svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents:
3350
diff
changeset
|
173 |
|
0 | 174 |
void DeleteIndustry(Industry *is); |
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
|
175 |
void PlantRandomFarmField(const Industry *i); |
0 | 176 |
|
177 |
enum { |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
178 |
IT_COAL_MINE = 0, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
179 |
IT_POWER_STATION = 1, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
180 |
IT_SAWMILL = 2, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
181 |
IT_FOREST = 3, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
182 |
IT_OIL_REFINERY = 4, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
183 |
IT_OIL_RIG = 5, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
184 |
IT_FACTORY = 6, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
185 |
IT_PRINTING_WORKS = 7, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
186 |
IT_STEEL_MILL = 8, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
187 |
IT_FARM = 9, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
188 |
IT_COPPER_MINE = 10, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
189 |
IT_OIL_WELL = 11, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
190 |
IT_BANK_TEMP = 12, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
191 |
IT_FOOD_PROCESS = 13, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
192 |
IT_PAPER_MILL = 14, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
193 |
IT_GOLD_MINE = 15, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
194 |
IT_BANK_TROPIC_ARCTIC = 16, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
195 |
IT_DIAMOND_MINE = 17, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
196 |
IT_IRON_MINE = 18, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
197 |
IT_FRUIT_PLANTATION = 19, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
198 |
IT_RUBBER_PLANTATION = 20, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
199 |
IT_WATER_SUPPLY = 21, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
200 |
IT_WATER_TOWER = 22, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
201 |
IT_FACTORY_2 = 23, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
202 |
IT_FARM_2 = 24, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
203 |
IT_LUMBER_MILL = 25, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
204 |
IT_COTTON_CANDY = 26, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
205 |
IT_CANDY_FACTORY = 27, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
206 |
IT_BATTERY_FARM = 28, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
207 |
IT_COLA_WELLS = 29, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
208 |
IT_TOY_SHOP = 30, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
209 |
IT_TOY_FACTORY = 31, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
210 |
IT_PLASTIC_FOUNTAINS = 32, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
211 |
IT_FIZZY_DRINK_FACTORY = 33, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
212 |
IT_BUBBLE_GENERATOR = 34, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
213 |
IT_TOFFEE_QUARRY = 35, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
214 |
IT_SUGAR_MINE = 36, |
3499
e95d6e5f66ae
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
215 |
IT_END, |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
216 |
IT_INVALID = 255, |
0 | 217 |
}; |
218 |
||
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
|
219 |
#endif /* INDUSTRY_H */ |