(svn r16482) [0.7] -Backport from trunk:

- Fix: [NewGRF] Invalidate NewGRF variable caches of more vehicles in more places. Esp. they were only invalidated for trains (r16480)
- Fix: [NewGRF] Call callbacks after initialisation of vehicle variables (r16479)
- Fix: [NewGRF] Determining most common (sub-)cargo-type was broken due to someone confusing similiary named variables (r16478)
- Fix: Loading indicator when 'unload' in and 'no loading' is off was pointing to the wrong direction [FS#2936] (r16477)
- Fix: Track reservation was drawn at bridge heads in the menu (r16470)
This commit is contained in:
rubidium 2009-05-31 12:22:53 +00:00
parent 02f3d2d8af
commit 7ccaa82206
10 changed files with 73 additions and 33 deletions

View File

@ -93,7 +93,7 @@ elif [ -d "$ROOT_DIR/.hg" ]; then
if [ -n "`hg status \"$SRC_DIR\" | grep -v '^?'`" ]; then
MODIFIED="2"
fi
HASH=`LC_ALL=C hg parents 2>/dev/null | head -n 1 | cut -d: -f3`
HASH=`LC_ALL=C hg parents --template="{node}"`
REV="h`echo $HASH | cut -c1-8`"
BRANCH=`hg branch | sed 's@^default$@@'`
REV_NR=`LC_ALL=C hg log -r $HASH:0 -k "svn" -l 1 --template "{desc}\n" "$SRC_DIR" | grep "^(svn r[0-9]*)" | head -n 1 | sed "s@.*(svn r\([0-9]*\)).*@\1@"`

View File

@ -337,24 +337,6 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
u->subtype = AIR_SHADOW;
u->UpdateDeltaXY(INVALID_DIR);
if (v->cargo_type != CT_PASSENGERS) {
uint16 callback = CALLBACK_FAILED;
if (HasBit(EngInfo(p1)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) {
callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v);
}
if (callback == CALLBACK_FAILED) {
/* Callback failed, or not executed; use the default cargo capacity */
v->cargo_cap = AircraftDefaultCargoCapacity(v->cargo_type, avi);
} else {
v->cargo_cap = callback;
}
/* Set the 'second compartent' capacity to none */
u->cargo_cap = 0;
}
v->reliability = e->reliability;
v->reliability_spd_dec = e->reliability_spd_dec;
v->max_age = e->lifelength * DAYS_IN_LEAP_YEAR;
@ -395,6 +377,28 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
v->vehicle_flags = 0;
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
v->InvalidateNewGRFCacheOfChain();
if (v->cargo_type != CT_PASSENGERS) {
uint16 callback = CALLBACK_FAILED;
if (HasBit(EngInfo(p1)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) {
callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v);
}
if (callback == CALLBACK_FAILED) {
/* Callback failed, or not executed; use the default cargo capacity */
v->cargo_cap = AircraftDefaultCargoCapacity(v->cargo_type, avi);
} else {
v->cargo_cap = callback;
}
/* Set the 'second compartent' capacity to none */
u->cargo_cap = 0;
}
v->InvalidateNewGRFCacheOfChain();
UpdateAircraftCache(v);
VehicleMove(v, false);
@ -580,6 +584,7 @@ CommandCost CmdRefitAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
v->cargo_type = new_cid;
v->cargo_subtype = new_subtype;
v->colourmap = PAL_NONE; // invalidate vehicle colour map
v->InvalidateNewGRFCacheOfChain();
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);

View File

@ -122,7 +122,7 @@ CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1,
/* Company colour data is indirectly cached. */
Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (v->owner == _current_company) v->cache_valid = 0;
if (v->owner == _current_company) v->InvalidateNewGRFCache();
}
}
return CommandCost();

View File

