Mercurial > hg > openttd
comparison 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 |
parents | d97197a65ab7 |
children | cade19792c8f |
comparison
equal
deleted
inserted
replaced
7096:c1b9f000066e | 7097:5c2889ace3ac |
---|---|
2 | 2 |
3 /** @file group_cmd.cpp Handling of the engine groups */ | 3 /** @file group_cmd.cpp Handling of the engine groups */ |
4 | 4 |
5 #include "stdafx.h" | 5 #include "stdafx.h" |
6 #include "openttd.h" | 6 #include "openttd.h" |
7 #include "variables.h" | |
7 #include "functions.h" | 8 #include "functions.h" |
8 #include "player.h" | 9 #include "player.h" |
9 #include "table/strings.h" | 10 #include "table/strings.h" |
10 #include "command.h" | 11 #include "command.h" |
11 #include "vehicle.h" | 12 #include "vehicle.h" |
15 #include "train.h" | 16 #include "train.h" |
16 #include "aircraft.h" | 17 #include "aircraft.h" |
17 #include "string.h" | 18 #include "string.h" |
18 #include "window.h" | 19 #include "window.h" |
19 #include "vehicle_gui.h" | 20 #include "vehicle_gui.h" |
21 #include "strings.h" | |
20 | 22 |
21 /** | 23 /** |
22 * Update the num engines of a groupID. Decrease the old one and increase the new one | 24 * Update the num engines of a groupID. Decrease the old one and increase the new one |
23 * @note called in SetTrainGroupID and UpdateTrainGroupID | 25 * @note called in SetTrainGroupID and UpdateTrainGroupID |
24 * @param i EngineID we have to update | 26 * @param i EngineID we have to update |
157 } | 159 } |
158 | 160 |
159 return CommandCost(); | 161 return CommandCost(); |
160 } | 162 } |
161 | 163 |
164 static bool IsUniqueGroupName(const char *name) | |
165 { | |
166 const Group *g; | |
167 char buf[512]; | |
168 | |
169 FOR_ALL_GROUPS(g) { | |
170 SetDParam(0, g->index); | |
171 GetString(buf, STR_GROUP_NAME, lastof(buf)); | |
172 if (strcmp(buf, name) == 0) return false; | |
173 } | |
174 | |
175 return true; | |
176 } | |
162 | 177 |
163 /** | 178 /** |
164 * Rename a group | 179 * Rename a group |
165 * @param tile unused | 180 * @param tile unused |
166 * @param p1 index of array group | 181 * @param p1 index of array group |
171 { | 186 { |
172 if (!IsValidGroupID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; | 187 if (!IsValidGroupID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; |
173 | 188 |
174 Group *g = GetGroup(p1); | 189 Group *g = GetGroup(p1); |
175 if (g->owner != _current_player) return CMD_ERROR; | 190 if (g->owner != _current_player) return CMD_ERROR; |
191 | |
192 if (!IsUniqueGroupName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); | |
176 | 193 |
177 /* Create the name */ | 194 /* Create the name */ |
178 StringID str = AllocateName(_cmd_text, 0); | 195 StringID str = AllocateName(_cmd_text, 0); |
179 if (str == STR_NULL) return CMD_ERROR; | 196 if (str == STR_NULL) return CMD_ERROR; |
180 | 197 |