Angband
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
ui-birth.c File Reference

Text-based user interface for character creation. More...

#include "angband.h"
#include "cmds.h"
#include "cmd-core.h"
#include "game-event.h"
#include "game-input.h"
#include "obj-tval.h"
#include "player.h"
#include "ui-birth.h"
#include "ui-display.h"
#include "ui-game.h"
#include "ui-help.h"
#include "ui-input.h"
#include "ui-menu.h"
#include "ui-options.h"
#include "ui-player.h"
#include "ui-prefs.h"
#include "ui-target.h"
#include "list-player-flags.h"

Data Structures

struct  birthmenu_data
 We have one of these structures for each menu we display - it holds the useful information for the menu - text of the menu items, "help" text, current (or default) selection, and whether random selection is allowed. More...
 

Macros

#define HEADER_ROW   1
 Locations of the menus, etc. More...
 
#define QUESTION_ROW   7
 
#define TABLE_ROW   9
 
#define QUESTION_COL   2
 
#define RACE_COL   2
 
#define RACE_AUX_COL   19
 
#define CLASS_COL   19
 
#define CLASS_AUX_COL   36
 
#define ROLLER_COL   36
 
#define HIST_INSTRUCT_ROW   18
 
#define MENU_ROWS   TABLE_ROW + 14
 
#define PF(a, b, c)   case PF_##a: return c;
 
#define BIRTH_MENU_HELPTEXT
 
#define COSTS_ROW   2
 

Point-based stat allocation. More...

 
#define COSTS_COL   (42 + 32)
 
#define TOTAL_COL   (42 + 19)
 

Typedefs

typedef void(* browse_f )(int oid, void *db, const region *l)
 We use different menu "browse functions" to display the help text sometimes supplied with the menu items - currently just the list of bonuses, etc, corresponding to each race and class. More...
 

Enumerations

enum  birth_stage {
  BIRTH_BACK = -1, BIRTH_RESET = 0, BIRTH_QUICKSTART, BIRTH_RACE_CHOICE,
  BIRTH_CLASS_CHOICE, BIRTH_ROLLER_CHOICE, BIRTH_POINTBASED, BIRTH_ROLLER,
  BIRTH_NAME_CHOICE, BIRTH_HISTORY_CHOICE, BIRTH_FINAL_CONFIRM, BIRTH_COMPLETE
}
 

Overview

This file implements the user interface side of the birth process for the classic terminal-based UI of Angband. More...
 
enum  birth_questions {
  BQ_METHOD = 0, BQ_RACE, BQ_CLASS, BQ_ROLLER,
  MAX_BIRTH_QUESTIONS
}
 
enum  birth_rollers { BR_POINTBASED = 0, BR_NORMAL, MAX_BIRTH_ROLLERS }
 

Functions

static void point_based_start (void)
 
static enum birth_stage textui_birth_quickstart (void)
 

Quickstart? screen. More...

 
static void birthmenu_display (struct menu *menu, int oid, bool cursor, int row, int col, int width)
 A custom "display" function for our menus that simply displays the text from our stored data in a different colour if it's currently selected. More...
 
static void skill_help (const int r_skills[], const int c_skills[], int mhp, int exp, int infra)
 
static const char * get_flag_desc (bitflag flag)
 
static const char * get_resist_desc (int element)
 
static void race_help (int i, void *db, const region *l)
 
static void class_help (int i, void *db, const region *l)
 
static void init_birth_menu (struct menu *menu, int n_choices, int initial_choice, const region *reg, bool allow_random, browse_f aux)
 Set up one of our menus ready to display choices for a birth question. More...
 
static void setup_menus (void)
 
static void free_birth_menu (struct menu *menu)
 Cleans up our stored menu info when we've finished with it. More...
 
static void free_birth_menus (void)
 
static void clear_question (void)
 Clear the previous question. More...
 
static void print_menu_instructions (void)
 Show the birth instructions on an otherwise blank screen. More...
 
