summaryrefslogtreecommitdiff
path: root/src/waypoint.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/waypoint.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/waypoint.cpp')
-rw-r--r--src/waypoint.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/waypoint.cpp b/src/waypoint.cpp
index c621bd71e..6b81cff41 100644
--- a/src/waypoint.cpp
+++ b/src/waypoint.cpp
@@ -24,6 +24,8 @@
#include "yapf/yapf.h"
#include "date.h"
#include "newgrf.h"
+#include "string.h"
+#include "strings.h"
enum {
MAX_WAYPOINTS_PER_TOWN = 64,
@@ -341,6 +343,20 @@ CommandCost CmdRemoveTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint
return RemoveTrainWaypoint(tile, flags, true);
}
+static bool IsUniqueWaypointName(const char *name)
+{
+ const Waypoint *wp;
+ char buf[512];
+
+ FOR_ALL_WAYPOINTS(wp) {
+ SetDParam(0, wp->index);
+ GetString(buf, STR_WAYPOINT_RAW, lastof(buf));
+ if (strcmp(buf, name) == 0) return false;
+ }
+
+ return true;
+}
+
/**
* Rename a waypoint.
* @param tile unused
@@ -355,8 +371,10 @@ CommandCost CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
if (!IsValidWaypointID(p1)) return CMD_ERROR;
- if (_cmd_text[0] != '\0') {
- StringID str = AllocateNameUnique(_cmd_text, 0);
+ if (!StrEmpty(_cmd_text)) {
+ if (!IsUniqueWaypointName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
+
+ StringID str = AllocateName(_cmd_text, 0);
if (str == 0) return CMD_ERROR;