Skip to content

Commit

Permalink
uinewgame: Add challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
1oom-fork committed Aug 21, 2024
1 parent 935b4b2 commit 170f409
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ int main_do(void)
}
while (1) {
struct game_new_options_s game_new_opts = GAME_NEW_OPTS_DEFAULT;
struct game_new_options_s game_challenge_opts = GAME_NEW_OPTS_DEFAULT;
main_menu_action_t main_menu_action;
int load_game_i = 0;

Expand Down Expand Up @@ -779,7 +780,7 @@ int main_do(void)
} else {
game_set_opts_from_value(&game_new_opts, game_opt_new_value);
game_set_custom_opts_from_cfg(&game_opt_custom);
main_menu_action = ui_main_menu(&game_new_opts, &game_opt_custom, &load_game_i);
main_menu_action = ui_main_menu(&game_new_opts, &game_opt_custom, &game_challenge_opts, &load_game_i);
}
switch (main_menu_action) {
case MAIN_MENU_ACT_NEW_GAME:
Expand All @@ -797,6 +798,12 @@ int main_do(void)
game_save_do_save_i(GAME_SAVE_I_INIT, "Init", &game);
}
break;
case MAIN_MENU_ACT_CHALLENGE_GAME:
game_new(&game, &game_aux, &game_challenge_opts);
if (game_opt_init_save_enabled) {
game_save_do_save_i(GAME_SAVE_I_INIT, "Init", &game);
}
break;
case MAIN_MENU_ACT_TUTOR:
game_new_tutor(&game, &game_aux);
break;
Expand Down
18 changes: 18 additions & 0 deletions src/game/game_new.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ struct game_new_options_s {
} \
}

#define GAME_NEW_OPTS_CHALLENGE_118835000 \
{ \
1, 1, 118835000, GALAXY_SIZE_SMALL, DIFFICULTY_IMPOSSIBLE, 0, 6, \
{ \
100, PLANET_SPECIAL_NORMAL, \
6, 6, \
2, 0, 1, false \
}, \
{ \
{ "", "", RACE_HUMAN, BANNER_BLUE, false }, \
{ "", "", RACE_MRRSHAN, BANNER_RANDOM, true }, \
{ "", "", RACE_SAKKRA, BANNER_RANDOM, true }, \
{ "", "", RACE_PSILON, BANNER_RANDOM, true }, \
{ "", "", RACE_KLACKON, BANNER_RANDOM, true }, \
{ "", "", RACE_SILICOID, BANNER_RANDOM, true } \
} \
}

struct game_aux_s;

