From 051e094921f208f48f3239622f96078c528ef734 Mon Sep 17 00:00:00 2001 From: darkvater Date: Sun, 14 Nov 2004 20:53:34 +0000 Subject: [PATCH] (svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky). --- engine.c | 18 ++++++-- engine.h | 11 ++--- sprite.c | 124 +++++++++++++++++++++++++++---------------------------- 3 files changed, 80 insertions(+), 73 deletions(-) diff --git a/engine.c b/engine.c index 70914ae9ce..7e6944f5db 100644 --- a/engine.c +++ b/engine.c @@ -243,14 +243,26 @@ void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteGroup *group) _engine_custom_sprites[engine][cargo] = *group; } -int GetCustomEngineSprite(byte engine, uint16 overriding_engine, byte cargo, - byte loaded, byte in_motion, byte direction) +int GetCustomEngineSprite(byte engine, Vehicle *v, byte direction) { - struct SpriteGroup *group = &_engine_custom_sprites[engine][cargo]; + struct SpriteGroup *group; struct RealSpriteGroup *rsg; + uint16 overriding_engine = -1; + byte cargo = CID_PURCHASE; + byte loaded = 0; + byte in_motion = 0; int totalsets, spriteset; int r; + if (v != NULL) { + overriding_engine = v->type == VEH_Train ? v->u.rail.first_engine : -1; + cargo = _global_cargo_id[_opt.landscape][v->cargo_type]; + loaded = ((v->cargo_count + 1) * 100) / (v->cargo_cap + 1); + in_motion = !!v->cur_speed; + } + + group = &_engine_custom_sprites[engine][cargo]; + if (overriding_engine != 0xffff) { struct SpriteGroup *overset; diff --git a/engine.h b/engine.h index 550336317c..7a20d67bd6 100644 --- a/engine.h +++ b/engine.h @@ -97,14 +97,9 @@ extern byte _engine_original_sprites[256]; void SetWagonOverrideSprites(byte engine, struct SpriteGroup *group, byte *train_id, int trains); void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteGroup *group); // loaded is in percents, overriding_engine 0xffff is none -int GetCustomEngineSprite(byte engine, uint16 overriding_engine, byte cargo, byte loaded, byte in_motion, byte direction); -#define GetCustomVehicleSprite(v, direction) \ - GetCustomEngineSprite(v->engine_type, v->type == VEH_Train ? v->u.rail.first_engine : -1, \ - _global_cargo_id[_opt.landscape][v->cargo_type], \ - ((v->cargo_count + 1) * 100) / (v->cargo_cap + 1), \ - !!v->cur_speed, direction) -#define GetCustomVehicleIcon(v, direction) \ - GetCustomEngineSprite(v, -1, CID_PURCHASE, 0, 0, direction) +int GetCustomEngineSprite(byte engine, Vehicle *v, byte direction); +#define GetCustomVehicleSprite(v, direction) GetCustomEngineSprite(v->engine_type, v, direction) +#define GetCustomVehicleIcon(et, direction) GetCustomEngineSprite(et, NULL, direction) void SetCustomEngineName(int engine, char *name); StringID GetCustomEngineName(int engine); diff --git a/sprite.c b/sprite.c index f0a130d4e0..23a21f1b14 100644 --- a/sprite.c +++ b/sprite.c @@ -1,62 +1,62 @@ -#include "stdafx.h" - -#include - -#include "ttd.h" -#include "sprite.h" - - -struct SpriteGroup *EvalDeterministicSpriteGroup(struct DeterministicSpriteGroup *dsg, int value) -{ - int i; - - value >>= dsg->shift_num; // This should bring us to the byte range. - value &= dsg->and_mask; - - if (dsg->operation != DSG_OP_NONE) - value += (signed char) dsg->add_val; - - switch (dsg->operation) { - case DSG_OP_DIV: - value /= (signed char) dsg->divmod_val; - break; - case DSG_OP_MOD: - value %= (signed char) dsg->divmod_val; - break; - case DSG_OP_NONE: - break; - } - - for (i = 0; i < dsg->num_ranges; i++) { - struct DeterministicSpriteGroupRange *range = &dsg->ranges[i]; - - if (range->low <= value && value <= range->high) - return &range->group; - } - - return dsg->default_group; -} - -int GetDeterministicSpriteValue(byte var) -{ - switch (var) { - case 0x00: - return _date; - case 0x01: - return _cur_year; - case 0x02: - return _cur_month; - case 0x03: - return _opt.landscape; - case 0x09: - return _date_fract; - case 0x0A: - return _tick_counter; - case 0x0C: - /* If we got here, it means there was no callback or - * callbacks aren't supported on our callpath. */ - return 0; - default: - return -1; - } -} +#include "stdafx.h" + +#include + +#include "ttd.h" +#include "sprite.h" + + +struct SpriteGroup *EvalDeterministicSpriteGroup(struct DeterministicSpriteGroup *dsg, int value) +{ + int i; + + value >>= dsg->shift_num; // This should bring us to the byte range. + value &= dsg->and_mask; + + if (dsg->operation != DSG_OP_NONE) + value += (signed char) dsg->add_val; + + switch (dsg->operation) { + case DSG_OP_DIV: + value /= (signed char) dsg->divmod_val; + break; + case DSG_OP_MOD: + value %= (signed char) dsg->divmod_val; + break; + case DSG_OP_NONE: + break; + } + + for (i = 0; i < dsg->num_ranges; i++) { + struct DeterministicSpriteGroupRange *range = &dsg->ranges[i]; + + if (range->low <= value && value <= range->high) + return &range->group; + } + + return dsg->default_group; +} + +int GetDeterministicSpriteValue(byte var) +{ + switch (var) { + case 0x00: + return _date; + case 0x01: + return _cur_year; + case 0x02: + return _cur_month; + case 0x03: + return _opt.landscape; + case 0x09: + return _date_fract; + case 0x0A: + return _tick_counter; + case 0x0C: + /* If we got here, it means there was no callback or + * callbacks aren't supported on our callpath. */ + return 0; + default: + return -1; + } +}