Mercurial > hg > openttd
diff src/group_cmd.cpp @ 7097:5c2889ace3ac draft
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
author | peter1138 <peter1138@openttd.org> |
---|---|
date | Wed, 27 Jun 2007 20:53:25 +0000 (2007-06-27) |
parents | d97197a65ab7 |
children | cade19792c8f |
line wrap: on
line diff
--- 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 @@ 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;