MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CmdRenameWaypoint

Function CmdRenameWaypoint

src/waypoint_cmd.cpp:585–612  ·  view source on GitHub ↗

* 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 */

Source from the content-addressed store, hash-verified

583 * @return the cost of this operation or an error
584 */
585CommandCost 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.

Callers

nothing calls this directly

Calls 9

CheckOwnershipFunction · 0.85
Utf8StringLengthFunction · 0.85
IsUniqueWaypointNameFunction · 0.85
CommandCostClass · 0.85
FailedMethod · 0.80
TestMethod · 0.80
emptyMethod · 0.45
clearMethod · 0.45
UpdateVirtCoordMethod · 0.45

Tested by

no test coverage detected