233 } |
233 } |
234 |
234 |
235 return IT_INVALID; //we have not found equivalent, whatever the reason |
235 return IT_INVALID; //we have not found equivalent, whatever the reason |
236 } |
236 } |
237 |
237 |
|
238 /** |
|
239 * Accessor for array _industry_specs. |
|
240 * This will ensure at once : proper access and |
|
241 * not allowing modifications of it. |
|
242 * @param thistype of industry (which is the index in _industry_spec) |
|
243 * @pre thistype < IT_END |
|
244 **/ |
|
245 static const IndustrySpec *GetIndustrySpecification(IndustryType thistype) |
|
246 { |
|
247 assert(thistype < IT_END); |
|
248 return &_industry_specs[thistype]; |
|
249 } |
|
250 |
238 static void IndustryDrawSugarMine(const TileInfo *ti) |
251 static void IndustryDrawSugarMine(const TileInfo *ti) |
239 { |
252 { |
240 const DrawIndustrySpec1Struct *d; |
253 const DrawIndustrySpec1Struct *d; |
241 uint32 image; |
254 uint32 image; |
242 |
255 |
372 int proc = dits->draw_proc - 1; |
385 int proc = dits->draw_proc - 1; |
373 if (proc >= 0) _industry_draw_tile_procs[proc](ti); |
386 if (proc >= 0) _industry_draw_tile_procs[proc](ti); |
374 } |
387 } |
375 } |
388 } |
376 |
389 |
377 static uint GetSlopeZ_Industry(const TileInfo* ti) |
390 static uint GetSlopeZ_Industry(const TileInfo *ti) |
378 { |
391 { |
379 return ti->z + (ti->tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT); |
392 return ti->z + (ti->tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT); |
380 } |
393 } |
381 |
394 |
382 static Slope GetSlopeTileh_Industry(TileIndex tile, Slope tileh) |
395 static Slope GetSlopeTileh_Industry(TileIndex tile, Slope tileh) |
399 if (a != CT_INVALID) ac[a] = 8; |
412 if (a != CT_INVALID) ac[a] = 8; |
400 } |
413 } |
401 |
414 |
402 static void GetTileDesc_Industry(TileIndex tile, TileDesc *td) |
415 static void GetTileDesc_Industry(TileIndex tile, TileDesc *td) |
403 { |
416 { |
404 const Industry* i = GetIndustryByTile(tile); |
417 const Industry *i = GetIndustryByTile(tile); |
405 |
418 |
406 td->owner = i->owner; |
419 td->owner = i->owner; |
407 td->str = STR_4802_COAL_MINE + i->type; |
420 td->str = STR_4802_COAL_MINE + i->type; |
408 if (!IsIndustryCompleted(tile)) { |
421 if (!IsIndustryCompleted(tile)) { |
409 SetDParamX(td->dparam, 0, td->str); |
422 SetDParamX(td->dparam, 0, td->str); |
411 } |
424 } |
412 } |
425 } |
413 |
426 |
414 static int32 ClearTile_Industry(TileIndex tile, byte flags) |
427 static int32 ClearTile_Industry(TileIndex tile, byte flags) |
415 { |
428 { |
416 Industry* i = GetIndustryByTile(tile); |
429 Industry *i = GetIndustryByTile(tile); |
417 |
430 |
418 /* * water can destroy industries |
431 /* * water can destroy industries |
419 * in editor you can bulldoze industries |
432 * in editor you can bulldoze industries |
420 * with magic_bulldozer cheat you can destroy industries |
433 * with magic_bulldozer cheat you can destroy industries |
421 * (area around OILRIG is water, so water shouldn't flood it |
434 * (area around OILRIG is water, so water shouldn't flood it |
440 5, 5, 5, 5, 5, |
453 5, 5, 5, 5, 5, |
441 }; |
454 }; |
442 |
455 |
443 static void TransportIndustryGoods(TileIndex tile) |
456 static void TransportIndustryGoods(TileIndex tile) |
444 { |
457 { |
445 Industry* i = GetIndustryByTile(tile); |
458 Industry *i = GetIndustryByTile(tile); |
446 uint cw, am; |
459 uint cw, am; |
447 |
460 |
448 cw = min(i->cargo_waiting[0], 255); |
461 cw = min(i->cargo_waiting[0], 255); |
449 if (cw > _industry_min_cargo[i->type]/* && i->produced_cargo[0] != 0xFF*/) { |
462 if (cw > _industry_min_cargo[i->type]/* && i->produced_cargo[0] != 0xFF*/) { |
450 i->cargo_waiting[0] -= cw; |
463 i->cargo_waiting[0] -= cw; |
809 CreateEffectVehicleAbove(TileX(tile) * TILE_SIZE + 6, TileY(tile) * TILE_SIZE + 6, 43, EV_SMOKE); |
822 CreateEffectVehicleAbove(TileX(tile) * TILE_SIZE + 6, TileY(tile) * TILE_SIZE + 6, 43, EV_SMOKE); |
810 break; |
823 break; |
811 |
824 |
812 |
825 |
813 case 143: { |
826 case 143: { |
814 Industry* i = GetIndustryByTile(tile); |
827 Industry *i = GetIndustryByTile(tile); |
815 if (i->was_cargo_delivered) { |
828 if (i->was_cargo_delivered) { |
816 i->was_cargo_delivered = false; |
829 i->was_cargo_delivered = false; |
817 SetIndustryAnimationLoop(tile, 0); |
830 SetIndustryAnimationLoop(tile, 0); |
818 AddAnimatedTile(tile); |
831 AddAnimatedTile(tile); |
819 } |
832 } |
973 SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, AXIS_X); |
986 SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, AXIS_X); |
974 SetupFarmFieldFence(tile + TileDiffXY(size_x - 1, 0), size_y, type, AXIS_Y); |
987 SetupFarmFieldFence(tile + TileDiffXY(size_x - 1, 0), size_y, type, AXIS_Y); |
975 SetupFarmFieldFence(tile + TileDiffXY(0, size_y - 1), size_x, type, AXIS_X); |
988 SetupFarmFieldFence(tile + TileDiffXY(0, size_y - 1), size_x, type, AXIS_X); |
976 } |
989 } |
977 |
990 |
978 static void MaybePlantFarmField(const Industry* i) |
991 static void MaybePlantFarmField(const Industry *i) |
979 { |
992 { |
980 if (CHANCE16(1, 8)) { |
993 if (CHANCE16(1, 8)) { |
981 int x = i->width / 2 + Random() % 31 - 16; |
994 int x = i->width / 2 + Random() % 31 - 16; |
982 int y = i->height / 2 + Random() % 31 - 16; |
995 int y = i->height / 2 + Random() % 31 - 16; |
983 TileIndex tile = TileAddWrap(i->xy, x, y); |
996 TileIndex tile = TileAddWrap(i->xy, x, y); |
1269 16, 16, 16, 16, 16, 16, 16, 16, |
1282 16, 16, 16, 16, 16, 16, 16, 16, |
1270 16, 16, 16, 16, 16, 16, 16, 16, |
1283 16, 16, 16, 16, 16, 16, 16, 16, |
1271 16, 16, 16, 16, 16, 16, 16, |
1284 16, 16, 16, 16, 16, 16, 16, |
1272 }; |
1285 }; |
1273 |
1286 |
1274 static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable* it, int type, const Town* t) |
1287 static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, int type, const Town *t) |
1275 { |
1288 { |
1276 _error_message = STR_0239_SITE_UNSUITABLE; |
1289 _error_message = STR_0239_SITE_UNSUITABLE; |
1277 |
1290 |
1278 do { |
1291 do { |
1279 TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); |
1292 TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); |
1345 return true; |
1358 return true; |
1346 } |
1359 } |
1347 |
1360 |
1348 static bool CheckIfTooCloseToIndustry(TileIndex tile, int type) |
1361 static bool CheckIfTooCloseToIndustry(TileIndex tile, int type) |
1349 { |
1362 { |
1350 const IndustrySpec* spec = &_industry_spec[type]; |
1363 const IndustrySpec *spec = GetIndustrySpecification(type); |
1351 const Industry* i; |
1364 const Industry *i; |
1352 |
1365 |
1353 // accepting industries won't be close, not even with patch |
1366 // accepting industries won't be close, not even with patch |
1354 if (_patches.same_industry_close && spec->accepts_cargo[0] == CT_INVALID) |
1367 if (_patches.same_industry_close && spec->accepts_cargo[0] == CT_INVALID) |
1355 return true; |
1368 return true; |
1356 |
1369 |
1398 |
1411 |
1399 /* Check if we can add a block to the pool */ |
1412 /* Check if we can add a block to the pool */ |
1400 return AddBlockToPool(&_industry_pool) ? AllocateIndustry() : NULL; |
1413 return AddBlockToPool(&_industry_pool) ? AllocateIndustry() : NULL; |
1401 } |
1414 } |
1402 |
1415 |
1403 static void DoCreateNewIndustry(Industry* i, TileIndex tile, int type, const IndustryTileTable* it, const Town* t, byte owner) |
1416 static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, const Town *t, byte owner) |
1404 { |
1417 { |
1405 const IndustrySpec *spec; |
1418 const IndustrySpec *spec = GetIndustrySpecification(type); |
1406 uint32 r; |
1419 uint32 r; |
1407 int j; |
1420 int j; |
1408 |
1421 |
1409 i->xy = tile; |
1422 i->xy = tile; |
1410 i->width = i->height = 0; |
1423 i->width = i->height = 0; |
1411 i->type = type; |
1424 i->type = type; |
1412 |
|
1413 spec = &_industry_spec[type]; |
|
1414 |
1425 |
1415 i->produced_cargo[0] = spec->produced_cargo[0]; |
1426 i->produced_cargo[0] = spec->produced_cargo[0]; |
1416 i->produced_cargo[1] = spec->produced_cargo[1]; |
1427 i->produced_cargo[1] = spec->produced_cargo[1]; |
1417 i->accepts_cargo[0] = spec->accepts_cargo[0]; |
1428 i->accepts_cargo[0] = spec->accepts_cargo[0]; |
1418 i->accepts_cargo[1] = spec->accepts_cargo[1]; |
1429 i->accepts_cargo[1] = spec->accepts_cargo[1]; |
1490 * @param p1 industry type @see build_industry.h and @see industry.h |
1501 * @param p1 industry type @see build_industry.h and @see industry.h |
1491 * @param p2 unused |
1502 * @param p2 unused |
1492 */ |
1503 */ |
1493 int32 CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1504 int32 CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1494 { |
1505 { |
1495 const Town* t; |
1506 const Town *t; |
1496 Industry *i; |
1507 Industry *i; |
1497 int num; |
1508 int num; |
1498 const IndustryTileTable * const *itt; |
1509 const IndustryTileTable * const *itt; |
1499 const IndustryTileTable *it; |
1510 const IndustryTileTable *it; |
1500 const IndustrySpec *spec; |
1511 const IndustrySpec *spec; |
1504 if (!CheckSuitableIndustryPos(tile)) return CMD_ERROR; |
1515 if (!CheckSuitableIndustryPos(tile)) return CMD_ERROR; |
1505 |
1516 |
1506 /* Check if the to-be built/founded industry is available for this climate. |
1517 /* Check if the to-be built/founded industry is available for this climate. |
1507 * Unfortunately we have no easy way of checking, except for looping the table */ |
1518 * Unfortunately we have no easy way of checking, except for looping the table */ |
1508 { |
1519 { |
1509 const byte* i; |
1520 const byte *i; |
1510 bool found = false; |
1521 bool found = false; |
1511 |
1522 |
1512 for (i = &_build_industry_types[_opt_ptr->landscape][0]; i != endof(_build_industry_types[_opt_ptr->landscape]); i++) { |
1523 for (i = &_build_industry_types[_opt_ptr->landscape][0]; i != endof(_build_industry_types[_opt_ptr->landscape]); i++) { |
1513 if (*i == p1) { |
1524 if (*i == p1) { |
1514 found = true; |
1525 found = true; |
1516 } |
1527 } |
1517 } |
1528 } |
1518 if (!found) return CMD_ERROR; |
1529 if (!found) return CMD_ERROR; |
1519 } |
1530 } |
1520 |
1531 |
1521 spec = &_industry_spec[p1]; |
1532 spec = GetIndustrySpecification(p1); |
1522 /* If the patch for raw-material industries is not on, you cannot build raw-material industries. |
1533 /* If the patch for raw-material industries is not on, you cannot build raw-material industries. |
1523 * Raw material industries are industries that do not accept cargo (at least for now) |
1534 * Raw material industries are industries that do not accept cargo (at least for now) |
1524 * Exclude the lumber mill (only "raw" industry that can be built) */ |
1535 * Exclude the lumber mill (only "raw" industry that can be built) */ |
1525 if (!_patches.build_rawmaterial_ind && |
1536 if (!_patches.build_rawmaterial_ind && |
1526 spec->accepts_cargo[0] == CT_INVALID && |
1537 spec->accepts_cargo[0] == CT_INVALID && |
1554 } |
1565 } |
1555 |
1566 |
1556 |
1567 |
1557 Industry *CreateNewIndustry(TileIndex tile, IndustryType type) |
1568 Industry *CreateNewIndustry(TileIndex tile, IndustryType type) |
1558 { |
1569 { |
1559 const Town* t; |
1570 const Town *t; |
1560 const IndustryTileTable *it; |
1571 const IndustryTileTable *it; |
1561 Industry *i; |
1572 Industry *i; |
1562 |
1573 |
1563 const IndustrySpec *spec; |
1574 const IndustrySpec *spec; |
1564 |
1575 |
1565 if (!CheckSuitableIndustryPos(tile)) return NULL; |
1576 if (!CheckSuitableIndustryPos(tile)) return NULL; |
1566 |
1577 |
1567 spec = &_industry_spec[type]; |
1578 spec = GetIndustrySpecification(type); |
1568 |
1579 |
1569 if (!_check_new_industry_procs[spec->check_proc](tile, type)) return NULL; |
1580 if (!_check_new_industry_procs[spec->check_proc](tile, type)) return NULL; |
1570 |
1581 |
1571 t = CheckMultipleIndustryInTown(tile, type); |
1582 t = CheckMultipleIndustryInTown(tile, type); |
1572 if (t == NULL) return NULL; |
1583 if (t == NULL) return NULL; |