extern int game_new(struct game_s *g, struct game_aux_s *gaux, struct game_new_options_s *opt);
Expand Down
3 changes: 2 additions & 1 deletion src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extern void ui_play_ending_exile(const char *name);
typedef enum {
MAIN_MENU_ACT_NEW_GAME,
MAIN_MENU_ACT_CUSTOM_GAME,
MAIN_MENU_ACT_CHALLENGE_GAME,
MAIN_MENU_ACT_LOAD_GAME,
MAIN_MENU_ACT_CONTINUE_GAME,
MAIN_MENU_ACT_QUIT_GAME,
Expand All @@ -41,7 +42,7 @@ typedef enum {

struct game_new_options_s;

extern main_menu_action_t ui_main_menu(struct game_new_options_s *newopts, struct game_new_options_s *customopts, int *load_game_i_ptr);
extern main_menu_action_t ui_main_menu(struct game_new_options_s *newopts, struct game_new_options_s *customopts, struct game_new_options_s *challengeopts, int *load_game_i_ptr);

struct game_s;
struct game_end_s;
Expand Down
7 changes: 6 additions & 1 deletion src/ui/classic/uimainmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ static void main_menu_make_game_page(struct main_menu_data_s *d)
menu_make_action_conditional(menu_allocate_item(), "Load Game", MAIN_MENU_ACT_LOAD_GAME, main_menu_have_save_any, MOO_KEY_l);
menu_make_action(menu_allocate_item(), "New Game", MAIN_MENU_ACT_NEW_GAME, MOO_KEY_n);
menu_make_page(menu_allocate_item(), "Custom Game", MAIN_MENU_PAGE_GAME_CUSTOM, MOO_KEY_u);
menu_make_action(menu_allocate_item(), "Challenge", MAIN_MENU_ACT_CHALLENGE_GAME, MOO_KEY_h);
menu_make_back(menu_allocate_item());
}

Expand Down Expand Up @@ -903,7 +904,7 @@ static main_menu_action_t main_menu_do(struct main_menu_data_s *d)

/* -------------------------------------------------------------------------- */

main_menu_action_t ui_main_menu(struct game_new_options_s *newopts, struct game_new_options_s *customopts, int *load_game_i_ptr)
main_menu_action_t ui_main_menu(struct game_new_options_s *newopts, struct game_new_options_s *customopts, struct game_new_options_s *challengeopts, int *load_game_i_ptr)
{
struct main_menu_data_s d;
bool flag_done = false;
Expand All @@ -925,6 +926,10 @@ main_menu_action_t ui_main_menu(struct game_new_options_s *newopts, struct game_
flag_done = ui_custom_game(customopts);
ui_draw_finish_mode = 1;
break;
case MAIN_MENU_ACT_CHALLENGE_GAME:
flag_done = ui_challenge_game(challengeopts);
ui_draw_finish_mode = 1;
break;
case MAIN_MENU_ACT_LOAD_GAME:
{
int i;
Expand Down
38 changes: 38 additions & 0 deletions src/ui/classic/uinewgame.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,3 +572,41 @@ bool ui_custom_game(struct game_new_options_s *newopts) {
new_game_free_data(&d);
return flag_ok;
}

bool ui_challenge_game(struct game_new_options_s *newopts) {
static const struct game_new_options_s challenge = GAME_NEW_OPTS_CHALLENGE_118835000;
struct new_game_data_s d;
bool flag_ok = false;

d.newopts = newopts;
*d.newopts = challenge;

new_game_load_data(&d);

flag_ok = ui_new_game_racebannernames(newopts, &d);

uiobj_unset_callback();
new_game_free_data(&d);

if (d.newopts->pdata[0].race == RACE_MRRSHAN) {
d.newopts->pdata[1].race = RACE_ALKARI;
}

if (d.newopts->pdata[0].race == RACE_SAKKRA) {
d.newopts->pdata[2].race = RACE_MEKLAR;
}

if (d.newopts->pdata[0].race == RACE_PSILON) {
d.newopts->pdata[3].race = RACE_HUMAN;
}

if (d.newopts->pdata[0].race == RACE_KLACKON) {
d.newopts->pdata[4].race = RACE_MEKLAR;
}

if (d.newopts->pdata[0].race == RACE_SILICOID) {
d.newopts->pdata[5].race = RACE_HUMAN;
}

return flag_ok;
}
1 change: 1 addition & 0 deletions src/ui/classic/uinewgame.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ struct game_new_options_s;
/* returns false on cancel */
extern bool ui_new_game(struct game_new_options_s *newopts);
extern bool ui_custom_game(struct game_new_options_s *newopts);
extern bool ui_challenge_game(struct game_new_options_s *newopts);

#endif
2 changes: 1 addition & 1 deletion src/ui/cmdline/uimainmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ static bool ui_new_game(struct game_new_options_s *newopts)

/* -------------------------------------------------------------------------- */

main_menu_action_t ui_main_menu(struct game_new_options_s *newopts, struct game_new_options_s *customopts, int *load_game_i_ptr)
main_menu_action_t ui_main_menu(struct game_new_options_s *newopts, struct game_new_options_s *customopts, struct game_new_options_s *challengeopts, int *load_game_i_ptr)
{
struct input_list_s main_menu_in[] = {
{ MAIN_MENU_ACT_CONTINUE_GAME, "C", NULL, game_str_mm_continue },
Expand Down

0 comments on commit 170f409

Please sign in to comment.