62 byte image_1; |
62 byte image_1; |
63 byte image_2; |
63 byte image_2; |
64 byte image_3; |
64 byte image_3; |
65 } DrawIndustrySpec4Struct; |
65 } DrawIndustrySpec4Struct; |
66 |
66 |
67 |
|
68 |
|
69 #include "table/industry_land.h" |
|
70 |
|
71 |
|
72 typedef struct IndustryTileTable { |
67 typedef struct IndustryTileTable { |
73 TileIndexDiffC ti; |
68 TileIndexDiffC ti; |
74 byte map5; |
69 byte map5; |
75 } IndustryTileTable; |
70 } IndustryTileTable; |
76 |
71 |
77 typedef struct IndustrySpec { |
72 typedef struct IndustrySpec { |
78 const IndustryTileTable * const * table; |
73 const IndustryTileTable *const *table; |
79 byte num_table; |
74 byte num_table; |
80 byte a,b,c; |
75 byte a,b,c; |
81 byte produced_cargo[2]; |
76 byte produced_cargo[2]; |
82 byte production_rate[2]; |
77 byte production_rate[2]; |
83 byte accepts_cargo[3]; |
78 byte accepts_cargo[3]; |
84 byte check_proc; |
79 byte check_proc; |
85 } IndustrySpec; |
80 } IndustrySpec; |
86 |
81 |
|
82 #include "table/industry_land.h" |
87 #include "table/build_industry.h" |
83 #include "table/build_industry.h" |
88 |
84 |
89 typedef enum IndustryType { |
85 typedef enum IndustryType { |
90 INDUSTRY_NOT_CLOSABLE, //! Industry can never close |
86 INDUSTRY_NOT_CLOSABLE, //! Industry can never close |
91 INDUSTRY_PRODUCTION, //! Industry can close and change of production |
87 INDUSTRY_PRODUCTION, //! Industry can close and change of production |
1547 } |
1543 } |
1548 _industry_sort_dirty = true; |
1544 _industry_sort_dirty = true; |
1549 InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
1545 InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
1550 } |
1546 } |
1551 |
1547 |
1552 /* p1 = industry type 0-36 */ |
1548 /** Build/Fund an industry |
|
1549 * @param x,y coordinates where industry is built |
|
1550 * @param p1 industry type @see build_industry.h and @see industry.h |
|
1551 * @param p2 unused |
|
1552 */ |
1553 int32 CmdBuildIndustry(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1553 int32 CmdBuildIndustry(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1554 { |
1554 { |
1555 uint tile = TILE_FROM_XY(x,y); |
|
1556 Town *t; |
1555 Town *t; |
|
1556 Industry *i; |
|
1557 TileIndex tile = TILE_FROM_XY(x,y); |
1557 int num; |
1558 int num; |
1558 const IndustryTileTable * const *itt; |
1559 const IndustryTileTable * const *itt; |
1559 const IndustryTileTable *it; |
1560 const IndustryTileTable *it; |
1560 Industry *i; |
|
1561 const IndustrySpec *spec; |
1561 const IndustrySpec *spec; |
1562 |
1562 |
1563 SET_EXPENSES_TYPE(EXPENSES_OTHER); |
1563 SET_EXPENSES_TYPE(EXPENSES_OTHER); |
1564 |
1564 |
1565 if (!CheckSuitableIndustryPos(tile)) |
1565 if (!CheckSuitableIndustryPos(tile)) return CMD_ERROR; |
1566 return CMD_ERROR; |
1566 |
|
1567 /* Check if the to-be built/founded industry is available for this climate. |
|
1568 * Unfortunately we have no easy way of checking, except for looping the table */ |
|
1569 { const byte *i; |
|
1570 bool found = false; |
|
1571 for (i = &_build_industry_types[_opt_ptr->landscape][0]; i != endof(_build_industry_types[_opt_ptr->landscape]); i++) { |
|
1572 if (*i == p1) {found = true; break;} |
|
1573 } |
|
1574 if (!found) return CMD_ERROR; |
|
1575 } |
1567 |
1576 |
1568 spec = &_industry_spec[p1]; |
1577 spec = &_industry_spec[p1]; |
1569 |
1578 /* If the patch for non-raw-material industries is not on, you cannot build raw-material industries. |
1570 if (!_check_new_industry_procs[spec->check_proc](tile, p1)) |
1579 * Raw material industries are industries that do not accept cargo (at least for now) */ |
1571 return CMD_ERROR; |
1580 if (!_patches.build_rawmaterial_ind && spec->accepts_cargo[0] == 255 && |
1572 |
1581 spec->accepts_cargo[1] == 255 && spec->accepts_cargo[2] == 255) return CMD_ERROR; |
1573 if ((t=CheckMultipleIndustryInTown(tile, p1)) == NULL) |
1582 |
1574 return CMD_ERROR; |
1583 if (!_check_new_industry_procs[spec->check_proc](tile, p1)) return CMD_ERROR; |
|
1584 |
|
1585 if ((t = CheckMultipleIndustryInTown(tile, p1)) == NULL) return CMD_ERROR; |
1575 |
1586 |
1576 num = spec->num_table; |
1587 num = spec->num_table; |
1577 itt = spec->table; |
1588 itt = spec->table; |
1578 |
1589 |
1579 do { |
1590 do { |
1580 if (--num < 0) |
1591 if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE); |
1581 return_cmd_error(STR_0239_SITE_UNSUITABLE); |
1592 } while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1, t)); |
1582 } while (!CheckIfIndustryTilesAreFree(tile, it=itt[num], p1, t)); |
1593 |
1583 |
1594 |
1584 |
1595 if (!CheckIfTooCloseToIndustry(tile, p1)) return CMD_ERROR; |
1585 if (!CheckIfTooCloseToIndustry(tile, p1)) |
1596 |
1586 return CMD_ERROR; |
1597 if ( (i = AllocateIndustry()) == NULL) return CMD_ERROR; |
1587 |
|
1588 if ( (i = AllocateIndustry()) == NULL) |
|
1589 return CMD_ERROR; |
|
1590 |
1598 |
1591 if (flags & DC_EXEC) |
1599 if (flags & DC_EXEC) |
1592 DoCreateNewIndustry(i, tile, p1, it, t, 0x10); |
1600 DoCreateNewIndustry(i, tile, p1, it, t, OWNER_NONE); |
1593 |
1601 |
1594 return (_price.build_industry >> 5) * _industry_type_costs[p1]; |
1602 return (_price.build_industry >> 5) * _industry_type_costs[p1]; |
1595 } |
1603 } |
1596 |
1604 |
1597 |
1605 |