mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-04 06:00:15 +00:00
(svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
This commit is contained in:
parent
e8bca26b74
commit
4879e04986
2
engine.c
2
engine.c
@ -580,7 +580,7 @@ int GetCustomEngineSprite(EngineID engine, const Vehicle *v, byte direction)
|
||||
spriteset--;
|
||||
}
|
||||
|
||||
r = (in_motion ? rsg->loaded[spriteset] : rsg->loading[spriteset]) + direction;
|
||||
r = (in_motion ? rsg->loaded[spriteset]->g.result.result : rsg->loading[spriteset]->g.result.result) + direction;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
42
newgrf.c
42
newgrf.c
@ -1228,6 +1228,21 @@ SpriteGroup *NewCallBackResultSpriteGroup(uint16 value)
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a spritegroup representing a sprite number result.
|
||||
* @param value The sprite number.
|
||||
* @param sprites The number of sprites per set.
|
||||
* @return A spritegroup representing the sprite number result.
|
||||
*/
|
||||
SpriteGroup *NewResultSpriteGroup(uint16 value, byte sprites)
|
||||
{
|
||||
SpriteGroup *group = calloc(1, sizeof(*group));
|
||||
group->type = SGT_RESULT;
|
||||
group->g.result.result = value;
|
||||
group->g.result.sprites = sprites;
|
||||
return group;
|
||||
}
|
||||
|
||||
/* Action 0x01 */
|
||||
static void NewSpriteSet(byte *buf, int len)
|
||||
{
|
||||
@ -1421,15 +1436,18 @@ static void NewSpriteGroup(byte *buf, int len)
|
||||
for (i = 0; i < rg->num_groups; i++) {
|
||||
uint16 groupid = grf_load_word(&buf);
|
||||
|
||||
if (groupid & 0x8000 || groupid >= _cur_grffile->spritegroups_count) {
|
||||
if (HASBIT(groupid, 15)) {
|
||||
rg->groups[i] = NewCallBackResultSpriteGroup(groupid);
|
||||
} else if (groupid >= _cur_grffile->spritegroups_count) {
|
||||
/* This doesn't exist for us. */
|
||||
i--;
|
||||
rg->num_groups--;
|
||||
continue;
|
||||
} else {
|
||||
/* XXX: If multiple surreal sets attach a surreal
|
||||
* set this way, we are in trouble. */
|
||||
rg->groups[i] = _cur_grffile->spritegroups[groupid];
|
||||
}
|
||||
/* XXX: If multiple surreal sets attach a surreal
|
||||
* set this way, we are in trouble. */
|
||||
rg->groups[i] = _cur_grffile->spritegroups[groupid];
|
||||
}
|
||||
|
||||
_cur_grffile->spritegroups[setid] = group;
|
||||
@ -1476,14 +1494,22 @@ static void NewSpriteGroup(byte *buf, int len)
|
||||
|
||||
for (i = 0; i < numloaded; i++) {
|
||||
uint16 spriteset_id = grf_load_word(&loaded_ptr);
|
||||
rg->loaded[i] = _cur_grffile->spriteset_start + spriteset_id * _cur_grffile->spriteset_numents;
|
||||
DEBUG(grf, 8) ("NewSpriteGroup: + rg->loaded[%i] = %u (subset %u)", i, rg->loaded[i], spriteset_id);
|
||||
if (HASBIT(spriteset_id, 15)) {
|
||||
rg->loaded[i] = NewCallBackResultSpriteGroup(spriteset_id);
|
||||
} else {
|
||||
rg->loaded[i] = NewResultSpriteGroup(_cur_grffile->spriteset_start + spriteset_id * _cur_grffile->spriteset_numents, rg->sprites_per_set);
|
||||
}
|
||||
DEBUG(grf, 8) ("NewSpriteGroup: + rg->loaded[%i] = %u (subset %u)", i, rg->loaded[i]->g.result.result, spriteset_id);
|
||||
}
|
||||
|
||||
for (i = 0; i < numloading; i++) {
|
||||
uint16 spriteset_id = grf_load_word(&loading_ptr);
|
||||
rg->loading[i] = _cur_grffile->spriteset_start + spriteset_id * _cur_grffile->spriteset_numents;
|
||||
DEBUG(grf, 8) ("NewSpriteGroup: + rg->loading[%i] = %u (subset %u)", i, rg->loading[i], spriteset_id);
|
||||
if (HASBIT(spriteset_id, 15)) {
|
||||
rg->loading[i] = NewCallBackResultSpriteGroup(spriteset_id);
|
||||
} else {
|
||||
rg->loading[i] = NewResultSpriteGroup(_cur_grffile->spriteset_start + spriteset_id * _cur_grffile->spriteset_numents, rg->sprites_per_set);
|
||||
}
|
||||
DEBUG(grf, 8) ("NewSpriteGroup: + rg->loading[%i] = %u (subset %u)", i, rg->loading[i]->g.result.result, spriteset_id);
|
||||
}
|
||||
|
||||
_cur_grffile->spritegroups[setid] = group;
|
||||
|
11
sprite.h
11
sprite.h
@ -44,9 +44,9 @@ typedef struct RealSpriteGroup {
|
||||
// of da stuff.
|
||||
|
||||
byte loaded_count;
|
||||
uint16 loaded[16]; // sprite ids
|
||||
SpriteGroup *loaded[16]; // sprite ids
|
||||
byte loading_count;
|
||||
uint16 loading[16]; // sprite ids
|
||||
SpriteGroup *loading[16]; // sprite ids
|
||||
} RealSpriteGroup;
|
||||
|
||||
/* Shared by deterministic and random groups. */
|
||||
@ -114,11 +114,17 @@ typedef struct CallbackResultSpriteGroup {
|
||||
uint16 result;
|
||||
} CallbackResultSpriteGroup;
|
||||
|
||||
typedef struct ResultSpriteGroup {
|
||||
uint16 result;
|
||||
byte sprites;
|
||||
} ResultSpriteGroup;
|
||||
|
||||
typedef enum SpriteGroupType {
|
||||
SGT_REAL,
|
||||
SGT_DETERMINISTIC,
|
||||
SGT_RANDOMIZED,
|
||||
SGT_CALLBACK,
|
||||
SGT_RESULT,
|
||||
} SpriteGroupType;
|
||||
|
||||
struct SpriteGroup {
|
||||
@ -129,6 +135,7 @@ struct SpriteGroup {
|
||||
DeterministicSpriteGroup determ;
|
||||
RandomizedSpriteGroup random;
|
||||
CallbackResultSpriteGroup callback;
|
||||
ResultSpriteGroup result;
|
||||
} g;
|
||||
};
|
||||
|
||||
|
@ -1349,9 +1349,9 @@ uint32 GetCustomStationRelocation(const StationSpec *spec, const Station *st, by
|
||||
const RealSpriteGroup *rsg = ResolveStationSpriteGroup(spec->spritegroup[ctype], st);
|
||||
|
||||
if (rsg->sprites_per_set != 0) {
|
||||
if (rsg->loading_count != 0) return rsg->loading[0];
|
||||
if (rsg->loading_count != 0) return rsg->loading[0]->g.result.result;
|
||||
|
||||
if (rsg->loaded_count != 0) return rsg->loaded[0];
|
||||
if (rsg->loaded_count != 0) return rsg->loaded[0]->g.result.result;
|
||||
}
|
||||
|
||||
error("Custom station 0x%08x::0x%02x has no sprites associated.",
|
||||
|
Loading…
Reference in New Issue
Block a user