comparison src/station_cmd.cpp @ 8520:c777304e2098 draft

(svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
author smatz <smatz@openttd.org>
date Sat, 09 Feb 2008 17:30:13 +0000
parents 0e4b2a37af1f
children 992fa65afba1
comparison
equal deleted inserted replaced
8519:0e4b2a37af1f 8520:c777304e2098
1463 rs_auto_delete.Detach(); 1463 rs_auto_delete.Detach();
1464 } 1464 }
1465 return cost; 1465 return cost;
1466 } 1466 }
1467 1467
1468
1469 static void *ClearRoadStopStatusEnum(Vehicle *v, void *)
1470 {
1471 if (v->type == VEH_ROAD) ClrBit(v->u.road.state, RVS_IN_DT_ROAD_STOP);
1472
1473 return NULL;
1474 }
1475
1476
1468 /** Remove a bus station 1477 /** Remove a bus station
1469 * @param st Station to remove 1478 * @param st Station to remove
1470 * @param flags operation to perform 1479 * @param flags operation to perform
1471 * @param tile TileIndex been queried 1480 * @param tile TileIndex been queried
1472 * @return cost or failure of operation 1481 * @return cost or failure of operation
1489 cur_stop = GetRoadStopByTile(tile, RoadStop::BUS); 1498 cur_stop = GetRoadStopByTile(tile, RoadStop::BUS);
1490 } 1499 }
1491 1500
1492 assert(cur_stop != NULL); 1501 assert(cur_stop != NULL);
1493 1502
1494 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; 1503 /* don't do the check for drive-through road stops when company bankrupts */
1504 if (IsDriveThroughStopTile(tile) && (flags & DC_BANKRUPT)) {
1505 /* remove the 'going through road stop' status from all vehicles on that tile */
1506 if (flags & DC_EXEC) VehicleFromPos(tile, NULL, &ClearRoadStopStatusEnum);
1507 } else {
1508 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
1509 }
1495 1510
1496 if (flags & DC_EXEC) { 1511 if (flags & DC_EXEC) {
1497 if (*primary_stop == cur_stop) { 1512 if (*primary_stop == cur_stop) {
1498 /* removed the first stop in the list */ 1513 /* removed the first stop in the list */
1499 *primary_stop = cur_stop->next; 1514 *primary_stop = cur_stop->next;
1903 if (!IsValidPlayer(_current_player)) return_cmd_error(INVALID_STRING_ID); 1918 if (!IsValidPlayer(_current_player)) return_cmd_error(INVALID_STRING_ID);
1904 1919
1905 TileIndex tile = st->dock_tile; 1920 TileIndex tile = st->dock_tile;
1906 1921
1907 if (HasStationInUse(st->index, INVALID_PLAYER)) return_cmd_error(STR_BUOY_IS_IN_USE); 1922 if (HasStationInUse(st->index, INVALID_PLAYER)) return_cmd_error(STR_BUOY_IS_IN_USE);
1908 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; 1923 /* remove the buoy if there is a ship on tile when company goes bankrupt... */
1924 if (!(flags & DC_BANKRUPT) && !EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
1909 1925
1910 if (flags & DC_EXEC) { 1926 if (flags & DC_EXEC) {
1911 st->dock_tile = 0; 1927 st->dock_tile = 0;
1912 /* Buoys are marked in the Station struct by this flag. Yes, it is this 1928 /* Buoys are marked in the Station struct by this flag. Yes, it is this
1913 * braindead.. */ 1929 * braindead.. */
2889 SetTileOwner(tile, new_player); 2905 SetTileOwner(tile, new_player);
2890 if (!IsBuoy(tile)) st->owner = new_player; // do not set st->owner for buoys 2906 if (!IsBuoy(tile)) st->owner = new_player; // do not set st->owner for buoys
2891 RebuildStationLists(); 2907 RebuildStationLists();
2892 InvalidateWindowClasses(WC_STATION_LIST); 2908 InvalidateWindowClasses(WC_STATION_LIST);
2893 } else { 2909 } else {
2894 if (IsDriveThroughStopTile(tile) && GetStopBuiltOnTownRoad(tile)) { 2910 if (IsDriveThroughStopTile(tile)) {
2895 /* For a drive-through stop on a town-owned road remove the stop and replace the road */ 2911 /* Remove the drive-through road stop */
2896 DoCommand(tile, 0, (GetStationType(tile) == STATION_TRUCK) ? RoadStop::TRUCK : RoadStop::BUS, DC_EXEC | DC_BANKRUPT, CMD_REMOVE_ROAD_STOP); 2912 DoCommand(tile, 0, (GetStationType(tile) == STATION_TRUCK) ? RoadStop::TRUCK : RoadStop::BUS, DC_EXEC | DC_BANKRUPT, CMD_REMOVE_ROAD_STOP);
2913 assert(IsTileType(tile, MP_ROAD));
2914 /* Change owner of tile and all roadtypes */
2915 ChangeTileOwner(tile, old_player, new_player);
2897 } else { 2916 } else {
2898 DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR); 2917 DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
2918 /* Set tile owner of water under (now removed) buoy and dock to OWNER_NONE.
2919 * Update owner of buoy if it was not removed (was in orders).
2920 * Do not update when owned by OWNER_WATER (sea and rivers). */
2921 if ((IsTileType(tile, MP_WATER) || IsBuoyTile(tile)) && IsTileOwner(tile, old_player)) SetTileOwner(tile, OWNER_NONE);
2899 } 2922 }
2900 } 2923 }
2901 } 2924 }
2902 2925
2903 /** 2926 /**