static enum birth_stage menu_question (enum birth_stage current, struct menu *current_menu, cmd_code choice_command)
 Allow the user to select from the current menu, and return the corresponding command to the game. More...
 
static enum birth_stage roller_command (bool first_call)
 

The rolling bit of the roller. More...

 
static void point_based_stats (game_event_type type, game_event_data *data, void *user)
 This is called whenever a stat changes. More...
 
static void point_based_misc (game_event_type type, game_event_data *data, void *user)
 This is called whenever any of the other miscellaneous stat-dependent things changed. More...
 
static void point_based_points (game_event_type type, game_event_data *data, void *user)
 This is called whenever the points totals are changed (in birth.c), so that we can update our display of how many points have been spent and are available. More...
 
static void point_based_stop (void)
 
static enum birth_stage point_based_command (void)
 
static enum birth_stage get_name_command (void)
 

Asking for the player's chosen name. More...

 
void get_screen_loc (size_t cursor, int *x, int *y, size_t n_lines, size_t *line_starts, size_t *line_lengths)
 
int edit_text (char *buffer, int buflen)
 
static enum birth_stage get_history_command (void)
 

Allowing the player to choose their history. More...

 
static enum birth_stage get_confirm_command (void)
 

Final confirmation of character. More...

 
int textui_do_birth (void)
 

Things that relate to the world outside this file: receiving game events and being asked for game commands. More...

 
static void ui_enter_birthscreen (game_event_type type, game_event_data *data, void *user)
 Called when we enter the birth mode - so we set up handlers, command hooks, etc, here. More...
 
static void ui_leave_birthscreen (game_event_type type, game_event_data *data, void *user)
 
void ui_init_birthstate_handlers (void)
 

Variables

static bool quickstart_allowed = false
 
bool arg_force_name
 
static struct menu race_menu
class_menu 
roller_menu
 

The various "menu" bits of the birth process - namely choice of race, class, and roller type. More...

 
static region race_region = {RACE_COL, TABLE_ROW, 17, MENU_ROWS}
 upper left column and row, width, and lower column More...
 
static region class_region = {CLASS_COL, TABLE_ROW, 17, MENU_ROWS}
 
static region roller_region = {ROLLER_COL, TABLE_ROW, 34, MENU_ROWS}
 
static const menu_iter birth_iter = { NULL, NULL, birthmenu_display, NULL, NULL }
 Our custom menu iterator, only really needed to allow us to override the default handling of "commands" in the standard iterators (hence only defining the display and handler parts). More...
 

Detailed Description

Text-based user interface for character creation.

Copyright (c) 1987 - 2015 Angband contributors

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Macro Definition Documentation

#define BIRTH_MENU_HELPTEXT
Value:
"{light blue}Please select your character traits from the menus below:{/}\n\n" \
"Use the {light green}movement keys{/} to scroll the menu, " \
"{light green}Enter{/} to select the current menu item, '{light green}*{/}' " \
"for a random menu item, '{light green}ESC{/}' to step back through the " \
"birth process, '{light green}={/}' for the birth options, '{light green}?{/}' " \
"for help, or '{light green}Ctrl-X{/}' to quit."

Referenced by print_menu_instructions().

#define CLASS_AUX_COL   36

Referenced by class_help().

#define CLASS_COL   19
#define COSTS_COL   (42 + 32)
#define COSTS_ROW   2


Point-based stat allocation.


Referenced by point_based_command(), and point_based_points().

#define HEADER_ROW   1

Locations of the menus, etc.

on the screen

Referenced by print_menu_instructions().

#define HIST_INSTRUCT_ROW   18

Referenced by edit_text().

#define MENU_ROWS   TABLE_ROW + 14
#define PF (   a,
  b,
 
)    case PF_##a: return c;
#define QUESTION_COL   2
#define QUESTION_ROW   7

Referenced by clear_question(), and menu_question().

#define RACE_AUX_COL   19

Referenced by race_help().

#define RACE_COL   2
#define ROLLER_COL   36
#define TABLE_ROW   9
#define TOTAL_COL   (42 + 19)

Referenced by point_based_points().

Typedef Documentation

