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

Character creation. More...

#include "angband.h"
#include "cmd-core.h"
#include "cmds.h"
#include "game-event.h"
#include "game-world.h"
#include "init.h"
#include "mon-lore.h"
#include "monster.h"
#include "obj-gear.h"
#include "obj-identify.h"
#include "obj-ignore.h"
#include "obj-make.h"
#include "obj-pile.h"
#include "obj-power.h"
#include "obj-randart.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "object.h"
#include "player-birth.h"
#include "player-history.h"
#include "player-quest.h"
#include "player-spell.h"
#include "player-timed.h"
#include "player-util.h"
#include "player.h"
#include "savefile.h"
#include "store.h"

Data Structures

struct  birther
 A structure to hold "rolled" information, and any other useful state for the birth process. More...

Macros

#define MAX_BIRTH_POINTS   20 /* 3 * (1+1+1+1+1+1+2) */

Typedefs

typedef struct birther birther

Functions

static int roman_to_int (const char *roman)
 

Overview

This file contains the game-mechanical part of the birth process.
static int int_to_roman (int n, char *roman, size_t bufsize)
 Converts an arabic numeral (int) to a roman numeral (char *).
static void save_roller_data (birther *tosave)
 Save the currently rolled data into the supplied 'player'.
static void load_roller_data (birther *saved, birther *prev_player)
 Load stored player data from 'player' as the currently rolled data, optionally placing the current data in 'prev_player' (if 'prev_player' is non-NULL).
static void get_stats (int stat_use[STAT_MAX])
 Roll for a characters stats.
static void roll_hp (void)
static void get_bonuses (void)
char * get_history (struct history_chart *chart)
 Get the racial history, and social class, using the "history charts".
static void get_ahw (struct player *p)
 Computes character's age, height, and weight.
static void get_money (void)
 Get the player's starting money.
void player_init (struct player *p)
void wield_all (struct player *p)
 Try to wield everything wieldable in the inventory.
static void player_outfit (struct player *p)
 Init players with some belongings.
static void recalculate_stats (int *stats, int points_left)
static void reset_stats (int stats[STAT_MAX], int points_spent[STAT_MAX], int *points_left, bool update_display)
static bool buy_stat (int choice, int stats[STAT_MAX], int points_spent[STAT_MAX], int *points_left, bool update_display)
static bool sell_stat (int choice, int stats[STAT_MAX], int points_spent[STAT_MAX], int *points_left, bool update_display)
static void generate_stats (int stats[STAT_MAX], int points_spent[STAT_MAX], int *points_left)
 This picks some reasonable starting values for stats based on the current race/class combo, etc.
void player_generate (struct player *p, const struct player_race *r, const struct player_class *c)
 This fleshes out a full player based on the choices currently made, and so is called whenever things like race or class are chosen.
static void do_birth_reset (bool use_quickstart, birther *quickstart_prev)
 Reset everything back to how it would be on loading the game.
void do_cmd_birth_init (struct command *cmd)
void do_cmd_birth_reset (struct command *cmd)
void do_cmd_choose_race (struct command *cmd)
void do_cmd_choose_class (struct command *cmd)
void do_cmd_buy_stat (struct command *cmd)
void do_cmd_sell_stat (struct command *cmd)
void do_cmd_reset_stats (struct command *cmd)
void do_cmd_roll_stats (struct command *cmd)
void do_cmd_prev_stats (struct command *cmd)
void do_cmd_choose_name (struct command *cmd)
void do_cmd_choose_history (struct command *cmd)
void do_cmd_accept_character (struct command *cmd)
char * find_roman_suffix_start (const char *buf)
 

Roman numeral functions, for dynastic successions


Variables

static int stats [STAT_MAX]
 

All of these should be in some kind of 'birth state' struct somewhere else


static int points_spent [STAT_MAX]
static int points_left
static bool quickstart_allowed
static bool rolled_stats = FALSE
static birther prev
 The last character displayed, to allow the user to flick between two.
