summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-04-21 14:33:33 +0000
committerrubidium <rubidium@openttd.org>2008-04-21 14:33:33 +0000
commite947fde7013a09d58744604faaf3c574dae51c47 (patch)
tree4c1ef67d89a0fbc13b10c3ed8a9880350b14ab12 /src
parentbbe13a0623eea9f46353fca57a35ae745040fbaf (diff)
downloadopenttd-e947fde7013a09d58744604faaf3c574dae51c47.tar.xz
(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.
Diffstat (limited to 'src')
-rw-r--r--src/articulated_vehicles.cpp6
-rw-r--r--src/economy.cpp2
-rw-r--r--src/newgrf_generic.cpp4
-rw-r--r--src/newgrf_house.cpp2
-rw-r--r--src/newgrf_spritegroup.cpp41
-rw-r--r--src/rail_gui.cpp8
-rw-r--r--src/station_cmd.cpp2
-rw-r--r--src/town_cmd.cpp2
-rw-r--r--src/train_cmd.cpp2
9 files changed, 16 insertions, 53 deletions
diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp
index 1f943b104..ef63e71b5 100644
--- a/src/articulated_vehicles.cpp
+++ b/src/articulated_vehicles.cpp
@@ -25,7 +25,7 @@ uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
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 @@ uint16 *GetCapacityOfArticulatedParts(EngineID engine, VehicleType type)
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 @@ void AddArticulatedParts(Vehicle **vl, VehicleType type)
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. */
diff --git a/src/economy.cpp b/src/economy.cpp
index b386416f8..a6dbea987 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1595,7 +1595,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
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];
diff --git a/src/newgrf_generic.cpp b/src/newgrf_generic.cpp
index 0097979e3..682ecdb33 100644
--- a/src/newgrf_generic.cpp
+++ b/src/newgrf_generic.cpp
@@ -176,5 +176,7 @@ uint16 GetAiPurchaseCallbackResult(uint8 feature, CargoID cargo_type, uint8 defa
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;
}
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp
index 15db58ffd..aa462f8a8 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -527,7 +527,7 @@ bool NewHouseTileLoop(TileIndex tile)
/* 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;
}
diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp
index 5e866d51d..b8103ae02 100644
--- a/src/newgrf_spritegroup.cpp
+++ b/src/newgrf_spritegroup.cpp
@@ -80,37 +80,6 @@ void InitializeSpriteGroupPool()
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 @@ static inline const SpriteGroup *ResolveVariable(const SpriteGroup *group, Resol
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 @@ const SpriteGroup *Resolve(const SpriteGroup *group, ResolverObject *object)
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;
}
}
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index bfcad9ba7..748c74249 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -952,7 +952,7 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
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 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
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 @@ static void BuildWaypointWndProc(Window *w, WindowEvent *e)
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 @@ static void BuildWaypointWndProc(Window *w, WindowEvent *e)
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);
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index efc508626..0a0669e32 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1014,7 +1014,7 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1,
}
/* 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;
}
}
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index b40f41166..8bbe05377 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -1936,7 +1936,7 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
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;
}
}
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 4f55e30ce..a1a378602 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -240,7 +240,7 @@ void TrainConsistChanged(Vehicle *v)
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 &&