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

Function CmdMoveStationName

src/station_cmd.cpp:4502–4532  ·  view source on GitHub ↗

* Move a station name. * @param flags type of operation * @param station_id id of the station * @param tile to move the station name to * @return the cost of this operation or an error and the station ID */

Source from the content-addressed store, hash-verified

4500 * @return the cost of this operation or an error and the station ID
4501 */
4502std::tuple<CommandCost, StationID> CmdMoveStationName(DoCommandFlags flags, StationID station_id, TileIndex tile)
4503{
4504 Station *st = Station::GetIfValid(station_id);
4505 if (st == nullptr) return { CMD_ERROR, StationID::Invalid() };
4506
4507 if (st->owner != OWNER_NONE) {
4508 CommandCost ret = CheckOwnership(st->owner);
4509 if (ret.Failed()) return { ret, StationID::Invalid() };
4510 }
4511
4512 const StationRect *r = &st->rect;
4513 if (!r->PtInExtendedRect(TileX(tile), TileY(tile))) {
4514 return { CommandCost(STR_ERROR_SITE_UNSUITABLE), StationID::Invalid() };
4515 }
4516
4517 bool other_station = false;
4518 /* Check if the tile is the base tile of another station */
4519 ForAllStationsRadius(tile, 0, [&](BaseStation *s) {
4520 if (s != nullptr) {
4521 if (s != st && s->xy == tile) other_station = true;
4522 }
4523 });
4524 if (other_station) return { CommandCost(STR_ERROR_SITE_UNSUITABLE), StationID::Invalid() };
4525
4526 if (flags.Test(DoCommandFlag::Execute)) {
4527 st->MoveSign(tile);
4528
4529 st->UpdateVirtCoord();
4530 }
4531 return { CommandCost(), station_id };
4532}
4533
4534/**
4535* 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