summaryrefslogtreecommitdiff
path: root/src/engine.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
commitcd0e022172005d5a6a463848cdc711df1dda648f (patch)
treee2ac06c3a62de5b5f8411541f83536ef20f32ee0 /src/engine.cpp
parent85fb4eb94b804a0412ae4db51343fb8ac2d8b824 (diff)
downloadopenttd-cd0e022172005d5a6a463848cdc711df1dda648f.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/engine.cpp')
-rw-r--r--src/engine.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index b8207c481..09a1b889f 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -21,6 +21,8 @@
#include "date.h"
#include "table/engines.h"
#include "group.h"
+#include "string.h"
+#include "strings.h"
EngineInfo _engine_info[TOTAL_NUM_ENGINES];
RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
@@ -368,6 +370,19 @@ void EnginesMonthlyLoop()
}
}
+static bool IsUniqueEngineName(const char *name)
+{
+ char buf[512];
+
+ for (EngineID i = 0; i < TOTAL_NUM_ENGINES; i++) {
+ SetDParam(0, i);
+ GetString(buf, STR_ENGINE_NAME, lastof(buf));
+ if (strcmp(buf, name) == 0) return false;
+ }
+
+ return true;
+}
+
/** Rename an engine.
* @param tile unused
* @param flags operation to perfom
@@ -378,9 +393,11 @@ CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
StringID str;
- if (!IsEngineIndex(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
+ if (!IsEngineIndex(p1) || StrEmpty(_cmd_text)) return CMD_ERROR;
+
+ if (!IsUniqueEngineName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
- str = AllocateNameUnique(_cmd_text, 0);
+ str = AllocateName(_cmd_text, 0);
if (str == 0) return CMD_ERROR;
if (flags & DC_EXEC) {