@ -522,13 +522,11 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
if (!HasBit(v->cache_valid, 2)) {
const Vehicle *u;
byte cargo_classes = 0;
CargoID common_cargo_best = CT_INVALID;
uint8 common_cargos[NUM_CARGO];
uint8 common_subtype_best = 0xFF; // Return 0xFF if nothing is carried
uint8 common_subtypes[256];
byte user_def_data = 0;
CargoID common_cargo_type = CT_PASSENGERS;
uint8 common_subtype = 0;
CargoID common_cargo_type = CT_INVALID;
uint8 common_subtype = 0xFF; // Return 0xFF if nothing is carried
/* Reset our arrays */
memset(common_cargos, 0, sizeof(common_cargos));
@ -545,9 +543,10 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
}
/* Pick the most common cargo type */
uint common_cargo_best_amount = 0;
for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
if (common_cargos[cargo] > common_cargo_best) {
common_cargo_best = common_cargos[cargo];
if (common_cargos[cargo] > common_cargo_best_amount) {
common_cargo_best_amount = common_cargos[cargo];
common_cargo_type = cargo;
}
}
@ -561,9 +560,10 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
}
/* Pick the most common subcargo type*/
uint common_subtype_best_amount = 0;
for (uint i = 0; i < lengthof(common_subtypes); i++) {
if (common_subtypes[i] > common_subtype_best) {
common_subtype_best = common_subtypes[i];
if (common_subtypes[i] > common_subtype_best_amount) {
common_subtype_best_amount = common_subtypes[i];
common_subtype = i;
}
}
@ -1093,7 +1093,9 @@ void TriggerVehicle(Vehicle *v, VehicleTrigger trigger)
VehicleEnteredDepotThisTick(v);
}
v->InvalidateNewGRFCacheOfChain();
DoTriggerVehicle(v, trigger, 0, true);
v->InvalidateNewGRFCacheOfChain();
}
/* Functions for changing the order of vehicle purchase lists

View File

@ -137,6 +137,8 @@ void RoadVehUpdateCache(Vehicle *v)
assert(v->type == VEH_ROAD);
assert(IsRoadVehFront(v));
v->InvalidateNewGRFCacheOfChain();
for (Vehicle *u = v; u != NULL; u = u->Next()) {
/* Check the v->first cache. */
assert(u->First() == v);
@ -262,12 +264,15 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
v->cargo_cap = rvi->capacity;
AddArticulatedParts(vl, VEH_ROAD);
v->InvalidateNewGRFCacheOfChain();
/* Call various callbacks after the whole consist has been constructed */
for (Vehicle *u = v; u != NULL; u = u->Next()) {
u->u.road.cached_veh_length = GetRoadVehLength(u);
/* Cargo capacity is zero if and only if the vehicle cannot carry anything */
if (u->cargo_cap != 0) u->cargo_cap = GetVehicleProperty(u, 0x0F, u->cargo_cap);
v->InvalidateNewGRFCache();
u->InvalidateNewGRFCache();
}
VehicleMove(v, false);

View File

@ -797,8 +797,12 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
v->vehicle_flags = 0;
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
v->InvalidateNewGRFCacheOfChain();
v->cargo_cap = GetVehicleProperty(v, 0x0D, svi->capacity);
v->InvalidateNewGRFCacheOfChain();
VehicleMove(v, false);
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
@ -942,6 +946,7 @@ CommandCost CmdRefitShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
v->cargo_type = new_cid;
v->cargo_subtype = new_subtype;
v->colourmap = PAL_NONE; // invalidate vehicle colour map
v->InvalidateNewGRFCacheOfChain();
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
InvalidateWindowClassesData(WC_SHIPS_LIST, 0);

View File

@ -241,13 +241,15 @@ void TrainConsistChanged(Vehicle *v, bool same_length)
/* Set user defined data to its default value */
u->u.rail.user_def_data = rvi_u->user_def_data;
u->cache_valid = 0;
v->InvalidateNewGRFCache();
u->InvalidateNewGRFCache();
}
for (Vehicle *u = v; u != NULL; u = u->Next()) {
/* Update user defined data (must be done before other properties) */
u->u.rail.user_def_data = GetVehicleProperty(u, 0x25, u->u.rail.user_def_data);
u->cache_valid = 0;
v->InvalidateNewGRFCache();
u->InvalidateNewGRFCache();
}
for (Vehicle *u = v; u != NULL; u = u->Next()) {
@ -333,7 +335,8 @@ void TrainConsistChanged(Vehicle *v, bool same_length)
if (!same_length) u->u.rail.cached_veh_length = veh_len;
v->u.rail.cached_total_length += u->u.rail.cached_veh_length;
u->cache_valid = 0;
v->InvalidateNewGRFCache();
u->InvalidateNewGRFCache();
}
/* store consist weight/max speed in cache */

View File

@ -1002,7 +1002,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
/* Bridge heads are drawn solid no matter how invisibility/transparency is set */
AddSortableSpriteToDraw(psid->sprite, psid->pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z);
if (_settings_client.gui.show_track_reservation && transport_type == TRANSPORT_RAIL && GetTunnelBridgeReservation(ti->tile)) {
if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && transport_type == TRANSPORT_RAIL && GetTunnelBridgeReservation(ti->tile)) {
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
if (HasBridgeFlatRamp(ti->tileh, DiagDirToAxis(tunnelbridge_direction))) {
AddSortableSpriteToDraw(DiagDirToAxis(tunnelbridge_direction) == AXIS_X ? rti->base_sprites.single_y : rti->base_sprites.single_x, PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, ti->z + 8);

View File

@ -962,7 +962,7 @@ uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour)
max += v->cargo_cap;
if (v->cargo_cap != 0 && colour != NULL) {
unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0;
loading |= !(u->current_order.GetUnloadType() & OUFB_UNLOAD) && st->goods[v->cargo_type].days_since_pickup != 255;
loading |= !(u->current_order.GetLoadType() & OLFB_NO_LOAD) && st->goods[v->cargo_type].days_since_pickup != 255;
cars++;
}
}

View File

@ -399,6 +399,26 @@ public:
*/
virtual SpriteID GetImage(Direction direction) const { return 0; }
/**
* Invalidates cached NewGRF variables
* @see InvalidateNewGRFCacheOfChain
*/
FORCEINLINE void InvalidateNewGRFCache()
{
this->cache_valid = 0;
}
/**
* Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
* @see InvalidateNewGRFCache
*/
FORCEINLINE void InvalidateNewGRFCacheOfChain()
{
for (Vehicle *u = this; u != NULL; u = u->Next()) {
u->InvalidateNewGRFCache();
}
}
/**
* Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
* @return the vehicle's speed