Feature: Signs, waypoint and station names may be moved (#14744)

This commit is contained in:
mmtunligit
2025-11-24 20:56:19 +01:00
committed by GitHub
parent f128d0de1d
commit 07177467b3
19 changed files with 380 additions and 28 deletions

View File

@@ -29,6 +29,7 @@
#include "road_internal.h" /* For drawing catenary/checking road removal */
#include "autoslope.h"
#include "water.h"
#include "tilehighlight_func.h"
#include "strings_func.h"
#include "clear_func.h"
#include "timer/timer_game_calendar.h"
@@ -71,6 +72,7 @@
#include "station_layout_type.h"
#include "widgets/station_widget.h"
#include "widgets/misc_widget.h"
#include "table/strings.h"
#include "table/station_land.h"
@@ -4475,6 +4477,59 @@ CommandCost CmdRenameStation(DoCommandFlags flags, StationID station_id, const s
return CommandCost();
}
/**
* 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
*/
std::tuple<CommandCost, StationID> CmdMoveStationName(DoCommandFlags flags, StationID station_id, TileIndex tile)
{
Station *st = Station::GetIfValid(station_id);
if (st == nullptr) return { CMD_ERROR, StationID::Invalid() };
if (st->owner != OWNER_NONE) {
CommandCost ret = CheckOwnership(st->owner);
if (ret.Failed()) return { ret, StationID::Invalid() };
}
const StationRect *r = &st->rect;
if (!r->PtInExtendedRect(TileX(tile), TileY(tile))) {
return { CommandCost(STR_ERROR_SITE_UNSUITABLE), StationID::Invalid() };
}
bool other_station = false;
/* Check if the tile is the base tile of another station */
ForAllStationsRadius(tile, 0, [&](BaseStation *s) {
if (s != nullptr) {
if (s != st && s->xy == tile) other_station = true;
}
});
if (other_station) return { CommandCost(STR_ERROR_SITE_UNSUITABLE), StationID::Invalid() };
if (flags.Test(DoCommandFlag::Execute)) {
st->MoveSign(tile);
st->UpdateVirtCoord();
}
return { CommandCost(), station_id };
}
/**
* Callback function that is called after a name is moved
* @param result of the operation
* @param station_id ID of the changed station
*/
void CcMoveStationName(Commands, const CommandCost &result, StationID station_id)
{
if (result.Failed()) return;
ResetObjectToPlace();
Station *st = Station::Get(station_id);
SetViewportStationRect(st, false);
}
static void AddNearbyStationsByCatchment(TileIndex tile, StationList &stations, StationList &nearby)
{
for (Station *st : nearby) {