472 static void ClickTile_Town(TileIndex tile) |
472 static void ClickTile_Town(TileIndex tile) |
473 { |
473 { |
474 /* not used */ |
474 /* not used */ |
475 } |
475 } |
476 |
476 |
477 static int32 ClearTile_Town(TileIndex tile, byte flags) |
477 static CommandCost ClearTile_Town(TileIndex tile, byte flags) |
478 { |
478 { |
479 int rating; |
479 int rating; |
480 int32 cost; |
480 CommandCost cost; |
481 Town *t; |
481 Town *t; |
482 HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); |
482 HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); |
483 |
483 |
484 if (flags&DC_AUTO && !(flags&DC_AI_BUILDING)) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
484 if (flags&DC_AUTO && !(flags&DC_AI_BUILDING)) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
485 if (!CanDeleteHouse(tile)) return CMD_ERROR; |
485 if (!CanDeleteHouse(tile)) return CMD_ERROR; |
702 k = (dir & 1) ? SLOPE_NE : SLOPE_NW; |
702 k = (dir & 1) ? SLOPE_NE : SLOPE_NW; |
703 if (k != slope && ComplementSlope(k) != slope) { |
703 if (k != slope && ComplementSlope(k) != slope) { |
704 uint32 r = Random(); |
704 uint32 r = Random(); |
705 |
705 |
706 if (CHANCE16I(1, 8, r) && !_generating_world) { |
706 if (CHANCE16I(1, 8, r) && !_generating_world) { |
707 int32 res; |
707 CommandCost res; |
708 |
708 |
709 if (CHANCE16I(1, 16, r)) { |
709 if (CHANCE16I(1, 16, r)) { |
710 res = DoCommand(tile, slope, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, |
710 res = DoCommand(tile, slope, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, |
711 CMD_TERRAFORM_LAND); |
711 CMD_TERRAFORM_LAND); |
712 } else { |
712 } else { |
724 } |
724 } |
725 } |
725 } |
726 |
726 |
727 static bool TerraformTownTile(TileIndex tile, int edges, int dir) |
727 static bool TerraformTownTile(TileIndex tile, int edges, int dir) |
728 { |
728 { |
729 int32 r; |
729 CommandCost r; |
730 |
730 |
731 TILE_ASSERT(tile); |
731 TILE_ASSERT(tile); |
732 |
732 |
733 r = DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); |
733 r = DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); |
734 if (CmdFailed(r) || r >= 126 * 16) return false; |
734 if (CmdFailed(r) || r >= 126 * 16) return false; |
1057 case SLOPE_NW: i = DIAGDIR_SE; break; |
1057 case SLOPE_NW: i = DIAGDIR_SE; break; |
1058 case SLOPE_NE: i = DIAGDIR_SW; break; |
1058 case SLOPE_NE: i = DIAGDIR_SW; break; |
1059 |
1059 |
1060 default: |
1060 default: |
1061 build_road_and_exit: |
1061 build_road_and_exit: |
1062 if (!CmdFailed(DoCommand(tile, rcmd, t1->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) { |
1062 if (CmdSucceeded(DoCommand(tile, rcmd, t1->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) { |
1063 _grow_town_result = -1; |
1063 _grow_town_result = -1; |
1064 } |
1064 } |
1065 return; |
1065 return; |
1066 } |
1066 } |
1067 |
1067 |
1090 { |
1090 { |
1091 int32 bridge_len = GetBridgeLength(tile, tmptile); |
1091 int32 bridge_len = GetBridgeLength(tile, tmptile); |
1092 do { |
1092 do { |
1093 byte bridge_type = RandomRange(MAX_BRIDGES - 1); |
1093 byte bridge_type = RandomRange(MAX_BRIDGES - 1); |
1094 if (CheckBridge_Stuff(bridge_type, bridge_len)) { |
1094 if (CheckBridge_Stuff(bridge_type, bridge_len)) { |
1095 if (!CmdFailed(DoCommand(tile, tmptile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE))) |
1095 if (CmdSucceeded(DoCommand(tile, tmptile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE))) |
1096 _grow_town_result = -1; |
1096 _grow_town_result = -1; |
1097 |
1097 |
1098 /* obviously, if building any bridge would fail, there is no need to try other bridge-types */ |
1098 /* obviously, if building any bridge would fail, there is no need to try other bridge-types */ |
1099 return; |
1099 return; |
1100 } |
1100 } |
1229 * clearing some land and then building a road there. */ |
1229 * clearing some land and then building a road there. */ |
1230 tile = t->xy; |
1230 tile = t->xy; |
1231 for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { |
1231 for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { |
1232 /* Only work with plain land that not already has a house */ |
1232 /* Only work with plain land that not already has a house */ |
1233 if (!IsTileType(tile, MP_HOUSE) && GetTileSlope(tile, NULL) == SLOPE_FLAT) { |
1233 if (!IsTileType(tile, MP_HOUSE) && GetTileSlope(tile, NULL) == SLOPE_FLAT) { |
1234 if (!CmdFailed(DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR))) { |
1234 if (CmdSucceeded(DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR))) { |
1235 DoCommand(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD); |
1235 DoCommand(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD); |
1236 _current_player = old_player; |
1236 _current_player = old_player; |
1237 return true; |
1237 return true; |
1238 } |
1238 } |
1239 } |
1239 } |
1474 * @param tile coordinates where town is built |
1474 * @param tile coordinates where town is built |
1475 * @param flags type of operation |
1475 * @param flags type of operation |
1476 * @param p1 size of the town (0 = small, 1 = medium, 2 = large) |
1476 * @param p1 size of the town (0 = small, 1 = medium, 2 = large) |
1477 * @param p2 size mode (@see TownSizeMode) |
1477 * @param p2 size mode (@see TownSizeMode) |
1478 */ |
1478 */ |
1479 int32 CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1479 CommandCost CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1480 { |
1480 { |
1481 Town *t; |
1481 Town *t; |
1482 uint32 townnameparts; |
1482 uint32 townnameparts; |
1483 |
1483 |
1484 /* Only in the scenario editor */ |
1484 /* Only in the scenario editor */ |
1598 if ((slope != SLOPE_FLAT && ~slope & _masks[mode])) b = ~b; |
1598 if ((slope != SLOPE_FLAT && ~slope & _masks[mode])) b = ~b; |
1599 if ((tileh != SLOPE_FLAT && ~tileh & _masks[mode+4])) b = ~b; |
1599 if ((tileh != SLOPE_FLAT && ~tileh & _masks[mode+4])) b = ~b; |
1600 if (b) |
1600 if (b) |
1601 return false; |
1601 return false; |
1602 |
1602 |
1603 return !CmdFailed(DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR)); |
1603 return CmdSucceeded(DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR)); |
1604 } |
1604 } |
1605 |
1605 |
1606 |
1606 |
1607 static bool CheckFree2x2Area(TileIndex tile) |
1607 static bool CheckFree2x2Area(TileIndex tile) |
1608 { |
1608 { |
1663 |
1663 |
1664 /* Generate a list of all possible houses that can be built. */ |
1664 /* Generate a list of all possible houses that can be built. */ |
1665 for (i = 0; i < HOUSE_MAX; i++) { |
1665 for (i = 0; i < HOUSE_MAX; i++) { |
1666 hs = GetHouseSpecs(i); |
1666 hs = GetHouseSpecs(i); |
1667 if ((~hs->building_availability & bitmask) == 0 && hs->enabled) { |
1667 if ((~hs->building_availability & bitmask) == 0 && hs->enabled) { |
1668 if (HASBIT(_loaded_newgrf_features, GRFLOADED_NEWHOUSES)) { |
1668 if (_loaded_newgrf_features.has_newhouses) { |
1669 probability_max += hs->probability; |
1669 probability_max += hs->probability; |
1670 cumulative_probs[num] = probability_max; |
1670 cumulative_probs[num] = probability_max; |
1671 } |
1671 } |
1672 houses[num++] = (HouseID)i; |
1672 houses[num++] = (HouseID)i; |
1673 } |
1673 } |
1674 } |
1674 } |
1675 |
1675 |
1676 for (;;) { |
1676 for (;;) { |
1677 if (HASBIT(_loaded_newgrf_features, GRFLOADED_NEWHOUSES)) { |
1677 if (_loaded_newgrf_features.has_newhouses) { |
1678 uint r = RandomRange(probability_max); |
1678 uint r = RandomRange(probability_max); |
1679 for (i = 0; i < num; i++) if (cumulative_probs[i] >= r) break; |
1679 for (i = 0; i < num; i++) if (cumulative_probs[i] >= r) break; |
1680 |
1680 |
1681 house = houses[i]; |
1681 house = houses[i]; |
1682 } else { |
1682 } else { |
1683 house = houses[RandomRange(num)]; |
1683 house = houses[RandomRange(num)]; |
1684 } |
1684 } |
1685 |
1685 |
1686 hs = GetHouseSpecs(house); |
1686 hs = GetHouseSpecs(house); |
1687 |
1687 |
1688 if (HASBIT(_loaded_newgrf_features, GRFLOADED_NEWHOUSES)) { |
1688 if (_loaded_newgrf_features.has_newhouses) { |
1689 if (hs->override != 0) hs = GetHouseSpecs(hs->override); |
1689 if (hs->override != 0) hs = GetHouseSpecs(hs->override); |
1690 |
1690 |
1691 if ((hs->extra_flags & BUILDING_IS_HISTORICAL) && !_generating_world) continue; |
1691 if ((hs->extra_flags & BUILDING_IS_HISTORICAL) && !_generating_world) continue; |
1692 |
1692 |
1693 if (HASBIT(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) { |
1693 if (HASBIT(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) { |
1765 } |
1765 } |
1766 } |
1766 } |
1767 |
1767 |
1768 static bool BuildTownHouse(Town *t, TileIndex tile) |
1768 static bool BuildTownHouse(Town *t, TileIndex tile) |
1769 { |
1769 { |
1770 int32 r; |
1770 CommandCost r; |
1771 |
1771 |
1772 if (IsSteepSlope(GetTileSlope(tile, NULL))) return false; |
1772 if (IsSteepSlope(GetTileSlope(tile, NULL))) return false; |
1773 if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return false; |
1773 if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return false; |
1774 |
1774 |
1775 r = DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR); |
1775 r = DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR); |
1841 * @param tile unused |
1841 * @param tile unused |
1842 * @param flags type of operation |
1842 * @param flags type of operation |
1843 * @param p1 town ID to rename |
1843 * @param p1 town ID to rename |
1844 * @param p2 unused |
1844 * @param p2 unused |
1845 */ |
1845 */ |
1846 int32 CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1846 CommandCost CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1847 { |
1847 { |
1848 StringID str; |
1848 StringID str; |
1849 Town *t; |
1849 Town *t; |
1850 |
1850 |
1851 if (!IsValidTownID(p1) || _cmd_text[0] == '\0') return CMD_ERROR; |
1851 if (!IsValidTownID(p1) || _cmd_text[0] == '\0') return CMD_ERROR; |
1927 } |
1927 } |
1928 |
1928 |
1929 static bool DoBuildStatueOfCompany(TileIndex tile, TownID town_id) |
1929 static bool DoBuildStatueOfCompany(TileIndex tile, TownID town_id) |
1930 { |
1930 { |
1931 PlayerID old; |
1931 PlayerID old; |
1932 int32 r; |
1932 CommandCost r; |
1933 |
1933 |
1934 if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return false; |
1934 if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return false; |
1935 |
1935 |
1936 if (!IsTileType(tile, MP_HOUSE) && |
1936 if (!IsTileType(tile, MP_HOUSE) && |
1937 !IsTileType(tile, MP_CLEAR) && |
1937 !IsTileType(tile, MP_CLEAR) && |
2045 * @param tile unused |
2045 * @param tile unused |
2046 * @param flags type of operation |
2046 * @param flags type of operation |
2047 * @param p1 town to do the action at |
2047 * @param p1 town to do the action at |
2048 * @param p2 action to perform, @see _town_action_proc for the list of available actions |
2048 * @param p2 action to perform, @see _town_action_proc for the list of available actions |
2049 */ |
2049 */ |
2050 int32 CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2050 CommandCost CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2051 { |
2051 { |
2052 int32 cost; |
2052 CommandCost cost; |
2053 Town *t; |
2053 Town *t; |
2054 |
2054 |
2055 if (!IsValidTownID(p1) || p2 > lengthof(_town_action_proc)) return CMD_ERROR; |
2055 if (!IsValidTownID(p1) || p2 > lengthof(_town_action_proc)) return CMD_ERROR; |
2056 |
2056 |
2057 t = GetTown(p1); |
2057 t = GetTown(p1); |