# HG changeset patch # User bjarni # Date 1203805386 0 # Node ID 0081fd86cc155701716114fd4b6af61f198ab3e9 # Parent eea8af2b73a83f97524ac4973d073b6015116153 (svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments diff -r eea8af2b73a8 -r 0081fd86cc15 src/autoreplace_cmd.cpp --- a/src/autoreplace_cmd.cpp Sat Feb 23 22:01:55 2008 +0000 +++ b/src/autoreplace_cmd.cpp Sat Feb 23 22:23:06 2008 +0000 @@ -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 diff -r eea8af2b73a8 -r 0081fd86cc15 src/vehicle.cpp --- a/src/vehicle.cpp Sat Feb 23 22:01:55 2008 +0000 +++ b/src/vehicle.cpp Sat Feb 23 22:23:06 2008 +0000 @@ -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;