* Move a waypoint name. * @param flags type of operation * @param waypoint_id id of waypoint * @param tile to move the waypoint name to * @return the cost of this operation or an error and the waypoint ID */
| 619 | * @return the cost of this operation or an error and the waypoint ID |
| 620 | */ |
| 621 | std::tuple<CommandCost, StationID> CmdMoveWaypointName(DoCommandFlags flags, StationID waypoint_id, TileIndex tile) |
| 622 | { |
| 623 | Waypoint *wp = Waypoint::GetIfValid(waypoint_id); |
| 624 | if (wp == nullptr) return { CMD_ERROR, StationID::Invalid() }; |
| 625 | |
| 626 | if (wp->owner != OWNER_NONE) { |
| 627 | CommandCost ret = CheckOwnership(wp->owner); |
| 628 | if (ret.Failed()) return { ret, StationID::Invalid() }; |
| 629 | } |
| 630 | |
| 631 | const StationRect *r = &wp->rect; |
| 632 | if (!r->PtInExtendedRect(TileX(tile), TileY(tile))) { |
| 633 | return { CommandCost(STR_ERROR_SITE_UNSUITABLE), StationID::Invalid() }; |
| 634 | } |
| 635 | |
| 636 | bool other_station = false; |
| 637 | /* Check if the tile is the base tile of another station */ |
| 638 | ForAllStationsRadius(tile, 0, [&](BaseStation *st) { |
| 639 | if (st != nullptr) { |
| 640 | if (st != wp && st->xy == tile) other_station = true; |
| 641 | } |
| 642 | }); |
| 643 | if (other_station) return { CommandCost(STR_ERROR_SITE_UNSUITABLE), StationID::Invalid() }; |
| 644 | |
| 645 | if (flags.Test(DoCommandFlag::Execute)) { |
| 646 | wp->MoveSign(tile); |
| 647 | |
| 648 | wp->UpdateVirtCoord(); |
| 649 | } |
| 650 | return { CommandCost(), waypoint_id }; |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * Callback function that is called after a name is moved |
nothing calls this directly
no test coverage detected