static birther quickstart_prev
 If quickstart is allowed, we store the old character in this, to allow for it to be reloaded if we step back that far in the birth process.
static const int birth_stat_costs [18+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 4 }
 Cost of each "point" of a stat.

Detailed Description

Character creation.

Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke

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 MAX_BIRTH_POINTS   20 /* 3 * (1+1+1+1+1+1+2) */

Referenced by reset_stats().

Typedef Documentation

typedef struct birther birther

Function Documentation

static bool buy_stat ( int  choice,
int  stats[STAT_MAX],
int  points_spent[STAT_MAX],
int points_left,
bool  update_display 
)
static
static void do_birth_reset ( bool  use_quickstart,
birther quickstart_prev 
)
static

Reset everything back to how it would be on loading the game.

References player::depth, get_bonuses(), load_roller_data(), and player_generate().

Referenced by do_cmd_birth_reset().

void do_cmd_accept_character ( struct command cmd)
void do_cmd_birth_init ( struct command cmd)
void do_cmd_birth_reset ( struct command cmd)
void do_cmd_buy_stat ( struct command cmd)
void do_cmd_choose_class ( struct command cmd)
void do_cmd_choose_history ( struct command cmd)
void do_cmd_choose_name ( struct command cmd)
void do_cmd_choose_race ( struct command cmd)
void do_cmd_prev_stats ( struct command cmd)
void do_cmd_reset_stats ( struct command cmd)
void do_cmd_roll_stats ( struct command cmd)
void do_cmd_sell_stat ( struct command cmd)
char* find_roman_suffix_start ( const char *  buf)


Roman numeral functions, for dynastic successions

Find the start of a possible Roman numerals suffix by going back from the end of the string to a space, then checking that all the remaining chars are valid Roman numerals.

Return the start position, or NULL if there isn't a valid suffix.

References p, and start.

Referenced by do_cmd_birth_init(), and player_safe_name().

static void generate_stats ( int  stats[STAT_MAX],
int  points_spent[STAT_MAX],
int points_left 
)
static

This picks some reasonable starting values for stats based on the current race/class combo, etc.

For now I'm disregarding concerns about role-playing, etc, and using the simple outline from http://angband.oook.cz/forum/showpost.php?p=17588&postcount=6:

0. buy base STR 17

  1. if possible buy adj DEX of 18/10
  2. spend up to half remaining points on each of spell-stat and con, but only up to max base of 16 unless a pure class [mage or priest or warrior]
  3. If there are any points left, spend as much as possible in order on DEX and then the non-spell-stat.

References buy_stat(), player::class, event_signal_birthpoints(), FALSE, player_class::magic, player_class::max_attacks, points_left, points_spent, recalculate_stats(), sell_stat(), class_magic::spell_realm, magic_realm::stat, STAT_MAX, player_state::stat_top, player::state, stats, and TRUE.

Referenced by do_cmd_choose_class(), do_cmd_choose_race(), and do_cmd_reset_stats().

static void get_ahw ( struct player p)
static
static void get_bonuses ( void  )
static
char* get_history ( struct history_chart chart)

Get the racial history, and social class, using the "history charts".

References history_chart::entries, history_entry::next, randint1, history_entry::roll, string_append(), history_entry::succ, and history_entry::text.

Referenced by do_cmd_roll_stats(), player_generate(), and test_0().

static void get_money ( void  )
static

Get the player's starting money.

References player::au, player::au_birth, angband_constants::start_gold, and z_info.

Referenced by do_cmd_accept_character().

static void get_stats ( int  stat_use[STAT_MAX])
static

Roll for a characters stats.

For efficiency, we include a chunk of "calc_bonuses()".

References player_class::c_adj, player::class, i, modify_stat_value(), player_race::r_adj, player::race, randint1, player::stat_birth, player::stat_cur, STAT_MAX, player::stat_max, and TRUE.

Referenced by do_cmd_roll_stats().

static int int_to_roman ( int  n,
char *  roman,
size_t  bufsize 
)
static

