mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +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--;
|
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;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
42
newgrf.c
42
newgrf.c
@ -1228,6 +1228,21 @@ SpriteGroup *NewCallBackResultSpriteGroup(uint16 value)
|
|||||||
return group;
|
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 */
|
/* Action 0x01 */
|
||||||
static void NewSpriteSet(byte *buf, int len)
|
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++) {
|
for (i = 0; i < rg->num_groups; i++) {
|
||||||
uint16 groupid = grf_load_word(&buf);
|
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. */
|
/* This doesn't exist for us. */
|
||||||
i--;
|
i--;
|
||||||
rg->num_groups--;
|
rg->num_groups--;
|
||||||
continue;
|
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;
|
_cur_grffile->spritegroups[setid] = group;
|
||||||
@ -1476,14 +1494,22 @@ static void NewSpriteGroup(byte *buf, int len)
|
|||||||
|
|
||||||
for (i = 0; i < numloaded; i++) {
|
for (i = 0; i < numloaded; i++) {
|
||||||
uint16 spriteset_id = grf_load_word(&loaded_ptr);
|
uint16 spriteset_id = grf_load_word(&loaded_ptr);
|
||||||
rg->loaded[i] = _cur_grffile->spriteset_start + spriteset_id * _cur_grffile->spriteset_numents;
|
if (HASBIT(spriteset_id, 15)) {
|
||||||
DEBUG(grf, 8) ("NewSpriteGroup: + rg->loaded[%i] = %u (subset %u)", i, rg->loaded[i], spriteset_id);
|
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++) {
|
for (i = 0; i < numloading; i++) {
|
||||||
uint16 spriteset_id = grf_load_word(&loading_ptr);
|
uint16 spriteset_id = grf_load_word(&loading_ptr);
|
||||||
rg->loading[i] = _cur_grffile->spriteset_start + spriteset_id * _cur_grffile->spriteset_numents;
|
if (HASBIT(spriteset_id, 15)) {
|
||||||
DEBUG(grf, 8) ("NewSpriteGroup: + rg->loading[%i] = %u (subset %u)", i, rg->loading[i], spriteset_id);
|
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;
|
_cur_grffile->spritegroups[setid] = group;
|
||||||
|
11
sprite.h
11
sprite.h
@ -44,9 +44,9 @@ typedef struct RealSpriteGroup {
|
|||||||
// of da stuff.
|
// of da stuff.
|
||||||
|
|
||||||
byte loaded_count;
|
byte loaded_count;
|
||||||
uint16 loaded[16]; // sprite ids
|
SpriteGroup *loaded[16]; // sprite ids
|
||||||
byte loading_count;
|
byte loading_count;
|
||||||
uint16 loading[16]; // sprite ids
|
SpriteGroup *loading[16]; // sprite ids
|
||||||
} RealSpriteGroup;
|
} RealSpriteGroup;
|
||||||
|
|
||||||
/* Shared by deterministic and random groups. */
|
/* Shared by deterministic and random groups. */
|
||||||
@ -114,11 +114,17 @@ typedef struct CallbackResultSpriteGroup {
|
|||||||
uint16 result;
|
uint16 result;
|
||||||
} CallbackResultSpriteGroup;
|
} CallbackResultSpriteGroup;
|
||||||
|
|
||||||
|
typedef struct ResultSpriteGroup {
|
||||||
|
uint16 result;
|
||||||
|
byte sprites;
|
||||||
|
} ResultSpriteGroup;
|
||||||
|
|
||||||
typedef enum SpriteGroupType {
|
typedef enum SpriteGroupType {
|
||||||
SGT_REAL,
|
SGT_REAL,
|
||||||
SGT_DETERMINISTIC,
|
SGT_DETERMINISTIC,
|
||||||
SGT_RANDOMIZED,
|
SGT_RANDOMIZED,
|
||||||
SGT_CALLBACK,
|
SGT_CALLBACK,
|
||||||
|
SGT_RESULT,
|
||||||
} SpriteGroupType;
|
} SpriteGroupType;
|
||||||
|
|
||||||
struct SpriteGroup {
|
struct SpriteGroup {
|
||||||
@ -129,6 +135,7 @@ struct SpriteGroup {
|
|||||||
DeterministicSpriteGroup determ;
|
DeterministicSpriteGroup determ;
|
||||||
RandomizedSpriteGroup random;
|
RandomizedSpriteGroup random;
|
||||||
CallbackResultSpriteGroup callback;
|
CallbackResultSpriteGroup callback;
|
||||||
|
ResultSpriteGroup result;
|
||||||
} g;
|
} g;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1349,9 +1349,9 @@ uint32 GetCustomStationRelocation(const StationSpec *spec, const Station *st, by
|
|||||||
const RealSpriteGroup *rsg = ResolveStationSpriteGroup(spec->spritegroup[ctype], st);
|
const RealSpriteGroup *rsg = ResolveStationSpriteGroup(spec->spritegroup[ctype], st);
|
||||||
|
|
||||||
if (rsg->sprites_per_set != 0) {
|
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.",
|
error("Custom station 0x%08x::0x%02x has no sprites associated.",
|
||||||
|
Loading…
Reference in New Issue
Block a user