mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-02 04:13:26 +00:00
(svn r12230) -Codechange: [autoreplace] made a function to detect if a vehicle needs autorenewing
This will remove duplicated code and ensure that the check is consistent
This commit is contained in:
parent
e821b3a9b8
commit
089969e1ca
@ -1574,7 +1574,7 @@ static inline bool CheckSendAircraftToHangarForReplacement(const Vehicle *v)
|
|||||||
/* There is no autoreplace assigned to this EngineID so we will set it to renew to the same type if needed */
|
/* There is no autoreplace assigned to this EngineID so we will set it to renew to the same type if needed */
|
||||||
new_engine = v->engine_type;
|
new_engine = v->engine_type;
|
||||||
|
|
||||||
if(!p->engine_renew || (v->age - v->max_age) < p->engine_renew_months * 30) {
|
if (!v->NeedsAutorenewing(p)) {
|
||||||
/* No need to replace the aircraft */
|
/* No need to replace the aircraft */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,16 @@
|
|||||||
|
|
||||||
#include "table/strings.h"
|
#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
|
* move the cargo from one engine to another if possible
|
||||||
*/
|
*/
|
||||||
@ -342,8 +352,7 @@ CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if the vehicle should be replaced
|
// check if the vehicle should be replaced
|
||||||
if (!p->engine_renew ||
|
if (!w->NeedsAutorenewing(p) || // replace if engine is too old
|
||||||
w->age - w->max_age < (p->engine_renew_months * 30) || // replace if engine is too old
|
|
||||||
w->max_age == 0) { // rail cars got a max age of 0
|
w->max_age == 0) { // rail cars got a max age of 0
|
||||||
/* If the vehicle belongs to a group, check if the group is protected from the global autoreplace.
|
/* If the vehicle belongs to a group, check if the group is protected from the global autoreplace.
|
||||||
If not, chek if an global auto remplacement is defined */
|
If not, chek if an global auto remplacement is defined */
|
||||||
|
@ -481,6 +481,8 @@ public:
|
|||||||
* @return true if there are other vehicles sharing the same order
|
* @return true if there are other vehicles sharing the same order
|
||||||
*/
|
*/
|
||||||
inline bool IsOrderListShared() const { return this->next_shared != NULL || this->prev_shared != NULL; };
|
inline bool IsOrderListShared() const { return this->next_shared != NULL || this->prev_shared != NULL; };
|
||||||
|
|
||||||
|
bool NeedsAutorenewing(const Player *p) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user