--- a/src/group_cmd.cpp Wed Jun 27 20:40:20 2007 +0000
+++ b/src/group_cmd.cpp Wed Jun 27 20:53:25 2007 +0000
@@ -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 @@
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 @@
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;