mirror of https://github.com/OpenTTD/OpenTTD
(svn r23743) -Fix [FS#4906]: Call CB 15E for all vehicles before actually executing any refit.
parent
d906c6865a
commit
f5ebbc96e9
|
@ -283,6 +283,13 @@ static CommandCost GetRefitCost(const Vehicle *v, EngineID engine_type, CargoID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Helper structure for RefitVehicle() */
|
||||||
|
struct RefitResult {
|
||||||
|
Vehicle *v; ///< Vehicle to refit
|
||||||
|
uint capacity; ///< New capacity of vehicle
|
||||||
|
uint mail_capacity; ///< New mail capacity of aircraft
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refits a vehicle (chain).
|
* Refits a vehicle (chain).
|
||||||
* This is the vehicle-type independent part of the CmdRefitXXX functions.
|
* This is the vehicle-type independent part of the CmdRefitXXX functions.
|
||||||
|
@ -309,6 +316,9 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles,
|
||||||
v = v->First();
|
v = v->First();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SmallVector<RefitResult, 16> refit_result;
|
||||||
|
refit_result.Clear();
|
||||||
|
|
||||||
v->InvalidateNewGRFCacheOfChain();
|
v->InvalidateNewGRFCacheOfChain();
|
||||||
for (; v != NULL; v = (only_this ? NULL : v->Next())) {
|
for (; v != NULL; v = (only_this ? NULL : v->Next())) {
|
||||||
if (v->type == VEH_TRAIN && !vehicles_to_refit.Contains(v->index) && !only_this) continue;
|
if (v->type == VEH_TRAIN && !vehicles_to_refit.Contains(v->index) && !only_this) continue;
|
||||||
|
@ -351,19 +361,38 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles,
|
||||||
}
|
}
|
||||||
cost.AddCost(refit_cost);
|
cost.AddCost(refit_cost);
|
||||||
|
|
||||||
|
/* Record the refitting.
|
||||||
|
* Do not execute the refitting immediately, so DetermineCapacity and GetRefitCost do the same in test and exec run.
|
||||||
|
* (weird NewGRFs)
|
||||||
|
* Note:
|
||||||
|
* - If the capacity of vehicles depends on other vehicles in the chain, the actual capacity is
|
||||||
|
* set after RefitVehicle() via ConsistChanged() and friends. The estimation via _returned_refit_capacity will be wrong.
|
||||||
|
* - We have to call the refit cost callback with the pre-refit configuration of the chain because we want refit and
|
||||||
|
* autorefit to behave the same, and we need its result for auto_refit_allowed.
|
||||||
|
*/
|
||||||
|
RefitResult *result = refit_result.Append();
|
||||||
|
result->v = v;
|
||||||
|
result->capacity = amount;
|
||||||
|
result->mail_capacity = mail_capacity;
|
||||||
|
}
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
v->cargo.Truncate((v->cargo_type == new_cid) ? amount : 0);
|
/* Store the result */
|
||||||
v->cargo_type = new_cid;
|
for (RefitResult *result = refit_result.Begin(); result != refit_result.End(); result++) {
|
||||||
v->cargo_cap = amount;
|
Vehicle *u = result->v;
|
||||||
v->cargo_subtype = new_subtype;
|
u->cargo.Truncate((u->cargo_type == new_cid) ? result->capacity : 0);
|
||||||
if (v->type == VEH_AIRCRAFT) {
|
u->cargo_type = new_cid;
|
||||||
Vehicle *u = v->Next();
|
u->cargo_cap = result->capacity;
|
||||||
u->cargo_cap = mail_capacity;
|
u->cargo_subtype = new_subtype;
|
||||||
u->cargo.Truncate(mail_capacity);
|
if (u->type == VEH_AIRCRAFT) {
|
||||||
|
Vehicle *w = u->Next();
|
||||||
|
w->cargo_cap = result->mail_capacity;
|
||||||
|
w->cargo.Truncate(result->mail_capacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refit_result.Clear();
|
||||||
_returned_refit_capacity = total_capacity;
|
_returned_refit_capacity = total_capacity;
|
||||||
_returned_mail_refit_capacity = total_mail_capacity;
|
_returned_mail_refit_capacity = total_mail_capacity;
|
||||||
return cost;
|
return cost;
|
||||||
|
|
Loading…
Reference in New Issue