* Remove a road waypoint * @param tile TileIndex been queried * @param flags operation to perform * @param replacement_spec_index replacement spec index to avoid deallocating, if < 0, tile is not being replaced * @return cost or failure of operation */
| 2354 | * @return cost or failure of operation |
| 2355 | */ |
| 2356 | CommandCost RemoveRoadWaypointStop(TileIndex tile, DoCommandFlags flags, int replacement_spec_index) |
| 2357 | { |
| 2358 | Waypoint *wp = Waypoint::GetByTile(tile); |
| 2359 | |
| 2360 | if (_current_company != OWNER_WATER) { |
| 2361 | CommandCost ret = CheckOwnership(wp->owner); |
| 2362 | if (ret.Failed()) return ret; |
| 2363 | } |
| 2364 | |
| 2365 | /* Ignore vehicles when the company goes bankrupt. The road will remain, any vehicles going to the waypoint will be removed. */ |
| 2366 | if (!flags.Test(DoCommandFlag::Bankrupt)) { |
| 2367 | CommandCost ret = EnsureNoVehicleOnGround(tile); |
| 2368 | if (ret.Failed()) return ret; |
| 2369 | } |
| 2370 | |
| 2371 | const RoadStopSpec *spec = GetRoadStopSpec(tile); |
| 2372 | |
| 2373 | if (flags.Test(DoCommandFlag::Execute)) { |
| 2374 | /* Update company infrastructure counts. */ |
| 2375 | for (RoadTramType rtt : _roadtramtypes) { |
| 2376 | RoadType rt = GetRoadType(tile, rtt); |
| 2377 | UpdateCompanyRoadInfrastructure(rt, GetRoadOwner(tile, rtt), -static_cast<int>(ROAD_STOP_TRACKBIT_FACTOR)); |
| 2378 | } |
| 2379 | |
| 2380 | Company::Get(wp->owner)->infrastructure.station--; |
| 2381 | DirtyCompanyInfrastructureWindows(wp->owner); |
| 2382 | |
| 2383 | uint specindex = GetCustomRoadStopSpecIndex(tile); |
| 2384 | |
| 2385 | DeleteNewGRFInspectWindow(GSF_ROADSTOPS, tile.base()); |
| 2386 | |
| 2387 | DoClearSquare(tile); |
| 2388 | |
| 2389 | wp->rect.AfterRemoveTile(wp, tile); |
| 2390 | |
| 2391 | wp->RemoveRoadStopTileData(tile); |
| 2392 | if ((int)specindex != replacement_spec_index) DeallocateSpecFromRoadStop(wp, specindex); |
| 2393 | |
| 2394 | if (replacement_spec_index < 0) { |
| 2395 | MakeRoadWaypointStationAreaSmaller(wp, wp->road_waypoint_area); |
| 2396 | |
| 2397 | UpdateStationSignCoord(wp); |
| 2398 | |
| 2399 | /* if we deleted the whole waypoint, delete the road facility. */ |
| 2400 | if (wp->road_waypoint_area.tile == INVALID_TILE) { |
| 2401 | wp->facilities.Reset({StationFacility::BusStop, StationFacility::TruckStop}); |
| 2402 | SetWindowWidgetDirty(WC_STATION_VIEW, wp->index, WID_SV_ROADVEHS); |
| 2403 | wp->UpdateVirtCoord(); |
| 2404 | DeleteStationIfEmpty(wp); |
| 2405 | } |
| 2406 | } |
| 2407 | } |
| 2408 | |
| 2409 | return CommandCost(EXPENSES_CONSTRUCTION, spec != nullptr ? spec->GetClearCost(PR_CLEAR_STATION_TRUCK) : _price[PR_CLEAR_STATION_TRUCK]); |
| 2410 | } |
| 2411 | |
| 2412 | /** |
| 2413 | * Remove a tile area of road stop or road waypoints |
no test coverage detected