diff options
author | Bardur Arantsson <bardur@scientician.net> | 2016-10-05 18:45:08 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2016-10-05 18:45:08 +0200 |
commit | fd6449ac75f553e32d2efa84c3cdfba88bb32d6e (patch) | |
tree | 61499f66f9f44171085ef4d3ba9aad4955658f2b | |
parent | 1173c144b06d5d2d3c9e6351af5e6f06cb843d4b (diff) |
Move ra_gen and ra_info into GameEditData
-rw-r--r-- | lib/edit/misc.txt | 3 | ||||
-rw-r--r-- | lib/mods/theme/edit/misc.txt | 3 | ||||
-rw-r--r-- | src/game_edit_data.hpp | 13 | ||||
-rw-r--r-- | src/init1.cc | 71 | ||||
-rw-r--r-- | src/init2.cc | 2 | ||||
-rw-r--r-- | src/object2.cc | 21 | ||||
-rw-r--r-- | src/randart.cc | 75 | ||||
-rw-r--r-- | src/randart_gen_type_fwd.hpp | 3 | ||||
-rw-r--r-- | src/randart_part_type.hpp | 16 | ||||
-rw-r--r-- | src/randart_part_type_fwd.hpp | 3 | ||||
-rw-r--r-- | src/variable.cc | 11 | ||||
-rw-r--r-- | src/variable.hpp | 5 |
12 files changed, 106 insertions, 120 deletions
diff --git a/lib/edit/misc.txt b/lib/edit/misc.txt index 91b903a6..2db42931 100644 --- a/lib/edit/misc.txt +++ b/lib/edit/misc.txt @@ -12,9 +12,6 @@ M:X:101 # Maximum y size of the wilderness M:Y:66 -# Maximum number of randart parts in ra_info.txt -M:Z:516 - # Maximum number of monsters in r_info.txt # WARNING ! add one more to the real count for the player ghost !! M:R:1078 diff --git a/lib/mods/theme/edit/misc.txt b/lib/mods/theme/edit/misc.txt index 7ba48a75..04e87eae 100644 --- a/lib/mods/theme/edit/misc.txt +++ b/lib/mods/theme/edit/misc.txt @@ -12,9 +12,6 @@ M:X:101 # Maximum y size of the wilderness M:Y:66 -# Maximum number of randart parts in ra_info.txt -M:Z:519 - # Maximum number of monsters in r_info.txt # WARNING ! add one more to the real count for the player ghost !! M:R:1081 diff --git a/src/game_edit_data.hpp b/src/game_edit_data.hpp index 7dea2610..2cfea630 100644 --- a/src/game_edit_data.hpp +++ b/src/game_edit_data.hpp @@ -1,5 +1,7 @@ #pragma once +#include "randart_gen_type.hpp" +#include "randart_part_type.hpp" #include "vault_type.hpp" #include <vector> @@ -15,4 +17,15 @@ struct GameEditData { */ std::vector<vault_type> v_info; + /** + * Random artifact part descriptors, i.e. the bits that + * randarts are made up of. + */ + std::vector<randart_part_type> ra_info; + + /** + * Random artifact generation parameters. + */ + std::vector<randart_gen_type> ra_gen; + }; diff --git a/src/init1.cc b/src/init1.cc index 08cc80a0..4f563005 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -55,6 +55,7 @@ #include "z-rand.hpp" #include <boost/algorithm/string/predicate.hpp> +#include <stdlib.h> using boost::algorithm::iequals; using boost::algorithm::ends_with; @@ -4013,9 +4014,10 @@ errr init_e_info_txt(FILE *fp) */ errr init_ra_info_txt(FILE *fp) { - int i, cur_t = 0, j, cur_g = 0; + auto &ra_gen = game->edit_data.ra_gen; + auto &ra_info = game->edit_data.ra_info; + char buf[1024]; - char *s; /* Current entry */ randart_part_type *ra_ptr = NULL; @@ -4050,11 +4052,14 @@ errr init_ra_info_txt(FILE *fp) &chance, &dd, &ds, &plus)) return (1); /* Save the values */ - ra_gen[cur_g].chance = chance; - ra_gen[cur_g].dd = dd; - ra_gen[cur_g].ds = ds; - ra_gen[cur_g].plus = plus; - cur_g++; + randart_gen_type gen; + gen.chance = chance; + gen.dd = dd; + gen.ds = ds; + gen.plus = plus; + + /* Add to data */ + ra_gen.emplace_back(gen); /* Next... */ continue; @@ -4064,30 +4069,16 @@ errr init_ra_info_txt(FILE *fp) if (buf[0] == 'N') { /* 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_ra_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - ra_ptr = &ra_info[i]; - - /* Needed hack */ - ra_ptr->power = -1; - cur_t = 0; - - for (j = 0; j < 20; j++) - { - ra_ptr->tval[j] = 255; - } - ra_ptr->flags = object_flag_set(); - ra_ptr->fego = ego_flag_set(); + ra_ptr = &expand_to_fit_index(ra_info, i); /* Next... */ continue; @@ -4099,20 +4090,19 @@ errr init_ra_info_txt(FILE *fp) /* Process 'T' for "Tval/Sval" (up to 5 lines) */ if (buf[0] == 'T') { - int tv, minsv, maxsv; - - if (cur_t == 20) return 1; - /* Scan for the values */ + int tv, minsv, maxsv; if (3 != sscanf(buf + 2, "%d:%d:%d", &tv, &minsv, &maxsv)) return (1); - /* Save the values */ - ra_ptr->tval[cur_t] = tv; - ra_ptr->min_sval[cur_t] = minsv; - ra_ptr->max_sval[cur_t] = maxsv; + /* Set up filter */ + randart_part_type::kind_filter_t filter; + filter.tval = tv; + filter.min_sval = minsv; + filter.max_sval = maxsv; - cur_t++; + /* Add filter */ + ra_ptr->kind_filter.emplace_back(filter); /* Next... */ continue; @@ -4174,18 +4164,21 @@ errr init_ra_info_txt(FILE *fp) /* Process 'Z' for "Granted power" */ if (buf[0] == 'Z') { - int i; - /* Acquire the text */ - s = buf + 2; + char const *s = buf + 2; /* Find it in the list */ + std::size_t i; for (i = 0; i < POWER_MAX; i++) { if (iequals(s, powers_type[i].name)) break; } - if (i == POWER_MAX) return (6); + /* Not present? Fail */ + if (i == POWER_MAX) + { + return (6); + } ra_ptr->power = i; @@ -7025,12 +7018,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_e_idx = atoi(zz[1]); } - /* Maximum ra_idx */ - else if (zz[0][0] == 'Z') - { - max_ra_idx = atoi(zz[1]); - } - /* Maximum o_idx */ else if (zz[0][0] == 'O') { diff --git a/src/init2.cc b/src/init2.cc index de810fc0..98476d58 100644 --- a/src/init2.cc +++ b/src/init2.cc @@ -392,7 +392,7 @@ namespace { static void allocate() { - ra_info = new randart_part_type[max_ra_idx]; + // Nothing to do } static errr parse(FILE *fp) diff --git a/src/object2.cc b/src/object2.cc index 98487e46..ab84a214 100644 --- a/src/object2.cc +++ b/src/object2.cc @@ -4679,23 +4679,20 @@ static bool_ kind_is_good(int k_idx) */ bool_ kind_is_artifactable(int k_idx) { - int i, j; - object_kind *k_ptr = &k_info[k_idx]; + auto const &ra_info = game->edit_data.ra_info; + object_kind *k_ptr = &k_info[k_idx]; if (kind_is_good(k_idx)) { - /* We consider the item artifactable if there is at least one - * randart power in ra_info that could be added to this item. */ - for (i = 0; i < max_ra_idx; i++) + // Consider the item artifactable if there is at least one + // randart power which could be added to the item. + for (auto const &ra_ref: ra_info) { - randart_part_type *ra_ptr = &ra_info[i]; - - for (j = 0; j < 20; j++) + for (auto const &filter: ra_ref.kind_filter) { - if (ra_ptr->tval[j] != k_ptr->tval) continue; - if (ra_ptr->min_sval[j] > k_ptr->sval) continue; - if (ra_ptr->max_sval[j] < k_ptr->sval) continue; - /* Winner */ + if (filter.tval != k_ptr->tval) continue; + if (filter.min_sval > k_ptr->sval) continue; + if (filter.max_sval < k_ptr->sval) continue; return TRUE; } } diff --git a/src/randart.cc b/src/randart.cc index 698be95b..488f11e1 100644 --- a/src/randart.cc +++ b/src/randart.cc @@ -7,6 +7,8 @@ */ #include "randart.hpp" + +#include "game.hpp" #include "mimic.hpp" #include "object1.hpp" #include "object2.hpp" @@ -14,17 +16,12 @@ #include "object_type.hpp" #include "options.hpp" #include "player_type.hpp" -#include "randart_gen_type.hpp" -#include "randart_part_type.hpp" #include "spells2.hpp" #include "util.hpp" #include "variable.h" #include "variable.hpp" #include "z-rand.hpp" -#include <memory> -#include <vector> - /* Chance of using syllables to form the name instead of the "template" files */ #define A_CURSED 13 #define WEIRD_LUCK 12 @@ -32,39 +29,49 @@ /* * Attempt to add a power to a randart */ -static bool_ grab_one_power(int *ra_idx, object_type *o_ptr, bool_ good, s16b *max_times) +static bool_ grab_one_power(int *ra_idx, object_type const *o_ptr, std::vector<s16b> &max_times) { + auto const &ra_info = game->edit_data.ra_info; + + assert(max_times.size() >= ra_info.size()); + bool_ ret = FALSE; std::vector<size_t> ok_ra; /* Grab the ok randart */ - for (size_t i = 0; i < max_ra_idx; i++) + for (size_t i = 0; i < ra_info.size(); i++) { - randart_part_type *ra_ptr = &ra_info[i]; + auto ra_ptr = &ra_info[i]; bool_ ok = FALSE; /* Must have the correct fields */ - for (size_t j = 0; j < 20; j++) + for (auto const &filter: ra_ptr->kind_filter) { - if (ra_ptr->tval[j] == o_ptr->tval) + if ((filter.tval == o_ptr->tval) && + (filter.min_sval <= o_ptr->sval) && + (o_ptr->sval <= filter.max_sval)) { - if ((ra_ptr->min_sval[j] <= o_ptr->sval) && (ra_ptr->max_sval[j] >= o_ptr->sval)) ok = TRUE; + ok = TRUE; + break; } + } - if (ok) break; + if ((0 < ra_ptr->max_pval) && (ra_ptr->max_pval < o_ptr->pval)) + { + ok = FALSE; } - if ((0 < ra_ptr->max_pval) && (ra_ptr->max_pval < o_ptr->pval)) ok = FALSE; + if (!ok) { /* Doesnt count as a try*/ continue; } - /* Good should be good, bad should be bad */ - if (good && (ra_ptr->value <= 0)) continue; - if ((!good) && (ra_ptr->value > 0)) continue; + /* Skip bad powers */ + if (ra_ptr->value <= 0) continue; + /* Already chosen the maximum number of times? */ if (max_times[i] >= ra_ptr->max) continue; /* Must NOT have the antagonic flags */ @@ -78,8 +85,8 @@ static bool_ grab_one_power(int *ra_idx, object_type *o_ptr, bool_ good, s16b *m /* Now test them a few times */ for (size_t count = 0; count < ok_ra.size() * 10; count++) { - size_t i = ok_ra[rand_int(ok_ra.size())]; - randart_part_type *ra_ptr = &ra_info[i]; + size_t i = *uniform_element(ok_ra); + auto ra_ptr = &ra_info[i]; /* XXX XXX Enforce minimum player level (loosely) */ if (ra_ptr->level > p_ptr->lev) @@ -238,8 +245,11 @@ void get_random_name(char * return_name) bool_ create_artifact(object_type *o_ptr, bool_ a_scroll, bool_ get_name) { + auto const &ra_gen = game->edit_data.ra_gen; + auto const &ra_info = game->edit_data.ra_info; + char new_name[80]; - int powers = 0, i; + int powers = 0; s32b total_flags, total_power = 0; bool_ a_cursed = FALSE; s16b pval = 0; @@ -249,35 +259,34 @@ bool_ create_artifact(object_type *o_ptr, bool_ a_scroll, bool_ get_name) if ((!a_scroll) && (randint(A_CURSED) == 1)) a_cursed = TRUE; - i = 0; - while (ra_gen[i].chance) + for (auto const &g: ra_gen) { - powers += damroll(ra_gen[i].dd, ra_gen[i].ds) + ra_gen[i].plus; - i++; + powers += damroll(g.dd, g.ds) + g.plus; } if ((!a_cursed) && (randint(30) == 1)) powers *= 2; if (a_cursed) powers /= 2; - std::unique_ptr<s16b[]> max_times(new s16b[max_ra_idx]); - for (int i = 0; i < max_ra_idx; i++) { - max_times[i] = 0; - } + std::vector<s16b> max_times(ra_info.size(), 0); /* Main loop */ while (powers) { - int ra_idx; - randart_part_type *ra_ptr; - powers--; - if (!grab_one_power(&ra_idx, o_ptr, TRUE, max_times.get())) continue; + int ra_idx; + if (!grab_one_power(&ra_idx, o_ptr, max_times)) + { + continue; + } - ra_ptr = &ra_info[ra_idx]; + auto ra_ptr = &ra_info[ra_idx]; - if (wizard) msg_format("Adding randart power: %d", ra_idx); + if (wizard) + { + msg_format("Adding randart power: %d", ra_idx); + } total_power += ra_ptr->value; diff --git a/src/randart_gen_type_fwd.hpp b/src/randart_gen_type_fwd.hpp deleted file mode 100644 index eba3e84e..00000000 --- a/src/randart_gen_type_fwd.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -struct randart_gen_type; diff --git a/src/randart_part_type.hpp b/src/randart_part_type.hpp index ad7b0c30..5a4ca329 100644 --- a/src/randart_part_type.hpp +++ b/src/randart_part_type.hpp @@ -4,14 +4,21 @@ #include "h-basic.h" #include "object_flag_set.hpp" +#include <vector> + /** * Random artifact part descriptor. */ struct randart_part_type { - byte tval[20] { }; - byte min_sval[20] { }; - byte max_sval[20] { }; +public: + struct kind_filter_t { + byte tval; + byte min_sval; + byte max_sval; + }; + + std::vector<kind_filter_t> kind_filter; byte level = 0; /* Minimum level */ byte rarity = 0; /* Object rarity */ @@ -32,5 +39,6 @@ struct randart_part_type object_flag_set aflags; /* Antagonistic ego item flags */ - s16b power = 0; /* Power granted(if any) */ + s16b power = -1; /* Power granted(if any) */ + }; diff --git a/src/randart_part_type_fwd.hpp b/src/randart_part_type_fwd.hpp deleted file mode 100644 index 979fd72c..00000000 --- a/src/randart_part_type_fwd.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -struct randart_part_type; diff --git a/src/variable.cc b/src/variable.cc index 33f9694e..3d27e442 100644 --- a/src/variable.cc +++ b/src/variable.cc @@ -455,12 +455,6 @@ set_type *set_info; */ ego_item_type *e_info; -/* - * The randart arrays - */ -randart_part_type *ra_info; -randart_gen_type ra_gen[30]; - /* jk */ /* the trap-arrays */ trap_type *t_info; @@ -689,11 +683,6 @@ u16b max_a_idx; u16b max_e_idx; /* - * Maximum number of randarts in ra_info.txt - */ -u16b max_ra_idx; - -/* * Maximum number of dungeon types in d_info.txt */ u16b max_d_idx; diff --git a/src/variable.hpp b/src/variable.hpp index f3b4c351..b9c965a5 100644 --- a/src/variable.hpp +++ b/src/variable.hpp @@ -28,8 +28,6 @@ #include "player_race_mod_fwd.hpp" #include "player_spec_fwd.hpp" #include "player_type_fwd.hpp" -#include "randart_gen_type_fwd.hpp" -#include "randart_part_type_fwd.hpp" #include "random_artifact.hpp" #include "random_quest.hpp" #include "school_type.hpp" @@ -174,8 +172,6 @@ extern feature_type *f_info; extern object_kind *k_info; extern artifact_type *a_info; extern ego_item_type *e_info; -extern randart_part_type *ra_info; -extern randart_gen_type ra_gen[30]; extern monster_race *r_info; extern monster_ego *re_info; extern dungeon_info_type *d_info; @@ -208,7 +204,6 @@ extern u16b max_k_idx; extern u16b max_f_idx; extern u16b max_a_idx; extern u16b max_e_idx; -extern u16b max_ra_idx; extern u16b max_d_idx; extern u16b max_o_idx; extern u16b max_m_idx; |