(svn r14958) -Codechange [FS#1923]: when checking for unique names, compare only with manually set names

There are situations that aren't solvable (because of different language files), so if the user really wants to have duplicated name, allow him to do so. It solves desyncs between server and clients using different languages. It behaves the same in SP and MP, so users won't see the different behaviour as a bug (and even checking in SP could be worked around by the user).
This commit is contained in:
smatz 2009-01-10 15:54:07 +00:00
parent 07d1c28025
commit 0cd41d1dc6
7 changed files with 9 additions and 53 deletions

View File

@ -493,13 +493,10 @@ void EnginesMonthlyLoop()
static bool IsUniqueEngineName(const char *name)
{
char buf[512];
const Engine *e;
FOR_ALL_ENGINES(e) {
SetDParam(0, e->index);
GetString(buf, STR_ENGINE_NAME, lastof(buf));
if (strcmp(buf, name) == 0) return false;
if (e->name != NULL && strcmp(e->name, name) == 0) return false;
}
return true;

View File

@ -149,12 +149,9 @@ CommandCost CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, c
static bool IsUniqueGroupName(const char *name)
{
const Group *g;
char buf[512];
FOR_ALL_GROUPS(g) {
SetDParam(0, g->index);
GetString(buf, STR_GROUP_NAME, lastof(buf));
if (strcmp(buf, name) == 0) return false;
if (g->name != NULL && strcmp(g->name, name) == 0) return false;
}
return true;

View File

@ -205,12 +205,9 @@ CommandCost CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2,
static bool IsUniqueCompanyName(const char *name)
{
const Company *c;
char buf[512];
FOR_ALL_COMPANIES(c) {
SetDParam(0, c->index);
GetString(buf, STR_COMPANY_NAME, lastof(buf));
if (strcmp(buf, name) == 0) return false;
if (c->name != NULL && strcmp(c->name, name) == 0) return false;
}
return true;
@ -244,12 +241,9 @@ CommandCost CmdRenameCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2,
static bool IsUniquePresidentName(const char *name)
{
const Company *c;
char buf[512];
FOR_ALL_COMPANIES(c) {
SetDParam(0, c->index);
GetString(buf, STR_PRESIDENT_NAME, lastof(buf));
if (strcmp(buf, name) == 0) return false;
if (c->president_name != NULL && strcmp(c->president_name, name) == 0) return false;
}
return true;

View File

@ -2895,12 +2895,9 @@ static void UpdateStationWaiting(Station *st, CargoID type, uint amount)
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;
if (st->name != NULL && strcmp(st->name, name) == 0) return false;
}
return true;

View File

@ -2103,12 +2103,9 @@ void ClearTownHouse(Town *t, TileIndex tile)
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;
if (t->name != NULL && strcmp(t->name, name) == 0) return false;
}
return true;

View File

@ -1525,32 +1525,9 @@ void VehicleEnterDepot(Vehicle *v)
static bool IsUniqueVehicleName(const char *name)
{
const Vehicle *v;
char buf[512];
FOR_ALL_VEHICLES(v) {
switch (v->type) {
case VEH_TRAIN:
if (!IsTrainEngine(v)) continue;
break;
case VEH_ROAD:
if (!IsRoadVehFront(v)) continue;
break;
case VEH_AIRCRAFT:
if (!IsNormalAircraft(v)) continue;
break;
case VEH_SHIP:
break;
default:
continue;
}
SetDParam(0, v->index);
GetString(buf, STR_VEHICLE_NAME, lastof(buf));
if (strcmp(buf, name) == 0) return false;
if (v->name != NULL && strcmp(v->name, name) == 0) return false;
}
return true;

View File

@ -336,12 +336,9 @@ CommandCost CmdRemoveTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint
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;
if (wp->name != NULL && strcmp(wp->name, name) == 0) return false;
}
return true;