diff options
author | peter1138 <peter1138@openttd.org> | 2007-06-27 20:53:25 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2007-06-27 20:53:25 +0000 |
commit | c692d897cd1bdeb8d4e00349519a460fcdd2c262 (patch) | |
tree | e2ac06c3a62de5b5f8411541f83536ef20f32ee0 /src/station_cmd.cpp | |
parent | de357c74c1ac4df582f32849bfbc5681c3552171 (diff) | |
download | openttd-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/station_cmd.cpp')
-rw-r--r-- | src/station_cmd.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 514cf4185..c870d6309 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -41,6 +41,7 @@ #include "misc/autoptr.hpp" #include "road.h" #include "cargotype.h" +#include "strings.h" /** * Called if a new block is added to the station-pool @@ -2479,6 +2480,20 @@ static void UpdateStationWaiting(Station *st, CargoID type, uint amount) st->MarkTilesDirty(true); } +static bool IsUniqueStationName(const char *name) +{ + const Station *st; + char buf[512]; + + FOR_ALL_STATIONS(st) { + SetDParam(0, st->index); + GetString(buf, STR_STATION, lastof(buf)); + if (strcmp(buf, name) == 0) return false; + } + + return true; +} + /** Rename a station * @param tile unused * @param flags operation to perform @@ -2487,12 +2502,14 @@ static void UpdateStationWaiting(Station *st, CargoID type, uint amount) */ CommandCost CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { - if (!IsValidStationID(p1) || _cmd_text[0] == '\0') return CMD_ERROR; + if (!IsValidStationID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; Station *st = GetStation(p1); if (!CheckOwnership(st->owner)) return CMD_ERROR; - StringID str = AllocateNameUnique(_cmd_text, 6); + if (!IsUniqueStationName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); + + StringID str = AllocateName(_cmd_text, 6); if (str == 0) return CMD_ERROR; if (flags & DC_EXEC) { |