Mercurial > hg > openttd
changeset 9020:94bb527c979f draft
(svn r12819) -Codechange: handle more NewGRFs in the same way as TTDP does it, i.e. testing the low bits for 0xFF or 0 instead of all bits.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Mon, 21 Apr 2008 14:33:33 +0000 |
parents | 382abce6450f |
children | e5aba9a61144 |
files | src/articulated_vehicles.cpp src/economy.cpp src/newgrf_generic.cpp src/newgrf_house.cpp src/newgrf_spritegroup.cpp src/rail_gui.cpp src/station_cmd.cpp src/town_cmd.cpp src/train_cmd.cpp |
diffstat | 9 files changed, 16 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -25,7 +25,7 @@ uint i; for (i = 1; i < MAX_UVALUE(EngineID); i++) { uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine_type, v); - if (callback == CALLBACK_FAILED || callback == 0xFF) break; + if (callback == CALLBACK_FAILED || GB(callback, 0, 8) == 0xFF) break; } delete v; @@ -52,7 +52,7 @@ for (uint i = 1; i < MAX_UVALUE(EngineID); i++) { uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine, NULL); - if (callback == CALLBACK_FAILED || callback == 0xFF) break; + if (callback == CALLBACK_FAILED || GB(callback, 0, 8) == 0xFF) break; EngineID artic_engine = GetFirstEngineOfType(type) + GB(callback, 0, 7); @@ -78,7 +78,7 @@ for (uint i = 1; i < MAX_UVALUE(EngineID); i++) { uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, v->engine_type, v); - if (callback == CALLBACK_FAILED || callback == 0xFF) return; + if (callback == CALLBACK_FAILED || GB(callback, 0, 8) == 0xFF) return; /* Attempt to use pre-allocated vehicles until they run out. This can happen * if the callback returns different values depending on the cargo type. */
--- a/src/economy.cpp +++ b/src/economy.cpp @@ -1595,7 +1595,7 @@ byte load_amount = EngInfo(v->engine_type)->load_amount; if (_patches.gradual_loading && HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_LOAD_AMOUNT)) { uint16 cb_load_amount = GetVehicleCallback(CBID_VEHICLE_LOAD_AMOUNT, 0, 0, v->engine_type, v); - if (cb_load_amount != CALLBACK_FAILED && cb_load_amount != 0) load_amount = cb_load_amount & 0xFF; + if (cb_load_amount != CALLBACK_FAILED && GB(cb_load_amount, 0, 8) != 0) load_amount = GB(cb_load_amount, 0, 8); } GoodsEntry *ge = &st->goods[v->cargo_type];
--- a/src/newgrf_generic.cpp +++ b/src/newgrf_generic.cpp @@ -176,5 +176,7 @@ object.u.generic.count = count; object.u.generic.station_size = station_size; - return GetGenericCallbackResult(feature, &object, file); + uint16 callback = GetGenericCallbackResult(feature, &object, file); + if (callback != CALLBACK_FAILED) callback = GB(callback, 0, 8); + return callback; }
--- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -527,7 +527,7 @@ /* Check callback 21, which determines if a house should be destroyed. */ if (HasBit(hs->callback_mask, CBM_HOUSE_DESTRUCTION)) { uint16 callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); - if (callback_res != CALLBACK_FAILED && callback_res > 0) { + if (callback_res != CALLBACK_FAILED && GB(callback_res, 0, 8) > 0) { ClearTownHouse(GetTownByTile(tile), tile); return false; }
--- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -80,37 +80,6 @@ TemporaryStorageArray<uint32, 0x110> _temp_store; -static inline bool Is8BitCallback(const ResolverObject *object) -{ - /* Var 0x7E procedure results are always 15 bit */ - if (object == NULL || object->procedure_call) return false; - - switch (object->callback) { - /* All these functions are 15 bit callbacks */ - case CBID_STATION_SPRITE_LAYOUT: - case CBID_VEHICLE_REFIT_CAPACITY: - case CBID_HOUSE_COLOUR: - case CBID_HOUSE_CARGO_ACCEPTANCE: - case CBID_INDUSTRY_LOCATION: - case CBID_HOUSE_ACCEPT_CARGO: - case CBID_INDTILE_CARGO_ACCEPTANCE: - case CBID_INDTILE_ACCEPT_CARGO: - case CBID_VEHICLE_COLOUR_MAPPING: - case CBID_HOUSE_PRODUCE_CARGO: - case CBID_INDTILE_SHAPE_CHECK: - case CBID_VEHICLE_SOUND_EFFECT: - case CBID_VEHICLE_MODIFY_PROPERTY: // depends on queried property - case CBID_CARGO_PROFIT_CALC: - case CBID_SOUNDS_AMBIENT_EFFECT: - case CBID_CARGO_STATION_RATING_CALC: - return false; - - /* The rest is a 8 bit callback, which should be truncated properly */ - default: - return true; - } -} - static inline uint32 GetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) { /* First handle variables common with Action7/9/D */ @@ -236,7 +205,7 @@ if (group->g.determ.num_ranges == 0) { /* nvar == 0 is a special case -- we turn our value into a callback result */ nvarzero.type = SGT_CALLBACK; - nvarzero.g.callback.result = GB(value, 0, Is8BitCallback(object) ? 8 : 15); + nvarzero.g.callback.result = value; return &nvarzero; } @@ -295,14 +264,6 @@ case SGT_REAL: return object->ResolveReal(object, group); case SGT_DETERMINISTIC: return ResolveVariable(group, object); case SGT_RANDOMIZED: return ResolveRandom(group, object); - case SGT_CALLBACK: { - if (!Is8BitCallback(object)) return group; - - static SpriteGroup result8bit; - result8bit.type = SGT_CALLBACK; - result8bit.g.callback.result = GB(group->g.callback.result, 0, 8); - return &result8bit; - } default: return group; } }
--- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -952,7 +952,7 @@ const StationSpec *statspec = GetCustomStationSpec(_railstation.station_class, i); if (statspec != NULL && statspec->name != 0) { - if (HasBit(statspec->callbackmask, CBM_STATION_AVAIL) && GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE) == 0) { + if (HasBit(statspec->callbackmask, CBM_STATION_AVAIL) && GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) { GfxFillRect(8, y - 2, 127, y + 10, (1 << PALETTE_MODIFIER_GREYOUT)); } @@ -1097,7 +1097,7 @@ statspec = GetCustomStationSpec(_railstation.station_class, y); if (statspec != NULL && HasBit(statspec->callbackmask, CBM_STATION_AVAIL) && - GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE) == 0) return; + GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) return; _railstation.station_type = y; @@ -1510,7 +1510,7 @@ if (statspec != NULL && HasBit(statspec->callbackmask, CBM_STATION_AVAIL) && - GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE) == 0) { + GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) { GfxFillRect(4 + i * 68, 18, 67 + i * 68, 75, (1 << PALETTE_MODIFIER_GREYOUT)); } } @@ -1530,7 +1530,7 @@ const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, type); if (statspec != NULL && HasBit(statspec->callbackmask, CBM_STATION_AVAIL) && - GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE) == 0) return; + GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) return; _cur_waypoint_type = type; SndPlayFx(SND_15_BEEP);
--- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1014,7 +1014,7 @@ } /* Check if the station is buildable */ - if (HasBit(statspec->callbackmask, CBM_STATION_AVAIL) && GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE) == 0) { + if (HasBit(statspec->callbackmask, CBM_STATION_AVAIL) && GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) { return CMD_ERROR; } }
--- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1936,7 +1936,7 @@ if (HasBit(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) { uint16 callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, 0, house, t, tile); - if (callback_res != CALLBACK_FAILED && callback_res == 0) continue; + if (callback_res != CALLBACK_FAILED && GB(callback_res, 0, 8) == 0) continue; } }
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -240,7 +240,7 @@ if (HasBit(EngInfo(u->engine_type)->callbackmask, CBM_TRAIN_WAGON_POWER)) { uint16 callback = GetVehicleCallback(CBID_TRAIN_WAGON_POWER, 0, 0, u->engine_type, u); - if (callback != CALLBACK_FAILED) u->u.rail.cached_vis_effect = callback; + if (callback != CALLBACK_FAILED) u->u.rail.cached_vis_effect = GB(callback, 0, 8); } if (rvi_v->pow_wag_power != 0 && rvi_u->railveh_type == RAILVEH_WAGON &&