diff options
author | bjarni <bjarni@openttd.org> | 2008-02-23 22:23:06 +0000 |
---|---|---|
committer | bjarni <bjarni@openttd.org> | 2008-02-23 22:23:06 +0000 |
commit | 8290a798fc3d8f941e87e2c52183967d223034fc (patch) | |
tree | a83cf50ad1c5a48702395201bc0945642ae513f2 /src/vehicle.cpp | |
parent | 089969e1cac6ebfb8ac14d692d2bfcd09f21ea6a (diff) | |
download | openttd-8290a798fc3d8f941e87e2c52183967d223034fc.tar.xz |
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r-- | src/vehicle.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 170a88ae2..e91f243a5 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -93,6 +93,24 @@ const uint32 _send_to_depot_proc_table[] = { /* 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; |