diff src/waypoint.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 d2846442a133
children 488bb393b04d
line wrap: on
line diff
--- 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 @@
 	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 @@
 
 	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;