1
0
Fork 0

(svn r2912) -Fix: [autorenew]: fixed issue where autorenewed vehicles didn't get all stats updated (peter1138)

release/0.4.5
bjarni 2005-09-03 19:22:56 +00:00
parent 3ace3769c9
commit 864cb3fa11
1 changed files with 23 additions and 27 deletions

View File

@ -1370,6 +1370,7 @@ int32 ReplaceVehicle(Vehicle *v)
EngineID old_engine_type = v->engine_type; EngineID old_engine_type = v->engine_type;
EngineID new_engine_type = p->engine_replacement[old_engine_type]; EngineID new_engine_type = p->engine_replacement[old_engine_type];
Vehicle *u, *first; Vehicle *u, *first;
Engine *e;
int cost, build_cost, rear_engine_cost = 0; int cost, build_cost, rear_engine_cost = 0;
// If replacing due to age only, use the same type :-) // If replacing due to age only, use the same type :-)
@ -1460,27 +1461,26 @@ int32 ReplaceVehicle(Vehicle *v)
} }
cost = build_cost - v->value + rear_engine_cost; cost = build_cost - v->value + rear_engine_cost;
if (old_engine_type != new_engine_type) { /* We do not really buy a new vehicle, we upgrade the old one */
/* We do not really buy a new vehicle, we upgrade the old one */ e = GetEngine(new_engine_type);
const Engine* e = GetEngine(new_engine_type);
v->reliability = e->reliability; v->reliability = e->reliability;
v->reliability_spd_dec = e->reliability_spd_dec; v->reliability_spd_dec = e->reliability_spd_dec;
v->age = 0; v->age = 0;
v->date_of_last_service = _date; v->date_of_last_service = _date;
v->build_year = _cur_year; v->build_year = _cur_year;
v->value = build_cost; v->value = build_cost;
if (v->engine_type != new_engine_type) { if (v->engine_type != new_engine_type) {
byte sprite = v->spritenum; byte sprite = v->spritenum;
byte cargo_type = v->cargo_type; byte cargo_type = v->cargo_type;
v->engine_type = new_engine_type; v->engine_type = new_engine_type;
v->max_age = e->lifelength * 366; v->max_age = e->lifelength * 366;
/* Update limits of the vehicle (for when upgraded) */ /* Update limits of the vehicle (for when upgraded) */
switch (v->type) { switch (v->type) {
case VEH_Train: case VEH_Train:
{ {
const RailVehicleInfo *rvi = RailVehInfo(new_engine_type); const RailVehicleInfo *rvi = RailVehInfo(new_engine_type);
@ -1596,20 +1596,16 @@ int32 ReplaceVehicle(Vehicle *v)
break; break;
} }
default: return CMD_ERROR; default: return CMD_ERROR;
} }
// makes sure that the cargo is still valid compared to new capacity // makes sure that the cargo is still valid compared to new capacity
if (v->cargo_count != 0) { if (v->cargo_count != 0) {
if ( v->cargo_type != cargo_type ) if ( v->cargo_type != cargo_type )
v->cargo_count = 0; v->cargo_count = 0;
else if ( v->cargo_count > v->cargo_cap ) else if ( v->cargo_count > v->cargo_cap )
v->cargo_count = v->cargo_cap; v->cargo_count = v->cargo_cap;
}
} }
} }
// A replaced vehicle should be classed as new
v->age = 0;
InvalidateWindow(WC_REPLACE_VEHICLE, v->type); InvalidateWindow(WC_REPLACE_VEHICLE, v->type);
ResortVehicleLists(); ResortVehicleLists();
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); InvalidateWindow(WC_VEHICLE_DETAILS, v->index);