mirror of https://github.com/OpenTTD/OpenTTD
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
parent
ec434b208e
commit
051e094921
18
engine.c
18
engine.c
|
@ -243,14 +243,26 @@ void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteGroup *group)
|
||||||
_engine_custom_sprites[engine][cargo] = *group;
|
_engine_custom_sprites[engine][cargo] = *group;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetCustomEngineSprite(byte engine, uint16 overriding_engine, byte cargo,
|
int GetCustomEngineSprite(byte engine, Vehicle *v, byte direction)
|
||||||
byte loaded, byte in_motion, byte direction)
|
|
||||||
{
|
{
|
||||||
struct SpriteGroup *group = &_engine_custom_sprites[engine][cargo];
|
struct SpriteGroup *group;
|
||||||
struct RealSpriteGroup *rsg;
|
struct RealSpriteGroup *rsg;
|
||||||
|
uint16 overriding_engine = -1;
|
||||||
|
byte cargo = CID_PURCHASE;
|
||||||
|
byte loaded = 0;
|
||||||
|
byte in_motion = 0;
|
||||||
int totalsets, spriteset;
|
int totalsets, spriteset;
|
||||||
int r;
|
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) {
|
if (overriding_engine != 0xffff) {
|
||||||
struct SpriteGroup *overset;
|
struct SpriteGroup *overset;
|
||||||
|
|
||||||
|
|
11
engine.h
11
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 SetWagonOverrideSprites(byte engine, struct SpriteGroup *group, byte *train_id, int trains);
|
||||||
void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteGroup *group);
|
void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteGroup *group);
|
||||||
// loaded is in percents, overriding_engine 0xffff is none
|
// 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);
|
int GetCustomEngineSprite(byte engine, Vehicle *v, byte direction);
|
||||||
#define GetCustomVehicleSprite(v, direction) \
|
#define GetCustomVehicleSprite(v, direction) GetCustomEngineSprite(v->engine_type, v, direction)
|
||||||
GetCustomEngineSprite(v->engine_type, v->type == VEH_Train ? v->u.rail.first_engine : -1, \
|
#define GetCustomVehicleIcon(et, direction) GetCustomEngineSprite(et, NULL, direction)
|
||||||
_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)
|
|
||||||
|
|
||||||
void SetCustomEngineName(int engine, char *name);
|
void SetCustomEngineName(int engine, char *name);
|
||||||
StringID GetCustomEngineName(int engine);
|
StringID GetCustomEngineName(int engine);
|
||||||
|
|
124
sprite.c
124
sprite.c
|
@ -1,62 +1,62 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "ttd.h"
|
#include "ttd.h"
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
|
|
||||||
|
|
||||||
struct SpriteGroup *EvalDeterministicSpriteGroup(struct DeterministicSpriteGroup *dsg, int value)
|
struct SpriteGroup *EvalDeterministicSpriteGroup(struct DeterministicSpriteGroup *dsg, int value)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
value >>= dsg->shift_num; // This should bring us to the byte range.
|
value >>= dsg->shift_num; // This should bring us to the byte range.
|
||||||
value &= dsg->and_mask;
|
value &= dsg->and_mask;
|
||||||
|
|
||||||
if (dsg->operation != DSG_OP_NONE)
|
if (dsg->operation != DSG_OP_NONE)
|
||||||
value += (signed char) dsg->add_val;
|
value += (signed char) dsg->add_val;
|
||||||
|
|
||||||
switch (dsg->operation) {
|
switch (dsg->operation) {
|
||||||
case DSG_OP_DIV:
|
case DSG_OP_DIV:
|
||||||
value /= (signed char) dsg->divmod_val;
|
value /= (signed char) dsg->divmod_val;
|
||||||
break;
|
break;
|
||||||
case DSG_OP_MOD:
|
case DSG_OP_MOD:
|
||||||
value %= (signed char) dsg->divmod_val;
|
value %= (signed char) dsg->divmod_val;
|
||||||
break;
|
break;
|
||||||
case DSG_OP_NONE:
|
case DSG_OP_NONE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < dsg->num_ranges; i++) {
|
for (i = 0; i < dsg->num_ranges; i++) {
|
||||||
struct DeterministicSpriteGroupRange *range = &dsg->ranges[i];
|
struct DeterministicSpriteGroupRange *range = &dsg->ranges[i];
|
||||||
|
|
||||||
if (range->low <= value && value <= range->high)
|
if (range->low <= value && value <= range->high)
|
||||||
return &range->group;
|
return &range->group;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dsg->default_group;
|
return dsg->default_group;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetDeterministicSpriteValue(byte var)
|
int GetDeterministicSpriteValue(byte var)
|
||||||
{
|
{
|
||||||
switch (var) {
|
switch (var) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
return _date;
|
return _date;
|
||||||
case 0x01:
|
case 0x01:
|
||||||
return _cur_year;
|
return _cur_year;
|
||||||
case 0x02:
|
case 0x02:
|
||||||
return _cur_month;
|
return _cur_month;
|
||||||
case 0x03:
|
case 0x03:
|
||||||
return _opt.landscape;
|
return _opt.landscape;
|
||||||
case 0x09:
|
case 0x09:
|
||||||
return _date_fract;
|
return _date_fract;
|
||||||
case 0x0A:
|
case 0x0A:
|
||||||
return _tick_counter;
|
return _tick_counter;
|
||||||
case 0x0C:
|
case 0x0C:
|
||||||
/* If we got here, it means there was no callback or
|
/* If we got here, it means there was no callback or
|
||||||
* callbacks aren't supported on our callpath. */
|
* callbacks aren't supported on our callpath. */
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue