|
1 /* $Id$ */ |
|
2 |
|
3 #ifndef INDUSTRY_H |
|
4 #define INDUSTRY_H |
|
5 |
|
6 #include "oldpool.h" |
|
7 |
|
8 typedef byte IndustryGfx; |
|
9 typedef uint8 IndustryType; |
|
10 |
|
11 enum { |
|
12 INVALID_INDUSTRY = 0xFFFF, |
|
13 }; |
|
14 |
|
15 typedef enum IndustryLifeTypes { |
|
16 INDUSTRYLIFE_NOT_CLOSABLE, ///< Industry can never close |
|
17 INDUSTRYLIFE_PRODUCTION, ///< Industry can close and change of production |
|
18 INDUSTRYLIFE_CLOSABLE, ///< Industry can only close (no production change) |
|
19 } IndustryLifeType; |
|
20 |
|
21 struct Industry { |
|
22 TileIndex xy; |
|
23 byte width; /* swapped order of w/h with town */ |
|
24 byte height; |
|
25 const Town* town; |
|
26 CargoID produced_cargo[2]; |
|
27 uint16 cargo_waiting[2]; |
|
28 byte production_rate[2]; |
|
29 CargoID accepts_cargo[3]; |
|
30 byte prod_level; |
|
31 uint16 last_mo_production[2]; |
|
32 uint16 last_mo_transported[2]; |
|
33 byte pct_transported[2]; |
|
34 uint16 total_production[2]; |
|
35 uint16 total_transported[2]; |
|
36 uint16 counter; |
|
37 |
|
38 byte type; |
|
39 byte owner; |
|
40 byte random_color; |
|
41 Year last_prod_year; |
|
42 byte was_cargo_delivered; |
|
43 |
|
44 IndustryID index; |
|
45 }; |
|
46 |
|
47 typedef struct IndustryTileTable { |
|
48 TileIndexDiffC ti; |
|
49 IndustryGfx gfx; |
|
50 } IndustryTileTable; |
|
51 |
|
52 typedef struct IndustrySpec { |
|
53 /** Tables with the 'layout' of different composition of GFXes */ |
|
54 const IndustryTileTable *const *table; |
|
55 /** Number of elements in the table */ |
|
56 byte num_table; |
|
57 /** Base cost multiplier*/ |
|
58 byte cost_multiplier; |
|
59 /** Industries this industry cannot be close to */ |
|
60 IndustryType conflicting[3]; |
|
61 /** index to a procedure to check for conflicting circumstances */ |
|
62 byte check_proc; |
|
63 |
|
64 CargoID produced_cargo[2]; |
|
65 byte production_rate[2]; |
|
66 /** The minimum amount of cargo transported to the stations; if the |
|
67 * waiting cargo is less than this number, no cargo is moved to it*/ |
|
68 byte minimal_cargo; |
|
69 CargoID accepts_cargo[3]; |
|
70 |
|
71 IndustryLifeType life_type; ///< This is also known as Industry production flag, in newgrf specs |
|
72 |
|
73 byte climate_availability; ///< Bitmask, giving landscape enums as bit position |
|
74 |
|
75 StringID name; |
|
76 StringID closure_text; |
|
77 StringID production_up_text; |
|
78 StringID production_down_text; |
|
79 } IndustrySpec; |
|
80 |
|
81 const IndustrySpec *GetIndustrySpec(IndustryType thistype); |
|
82 |
|
83 DECLARE_OLD_POOL(Industry, Industry, 3, 8000) |
|
84 |
|
85 /** |
|
86 * Check if an Industry really exists. |
|
87 */ |
|
88 static inline bool IsValidIndustry(const Industry *industry) |
|
89 { |
|
90 return industry->xy != 0; |
|
91 } |
|
92 |
|
93 static inline bool IsValidIndustryID(IndustryID index) |
|
94 { |
|
95 return index < GetIndustryPoolSize() && IsValidIndustry(GetIndustry(index)); |
|
96 } |
|
97 |
|
98 VARDEF int _total_industries; |
|
99 |
|
100 static inline IndustryID GetMaxIndustryIndex(void) |
|
101 { |
|
102 /* TODO - This isn't the real content of the function, but |
|
103 * with the new pool-system this will be replaced with one that |
|
104 * _really_ returns the highest index. Now it just returns |
|
105 * the next safe value we are sure about everything is below. |
|
106 */ |
|
107 return GetIndustryPoolSize() - 1; |
|
108 } |
|
109 |
|
110 static inline uint GetNumIndustries(void) |
|
111 { |
|
112 return _total_industries; |
|
113 } |
|
114 |
|
115 /** |
|
116 * Return a random valid industry. |
|
117 */ |
|
118 static inline Industry *GetRandomIndustry(void) |
|
119 { |
|
120 int num = RandomRange(GetNumIndustries()); |
|
121 IndustryID index = INVALID_INDUSTRY; |
|
122 |
|
123 if (GetNumIndustries() == 0) return NULL; |
|
124 |
|
125 while (num >= 0) { |
|
126 num--; |
|
127 index++; |
|
128 |
|
129 /* Make sure we have a valid industry */ |
|
130 while (!IsValidIndustryID(index)) { |
|
131 index++; |
|
132 assert(index <= GetMaxIndustryIndex()); |
|
133 } |
|
134 } |
|
135 |
|
136 return GetIndustry(index); |
|
137 } |
|
138 |
|
139 void DestroyIndustry(Industry *i); |
|
140 |
|
141 static inline void DeleteIndustry(Industry *i) |
|
142 { |
|
143 DestroyIndustry(i); |
|
144 i->xy = 0; |
|
145 } |
|
146 |
|
147 #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)) |
|
148 #define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0) |
|
149 |
|
150 VARDEF const Industry** _industry_sort; |
|
151 VARDEF bool _industry_sort_dirty; |
|
152 |
|
153 |
|
154 void DeleteIndustry(Industry *is); |
|
155 void PlantRandomFarmField(const Industry *i); |
|
156 |
|
157 enum { |
|
158 IT_COAL_MINE = 0, |
|
159 IT_POWER_STATION = 1, |
|
160 IT_SAWMILL = 2, |
|
161 IT_FOREST = 3, |
|
162 IT_OIL_REFINERY = 4, |
|
163 IT_OIL_RIG = 5, |
|
164 IT_FACTORY = 6, |
|
165 IT_PRINTING_WORKS = 7, |
|
166 IT_STEEL_MILL = 8, |
|
167 IT_FARM = 9, |
|
168 IT_COPPER_MINE = 10, |
|
169 IT_OIL_WELL = 11, |
|
170 IT_BANK_TEMP = 12, |
|
171 IT_FOOD_PROCESS = 13, |
|
172 IT_PAPER_MILL = 14, |
|
173 IT_GOLD_MINE = 15, |
|
174 IT_BANK_TROPIC_ARCTIC = 16, |
|
175 IT_DIAMOND_MINE = 17, |
|
176 IT_IRON_MINE = 18, |
|
177 IT_FRUIT_PLANTATION = 19, |
|
178 IT_RUBBER_PLANTATION = 20, |
|
179 IT_WATER_SUPPLY = 21, |
|
180 IT_WATER_TOWER = 22, |
|
181 IT_FACTORY_2 = 23, |
|
182 IT_FARM_2 = 24, |
|
183 IT_LUMBER_MILL = 25, |
|
184 IT_COTTON_CANDY = 26, |
|
185 IT_CANDY_FACTORY = 27, |
|
186 IT_BATTERY_FARM = 28, |
|
187 IT_COLA_WELLS = 29, |
|
188 IT_TOY_SHOP = 30, |
|
189 IT_TOY_FACTORY = 31, |
|
190 IT_PLASTIC_FOUNTAINS = 32, |
|
191 IT_FIZZY_DRINK_FACTORY = 33, |
|
192 IT_BUBBLE_GENERATOR = 34, |
|
193 IT_TOFFEE_QUARRY = 35, |
|
194 IT_SUGAR_MINE = 36, |
|
195 IT_END, |
|
196 IT_INVALID = 255, |
|
197 }; |
|
198 |
|
199 #endif /* INDUSTRY_H */ |