Skip to content

Commit

Permalink
tr1/game-flow: use DoLevelSequence
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Feb 1, 2025
1 parent 981cd7a commit fa2b8e6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/tr1/game/game_flow/sequencer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

#include <libtrx/game/game_flow/sequencer.h>

GF_COMMAND GF_DoLevelSequence(
const GF_LEVEL *start_level, GF_SEQUENCE_CONTEXT seq_ctx);
GF_COMMAND GF_PlayAvailableStory(int32_t slot_num);
25 changes: 25 additions & 0 deletions src/tr1/game/game_flow/sequencer_misc.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "game/demo.h"
#include "game/game.h"
#include "game/game_flow/common.h"
#include "game/game_flow/sequencer.h"
#include "game/game_flow/vars.h"
Expand Down Expand Up @@ -37,3 +38,27 @@ GF_COMMAND GF_PlayAvailableStory(const int32_t slot_num)
}
return (GF_COMMAND) { .action = GF_EXIT_TO_TITLE };
}

GF_COMMAND GF_DoLevelSequence(
const GF_LEVEL *const start_level, const GF_SEQUENCE_CONTEXT seq_ctx)
{
const GF_LEVEL *current_level = start_level;
const GF_LEVEL_TABLE_TYPE level_table_type =
GF_GetLevelTableType(current_level->type);
const int32_t level_count = GF_GetLevelTable(level_table_type)->count;
while (true) {
const GF_COMMAND gf_cmd =
GF_InterpretSequence(current_level, seq_ctx, nullptr);

if (gf_cmd.action != GF_NOOP && gf_cmd.action != GF_LEVEL_COMPLETE) {
return gf_cmd;
}
if (Game_IsInGym()) {
return (GF_COMMAND) { .action = GF_EXIT_TO_TITLE };
}
if (current_level->num + 1 >= level_count) {
return (GF_COMMAND) { .action = GF_EXIT_TO_TITLE };
}
current_level++;
}
}
6 changes: 3 additions & 3 deletions src/tr1/game/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ void Shell_Main(void)
const int32_t level_num = gf_cmd.param;
const GF_LEVEL *const level = GF_GetLevel(GFLT_MAIN, level_num);
if (level != nullptr) {
gf_cmd = GF_InterpretSequence(level, GFSC_NORMAL, nullptr);
gf_cmd = GF_DoLevelSequence(level, GFSC_NORMAL);
}
break;
}

case GF_SELECT_GAME: {
const GF_LEVEL *const level = GF_GetLevel(GFLT_MAIN, gf_cmd.param);
gf_cmd = GF_InterpretSequence(level, GFSC_SELECT, nullptr);
gf_cmd = GF_DoLevelSequence(level, GFSC_NORMAL);
break;
}

Expand All @@ -222,7 +222,7 @@ void Shell_Main(void)
} else {
Savegame_BindSlot(slot_num);
const GF_LEVEL *const level = GF_GetLevel(GFLT_MAIN, level_num);
gf_cmd = GF_InterpretSequence(level, GFSC_SAVED, nullptr);
gf_cmd = GF_DoLevelSequence(level, GFSC_SAVED);
}
break;
}
Expand Down

0 comments on commit fa2b8e6

Please sign in to comment.