mirror of https://github.com/OpenTTD/OpenTTD
(svn r18495) -Codechange: make sure we don't taint the vehicle cache with finding refit options and unmagify a constant
parent
c2ec2e2db3
commit
f9970ac646
|
@ -156,6 +156,9 @@ static void DrawVehicleProfitButton(const Vehicle *v, int x, int y)
|
||||||
DrawSprite(SPR_BLOT, pal, x, y);
|
DrawSprite(SPR_BLOT, pal, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Maximum number of refit cycles we try, to prevent infinite loops. */
|
||||||
|
static const int MAX_REFIT_CYCLE = 16;
|
||||||
|
|
||||||
struct RefitOption {
|
struct RefitOption {
|
||||||
CargoID cargo;
|
CargoID cargo;
|
||||||
byte subtype;
|
byte subtype;
|
||||||
|
@ -200,11 +203,15 @@ static RefitList *BuildRefitList(const Vehicle *v)
|
||||||
|
|
||||||
u->cargo_type = cid;
|
u->cargo_type = cid;
|
||||||
|
|
||||||
for (refit_cyc = 0; refit_cyc < 16 && num_lines < max_lines; refit_cyc++) {
|
for (refit_cyc = 0; refit_cyc < MAX_REFIT_CYCLE && num_lines < max_lines; refit_cyc++) {
|
||||||
bool duplicate = false;
|
bool duplicate = false;
|
||||||
uint16 callback;
|
uint16 callback;
|
||||||
|
|
||||||
u->cargo_subtype = refit_cyc;
|
u->cargo_subtype = refit_cyc;
|
||||||
|
|
||||||
|
/* Make sure we don't pick up anything cached. */
|
||||||
|
u->First()->InvalidateNewGRFCache();
|
||||||
|
u->InvalidateNewGRFCache();
|
||||||
callback = GetVehicleCallback(CBID_VEHICLE_CARGO_SUFFIX, 0, 0, u->engine_type, u);
|
callback = GetVehicleCallback(CBID_VEHICLE_CARGO_SUFFIX, 0, 0, u->engine_type, u);
|
||||||
|
|
||||||
if (callback == 0xFF) callback = CALLBACK_FAILED;
|
if (callback == 0xFF) callback = CALLBACK_FAILED;
|
||||||
|
@ -227,6 +234,10 @@ static RefitList *BuildRefitList(const Vehicle *v)
|
||||||
/* Reset the vehicle's cargo type */
|
/* Reset the vehicle's cargo type */
|
||||||
u->cargo_type = temp_cargo;
|
u->cargo_type = temp_cargo;
|
||||||
u->cargo_subtype = temp_subtype;
|
u->cargo_subtype = temp_subtype;
|
||||||
|
|
||||||
|
/* And make sure we haven't tainted the cache */
|
||||||
|
u->First()->InvalidateNewGRFCache();
|
||||||
|
u->InvalidateNewGRFCache();
|
||||||
} else {
|
} else {
|
||||||
/* No cargo suffix callback -- use no subtype */
|
/* No cargo suffix callback -- use no subtype */
|
||||||
bool duplicate = false;
|
bool duplicate = false;
|
||||||
|
|
Loading…
Reference in New Issue