1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Do not allow duplicate ride names

This commit is contained in:
Ted John
2019-07-21 13:19:24 +01:00
parent f8b08b334e
commit 1d4c1958dd
3 changed files with 21 additions and 18 deletions

View File

@@ -59,21 +59,12 @@ public:
return std::make_unique<GameActionResult>(GA_ERROR::INVALID_PARAMETERS, STR_CANT_RENAME_RIDE_ATTRACTION, STR_NONE);
}
if (_name.empty())
if (!_name.empty() && Ride::NameExists(_name, ride->id))
{
return std::make_unique<GameActionResult>(
GA_ERROR::INVALID_PARAMETERS, STR_CANT_RENAME_RIDE_ATTRACTION, STR_INVALID_RIDE_ATTRACTION_NAME);
GA_ERROR::INVALID_PARAMETERS, STR_CANT_RENAME_RIDE_ATTRACTION, STR_ERROR_EXISTING_NAME);
}
rct_string_id newUserStringId = user_string_allocate(
USER_STRING_HIGH_ID_NUMBER | USER_STRING_DUPLICATION_PERMITTED, _name.c_str());
if (newUserStringId == 0)
{
// TODO: Probably exhausted, introduce new error.
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_CANT_RENAME_RIDE_ATTRACTION, STR_NONE);
}
user_string_free(newUserStringId);
return std::make_unique<GameActionResult>();
}
@@ -86,7 +77,14 @@ public:
return std::make_unique<GameActionResult>(GA_ERROR::INVALID_PARAMETERS, STR_CANT_RENAME_RIDE_ATTRACTION, STR_NONE);
}
ride->custom_name = _name;
if (_name.empty())
{
ride->SetNameToDefault();
}
else
{
ride->custom_name = _name;
}
scrolling_text_invalidate();
gfx_invalidate_screen();

View File

@@ -5734,7 +5734,7 @@ static bool ride_with_colour_config_exists(uint8_t ride_type, const TrackColour*
return false;
}
static bool ride_name_exists(char* name)
bool Ride::NameExists(const std::string_view& name, ride_id_t excludeRideId)
{
char buffer[256]{};
uint32_t formatArgs[32]{};
@@ -5743,11 +5743,14 @@ static bool ride_name_exists(char* name)
int32_t i;
FOR_ALL_RIDES (i, ride)
{
ride->FormatNameTo(formatArgs);
format_string(buffer, 256, STR_STRINGID, formatArgs);
if ((strcmp(buffer, name) == 0) && ride_has_any_track_elements(ride))
if (i != excludeRideId)
{
return true;
ride->FormatNameTo(formatArgs);
format_string(buffer, 256, STR_STRINGID, formatArgs);
if (std::string_view(buffer) == name && ride_has_any_track_elements(ride))
{
return true;
}
}
}
return false;
@@ -5833,13 +5836,14 @@ void Ride::SetNameToDefault()
uint8_t rideNameArgs[32]{};
// Increment default name number until we find a unique name
custom_name = {};
default_name_number = 0;
do
{
default_name_number++;
FormatNameTo(rideNameArgs);
format_string(rideNameBuffer, 256, STR_STRINGID, &rideNameArgs);
} while (ride_name_exists(rideNameBuffer));
} while (Ride::NameExists(rideNameBuffer, id));
}
/**

View File

@@ -414,6 +414,7 @@ public:
void FormatStatusTo(void* args) const;
static void UpdateAll();
static bool NameExists(const std::string_view& name, ride_id_t excludeRideId = RIDE_ID_NULL);
};
#pragma pack(push, 1)