Skip to content

Commit

Permalink
menu: add TF.DE contest mode entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Akaricchi committed Oct 9, 2024
1 parent c098579 commit 70fad20
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
30 changes: 28 additions & 2 deletions src/menu/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef struct StartGameContext {
Replay replay;
Difficulty difficulty;
ResourceGroup rg;
bool contest_mode;
} StartGameContext;

static void start_game_do_pick_character(CallChainResult ccr);
Expand Down Expand Up @@ -72,6 +73,21 @@ static void start_game_internal(MenuData *menu, StageInfo *info, bool difficulty
}
}

void start_game_contest(MenuData *m, void *arg) {
auto ctx = ALLOC(StartGameContext);
res_group_init(&ctx->rg);

StageInfo *info = stageinfo_get_by_id(5);
global.is_practice_mode = false;
ctx->current_stage = info;
ctx->restart_stage = info;
ctx->difficulty = D_Normal;
ctx->contest_mode = true;

CallChain cc_pick_character = CALLCHAIN(start_game_do_pick_character, ctx);
run_call_chain(&cc_pick_character, NULL);
}

static void start_game_do_pick_character(CallChainResult ccr) {
StartGameContext *ctx = ccr.ctx;
MenuData *prev_menu = ccr.result;
Expand Down Expand Up @@ -105,6 +121,11 @@ static void reset_game(StartGameContext *ctx) {
);
global.diff = ctx->difficulty;

if(ctx->contest_mode) {
global.plr.lives = 6;
global.plr.power_stored = 400;
}

assert(global.plr.mode != NULL);
}

Expand Down Expand Up @@ -156,7 +177,7 @@ static void start_game_do_leave_stage(CallChainResult ccr) {
} else {
CallChain cc;

if(global.gameover == GAMEOVER_WIN) {
if(global.gameover == GAMEOVER_WIN && !ctx->contest_mode) {
res_group_release(&ctx->rg);
res_purge();
credits_preload(&ctx->rg);
Expand All @@ -165,7 +186,12 @@ static void start_game_do_leave_stage(CallChainResult ccr) {
cc = CALLCHAIN(start_game_do_cleanup, ctx);
}

ask_save_replay(&ctx->replay, cc);
if(ctx->contest_mode) {
do_save_replay(&ctx->replay);
run_call_chain(&cc, NULL);
} else {
ask_save_replay(&ctx->replay, cc);
}
}
} else {
ask_save_replay(&ctx->replay, CALLCHAIN(start_game_do_cleanup, ctx));
Expand Down
1 change: 1 addition & 0 deletions src/menu/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

void start_game(MenuData *m, void *arg);
void start_game_no_difficulty_menu(MenuData *m, void *arg);
void start_game_contest(MenuData *m, void *arg);
void draw_menu_selector(float x, float y, float w, float h, float t);
void draw_menu_title(MenuData *m, const char *title);
void draw_menu_list(MenuData *m, float x, float y, void (*draw)(MenuEntry*, int, int, void*), float scroll_threshold, void *userdata);
Expand Down
1 change: 1 addition & 0 deletions src/menu/mainmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ MenuData* create_main_menu(void) {
ptrdiff_t stage_practice_idx, spell_practice_idx;

add_menu_entry(m, "Start Story", start_game, NULL);
add_menu_entry(m, "TF.DE Contest Mode", start_game_contest, NULL);
add_menu_entry(m, "Start Extra", NULL, NULL);
stage_practice_entry = add_menu_entry(m, "Stage Practice", menu_action_enter_stagepractice, NULL);
stage_practice_idx = dynarray_indexof(&m->entries, stage_practice_entry);
Expand Down
2 changes: 1 addition & 1 deletion src/menu/savereplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "video.h"

attr_nonnull_all
static void do_save_replay(Replay *rpy) {
void do_save_replay(Replay *rpy) {
char strtime[FILENAME_TIMESTAMP_MIN_BUF_SIZE], *name;
char prepr[16], drepr[16];

Expand Down
3 changes: 3 additions & 0 deletions src/menu/savereplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@

void ask_save_replay(Replay *rpy, CallChain next)
attr_nonnull(1);

void do_save_replay(Replay *rpy)
attr_nonnull(1);

0 comments on commit 70fad20

Please sign in to comment.