typedef void(* browse_f)(int oid, void *db, const region *l)

We use different menu "browse functions" to display the help text sometimes supplied with the menu items - currently just the list of bonuses, etc, corresponding to each race and class.

Enumeration Type Documentation

Enumerator
BQ_METHOD 
BQ_RACE 
BQ_CLASS 
BQ_ROLLER 
MAX_BIRTH_QUESTIONS 
Enumerator
BR_POINTBASED 
BR_NORMAL 
MAX_BIRTH_ROLLERS 

Overview

This file implements the user interface side of the birth process for the classic terminal-based UI of Angband.

It models birth as a series of steps which must be carried out in a specified order, with the option of stepping backwards to revisit past choices.

It starts when we receive the EVENT_ENTER_BIRTH event from the game, and ends when we receive the EVENT_LEAVE_BIRTH event. In between, we will repeatedly be asked to supply a game command, which change the state of the character being rolled. Once the player is happy with their character, we send the CMD_ACCEPT_CHARACTER command. A local-to-this-file global to hold the most important bit of state between calls to the game proper. Probably not strictly necessary, but reduces complexity a bit.

Enumerator
BIRTH_BACK 
BIRTH_RESET 
BIRTH_QUICKSTART 
BIRTH_RACE_CHOICE 
BIRTH_CLASS_CHOICE 
BIRTH_ROLLER_CHOICE 
BIRTH_POINTBASED 
BIRTH_ROLLER 
BIRTH_NAME_CHOICE 
BIRTH_HISTORY_CHOICE 
BIRTH_FINAL_CONFIRM 
BIRTH_COMPLETE 

Function Documentation

static void birthmenu_display ( struct menu menu,
int  oid,
bool  cursor,
int  row,
int  col,
int  width 
)
static

A custom "display" function for our menus that simply displays the text from our stored data in a different colour if it's currently selected.

References c_put_str(), curs_attrs, CURS_KNOWN, data, birthmenu_data::items, and menu::menu_data.

static void class_help ( int  i,
void db,
const region l 
)
static
static void clear_question ( void  )
static

Clear the previous question.

References i, QUESTION_ROW, TABLE_ROW, and Term_erase().

Referenced by menu_question().

int edit_text ( char *  buffer,
int  buflen 
)
static void free_birth_menu ( struct menu menu)
static

Cleans up our stored menu info when we've finished with it.

References data, birthmenu_data::items, mem_free(), and menu::menu_data.

Referenced by free_birth_menus().

static void free_birth_menus ( void  )
static

References free_birth_menu(), and roller_menu.

Referenced by ui_leave_birthscreen().

static enum birth_stage get_confirm_command ( void  )
static
static const char* get_flag_desc ( bitflag  flag)
static

Referenced by race_help().

static enum birth_stage get_history_command ( void  )
static
static enum birth_stage get_name_command ( void  )
static
static const char* get_resist_desc ( int  element)
static

Referenced by race_help().

void get_screen_loc ( size_t  cursor,
int x,
int y,
size_t  n_lines,
size_t *  line_starts,
size_t *  line_lengths 
)

References i.

Referenced by edit_text().

static void init_birth_menu ( struct menu menu,
int  n_choices,
int  initial_choice,
const region reg,
bool  allow_random,
browse_f  aux 
)
static

Set up one of our menus ready to display choices for a birth question.

This is slightly involved.

References birthmenu_data::allow_random, menu::browse_hook, menu::cursor, menu::flags, birthmenu_data::items, lower_case, mem_alloc(), menu_init(), menu_layout(), menu_setpriv(), MN_DBL_TAP, MN_SKIN_SCROLL, and menu::selections.

Referenced by setup_menus().

static enum birth_stage menu_question ( enum birth_stage  current,
struct menu current_menu,
cmd_code  choice_command 
)
static
static enum birth_stage point_based_command ( void  )
static
static void point_based_misc ( game_event_type  type,
game_event_data data,
void user 
)
static

This is called whenever any of the other miscellaneous stat-dependent things changed.

