summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine.c2
-rw-r--r--newgrf.c42
-rw-r--r--sprite.h11
-rw-r--r--station_cmd.c4
4 files changed, 46 insertions, 13 deletions
diff --git a/engine.c b/engine.c
index 26f472080..71b55b64c 100644
--- a/engine.c
+++ b/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;
}
diff --git a/newgrf.c b/newgrf.c
index 2d1542561..ef4fa1f3f 100644
--- a/newgrf.c
+++ b/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;
diff --git a/sprite.h b/sprite.h
index 2bacfd734..2e1938cac 100644
--- a/sprite.h
+++ b/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;
};
diff --git a/station_cmd.c b/station_cmd.c
index 4a62781f3..6275e0fb7 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -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.",