summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-09-18 20:41:59 +0000
committerrubidium <rubidium@openttd.org>2007-09-18 20:41:59 +0000
commit262836a24f2f1f4a2c9c4dec4f7e0b06993839ee (patch)
treefd0614066e77232e7262f17cc747c6bd812826c1
parent7f721d31c2dd21fe9b5740cf9cabff269134757e (diff)
downloadopenttd-262836a24f2f1f4a2c9c4dec4f7e0b06993839ee.tar.xz
(svn r11127) -Fix: truncate the result of 8 bits callbacks.
-rw-r--r--src/newgrf_callbacks.h3
-rw-r--r--src/newgrf_spritegroup.cpp20
2 files changed, 22 insertions, 1 deletions
diff --git a/src/newgrf_callbacks.h b/src/newgrf_callbacks.h
index fefd4f27f..e62523a60 100644
--- a/src/newgrf_callbacks.h
+++ b/src/newgrf_callbacks.h
@@ -13,6 +13,9 @@
* bit is set in the callback flags/trigger for a vehicle, house,
* industry, etc.
* Names are formatted as CBID_<CLASS>_<CALLBACK>
+ *
+ * @note Do not forget to add 15 bits callbacks to the switch in
+ * newgrf_spritegroup.cpp (search for "15 bits callback").
*/
enum CallbackID {
/** Set when using the callback resolve system, but not to resolve a callback. */
diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp
index 53c655c55..9dcc674d8 100644
--- a/src/newgrf_spritegroup.cpp
+++ b/src/newgrf_spritegroup.cpp
@@ -192,7 +192,25 @@ 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, 15);
+ switch (object->callback) {
+ /* All these functions are 15 bit callbacks */
+ case CBID_VEHICLE_REFIT_CAPACITY:
+ case CBID_BUILDING_COLOUR:
+ case CBID_HOUSE_CARGO_ACCEPTANCE:
+ case CBID_INDUSTRY_LOCATION:
+ case CBID_INDTILE_CARGO_ACCEPTANCE:
+ case CBID_VEHICLE_COLOUR_MAPPING:
+ case CBID_HOUSE_PRODUCE_CARGO:
+ case CBID_VEHICLE_SOUND_EFFECT:
+ case CBID_SOUNDS_AMBIENT_EFFECT:
+ nvarzero.g.callback.result = GB(value, 0, 15);
+ break;
+
+ /* The rest is a 8 bit callback, which should be truncated properly */
+ default:
+ nvarzero.g.callback.result = GB(value, 0, 8);
+ break;
+ }
return &nvarzero;
}