Converts an arabic numeral (int) to a roman numeral (char *).

An arabic numeral is accepted in parameter n, and the corresponding upper-case roman numeral is placed in the parameter roman. The length of the buffer must be passed in the bufsize parameter. When there is insufficient room in the buffer, or a roman numeral does not exist (e.g. non-positive integers) a value of 0 is returned and the roman buffer will be the empty string. On success, a value of 1 is returned and the zero-terminated roman numeral is placed in the parameter roman.

References i, and my_strcat().

Referenced by do_cmd_birth_init().

static void load_roller_data ( birther saved,
birther prev_player 
)
static

Load stored player data from 'player' as the currently rolled data, optionally placing the current data in 'prev_player' (if 'prev_player' is non-NULL).

It is perfectly legal to specify the same "birther" for both 'player' and 'prev_player'.

References birther::age, player::age, birther::au, player::au, player::au_birth, birther::class, player::class, birther::history, player::history, player::ht, player::ht_birth, i, birther::race, player::race, save_roller_data(), angband_constants::start_gold, birther::stat, player::stat_birth, player::stat_cur, STAT_MAX, player::stat_max, player::wt, player::wt_birth, and z_info.

Referenced by do_birth_reset(), and do_cmd_prev_stats().

void player_generate ( struct player p,
const struct player_race r,
const struct player_class c 
)
void player_init ( struct player p)
static void player_outfit ( struct player p)
static
static void recalculate_stats ( int stats,
int  points_left 
)
static
static void reset_stats ( int  stats[STAT_MAX],
int  points_spent[STAT_MAX],
int points_left,
bool  update_display 
)
static
static void roll_hp ( void  )
static
static int roman_to_int ( const char *  roman)
static

Overview

This file contains the game-mechanical part of the birth process.

Converts a roman numeral (char *) to an arabic numeral (int).

To follow the code, start at player_birth towards the bottom of the file - that is the only external entry point to the functions defined here.

Player (in the Angband sense of character) birth is modelled as a a series of commands from the UI to the game to manipulate the character and corresponding events to inform the UI of the outcomes of these changes.

The current aim of this section is that after any birth command is carried out, the character should be left in a playable state. In particular, this means that if a savefile is supplied, the character will be set up according to the "quickstart" rules until another race or class is chosen, or until the stats are reset by the UI.

Once the UI signals that the player is happy with the character, the game does housekeeping to ensure the character is ready to start the game (clearing the history log, making sure options are set, etc) before returning control to the game proper.

The null-terminated roman numeral is accepted in the roman parameter and the corresponding integer arabic numeral is returned. Only upper-case values are considered. When the roman parameter is empty or does not resemble a roman numeral, a value of -1 is returned.

XXX This function will parse certain non-sense strings as roman numerals, such as IVXCCCVIII

References c1, c2, i, and p.

Referenced by do_cmd_birth_init().

static void save_roller_data ( birther tosave)
static
static bool sell_stat ( int  choice,
int  stats[STAT_MAX],
int  points_spent[STAT_MAX],
int points_left,
bool  update_display 
)
static
void wield_all ( struct player p)

Variable Documentation

const int birth_stat_costs[18+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 4 }
static

Cost of each "point" of a stat.

Referenced by buy_stat(), and sell_stat().

int points_left
static
int points_spent[STAT_MAX]
static
birther prev
static

The last character displayed, to allow the user to flick between two.

We rely on prev.age being zero to determine whether there is a stored character or not, so initialise it here.

Referenced by describe_elements(), event_remove_handler(), finish_parse_history(), keymap_remove(), lore_append_abilities(), obj_desc_name_format(), object_delete(), pile_check_integrity(), pile_excise(), test_obj_piles(), textui_do_birth(), wield_item(), and wiz_reroll_item().

bool quickstart_allowed
static
birther quickstart_prev
static

If quickstart is allowed, we store the old character in this, to allow for it to be reloaded if we step back that far in the birth process.

bool rolled_stats = FALSE
static
int stats[STAT_MAX]
static