void display_grid(t_grid *grid) { int x; int y; display_strart(grid); x = 0; while (x < grid->lines) { y = 0; while (y < grid->columns) { ft_putstr("\033[34mx "); if (!grid->grid[x][y]) ft_putchar(' '); else display_player(grid->grid[x][y]); ft_putchar(' '); y++; } ft_putstr("\033[34mx\n"); if (x != grid->lines - 1) display_inter(grid); x++; } display_end(grid); }
void display_essentials(struct Game *game) { display_stars(game); display_asteroids(game); display_player(game); }
int exec_fct(SDL_Surface *screen, t_map *map) { t_player player; int continuer; t_image img; int jump; t_npc *monsters; SDL_EnableKeyRepeat(10, 10); continuer = 1; monsters = init_all(&img, &player, map); jump = 0; while (continuer > 0) { display_map(screen, map, &img); display_npcs(screen, monsters); display_player(screen, &player); display_life(screen, &player); SDL_Flip(screen); continuer = gravite(&player, map); if (continuer >= 0) player_act(&continuer, map, &player); if (continuer > 0) continuer = env_act(map, &player, monsters); } img_delete(&img); return (continuer); }
/* * Get the Sex. */ static bool get_sex(void) { char query2; int loopagain = TRUE; // Set the default sex info to female if (p_ptr->psex == SEX_UNDEFINED) { p_ptr->psex = SEX_FEMALE; sp_ptr = &sex_info[SEX_FEMALE]; } while (loopagain == TRUE) { /* Display the player */ display_player(0); // Highlight the relevant feature c_put_str(TERM_YELLOW, sp_ptr->title, 3, 8); /* Prompt */ Term_putstr(QUESTION_COL, INSTRUCT_ROW + 1, -1, TERM_SLATE, "Enter accept sex"); Term_putstr(QUESTION_COL, INSTRUCT_ROW + 2, -1, TERM_SLATE, "Space change sex"); /* Hack - highlight the key names */ Term_putstr(QUESTION_COL, INSTRUCT_ROW + 1, - 1, TERM_L_WHITE, "Enter"); Term_putstr(QUESTION_COL, INSTRUCT_ROW + 2, - 1, TERM_L_WHITE, "Space"); /* Move the cursor */ Term_gotoxy(0, INSTRUCT_ROW + 1); /* Query */ query2 = inkey(); if ((query2 == '\r') || (query2 == '\n')) { /* got a sex*/ loopagain = FALSE; p_ptr->redraw |= (PR_MISC); } else if (query2 == ESCAPE) return (FALSE); else if (((query2 == 'Q') || (query2 == 'q')) && (turn == 0)) quit (NULL); else { if (p_ptr->psex == SEX_FEMALE) p_ptr->psex = SEX_MALE; else p_ptr->psex = SEX_FEMALE; sp_ptr = &sex_info[p_ptr->psex]; } } return (TRUE); }
/** * ------------------------------------------------------------------------ * The rolling bit of the roller. * ------------------------------------------------------------------------ */ static enum birth_stage roller_command(bool first_call) { char prompt[80] = ""; size_t promptlen = 0; struct keypress ch; enum birth_stage next = BIRTH_ROLLER; /* Used to keep track of whether we've rolled a character before or not. */ static bool prev_roll = FALSE; /* Display the player - a bit cheaty, but never mind. */ display_player(0); if (first_call) prev_roll = FALSE; /* Prepare a prompt (must squeeze everything in) */ strnfcat(prompt, sizeof (prompt), &promptlen, "['r' to reroll"); if (prev_roll) strnfcat(prompt, sizeof(prompt), &promptlen, ", 'p' for previous roll"); strnfcat(prompt, sizeof (prompt), &promptlen, " or 'Enter' to accept]"); /* Prompt for it */ prt(prompt, Term->hgt - 1, Term->wid / 2 - promptlen / 2); /* Prompt and get a command */ ch = inkey(); /* Analyse the command */ if (ch.code == ESCAPE) { /* Back out */ next = BIRTH_BACK; } else if (ch.code == KC_ENTER) { /* 'Enter' accepts the roll */ next = BIRTH_NAME_CHOICE; } else if ((ch.code == ' ') || (ch.code == 'r')) { /* Reroll this character */ cmdq_push(CMD_ROLL_STATS); prev_roll = TRUE; } else if (prev_roll && (ch.code == 'p')) { /* Previous character */ cmdq_push(CMD_PREV_STATS); } else if (ch.code == KTRL('X')) { /* Quit */ quit(NULL); } else if (ch.code == '?') { /* Help XXX */ do_cmd_help(); } else { /* Nothing handled directly here */ bell("Illegal roller command!"); } return next; }
int display_sdl(t_graphic *c) { if (SDL_FillRect(c->display.list[WINDOW], NULL, 0x000000) == -1) return (my_error(SDL_GetError(), FAILURE)); if (c->map != NULL && (display_map(c) == FAILURE || display_items(c) == FAILURE || display_eggs(c) == FAILURE || display_player(c) == FAILURE || display_anims(c) == FAILURE || display_gui(c) == FAILURE)) return (FAILURE); if (SDL_Flip(c->display.list[WINDOW]) == -1) return (my_error(SDL_GetError(), FAILURE)); if (SDL_PollEvent(&c->display.event) == -1) return (my_error((SDL_GetError()), FAILURE)); SDL_Delay(1000 * 7 / c->time / NB_SPRITES_ANIM); return (event(c)); }
// Clears and redraws the entire interface. static void display_all(void) { for (i8 y = 1; y < ARRAY_SIZE(g.board) - 1; ++y) for (i8 x = 1; x < ARRAY_SIZE(*g.board) - 1; ++x) display_tile({x, y}); for (Trap *t = g.traps; t->pos.x; ++t) if (TILE(t->pos).revealed && !TILE(t->pos).destroyed) display_trap(t); Coords pos = {64, 1}; for (Monster *m = &g.monsters[g.last_monster]; m != &player; --m) if (m->hp && (m->aggro || TILE(m->pos).revealed || g.head == HEAD_CIRCLET)) display_monster(m, pos); for (++pos.y; pos.y < 50; ++pos.y) print_at(pos, "\033[K"); display_player(); print_at({0, 0}, "%s\033[K", g.game_over? player.hp ? "You won!" : "You died..." : ""); }
/* * Get the racial history, and social class, using the "history charts". */ static bool get_history(void) { int i; char line[70]; char query2; int loopagain = TRUE; // hack to see whether we are opening an old player file bool roll_history = !(p_ptr->history[0]); while (loopagain == TRUE) { if (roll_history) { /*get the random history, display for approval. */ get_history_aux(); } else { roll_history = TRUE; } /* Display the player */ display_player(0); // Highlight relevant info display_player_xtra_info(2); /* Prompt */ Term_putstr(QUESTION_COL, INSTRUCT_ROW + 1, -1, TERM_SLATE, "Enter accept history"); Term_putstr(QUESTION_COL, INSTRUCT_ROW + 2, -1, TERM_SLATE, "Space reroll history"); Term_putstr(QUESTION_COL, INSTRUCT_ROW + 3, -1, TERM_SLATE, " m manually enter history"); /* Hack - highlight the key names */ Term_putstr(QUESTION_COL, INSTRUCT_ROW + 1, - 1, TERM_L_WHITE, "Enter"); Term_putstr(QUESTION_COL, INSTRUCT_ROW + 2, - 1, TERM_L_WHITE, "Space"); Term_putstr(QUESTION_COL + 4, INSTRUCT_ROW + 3, - 1, TERM_L_WHITE, "m"); /* Move the cursor */ Term_gotoxy(0, INSTRUCT_ROW + 1); /* Query */ query2 = inkey(); if ((query2 == '\r') || (query2 == '\n')) { /* got a history*/ loopagain = FALSE; p_ptr->redraw |= (PR_MISC); } else if ((query2 == 'm') || (query2 == 'M')) { /* don't want a random history */ /* Clear the previous history strings */ p_ptr->history[0] = '\0'; /* Display the player */ display_player(0); for (i = 1; i <= 3; i++) { // clear line line[0] = '\0'; Term_gotoxy(1, 15+i); /* Prompt for a new history */ if (askfor_aux(line, sizeof(line))) { /* Get the textual history */ my_strcat(p_ptr->history, line, sizeof(p_ptr->history)); /* Add a space */ my_strcat(p_ptr->history, "\n", sizeof(p_ptr->history)); p_ptr->redraw |= (PR_MISC); /* Display the player */ display_player(0); } else { return (FALSE); } } // confirm the choices if (!get_history()) return (FALSE); loopagain = FALSE; } else if (query2 == ESCAPE) return (FALSE); else if (((query2 == 'Q') || (query2 == 'q')) && (turn == 0)) quit (NULL); } return (TRUE); }
/* * 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. */ errr get_birth_command(bool wait) { static enum birth_stage current_stage = BIRTH_RESET; static enum birth_stage prev; static enum birth_stage roller = BIRTH_RESET; enum birth_stage next = current_stage; switch (current_stage) { case BIRTH_RESET: { cmd_insert(CMD_BIRTH_RESET); roller = BIRTH_RESET; if (quickstart_allowed) next = BIRTH_QUICKSTART; else next = BIRTH_SEX_CHOICE; break; } case BIRTH_QUICKSTART: { display_player(0); next = get_quickstart_command(); break; } case BIRTH_SEX_CHOICE: case BIRTH_CLASS_CHOICE: case BIRTH_RACE_CHOICE: case BIRTH_ROLLER_CHOICE: { menu_type *menu = &sex_menu; cmd_code command = CMD_CHOOSE_SEX; Term_clear(); print_menu_instructions(); if (current_stage > BIRTH_SEX_CHOICE) { menu_refresh(&sex_menu, FALSE); menu = &race_menu; command = CMD_CHOOSE_RACE; } 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; command = CMD_NULL; } next = menu_question(current_stage, menu, command); if (next == BIRTH_BACK) next = current_stage - 1; /* Make sure that 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_FINAL_CONFIRM: { if (prev < BIRTH_FINAL_CONFIRM) display_player(0); next = get_confirm_command(); if (next == BIRTH_BACK) next = BIRTH_NAME_CHOICE; break; } default: { /* Remove dodgy compiler warning, */ } } prev = current_stage; current_stage = next; return 0; }
static enum birth_stage roller_command(bool first_call) { char prompt[80] = ""; size_t promptlen = 0; struct keypress ch; enum birth_stage next = BIRTH_ROLLER; /* Used to keep track of whether we've rolled a character before or not. */ static bool prev_roll = FALSE; /* Display the player - a bit cheaty, but never mind. */ display_player(0); if (first_call) prev_roll = FALSE; /* Add buttons */ button_add("[ESC]", ESCAPE); button_add("[Enter]", '\r'); button_add("[r]", 'r'); if (prev_roll) button_add("[p]", 'p'); clear_from(Term->hgt - 2); redraw_stuff(p_ptr); /* Prepare a prompt (must squeeze everything in) */ strnfcat(prompt, sizeof (prompt), &promptlen, "['r' to reroll"); if (prev_roll) strnfcat(prompt, sizeof(prompt), &promptlen, ", 'p' for prev"); strnfcat(prompt, sizeof (prompt), &promptlen, " or 'Enter' to accept]"); /* Prompt for it */ prt(prompt, Term->hgt - 1, Term->wid / 2 - promptlen / 2); /* Prompt and get a command */ ch = inkey(); if (ch.code == ESCAPE) { button_kill('r'); button_kill('p'); next = BIRTH_BACK; } /* 'Enter' accepts the roll */ if ((ch.code == '\r') || (ch.code == '\n')) { next = BIRTH_NAME_CHOICE; } /* Reroll this character */ else if ((ch.code == ' ') || (ch.code == 'r')) { cmd_insert(CMD_ROLL_STATS); prev_roll = TRUE; } /* Previous character */ else if (prev_roll && (ch.code == 'p')) { cmd_insert(CMD_PREV_STATS); } /* Quit */ else if (ch.code == KTRL('X')) { cmd_insert(CMD_QUIT); next = BIRTH_COMPLETE; } /* Help XXX */ else if (ch.code == '?') { do_cmd_help(); } /* Nothing handled directly here */ else { bell("Illegal roller command!"); } /* Kill buttons */ button_kill(ESCAPE); button_kill('\r'); button_kill('r'); button_kill('p'); redraw_stuff(p_ptr); return next; }
/* * Hack -- change name */ void do_cmd_change_name(void) { ui_event ke; int mode = 0; const char *p; bool more = TRUE; /* Prompt */ p = "['c' to change name, 'f' to file, 'h' to change mode, or ESC]"; /* Save screen */ screen_save(); /* Forever */ while (more) { /* Display the player */ display_player(mode); /* Prompt */ Term_putstr(2, 23, -1, TERM_WHITE, p); /* Query */ ke = inkey_ex(); if (ke.type == EVT_KBRD) { switch (ke.key.code) { case ESCAPE: more = FALSE; break; case 'c': { char namebuf[32] = ""; if (get_name(namebuf, sizeof namebuf)) { /* Set player name */ my_strcpy(op_ptr->full_name, namebuf, sizeof(op_ptr->full_name)); /* Don't change savefile name. */ process_player_name(FALSE); } break; } case 'f': { char buf[1024]; char fname[80]; strnfmt(fname, sizeof fname, "%s.txt", op_ptr->base_name); if (get_file(fname, buf, sizeof buf)) { if (file_character(buf, FALSE) != 0) msg("Character dump failed!"); else msg("Character dump successful."); } } case 'h': case ARROW_LEFT: case ' ': mode = (mode + 1) % INFO_SCREENS; break; case 'l': case ARROW_RIGHT: mode = (mode - 1) % INFO_SCREENS; break; } } else if (ke.type == EVT_MOUSE) { /* Just flip through the screens */ mode = (mode + 1) % INFO_SCREENS; } /* Flush messages */ message_flush(); } /* Load screen */ screen_load(); }
/* * Hack -- Dump a character description file * * XXX XXX XXX Allow the "full" flag to dump additional info, * and trigger its usage from various places in the code. */ errr file_character(const char *path, bool full) { int i, x, y; int a; wchar_t c; ang_file *fp; struct store *st_ptr = &stores[STORE_HOME]; char o_name[80]; char buf[1024]; char *p; /* Unused parameter */ (void)full; /* Open the file for writing */ fp = file_open(path, MODE_WRITE, FTYPE_TEXT); if (!fp) return (-1); /* Begin dump */ file_putf(fp, " [%s Character Dump]\n\n", buildid); /* Display player */ display_player(0); /* Dump part of the screen */ for (y = 1; y < 23; y++) { p = buf; /* Dump each row */ for (x = 0; x < 79; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Dump it */ p += wctomb(p, c); } /* Back up over spaces */ while ((p > buf) && (p[-1] == ' ')) --p; /* Terminate */ *p = '\0'; /* End the row */ x_file_putf(fp, "%s\n", buf); } /* Skip a line */ file_putf(fp, "\n"); /* Display player */ display_player(1); /* Dump part of the screen */ for (y = 11; y < 20; y++) { p = buf; /* Dump each row */ for (x = 0; x < 39; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Dump it */ p += wctomb(p, c); } /* Back up over spaces */ while ((p > buf) && (p[-1] == ' ')) --p; /* Terminate */ *p = '\0'; /* End the row */ x_file_putf(fp, "%s\n", buf); } /* Skip a line */ file_putf(fp, "\n"); /* Dump part of the screen */ for (y = 11; y < 20; y++) { p = buf; /* Dump each row */ for (x = 0; x < 39; x++) { /* Get the attr/char */ (void)(Term_what(x + 40, y, &a, &c)); /* Dump it */ p += wctomb(p, c); } /* Back up over spaces */ while ((p > buf) && (p[-1] == ' ')) --p; /* Terminate */ *p = '\0'; /* End the row */ x_file_putf(fp, "%s\n", buf); } /* Skip some lines */ file_putf(fp, "\n\n"); /* If dead, dump last messages -- Prfnoff */ if (p_ptr->is_dead) { i = messages_num(); if (i > 15) i = 15; file_putf(fp, " [Last Messages]\n\n"); while (i-- > 0) { x_file_putf(fp, "> %s\n", message_str((s16b)i)); } x_file_putf(fp, "\nKilled by %s.\n\n", p_ptr->died_from); } /* Dump the equipment */ file_putf(fp, " [Character Equipment]\n\n"); for (i = INVEN_WIELD; i < ALL_INVEN_TOTAL; i++) { if (i == INVEN_TOTAL) { file_putf(fp, "\n\n [Character Quiver]\n\n"); continue; } object_desc(o_name, sizeof(o_name), &p_ptr->inventory[i], ODESC_PREFIX | ODESC_FULL); x_file_putf(fp, "%c) %s\n", index_to_label(i), o_name); if (p_ptr->inventory[i].kind) object_info_chardump(fp, &p_ptr->inventory[i], 5, 72); } /* Dump the inventory */ file_putf(fp, "\n\n [Character Inventory]\n\n"); for (i = 0; i < INVEN_PACK; i++) { if (!p_ptr->inventory[i].kind) break; object_desc(o_name, sizeof(o_name), &p_ptr->inventory[i], ODESC_PREFIX | ODESC_FULL); x_file_putf(fp, "%c) %s\n", index_to_label(i), o_name); object_info_chardump(fp, &p_ptr->inventory[i], 5, 72); } file_putf(fp, "\n\n"); /* Dump the Home -- if anything there */ if (st_ptr->stock_num) { /* Header */ file_putf(fp, " [Home Inventory]\n\n"); /* Dump all available items */ for (i = 0; i < st_ptr->stock_num; i++) { object_desc(o_name, sizeof(o_name), &st_ptr->stock[i], ODESC_PREFIX | ODESC_FULL); x_file_putf(fp, "%c) %s\n", I2A(i), o_name); object_info_chardump(fp, &st_ptr->stock[i], 5, 72); } /* Add an empty line */ file_putf(fp, "\n\n"); } /* Dump character history */ dump_history(fp); file_putf(fp, "\n\n"); /* Dump options */ file_putf(fp, " [Options]\n\n"); /* Dump options */ for (i = 0; i < OPT_PAGE_MAX - 1; i++) { int j; const char *title = ""; switch (i) { case 0: title = "Interface"; break; case 1: title = "Warning"; break; case 2: title = "Birth"; break; } file_putf(fp, " [%s]\n\n", title); for (j = 0; j < OPT_PAGE_PER; j++) { int opt = option_page[i][j]; if (!option_name(opt)) continue; file_putf(fp, "%-45s: %s (%s)\n", option_desc(opt), op_ptr->opt[opt] ? "yes" : "no ", option_name(opt)); } /* Skip some lines */ file_putf(fp, "\n"); } file_close(fp); /* Success */ return (0); }
/* * Get the Age, Height and Weight. */ static bool get_ahw(void) { char prompt[50]; char line[70]; char query2; int loopagain = TRUE; // hack to see whether we are opening an old player file bool roll_ahw = !p_ptr->age; //put_str("(a)ccept age/height/weight, (r)eroll, (m)anually enter ", 0, 0); while (loopagain == TRUE) { if (roll_ahw) { /*get the random age/height/weight, display for approval. */ get_ahw_aux(); } else { roll_ahw = TRUE; } /* Display the player */ display_player(0); // Highlight relevant info display_player_xtra_info(1); /* Prompt */ Term_putstr(QUESTION_COL, INSTRUCT_ROW + 1, -1, TERM_SLATE, "Enter accept age/height/weight"); Term_putstr(QUESTION_COL, INSTRUCT_ROW + 2, -1, TERM_SLATE, "Space reroll"); Term_putstr(QUESTION_COL, INSTRUCT_ROW + 3, -1, TERM_SLATE, " m manually enter"); /* Hack - highlight the key names */ Term_putstr(QUESTION_COL, INSTRUCT_ROW + 1, - 1, TERM_L_WHITE, "Enter"); Term_putstr(QUESTION_COL, INSTRUCT_ROW + 2, - 1, TERM_L_WHITE, "Space"); Term_putstr(QUESTION_COL + 4, INSTRUCT_ROW + 3, - 1, TERM_L_WHITE, "m"); /* Move the cursor */ Term_gotoxy(0, INSTRUCT_ROW + 1); /* Query */ query2 = inkey(); if ((query2 == '\r') || (query2 == '\n')) { /* got ahw*/ loopagain = FALSE; p_ptr->redraw |= (PR_MISC); } else if ((query2 == 'm') || (query2 == 'M')) { /* don't want random stats */ int age = 0; int height = 0; int weight = 0; int age_l, age_h, height_l, height_h, weight_l, weight_h; age_l = 10; age_h = 4865; if (p_ptr->psex == SEX_MALE) { height_l = rp_ptr->m_b_ht - 5 * (rp_ptr->m_m_ht); height_h = rp_ptr->m_b_ht + 5 * (rp_ptr->m_m_ht); weight_l = rp_ptr->m_b_wt / 3; weight_h = rp_ptr->m_b_wt * 2; } else { height_l = rp_ptr->f_b_ht - 5 * (rp_ptr->f_m_ht); height_h = rp_ptr->f_b_ht + 5 * (rp_ptr->f_m_ht); weight_l = rp_ptr->f_b_wt / 3; weight_h = rp_ptr->f_b_wt * 2; } // clear line line[0] = '\0'; while ((age < age_l) || (age > age_h)) { sprintf(prompt, "Enter age (%d-%d): ", age_l, age_h); if (!term_get_string(prompt, line, sizeof(line))) return (FALSE); age = atoi(line); p_ptr->age = age; } /* Display the player */ p_ptr->redraw |= (PR_MISC); display_player(0); // clear line line[0] = '\0'; while ((height < height_l) || (height > height_h)) { sprintf(prompt, "Enter height in inches (%d-%d): ", height_l, height_h); if (!term_get_string(prompt, line, sizeof(line))) return (FALSE); height = atoi(line); p_ptr->ht = height; } /* Display the player */ p_ptr->redraw |= (PR_MISC); display_player(0); // clear line line[0] = '\0'; while ((weight < weight_l) || (weight > weight_h)) { sprintf(prompt, "Enter weight in pounds (%d-%d): ", weight_l, weight_h); if (!term_get_string(prompt, line, sizeof(line))) return (FALSE); weight = atoi(line); p_ptr->wt = weight; } /* Display the player */ p_ptr->redraw |= (PR_MISC); display_player(0); // confirm the choices if (!get_ahw()) return (FALSE); loopagain = FALSE; } else if (query2 == ESCAPE) return (FALSE); else if (((query2 == 'Q') || (query2 == 'q')) && (turn == 0)) quit (NULL); } return (TRUE); }
int main(int ac, char **av) { int i; i = 0; printf("Hello\n"); if (ac == 1) { t_game *game; game = init_game(22); display_deck(&game->deck); printf("=================================================================\n"); // printf("Name: %s\n", av[0]); while (i < 1) { game->deck = *shuffle_deck(&game->deck); display_deck(&game->deck); printf("=================================================================\n"); i++; } game = serve_card(game); // display_deck(&game->deck); printf("=================================================================\n"); i = 0; while (i < game->np) { display_player(&game->players[i]); i++; } game = serve_flop(game); // display_deck(&game->deck); printf("=================================================================\n"); i = 0; while (i < game->np) { display_player(&game->players[i]); i++; } printf("=================================================================\n"); game = serve_turn(game); // display_deck(&game->deck); printf("=================================================================\n"); i = 0; while (i < game->np) { display_player(&game->players[i]); i++; } printf("=================================================================\n"); game = serve_river(game); // display_deck(&game->deck); printf("=================================================================\n"); i = 0; while (i < game->np) { display_player(&game->players[i]); i++; } printf("=================================================================\n"); printf("Name: %s\n", av[0]); } return (0); }
/** * Hack -- change name */ void do_cmd_change_name(void) { ui_event ke; int mode = 0; const char *p; bool more = true; /* Prompt */ p = "['c' to change name, 'f' to file, 'h' to change mode, or ESC]"; /* Save screen */ screen_save(); /* Forever */ while (more) { /* Display the player */ display_player(mode); /* Prompt */ Term_putstr(2, 23, -1, COLOUR_WHITE, p); /* Query */ ke = inkey_ex(); if ((ke.type == EVT_KBRD)||(ke.type == EVT_BUTTON)) { switch (ke.key.code) { case ESCAPE: more = false; break; case 'c': { if(arg_force_name) msg("You are not allowed to change your name!"); else { char namebuf[32] = ""; /* Set player name */ if (get_character_name(namebuf, sizeof namebuf)) my_strcpy(player->full_name, namebuf, sizeof(player->full_name)); } break; } case 'f': { char buf[1024]; char fname[80]; /* Get the filesystem-safe name and append .txt */ player_safe_name(fname, sizeof(fname), player->full_name, false); my_strcat(fname, ".txt", sizeof(fname)); if (get_file(fname, buf, sizeof buf)) { if (dump_save(buf)) msg("Character dump successful."); else msg("Character dump failed!"); } break; } case 'h': case ARROW_LEFT: case ' ': mode = (mode + 1) % INFO_SCREENS; break; case 'l': case ARROW_RIGHT: mode = (mode - 1) % INFO_SCREENS; break; } } else if (ke.type == EVT_MOUSE) { if (ke.mouse.button == 1) { /* Flip through the screens */ mode = (mode + 1) % INFO_SCREENS; } else if (ke.mouse.button == 2) { /* exit the screen */ more = false; } else { /* Flip backwards through the screens */ mode = (mode - 1) % INFO_SCREENS; } } /* Flush messages */ event_signal(EVENT_MESSAGE_FLUSH); } /* Load screen */ screen_load(); }
int main( int argc, char **argv ) { char ch; int serfd; char data[256]; char recvdata[256]; int length; int recvlength; int i; char cmdline[256]; int ret; //调试输出单元 tracePrintfInit(); { //modifyTraceLevelByMode(SYS_MODE, DEBUG_TRACE); //modifyTraceLevelByMode(IMG_MODE, DEBUG_TRACE); //modifyTraceLevelByMode(FT_MODE, DEBUG_TRACE); } printf("begin integrate\n"); serfd = InitSerialCom(2,115200,'n',1, 8); if (serfd == -1) { printf("COM2 open failure\n"); return 0; } i = 0; while(1) { memset(data, 0, 256); sprintf(data, "hello\n"); length = strlen(data); SerialSend(serfd, (unsigned char *)data, length); memset(recvdata, 0, 256); recvlength = serialReceive(serfd, recvdata, 256); if (recvlength) { printf("|%s|%d\n", recvdata, recvlength); if (recvlength == 2) { if (strncmp(recvdata, "ok", strlen("ok")) == 0) { printf("COM2 OK\n"); break; } } } i++; if (i > 50) { printf("COM2 FAILURE\n"); break; } usleep(1000*500); } while(1) { memset(cmdline, 0, 256); scanf("%s", cmdline); if (strncmp(cmdline, "getRTCTime", strlen("getRTCTime")) == 0) { memset(data, 0, 64); get_current_time_string(data); } else if (strncmp(cmdline, "setUSBTest", strlen("setUSBTest")) == 0) { ret = confirm_usb_running(); if (ret) { printf("testUSBSuccess\n"); } else { printf("testUSBFailure\n"); } } else if (strncmp(cmdline, "getSN", strlen("getSN")) == 0) { memset(data, 0, 64); get_pcba_sn(data, 64); printf("reportSN|%s\n", data); } else if (strncmp(cmdline, "getMac", strlen("getMac")) == 0) { memset(data, 0, 64); get_pcba_mac(data, 64); printf("reportMAC|%s\n", data); } else if (strncmp(cmdline, "getMediaBoradTestReport", strlen("getMediaBoradTestReport")) == 0) { memset(data, 0, 64); get_pcba_idx99(data, 64); printf("reportMediaBoardTestInfo|%s\n", data); } } #if 0 char ch; //调试输出单元 tracePrintfInit(); { //modifyTraceLevelByMode(SYS_MODE, DEBUG_TRACE); //modifyTraceLevelByMode(IMG_MODE, DEBUG_TRACE); //modifyTraceLevelByMode(FT_MODE, DEBUG_TRACE); } init_display_output_device(FMT_1080P_60); init_framebuf_module(); ft_Font_Init(); init_temperature_module(); sync_time_from_rtc(); prepare_bg(); /* system("mkdir -p /media"); system("mkdir -p /media/tfcard"); system("mkdir -p /media/usb"); system("mkdir -p /media/msata"); */ init_hard_device_task(); system("rm /tmp/leftai_ok /tmp/rightai_ok"); system("/tmp/sample_ai >/tmp/ai.log &"); display_welcom(); usleep(3000*1000); //ai_display_filter(1); while(1) { #if 1 if ((access("/tmp/leftai_ok", F_OK) == 0) && (access("/tmp/rightai_ok", F_OK) == 0)) { usleep(1000*1000); break; } #else if (access("/tmp/rightai_ok", F_OK) == 0) { break; } #endif ai_display_filter(0); if (get_ai_force_exit()) { break; } usleep(1000*1000); } if ((access("/tmp/leftai_ok", F_OK) == 0) && (access("/tmp/rightai_ok", F_OK) == 0)) { set_test_status(audio_ok); } ai_display_filter(1); system("touch /tmp/exit_ai"); // printf("aaaaaaa\n"); display_stb_info(); usleep(500*1000); // printf("dddddd\n"); series_display(); usleep(500*1000); display_msata(); usleep(500*1000); display_tfcard(); usleep(500*1000); display_usb(); usleep(500*1000); while(1) { if (test_flag & gpio_test) { display_gpio_test(); break; } else { display_gpio_putdown(); } if (get_force_exit_gpio()) { printf("\nGPIO failure\n"); break; } usleep(1000*1000); } save_test_status(); exit_timer(); usleep(500*1000); printf("\nvideo play\n"); display_player(); //save_test_status(); #if 1 while(1) { ch = getchar(); if (ch == 'q') { break; } else if (ch == 'w') { test_framebuf(); } else if (ch == 'e') { clearFramebuf(); } else if (ch == 'r') { Pixel64 *pCanvas; int width; int height; GrPos Pos; GrRegion Region; decJpgFile("/nfs/wait4open.jpg", &pCanvas, &height, &width); Pos.x = Pos.y = 0; Region.x = Region.y = 0; Region.w = width; Region.h = height; paint_canvas_2_background(pCanvas, Pos, Region); refresh_background_2_device(Pos, Region); } else if (ch == 't') { Pixel64 *pCanvas; int width; int height; GrPos Pos; GrRegion Region; decPngFile("/nfs/ico_dir.png", &pCanvas, &width, &height); Pos.x = 100; Pos.y = 100; Region.x = 0; Region.y = 0; Region.w = width; Region.h = height; paint_canvas_2_logic_device(pCanvas, Pos, Region); pCanvas = get_logic_canvas(); move_region_2_display(pCanvas, Pos, Region); } else if (ch == 'y') { GrPos Pos; Pixel64 FT; Pos.x = 137; Pos.y = 102; FT.RGB.a = 0xFF; FT.RGB.r = 0xD7; FT.RGB.g = 0xD7; FT.RGB.b = 0xD7; ft_Font_Str2Disp("hello world", FT, Pos, 40); } else if (ch == 'u') { fprintf(stderr, "开始装备测试\n"); set_test_network(0); } else if (ch == 'i') { confirm_network_running(0); } else if (ch == 'o') { float temp; temp = read_temperature(); printf("temperature %3.4f\n", temp); } else if (ch == 'p') { save_time_into_rtc(); } else if (ch == 'a') { sync_time_from_rtc(); } else if (ch == 's') { int value40; int value41; int value44; read_gpio_status(40, &value40); read_gpio_status(41, &value41); read_gpio_status(44, &value44); printf("40 = %d, 41 = %d, 44 = %d\n", value40, value41, value44); } else if (ch == 'd') { write_gpio_status(44, 0); } else if (ch == 'f') { write_gpio_status(44, 1); } else if (ch == 'g') { fd_ser = InitSerialCom(1,115200,'n',1, 8); } else if (ch == 'h') { unsigned char data[10]; sprintf(data, "hello"); SerialSend(fd_ser, data, 5); } else if (ch == 'j') { unsigned char data[10]; memset(data, 0, 10); serialReceive(fd_ser, data, 10); printf("data\n", data); } else if (ch == 'k') { get_system_time(); } else if (ch == 'l') { Pixel64 *pcanvas; Pixel64 FT; int i, j; FILE *wfp; pcanvas = getFramebuf(); wfp = fopen("/nfs/screen.raw", "wb"); for (i = 0; i < 720; i++) { for (j = 0; j < 1280; j++) { FT.RGB.r = pcanvas[j].RGB.r; FT.RGB.b = pcanvas[j].RGB.b; FT.RGB.a = pcanvas[j].RGB.a; FT.RGB.g = pcanvas[j].RGB.g; fwrite(&(FT.RGB.r), 1, 1, wfp); fwrite(&(FT.RGB.g), 1, 1, wfp); fwrite(&(FT.RGB.b), 1, 1, wfp); } pcanvas += 1280; } fclose(wfp); } } #endif close_logic_framebuf_module(); ft_Font_Destroy(); close_display_output_device(); return 0; #endif }
static enum birth_stage roller_command(bool first_call) { char prompt[80] = ""; size_t promptlen = 0; ui_event_data ke; char ch; enum birth_stage next = BIRTH_ROLLER; /* Used to keep track of whether we've rolled a character before or not. */ static bool prev_roll = FALSE; /* Display the player - a bit cheaty, but never mind. */ display_player(0, TRUE); if (first_call) prev_roll = FALSE; /* Add buttons */ button_kill_all(); button_add("[ESCAPE]", ESCAPE); button_add("[ACCEPT]", '\r'); button_add("[REROLL]", 'r'); if (prev_roll) button_add("[PREV]", 'p'); button_add("[HELP]", '?'); button_add("[QUIT]", '\x18'); /* CTRL-X */ clear_from(Term->hgt - 2); handle_stuff(); event_signal(EVENT_MOUSEBUTTONS); /* Prepare a prompt (must squeeze everything in) */ strnfcat(prompt, sizeof (prompt), &promptlen, "['r' to reroll"); if (prev_roll) strnfcat(prompt, sizeof(prompt), &promptlen, ", 'p' for prev"); strnfcat(prompt, sizeof (prompt), &promptlen, " or 'Enter' to accept]"); /* Prompt for it */ prt(prompt, Term->hgt - (mouse_buttons ? 2 : 1), Term->wid / 2 - promptlen / 2); /* Prompt and get a command */ ke = inkey_ex(); ch = ke.key; if (ch == ESCAPE) { button_kill('r'); button_kill('p'); next = BIRTH_BACK; } /* 'Enter' accepts the roll */ if ((ch == '\r') || (ch == '\n')) { next = BIRTH_NAME_CHOICE; } /* Reroll this character */ else if ((ch == ' ') || (ch == 'r')) { cmd_insert(CMD_ROLL_STATS); prev_roll = TRUE; } /* Previous character */ else if (prev_roll && (ch == 'p')) { cmd_insert(CMD_PREV_STATS); } /* Quit */ else if (ch == KTRL('X')) { cmd_insert(CMD_QUIT); next = BIRTH_COMPLETE; } /* Help XXX */ else if (ch == '?') { do_cmd_help(); } /* Nothing handled directly here */ else { bell("Illegal roller command!"); } /* Kill buttons */ button_kill_all(); handle_stuff(); event_signal(EVENT_MOUSEBUTTONS); return next; }
/** * Display some character info */ static void death_info(const char *title, int row) { int i, j, k, which = 0; object_type *o_ptr; store_type *st_ptr; ui_event_data ke; bool done = FALSE; /* Get the store number of the home */ if (OPT(adult_dungeon)) which = NUM_TOWNS_SMALL * 4 + STORE_HOME; else { for (i = 0; i < NUM_TOWNS; i++) { /* Found the town */ if (p_ptr->home == towns[i]) { which += (i < NUM_TOWNS_SMALL ? 3 : STORE_HOME); break; } /* Next town */ else which += (i < NUM_TOWNS_SMALL ? MAX_STORES_SMALL : MAX_STORES_BIG); } } /* Activate the store */ st_ptr = &store[which]; screen_save(); /* Display player */ display_player(0); /* Prompt for inventory */ prt("Hit any key to see more information (ESC to abort): ", 0, 0); /* Buttons */ button_backup_all(); button_kill_all(); button_add("ESC", ESCAPE); button_add("Continue", 'q'); /* Allow abort at this point */ ke = inkey_ex(); if (ke.key == ESCAPE) done = TRUE; /* Show equipment and inventory */ /* Equipment -- if any */ if ((p_ptr->equip_cnt) && !done) { Term_clear(); item_tester_full = TRUE; show_equip(OLIST_WEIGHT); prt("You are using: -more-", 0, 0); ke = inkey_ex(); if (ke.key == ESCAPE) done = TRUE; } /* Inventory -- if any */ if ((p_ptr->inven_cnt) && !done) { Term_clear(); item_tester_full = TRUE; show_inven(OLIST_WEIGHT); prt("You are carrying: -more-", 0, 0); ke = inkey_ex(); if (ke.key == ESCAPE) done = TRUE; } /* Home -- if anything there */ if ((st_ptr->stock_num) && !done) { /* Display contents of the home */ for (k = 0, i = 0; i < st_ptr->stock_num; k++) { /* Clear screen */ Term_clear(); /* Show 12 items */ for (j = 0; (j < 12) && (i < st_ptr->stock_num); j++, i++) { byte attr; char o_name[80]; char tmp_val[80]; /* Get the object */ o_ptr = &st_ptr->stock[i]; /* Print header, clear line */ sprintf(tmp_val, "%c) ", I2A(j)); prt(tmp_val, j + 2, 4); /* Get the object description */ object_desc(o_name, sizeof(o_name), o_ptr, ODESC_PREFIX | ODESC_FULL); /* Get the inventory color */ attr = tval_to_attr[o_ptr->tval & 0x7F]; /* Display the object */ c_put_str(attr, o_name, j + 2, 7); } /* Caption */ prt(format("Your home contains (page %d): -more-", k + 1), 0, 0); /* Wait for it */ ke = inkey_ex(); if (ke.key == ESCAPE) done = TRUE; } } screen_load(); }
/* * Hack -- Dump a character description file * * XXX XXX XXX Allow the "full" flag to dump additional info, * and trigger its usage from various places in the code. */ errr file_character(const char *path, bool full) { int i, x, y; byte a; char c; ang_file *fp; struct store *st_ptr = &stores[STORE_HOME]; char o_name[80]; byte (*old_xchar_hook)(byte c) = Term.xchar_hook; char buf[1024]; /* We use either ascii or system-specific encoding */ int encoding = OPT(xchars_to_file) ? SYSTEM_SPECIFIC : ASCII; /* Unused parameter */ (void)full; /* Open the file for writing */ fp = file_open(path, MODE_WRITE, FTYPE_TEXT); if (!fp) return (-1); /* Display the requested encoding -- ASCII or system-specific */ if (!OPT(xchars_to_file)) Term.xchar_hook = null; /* Begin dump */ file_putf(fp, " [%s Character Dump]\n\n", buildid); /* Display player */ display_player(0); /* Dump part of the screen */ for (y = 1; y < 23; y++) { /* Dump each row */ for (x = 0; x < 79; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Dump it */ buf[x] = c; } /* Back up over spaces */ while ((x > 0) && (buf[x-1] == ' ')) --x; /* Terminate */ buf[x] = '\0'; /* End the row */ x_file_putf(fp, encoding, "%s\n", buf); } /* Skip a line */ file_putf(fp, "\n"); /* Display player */ display_player(1); /* Dump part of the screen */ for (y = 11; y < 20; y++) { /* Dump each row */ for (x = 0; x < 39; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Dump it */ buf[x] = c; } /* Back up over spaces */ while ((x > 0) && (buf[x-1] == ' ')) --x; /* Terminate */ buf[x] = '\0'; /* End the row */ x_file_putf(fp, encoding, "%s\n", buf); } /* Skip a line */ file_putf(fp, "\n"); /* Dump part of the screen */ for (y = 11; y < 20; y++) { /* Dump each row */ for (x = 0; x < 39; x++) { /* Get the attr/char */ (void)(Term_what(x + 40, y, &a, &c)); /* Dump it */ buf[x] = c; } /* Back up over spaces */ while ((x > 0) && (buf[x-1] == ' ')) --x; /* Terminate */ buf[x] = '\0'; /* End the row */ x_file_putf(fp, encoding, "%s\n", buf); } /* Skip some lines */ file_putf(fp, "\n\n"); /* If dead, dump last messages -- Prfnoff */ if (p_ptr.is_dead) { i = messages_num(); if (i > 15) i = 15; file_putf(fp, " [Last Messages]\n\n"); while (i-- > 0) { x_file_putf(fp, encoding, "> %s\n", message_str((s16b)i)); } x_file_putf(fp, encoding, "\nKilled by %s.\n\n", p_ptr.died_from); } /* Dump the equipment */ file_putf(fp, " [Character Equipment]\n\n"); for (i = INVEN_WIELD; i < ALL_INVEN_TOTAL; i++) { if (i == INVEN_TOTAL) { file_putf(fp, "\n\n [Character Quiver]\n\n"); continue; } object_desc(o_name, sizeof(o_name), &p_ptr.inventory[i], ODESC_PREFIX | ODESC_FULL); x_file_putf(fp, encoding, "%c) %s\n", index_to_label(i), o_name); if (p_ptr.inventory[i].kind) object_info_chardump(fp, &p_ptr.inventory[i], 5, 72); } /* Dump the inventory */ file_putf(fp, "\n\n [Character Inventory]\n\n"); for (i = 0; i < INVEN_PACK; i++) { if (!p_ptr.inventory[i].kind) break; object_desc(o_name, sizeof(o_name), &p_ptr.inventory[i], ODESC_PREFIX | ODESC_FULL); x_file_putf(fp, encoding, "%c) %s\n", index_to_label(i), o_name); object_info_chardump(fp, &p_ptr.inventory[i], 5, 72); } file_putf(fp, "\n\n"); /* Dump the Home -- if anything there */ if (st_ptr.stock_num) { /* Header */ file_putf(fp, " [Home Inventory]\n\n"); /* Dump all available items */ for (i = 0; i < st_ptr.stock_num; i++) { object_desc(o_name, sizeof(o_name), &st_ptr.stock[i], ODESC_PREFIX | ODESC_FULL); x_file_putf(fp, encoding, "%c) %s\n", I2A(i), o_name); object_info_chardump(fp, &st_ptr.stock[i], 5, 72); } /* Add an empty line */ file_putf(fp, "\n\n"); } /* Dump character history */ dump_history(fp); file_putf(fp, "\n\n"); /* Dump options */ file_putf(fp, " [Options]\n\n"); /* Dump options */ for (i = OPT_BIRTH; i < OPT_BIRTH + N_OPTS_BIRTH; i++) { if (option_name(i)) { file_putf(fp, "%-45s: %s (%s)\n", option_desc(i), op_ptr.opt[i] ? "yes" : "no ", option_name(i)); } } /* Skip some lines */ file_putf(fp, "\n\n"); /* Return to standard display */ Term.xchar_hook = old_xchar_hook; file_close(fp); /* Success */ return (0); }
/** * Menu command: view character dump and inventory. */ static void death_info(const char *title, int row) { struct store *home = &stores[STORE_HOME]; screen_save(); /* Display player */ display_player(0); /* Prompt for inventory */ prt("Hit any key to see more information: ", 0, 0); /* Allow abort at this point */ (void)anykey(); /* Show equipment and inventory */ /* Equipment -- if any */ if (player->upkeep->equip_cnt) { Term_clear(); show_equip(OLIST_WEIGHT | OLIST_SEMPTY | OLIST_DEATH, NULL); prt("You are using: -more-", 0, 0); (void)anykey(); } /* Inventory -- if any */ if (player->upkeep->inven_cnt) { Term_clear(); show_inven(OLIST_WEIGHT | OLIST_DEATH, NULL); prt("You are carrying: -more-", 0, 0); (void)anykey(); } /* Quiver -- if any */ if (player->upkeep->quiver_cnt) { Term_clear(); show_quiver(OLIST_WEIGHT | OLIST_DEATH, NULL); prt("Your quiver holds: -more-", 0, 0); (void)anykey(); } /* Home -- if anything there */ if (home->stock) { int page; struct object *obj = home->stock; /* Display contents of the home */ for (page = 1; obj; page++) { int line; /* Clear screen */ Term_clear(); /* Show 12 items */ for (line = 0; obj && line < 12; obj = obj->next, line++) { byte attr; char o_name[80]; char tmp_val[80]; /* Print header, clear line */ strnfmt(tmp_val, sizeof(tmp_val), "%c) ", I2A(line)); prt(tmp_val, line + 2, 4); /* Get the object description */ object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL); /* Get the inventory color */ attr = obj->kind->base->attr; /* Display the object */ c_put_str(attr, o_name, line + 2, 7); } /* Caption */ prt(format("Your home contains (page %d): -more-", page), 0, 0); /* Wait for it */ (void)anykey(); } } screen_load(); }
/* * Helper function for 'player_birth()'. * * This function handles "point-based" character creation. * * The player selects, for each stat, a value from 6 to 18 (inclusive), * each costing a certain amount of points (as above), from a pool of 30 * available points, to which race/house modifiers are then applied. * * Each unused point is converted into 100 experience points. */ static bool player_birth_aux_2(void) { int i; int row = 2; int col = 42; int stat = 0; int stats[A_MAX]; int cost; char ch; char buf[80]; /* Initialize stats */ for (i = 0; i < A_MAX; i++) { /* Initial stats */ stats[i] = p_ptr->stat_base[i]; } /* Determine experience and things */ get_extra(); /* Interact */ while (1) { /* Reset cost */ cost = 0; /* Process stats */ for (i = 0; i < A_MAX; i++) { /* Obtain a "bonus" for "race" */ int bonus = rp_ptr->r_adj[i] + hp_ptr->h_adj[i]; /* Apply the racial bonuses */ p_ptr->stat_base[i] = stats[i] + bonus; p_ptr->stat_drain[i] = 0; /* Total cost */ cost += birth_stat_costs[stats[i] + 4]; } /* Restrict cost */ if (cost > MAX_COST) { /* Warning */ bell("Excessive stats!"); /* Reduce stat */ stats[stat]--; /* Recompute costs */ continue; } p_ptr->new_exp = p_ptr->exp = PY_START_EXP; /* Calculate the bonuses and hitpoints */ p_ptr->update |= (PU_BONUS | PU_HP); /* Update stuff */ update_stuff(); /* Fully healed */ p_ptr->chp = p_ptr->mhp; /* Fully rested */ calc_voice(); p_ptr->csp = p_ptr->msp; /* Display the player */ display_player(0); /* Display the costs header */ c_put_str(TERM_WHITE, "Points Left:", 0, col + 21); strnfmt(buf, sizeof(buf), "%2d", MAX_COST - cost); c_put_str(TERM_L_GREEN, buf, 0, col + 34); /* Display the costs */ for (i = 0; i < A_MAX; i++) { byte attr = (i == stat) ? TERM_L_BLUE : TERM_L_WHITE; /* Display cost */ strnfmt(buf, sizeof(buf), "%4d", birth_stat_costs[stats[i] + 4]); c_put_str(attr, buf, row + i, col + 32); } /* Prompt */ Term_putstr(QUESTION_COL, INSTRUCT_ROW + 1, -1, TERM_SLATE, "Arrow keys allocate points to stats"); Term_putstr(QUESTION_COL, INSTRUCT_ROW + 2, -1, TERM_SLATE, " Enter accept current values"); /* Hack - highlight the key names */ Term_putstr(QUESTION_COL, INSTRUCT_ROW + 1, - 1, TERM_L_WHITE, "Arrow keys"); Term_putstr(QUESTION_COL + 5, INSTRUCT_ROW + 2, - 1, TERM_L_WHITE, "Enter"); /* Get key */ hide_cursor = TRUE; ch = inkey(); hide_cursor = FALSE; /* Quit */ if ((ch == 'Q') || (ch == 'q')) quit(NULL); /* Start over */ if (ch == ESCAPE) return (FALSE); /* Done */ if ((ch == '\r') || (ch == '\n')) break; /* Prev stat */ if (ch == '8') { stat = (stat + A_MAX - 1) % A_MAX; } /* Next stat */ if (ch == '2') { stat = (stat + 1) % A_MAX; } /* Decrease stat */ if ((ch == '4') && (stats[stat] > 0)) { stats[stat]--; } /* Increase stat */ if (ch == '6') { stats[stat]++; } } /* Done */ return (TRUE); }
/** * Write a character dump */ void write_character_dump(ang_file *fff) { int i, x, y; int a; wchar_t c; struct store *home = &stores[STORE_HOME]; struct object **home_list = mem_zalloc(sizeof(struct object *) * z_info->store_inven_max); char o_name[80]; char buf[1024]; char *p; /* Begin dump */ file_putf(fff, " [%s Character Dump]\n\n", buildid); /* Display player */ display_player(0); /* Dump part of the screen */ for (y = 1; y < 23; y++) { p = buf; /* Dump each row */ for (x = 0; x < 79; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Dump it */ p += wctomb(p, c); } /* Back up over spaces */ while ((p > buf) && (p[-1] == ' ')) --p; /* Terminate */ *p = '\0'; /* End the row */ file_putf(fff, "%s\n", buf); } /* Skip a line */ file_putf(fff, "\n"); /* Display player */ display_player(1); /* Dump part of the screen */ for (y = 11; y < 20; y++) { p = buf; /* Dump each row */ for (x = 0; x < 39; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Dump it */ p += wctomb(p, c); } /* Back up over spaces */ while ((p > buf) && (p[-1] == ' ')) --p; /* Terminate */ *p = '\0'; /* End the row */ file_putf(fff, "%s\n", buf); } /* Skip a line */ file_putf(fff, "\n"); /* Dump part of the screen */ for (y = 11; y < 20; y++) { p = buf; /* Dump each row */ for (x = 0; x < 39; x++) { /* Get the attr/char */ (void)(Term_what(x + 40, y, &a, &c)); /* Dump it */ p += wctomb(p, c); } /* Back up over spaces */ while ((p > buf) && (p[-1] == ' ')) --p; /* Terminate */ *p = '\0'; /* End the row */ file_putf(fff, "%s\n", buf); } /* Skip some lines */ file_putf(fff, "\n\n"); /* If dead, dump last messages -- Prfnoff */ if (player->is_dead) { i = messages_num(); if (i > 15) i = 15; file_putf(fff, " [Last Messages]\n\n"); while (i-- > 0) { file_putf(fff, "> %s\n", message_str((s16b)i)); } file_putf(fff, "\nKilled by %s.\n\n", player->died_from); } /* Dump the equipment */ file_putf(fff, " [Character Equipment]\n\n"); for (i = 0; i < player->body.count; i++) { struct object *obj = slot_object(player, i); if (!obj) continue; object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL); file_putf(fff, "%c) %s\n", gear_to_label(obj), o_name); object_info_chardump(fff, obj, 5, 72); } file_putf(fff, "\n\n"); /* Dump the inventory */ file_putf(fff, "\n\n [Character Inventory]\n\n"); for (i = 0; i < z_info->pack_size; i++) { struct object *obj = player->upkeep->inven[i]; if (!obj) break; object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL); file_putf(fff, "%c) %s\n", gear_to_label(obj), o_name); object_info_chardump(fff, obj, 5, 72); } file_putf(fff, "\n\n"); /* Dump the quiver */ file_putf(fff, "\n\n [Character Quiver]\n\n"); for (i = 0; i < z_info->quiver_size; i++) { struct object *obj = player->upkeep->quiver[i]; if (!obj) continue; object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL); file_putf(fff, "%c) %s\n", gear_to_label(obj), o_name); object_info_chardump(fff, obj, 5, 72); } file_putf(fff, "\n\n"); /* Dump the Home -- if anything there */ store_stock_list(home, home_list, z_info->store_inven_max); if (home->stock_num) { /* Header */ file_putf(fff, " [Home Inventory]\n\n"); /* Dump all available items */ for (i = 0; i < z_info->store_inven_max; i++) { struct object *obj = home_list[i]; if (!obj) break; object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL); file_putf(fff, "%c) %s\n", I2A(i), o_name); object_info_chardump(fff, obj, 5, 72); } /* Add an empty line */ file_putf(fff, "\n\n"); } /* Dump character history */ dump_history(fff); file_putf(fff, "\n\n"); /* Dump options */ file_putf(fff, " [Options]\n\n"); /* Dump options */ for (i = 0; i < OP_MAX; i++) { int opt; const char *title = ""; switch (i) { case OP_INTERFACE: title = "User interface"; break; case OP_BIRTH: title = "Birth"; break; default: continue; } file_putf(fff, " [%s]\n\n", title); for (opt = 0; opt < OPT_MAX; opt++) { if (option_type(opt) != i) continue; file_putf(fff, "%-45s: %s (%s)\n", option_desc(opt), player->opts.opt[opt] ? "yes" : "no ", option_name(opt)); } /* Skip some lines */ file_putf(fff, "\n"); } mem_free(home_list); }
/* * Increase your skills by spending experience points */ extern bool gain_skills(void) { int i; int row = 7; int col = 42; int skill = 0; int old_base[S_MAX]; int skill_gain[S_MAX]; int old_new_exp = p_ptr->new_exp; int total_cost = 0; //int old_csp = p_ptr->csp; //int old_msp = p_ptr->msp; char ch; char buf[80]; bool accepted; int tab = 0; // hack global variable skill_gain_in_progress = TRUE; /* save the old skills */ for (i = 0; i < S_MAX; i++) old_base[i] = p_ptr->skill_base[i]; /* initialise the skill gains */ for (i = 0; i < S_MAX; i++) skill_gain[i] = 0; /* Interact */ while (1) { // reset the total cost total_cost = 0; /* Process skills */ for (i = 0; i < S_MAX; i++) { /* Total cost */ total_cost += skill_cost(old_base[i], skill_gain[i]); } // set the new experience pool total p_ptr->new_exp = old_new_exp - total_cost; /* Restrict cost */ if (p_ptr->new_exp < 0) { /* Warning */ bell("Excessive skills!"); /* Reduce stat */ skill_gain[skill]--; /* Recompute costs */ continue; } /* Calculate the bonuses */ p_ptr->update |= (PU_BONUS); /* Set the redraw flag for everything */ p_ptr->redraw |= (PR_EXP | PR_BASIC); /* update the skills */ for (i = 0; i < S_MAX; i++) { p_ptr->skill_base[i] = old_base[i] + skill_gain[i]; } /* Update stuff */ update_stuff(); /* Update voice level */ //if (p_ptr->msp == 0) p_ptr->csp = 0; //else p_ptr->csp = (old_csp * p_ptr->msp) / old_msp; /* Display the player */ display_player(0); /* Display the costs header */ if (!character_dungeon) { if (p_ptr->new_exp >= 10000) tab = 0; else if (p_ptr->new_exp >= 1000) tab = 1; else if (p_ptr->new_exp >= 100) tab = 2; else if (p_ptr->new_exp >= 10) tab = 3; else tab = 4; strnfmt(buf, sizeof(buf), "%6d", p_ptr->new_exp); c_put_str(TERM_L_GREEN, buf, row - 2, col + 30); c_put_str(TERM_WHITE, "Points Left:", row - 2, col + 17 + tab); } /* Display the costs */ for (i = 0; i < S_MAX; i++) { byte attr = (i == skill) ? TERM_L_BLUE : TERM_L_WHITE; /* Display cost */ strnfmt(buf, sizeof(buf), "%6d", skill_cost(old_base[i], skill_gain[i])); c_put_str(attr, buf, row + i, col + 30); } /* Special Prompt? */ if (character_dungeon) { Term_putstr(QUESTION_COL + 38 + 2, INSTRUCT_ROW + 1, -1, TERM_SLATE, "ESC abort skill increases "); /* Hack - highlight the key names */ Term_putstr(QUESTION_COL + 38 + 2, INSTRUCT_ROW + 1, - 1, TERM_L_WHITE, "ESC"); } /* Prompt */ Term_putstr(QUESTION_COL, INSTRUCT_ROW + 1, -1, TERM_SLATE, "Arrow keys allocate points to skills"); Term_putstr(QUESTION_COL, INSTRUCT_ROW + 2, -1, TERM_SLATE, " Enter accept current values"); /* Hack - highlight the key names */ Term_putstr(QUESTION_COL, INSTRUCT_ROW + 1, - 1, TERM_L_WHITE, "Arrow keys"); Term_putstr(QUESTION_COL + 5, INSTRUCT_ROW + 2, - 1, TERM_L_WHITE, "Enter"); /* Get key */ hide_cursor = TRUE; ch = inkey(); hide_cursor = FALSE; /* Quit (only if haven't begun game yet) */ if (((ch == 'Q') || (ch == 'q')) && (turn == 0)) quit(NULL); /* Done */ if ((ch == '\r') || (ch == '\n')) { accepted = TRUE; break; } /* Abort */ if (ch == ESCAPE) { p_ptr->new_exp = old_new_exp; for (i=0; i<S_MAX; i++) p_ptr->skill_base[i] = old_base[i]; //p_ptr->csp = old_csp; accepted = FALSE; break; } /* Prev skill */ if (ch == '8') { skill = (skill + S_MAX - 1) % S_MAX; } /* Next skill */ if (ch == '2') { skill = (skill + 1) % S_MAX; } /* Decrease skill */ if ((ch == '4') && (skill_gain[skill] > 0)) { skill_gain[skill]--; } /* Increase stat */ if (ch == '6') { skill_gain[skill]++; } } // reset hack global variable skill_gain_in_progress = FALSE; /* Calculate the bonuses */ p_ptr->update |= (PU_BONUS); /* Update stuff */ update_stuff(); /* Done */ return (accepted); }
/* * Menu command: view character dump and inventory. */ static void death_info(const char *title, int row) { int i, j, k; object_type *o_ptr; store_type *st_ptr = &store[STORE_HOME]; screen_save(); /* Display player */ display_player(0); /* Prompt for inventory */ prt("Hit any key to see more information: ", 0, 0); /* Allow abort at this point */ (void)anykey(); /* Show equipment and inventory */ /* Equipment -- if any */ if (p_ptr->equip_cnt) { Term_clear(); item_tester_full = TRUE; show_equip(OLIST_WEIGHT); prt("You are using: -more-", 0, 0); (void)anykey(); } /* Inventory -- if any */ if (p_ptr->inven_cnt) { Term_clear(); item_tester_full = TRUE; show_inven(OLIST_WEIGHT); prt("You are carrying: -more-", 0, 0); (void)anykey(); } /* Home -- if anything there */ if (st_ptr->stock_num) { /* Display contents of the home */ for (k = 0, i = 0; i < st_ptr->stock_num; k++) { /* Clear screen */ Term_clear(); /* Show 12 items */ for (j = 0; (j < 12) && (i < st_ptr->stock_num); j++, i++) { byte attr; char o_name[80]; char tmp_val[80]; /* Get the object */ o_ptr = &st_ptr->stock[i]; /* Print header, clear line */ strnfmt(tmp_val, sizeof(tmp_val), "%c) ", I2A(j)); prt(tmp_val, j+2, 4); /* Get the object description */ object_desc(o_name, sizeof(o_name), o_ptr, ODESC_PREFIX | ODESC_FULL); /* Get the inventory color */ attr = tval_to_attr[o_ptr->tval % N_ELEMENTS(tval_to_attr)]; /* Display the object */ c_put_str(attr, o_name, j+2, 7); } /* Caption */ prt(format("Your home contains (page %d): -more-", k+1), 0, 0); /* Wait for it */ (void)anykey(); } } screen_load(); }
/** * 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; }