(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
This commit is contained in:
@@ -171,18 +171,22 @@ static bool IsUniqueGroupName(const char *name)
|
||||
CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
if (!IsValidGroupID(p1)) return CMD_ERROR;
|
||||
if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_GROUP_NAME_BYTES) return CMD_ERROR;
|
||||
|
||||
Group *g = GetGroup(p1);
|
||||
if (g->owner != _current_player) return CMD_ERROR;
|
||||
|
||||
if (!IsUniqueGroupName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
|
||||
bool reset = StrEmpty(_cmd_text);
|
||||
|
||||
if (!reset) {
|
||||
if (strlen(_cmd_text) >= MAX_LENGTH_GROUP_NAME_BYTES) return CMD_ERROR;
|
||||
if (!IsUniqueGroupName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
/* Delete the old name */
|
||||
free(g->name);
|
||||
/* Assign the new one */
|
||||
g->name = strdup(_cmd_text);
|
||||
g->name = reset ? NULL : strdup(_cmd_text);
|
||||
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player);
|
||||
}
|
||||
|
Reference in New Issue
Block a user