Allow generating new default name for station
Ctrl-click default button in rename station query window
This commit is contained in:
@@ -236,7 +236,7 @@ static bool FindNearIndustryName(TileIndex tile, void *user_data)
|
|||||||
return !sni->indtypes[indtype];
|
return !sni->indtypes[indtype];
|
||||||
}
|
}
|
||||||
|
|
||||||
static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming name_class)
|
static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming name_class, bool force_change = false)
|
||||||
{
|
{
|
||||||
static const uint32 _gen_station_name_bits[] = {
|
static const uint32 _gen_station_name_bits[] = {
|
||||||
0, // STATIONNAMING_RAIL
|
0, // STATIONNAMING_RAIL
|
||||||
@@ -256,7 +256,7 @@ static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming n
|
|||||||
std::bitset<MAX_EXTRA_STATION_NAMES> extra_names;
|
std::bitset<MAX_EXTRA_STATION_NAMES> extra_names;
|
||||||
|
|
||||||
for (const Station *s : Station::Iterate()) {
|
for (const Station *s : Station::Iterate()) {
|
||||||
if (s != st && s->town == t) {
|
if ((force_change || s != st) && s->town == t) {
|
||||||
if (s->indtype != IT_INVALID) {
|
if (s->indtype != IT_INVALID) {
|
||||||
indtypes[s->indtype] = true;
|
indtypes[s->indtype] = true;
|
||||||
StringID name = GetIndustrySpec(s->indtype)->station_name;
|
StringID name = GetIndustrySpec(s->indtype)->station_name;
|
||||||
@@ -282,6 +282,8 @@ static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming n
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
st->extra_name_index = UINT16_MAX;
|
||||||
|
|
||||||
TileIndex indtile = tile;
|
TileIndex indtile = tile;
|
||||||
StationNameInformation sni = { free_names, indtypes };
|
StationNameInformation sni = { free_names, indtypes };
|
||||||
if (CircularTileSearch(&indtile, 7, FindNearIndustryName, &sni)) {
|
if (CircularTileSearch(&indtile, 7, FindNearIndustryName, &sni)) {
|
||||||
@@ -4727,7 +4729,8 @@ static bool IsUniqueStationName(const char *name)
|
|||||||
* @param tile unused
|
* @param tile unused
|
||||||
* @param flags operation to perform
|
* @param flags operation to perform
|
||||||
* @param p1 station ID that is to be renamed
|
* @param p1 station ID that is to be renamed
|
||||||
* @param p2 unused
|
* @param p2 various bitstuffed elements
|
||||||
|
* - p2 = (bit 0) - whether to generate a new default name, if resetting name
|
||||||
* @param text the new name or an empty string when resetting to the default
|
* @param text the new name or an empty string when resetting to the default
|
||||||
* @return the cost of this operation or an error
|
* @return the cost of this operation or an error
|
||||||
*/
|
*/
|
||||||
@@ -4750,6 +4753,22 @@ CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
|||||||
st->cached_name.clear();
|
st->cached_name.clear();
|
||||||
if (reset) {
|
if (reset) {
|
||||||
st->name.clear();
|
st->name.clear();
|
||||||
|
if (HasBit(p2, 0) && st->industry == nullptr) {
|
||||||
|
StationNaming name_class;
|
||||||
|
if (st->facilities & FACIL_AIRPORT) {
|
||||||
|
name_class = STATIONNAMING_AIRPORT;
|
||||||
|
} else if (st->facilities & FACIL_DOCK) {
|
||||||
|
name_class = STATIONNAMING_DOCK;
|
||||||
|
} else if (st->facilities & FACIL_TRAIN) {
|
||||||
|
name_class = STATIONNAMING_RAIL;
|
||||||
|
} else if (st->facilities & (FACIL_BUS_STOP | FACIL_TRUCK_STOP)) {
|
||||||
|
name_class = STATIONNAMING_ROAD;
|
||||||
|
} else {
|
||||||
|
name_class = STATIONNAMING_RAIL;
|
||||||
|
}
|
||||||
|
Random(); // Advance random seed each time this is called
|
||||||
|
st->string_id = GenerateStationName(st, st->xy, name_class, true);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
st->name = text;
|
st->name = text;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2224,7 +2224,7 @@ struct StationViewWindow : public Window {
|
|||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (str == nullptr) return;
|
||||||
|
|
||||||
DoCommandP(0, this->window_number, 0, CMD_RENAME_STATION | CMD_MSG(STR_ERROR_CAN_T_RENAME_STATION), nullptr, str);
|
DoCommandP(0, this->window_number, _ctrl_pressed ? 1 : 0, CMD_RENAME_STATION | CMD_MSG(STR_ERROR_CAN_T_RENAME_STATION), nullptr, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnResize() override
|
void OnResize() override
|
||||||
|
|||||||
Reference in New Issue
Block a user