75 #include "table/town_land.h" |
75 #include "table/town_land.h" |
76 |
76 |
77 |
77 |
78 static void TownDrawHouseLift(const TileInfo *ti) |
78 static void TownDrawHouseLift(const TileInfo *ti) |
79 { |
79 { |
80 AddChildSpriteScreen(0x5A3, 0xE, 0x3C - GB(_m[ti->tile].m1, 0, 7)); |
80 AddChildSpriteScreen(SPR_LIFT, 14, 60 - GB(_m[ti->tile].m1, 0, 7)); |
81 } |
81 } |
82 |
82 |
83 typedef void TownDrawTileProc(const TileInfo *ti); |
83 typedef void TownDrawTileProc(const TileInfo *ti); |
84 static TownDrawTileProc * const _town_draw_tile_procs[1] = { |
84 static TownDrawTileProc * const _town_draw_tile_procs[1] = { |
85 TownDrawHouseLift |
85 TownDrawHouseLift |
1019 * @param p2 unused |
1019 * @param p2 unused |
1020 */ |
1020 */ |
1021 int32 CmdBuildTown(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1021 int32 CmdBuildTown(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1022 { |
1022 { |
1023 TileIndex tile = TileVirtXY(x, y); |
1023 TileIndex tile = TileVirtXY(x, y); |
1024 TileInfo ti; |
|
1025 Town *t; |
1024 Town *t; |
1026 uint32 townnameparts; |
1025 uint32 townnameparts; |
1027 |
1026 |
1028 /* Only in the scenario editor */ |
1027 /* Only in the scenario editor */ |
1029 if (_game_mode != GM_EDITOR) return CMD_ERROR; |
1028 if (_game_mode != GM_EDITOR) return CMD_ERROR; |
1033 // Check if too close to the edge of map |
1032 // Check if too close to the edge of map |
1034 if (DistanceFromEdge(tile) < 12) |
1033 if (DistanceFromEdge(tile) < 12) |
1035 return_cmd_error(STR_0237_TOO_CLOSE_TO_EDGE_OF_MAP); |
1034 return_cmd_error(STR_0237_TOO_CLOSE_TO_EDGE_OF_MAP); |
1036 |
1035 |
1037 // Can only build on clear flat areas. |
1036 // Can only build on clear flat areas. |
1038 FindLandscapeHeightByTile(&ti, tile); |
1037 if (!IsTileType(tile, MP_CLEAR) || GetTileSlope(tile, NULL) != 0) { |
1039 if (ti.type != MP_CLEAR || ti.tileh != 0) |
|
1040 return_cmd_error(STR_0239_SITE_UNSUITABLE); |
1038 return_cmd_error(STR_0239_SITE_UNSUITABLE); |
|
1039 } |
1041 |
1040 |
1042 // Check distance to all other towns. |
1041 // Check distance to all other towns. |
1043 if (IsCloseToTown(tile, 20)) |
1042 if (IsCloseToTown(tile, 20)) |
1044 return_cmd_error(STR_0238_TOO_CLOSE_TO_ANOTHER_TOWN); |
1043 return_cmd_error(STR_0238_TOO_CLOSE_TO_ANOTHER_TOWN); |
1045 |
1044 |
1061 } |
1060 } |
1062 |
1061 |
1063 Town *CreateRandomTown(uint attempts) |
1062 Town *CreateRandomTown(uint attempts) |
1064 { |
1063 { |
1065 TileIndex tile; |
1064 TileIndex tile; |
1066 TileInfo ti; |
|
1067 Town *t; |
1065 Town *t; |
1068 uint32 townnameparts; |
1066 uint32 townnameparts; |
1069 |
1067 |
1070 do { |
1068 do { |
1071 // Generate a tile index not too close from the edge |
1069 // Generate a tile index not too close from the edge |
1072 tile = RandomTile(); |
1070 tile = RandomTile(); |
1073 if (DistanceFromEdge(tile) < 20) continue; |
1071 if (DistanceFromEdge(tile) < 20) continue; |
1074 |
1072 |
1075 // Make sure the tile is plain |
1073 // Make sure the tile is plain |
1076 FindLandscapeHeightByTile(&ti, tile); |
1074 if (!IsTileType(tile, MP_CLEAR) || GetTileSlope(tile, NULL) != 0) continue; |
1077 if (ti.type != MP_CLEAR || ti.tileh != 0) |
|
1078 continue; |
|
1079 |
1075 |
1080 // Check not too close to a town |
1076 // Check not too close to a town |
1081 if (IsCloseToTown(tile, 20)) continue; |
1077 if (IsCloseToTown(tile, 20)) continue; |
1082 |
1078 |
1083 // Get a unique name for the town. |
1079 // Get a unique name for the town. |
1560 NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_GENERAL, 0), t->xy, 0); |
1556 NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_GENERAL, 0), t->xy, 0); |
1561 } |
1557 } |
1562 |
1558 |
1563 static bool DoBuildStatueOfCompany(TileIndex tile) |
1559 static bool DoBuildStatueOfCompany(TileIndex tile) |
1564 { |
1560 { |
1565 TileInfo ti; |
|
1566 PlayerID old; |
1561 PlayerID old; |
1567 int32 r; |
1562 int32 r; |
1568 |
1563 |
1569 FindLandscapeHeightByTile(&ti, tile); |
1564 if (GetTileSlope(tile, NULL) != 0) return false; |
1570 if (ti.tileh != 0) return false; |
1565 |
1571 |
1566 if (!IsTileType(tile, MP_HOUSE) && |
1572 if (ti.type != MP_HOUSE && ti.type != MP_CLEAR && ti.type != MP_TREES) |
1567 !IsTileType(tile, MP_CLEAR) && |
|
1568 !IsTileType(tile, MP_TREES)) { |
1573 return false; |
1569 return false; |
1574 |
1570 } |
1575 |
1571 |
1576 old = _current_player; |
1572 old = _current_player; |
1577 _current_player = OWNER_NONE; |
1573 _current_player = OWNER_NONE; |
1578 r = DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
1574 r = DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
1579 _current_player = old; |
1575 _current_player = old; |