summaryrefslogtreecommitdiff
path: root/src/group_cmd.cpp
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-06-27 20:53:25 +0000
committerpeter1138 <peter1138@openttd.org>2007-06-27 20:53:25 +0000
commitc692d897cd1bdeb8d4e00349519a460fcdd2c262 (patch)
treee2ac06c3a62de5b5f8411541f83536ef20f32ee0 /src/group_cmd.cpp
parentde357c74c1ac4df582f32849bfbc5681c3552171 (diff)
downloadopenttd-c692d897cd1bdeb8d4e00349519a460fcdd2c262.tar.xz
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
Diffstat (limited to 'src/group_cmd.cpp')
-rw-r--r--src/group_cmd.cpp17
1 files changed, 17 insertions, 0 deletions
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;