* Rename a waypoint. * @param flags type of operation * @param waypoint_id id of waypoint * @param text the new name or an empty string when resetting to the default * @return the cost of this operation or an error */
| 583 | * @return the cost of this operation or an error |
| 584 | */ |
| 585 | CommandCost CmdRenameWaypoint(DoCommandFlags flags, StationID waypoint_id, const std::string &text) |
| 586 | { |
| 587 | Waypoint *wp = Waypoint::GetIfValid(waypoint_id); |
| 588 | if (wp == nullptr) return CMD_ERROR; |
| 589 | |
| 590 | if (wp->owner != OWNER_NONE) { |
| 591 | CommandCost ret = CheckOwnership(wp->owner); |
| 592 | if (ret.Failed()) return ret; |
| 593 | } |
| 594 | |
| 595 | bool reset = text.empty(); |
| 596 | |
| 597 | if (!reset) { |
| 598 | if (Utf8StringLength(text) >= MAX_LENGTH_STATION_NAME_CHARS) return CMD_ERROR; |
| 599 | if (!IsUniqueWaypointName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE); |
| 600 | } |
| 601 | |
| 602 | if (flags.Test(DoCommandFlag::Execute)) { |
| 603 | if (reset) { |
| 604 | wp->name.clear(); |
| 605 | } else { |
| 606 | wp->name = text; |
| 607 | } |
| 608 | |
| 609 | wp->UpdateVirtCoord(); |
| 610 | } |
| 611 | return CommandCost(); |
| 612 | } |
| 613 | |
| 614 | /** |
| 615 | * Move a waypoint name. |
nothing calls this directly
no test coverage detected