From 073ad3584fbf781ce10bef61ad4ff38850282f47 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 21 Jun 2016 13:37:02 +0200 Subject: Rework TR{1,2,3,4,5}_* flags to flag_set<> --- src/randart.cc | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) (limited to 'src/randart.cc') diff --git a/src/randart.cc b/src/randart.cc index 5135438a..9528faee 100644 --- a/src/randart.cc +++ b/src/randart.cc @@ -10,6 +10,7 @@ #include "mimic.hpp" #include "object1.hpp" #include "object2.hpp" +#include "object_flag.hpp" #include "object_type.hpp" #include "options.hpp" #include "player_type.hpp" @@ -37,7 +38,6 @@ static bool_ grab_one_power(int *ra_idx, object_type *o_ptr, bool_ good, s16b *max_times) { bool_ ret = FALSE; - u32b f1, f2, f3, f4, f5, esp; std::vector ok_ra; @@ -71,13 +71,8 @@ static bool_ grab_one_power(int *ra_idx, object_type *o_ptr, bool_ good, s16b *m if (max_times[i] >= ra_ptr->max) continue; /* Must NOT have the antagonic flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); - if (f1 & ra_ptr->aflags1) continue; - if (f2 & ra_ptr->aflags2) continue; - if (f3 & ra_ptr->aflags3) continue; - if (f4 & ra_ptr->aflags4) continue; - if (f5 & ra_ptr->aflags5) continue; - if (esp & ra_ptr->aesp) continue; + auto const flags = object_flags(o_ptr); + if (flags & ra_ptr->aflags) continue; /* ok */ ok_ra.push_back(i); @@ -124,7 +119,7 @@ static bool_ grab_one_power(int *ra_idx, object_type *o_ptr, bool_ good, s16b *m void give_activation_power (object_type * o_ptr) { o_ptr->xtra2 = 0; - o_ptr->art_flags3 &= ~TR3_ACTIVATE; + o_ptr->art_flags &= ~TR_ACTIVATE; o_ptr->timeout = 0; } @@ -268,7 +263,6 @@ bool_ create_artifact(object_type *o_ptr, bool_ a_scroll, bool_ get_name) int powers = 0, i; s32b total_flags, total_power = 0; bool_ a_cursed = FALSE; - u32b f1, f2, f3, f4, f5, esp; s16b pval = 0; bool_ limit_blows = FALSE; @@ -308,20 +302,15 @@ bool_ create_artifact(object_type *o_ptr, bool_ a_scroll, bool_ get_name) total_power += ra_ptr->value; - o_ptr->art_flags1 |= ra_ptr->flags1; - o_ptr->art_flags2 |= ra_ptr->flags2; - o_ptr->art_flags3 |= ra_ptr->flags3; - o_ptr->art_flags4 |= ra_ptr->flags4; - o_ptr->art_flags5 |= ra_ptr->flags5; - o_ptr->art_esp |= ra_ptr->esp; + o_ptr->art_flags |= ra_ptr->flags; add_random_ego_flag(o_ptr, ra_ptr->fego, &limit_blows); /* get flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); /* Hack -- acquire "cursed" flag */ - if (f3 & TR3_CURSED) o_ptr->ident |= (IDENT_CURSED); + if (flags & TR_CURSED) o_ptr->ident |= (IDENT_CURSED); /* Hack -- obtain bonuses */ if (ra_ptr->max_to_h > 0) o_ptr->to_h += randint(ra_ptr->max_to_h); @@ -339,23 +328,23 @@ bool_ create_artifact(object_type *o_ptr, bool_ a_scroll, bool_ get_name) if (pval < 0) o_ptr->pval = randint( -pval); /* No insane number of blows */ - if (limit_blows && (o_ptr->art_flags1 & TR1_BLOWS)) + if (limit_blows && (o_ptr->art_flags & TR_BLOWS)) { if (o_ptr->pval > 2) o_ptr->pval = randint(2); } /* Just to be sure */ - o_ptr->art_flags3 |= ( TR3_IGNORE_ACID | TR3_IGNORE_ELEC | - TR3_IGNORE_FIRE | TR3_IGNORE_COLD); + o_ptr->art_flags |= + TR_IGNORE_ACID | + TR_IGNORE_ELEC | + TR_IGNORE_FIRE | + TR_IGNORE_COLD; total_flags = flag_cost(o_ptr, o_ptr->pval); if (cheat_peek) msg_format("%ld", total_flags); if (a_cursed) curse_artifact(o_ptr); - /* Extract the flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); - if (get_name) { if (a_scroll) @@ -393,13 +382,16 @@ bool_ create_artifact(object_type *o_ptr, bool_ a_scroll, bool_ get_name) /* Window stuff */ p_ptr->window |= (PW_INVEN | PW_EQUIP); + /* Extract the flags */ + auto const flags = object_flags(o_ptr); + /* HACKS for ToME */ if (o_ptr->tval == TV_CLOAK && o_ptr->sval == SV_MIMIC_CLOAK) { s32b mimic = find_random_mimic_shape(127, TRUE); o_ptr->pval2 = mimic; } - else if (f5 & TR5_SPELL_CONTAIN) + else if (flags & TR_SPELL_CONTAIN) { o_ptr->pval2 = -1; } -- cgit v1.2.3 From 6006546b4d015619b7d119d400fac819da6bc826 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Factor out 'flush_failure' option handling --- src/randart.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/randart.cc') diff --git a/src/randart.cc b/src/randart.cc index 9528faee..e22f1c93 100644 --- a/src/randart.cc +++ b/src/randart.cc @@ -458,7 +458,7 @@ bool_ artifact_scroll(void) if (!okay) { /* Flush */ - if (flush_failure) flush(); + flush_on_failure(); /* Message */ msg_print("The enchantment failed."); -- cgit v1.2.3 From f035201f330a3b1f50a2041ea9ad3f854f7d4e00 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Move all options to a struct instead of using globals --- src/randart.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/randart.cc') diff --git a/src/randart.cc b/src/randart.cc index e22f1c93..f7ea95f3 100644 --- a/src/randart.cc +++ b/src/randart.cc @@ -341,7 +341,10 @@ bool_ create_artifact(object_type *o_ptr, bool_ a_scroll, bool_ get_name) TR_IGNORE_COLD; total_flags = flag_cost(o_ptr, o_ptr->pval); - if (cheat_peek) msg_format("%ld", total_flags); + if (options->cheat_peek) + { + msg_format("%ld", total_flags); + } if (a_cursed) curse_artifact(o_ptr); -- cgit v1.2.3 From 8bbf783ead4517465445272f9144cf06bdac9be7 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Refactor object_type 'artifact name' field to std::string We don't really need quarks for this since we're not nearly as memory-constrained these days. --- src/randart.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/randart.cc') diff --git a/src/randart.cc b/src/randart.cc index f7ea95f3..1ccba225 100644 --- a/src/randart.cc +++ b/src/randart.cc @@ -379,7 +379,7 @@ bool_ create_artifact(object_type *o_ptr, bool_ a_scroll, bool_ get_name) } /* Save the inscription */ - o_ptr->art_name = quark_add(new_name); + o_ptr->artifact_name = new_name; o_ptr->name2 = o_ptr->name2b = 0; /* Window stuff */ -- cgit v1.2.3 From 288c3d3f725eabfee06507966a0ba63bf587c3da Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Remove quark.{cc,hpp} --- src/randart.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'src/randart.cc') diff --git a/src/randart.cc b/src/randart.cc index 1ccba225..7a6b2398 100644 --- a/src/randart.cc +++ b/src/randart.cc @@ -14,7 +14,6 @@ #include "object_type.hpp" #include "options.hpp" #include "player_type.hpp" -#include "quark.hpp" #include "randart_gen_type.hpp" #include "randart_part_type.hpp" #include "spells2.hpp" -- cgit v1.2.3 From d8de8c129fb9fc8d2110f39108949d7025456151 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Remove dead code --- src/randart.cc | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'src/randart.cc') diff --git a/src/randart.cc b/src/randart.cc index 7a6b2398..698be95b 100644 --- a/src/randart.cc +++ b/src/randart.cc @@ -26,10 +26,8 @@ #include /* Chance of using syllables to form the name instead of the "template" files */ -#define TABLE_NAME 45 #define A_CURSED 13 #define WEIRD_LUCK 12 -#define ACTIVATION_CHANCE 3 /* * Attempt to add a power to a randart @@ -115,24 +113,6 @@ static bool_ grab_one_power(int *ra_idx, object_type *o_ptr, bool_ good, s16b *m return (ret); } -void give_activation_power (object_type * o_ptr) -{ - o_ptr->xtra2 = 0; - o_ptr->art_flags &= ~TR_ACTIVATE; - o_ptr->timeout = 0; -} - - -int get_activation_power() -{ - object_type *o_ptr, forge; - - o_ptr = &forge; - - give_activation_power(o_ptr); - - return o_ptr->xtra2; -} #define MIN_NAME_LEN 5 #define MAX_NAME_LEN 9 -- cgit v1.2.3 From fd6449ac75f553e32d2efa84c3cdfba88bb32d6e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move ra_gen and ra_info into GameEditData --- src/randart.cc | 75 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 33 deletions(-) (limited to 'src/randart.cc') 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 -#include - /* 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 &max_times) { + auto const &ra_info = game->edit_data.ra_info; + + assert(max_times.size() >= ra_info.size()); + bool_ ret = FALSE; std::vector 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 max_times(new s16b[max_ra_idx]); - for (int i = 0; i < max_ra_idx; i++) { - max_times[i] = 0; - } + std::vector 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; -- cgit v1.2.3 From a40a0d1aeddb4742e486f601cbcc7e9ddcc06e2d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 2 May 2017 19:20:57 +0200 Subject: Move player_{name,base} to Game --- src/randart.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/randart.cc') diff --git a/src/randart.cc b/src/randart.cc index 488f11e1..55ffd265 100644 --- a/src/randart.cc +++ b/src/randart.cc @@ -358,7 +358,7 @@ bool_ create_artifact(object_type *o_ptr, bool_ a_scroll, bool_ get_name) } else /* Default name = of 'player name' */ - sprintf(new_name, "of '%s'", player_name); + sprintf(new_name, "of '%s'", game->player_name.c_str()); } else { -- cgit v1.2.3 From 6a35e3de332df186eab39c3b67506882409a3ca2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 2 May 2017 19:20:57 +0200 Subject: Remove redundant (void) parameters and return value casts --- src/randart.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/randart.cc') diff --git a/src/randart.cc b/src/randart.cc index 55ffd265..a902d734 100644 --- a/src/randart.cc +++ b/src/randart.cc @@ -174,7 +174,7 @@ void build_prob(cptr learn) * set. Relies on European vowels (a, e, i, o, u). The generated name should * be copied/used before calling this function again. */ -static char *make_word(void) +static char *make_word() { static char word_buf[90]; int r, totalfreq; @@ -391,7 +391,7 @@ bool_ create_artifact(object_type *o_ptr, bool_ a_scroll, bool_ get_name) } -bool_ artifact_scroll(void) +bool_ artifact_scroll() { bool_ okay = FALSE; -- cgit v1.2.3