summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-10-05 18:45:08 +0200
committerBardur Arantsson <bardur@scientician.net>2016-10-05 18:45:08 +0200
commitb329b2fd77e32112a08fc41e1be58b32648225cf (patch)
tree6478e5cd4f782c85f40935c232b4337712acadb0
parentfd6449ac75f553e32d2efa84c3cdfba88bb32d6e (diff)
Move ow_info and ba_info into GameEditData
-rw-r--r--lib/edit/misc.txt6
-rw-r--r--lib/mods/theme/edit/misc.txt6
-rw-r--r--src/bldg.cc9
-rw-r--r--src/game_edit_data.hpp12
-rw-r--r--src/init1.cc44
-rw-r--r--src/init2.cc4
-rw-r--r--src/owner_type.hpp14
-rw-r--r--src/owner_type_fwd.hpp3
-rw-r--r--src/store.cc37
-rw-r--r--src/store_action_type.hpp12
-rw-r--r--src/util.cc1
-rw-r--r--src/util.hpp4
-rw-r--r--src/variable.cc20
-rw-r--r--src/variable.hpp6
14 files changed, 75 insertions, 103 deletions
diff --git a/lib/edit/misc.txt b/lib/edit/misc.txt
index 2db42931..0a9f4fdc 100644
--- a/lib/edit/misc.txt
+++ b/lib/edit/misc.txt
@@ -45,12 +45,6 @@ M:U:176
# Maximum number of terrain types in wf_info.txt
M:W:30
-# Maximum number of owners types in ow_info.txt
-M:N:70
-
-# Maximum number of building actions in ba_info.txt
-M:B:62
-
# Maximum number of store types in st_info.txt
M:S:61
diff --git a/lib/mods/theme/edit/misc.txt b/lib/mods/theme/edit/misc.txt
index 04e87eae..4fa03332 100644
--- a/lib/mods/theme/edit/misc.txt
+++ b/lib/mods/theme/edit/misc.txt
@@ -45,12 +45,6 @@ M:U:176
# Maximum number of terrain types in wf_info.txt
M:W:64
-# Maximum number of owners types in ow_info.txt
-M:N:215
-
-# Maximum number of building actions in ba_info.txt
-M:B:70
-
# Maximum number of store types in st_info.txt
M:S:89
diff --git a/src/bldg.cc b/src/bldg.cc
index d465dbbe..0425a909 100644
--- a/src/bldg.cc
+++ b/src/bldg.cc
@@ -16,6 +16,7 @@
#include "cave_type.hpp"
#include "cmd3.hpp"
#include "files.hpp"
+#include "game.hpp"
#include "hooks.hpp"
#include "hook_quest_finish_in.hpp"
#include "hook_quest_fail_in.hpp"
@@ -53,8 +54,9 @@ static int building_loc = 0;
*/
static bool_ is_state_aux(store_type const *s_ptr, int state)
{
- owner_type *ow_ptr = &ow_info[s_ptr->owner];
+ auto const &ow_info = game->edit_data.ow_info;
+ auto ow_ptr = &ow_info[s_ptr->owner];
/* Check race */
if (ow_ptr->races[state][p_ptr->prace / 32] & (1 << p_ptr->prace))
@@ -112,11 +114,12 @@ static void clear_bldg(int min_row, int max_row)
*/
void show_building(store_type const *s_ptr)
{
+ auto const &ba_info = game->edit_data.ba_info;
store_info_type *st_ptr = &st_info[s_ptr->st_idx];
for (std::size_t i = 0; i < st_ptr->actions.size(); i++)
{
- store_action_type *ba_ptr = &ba_info[st_ptr->actions[i]];
+ auto ba_ptr = &ba_info[st_ptr->actions[i]];
byte action_color;
char buff[20];
@@ -194,7 +197,7 @@ void show_building(store_type const *s_ptr)
strnfmt(tmp_str, 80, " %c", ba_ptr->letter);
c_put_str(TERM_YELLOW, tmp_str, 21 + (i / 2), 17 + (30 * (i % 2)));
- strnfmt(tmp_str, 80, ") %s %s", ba_ptr->name, buff);
+ strnfmt(tmp_str, 80, ") %s %s", ba_ptr->name.c_str(), buff);
c_put_str(action_color, tmp_str, 21 + (i / 2), 2 + 17 + (30 * (i % 2)));
}
}
diff --git a/src/game_edit_data.hpp b/src/game_edit_data.hpp
index 2cfea630..8ffb6b9a 100644
--- a/src/game_edit_data.hpp
+++ b/src/game_edit_data.hpp
@@ -1,7 +1,9 @@
#pragma once
+#include "owner_type.hpp"
#include "randart_gen_type.hpp"
#include "randart_part_type.hpp"
+#include "store_action_type.hpp"
#include "vault_type.hpp"
#include <vector>
@@ -28,4 +30,14 @@ struct GameEditData {
*/
std::vector<randart_gen_type> ra_gen;
+ /**
+ * Building actions.
+ */
+ std::vector<store_action_type> ba_info;
+
+ /**
+ * Building owners.
+ */
+ std::vector<owner_type> ow_info;
+
};
diff --git a/src/init1.cc b/src/init1.cc
index 4f563005..086314a2 100644
--- a/src/init1.cc
+++ b/src/init1.cc
@@ -5928,9 +5928,9 @@ errr init_st_info_txt(FILE *fp)
*/
errr init_ba_info_txt(FILE *fp)
{
- int i = 0;
+ auto &ba_info = game->edit_data.ba_info;
+
char buf[1024];
- char *s;
/* Current entry */
store_action_type *ba_ptr = NULL;
@@ -5958,7 +5958,7 @@ errr init_ba_info_txt(FILE *fp)
if (buf[0] == 'N')
{
/* Find the colon before the name */
- s = strchr(buf + 2, ':');
+ char *s = strchr(buf + 2, ':');
/* Verify that colon */
if (!s) return (1);
@@ -5970,23 +5970,19 @@ errr init_ba_info_txt(FILE *fp)
if (!*s) return (1);
/* Get the index */
- i = atoi(buf + 2);
+ int i = atoi(buf + 2);
/* Verify information */
if (i < error_idx) return (4);
- /* Verify information */
- if (i >= max_ba_idx) return (2);
-
/* Save the index */
error_idx = i;
/* Point at the "info" */
- ba_ptr = &ba_info[i];
+ ba_ptr = &expand_to_fit_index(ba_info, i);
/* Copy name */
- assert(!ba_ptr->name);
- ba_ptr->name = my_strdup(s);
+ ba_ptr->name = s;
/* Next... */
continue;
@@ -6047,9 +6043,9 @@ errr init_ba_info_txt(FILE *fp)
*/
errr init_ow_info_txt(FILE *fp)
{
- int i;
+ auto &ow_info = game->edit_data.ow_info;
+
char buf[1024];
- char *s;
/* Current entry */
owner_type *ow_ptr = NULL;
@@ -6076,7 +6072,7 @@ errr init_ow_info_txt(FILE *fp)
if (buf[0] == 'N')
{
/* Find the colon before the name */
- s = strchr(buf + 2, ':');
+ char *s = strchr(buf + 2, ':');
/* Verify that colon */
if (!s) return (1);
@@ -6088,23 +6084,19 @@ errr init_ow_info_txt(FILE *fp)
if (!*s) return (1);
/* Get the index */
- i = atoi(buf + 2);
+ int i = atoi(buf + 2);
/* Verify information */
if (i < error_idx) return (4);
- /* Verify information */
- if (i >= max_ow_idx) return (2);
-
/* Save the index */
error_idx = i;
/* Point at the "info" */
- ow_ptr = &ow_info[i];
+ ow_ptr = &expand_to_fit_index(ow_info, i);
/* Copy name */
- assert(!ow_ptr->name);
- ow_ptr->name = my_strdup(s);
+ ow_ptr->name = s;
/* Next... */
continue;
@@ -7067,12 +7059,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst
max_wf_idx = atoi(zz[1]);
}
- /* Maximum ba_idx */
- else if (zz[0][0] == 'B')
- {
- max_ba_idx = atoi(zz[1]);
- }
-
/* Maximum st_idx */
else if (zz[0][0] == 'S')
{
@@ -7085,12 +7071,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst
max_set_idx = atoi(zz[1]);
}
- /* Maximum ow_idx */
- else if (zz[0][0] == 'N')
- {
- max_ow_idx = atoi(zz[1]);
- }
-
/* Maximum wilderness x size */
else if (zz[0][0] == 'X')
{
diff --git a/src/init2.cc b/src/init2.cc
index 98476d58..160dbeef 100644
--- a/src/init2.cc
+++ b/src/init2.cc
@@ -472,7 +472,7 @@ namespace {
static void allocate()
{
- ow_info = make_array<owner_type>(max_ow_idx);
+ // Nothing to do
}
static errr parse(FILE *fp)
@@ -488,7 +488,7 @@ namespace {
static void allocate()
{
- ba_info = make_array<store_action_type>(max_ba_idx);
+ // Nothing to do
}
static errr parse(FILE *fp)
diff --git a/src/owner_type.hpp b/src/owner_type.hpp
index 703d3159..4c47dc48 100644
--- a/src/owner_type.hpp
+++ b/src/owner_type.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include <string>
+
#include "h-basic.h"
/*
@@ -10,30 +12,30 @@ struct owner_type
/**
* Name
*/
- const char *name;
+ std::string name;
/**
* Purse limit
*/
- s16b max_cost;
+ s16b max_cost = 0;
/**
* Inflation
*/
- s16b inflation;
+ s16b inflation = 0;
/**
* Liked/hated races.
*/
- u32b races[2][2];
+ u32b races[2][2] { };
/**
* Liked/hated classes
*/
- u32b classes[2][2];
+ u32b classes[2][2] { };
/**
* Costs for liked people
*/
- s16b costs[3];
+ s16b costs[3] { };
};
diff --git a/src/owner_type_fwd.hpp b/src/owner_type_fwd.hpp
deleted file mode 100644
index 20c25802..00000000
--- a/src/owner_type_fwd.hpp
+++ /dev/null
@@ -1,3 +0,0 @@
-#pragma once
-
-struct owner_type;
diff --git a/src/store.cc b/src/store.cc
index eb8f703c..ab6e119b 100644
--- a/src/store.cc
+++ b/src/store.cc
@@ -15,6 +15,7 @@
#include "cmd4.hpp"
#include "cmd5.hpp"
#include "files.hpp"
+#include "game.hpp"
#include "hooks.hpp"
#include "obj_theme.hpp"
#include "object1.hpp"
@@ -223,7 +224,7 @@ static store_type *st_ptr = NULL;
/*
* We store the current "owner type" here so everyone can access it
*/
-static owner_type *ot_ptr = NULL;
+static owner_type const *ot_ptr = NULL;
@@ -1577,7 +1578,7 @@ void display_store(void)
else
{
/* Put the owner name and race */
- strnfmt(buf, 80, "%s", ot_ptr->name);
+ strnfmt(buf, 80, "%s", ot_ptr->name.c_str());
put_str(buf, 3, 10);
/* Show the max price in the store (above prices) */
@@ -2757,8 +2758,10 @@ static bool_ leave_store = FALSE;
* Find building action for command. Returns nullptr if no matching
* action is found.
*/
-static store_action_type *find_store_action(s16b command_cmd)
+static store_action_type const *find_store_action(s16b command_cmd)
{
+ auto const &ba_info = game->edit_data.ba_info;
+
for (std::size_t i = 0; i < st_info[st_ptr->st_idx].actions.size(); i++)
{
auto ba_ptr = &ba_info[st_info[st_ptr->st_idx].actions[i]];
@@ -2793,8 +2796,7 @@ static bool_ store_process_command(void)
/* Handle repeating the last command */
repeat_check();
- store_action_type *ba_ptr =
- find_store_action(command_cmd);
+ auto ba_ptr = find_store_action(command_cmd);
if (ba_ptr)
{
@@ -3097,6 +3099,9 @@ static bool_ store_process_command(void)
*/
void do_cmd_store(void)
{
+ auto const &ow_info = game->edit_data.ow_info;
+ auto const &ba_info = game->edit_data.ba_info;
+
int which;
int maintain_num;
int tmp_chr;
@@ -3180,7 +3185,7 @@ void do_cmd_store(void)
/* Mega-Hack -- Ignore keymaps on store action letters */
for (std::size_t i = 0; i < st_info[st_ptr->st_idx].actions.size(); i++)
{
- store_action_type *ba_ptr = &ba_info[st_info[st_ptr->st_idx].actions[i]];
+ auto ba_ptr = &ba_info[st_info[st_ptr->st_idx].actions[i]];
request_command_ignore_keymaps[2*i] = ba_ptr->letter;
request_command_ignore_keymaps[2*i+1] = ba_ptr->letter_aux;
}
@@ -3363,6 +3368,8 @@ void do_cmd_store(void)
*/
void store_shuffle(int which)
{
+ auto const &ow_info = game->edit_data.ow_info;
+
/* Ignore home */
if (which == STORE_HOME) return;
@@ -3410,6 +3417,8 @@ void store_shuffle(int which)
*/
void store_maint(int town_num, int store_num)
{
+ auto const &ow_info = game->edit_data.ow_info;
+
int const old_rating = rating;
cur_store_num = store_num;
@@ -3500,6 +3509,8 @@ void store_maint(int town_num, int store_num)
*/
void store_init(int town_num, int store_num)
{
+ auto const &ow_info = game->edit_data.ow_info;
+
cur_store_num = store_num;
// Activate store
@@ -3540,10 +3551,12 @@ void store_init(int town_num, int store_num)
*/
void do_cmd_home_trump(void)
{
+ auto const &ow_info = game->edit_data.ow_info;
+ auto const &ba_info = game->edit_data.ba_info;
+
int which;
int maintain_num;
int tmp_chr;
- int i;
int town_num;
/* Extract the store code */
@@ -3568,8 +3581,10 @@ void do_cmd_home_trump(void)
if (maintain_num)
{
/* Maintain the store */
- for (i = 0; i < maintain_num; i++)
+ for (int i = 0; i < maintain_num; i++)
+ {
store_maint(town_num, which);
+ }
/* Save the visit */
town_info[town_num].store[which].last_visit = turn;
@@ -3611,10 +3626,10 @@ void do_cmd_home_trump(void)
display_store();
/* Mega-Hack -- Ignore keymaps on store action letters */
- for (i = 0; i < 6; i++)
+ auto const &st_actions = st_info[st_ptr->st_idx].actions;
+ for (std::size_t i = 0; (i < (MAX_IGNORE_KEYMAPS/2)) && (i < st_actions.size()); i++)
{
- store_action_type *ba_ptr =
- &ba_info[st_info[st_ptr->st_idx].actions[i]];
+ auto ba_ptr = &ba_info[st_actions[i]];
request_command_ignore_keymaps[2*i] = ba_ptr->letter;
request_command_ignore_keymaps[2*i+1] = ba_ptr->letter_aux;
}
diff --git a/src/store_action_type.hpp b/src/store_action_type.hpp
index 048e13a0..ee479375 100644
--- a/src/store_action_type.hpp
+++ b/src/store_action_type.hpp
@@ -7,11 +7,11 @@
*/
struct store_action_type
{
- const char *name; /* Name */
+ std::string name; /* Name */
- s16b costs[3]; /* Costs for liked people */
- char letter; /* Action letter */
- char letter_aux; /* Action letter */
- s16b action; /* Action code */
- s16b action_restr; /* Action restriction */
+ std::array<s16b, 3> costs { }; /* Costs for liked people */
+ char letter = '\0'; /* Action letter */
+ char letter_aux = '\0'; /* Action letter */
+ s16b action = 0; /* Action code */
+ s16b action_restr = 0; /* Action restriction */
};
diff --git a/src/util.cc b/src/util.cc
index 6dfbca65..cde2fcb6 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -2716,7 +2716,6 @@ static char request_command_buffer[256];
* request_command(). This MUST have at least twice as many characters as
* there are building actions in the actions[] array in store_info_type.
*/
-#define MAX_IGNORE_KEYMAPS 12
char request_command_ignore_keymaps[MAX_IGNORE_KEYMAPS];
/*
diff --git a/src/util.hpp b/src/util.hpp
index eafe4f31..c4c7b30c 100644
--- a/src/util.hpp
+++ b/src/util.hpp
@@ -6,6 +6,8 @@
#include <vector>
#include <string>
+#define MAX_IGNORE_KEYMAPS 12
+
extern bool_ input_box(cptr text, int y, int x, char *buf, int max);
extern void draw_box(int y, int x, int h, int w);
extern void display_list(int y, int x, int h, int w, cptr title, cptr *list, int max, int begin, int sel, byte sel_color);
@@ -54,7 +56,7 @@ extern bool_ get_string(cptr prompt, char *buf, int len);
extern bool_ get_check(cptr prompt);
extern bool_ get_com(cptr prompt, char *command);
extern s32b get_quantity(cptr prompt, s32b max);
-extern char request_command_ignore_keymaps[];
+extern char request_command_ignore_keymaps[MAX_IGNORE_KEYMAPS];
extern bool_ request_command_inven_mode;
extern void request_command(int shopping);
extern bool_ is_a_vowel(int ch);
diff --git a/src/variable.cc b/src/variable.cc
index 3d27e442..1eb5aaab 100644
--- a/src/variable.cc
+++ b/src/variable.cc
@@ -517,16 +517,6 @@ int wildc2i[256];
store_info_type *st_info;
/*
- * The building actions types arrays
- */
-store_action_type *ba_info;
-
-/*
- * The owner types arrays
- */
-owner_type *ow_info;
-
-/*
* Default texts for feature information.
*/
cptr DEFAULT_FEAT_TEXT = "a wall blocking your way";
@@ -706,16 +696,6 @@ u16b max_c_idx;
u16b max_mc_idx;
/*
- * Maximum number of actions types in ba_info.txt
- */
-u16b max_ba_idx;
-
-/*
- * Maximum number of owner types in ow_info.txt
- */
-u16b max_ow_idx;
-
-/*
* Maximum number of objects in the level
*/
u16b max_o_idx;
diff --git a/src/variable.hpp b/src/variable.hpp
index b9c965a5..a42d246c 100644
--- a/src/variable.hpp
+++ b/src/variable.hpp
@@ -21,7 +21,6 @@
#include "object_kind_fwd.hpp"
#include "object_type_fwd.hpp"
#include "options.hpp"
-#include "owner_type_fwd.hpp"
#include "player_class_fwd.hpp"
#include "player_defs.hpp"
#include "player_race_fwd.hpp"
@@ -36,7 +35,6 @@
#include "skill_modifiers_fwd.hpp"
#include "skill_type_fwd.hpp"
#include "skills_defs.hpp"
-#include "store_action_type_fwd.hpp"
#include "store_info_type_fwd.hpp"
#include "timer_type_fwd.hpp"
#include "town_type_fwd.hpp"
@@ -183,8 +181,6 @@ extern trap_type *t_info;
extern wilderness_type_info *wf_info;
extern int wildc2i[256];
extern store_info_type *st_info;
-extern store_action_type *ba_info;
-extern owner_type *ow_info;
extern set_type *set_info;
extern cptr DEFAULT_FEAT_TEXT;
extern cptr DEFAULT_FEAT_TUNNEL;
@@ -213,8 +209,6 @@ extern u16b max_c_idx;
extern u16b max_mc_idx;
extern u16b max_rmp_idx;
extern u16b max_st_idx;
-extern u16b max_ba_idx;
-extern u16b max_ow_idx;
extern u16b max_wf_idx;
extern u16b max_set_idx;
extern int init_flags;