From 92a827800f690c04927c5cbbdd5fa788b9f2cd4c Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 18 Sep 2007 20:41:59 +0000 Subject: (svn r11127) -Fix: truncate the result of 8 bits callbacks. --- src/newgrf_callbacks.h | 3 +++ src/newgrf_spritegroup.cpp | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) 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__ + * + * @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; } -- cgit v1.2.3-70-g09d2