We are hooked into changes in the amount of gold in this case, but redisplay everything because it's easier.

References display_player_xtra_info().

Referenced by point_based_start(), and point_based_stop().

static void point_based_points ( game_event_type  type,
game_event_data data,
void user 
)
static

This is called whenever the points totals are changed (in birth.c), so that we can update our display of how many points have been spent and are available.

References game_event_data::birthstats, COSTS_COL, COSTS_ROW, format(), i, put_str(), game_event_data::remaining, STAT_MAX, stats, game_event_data::stats, and TOTAL_COL.

Referenced by point_based_start(), and point_based_stop().

static void point_based_start ( void  )
static
static void point_based_stats ( game_event_type  type,
game_event_data data,
void user 
)
static

This is called whenever a stat changes.

We take the easy road, and just redisplay them all using the standard function.

References display_player_stat_info().

Referenced by point_based_start(), and point_based_stop().

static void point_based_stop ( void  )
static
static void print_menu_instructions ( void  )
static

Show the birth instructions on an otherwise blank screen.

References BIRTH_MENU_HELPTEXT, HEADER_ROW, QUESTION_COL, Term_clear(), Term_gotoxy(), text_out_e(), text_out_hook, text_out_indent, and text_out_to_screen().

Referenced by textui_do_birth().

static void race_help ( int  i,
void db,
const region l 
)
static
static enum birth_stage roller_command ( bool  first_call)
static
static void setup_menus ( void  )
static
static void skill_help ( const int  r_skills[],
const int  c_skills[],
int  mhp,
int  exp,
int  infra 
)
static
static enum birth_stage textui_birth_quickstart ( void  )
static
int textui_do_birth ( void  )


Things that relate to the world outside this file: receiving game events and being asked for game commands.


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.

References BIRTH_BACK, BIRTH_CLASS_CHOICE, BIRTH_COMPLETE, BIRTH_FINAL_CONFIRM, BIRTH_HISTORY_CHOICE, BIRTH_NAME_CHOICE, BIRTH_POINTBASED, BIRTH_QUICKSTART, BIRTH_RACE_CHOICE, BIRTH_RESET, BIRTH_ROLLER, BIRTH_ROLLER_CHOICE, CMD_BIRTH, CMD_BIRTH_INIT, CMD_BIRTH_RESET, CMD_CHOOSE_CLASS, CMD_CHOOSE_RACE, cmdq_execute(), cmdq_push(), display_player(), get_confirm_command(), get_history_command(), get_name_command(), menu_question(), menu_refresh(), point_based_command(), point_based_start(), point_based_stop(), prev, print_menu_instructions(), quickstart_allowed, roller_command(), roller_menu, Term_clear(), and textui_birth_quickstart().

Referenced by start_game().

static void ui_enter_birthscreen ( game_event_type  type,
game_event_data data,
void user 
)
static

Called when we enter the birth mode - so we set up handlers, command hooks, etc, here.

References game_event_data::flag, quickstart_allowed, and setup_menus().

Referenced by ui_init_birthstate_handlers().

void ui_init_birthstate_handlers ( void  )
static void ui_leave_birthscreen ( game_event_type  type,
game_event_data data,
void user 
)
static

Variable Documentation

bool arg_force_name
const menu_iter birth_iter = { NULL, NULL, birthmenu_display, NULL, NULL }
static

Our custom menu iterator, only really needed to allow us to override the default handling of "commands" in the standard iterators (hence only defining the display and handler parts).

region class_region = {CLASS_COL, TABLE_ROW, 17, MENU_ROWS}
static
bool quickstart_allowed = false
static
region race_region = {RACE_COL, TABLE_ROW, 17, MENU_ROWS}
static

upper left column and row, width, and lower column

struct menu race_menu class_menu roller_menu
static


The various "menu" bits of the birth process - namely choice of race, class, and roller type.


The various menus

Referenced by free_birth_menus(), setup_menus(), and textui_do_birth().

region roller_region = {ROLLER_COL, TABLE_ROW, 34, MENU_ROWS}
static