From c692d897cd1bdeb8d4e00349519a460fcdd2c262 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Wed, 27 Jun 2007 20:53:25 +0000 Subject: (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type. --- src/group_cmd.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/group_cmd.cpp') diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index 7505d63b5..782324799 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -4,6 +4,7 @@ #include "stdafx.h" #include "openttd.h" +#include "variables.h" #include "functions.h" #include "player.h" #include "table/strings.h" @@ -17,6 +18,7 @@ #include "string.h" #include "window.h" #include "vehicle_gui.h" +#include "strings.h" /** * Update the num engines of a groupID. Decrease the old one and increase the new one @@ -159,6 +161,19 @@ CommandCost CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) return CommandCost(); } +static bool IsUniqueGroupName(const char *name) +{ + const Group *g; + char buf[512]; + + FOR_ALL_GROUPS(g) { + SetDParam(0, g->index); + GetString(buf, STR_GROUP_NAME, lastof(buf)); + if (strcmp(buf, name) == 0) return false; + } + + return true; +} /** * Rename a group @@ -174,6 +189,8 @@ CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) Group *g = GetGroup(p1); if (g->owner != _current_player) return CMD_ERROR; + if (!IsUniqueGroupName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + /* Create the name */ StringID str = AllocateName(_cmd_text, 0); if (str == STR_NULL) return CMD_ERROR; -- cgit v1.2.3-54-g00ecf