int player_init() { int role, i; struct passwd *pw; pw = getpwuid(getuid()); player.name = ask_str("What is your name?", pw->pw_name); role = ask_role(); if(role == -1) return -1; else player.role = (unsigned int) role; /* player is placed into a sensible position in player_set_level() */ player.x = 0; player.y = 0; player.xp = 0; for(i = 0; i < 6; i++) { ((unsigned int *) &player.stats)[i] = 4 + (random() % 12); ((int *) &player.stats_exe)[i] = 0; } player.stats.hpmax = 8 + (random() % 8); player.stats.hp = player.stats.hpmax; player.turn = 0; player.type = &ptypes[player.role]; return 0; }
/** * @brief Searches for a entrant either by name or id given by the user. * The function prompts the user with the choice of searching by name or by * the entrant id. * * @param event Event structure. The result will be stored in this variable. * * @return If successful the function returns a pointer to the entrant. If it * fails NULL is returned. */ ENTRANT *query_entrant(EVENT *event) { int response, ret; do { printf("\nSearch by name or entrant number?\n"); printf("1. Number.\n2. Name.\n\n0. Back\n>> "); ret = scanf(" %d", &response); if (ret != 1) { continue; } if (response == 1) { response = ask_int("\nPlease enter a entrant ID:\n0. Back.", 0, event->entrants->size); if (response == 0) { return NULL; } return entrant_id_search(response, event->entrants); } else if (response == 2) { char response_str[256]; ask_str("\nPlease enter entrant name:\n0. Back", response_str); if (strcmp(response_str, "0") == 0) { return NULL; } return entrant_name_search(response_str, event->entrants); } else if (response == 0) { return NULL; } } while (1); }