int test_prefs(void *state) { bool error = FALSE; graphics_mode *mode; /* This is a bit of a hack to ensure we have a player struct set up */ /* Otherwise race/class dependent graphics will crash */ cmdq_push(CMD_BIRTH_RESET); cmdq_execute(CMD_BIRTH); event_add_handler(EVENT_MESSAGE, getmsg, &error); for (mode = graphics_modes; mode; mode = mode->pNext) { /* Skip 'normal' */ if (mode->grafID == 0) continue; printf("Testing mode '%s'.\n", mode->menuname); /* Load pref file */ use_graphics = mode->grafID; reset_visuals(TRUE); } eq(error, FALSE); ok; }
int test_newgame(void *state) { /* Try making a new game */ cmdq_push(CMD_BIRTH_INIT); cmdq_push(CMD_BIRTH_RESET); cmdq_push(CMD_CHOOSE_RACE); cmd_set_arg_choice(cmdq_peek(), "choice", 0); cmdq_push(CMD_CHOOSE_CLASS); cmd_set_arg_choice(cmdq_peek(), "choice", 0); cmdq_push(CMD_ROLL_STATS); cmdq_push(CMD_NAME_CHOICE); cmd_set_arg_string(cmdq_peek(), "name", "Tester"); cmdq_push(CMD_ACCEPT_CHARACTER); cmdq_execute(CMD_BIRTH); eq(player->is_dead, FALSE); cave_generate(&cave, player); on_new_level(); noteq(cave, NULL); eq(player->chp, player->mhp); eq(player->food, PY_FOOD_FULL - 1); /* Should be all set up to save properly now */ eq(savefile_save("Test1"), TRUE); /* Make sure it saved properly */ eq(file_exists("Test1"), TRUE); ok; }
int test_magic_missile(void *state) { /* Try making a new game */ cmdq_push(CMD_BIRTH_INIT); cmdq_push(CMD_BIRTH_RESET); cmdq_push(CMD_CHOOSE_RACE); cmd_set_arg_choice(cmdq_peek(), "choice", 4); cmdq_push(CMD_CHOOSE_CLASS); cmd_set_arg_choice(cmdq_peek(), "choice", 1); cmdq_push(CMD_ROLL_STATS); cmdq_push(CMD_NAME_CHOICE); cmd_set_arg_string(cmdq_peek(), "name", "Tyrion"); cmdq_push(CMD_ACCEPT_CHARACTER); cmdq_execute(CMD_BIRTH); eq(player->is_dead, FALSE); cave_generate(&cave, player); on_new_level(); notnull(cave); eq(player->chp, player->mhp); eq(player->food, PY_FOOD_FULL - 1); cmdq_push(CMD_STUDY); cmd_set_arg_choice(cmdq_peek(), "spell", 0); run_game_loop(); cmdq_push(CMD_CAST); cmd_set_arg_choice(cmdq_peek(), "spell", 0); cmd_set_arg_target(cmdq_peek(), "target", 2); run_game_loop(); noteq(player->csp, player->msp); ok; }
/** * This is called when we receive a request for a command in the birth * process. * The birth process continues until we send a final character confirmation * command (or quit), so this is effectively called in a loop by the main * game. * * We're imposing a step-based system onto the main game here, so we need * to keep track of where we're up to, where each step moves on to, etc. */ int textui_do_birth(void) { enum birth_stage current_stage = BIRTH_RESET; enum birth_stage prev; enum birth_stage roller = BIRTH_RESET; enum birth_stage next = current_stage; bool done = FALSE; cmdq_push(CMD_BIRTH_INIT); cmdq_execute(CMD_BIRTH); while (!done) { switch (current_stage) { case BIRTH_RESET: { cmdq_push(CMD_BIRTH_RESET); roller = BIRTH_RESET; if (quickstart_allowed) next = BIRTH_QUICKSTART; else next = BIRTH_RACE_CHOICE; break; } case BIRTH_QUICKSTART: { display_player(0); next = textui_birth_quickstart(); if (next == BIRTH_COMPLETE) done = TRUE; break; } case BIRTH_CLASS_CHOICE: case BIRTH_RACE_CHOICE: case BIRTH_ROLLER_CHOICE: { struct menu *menu = &race_menu; cmd_code command = CMD_CHOOSE_RACE; Term_clear(); print_menu_instructions(); if (current_stage > BIRTH_RACE_CHOICE) { menu_refresh(&race_menu, FALSE); menu = &class_menu; command = CMD_CHOOSE_CLASS; } if (current_stage > BIRTH_CLASS_CHOICE) { menu_refresh(&class_menu, FALSE); menu = &roller_menu; } next = menu_question(current_stage, menu, command); if (next == BIRTH_BACK) next = current_stage - 1; /* Make sure the character gets reset before quickstarting */ if (next == BIRTH_QUICKSTART) next = BIRTH_RESET; break; } case BIRTH_POINTBASED: { roller = BIRTH_POINTBASED; if (prev > BIRTH_POINTBASED) point_based_start(); next = point_based_command(); if (next == BIRTH_BACK) next = BIRTH_ROLLER_CHOICE; if (next != BIRTH_POINTBASED) point_based_stop(); break; } case BIRTH_ROLLER: { roller = BIRTH_ROLLER; next = roller_command(prev < BIRTH_ROLLER); if (next == BIRTH_BACK) next = BIRTH_ROLLER_CHOICE; break; } case BIRTH_NAME_CHOICE: { if (prev < BIRTH_NAME_CHOICE) display_player(0); next = get_name_command(); if (next == BIRTH_BACK) next = roller; break; } case BIRTH_HISTORY_CHOICE: { if (prev < BIRTH_HISTORY_CHOICE) display_player(0); next = get_history_command(); if (next == BIRTH_BACK) next = BIRTH_NAME_CHOICE; break; } case BIRTH_FINAL_CONFIRM: { if (prev < BIRTH_FINAL_CONFIRM) display_player(0); next = get_confirm_command(); if (next == BIRTH_BACK) next = BIRTH_HISTORY_CHOICE; if (next == BIRTH_COMPLETE) done = TRUE; break; } default: { /* Remove dodgy compiler warning, */ } } prev = current_stage; current_stage = next; /* Execute whatever commands have been sent */ cmdq_execute(CMD_BIRTH); } return 0; }