changeset 8629:8d7472e6d544 draft

(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
author bjarni <bjarni@openttd.org>
date Sat, 23 Feb 2008 22:23:06 +0000
parents 97445f45ba39
children 85bfaeeb062f
files src/autoreplace_cmd.cpp src/vehicle.cpp
diffstat 2 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -25,15 +25,6 @@
 
 #include "table/strings.h"
 
-bool Vehicle::NeedsAutorenewing(const Player *p) const
-{
-	assert(p == GetPlayer(this->owner));
-
-	if (!p->engine_renew) return false;
-	if (this->age - this->max_age < (p->engine_renew_months * 30)) return false;
-
-	return true;
-}
 
 /*
  * move the cargo from one engine to another if possible
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -93,6 +93,24 @@
 /* Initialize the vehicle-pool */
 DEFINE_OLD_POOL_GENERIC(Vehicle, Vehicle)
 
+/** Function to tell if a vehicle needs to be autorenewed
+ * @param *p The vehicle owner
+ * @return true if the vehicle is old enough for replacement
+ */
+bool Vehicle::NeedsAutorenewing(const Player *p) const
+{
+	/* We can always generate the Player pointer when we have the vehicle.
+	 * However this takes time and since the Player pointer is often present
+	 * when this function is called then it's faster to pass the pointer as an
+	 * argument rather than finding it again. */
+	assert(p == GetPlayer(this->owner));
+
+	if (!p->engine_renew) return false;
+	if (this->age - this->max_age < (p->engine_renew_months * 30)) return false;
+
+	return true;
+}
+
 void VehicleServiceInDepot(Vehicle *v)
 {
 	v->date_of_last_service = _date;