summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2009-03-05 17:52:35 +0000
committerpeter1138 <peter1138@openttd.org>2009-03-05 17:52:35 +0000
commit85569a45591b0ecf29864c213a7cdbb50e697972 (patch)
tree2c1822832e3af874042b7a32214abd101cfbfeef
parentc50730d57be74518eb8b54e396c90fd70afd90ec (diff)
downloadopenttd-85569a45591b0ecf29864c213a7cdbb50e697972.tar.xz
(svn r15622) -Codechange: Duplication.
-rw-r--r--src/vehicle.cpp42
1 files changed, 17 insertions, 25 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 2b33a73e8..0f0602cb4 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1171,6 +1171,21 @@ CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32
return cost;
}
+/** Test if a name is unique among vehicle names.
+ * @param name Name to test.
+ * @return True ifffffff the name is unique.
+ */
+static bool IsUniqueVehicleName(const char *name)
+{
+ const Vehicle *v;
+
+ FOR_ALL_VEHICLES(v) {
+ if (v->name != NULL && strcmp(v->name, name) == 0) return false;
+ }
+
+ return true;
+}
+
/** Clone the custom name of a vehicle, adding or incrementing a number.
* @param src Source vehicle, with a custom name.
* @param dst Destination vehicle.
@@ -1206,21 +1221,9 @@ static void CloneVehicleName(const Vehicle *src, Vehicle *dst)
for (int max_iterations = 1000; max_iterations > 0; max_iterations--, num++) {
/* Attach the number to the temporary name. */
seprintf(&buf[number_position], lastof(buf), "%d", num);
- bool dup = false;
-
- /* Check name against all other vehicles for this company. */
- const Vehicle *v;
- FOR_ALL_VEHICLES(v) {
- if (v->owner == src->owner && v->name != NULL) {
- if (strcmp(buf, v->name) == 0) {
- dup = true;
- break;
- }
- }
- }
- if (!dup) {
- /* Name is not a duplicate, so assign it. */
+ /* Check the name is unique. */
+ if (IsUniqueVehicleName(buf)) {
dst->name = strdup(buf);
break;
}
@@ -1572,17 +1575,6 @@ void VehicleEnterDepot(Vehicle *v)
}
}
-static bool IsUniqueVehicleName(const char *name)
-{
- const Vehicle *v;
-
- FOR_ALL_VEHICLES(v) {
- if (v->name != NULL && strcmp(v->name, name) == 0) return false;
- }
-
- return true;
-}
-
/** Give a custom name to your vehicle
* @param tile unused
* @param flags type of operation