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