* 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 */
| 4500 | * @return the cost of this operation or an error and the station ID |
| 4501 | */ |
| 4502 | std::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 |
nothing calls this directly
no test coverage detected