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

Function CmdMoveWaypointName

src/waypoint_cmd.cpp:621–651  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

619 * @return the cost of this operation or an error and the waypoint ID
620 */
621std::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

Callers

nothing calls this directly

Calls 11

InvalidFunction · 0.85
CheckOwnershipFunction · 0.85
TileXFunction · 0.85
TileYFunction · 0.85
CommandCostClass · 0.85
ForAllStationsRadiusFunction · 0.85
FailedMethod · 0.80
PtInExtendedRectMethod · 0.80
TestMethod · 0.80
MoveSignMethod · 0.45
UpdateVirtCoordMethod · 0.45

Tested by

no test coverage detected