Skip to content

Commit

Permalink
tr2/game-flow: fix carrying final level stats
Browse files Browse the repository at this point in the history
Resolves #2480 where the final level statistics were not being added to
the overall cumulative stats. TR1 was not affected by this problem
because it records the current statistics in the resume/start
information for the current level, unlike TR2, which continues to store
these statistics in a separate structure.
  • Loading branch information
rr- committed Feb 10, 2025
1 parent 68d4e07 commit 843f963
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion data/tr1/ship/cfg/TR1X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@
{"type": "level_stats"},
{"type": "play_fmv", "fmv_id": 10},
{"type": "play_music", "music_track": 19},
{"type": "level_complete"},
{"type": "display_picture", "path": "data/images/end.webp", "display_time": 7.5, "fade_in_time": 1.0, "fade_out_time": 1.0},
{"type": "display_picture", "path": "data/images/credits_1.webp", "display_time": 7.5, "fade_in_time": 1.0, "fade_out_time": 1.0},
{"type": "display_picture", "path": "data/images/credits_2.webp", "display_time": 7.5, "fade_in_time": 1.0, "fade_out_time": 1.0},
{"type": "display_picture", "path": "data/images/credits_3.webp", "display_time": 7.5, "fade_in_time": 1.0, "fade_out_time": 1.0},
{"type": "total_stats", "background_path": "data/images/install.webp"},
{"type": "level_complete"},
],
"injections": [
"data/injections/pyramid_fd.bin",
Expand Down
2 changes: 1 addition & 1 deletion data/tr2/ship/cfg/TR2X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
{"type": "remove_medipacks"},
{"type": "loop_game"},
{"type": "play_music", "music_track": 52},
{"type": "level_complete"},
{"type": "display_picture", "path": "data/credit01.pcx", "display_time": 15, "fade_in_time": 0.5, "fade_out_time": 0.5},
{"type": "display_picture", "path": "data/credit02.pcx", "display_time": 15, "fade_in_time": 0.5, "fade_out_time": 0.5},
{"type": "display_picture", "path": "data/credit03.pcx", "display_time": 15, "fade_in_time": 0.5, "fade_out_time": 0.5},
Expand All @@ -353,7 +354,6 @@
{"type": "display_picture", "path": "data/credit07.pcx", "display_time": 15, "fade_in_time": 0.5, "fade_out_time": 0.5},
{"type": "display_picture", "path": "data/credit08.pcx", "display_time": 15, "fade_in_time": 0.5, "fade_out_time": 0.5},
{"type": "total_stats", "background_path": "data/end.pcx"},
{"type": "level_complete"},
],
"injections": [
"data/injections/house_itemrots.bin",
Expand Down
31 changes: 24 additions & 7 deletions src/libtrx/game/game_flow/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@
static const GF_LEVEL *m_CurrentLevel = nullptr;
static GF_COMMAND m_OverrideCommand = { .action = GF_NOOP };

static bool M_SkipLevel(const GF_LEVEL *level);
static void M_FreeSequence(GF_SEQUENCE *sequence);
static void M_FreeInjections(INJECTION_DATA *injections);
static void M_FreeLevel(GF_LEVEL *level);
static void M_FreeLevelTable(GF_LEVEL_TABLE *level_table);
static void M_FreeFMVs(GAME_FLOW *gf);

static bool M_SkipLevel(const GF_LEVEL *const level)
{
#if TR_VERSION == 1
return level->type == GFL_DUMMY || level->type == GFL_CURRENT;
#endif
return false;
}

static void M_FreeSequence(GF_SEQUENCE *const sequence)
{
Memory_Free(sequence->events);
Expand Down Expand Up @@ -171,11 +180,9 @@ const GF_LEVEL *GF_GetLastLevel(void)
if (level->type == GFL_GYM) {
continue;
}
#if TR_VERSION == 1
if (level->type == GFL_DUMMY || level->type == GFL_CURRENT) {
if (M_SkipLevel(level)) {
continue;
}
#endif
result = level;
}
return result;
Expand All @@ -200,9 +207,13 @@ const GF_LEVEL *GF_GetLevelAfter(const GF_LEVEL *const level)
GF_GetLevelTableType(level->type);
const GF_LEVEL_TABLE *const level_table =
GF_GetLevelTable(level_table_type);
return level->num + 1 < level_table->count
? &level_table->levels[level->num + 1]
: nullptr;
for (int32_t i = level->num + 1; i < level_table->count; i++) {
const GF_LEVEL *const next_level = &level_table->levels[i];
if (!M_SkipLevel(next_level)) {
return next_level;
}
}
return nullptr;
}

const GF_LEVEL *GF_GetLevelBefore(const GF_LEVEL *const level)
Expand All @@ -211,7 +222,13 @@ const GF_LEVEL *GF_GetLevelBefore(const GF_LEVEL *const level)
GF_GetLevelTableType(level->type);
const GF_LEVEL_TABLE *const level_table =
GF_GetLevelTable(level_table_type);
return level->num - 1 >= 0 ? &level_table->levels[level->num - 1] : nullptr;
for (int32_t i = level->num - 1; i >= 0; i--) {
const GF_LEVEL *const prev_level = &level_table->levels[i];
if (!M_SkipLevel(prev_level)) {
return prev_level;
}
}
return nullptr;
}

void GF_SetCurrentLevel(const GF_LEVEL *const level)
Expand Down
3 changes: 1 addition & 2 deletions src/tr1/game/game_flow/sequencer_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,8 @@ static DECLARE_GF_EVENT_HANDLER(M_HandleLevelComplete)
};
}

// missing level
if (next_level == nullptr) {
return (GF_COMMAND) { .action = GF_EXIT_TO_TITLE };
return (GF_COMMAND) { .action = GF_NOOP };
}

// carry info to the next level
Expand Down
2 changes: 1 addition & 1 deletion src/tr2/game/game_flow/sequencer_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static DECLARE_GF_EVENT_HANDLER(M_HandleLevelComplete)
g_SaveGame.current_level = next_level->num;
}
if (next_level == nullptr) {
return (GF_COMMAND) { .action = GF_EXIT_TO_TITLE };
return (GF_COMMAND) { .action = GF_NOOP };
}
return (GF_COMMAND) {
.action = GF_START_GAME,
Expand Down

0 comments on commit 843f963

Please sign in to comment.