From 42847682e6b753a819d23c3df77467f6d39c486b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move bg into GameEditData --- src/birth.cc | 47 +++++++++++++++++++++-------------------------- src/game_edit_data.hpp | 6 ++++++ src/hist_type.hpp | 4 +++- src/hist_type_fwd.hpp | 3 --- src/init1.cc | 32 ++++++++++++-------------------- src/init2.cc | 2 -- src/variable.cc | 6 ------ src/variable.hpp | 3 --- 8 files changed, 42 insertions(+), 61 deletions(-) delete mode 100644 src/hist_type_fwd.hpp (limited to 'src') diff --git a/src/birth.cc b/src/birth.cc index 889d1cc9..0d8a5e20 100644 --- a/src/birth.cc +++ b/src/birth.cc @@ -58,6 +58,7 @@ #include "xtra2.hpp" #include "z-rand.hpp" +#include #include #include @@ -518,6 +519,8 @@ static void get_extra(void) */ static void get_history(void) { + auto const &bg = game->edit_data.bg; + int i, n, chart, roll; char *s, *t; @@ -526,7 +529,10 @@ static void get_history(void) /* Clear the previous history strings */ - for (i = 0; i < 4; i++) history[i][0] = '\0'; + for (i = 0; i < 4; i++) + { + history[i][0] = '\0'; + } /* Clear the history text */ buf[0] = '\0'; @@ -543,12 +549,14 @@ static void get_history(void) /* Roll for nobility */ roll = randint(100); - /* Access the proper entry in the table */ - while ((chart != bg[i].chart) || (roll > bg[i].roll)) i++; + while ((chart != bg[i].chart) || (roll > bg[i].roll)) + { + i++; + } /* Acquire the textual history */ - (void)strcat(buf, bg[i].info); + strcat(buf, bg[i].info.c_str()); /* Enter the next chart */ chart = bg[i].next; @@ -2941,12 +2949,9 @@ static bool_ player_birth_aux() /* * Helper function for validate_bg(). */ -static void validate_bg_aux(int chart, bool_ chart_checked[], char *buf) +static void validate_bg_aux(int chart, bool_ chart_checked[], std::string &buf) { - char *s; - - int i; - + auto const &bg = game->edit_data.bg; /* Assume the chart does not exist */ bool_ chart_exists = FALSE; @@ -2954,34 +2959,29 @@ static void validate_bg_aux(int chart, bool_ chart_checked[], char *buf) /* Assume the chart is not complete */ bool_ chart_complete = FALSE; - int bg_max = max_bg_idx; - /* No chart */ if (!chart) return; /* Already saw this chart */ if (chart_checked[chart]) return; - /* Build a debug message */ - s = buf + strlen(buf); - /* XXX XXX XXX */ - (void) strnfmt(s, -1, "%d --> ", chart); + buf += fmt::format("{:d} --> ", chart); /* Check each chart */ - for (i = 0; i < bg_max; i++) + for (auto const &hist: bg) { /* Require same chart */ - if (bg[i].chart != chart) continue; + if (hist.chart != chart) continue; /* The chart exists */ chart_exists = TRUE; /* Validate the "next" chart recursively */ - validate_bg_aux(bg[i].next, chart_checked, buf); + validate_bg_aux(hist.next, chart_checked, buf); /* Require a terminator */ - if (bg[i].roll != 100) continue; + if (hist.roll != 100) continue; /* The chart is complete */ chart_complete = TRUE; @@ -2990,7 +2990,7 @@ static void validate_bg_aux(int chart, bool_ chart_checked[], char *buf) /* Failed: The chart does not exist */ if (!chart_exists) { - quit_fmt("birth.c: bg[] chart %d does not exist\n%s", chart, buf); + quit_fmt("birth.c: bg[] chart %d does not exist\n%s", chart, buf.c_str()); } /* Failed: The chart is not complete */ @@ -3001,9 +3001,6 @@ static void validate_bg_aux(int chart, bool_ chart_checked[], char *buf) /* Remember we saw this chart */ chart_checked[chart] = TRUE; - - /* Build a debug message */ - *s = 0; } @@ -3027,10 +3024,8 @@ static void validate_bg(void) /* Get the first chart for this race */ int chart = race.chart; - /* Buffer */ - char buf[1024] = { '\0' }; - /* Validate the chart recursively */ + std::string buf; validate_bg_aux(chart, chart_checked, buf); } } diff --git a/src/game_edit_data.hpp b/src/game_edit_data.hpp index 7addfd65..9370b7d4 100644 --- a/src/game_edit_data.hpp +++ b/src/game_edit_data.hpp @@ -1,5 +1,6 @@ #pragma once +#include "hist_type.hpp" #include "owner_type.hpp" #include "player_class.hpp" #include "player_race.hpp" @@ -58,4 +59,9 @@ struct GameEditData { */ std::vector race_mod_info; + /** + * Player race histories + */ + std::vector bg; + }; diff --git a/src/hist_type.hpp b/src/hist_type.hpp index 2da47b7c..07b5a632 100644 --- a/src/hist_type.hpp +++ b/src/hist_type.hpp @@ -2,12 +2,14 @@ #include "h-basic.h" +#include + /** * Player background descriptor. */ struct hist_type { - char *info; /* Textual History */ + std::string info; /* Textual History */ byte roll; /* Frequency of this entry */ s16b chart; /* Chart index */ diff --git a/src/hist_type_fwd.hpp b/src/hist_type_fwd.hpp deleted file mode 100644 index d1cbce91..00000000 --- a/src/hist_type_fwd.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -struct hist_type; diff --git a/src/init1.cc b/src/init1.cc index 3b0bb701..f6d798a9 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -922,6 +922,7 @@ errr init_player_info_txt(FILE *fp) auto &class_info = game->edit_data.class_info; auto &race_info = game->edit_data.race_info; auto &race_mod_info = game->edit_data.race_mod_info; + auto &bg = game->edit_data.bg; int lev = 1; int tit_idx = 0; @@ -962,21 +963,21 @@ errr init_player_info_txt(FILE *fp) /* Process 'H' for "History" */ if (buf[0] == 'H') { - int idx; - char *zz[6]; + char *zz[5]; /* Scan for the values */ - if (tokenize(buf + 2, 6, zz, ':', ':') != 6) return (1); + if (tokenize(buf + 2, 5, zz, ':', ':') != 5) return (1); - idx = atoi(zz[0]); - bg[idx].roll = atoi(zz[1]); - bg[idx].chart = atoi(zz[2]); - bg[idx].next = atoi(zz[3]); - bg[idx].bonus = atoi(zz[4]); + /* Create new entry */ + hist_type hist; + hist.roll = atoi(zz[0]); + hist.chart = atoi(zz[1]); + hist.next = atoi(zz[2]); + hist.bonus = atoi(zz[3]); + hist.info = my_strdup(zz[4]); - /* Copy text */ - assert(!bg[idx].info); - bg[idx].info = my_strdup(zz[5]); + /* Append */ + bg.emplace_back(hist); /* Next... */ continue; @@ -6940,15 +6941,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_o_idx = atoi(zz[1]); } - /* Maximum player types */ - else if (zz[0][0] == 'P') - { - if (zz[1][0] == 'H') - { - max_bg_idx = atoi(zz[2]); - } - } - /* Maximum m_idx */ else if (zz[0][0] == 'M') { diff --git a/src/init2.cc b/src/init2.cc index 1596c057..be69192f 100644 --- a/src/init2.cc +++ b/src/init2.cc @@ -15,7 +15,6 @@ #include "generate.hpp" #include "gen_evol.hpp" #include "gen_maze.hpp" -#include "hist_type.hpp" #include "hooks.hpp" #include "init1.hpp" #include "lua_bind.hpp" @@ -551,7 +550,6 @@ namespace { static void allocate() { - bg = make_array(max_bg_idx); gen_skill = new skill_modifiers; } diff --git a/src/variable.cc b/src/variable.cc index 426d4b3a..272d9267 100644 --- a/src/variable.cc +++ b/src/variable.cc @@ -773,12 +773,6 @@ DECLARE_FLAG_ZERO_IMPL(dungeon_flag_set, dungeon_flags); */ birther previous_char; -/* - * Race histories - */ -hist_type *bg; -int max_bg_idx; - /* * The spell list of schools */ diff --git a/src/variable.hpp b/src/variable.hpp index 80520f67..9b1e4816 100644 --- a/src/variable.hpp +++ b/src/variable.hpp @@ -13,7 +13,6 @@ #include "ego_item_type_fwd.hpp" #include "fate.hpp" #include "feature_type_fwd.hpp" -#include "hist_type_fwd.hpp" #include "monster_ego_fwd.hpp" #include "monster_race_fwd.hpp" #include "monster_type_fwd.hpp" @@ -225,7 +224,6 @@ extern bool_ *special_lvl[MAX_DUNGEON_DEPTH]; extern bool_ generate_special_feeling; DECLARE_FLAG_ZERO_INTF(dungeon_flag_set, dungeon_flags); extern birther previous_char; -extern int max_bg_idx; extern s16b schools_count; extern school_type schools[SCHOOLS_MAX]; extern int project_time; @@ -248,7 +246,6 @@ extern s32b DUNGEON_ASTRAL_WILD_Y; extern deity_type deity_info[MAX_GODS]; extern timer_type *gl_timers; extern const char *get_version_string(); -extern hist_type *bg; extern bool_ arg_wizard; extern bool_ arg_force_original; extern bool_ arg_force_roguelike; -- cgit v1.2.3