summaryrefslogtreecommitdiff
path: root/src/town_cmd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/town_cmd.cpp')
-rw-r--r--src/town_cmd.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index f19c2266b..0250887df 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -1859,6 +1859,20 @@ void ClearTownHouse(Town *t, TileIndex tile)
if (eflags & BUILDING_HAS_4_TILES) DoClearTownHouseHelper(tile + TileDiffXY(1, 1));
}
+static bool IsUniqueTownName(const char *name)
+{
+ const Town *t;
+ char buf[512];
+
+ FOR_ALL_TOWNS(t) {
+ SetDParam(0, t->index);
+ GetString(buf, STR_TOWN, lastof(buf));
+ if (strcmp(buf, name) == 0) return false;
+ }
+
+ return true;
+}
+
/** Rename a town (server-only).
* @param tile unused
* @param flags type of operation
@@ -1870,11 +1884,13 @@ CommandCost CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
StringID str;
Town *t;
- if (!IsValidTownID(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
+ if (!IsValidTownID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR;
t = GetTown(p1);
- str = AllocateNameUnique(_cmd_text, 4);
+ if (!IsUniqueTownName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
+
+ str = AllocateName(_cmd_text, 4);
if (str == 0) return CMD_ERROR;
if (flags & DC_EXEC) {