author | tron |
Sun, 16 Jan 2005 11:24:58 +0000 | |
changeset 1035 | 812f837ee03f |
parent 1019 | 6bae6c11e865 |
child 1048 | 8611c5c02dcb |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
3 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
552
diff
changeset
|
4 |
#include "map.h" |
0 | 5 |
#include "viewport.h" |
6 |
#include "command.h" |
|
7 |
#include "industry.h" |
|
8 |
#include "town.h" |
|
9 |
#include "vehicle.h" |
|
10 |
#include "news.h" |
|
11 |
#include "saveload.h" |
|
12 |
#include "economy.h" |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
314
diff
changeset
|
13 |
#include "sound.h" |
0 | 14 |
|
15 |
byte _industry_sound_ctr; |
|
16 |
TileIndex _industry_sound_tile; |
|
17 |
||
18 |
void ShowIndustryViewWindow(int industry); |
|
19 |
void BuildOilRig(uint tile); |
|
20 |
void DeleteOilRig(uint tile); |
|
21 |
||
22 |
typedef struct DrawIndustryTileStruct { |
|
23 |
uint32 sprite_1; |
|
24 |
uint32 sprite_2; |
|
25 |
||
26 |
byte subtile_xy; |
|
27 |
byte width_height; |
|
28 |
byte dz; |
|
29 |
byte proc; |
|
30 |
} DrawIndustryTileStruct; |
|
31 |
||
32 |
||
33 |
typedef struct DrawIndustrySpec1Struct { |
|
34 |
byte x; |
|
35 |
byte image_1; |
|
36 |
byte image_2; |
|
37 |
byte image_3; |
|
38 |
} DrawIndustrySpec1Struct; |
|
39 |
||
40 |
typedef struct DrawIndustrySpec4Struct { |
|
41 |
byte image_1; |
|
42 |
byte image_2; |
|
43 |
byte image_3; |
|
44 |
} DrawIndustrySpec4Struct; |
|
45 |
||
46 |
||
47 |
||
48 |
#include "table/industry_land.h" |
|
49 |
||
50 |
||
51 |
typedef struct IndustryTileTable { |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
52 |
TileIndexDiffC ti; |
0 | 53 |
byte map5; |
54 |
} IndustryTileTable; |
|
55 |
||
56 |
typedef struct IndustrySpec { |
|
57 |
const IndustryTileTable * const * table; |
|
58 |
byte num_table; |
|
59 |
byte a,b,c; |
|
60 |
byte produced_cargo[2]; |
|
61 |
byte production_rate[2]; |
|
62 |
byte accepts_cargo[3]; |
|
63 |
byte check_proc; |
|
64 |
} IndustrySpec; |
|
65 |
||
66 |
#include "table/build_industry.h" |
|
67 |
||
68 |
static const byte _industry_close_mode[37] = { |
|
69 |
1,0,2,1,2,1,2,2,2,1,1,1,0,2,2,1,0,1,1,1,1,1,0,2,1,2,1,2,1,1,0,2,1,2,1,1,1, |
|
70 |
}; |
|
71 |
||
72 |
static const StringID _industry_prod_up_strings[] = { |
|
73 |
STR_4836_NEW_COAL_SEAM_FOUND_AT, |
|
74 |
STR_4835_INCREASES_PRODUCTION, |
|
75 |
STR_4835_INCREASES_PRODUCTION, |
|
76 |
STR_4835_INCREASES_PRODUCTION, |
|
77 |
STR_4835_INCREASES_PRODUCTION, |
|
78 |
STR_4837_NEW_OIL_RESERVES_FOUND, |
|
79 |
STR_4835_INCREASES_PRODUCTION, |
|
80 |
STR_4835_INCREASES_PRODUCTION, |
|
81 |
STR_4835_INCREASES_PRODUCTION, |
|
82 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
83 |
STR_4835_INCREASES_PRODUCTION, |
|
84 |
STR_4837_NEW_OIL_RESERVES_FOUND, |
|
85 |
STR_4835_INCREASES_PRODUCTION, |
|
86 |
STR_4835_INCREASES_PRODUCTION, |
|
87 |
STR_4835_INCREASES_PRODUCTION, |
|
88 |
STR_4835_INCREASES_PRODUCTION, |
|
89 |
STR_4835_INCREASES_PRODUCTION, |
|
90 |
STR_4835_INCREASES_PRODUCTION, |
|
91 |
STR_4835_INCREASES_PRODUCTION, |
|
92 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
93 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
94 |
STR_4835_INCREASES_PRODUCTION, |
|
95 |
STR_4835_INCREASES_PRODUCTION, |
|
96 |
STR_4835_INCREASES_PRODUCTION, |
|
97 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
98 |
STR_4835_INCREASES_PRODUCTION, |
|
99 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
100 |
STR_4835_INCREASES_PRODUCTION, |
|
101 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
102 |
STR_4835_INCREASES_PRODUCTION, |
|
103 |
STR_4835_INCREASES_PRODUCTION, |
|
104 |
STR_4835_INCREASES_PRODUCTION, |
|
105 |
STR_4835_INCREASES_PRODUCTION, |
|
106 |
STR_4835_INCREASES_PRODUCTION, |
|
107 |
STR_4835_INCREASES_PRODUCTION, |
|
108 |
STR_4835_INCREASES_PRODUCTION, |
|
109 |
STR_4835_INCREASES_PRODUCTION, |
|
110 |
}; |
|
111 |
||
112 |
static const StringID _industry_prod_down_strings[] = { |
|
113 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
114 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
115 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
116 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
117 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
118 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
119 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
120 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
121 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
122 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
123 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
124 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
125 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
126 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
127 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
128 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
129 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
130 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
131 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
132 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
133 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
134 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
135 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
136 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
137 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
138 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
139 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
140 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
141 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
142 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
143 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
144 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
145 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
146 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
147 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
148 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
149 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
150 |
}; |
|
151 |
||
152 |
static const StringID _industry_close_strings[] = { |
|
153 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
154 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
155 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
156 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
157 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
158 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
159 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
160 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
161 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
162 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
163 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
164 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
165 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
166 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
167 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
168 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
169 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
170 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
171 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
172 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
173 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
174 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
175 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
176 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
177 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
178 |
STR_4834_LACK_OF_NEARBY_TREES_CAUSES, |
|
179 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
180 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
181 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
182 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
183 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
184 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
185 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
186 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
187 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
188 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
189 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE , |
|
190 |
}; |
|
191 |
||
192 |
||
193 |
static void IndustryDrawTileProc1(TileInfo *ti) |
|
194 |
{ |
|
195 |
const DrawIndustrySpec1Struct *d; |
|
196 |
uint32 image; |
|
197 |
||
198 |
if (!(_map_owner[ti->tile] & 0x80)) |
|
199 |
return; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
200 |
|
0 | 201 |
d = &_draw_industry_spec1[_map3_lo[ti->tile]]; |
202 |
||
203 |
AddChildSpriteScreen(0x12A7 + d->image_1, d->x, 0); |
|
204 |
||
205 |
if ( (image = d->image_2) != 0) |
|
206 |
AddChildSpriteScreen(0x12B0 + image - 1, 8, 41); |
|
207 |
||
208 |
if ( (image = d->image_3) != 0) |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
209 |
AddChildSpriteScreen(0x12AC + image - 1, |
0 | 210 |
_drawtile_proc1_x[image-1], _drawtile_proc1_y[image-1]); |
211 |
} |
|
212 |
||
213 |
static void IndustryDrawTileProc2(TileInfo *ti) |
|
214 |
{ |
|
215 |
int x = 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
216 |
|
0 | 217 |
if (_map_owner[ti->tile] & 0x80) { |
218 |
x = _industry_anim_offs[_map3_lo[ti->tile]]; |
|
219 |
if ( (byte)x == 0xFF) |
|
220 |
x = 0; |
|
221 |
} |
|
222 |
||
223 |
AddChildSpriteScreen(0x129F, 22-x, x+24); |
|
224 |
AddChildSpriteScreen(0x129E, 6, 0xE); |
|
225 |
} |
|
226 |
||
227 |
static void IndustryDrawTileProc3(TileInfo *ti) |
|
228 |
{ |
|
229 |
if (_map_owner[ti->tile] & 0x80) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
230 |
AddChildSpriteScreen(0x128B, 5, |
0 | 231 |
_industry_anim_offs_2[_map3_lo[ti->tile]]); |
232 |
} |
|
552
698b1118e41f
(svn r952) -A tiny insignificant fix for a toyland industry gfx
darkvater
parents:
543
diff
changeset
|
233 |
AddChildSpriteScreen(4746, 3, 67); |
0 | 234 |
} |
235 |
||
236 |
static void IndustryDrawTileProc4(TileInfo *ti) |
|
237 |
{ |
|
238 |
const DrawIndustrySpec4Struct *d; |
|
239 |
||
240 |
d = &_industry_anim_offs_3[_map3_lo[ti->tile]]; |
|
241 |
||
242 |
if (d->image_1 != 0xFF) { |
|
243 |
AddChildSpriteScreen(0x126F, 0x32 - d->image_1 * 2, 0x60 + d->image_1); |
|
244 |
} |
|
245 |
||
246 |
if (d->image_2 != 0xFF) { |
|
247 |
AddChildSpriteScreen(0x1270, 0x10 - d->image_2*2, 100 + d->image_2); |
|
248 |
} |
|
249 |
||
250 |
AddChildSpriteScreen(0x126E, 7, d->image_3); |
|
251 |
AddChildSpriteScreen(0x126D, 0, 42); |
|
252 |
} |
|
253 |
||
254 |
static void DrawCoalPlantSparkles(TileInfo *ti) |
|
255 |
{ |
|
256 |
int image = _map_owner[ti->tile]; |
|
257 |
if (image & 0x80) { |
|
258 |
image = (image >> 2) & 0x1F; |
|
259 |
if (image != 0 && image < 7) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
260 |
AddChildSpriteScreen(image + 0x806, |
0 | 261 |
_coal_plant_sparkles_x[image-1], |
262 |
_coal_plant_sparkles_y[image-1] |
|
263 |
); |
|
264 |
} |
|
265 |
} |
|
266 |
} |
|
267 |
||
268 |
typedef void IndustryDrawTileProc(TileInfo *ti); |
|
269 |
static IndustryDrawTileProc * const _industry_draw_tile_procs[5] = { |
|
270 |
IndustryDrawTileProc1, |
|
271 |
IndustryDrawTileProc2, |
|
272 |
IndustryDrawTileProc3, |
|
273 |
IndustryDrawTileProc4, |
|
274 |
DrawCoalPlantSparkles, |
|
275 |
}; |
|
276 |
||
277 |
static void DrawTile_Industry(TileInfo *ti) |
|
278 |
{ |
|
279 |
Industry *ind; |
|
280 |
const DrawIndustryTileStruct *dits; |
|
281 |
byte z; |
|
282 |
uint32 image, ormod; |
|
283 |
||
284 |
/* Pointer to industry */ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
285 |
ind = GetIndustry(_map2[ti->tile]); |
0 | 286 |
ormod = (ind->color_map+0x307)<<16; |
287 |
||
288 |
/* Retrieve pointer to the draw industry tile struct */ |
|
289 |
dits = &_industry_draw_tile_data[(ti->map5<<2) | (_map_owner[ti->tile]&3)]; |
|
290 |
||
291 |
image = dits->sprite_1; |
|
292 |
if (image&0x8000 && (image & 0xFFFF0000) == 0) |
|
293 |
image |= ormod; |
|
294 |
||
295 |
z = ti->z; |
|
296 |
/* Add bricks below the industry? */ |
|
297 |
if (ti->tileh & 0xF) { |
|
298 |
AddSortableSpriteToDraw((ti->tileh & 0xF) + 0x3DD, ti->x, ti->y, 16, 16, 7, z); |
|
299 |
AddChildSpriteScreen(image, 0x1F, 1); |
|
300 |
z += 8; |
|
301 |
} else { |
|
302 |
/* Else draw regular ground */ |
|
303 |
DrawGroundSprite(image); |
|
304 |
} |
|
305 |
||
306 |
/* Add industry on top of the ground? */ |
|
307 |
if ((image = dits->sprite_2) != 0) { |
|
308 |
||
309 |
if (image&0x8000 && (image & 0xFFFF0000) == 0) |
|
310 |
image |= ormod; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
311 |
|
497
4d1c889526ee
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
312 |
if (_display_opt & DO_TRANS_BUILDINGS) |
0 | 313 |
image = (image & 0x3FFF) | 0x3224000; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
314 |
|
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
315 |
AddSortableSpriteToDraw(image, |
0 | 316 |
ti->x | (dits->subtile_xy>>4), |
317 |
ti->y | (dits->subtile_xy&0xF), |
|
318 |
(dits->width_height>>4)+1, |
|
319 |
(dits->width_height&0xF)+1, |
|
320 |
dits->dz, |
|
321 |
z); |
|
322 |
||
497
4d1c889526ee
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
323 |
if (_display_opt & DO_TRANS_BUILDINGS) |
0 | 324 |
return; |
325 |
} |
|
326 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
327 |
/* TTDBUG: strange code here, return if AddSortableSpriteToDraw failed? */ |
0 | 328 |
{ |
329 |
int proc; |
|
330 |
if ((proc=dits->proc-1) >= 0 ) |
|
331 |
_industry_draw_tile_procs[proc](ti); |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
||
336 |
static uint GetSlopeZ_Industry(TileInfo *ti) { |
|
337 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z; |
|
338 |
} |
|
339 |
||
39 | 340 |
static uint GetSlopeTileh_Industry(TileInfo *ti) { |
341 |
return 0; |
|
342 |
} |
|
343 |
||
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
344 |
static void GetAcceptedCargo_Industry(uint tile, AcceptedCargo ac) |
0 | 345 |
{ |
346 |
int m5 = _map5[tile]; |
|
347 |
int a; |
|
348 |
||
349 |
a = _industry_map5_accepts_1[m5]; |
|
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
350 |
if (a >= 0) ac[a] = (a == 0) ? 1 : 8; |
0 | 351 |
|
352 |
a = _industry_map5_accepts_2[m5]; |
|
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
353 |
if (a >= 0) ac[a] = 8; |
0 | 354 |
|
355 |
a = _industry_map5_accepts_3[m5]; |
|
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
356 |
if (a >= 0) ac[a] = 8; |
0 | 357 |
} |
358 |
||
359 |
static void GetTileDesc_Industry(uint tile, TileDesc *td) |
|
360 |
{ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
361 |
Industry *i = GetIndustry(_map2[tile]); |
0 | 362 |
|
363 |
td->owner = i->owner; |
|
364 |
td->str = STR_4802_COAL_MINE + i->type; |
|
365 |
if ((_map_owner[tile] & 0x80) == 0) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
366 |
SetDParamX(td->dparam, 0, td->str); |
0 | 367 |
td->str = STR_2058_UNDER_CONSTRUCTION; |
368 |
} |
|
369 |
} |
|
370 |
||
371 |
static int32 ClearTile_Industry(uint tile, byte flags) |
|
372 |
{ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
373 |
Industry *i = GetIndustry(_map2[tile]); |
0 | 374 |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
375 |
/* * water can destroy industries |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
376 |
* in editor you can bulldoze industries |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
377 |
* with magic_bulldozer cheat you can destroy industries |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
378 |
* (area around OILRIG is water, so water shouldn't flood it |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
379 |
*/ |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
380 |
if ((_current_player != OWNER_WATER && _game_mode != GM_EDITOR && |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
381 |
!_cheats.magic_bulldozer.value) || |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
382 |
(_current_player == OWNER_WATER && i->type == IT_OIL_RIG) ) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
383 |
SetDParam(0, STR_4802_COAL_MINE + i->type); |
0 | 384 |
return_cmd_error(STR_4800_IN_THE_WAY); |
385 |
} |
|
386 |
||
387 |
if (flags & DC_EXEC) { |
|
388 |
DeleteIndustry(i); |
|
389 |
} |
|
390 |
return 0; |
|
391 |
} |
|
392 |
||
393 |
/* p1 index of industry to destroy */ |
|
394 |
/* Destroy Industry button costing money removed per request of dominik |
|
395 |
int32 CmdDestroyIndustry(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
396 |
{ |
|
397 |
uint tile = TILE_FROM_XY(x,y); |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
398 |
Industry *i = GetIndustry((uint16)p1); |
0 | 399 |
Town *t = ClosestTownFromTile(tile, (uint)-1); // find closest town to penaltize (ALWAYS penaltize) |
400 |
||
889
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
857
diff
changeset
|
401 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
857
diff
changeset
|
402 |
|
0 | 403 |
// check if you're allowed to remove the industry. Minimum amount |
404 |
// of ratings to remove the industry depends on difficulty setting |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
405 |
if (!CheckforTownRating(tile, flags, t, INDUSTRY_REMOVE)) |
0 | 406 |
return CMD_ERROR; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
407 |
|
0 | 408 |
if (flags & DC_EXEC) { |
409 |
DeleteIndustry(i); |
|
410 |
CreateEffectVehicleAbove(x + 8,y + 8, 2, EV_DEMOLISH); |
|
1005 | 411 |
ChangeTownRating(t, RATING_INDUSTRY_DOWN_STEP, RATING_INDUSTRY_MINIMUM); |
0 | 412 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
413 |
|
0 | 414 |
return (_price.build_industry >> 5) * _industry_type_costs[i->type]*2; |
415 |
} |
|
416 |
*/ |
|
417 |
||
418 |
static const byte _industry_min_cargo[] = { |
|
419 |
5, 5, 5, 30, 5, 5, 5, 5, |
|
420 |
5, 5, 5, 5, 2, 5, 5, 5, |
|
421 |
5, 5, 5, 15, 15, 5, 5, 5, |
|
422 |
5, 5, 30, 5, 30, 5, 5, 5, |
|
423 |
5, 5, 5, 5, 5, |
|
424 |
}; |
|
425 |
||
410 | 426 |
static void TransportIndustryGoods(uint tile) |
0 | 427 |
{ |
428 |
Industry *i; |
|
429 |
int type; |
|
430 |
uint cw, am; |
|
431 |
byte m5; |
|
432 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
433 |
i = GetIndustry(_map2[tile]); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
434 |
|
0 | 435 |
type = i->type; |
436 |
cw = min(i->cargo_waiting[0], 255); |
|
437 |
if (cw > _industry_min_cargo[type]/* && i->produced_cargo[0] != 0xFF*/) { |
|
438 |
i->cargo_waiting[0] -= cw; |
|
439 |
||
440 |
/* fluctuating economy? */ |
|
441 |
if (_economy.fluct <= 0) cw = (cw + 1) >> 1; |
|
442 |
||
443 |
i->last_mo_production[0] += cw; |
|
444 |
||
445 |
am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw); |
|
446 |
i->last_mo_transported[0] += am; |
|
447 |
if (am != 0 && (m5 = _industry_produce_map5[_map5[tile]]) != 0xFF) { |
|
448 |
_map5[tile] = m5; |
|
449 |
_map_owner[tile] = 0x80; |
|
450 |
MarkTileDirtyByTile(tile); |
|
451 |
} |
|
452 |
} |
|
453 |
||
454 |
type = i->type; |
|
455 |
cw = min(i->cargo_waiting[1], 255); |
|
456 |
if (cw > _industry_min_cargo[type]) { |
|
457 |
i->cargo_waiting[1] -= cw; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
458 |
|
0 | 459 |
if (_economy.fluct <= 0) cw = (cw + 1) >> 1; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
460 |
|
0 | 461 |
i->last_mo_production[1] += cw; |
462 |
||
463 |
am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[1], cw); |
|
464 |
i->last_mo_transported[1] += am; |
|
465 |
} |
|
466 |
} |
|
467 |
||
468 |
||
469 |
static void AnimateTile_Industry(uint tile) |
|
470 |
{ |
|
471 |
byte m,n; |
|
472 |
||
473 |
switch(_map5[tile]) { |
|
474 |
case 174: |
|
475 |
if ((_tick_counter & 1) == 0) { |
|
476 |
m = _map3_lo[tile] + 1; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
477 |
|
0 | 478 |
switch(m & 7) { |
541 | 479 |
case 2: SndPlayTileFx(SND_2D_RIP_2, tile); break; |
480 |
case 6: SndPlayTileFx(SND_29_RIP, tile); break; |
|
0 | 481 |
} |
482 |
||
483 |
if (m >= 96) { |
|
484 |
m = 0; |
|
485 |
DeleteAnimatedTile(tile); |
|
486 |
} |
|
487 |
_map3_lo[tile] = m; |
|
488 |
||
489 |
MarkTileDirtyByTile(tile); |
|
490 |
} |
|
491 |
break; |
|
492 |
||
493 |
case 165: |
|
494 |
if ((_tick_counter & 3) == 0) { |
|
495 |
m = _map3_lo[tile]; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
496 |
|
0 | 497 |
if (_industry_anim_offs[m] == 0xFF) { |
541 | 498 |
SndPlayTileFx(SND_30_CARTOON_SOUND, tile); |
0 | 499 |
} |
500 |
||
501 |
if (++m >= 70) { |
|
502 |
m = 0; |
|
503 |
DeleteAnimatedTile(tile); |
|
504 |
} |
|
505 |
_map3_lo[tile] = m; |
|
506 |
||
507 |
MarkTileDirtyByTile(tile); |
|
508 |
} |
|
509 |
break; |
|
510 |
||
511 |
case 162: |
|
512 |
if ((_tick_counter&1) == 0) { |
|
513 |
m = _map3_lo[tile]; |
|
514 |
||
515 |
if (++m >= 40) { |
|
516 |
m = 0; |
|
517 |
DeleteAnimatedTile(tile); |
|
518 |
} |
|
519 |
_map3_lo[tile] = m; |
|
520 |
||
521 |
MarkTileDirtyByTile(tile); |
|
522 |
} |
|
523 |
break; |
|
524 |
||
525 |
// Sparks on a coal plant |
|
526 |
case 10: |
|
527 |
if ((_tick_counter & 3) == 0) { |
|
528 |
m = _map_owner[tile]; |
|
529 |
if ((m & (31<<2)) == (6 << 2)) { |
|
530 |
_map_owner[tile] = m&~(31<<2); |
|
531 |
DeleteAnimatedTile(tile); |
|
532 |
} else { |
|
533 |
_map_owner[tile] = m + (1<<2); |
|
534 |
MarkTileDirtyByTile(tile); |
|
535 |
} |
|
536 |
} |
|
537 |
break; |
|
538 |
||
539 |
case 143: |
|
540 |
if ((_tick_counter & 1) == 0) { |
|
541 |
m = _map3_lo[tile] + 1; |
|
542 |
||
543 |
if (m == 1) { |
|
541 | 544 |
SndPlayTileFx(SND_2C_MACHINERY, tile); |
0 | 545 |
} else if (m == 23) { |
541 | 546 |
SndPlayTileFx(SND_2B_COMEDY_HIT, tile); |
0 | 547 |
} else if (m == 28) { |
541 | 548 |
SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile); |
0 | 549 |
} |
550 |
||
551 |
if (m >= 50 && (m=0,++_map3_hi[tile] >= 8)) { |
|
552 |
_map3_hi[tile] = 0; |
|
553 |
DeleteAnimatedTile(tile); |
|
554 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
555 |
_map3_lo[tile] = m; |
0 | 556 |
MarkTileDirtyByTile(tile); |
557 |
} |
|
558 |
break; |
|
559 |
||
560 |
case 148: case 149: case 150: case 151: |
|
561 |
case 152: case 153: case 154: case 155: |
|
562 |
if ((_tick_counter & 3) == 0) { |
|
563 |
m = _map5[tile] + 1; |
|
564 |
if (m == 155+1) m = 148; |
|
565 |
_map5[tile] = m; |
|
566 |
||
567 |
MarkTileDirtyByTile(tile); |
|
568 |
} |
|
569 |
break; |
|
570 |
||
571 |
case 30: case 31: case 32: |
|
572 |
if ((_tick_counter & 7) == 0) { |
|
573 |
bool b = CHANCE16(1,7); |
|
574 |
m = _map_owner[tile]; |
|
575 |
m = (m & 3) + 1; |
|
576 |
n = _map5[tile]; |
|
577 |
if (m == 4 && (m=0,++n) == 32+1 && (n=30,b)) { |
|
578 |
_map_owner[tile] = 0x83; |
|
579 |
_map5[tile] = 29; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
580 |
DeleteAnimatedTile(tile); |
0 | 581 |
} else { |
582 |
_map5[tile] = n; |
|
583 |
_map_owner[tile] = (_map_owner[tile] & ~3) | m; |
|
584 |
MarkTileDirtyByTile(tile); |
|
585 |
} |
|
586 |
} |
|
587 |
break; |
|
588 |
||
589 |
case 88: |
|
590 |
case 48: |
|
591 |
case 1: { |
|
592 |
int state = _tick_counter & 0x7FF; |
|
593 |
||
594 |
if ((state -= 0x400) < 0) |
|
595 |
return; |
|
596 |
||
597 |
if (state < 0x1A0) { |
|
598 |
if (state < 0x20 || state >= 0x180) { |
|
599 |
if (! (_map_owner[tile] & 0x40)) { |
|
600 |
_map_owner[tile] |= 0x40; |
|
541 | 601 |
SndPlayTileFx(SND_0B_MINING_MACHINERY, tile); |
0 | 602 |
} |
603 |
if (state & 7) |
|
604 |
return; |
|
605 |
} else { |
|
606 |
if (state & 3) |
|
607 |
return; |
|
608 |
} |
|
609 |
m = (_map_owner[tile] + 1) | 0x40; |
|
610 |
if (m > 0xC2) m = 0xC0; |
|
611 |
_map_owner[tile] = m; |
|
612 |
MarkTileDirtyByTile(tile); |
|
613 |
} else if (state >= 0x200 && state < 0x3A0) { |
|
614 |
int i; |
|
615 |
i = (state < 0x220 || state >= 0x380) ? 7 : 3; |
|
616 |
if (state & i) |
|
617 |
return; |
|
618 |
||
619 |
m = (_map_owner[tile] & 0xBF) - 1; |
|
620 |
if (m < 0x80) m = 0x82; |
|
621 |
_map_owner[tile] = m; |
|
622 |
MarkTileDirtyByTile(tile); |
|
623 |
} |
|
624 |
} break; |
|
625 |
} |
|
626 |
} |
|
627 |
||
628 |
static void MakeIndustryTileBiggerCase8(uint tile) |
|
629 |
{ |
|
630 |
TileInfo ti; |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
631 |
FindLandscapeHeight(&ti, TileX(tile) * 16, TileY(tile) * 16); |
0 | 632 |
CreateEffectVehicle(ti.x + 15, ti.y + 14, ti.z + 59 + (ti.tileh != 0 ? 8 : 0), EV_INDUSTRYSMOKE); |
633 |
} |
|
634 |
||
635 |
static void MakeIndustryTileBigger(uint tile, byte size) |
|
636 |
{ |
|
637 |
byte b = (byte)((size + (1<<2)) & (3<<2)); |
|
638 |
||
639 |
if (b != 0) { |
|
640 |
_map_owner[tile] = b | (size & 3); |
|
641 |
return; |
|
642 |
} |
|
643 |
||
644 |
size = (size + 1) & 3; |
|
645 |
if (size == 3) size |= 0x80; |
|
646 |
_map_owner[tile] = size | b; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
647 |
|
0 | 648 |
MarkTileDirtyByTile(tile); |
649 |
||
650 |
if (!(_map_owner[tile] & 0x80)) |
|
651 |
return; |
|
652 |
||
653 |
switch(_map5[tile]) { |
|
654 |
case 8: |
|
655 |
MakeIndustryTileBiggerCase8(tile); |
|
656 |
break; |
|
657 |
||
658 |
case 24: |
|
659 |
if (_map5[tile + TILE_XY(0,1)] == 24) { |
|
660 |
BuildOilRig(tile); |
|
661 |
} |
|
662 |
break; |
|
663 |
||
664 |
case 143: |
|
665 |
case 162: |
|
666 |
case 165: |
|
667 |
_map3_lo[tile] = 0; |
|
668 |
_map3_hi[tile] = 0; |
|
669 |
break; |
|
670 |
||
671 |
case 148: case 149: case 150: case 151: |
|
672 |
case 152: case 153: case 154: case 155: |
|
673 |
AddAnimatedTile(tile); |
|
674 |
break; |
|
675 |
} |
|
676 |
} |
|
677 |
||
678 |
||
679 |
||
680 |
static void TileLoopIndustryCase161(uint tile) |
|
681 |
{ |
|
682 |
int dir; |
|
683 |
Vehicle *v; |
|
684 |
static const int8 _tileloop_ind_case_161[12] = { |
|
685 |
11, 0, -4, -14, |
|
686 |
-4, -10, -4, 1, |
|
687 |
49, 59, 60, 65, |
|
688 |
}; |
|
689 |
||
541 | 690 |
SndPlayTileFx(SND_2E_EXTRACT_AND_POP, tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
691 |
|
0 | 692 |
dir = Random() & 3; |
693 |
||
694 |
v = CreateEffectVehicleAbove( |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
695 |
TileX(tile) * 16 + _tileloop_ind_case_161[dir + 0], |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
696 |
TileY(tile) * 16 + _tileloop_ind_case_161[dir + 4], |
0 | 697 |
_tileloop_ind_case_161[dir + 8], |
698 |
EV_INDUSTRY_SMOKE |
|
699 |
); |
|
700 |
||
701 |
if (v != NULL) |
|
702 |
v->u.special.unk2 = dir; |
|
703 |
} |
|
704 |
||
705 |
static void TileLoop_Industry(uint tile) |
|
706 |
{ |
|
707 |
byte n; |
|
708 |
||
709 |
if (!(_map_owner[tile] & 0x80)) { |
|
710 |
MakeIndustryTileBigger(tile, _map_owner[tile]); |
|
711 |
return; |
|
712 |
} |
|
713 |
||
714 |
if (_game_mode == GM_EDITOR) |
|
715 |
return; |
|
716 |
||
717 |
TransportIndustryGoods(tile); |
|
718 |
||
719 |
n = _industry_map5_animation_next[_map5[tile]]; |
|
720 |
if (n != 255) { |
|
721 |
_map5[tile] = n; |
|
722 |
_map_owner[tile] = 0; |
|
723 |
MarkTileDirtyByTile(tile); |
|
724 |
return; |
|
725 |
} |
|
726 |
||
727 |
#define SET_AND_ANIMATE(tile,a,b) { _map5[tile]=a; _map_owner[tile]=b; AddAnimatedTile(tile); } |
|
728 |
#define SET_AND_UNANIMATE(tile,a,b) { _map5[tile]=a; _map_owner[tile]=b; DeleteAnimatedTile(tile); } |
|
729 |
||
730 |
switch(_map5[tile]) { |
|
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
731 |
case 0x18: // coast line at oilrigs |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
732 |
case 0x19: |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
733 |
case 0x1A: |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
734 |
case 0x1B: |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
735 |
case 0x1C: |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
736 |
TileLoop_Water(tile); |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
737 |
break; |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
738 |
|
0 | 739 |
case 0: |
740 |
if (!(_tick_counter & 0x400) && CHANCE16(1,2)) |
|
741 |
SET_AND_ANIMATE(tile,1,0x80); |
|
742 |
break; |
|
743 |
||
744 |
case 47: |
|
745 |
if (!(_tick_counter & 0x400) && CHANCE16(1,2)) |
|
746 |
SET_AND_ANIMATE(tile,0x30,0x80); |
|
747 |
break; |
|
748 |
||
749 |
case 79: |
|
750 |
if (!(_tick_counter & 0x400) && CHANCE16(1,2)) |
|
751 |
SET_AND_ANIMATE(tile,0x58,0x80); |
|
752 |
break; |
|
753 |
||
754 |
case 29: |
|
755 |
if (CHANCE16(1,6)) |
|
756 |
SET_AND_ANIMATE(tile,0x1E,0x80); |
|
757 |
break; |
|
758 |
||
759 |
case 1: |
|
760 |
if (!(_tick_counter & 0x400)) |
|
761 |
SET_AND_UNANIMATE(tile, 0, 0x83); |
|
762 |
break; |
|
763 |
||
764 |
case 48: |
|
765 |
if (!(_tick_counter & 0x400)) |
|
766 |
SET_AND_UNANIMATE(tile, 0x2F, 0x83); |
|
767 |
break; |
|
768 |
||
769 |
case 88: |
|
770 |
if (!(_tick_counter & 0x400)) |
|
771 |
SET_AND_UNANIMATE(tile, 0x4F, 0x83); |
|
772 |
break; |
|
773 |
||
774 |
case 10: |
|
775 |
if (CHANCE16(1,3)) { |
|
541 | 776 |
SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile); |
0 | 777 |
AddAnimatedTile(tile); |
778 |
} |
|
779 |
break; |
|
780 |
||
781 |
case 49: { |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
782 |
CreateEffectVehicleAbove(TileX(tile) * 16 + 6, TileY(tile) * 16 + 6, 43, EV_SMOKE_3); |
0 | 783 |
} break; |
784 |
||
785 |
||
786 |
case 143: { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
787 |
Industry *i = GetIndustry(_map2[tile]); |
0 | 788 |
if (i->was_cargo_delivered) { |
789 |
i->was_cargo_delivered = false; |
|
790 |
if ((_map3_hi[tile]|_map3_lo[tile]) != 0) |
|
791 |
_map3_hi[tile] = 0; |
|
792 |
AddAnimatedTile(tile); |
|
793 |
} |
|
794 |
} |
|
795 |
break; |
|
796 |
||
797 |
case 161: |
|
798 |
TileLoopIndustryCase161(tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
799 |
break; |
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
800 |
|
0 | 801 |
case 165: |
802 |
AddAnimatedTile(tile); |
|
803 |
break; |
|
804 |
||
805 |
case 174: |
|
806 |
if (CHANCE16(1,3)) { |
|
807 |
AddAnimatedTile(tile); |
|
808 |
} |
|
809 |
break; |
|
810 |
} |
|
811 |
} |
|
812 |
||
813 |
||
814 |
static void ClickTile_Industry(uint tile) |
|
815 |
{ |
|
816 |
ShowIndustryViewWindow(_map2[tile]); |
|
817 |
} |
|
818 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
819 |
static uint32 GetTileTrackStatus_Industry(uint tile, TransportType mode) |
0 | 820 |
{ |
821 |
return 0; |
|
822 |
} |
|
823 |
||
824 |
static void GetProducedCargo_Industry(uint tile, byte *b) |
|
825 |
{ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
826 |
Industry *i = GetIndustry(_map2[tile]); |
0 | 827 |
b[0] = i->produced_cargo[0]; |
828 |
b[1] = i->produced_cargo[1]; |
|
829 |
} |
|
830 |
||
831 |
static void ChangeTileOwner_Industry(uint tile, byte old_player, byte new_player) |
|
832 |
{ |
|
833 |
/* not used */ |
|
834 |
} |
|
835 |
||
836 |
void DeleteIndustry(Industry *i) |
|
837 |
{ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
838 |
BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy); |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
839 |
if (IsTileType(tile_cur, MP_INDUSTRY)) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
840 |
if (_map2[tile_cur] == i->index) { |
0 | 841 |
DoClearSquare(tile_cur); |
842 |
} |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
843 |
} else if (IsTileType(tile_cur, MP_STATION) && _map5[tile_cur] == 0x4B) { |
0 | 844 |
DeleteOilRig(tile_cur); |
845 |
} |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
846 |
END_TILE_LOOP(tile_cur, i->width, i->height, i->xy); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
847 |
|
0 | 848 |
i->xy = 0; |
849 |
_industry_sort_dirty = true; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
850 |
DeleteSubsidyWithIndustry(i->index); |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
851 |
DeleteWindowById(WC_INDUSTRY_VIEW, i->index); |
0 | 852 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
853 |
} |
|
854 |
||
855 |
static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}; |
|
856 |
||
857 |
static bool IsBadFarmFieldTile(uint tile) |
|
858 |
{ |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
859 |
if (IsTileType(tile, MP_CLEAR)) { |
0 | 860 |
byte m5 = _map5[tile] & 0x1C; |
861 |
if (m5 == 0xC || m5 == 0x10) |
|
862 |
return true; |
|
863 |
return false; |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
864 |
} else if (IsTileType(tile, MP_TREES)) { |
0 | 865 |
return false; |
866 |
} else { |
|
867 |
return true; |
|
868 |
} |
|
869 |
} |
|
870 |
||
871 |
static bool IsBadFarmFieldTile2(uint tile) |
|
872 |
{ |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
873 |
if (IsTileType(tile, MP_CLEAR)) { |
0 | 874 |
byte m5 = _map5[tile] & 0x1C; |
875 |
if (m5 == 0x10) |
|
876 |
return true; |
|
877 |
return false; |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
878 |
} else if (IsTileType(tile, MP_TREES)) { |
0 | 879 |
return false; |
880 |
} else { |
|
881 |
return true; |
|
882 |
} |
|
883 |
} |
|
884 |
||
885 |
static void SetupFarmFieldFence(uint tile, int size, byte type, int direction) |
|
886 |
{ |
|
887 |
byte or, and; |
|
888 |
||
889 |
do { |
|
890 |
tile = TILE_MASK(tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
891 |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
892 |
if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) { |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
893 |
|
0 | 894 |
or = type; |
895 |
if (or == 1 && (uint16)Random() <= 9362) or = 2; |
|
896 |
||
897 |
or <<= 2; |
|
898 |
and = (byte)~0x1C; |
|
899 |
if (direction) { |
|
900 |
or <<= 3; |
|
901 |
and = (byte)~0xE0; |
|
902 |
} |
|
903 |
_map3_hi[tile] = (_map3_hi[tile] & and) | or; |
|
904 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
905 |
|
0 | 906 |
tile += direction ? TILE_XY(0,1) : TILE_XY(1,0); |
907 |
} while (--size); |
|
908 |
} |
|
909 |
||
910 |
static void PlantFarmField(uint tile) |
|
911 |
{ |
|
912 |
uint size_x, size_y; |
|
913 |
uint32 r; |
|
914 |
int count; |
|
915 |
int type, type2; |
|
916 |
||
917 |
if (_opt.landscape == LT_HILLY) { |
|
918 |
if (GetTileZ(tile) >= (_opt.snow_line - 16)) |
|
919 |
return; |
|
920 |
} |
|
921 |
||
922 |
/* determine field size */ |
|
923 |
r = (Random() & 0x303) + 0x404; |
|
924 |
if (_opt.landscape == LT_HILLY) r += 0x404; |
|
925 |
size_x = (byte)r; |
|
926 |
size_y = r >> 8; |
|
927 |
||
928 |
/* offset tile to match size */ |
|
929 |
tile = tile - TILE_XY(size_x>>1, size_y>>1); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
930 |
|
0 | 931 |
/* check the amount of bad tiles */ |
932 |
count = 0; |
|
933 |
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
934 |
cur_tile = TILE_MASK(cur_tile); |
|
935 |
count += IsBadFarmFieldTile(cur_tile); |
|
936 |
END_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
937 |
if ((uint)(count * 2) >= size_x * size_y) |
|
938 |
return; |
|
939 |
||
940 |
/* determine type of field */ |
|
941 |
r = Random(); |
|
942 |
type = ((r & 0xE0) | 0xF); |
|
943 |
type2 = ((byte)(r >> 8) * 9) >> 8; |
|
944 |
||
945 |
/* make field */ |
|
946 |
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
947 |
cur_tile = TILE_MASK(cur_tile); |
|
948 |
if (!IsBadFarmFieldTile2(cur_tile)) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
949 |
ModifyTile(cur_tile, |
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
950 |
MP_SETTYPE(MP_CLEAR) | |
0 | 951 |
MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5, |
952 |
type2, /* map3_lo */ |
|
953 |
OWNER_NONE, /* map_owner */ |
|
954 |
type); /* map5 */ |
|
955 |
} |
|
956 |
END_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
957 |
|
0 | 958 |
type = 3; |
959 |
if (_opt.landscape != LT_HILLY && _opt.landscape != LT_DESERT) { |
|
960 |
type = _plantfarmfield_type[Random() & 0xF]; |
|
961 |
} |
|
962 |
||
963 |
SetupFarmFieldFence(tile-TILE_XY(1,0), size_y, type, 1); |
|
964 |
SetupFarmFieldFence(tile-TILE_XY(0,1), size_x, type, 0); |
|
965 |
SetupFarmFieldFence(tile+TILE_XY(1,0) * (size_x-1), size_y, type, 1); |
|
966 |
SetupFarmFieldFence(tile+TILE_XY(0,1) * (size_y-1), size_x, type, 0); |
|
967 |
} |
|
968 |
||
969 |
static void MaybePlantFarmField(Industry *i) |
|
970 |
{ |
|
971 |
uint tile; |
|
972 |
if (CHANCE16(1,8)) { |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
973 |
int x = (i->width>>1) + Random() % 31 - 16; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
974 |
int y = (i->height>>1) + Random() % 31 - 16; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
975 |
tile = TileAddWrap(i->xy, x, y); |
0 | 976 |
if (tile != TILE_WRAPPED) |
977 |
PlantFarmField(tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
978 |
} |
0 | 979 |
} |
980 |
||
981 |
static void ChopLumberMillTrees(Industry *i) |
|
982 |
{ |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
983 |
static const TileIndexDiffC _chop_dir[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
984 |
{ 0, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
985 |
{ 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
986 |
{ 0, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
987 |
{-1, 0} |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
988 |
}; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
989 |
|
0 | 990 |
uint tile = i->xy; |
991 |
int dir, a, j; |
|
992 |
||
993 |
if ((_map_owner[tile] & 0x80) == 0) |
|
994 |
return; |
|
995 |
||
996 |
/* search outwards as a rectangular spiral */ |
|
997 |
for(a=1; a!=41; a+=2) { |
|
998 |
for(dir=0; dir!=4; dir++) { |
|
999 |
j = a; |
|
1000 |
do { |
|
1001 |
tile = TILE_MASK(tile); |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
1002 |
if (IsTileType(tile, MP_TREES)) { |
314 | 1003 |
uint old_player = _current_player; |
0 | 1004 |
/* found a tree */ |
1005 |
||
1006 |
_current_player = OWNER_NONE; |
|
1007 |
_industry_sound_ctr = 1; |
|
1008 |
_industry_sound_tile = tile; |
|
541 | 1009 |
SndPlayTileFx(SND_38_CHAINSAW, tile); |
0 | 1010 |
|
1011 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1012 |
SetMapExtraBits(tile, 0); |
|
1013 |
||
1014 |
i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + 45); |
|
314 | 1015 |
|
1016 |
_current_player = old_player; |
|
0 | 1017 |
return; |
1018 |
} |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1019 |
tile += ToTileIndexDiff(_chop_dir[dir]); |
0 | 1020 |
} while (--j); |
1021 |
} |
|
1022 |
tile -= TILE_XY(1,1); |
|
1023 |
} |
|
1024 |
} |
|
1025 |
||
1026 |
static const byte _industry_sounds[37][2] = { |
|
1027 |
{0}, |
|
1028 |
{0}, |
|
541 | 1029 |
{1, SND_28_SAWMILL}, |
0 | 1030 |
{0}, |
1031 |
{0}, |
|
1032 |
{0}, |
|
541 | 1033 |
{1, SND_03_FACTORY_WHISTLE}, |
1034 |
{1, SND_03_FACTORY_WHISTLE}, |
|
0 | 1035 |
{0}, |
541 | 1036 |
{3, SND_24_SHEEP}, |
0 | 1037 |
{0}, |
1038 |
{0}, |
|
1039 |
{0}, |
|
1040 |
{0}, |
|
541 | 1041 |
{1, SND_28_SAWMILL}, |
0 | 1042 |
{0}, |
1043 |
{0}, |
|
1044 |
{0}, |
|
1045 |
{0}, |
|
1046 |
{0}, |
|
1047 |
{0}, |
|
1048 |
{0}, |
|
1049 |
{0}, |
|
541 | 1050 |
{1, SND_03_FACTORY_WHISTLE}, |
0 | 1051 |
{0}, |
1052 |
{0}, |
|
1053 |
{0}, |
|
1054 |
{0}, |
|
1055 |
{0}, |
|
1056 |
{0}, |
|
1057 |
{0}, |
|
1058 |
{0}, |
|
541 | 1059 |
{1, SND_33_PLASTIC_MINE}, |
0 | 1060 |
{0}, |
1061 |
{0}, |
|
1062 |
{0}, |
|
1063 |
{0}, |
|
1064 |
}; |
|
1065 |
||
1066 |
||
1067 |
static void ProduceIndustryGoods(Industry *i) |
|
1068 |
{ |
|
1069 |
uint32 r; |
|
1070 |
uint num; |
|
1071 |
||
1072 |
/* play a sound? */ |
|
1073 |
if ((i->counter & 0x3F) == 0) { |
|
1074 |
if (CHANCE16R(1,14,r) && (num=_industry_sounds[i->type][0]) != 0) { |
|
1075 |
SndPlayTileFx( |
|
1076 |
_industry_sounds[i->type][1] + (((r >> 16) * num) >> 16), |
|
1077 |
i->xy); |
|
1078 |
} |
|
1079 |
} |
|
1080 |
||
1081 |
i->counter--; |
|
1082 |
||
1083 |
/* produce some cargo */ |
|
1084 |
if ((i->counter & 0xFF) == 0) { |
|
1085 |
i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + i->production_rate[0]); |
|
1086 |
i->cargo_waiting[1] = min(0xffff, i->cargo_waiting[1] + i->production_rate[1]); |
|
1087 |
||
1088 |
if (i->type == IT_FARM) |
|
1089 |
MaybePlantFarmField(i); |
|
1090 |
else if (i->type == IT_LUMBER_MILL && (i->counter & 0x1FF) == 0) |
|
1091 |
ChopLumberMillTrees(i); |
|
1092 |
} |
|
1093 |
} |
|
1094 |
||
1095 |
void OnTick_Industry() |
|
1096 |
{ |
|
1097 |
Industry *i; |
|
1098 |
||
1099 |
if (_industry_sound_ctr != 0) { |
|
1100 |
_industry_sound_ctr++; |
|
1101 |
||
1102 |
if (_industry_sound_ctr == 75) { |
|
541 | 1103 |
SndPlayTileFx(SND_37_BALLOON_SQUEAK, _industry_sound_tile); |
0 | 1104 |
} else if (_industry_sound_ctr == 160) { |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1105 |
_industry_sound_ctr = 0; |
541 | 1106 |
SndPlayTileFx(SND_36_CARTOON_CRASH, _industry_sound_tile); |
0 | 1107 |
} |
1108 |
} |
|
1109 |
||
1110 |
if (_game_mode == GM_EDITOR) |
|
1111 |
return; |
|
1112 |
||
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1113 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1114 |
if (i->xy != 0) |
1115 |
ProduceIndustryGoods(i); |
|
1116 |
} |
|
1117 |
} |
|
1118 |
||
1119 |
||
1120 |
static bool CheckNewIndustry_NULL(uint tile, int type) |
|
1121 |
{ |
|
1122 |
return true; |
|
1123 |
} |
|
1124 |
||
1125 |
static bool CheckNewIndustry_Forest(uint tile, int type) |
|
1126 |
{ |
|
1127 |
if (_opt.landscape == LT_HILLY) { |
|
1128 |
if (GetTileZ(tile) < (_opt.snow_line + 16) ) { |
|
1129 |
_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED; |
|
1130 |
return false; |
|
1131 |
} |
|
1132 |
} |
|
1133 |
return true; |
|
1134 |
} |
|
1135 |
||
7
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1136 |
extern bool _ignore_restrictions; |
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1137 |
|
0 | 1138 |
static bool CheckNewIndustry_Oilwell(uint tile, int type) |
1139 |
{ |
|
1140 |
int x,y; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1141 |
|
7
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1142 |
if(_ignore_restrictions && _game_mode == GM_EDITOR) |
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1143 |
return true; |
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1144 |
|
0 | 1145 |
if (type != IT_OIL_RIG && _game_mode == GM_EDITOR) |
1146 |
return true; |
|
1147 |
||
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1148 |
x = TileX(tile); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1149 |
y = TileY(tile); |
0 | 1150 |
|
1151 |
if ( x < 15 || y < 15 || x > 238 || y > 238) |
|
1152 |
return true; |
|
1153 |
||
1154 |
_error_message = STR_483B_CAN_ONLY_BE_POSITIONED; |
|
1155 |
return false; |
|
1156 |
} |
|
1157 |
||
1158 |
static bool CheckNewIndustry_Farm(uint tile, int type) |
|
1159 |
{ |
|
1160 |
if (_opt.landscape == LT_HILLY) { |
|
1161 |
if (GetTileZ(tile) >= (_opt.snow_line - 16)) { |
|
1162 |
_error_message = STR_0239_SITE_UNSUITABLE; |
|
1163 |
return false; |
|
1164 |
} |
|
1165 |
} |
|
1166 |
return true; |
|
1167 |
} |
|
1168 |
||
1169 |
static bool CheckNewIndustry_Plantation(uint tile, int type) |
|
1170 |
{ |
|
1171 |
if (GetMapExtraBits(tile) == 1) { |
|
1172 |
_error_message = STR_0239_SITE_UNSUITABLE; |
|
1173 |
return false; |
|
1174 |
} |
|
1175 |
||
1176 |
return true; |
|
1177 |
} |
|
1178 |
||
1179 |
static bool CheckNewIndustry_Water(uint tile, int type) |
|
1180 |
{ |
|
1181 |
if (GetMapExtraBits(tile) != 1) { |
|
1182 |
_error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; |
|
1183 |
return false; |
|
1184 |
} |
|
1185 |
||
1186 |
return true; |
|
1187 |
} |
|
1188 |
||
1189 |
static bool CheckNewIndustry_Lumbermill(uint tile, int type) |
|
1190 |
{ |
|
1191 |
if (GetMapExtraBits(tile) != 2) { |
|
1192 |
_error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; |
|
1193 |
return false; |
|
1194 |
} |
|
1195 |
return true; |
|
1196 |
} |
|
1197 |
||
1198 |
static bool CheckNewIndustry_BubbleGen(uint tile, int type) |
|
1199 |
{ |
|
1200 |
if (GetTileZ(tile) > 32) { |
|
1201 |
return false; |
|
1202 |
} |
|
1203 |
return true; |
|
1204 |
} |
|
1205 |
||
1206 |
typedef bool CheckNewIndustryProc(uint tile, int type); |
|
1207 |
static CheckNewIndustryProc * const _check_new_industry_procs[] = { |
|
1208 |
CheckNewIndustry_NULL, |
|
1209 |
CheckNewIndustry_Forest, |
|
1210 |
CheckNewIndustry_Oilwell, |
|
1211 |
CheckNewIndustry_Farm, |
|
1212 |
CheckNewIndustry_Plantation, |
|
1213 |
CheckNewIndustry_Water, |
|
1214 |
CheckNewIndustry_Lumbermill, |
|
1215 |
CheckNewIndustry_BubbleGen, |
|
1216 |
}; |
|
1217 |
||
1218 |
static bool CheckSuitableIndustryPos(uint tile) |
|
1219 |
{ |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1220 |
uint x = TileX(tile); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1221 |
uint y = TileY(tile); |
0 | 1222 |
|
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
838
diff
changeset
|
1223 |
if ( x < 2 || y < 2 || x > MapMaxX() - 3 || y > MapMaxY() - 3) { |
0 | 1224 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1225 |
return false; |
|
1226 |
} |
|
1227 |
||
1228 |
return true; |
|
1229 |
} |
|
1230 |
||
1231 |
static Town *CheckMultipleIndustryInTown(uint tile, int type) |
|
1232 |
{ |
|
1233 |
Town *t; |
|
1234 |
Industry *i; |
|
1235 |
||
1236 |
t = ClosestTownFromTile(tile, (uint)-1); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1237 |
|
0 | 1238 |
if (_patches.multiple_industry_per_town) |
1239 |
return t; |
|
1240 |
||
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1241 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1242 |
if (i->xy != 0 && |
1243 |
i->type == (byte)type && |
|
1244 |
i->town == t) { |
|
1245 |
_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN; |
|
1246 |
return NULL; |
|
1247 |
} |
|
1248 |
} |
|
1249 |
||
1250 |
return t; |
|
1251 |
} |
|
1252 |
||
1253 |
static const byte _industry_map5_bits[] = { |
|
1254 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1255 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1256 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1257 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1258 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1259 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1260 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1261 |
16, 16, 4, 2, 16, 16, 16, 16, |
|
1262 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1263 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1264 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1265 |
16, 4, 2, 16, 16, 16, 16, 16, |
|
1266 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1267 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1268 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1269 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1270 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1271 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1272 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1273 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1274 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1275 |
16, 16, 16, 16, 16, 16, 16, |
|
1276 |
}; |
|
1277 |
||
1278 |
static bool CheckIfIndustryTilesAreFree(uint tile, const IndustryTileTable *it, int type, Town *t) |
|
1279 |
{ |
|
1280 |
TileInfo ti; |
|
1281 |
uint cur_tile; |
|
1282 |
||
1283 |
_error_message = STR_0239_SITE_UNSUITABLE; |
|
1284 |
||
1285 |
do { |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1286 |
cur_tile = tile + ToTileIndexDiff(it->ti); |
0 | 1287 |
if (!IsValidTile(cur_tile)) { |
1288 |
if (it->map5 == 0xff) |
|
1289 |
continue; |
|
1290 |
return false; |
|
1291 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1292 |
|
0 | 1293 |
FindLandscapeHeightByTile(&ti, cur_tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1294 |
|
0 | 1295 |
if (it->map5 == 0xFF) { |
1296 |
if (ti.type != MP_WATER || ti.tileh != 0) |
|
1297 |
return false; |
|
1298 |
} else { |
|
1299 |
if (!EnsureNoVehicle(cur_tile)) |
|
1300 |
return false; |
|
1301 |
||
1302 |
if (type == IT_OIL_RIG) { |
|
1303 |
if (ti.type != MP_WATER || ti.map5 != 0) |
|
1304 |
return false; |
|
1305 |
} else { |
|
1306 |
if (ti.type == MP_WATER && ti.map5 == 0) |
|
1307 |
return false; |
|
1308 |
if (ti.tileh & 0x10) |
|
1309 |
return false; |
|
1310 |
||
1311 |
if (ti.tileh != 0) { |
|
1312 |
int t; |
|
1313 |
byte bits = _industry_map5_bits[it->map5]; |
|
1314 |
||
1315 |
if (bits & 0x10) |
|
1316 |
return false; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1317 |
|
0 | 1318 |
t = ~ti.tileh; |
1319 |
||
1320 |
if (bits & 1 && (t & (1+8))) |
|
1321 |
return false; |
|
1322 |
||
1323 |
if (bits & 2 && (t & (4+8))) |
|
1324 |
return false; |
|
1325 |
||
1326 |
if (bits & 4 && (t & (1+2))) |
|
1327 |
return false; |
|
1328 |
||
1329 |
if (bits & 8 && (t & (2+4))) |
|
1330 |
return false; |
|
1331 |
} |
|
1332 |
||
1333 |
if (type == IT_BANK) { |
|
1334 |
if (ti.type != MP_HOUSE || t->population < 1200) { |
|
1335 |
_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS; |
|
1336 |
return false; |
|
1337 |
} |
|
1338 |
} else if (type == IT_BANK_2) { |
|
1339 |
if (ti.type != MP_HOUSE) { |
|
1340 |
_error_message = STR_030D_CAN_ONLY_BE_BUILT_IN_TOWNS; |
|
1341 |
return false; |
|
1342 |
} |
|
1343 |
} else if (type == IT_TOY_SHOP) { |
|
1344 |
if (GetTileDist1D(t->xy, cur_tile) > 9) |
|
1345 |
return false; |
|
1346 |
if (ti.type != MP_HOUSE) goto do_clear; |
|
1347 |
} else if (type == IT_WATER_TOWER) { |
|
1348 |
if (ti.type != MP_HOUSE) { |
|
1349 |
_error_message = STR_0316_CAN_ONLY_BE_BUILT_IN_TOWNS; |
|
1350 |
return false; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1351 |
} |
0 | 1352 |
} else { |
1353 |
do_clear: |
|
1354 |
if (DoCommandByTile(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR) == CMD_ERROR) |
|
1355 |
return false; |
|
1356 |
} |
|
1357 |
} |
|
1358 |
} |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1359 |
} while ((++it)->ti.x != -0x80); |
0 | 1360 |
|
1361 |
return true; |
|
1362 |
} |
|
1363 |
||
1364 |
static bool CheckIfTooCloseToIndustry(uint tile, int type) |
|
1365 |
{ |
|
1366 |
Industry *i; |
|
1367 |
const IndustrySpec *spec; |
|
1368 |
spec = &_industry_spec[type]; |
|
1369 |
||
1370 |
// accepting industries won't be close, not even with patch |
|
1371 |
if (_patches.same_industry_close && (spec->accepts_cargo[0] == 0xFF) ) |
|
1372 |
return true; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1373 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1374 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1375 |
// check if an industry that accepts the same goods is nearby |
1376 |
if (i->xy != 0 && |
|
1377 |
(GetTileDist1D(tile, i->xy) <= 14) && |
|
1378 |
spec->accepts_cargo[0] != 0xFF && |
|
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1005
diff
changeset
|
1379 |
spec->accepts_cargo[0] == i->accepts_cargo[0] && |
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1005
diff
changeset
|
1380 |
!(_game_mode == GM_EDITOR && |
952
48dbeb24b216
(svn r1443) Added feature that users are able to place multiple accepting industies nearby in the editor mode if the appropriate patches are set
miham
parents:
926
diff
changeset
|
1381 |
_patches.same_industry_close && |
48dbeb24b216
(svn r1443) Added feature that users are able to place multiple accepting industies nearby in the editor mode if the appropriate patches are set
miham
parents:
926
diff
changeset
|
1382 |
_patches.multiple_industry_per_town)) { |
0 | 1383 |
_error_message = STR_INDUSTRY_TOO_CLOSE; |
1384 |
return false; |
|
1385 |
} |
|
1386 |
||
1387 |
// check "not close to" field. |
|
1388 |
if (i->xy != 0 && |
|
1389 |
(i->type == spec->a || i->type == spec->b || i->type == spec->c) && |
|
1390 |
GetTileDist1D(tile, i->xy) <= 14) { |
|
1391 |
_error_message = STR_INDUSTRY_TOO_CLOSE; |
|
1392 |
return false; |
|
1393 |
} |
|
1394 |
} |
|
1395 |
return true; |
|
1396 |
} |
|
1397 |
||
1398 |
static Industry *AllocateIndustry() |
|
1399 |
{ |
|
1400 |
Industry *i; |
|
1401 |
||
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1402 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1403 |
if (i->xy == 0) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1404 |
if (i->index > _total_industries) |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1405 |
_total_industries = i->index; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1406 |
|
0 | 1407 |
return i; |
1408 |
} |
|
1409 |
} |
|
1410 |
return NULL; |
|
1411 |
} |
|
1412 |
||
1413 |
static void DoCreateNewIndustry(Industry *i, uint tile, int type, const IndustryTileTable *it, Town *t, byte owner) |
|
1414 |
{ |
|
1415 |
const IndustrySpec *spec; |
|
1416 |
uint32 r; |
|
1417 |
uint cur_tile; |
|
1418 |
int j; |
|
1419 |
||
1420 |
i->xy = tile; |
|
1421 |
i->width = i->height = 0; |
|
1422 |
i->type = type; |
|
1423 |
||
1424 |
spec = &_industry_spec[type]; |
|
1425 |
||
1426 |
i->produced_cargo[0] = spec->produced_cargo[0]; |
|
1427 |
i->produced_cargo[1] = spec->produced_cargo[1]; |
|
1428 |
i->accepts_cargo[0] = spec->accepts_cargo[0]; |
|
1429 |
i->accepts_cargo[1] = spec->accepts_cargo[1]; |
|
1430 |
i->accepts_cargo[2] = spec->accepts_cargo[2]; |
|
1431 |
i->production_rate[0] = spec->production_rate[0]; |
|
1432 |
i->production_rate[1] = spec->production_rate[1]; |
|
1433 |
||
1434 |
if (_patches.smooth_economy) { |
|
1435 |
i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255); |
|
1436 |
i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255); |
|
1437 |
} |
|
1438 |
||
1439 |
i->town = t; |
|
1440 |
i->owner = owner; |
|
1441 |
||
1442 |
r = Random() & 0xFFF; |
|
1443 |
i->color_map = (byte)(r >> 8); |
|
1444 |
i->counter = (uint16)r; |
|
1445 |
i->cargo_waiting[0] = 0; |
|
1446 |
i->cargo_waiting[1] = 0; |
|
1447 |
i->last_mo_production[0] = 0; |
|
1448 |
i->last_mo_production[1] = 0; |
|
1449 |
i->last_mo_transported[0] = 0; |
|
1450 |
i->last_mo_transported[1] = 0; |
|
1451 |
i->pct_transported[0] = 0; |
|
1452 |
i->pct_transported[1] = 0; |
|
1453 |
i->total_transported[0] = 0; |
|
1454 |
i->total_transported[1] = 0; |
|
1455 |
i->was_cargo_delivered = false; |
|
1456 |
i->last_prod_year = _cur_year; |
|
1457 |
i->total_production[0] = i->production_rate[0] * 8; |
|
1458 |
i->total_production[1] = i->production_rate[1] * 8; |
|
1459 |
||
1460 |
if (_generating_world == 0) |
|
1461 |
i->total_production[0] = i->total_production[1] = 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1462 |
|
0 | 1463 |
i->prod_level = 0x10; |
1464 |
||
1465 |
do { |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1466 |
cur_tile = tile + ToTileIndexDiff(it->ti); |
0 | 1467 |
|
1468 |
if (it->map5 != 0xFF) { |
|
1469 |
byte size; |
|
1470 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1471 |
size = it->ti.x; |
0 | 1472 |
if (size > i->width) i->width = size; |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1473 |
size = it->ti.y; |
0 | 1474 |
if (size > i->height)i->height = size; |
1475 |
||
1476 |
DoCommandByTile(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1477 |
||
1478 |
_map_type_and_height[cur_tile] = (_map_type_and_height[cur_tile]&~0xF0) | (MP_INDUSTRY<<4); |
|
1479 |
_map5[cur_tile] = it->map5; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1480 |
_map2[cur_tile] = i->index; |
0 | 1481 |
_map_owner[cur_tile] = _generating_world ? 0x1E : 0; /* maturity */ |
1482 |
} |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1483 |
} while ((++it)->ti.x != -0x80); |
0 | 1484 |
|
1485 |
i->width++; |
|
1486 |
i->height++; |
|
1487 |
||
1488 |
if (i->type == IT_FARM || i->type == IT_FARM_2) { |
|
1489 |
tile = i->xy + TILE_XY((i->width >> 1), (i->height >> 1)); |
|
1490 |
for(j=0; j!=50; j++) { |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1491 |
int x = Random() % 31 - 16; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1492 |
int y = Random() % 31 - 16; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1493 |
uint new_tile = TileAddWrap(tile, x, y); |
0 | 1494 |
if (new_tile != TILE_WRAPPED) |
1495 |
PlantFarmField(new_tile); |
|
131
16e59d059384
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents:
110
diff
changeset
|
1496 |
} |
0 | 1497 |
} |
1498 |
_industry_sort_dirty = true; |
|
1499 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
|
1500 |
} |
|
1501 |
||
1502 |
/* p1 = industry type 0-36 */ |
|
1503 |
int32 CmdBuildIndustry(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1504 |
{ |
|
1505 |
uint tile = TILE_FROM_XY(x,y); |
|
1506 |
Town *t; |
|
1507 |
int num; |
|
1508 |
const IndustryTileTable * const *itt; |
|
1509 |
const IndustryTileTable *it; |
|
1510 |
Industry *i; |
|
1511 |
const IndustrySpec *spec; |
|
1512 |
||
1513 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
1514 |
||
1515 |
if (!CheckSuitableIndustryPos(tile)) |
|
1516 |
return CMD_ERROR; |
|
1517 |
||
1518 |
spec = &_industry_spec[p1]; |
|
1519 |
||
1520 |
if (!_check_new_industry_procs[spec->check_proc](tile, p1)) |
|
1521 |
return CMD_ERROR; |
|
1522 |
||
1523 |
if ((t=CheckMultipleIndustryInTown(tile, p1)) == NULL) |
|
1524 |
return CMD_ERROR; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1525 |
|
0 | 1526 |
num = spec->num_table; |
1527 |
itt = spec->table; |
|
1528 |
||
1529 |
do { |
|
1530 |
if (--num < 0) |
|
1531 |
return_cmd_error(STR_0239_SITE_UNSUITABLE); |
|
1532 |
} while (!CheckIfIndustryTilesAreFree(tile, it=itt[num], p1, t)); |
|
1533 |
||
1534 |
||
1535 |
if (!CheckIfTooCloseToIndustry(tile, p1)) |
|
1536 |
return CMD_ERROR; |
|
1537 |
||
1538 |
if ( (i = AllocateIndustry()) == NULL) |
|
1539 |
return CMD_ERROR; |
|
1540 |
||
1541 |
if (flags & DC_EXEC) |
|
1542 |
DoCreateNewIndustry(i, tile, p1, it, t, 0x10); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1543 |
|
0 | 1544 |
return (_price.build_industry >> 5) * _industry_type_costs[p1]; |
1545 |
} |
|
1546 |
||
1547 |
||
1548 |
Industry *CreateNewIndustry(uint tile, int type) |
|
1549 |
{ |
|
1550 |
Town *t; |
|
1551 |
const IndustryTileTable *it; |
|
1552 |
Industry *i; |
|
1553 |
||
1554 |
const IndustrySpec *spec; |
|
1555 |
||
1556 |
if (!CheckSuitableIndustryPos(tile)) |
|
1557 |
return NULL; |
|
1558 |
||
1559 |
spec = &_industry_spec[type]; |
|
1560 |
||
1561 |
if (!_check_new_industry_procs[spec->check_proc](tile, type)) |
|
1562 |
return NULL; |
|
1563 |
||
1564 |
if (!(t=CheckMultipleIndustryInTown(tile, type))) |
|
1565 |
return NULL; |
|
1566 |
||
1567 |
/* pick a random layout */ |
|
1568 |
it = spec->table[(spec->num_table * (uint16)Random()) >> 16]; |
|
1569 |
||
1570 |
if (!CheckIfIndustryTilesAreFree(tile, it, type, t)) |
|
1571 |
return NULL; |
|
1572 |
||
1573 |
if (!CheckIfTooCloseToIndustry(tile, type)) |
|
1574 |
return NULL; |
|
1575 |
||
1576 |
if ( (i = AllocateIndustry()) == NULL) |
|
1577 |
return NULL; |
|
1578 |
||
1579 |
DoCreateNewIndustry(i, tile, type, it, t, 0x10); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1580 |
|
0 | 1581 |
return i; |
1582 |
} |
|
1583 |
||
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1584 |
static const byte _numof_industry_table[4][12] = { |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1585 |
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
0 | 1586 |
{0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5}, |
1587 |
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, |
|
1588 |
{0, 2, 3, 4, 6, 7, 8, 9, 10, 10, 10}, |
|
1589 |
}; |
|
1590 |
||
1591 |
static void PlaceInitialIndustry(byte type, int amount) |
|
1592 |
{ |
|
1593 |
int num = _numof_industry_table[_opt.diff.number_industries][amount]; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1594 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1595 |
if (_opt.diff.number_industries != 0) |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1596 |
{ |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1597 |
byte old_player = _current_player; |
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1598 |
_current_player = OWNER_NONE; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1599 |
assert(num > 0); |
0 | 1600 |
|
1601 |
do { |
|
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1602 |
int i = 2000; |
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1603 |
do { |
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1604 |
if (CreateNewIndustry(TILE_MASK(Random()), type) != NULL) |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1605 |
break; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1606 |
} while (--i != 0); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1607 |
} while (--num); |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1608 |
|
267 | 1609 |
_current_player = old_player; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1610 |
} |
0 | 1611 |
} |
1612 |
||
1613 |
void GenerateIndustries() |
|
1614 |
{ |
|
1615 |
const byte *b; |
|
1616 |
||
1617 |
b = _industry_create_table[_opt.landscape]; |
|
1618 |
do { |
|
1619 |
PlaceInitialIndustry(b[1], b[0]); |
|
1620 |
} while ( (b+=2)[0] != 0); |
|
1621 |
} |
|
1622 |
||
1623 |
static void ExtChangeIndustryProduction(Industry *i) |
|
1624 |
{ |
|
1625 |
bool closeit; |
|
1626 |
int j; |
|
1627 |
||
1628 |
if (_industry_close_mode[i->type] == 0) return; |
|
1629 |
||
1630 |
closeit = true; |
|
1631 |
||
1632 |
if (_industry_close_mode[i->type] == 2) { |
|
1633 |
if ( (byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1,180)) |
|
1634 |
closeit = false; |
|
1635 |
} else { |
|
1636 |
for (j=0; j != 2 && i->produced_cargo[j]!=255; j++){ |
|
1637 |
uint32 r; |
|
1638 |
int change,percent,old; |
|
1639 |
int mag; |
|
1640 |
||
1641 |
change = old = i->production_rate[j]; |
|
1642 |
if (CHANCE16R(20,1024,r))change -= ((RandomRange(50) + 10)*old) >> 8; |
|
1643 |
if (CHANCE16I(20+(i->pct_transported[j]*20>>8),1024,r>>16)) change += ((RandomRange(50) + 10)*old) >> 8; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1644 |
|
0 | 1645 |
// make sure it doesn't exceed 255 or goes below 0 |
1646 |
change = clamp(change, 0, 255); |
|
1647 |
if (change == old) { |
|
1648 |
closeit = false; |
|
1649 |
continue; |
|
1650 |
} |
|
1651 |
||
1652 |
percent = change*100/old - 100; |
|
1653 |
i->production_rate[j] = change; |
|
1654 |
||
1655 |
if (change >= _industry_spec[i->type].production_rate[j]/4) |
|
1656 |
closeit = false; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1657 |
|
0 | 1658 |
mag = abs(percent); |
1659 |
if (mag >= 10) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1660 |
SetDParam(3, mag); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1661 |
SetDParam(0,_cargoc.names_s[i->produced_cargo[j]]); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1662 |
SetDParam(1, i->town->index); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1663 |
SetDParam(2, i->type + STR_4802_COAL_MINE); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1664 |
AddNewsItem(percent>=0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN, |
0 | 1665 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), |
1666 |
i->xy + TILE_XY(1,1), 0); |
|
1667 |
} |
|
1668 |
} |
|
1669 |
} |
|
1670 |
||
1671 |
if (closeit) { |
|
1672 |
i->prod_level = 0; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1673 |
SetDParam(1, i->type + STR_4802_COAL_MINE); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1674 |
SetDParam(0, i->town->index); |
0 | 1675 |
AddNewsItem(_industry_close_strings[i->type], NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TILE_XY(1,1), 0); |
1676 |
} |
|
1677 |
} |
|
1678 |
||
1679 |
||
1680 |
static void UpdateIndustryStatistics(Industry *i) |
|
1681 |
{ |
|
1682 |
byte pct; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1683 |
|
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1684 |
if (i->produced_cargo[0] != 0xFF) { |
0 | 1685 |
pct = 0; |
1686 |
if (i->last_mo_production[0] != 0) { |
|
1687 |
i->last_prod_year = _cur_year; |
|
1688 |
pct = min(i->last_mo_transported[0] * 256 / i->last_mo_production[0],255); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1689 |
} |
0 | 1690 |
i->pct_transported[0] = pct; |
1691 |
||
1692 |
i->total_production[0] = i->last_mo_production[0]; |
|
1693 |
i->last_mo_production[0] = 0; |
|
1694 |
||
1695 |
i->total_transported[0] = i->last_mo_transported[0]; |
|
1696 |
i->last_mo_transported[0] = 0; |
|
1697 |
} |
|
1698 |
||
1699 |
if (i->produced_cargo[1] != 0xFF) { |
|
1700 |
pct = 0; |
|
1701 |
if (i->last_mo_production[1] != 0) { |
|
1702 |
i->last_prod_year = _cur_year; |
|
1703 |
pct = min(i->last_mo_transported[1] * 256 / i->last_mo_production[1],255); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1704 |
} |
0 | 1705 |
i->pct_transported[1] = pct; |
1706 |
||
1707 |
i->total_production[1] = i->last_mo_production[1]; |
|
1708 |
i->last_mo_production[1] = 0; |
|
1709 |
||
1710 |
i->total_transported[1] = i->last_mo_transported[1]; |
|
1711 |
i->last_mo_transported[1] = 0; |
|
1712 |
} |
|
1713 |
||
1714 |
||
1715 |
if ( i->produced_cargo[0] != 0xFF || i->produced_cargo[1] != 0xFF ) |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1716 |
InvalidateWindow(WC_INDUSTRY_VIEW, i->index); |
0 | 1717 |
|
1718 |
if (i->prod_level == 0) |
|
1719 |
DeleteIndustry(i); |
|
1720 |
else if (_patches.smooth_economy) |
|
1721 |
ExtChangeIndustryProduction(i); |
|
1722 |
} |
|
1723 |
||
1724 |
static const byte _new_industry_rand[4][32] = { |
|
1725 |
{12,12,12,12,12,12,12, 0, 0, 6, 6, 9, 9, 3, 3, 3,18,18, 4, 4, 2, 2, 5, 5, 5, 5, 5, 5, 1, 1, 8, 8}, |
|
1726 |
{16,16,16, 0, 0, 0, 9, 9, 9, 9,13,13, 3, 3, 3, 3,15,15,15, 4, 4,11,11,11,11,11,14,14, 1, 1, 7, 7}, |
|
1727 |
{21,21,21,24,22,22,22,22,23,23,12,12,12, 4, 4,19,19,19,13,13,20,20,20,11,11,11,17,17,17,10,10,10}, |
|
1728 |
{30,30,30,36,36,31,31,31,27,27,27,28,28,28,26,26,26,34,34,34,35,35,35,29,29,29,32,32,32,33,33,33}, |
|
1729 |
}; |
|
1730 |
||
1731 |
static void MaybeNewIndustry(uint32 r) |
|
1732 |
{ |
|
1733 |
int type; |
|
1734 |
int j; |
|
1735 |
Industry *i; |
|
1736 |
||
1737 |
type = _new_industry_rand[_opt.landscape][(r >> 16) & 0x1F]; |
|
1738 |
if (type == IT_OIL_WELL && _date > 10958) |
|
1739 |
return; |
|
1740 |
||
1741 |
if (type == IT_OIL_RIG && _date < 14610) |
|
1742 |
return; |
|
1743 |
||
1744 |
j = 2000; |
|
1745 |
for(;;) { |
|
1746 |
i = CreateNewIndustry(TILE_MASK(Random()), type); |
|
1747 |
if (i != NULL) |
|
1748 |
break; |
|
1749 |
if (--j == 0) |
|
1750 |
return; |
|
1751 |
} |
|
1752 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1753 |
SetDParam(0, type + STR_4802_COAL_MINE); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1754 |
SetDParam(1, i->town->index); |
0 | 1755 |
AddNewsItem( STR_482D_NEW_UNDER_CONSTRUCTION + (type == IT_FOREST), NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ECONOMY,0), i->xy, 0); |
1756 |
} |
|
1757 |
||
1758 |
static void MaybeCloseIndustry(Industry *i) |
|
1759 |
{ |
|
1760 |
uint32 r; |
|
1761 |
StringID str; |
|
1762 |
int type = i->type; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1763 |
|
0 | 1764 |
if (_industry_close_mode[type] == 1) { |
1765 |
/* decrease or increase */ |
|
1766 |
if (type == IT_OIL_WELL && _opt.landscape == LT_NORMAL) goto decrease_production; |
|
1767 |
if (CHANCE16I(1,3,r=Random())) { |
|
1768 |
if ((i->pct_transported[0] > 153) ^ CHANCE16I(1,3,r>>16)) { |
|
1769 |
||
1770 |
/* Increase production */ |
|
1771 |
if (i->prod_level != 0x80) { |
|
1772 |
byte b; |
|
1773 |
||
1774 |
i->prod_level <<= 1; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1775 |
|
0 | 1776 |
b = i->production_rate[0]*2; |
1777 |
if (i->production_rate[0] >= 128) b=255; |
|
1778 |
i->production_rate[0] = b; |
|
1779 |
b = i->production_rate[1]*2; |
|
1780 |
if (i->production_rate[1] >= 128) b=255; |
|
1781 |
i->production_rate[1] = b; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1782 |
|
0 | 1783 |
str = _industry_prod_up_strings[type]; |
1784 |
goto add_news; |
|
1785 |
} |
|
1786 |
} else { |
|
1787 |
decrease_production: |
|
1788 |
||
1789 |
/* Decrease production */ |
|
1790 |
if (i->prod_level == 4) goto close_industry; |
|
1791 |
i->prod_level>>=1; |
|
1792 |
i->production_rate[0] = (i->production_rate[0]+1) >> 1; |
|
1793 |
i->production_rate[1] = (i->production_rate[1]+1) >> 1; |
|
1794 |
||
1795 |
str = _industry_prod_down_strings[type]; |
|
1796 |
goto add_news; |
|
1797 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1798 |
} |
0 | 1799 |
} else if (_industry_close_mode[type] > 1) { |
1800 |
/* maybe close */ |
|
1801 |
if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1,2)) { |
|
1802 |
close_industry: |
|
1803 |
i->prod_level = 0; |
|
1804 |
str = _industry_close_strings[type]; |
|
1805 |
add_news: |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1806 |
SetDParam(1, type + STR_4802_COAL_MINE); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1807 |
SetDParam(0, i->town->index); |
0 | 1808 |
AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TILE_XY(1,1), 0); |
1809 |
} |
|
1810 |
} |
|
1811 |
} |
|
1812 |
||
1813 |
void IndustryMonthlyLoop() |
|
1814 |
{ |
|
1815 |
Industry *i; |
|
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1816 |
byte old_player = _current_player; |
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1817 |
_current_player = OWNER_NONE; |
0 | 1818 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1819 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1820 |
if (i->xy != 0) |
1821 |
UpdateIndustryStatistics(i); |
|
1822 |
} |
|
1823 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1824 |
i = GetIndustry(RandomRange(_industries_size)); |
0 | 1825 |
|
1826 |
if (i->xy == 0) { |
|
1827 |
uint32 r; |
|
1828 |
if (CHANCE16I(1,9,r=Random())) |
|
1829 |
MaybeNewIndustry(r); |
|
1830 |
} else if (!_patches.smooth_economy) { |
|
1831 |
MaybeCloseIndustry(i); |
|
1832 |
} |
|
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1833 |
|
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1834 |
_current_player = old_player; |
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1835 |
|
0 | 1836 |
// production-change |
1837 |
_industry_sort_dirty = true; |
|
1838 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
|
1839 |
} |
|
1840 |
||
1841 |
||
1842 |
void InitializeIndustries() |
|
1843 |
{ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1844 |
Industry *i; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1845 |
int j; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1846 |
|
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1847 |
memset(_industries, 0, sizeof(_industries[0]) * _industries_size); |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1848 |
|
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1849 |
j = 0; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1850 |
FOR_ALL_INDUSTRIES(i) |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1851 |
i->index = j++; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1852 |
|
0 | 1853 |
_total_industries = 0; |
1854 |
_industry_sort_dirty = true; |
|
1855 |
} |
|
1856 |
||
1857 |
const TileTypeProcs _tile_type_industry_procs = { |
|
1858 |
DrawTile_Industry, /* draw_tile_proc */ |
|
1859 |
GetSlopeZ_Industry, /* get_slope_z_proc */ |
|
1860 |
ClearTile_Industry, /* clear_tile_proc */ |
|
1861 |
GetAcceptedCargo_Industry, /* get_accepted_cargo_proc */ |
|
1862 |
GetTileDesc_Industry, /* get_tile_desc_proc */ |
|
1863 |
GetTileTrackStatus_Industry,/* get_tile_track_status_proc */ |
|
1864 |
ClickTile_Industry, /* click_tile_proc */ |
|
1865 |
AnimateTile_Industry, /* animate_tile_proc */ |
|
1866 |
TileLoop_Industry, /* tile_loop_proc */ |
|
1867 |
ChangeTileOwner_Industry, /* change_tile_owner_proc */ |
|
1868 |
GetProducedCargo_Industry, /* get_produced_cargo_proc */ |
|
1869 |
NULL, /* vehicle_enter_tile_proc */ |
|
1870 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 1871 |
GetSlopeTileh_Industry, /* get_slope_tileh_proc */ |
0 | 1872 |
}; |
1873 |
||
1874 |
static const byte _industry_desc[] = { |
|
1875 |
SLE_VAR(Industry,xy, SLE_UINT16), |
|
1876 |
SLE_VAR(Industry,width, SLE_UINT8), |
|
1877 |
SLE_VAR(Industry,height, SLE_UINT8), |
|
1878 |
SLE_REF(Industry,town, REF_TOWN), |
|
1879 |
SLE_ARR(Industry,produced_cargo, SLE_UINT8, 2), |
|
1880 |
SLE_ARR(Industry,cargo_waiting, SLE_UINT16, 2), |
|
1881 |
SLE_ARR(Industry,production_rate, SLE_UINT8, 2), |
|
1882 |
SLE_ARR(Industry,accepts_cargo, SLE_UINT8, 3), |
|
1883 |
SLE_VAR(Industry,prod_level, SLE_UINT8), |
|
1884 |
SLE_ARR(Industry,last_mo_production,SLE_UINT16, 2), |
|
1885 |
SLE_ARR(Industry,last_mo_transported,SLE_UINT16, 2), |
|
1886 |
SLE_ARR(Industry,pct_transported,SLE_UINT8, 2), |
|
1887 |
SLE_ARR(Industry,total_production,SLE_UINT16, 2), |
|
1888 |
SLE_ARR(Industry,total_transported,SLE_UINT16, 2), |
|
1889 |
||
1890 |
SLE_VAR(Industry,counter, SLE_UINT16), |
|
1891 |
||
1892 |
SLE_VAR(Industry,type, SLE_UINT8), |
|
1893 |
SLE_VAR(Industry,owner, SLE_UINT8), |
|
1894 |
SLE_VAR(Industry,color_map, SLE_UINT8), |
|
1895 |
SLE_VAR(Industry,last_prod_year, SLE_UINT8), |
|
1896 |
SLE_VAR(Industry,was_cargo_delivered,SLE_UINT8), |
|
1897 |
||
1898 |
// reserve extra space in savegame here. (currently 32 bytes) |
|
1899 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 4, 2, 255), |
|
1900 |
||
1901 |
SLE_END() |
|
1902 |
}; |
|
1903 |
||
1904 |
static void Save_INDY() |
|
1905 |
{ |
|
1906 |
Industry *ind; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1907 |
|
0 | 1908 |
// Write the vehicles |
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1909 |
FOR_ALL_INDUSTRIES(ind) { |
0 | 1910 |
if (ind->xy != 0) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1911 |
SlSetArrayIndex(ind->index); |
0 | 1912 |
SlObject(ind, _industry_desc); |
1913 |
} |
|
1914 |
} |
|
1915 |
} |
|
1916 |
||
1917 |
static void Load_INDY() |
|
1918 |
{ |
|
1919 |
int index; |
|
1920 |
_total_industries = 0; |
|
1921 |
while ((index = SlIterateArray()) != -1) { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1922 |
Industry *i = GetIndustry(index); |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1923 |
|
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1924 |
SlObject(i, _industry_desc); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1925 |
if (index > _total_industries) _total_industries = index; |
0 | 1926 |
} |
1927 |
} |
|
1928 |
||
1929 |
const ChunkHandler _industry_chunk_handlers[] = { |
|
1930 |
{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY | CH_LAST}, |
|
1931 |
}; |
|
1932 |