763 { |
763 { |
764 do { |
764 do { |
765 tile = TILE_MASK(tile); |
765 tile = TILE_MASK(tile); |
766 |
766 |
767 if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) { |
767 if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) { |
768 byte or = type; |
768 byte or_ = type; |
769 |
769 |
770 if (or == 1 && CHANCE16(1, 7)) or = 2; |
770 if (or_ == 1 && CHANCE16(1, 7)) or_ = 2; |
771 |
771 |
772 if (direction == AXIS_X) { |
772 if (direction == AXIS_X) { |
773 SetFenceSE(tile, or); |
773 SetFenceSE(tile, or_); |
774 } else { |
774 } else { |
775 SetFenceSW(tile, or); |
775 SetFenceSW(tile, or_); |
776 } |
776 } |
777 } |
777 } |
778 |
778 |
779 tile += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
779 tile += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
780 } while (--size); |
780 } while (--size); |
1223 /* Is the tile clear? */ |
1223 /* Is the tile clear? */ |
1224 if ((GetTileType(tile_walk) != MP_CLEAR) && (GetTileType(tile_walk) != MP_TREES)) |
1224 if ((GetTileType(tile_walk) != MP_CLEAR) && (GetTileType(tile_walk) != MP_TREES)) |
1225 return false; |
1225 return false; |
1226 |
1226 |
1227 /* Don't allow too big of a change if this is the sub-tile check */ |
1227 /* Don't allow too big of a change if this is the sub-tile check */ |
1228 if (internal != 0 && myabs(curh - height) > 1) return false; |
1228 if (internal != 0 && delta(curh, height) > 1) return false; |
1229 |
1229 |
1230 /* Different height, so the surrounding tiles of this tile |
1230 /* Different height, so the surrounding tiles of this tile |
1231 * has to be correct too (in level, or almost in level) |
1231 * has to be correct too (in level, or almost in level) |
1232 * else you get a chain-reaction of terraforming. */ |
1232 * else you get a chain-reaction of terraforming. */ |
1233 if (internal == 0 && curh != height) { |
1233 if (internal == 0 && curh != height) { |
1351 |
1351 |
1352 /* Check if we can add a block to the pool */ |
1352 /* Check if we can add a block to the pool */ |
1353 return AddBlockToPool(&_Industry_pool) ? AllocateIndustry() : NULL; |
1353 return AddBlockToPool(&_Industry_pool) ? AllocateIndustry() : NULL; |
1354 } |
1354 } |
1355 |
1355 |
1356 static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, const Town *t, byte owner) |
1356 static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, const Town *t, Owner owner) |
1357 { |
1357 { |
1358 const IndustrySpec *indspec = GetIndustrySpec(type); |
1358 const IndustrySpec *indspec = GetIndustrySpec(type); |
1359 uint32 r; |
1359 uint32 r; |
1360 int j; |
1360 int j; |
1361 |
1361 |
1593 break; |
1593 break; |
1594 |
1594 |
1595 default: /* INDUSTRY_PRODUCTION */ |
1595 default: /* INDUSTRY_PRODUCTION */ |
1596 for (j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){ |
1596 for (j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){ |
1597 uint32 r = Random(); |
1597 uint32 r = Random(); |
1598 int old, new, percent; |
1598 int old_prod, new_prod, percent; |
1599 int mag; |
1599 int mag; |
1600 |
1600 |
1601 new = old = i->production_rate[j]; |
1601 new_prod = old_prod = i->production_rate[j]; |
1602 if (CHANCE16I(20, 1024, r)) |
1602 if (CHANCE16I(20, 1024, r)) |
1603 new -= ((RandomRange(50) + 10) * old) >> 8; |
1603 new_prod -= ((RandomRange(50) + 10) * old_prod) >> 8; |
1604 if (CHANCE16I(20 + (i->pct_transported[j] * 20 >> 8), 1024, r >> 16)) |
1604 if (CHANCE16I(20 + (i->pct_transported[j] * 20 >> 8), 1024, r >> 16)) |
1605 new += ((RandomRange(50) + 10) * old) >> 8; |
1605 new_prod += ((RandomRange(50) + 10) * old_prod) >> 8; |
1606 |
1606 |
1607 new = clamp(new, 0, 255); |
1607 new_prod = clamp(new_prod, 0, 255); |
1608 if (new == old) { |
1608 if (new_prod == old_prod) { |
1609 closeit = false; |
1609 closeit = false; |
1610 continue; |
1610 continue; |
1611 } |
1611 } |
1612 |
1612 |
1613 percent = new * 100 / old - 100; |
1613 percent = new_prod * 100 / old_prod - 100; |
1614 i->production_rate[j] = new; |
1614 i->production_rate[j] = new_prod; |
1615 |
1615 |
1616 if (new >= indspec->production_rate[j] / 4) |
1616 if (new_prod >= indspec->production_rate[j] / 4) |
1617 closeit = false; |
1617 closeit = false; |
1618 |
1618 |
1619 mag = abs(percent); |
1619 mag = abs(percent); |
1620 if (mag >= 10) { |
1620 if (mag >= 10) { |
1621 SetDParam(2, mag); |
1621 SetDParam(2, mag); |
1825 _total_industries = 0; |
1825 _total_industries = 0; |
1826 _industry_sort_dirty = true; |
1826 _industry_sort_dirty = true; |
1827 _industry_sound_tile = 0; |
1827 _industry_sound_tile = 0; |
1828 } |
1828 } |
1829 |
1829 |
1830 const TileTypeProcs _tile_type_industry_procs = { |
1830 extern const TileTypeProcs _tile_type_industry_procs = { |
1831 DrawTile_Industry, /* draw_tile_proc */ |
1831 DrawTile_Industry, /* draw_tile_proc */ |
1832 GetSlopeZ_Industry, /* get_slope_z_proc */ |
1832 GetSlopeZ_Industry, /* get_slope_z_proc */ |
1833 ClearTile_Industry, /* clear_tile_proc */ |
1833 ClearTile_Industry, /* clear_tile_proc */ |
1834 GetAcceptedCargo_Industry, /* get_accepted_cargo_proc */ |
1834 GetAcceptedCargo_Industry, /* get_accepted_cargo_proc */ |
1835 GetTileDesc_Industry, /* get_tile_desc_proc */ |
1835 GetTileDesc_Industry, /* get_tile_desc_proc */ |