Mercurial > hg > openttd
comparison src/station_cmd.cpp @ 6674:2a72960b1ec6 draft
(svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
author | maedhros <maedhros@openttd.org> |
---|---|
date | Wed, 23 May 2007 17:33:03 +0000 |
parents | d6b2f3c0cd3b |
children | 8451c7d3a664 |
comparison
equal
deleted
inserted
replaced
6673:b42a1e412f8e | 6674:2a72960b1ec6 |
---|---|
792 * @param flags operation to perform | 792 * @param flags operation to perform |
793 * @param p1 various bitstuffed elements | 793 * @param p1 various bitstuffed elements |
794 * - p1 = (bit 0) - orientation (Axis) | 794 * - p1 = (bit 0) - orientation (Axis) |
795 * - p1 = (bit 8-15) - number of tracks | 795 * - p1 = (bit 8-15) - number of tracks |
796 * - p1 = (bit 16-23) - platform length | 796 * - p1 = (bit 16-23) - platform length |
797 * - p1 = (bit 24) - allow stations directly adjacent to other stations. | |
797 * @param p2 various bitstuffed elements | 798 * @param p2 various bitstuffed elements |
798 * - p2 = (bit 0- 3) - railtype (p2 & 0xF) | 799 * - p2 = (bit 0- 3) - railtype (p2 & 0xF) |
799 * - p2 = (bit 8-15) - custom station class | 800 * - p2 = (bit 8-15) - custom station class |
800 * - p2 = (bit 16-23) - custom station id | 801 * - p2 = (bit 16-23) - custom station id |
801 */ | 802 */ |
836 // for detail info, see: https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 | 837 // for detail info, see: https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 |
837 ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _patches.nonuniform_stations ? &est : NULL); | 838 ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _patches.nonuniform_stations ? &est : NULL); |
838 if (CmdFailed(ret)) return ret; | 839 if (CmdFailed(ret)) return ret; |
839 int32 cost = ret + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len; | 840 int32 cost = ret + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len; |
840 | 841 |
841 // Make sure there are no similar stations around us. | 842 Station *st = NULL; |
842 Station *st = GetStationAround(tile_org, w_org, h_org, est); | 843 bool check_surrounding = true; |
843 if (st == CHECK_STATIONS_ERR) return CMD_ERROR; | 844 |
845 if (_patches.adjacent_stations) { | |
846 if (est != INVALID_STATION) { | |
847 if (HASBIT(p1, 24)) { | |
848 /* You can't build an adjacent station over the top of one that | |
849 * already exists. */ | |
850 return_cmd_error(STR_MUST_REMOVE_RAILWAY_STATION_FIRST); | |
851 } else { | |
852 /* Extend the current station, and don't check whether it will | |
853 * be near any other stations. */ | |
854 st = GetStation(est); | |
855 check_surrounding = false; | |
856 } | |
857 } else { | |
858 /* There's no station here. Don't check the tiles surrounding this | |
859 * one if the player wanted to build an adjacent station. */ | |
860 if (HASBIT(p1, 24)) check_surrounding = false; | |
861 } | |
862 } | |
863 | |
864 if (check_surrounding) { | |
865 // Make sure there are no similar stations around us. | |
866 st = GetStationAround(tile_org, w_org, h_org, est); | |
867 if (st == CHECK_STATIONS_ERR) return CMD_ERROR; | |
868 } | |
844 | 869 |
845 // See if there is a deleted station close to us. | 870 // See if there is a deleted station close to us. |
846 if (st == NULL) st = GetClosestStationFromTile(tile_org); | 871 if (st == NULL) st = GetClosestStationFromTile(tile_org); |
847 | 872 |
848 /* In case of new station if DC_EXEC is NOT set we still need to create the station | 873 /* In case of new station if DC_EXEC is NOT set we still need to create the station |
1213 * @param flags operation to perform | 1238 * @param flags operation to perform |
1214 * @param p1 entrance direction (DiagDirection) | 1239 * @param p1 entrance direction (DiagDirection) |
1215 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops | 1240 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops |
1216 * bit 1: 0 for normal, 1 for drive-through | 1241 * bit 1: 0 for normal, 1 for drive-through |
1217 * bit 2..4: the roadtypes | 1242 * bit 2..4: the roadtypes |
1243 * bit 5: allow stations directly adjacent to other stations. | |
1218 */ | 1244 */ |
1219 int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) | 1245 int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1220 { | 1246 { |
1221 bool type = HASBIT(p2, 0); | 1247 bool type = HASBIT(p2, 0); |
1222 bool is_drive_through = HASBIT(p2, 1); | 1248 bool is_drive_through = HASBIT(p2, 1); |
1253 int32 ret = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL); | 1279 int32 ret = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL); |
1254 _current_player = cur_owner; | 1280 _current_player = cur_owner; |
1255 if (CmdFailed(ret)) return ret; | 1281 if (CmdFailed(ret)) return ret; |
1256 int32 cost = build_over_road ? 0 : ret; // Don't add cost of clearing road when overbuilding | 1282 int32 cost = build_over_road ? 0 : ret; // Don't add cost of clearing road when overbuilding |
1257 | 1283 |
1258 Station *st = GetStationAround(tile, 1, 1, INVALID_STATION); | 1284 Station *st = NULL; |
1259 if (st == CHECK_STATIONS_ERR) return CMD_ERROR; | 1285 |
1286 if (!_patches.adjacent_stations || !HASBIT(p2, 5)) { | |
1287 st = GetStationAround(tile, 1, 1, INVALID_STATION); | |
1288 if (st == CHECK_STATIONS_ERR) return CMD_ERROR; | |
1289 } | |
1260 | 1290 |
1261 /* Find a station close to us */ | 1291 /* Find a station close to us */ |
1262 if (st == NULL) st = GetClosestStationFromTile(tile); | 1292 if (st == NULL) st = GetClosestStationFromTile(tile); |
1263 | 1293 |
1264 //give us a road stop in the list, and check if something went wrong | 1294 //give us a road stop in the list, and check if something went wrong |
1519 | 1549 |
1520 /** Place an Airport. | 1550 /** Place an Airport. |
1521 * @param tile tile where airport will be built | 1551 * @param tile tile where airport will be built |
1522 * @param flags operation to perform | 1552 * @param flags operation to perform |
1523 * @param p1 airport type, @see airport.h | 1553 * @param p1 airport type, @see airport.h |
1524 * @param p2 unused | 1554 * @param p2 (bit 0) - allow airports directly adjacent to other airports. |
1525 */ | 1555 */ |
1526 int32 CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) | 1556 int32 CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1527 { | 1557 { |
1528 bool airport_upgrade = true; | 1558 bool airport_upgrade = true; |
1529 | 1559 |
1557 | 1587 |
1558 int32 ret = CheckFlatLandBelow(tile, w, h, flags, 0, NULL); | 1588 int32 ret = CheckFlatLandBelow(tile, w, h, flags, 0, NULL); |
1559 if (CmdFailed(ret)) return ret; | 1589 if (CmdFailed(ret)) return ret; |
1560 int32 cost = ret; | 1590 int32 cost = ret; |
1561 | 1591 |
1562 Station *st = GetStationAround(tile, w, h, INVALID_STATION); | 1592 Station *st = NULL; |
1563 if (st == CHECK_STATIONS_ERR) return CMD_ERROR; | 1593 |
1594 if (!_patches.adjacent_stations || !HASBIT(p2, 0)) { | |
1595 st = GetStationAround(tile, w, h, INVALID_STATION); | |
1596 if (st == CHECK_STATIONS_ERR) return CMD_ERROR; | |
1597 } | |
1564 | 1598 |
1565 /* Find a station close to us */ | 1599 /* Find a station close to us */ |
1566 if (st == NULL) st = GetClosestStationFromTile(tile); | 1600 if (st == NULL) st = GetClosestStationFromTile(tile); |
1567 | 1601 |
1568 if (w > _patches.station_spread || h > _patches.station_spread) { | 1602 if (w > _patches.station_spread || h > _patches.station_spread) { |
1803 static const byte _dock_h_chk[4] = { 1, 2, 1, 2 }; | 1837 static const byte _dock_h_chk[4] = { 1, 2, 1, 2 }; |
1804 | 1838 |
1805 /** Build a dock/haven. | 1839 /** Build a dock/haven. |
1806 * @param tile tile where dock will be built | 1840 * @param tile tile where dock will be built |
1807 * @param flags operation to perform | 1841 * @param flags operation to perform |
1808 * @param p1 unused | 1842 * @param p1 (bit 0) - allow docks directly adjacent to other docks. |
1809 * @param p2 unused | 1843 * @param p2 unused |
1810 */ | 1844 */ |
1811 int32 CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) | 1845 int32 CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1812 { | 1846 { |
1813 int32 cost; | 1847 int32 cost; |
1845 if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) { | 1879 if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) { |
1846 return_cmd_error(STR_304B_SITE_UNSUITABLE); | 1880 return_cmd_error(STR_304B_SITE_UNSUITABLE); |
1847 } | 1881 } |
1848 | 1882 |
1849 /* middle */ | 1883 /* middle */ |
1850 Station *st = GetStationAround( | 1884 Station *st = NULL; |
1851 tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]), | 1885 |
1852 _dock_w_chk[direction], _dock_h_chk[direction], INVALID_STATION); | 1886 if (!_patches.adjacent_stations || !HASBIT(p1, 0)) { |
1853 if (st == CHECK_STATIONS_ERR) return CMD_ERROR; | 1887 st = GetStationAround( |
1888 tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]), | |
1889 _dock_w_chk[direction], _dock_h_chk[direction], INVALID_STATION); | |
1890 if (st == CHECK_STATIONS_ERR) return CMD_ERROR; | |
1891 } | |
1854 | 1892 |
1855 /* Find a station close to us */ | 1893 /* Find a station close to us */ |
1856 if (st == NULL) st = GetClosestStationFromTile(tile); | 1894 if (st == NULL) st = GetClosestStationFromTile(tile); |
1857 | 1895 |
1858 /* In case of new station if DC_EXEC is NOT set we still need to create the station | 1896 /* In case of new station if DC_EXEC is NOT set we still need to create the station |