From 6f02ef2e62739efc23d10ae2c7cea69a908b657b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 21 Jun 2016 11:02:48 +0200 Subject: Rework ETR4_* flags to flag_set<> --- src/defines.h | 34 ------------------------ src/ego_flag.hpp | 12 +++++++++ src/ego_flag_list.hpp | 38 +++++++++++++++++++++++++++ src/ego_flag_set.hpp | 7 +++++ src/ego_item_type.hpp | 3 ++- src/init1.cc | 62 +++++++++++++++---------------------------- src/object2.cc | 67 ++++++++++++++++++++++++----------------------- src/object2.hpp | 3 ++- src/randart_part_type.hpp | 3 ++- 9 files changed, 118 insertions(+), 111 deletions(-) create mode 100644 src/ego_flag.hpp create mode 100644 src/ego_flag_list.hpp create mode 100644 src/ego_flag_set.hpp diff --git a/src/defines.h b/src/defines.h index d69247ce..52ce7c3e 100644 --- a/src/defines.h +++ b/src/defines.h @@ -2234,40 +2234,6 @@ #define NEW_GROUP_CHANCE 40 /* Chance to get a new group */ -/*** Ego flags ***/ -#define ETR4_SUSTAIN 0x00000001L /* Ego-Item gives a Random Sustain */ -#define ETR4_OLD_RESIST 0x00000002L /* The old "extra power" random high resist */ -#define ETR4_ABILITY 0x00000004L /* Ego-Item has a random Sustain */ -#define ETR4_R_ELEM 0x00000008L /* Item resists Acid/Fire/Cold/Elec or Poison */ -#define ETR4_R_LOW 0x00000010L /* Item has a random low resist */ -#define ETR4_R_HIGH 0x00000020L /* Item has a random high resist */ -#define ETR4_R_ANY 0x00000040L /* Item has one additional resist */ -#define ETR4_R_DRAGON 0x00000080L /* Item gets "Dragon" Resist */ -#define ETR4_SLAY_WEAP 0x00000100L /* Special 'Slaying' bonus */ -#define ETR4_DAM_DIE 0x00000200L /* Item has an additional dam die */ -#define ETR4_DAM_SIZE 0x00000400L /* Item has greater damage dice */ -#define ETR4_PVAL_M1 0x00000800L /* Item has +1 to pval */ -#define ETR4_PVAL_M2 0x00001000L /* Item has +(up to 2) to pval */ -#define ETR4_PVAL_M3 0x00002000L /* Item has +(up to 3) to pval */ -#define ETR4_PVAL_M5 0x00004000L /* Item has +(up to 5) to pval */ -#define ETR4_AC_M1 0x00008000L /* Item has +1 to AC */ -#define ETR4_AC_M2 0x00010000L /* Item has +(up to 2) to AC */ -#define ETR4_AC_M3 0x00020000L /* Item has +(up to 3) to AC */ -#define ETR4_AC_M5 0x00040000L /* Item has +(up to 5) to AC */ -#define ETR4_TH_M1 0x00080000L /* Item has +1 to hit */ -#define ETR4_TH_M2 0x00100000L /* Item has +(up to 2) to hit */ -#define ETR4_TH_M3 0x00200000L /* Item has +(up to 3) to hit */ -#define ETR4_TH_M5 0x00400000L /* Item has +(up to 5) to hit */ -#define ETR4_TD_M1 0x00800000L /* Item has +1 to dam */ -#define ETR4_TD_M2 0x01000000L /* Item has +(up to 2) to dam */ -#define ETR4_TD_M3 0x02000000L /* Item has +(up to 3) to dam */ -#define ETR4_TD_M5 0x04000000L /* Item has +(up to 5) to dam */ -#define ETR4_R_P_ABILITY 0x08000000L /* Item has a random pval-affected ability */ -#define ETR4_R_STAT 0x10000000L /* Item affects a random stat */ -#define ETR4_R_STAT_SUST 0x20000000L /* Item affects a random stat & sustains it */ -#define ETR4_R_IMMUNITY 0x40000000L /* Item gives a random immunity */ -#define ETR4_LIMIT_BLOWS 0x80000000L /* switch the "limit blows" feature */ - /*** Town flags ***/ #define TOWN_REAL 0x01 /* Town is really present */ #define TOWN_KNOWN 0x02 /* Town is found by the player */ diff --git a/src/ego_flag.hpp b/src/ego_flag.hpp new file mode 100644 index 00000000..8afb6b19 --- /dev/null +++ b/src/ego_flag.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "ego_flag_set.hpp" +#include + +// +// Define flag set for each flag. +// +#define ETR(tier, index, name) \ + DECLARE_FLAG(ego_flag_set, BOOST_PP_CAT(ETR_,name), tier, index) +#include "ego_flag_list.hpp" +#undef ETR diff --git a/src/ego_flag_list.hpp b/src/ego_flag_list.hpp new file mode 100644 index 00000000..b05fb9b1 --- /dev/null +++ b/src/ego_flag_list.hpp @@ -0,0 +1,38 @@ +/** + * X-macro list of all the ego flags + */ + +/* ETR(, , ) */ + +ETR(1, 0, SUSTAIN ) /* Ego-Item gives a Random Sustain */ +ETR(1, 1, OLD_RESIST ) /* The old "extra power" random high resist */ +ETR(1, 2, ABILITY ) /* Ego-Item has a random Sustain */ +ETR(1, 3, R_ELEM ) /* Item resists Acid/Fire/Cold/Elec or Poison */ +ETR(1, 4, R_LOW ) /* Item has a random low resist */ +ETR(1, 5, R_HIGH ) /* Item has a random high resist */ +ETR(1, 6, R_ANY ) /* Item has one additional resist */ +ETR(1, 7, R_DRAGON ) /* Item gets "Dragon" Resist */ +ETR(1, 8, SLAY_WEAP ) /* Special 'Slaying' bonus */ +ETR(1, 9, DAM_DIE ) /* Item has an additional dam die */ +ETR(1, 10, DAM_SIZE ) /* Item has greater damage dice */ +ETR(1, 11, PVAL_M1 ) /* Item has +1 to pval */ +ETR(1, 12, PVAL_M2 ) /* Item has +(up to 2) to pval */ +ETR(1, 13, PVAL_M3 ) /* Item has +(up to 3) to pval */ +ETR(1, 14, PVAL_M5 ) /* Item has +(up to 5) to pval */ +ETR(1, 15, AC_M1 ) /* Item has +1 to AC */ +ETR(1, 16, AC_M2 ) /* Item has +(up to 2) to AC */ +ETR(1, 17, AC_M3 ) /* Item has +(up to 3) to AC */ +ETR(1, 18, AC_M5 ) /* Item has +(up to 5) to AC */ +ETR(1, 19, TH_M1 ) /* Item has +1 to hit */ +ETR(1, 20, TH_M2 ) /* Item has +(up to 2) to hit */ +ETR(1, 21, TH_M3 ) /* Item has +(up to 3) to hit */ +ETR(1, 22, TH_M5 ) /* Item has +(up to 5) to hit */ +ETR(1, 23, TD_M1 ) /* Item has +1 to dam */ +ETR(1, 24, TD_M2 ) /* Item has +(up to 2) to dam */ +ETR(1, 25, TD_M3 ) /* Item has +(up to 3) to dam */ +ETR(1, 26, TD_M5 ) /* Item has +(up to 5) to dam */ +ETR(1, 27, R_P_ABILITY) /* Item has a random pval-affected ability */ +ETR(1, 28, R_STAT ) /* Item affects a random stat */ +ETR(1, 29, R_STAT_SUST) /* Item affects a random stat & sustains it */ +ETR(1, 30, R_IMMUNITY ) /* Item gives a random immunity */ +ETR(1, 31, LIMIT_BLOWS) /* switch the "limit blows" feature */ diff --git a/src/ego_flag_set.hpp b/src/ego_flag_set.hpp new file mode 100644 index 00000000..0e77d5e0 --- /dev/null +++ b/src/ego_flag_set.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "flag_set.hpp" + +constexpr std::size_t ETR_MAX_TIERS = 1; + +typedef flag_set ego_flag_set; diff --git a/src/ego_item_type.hpp b/src/ego_item_type.hpp index 77fe6637..2082c083 100644 --- a/src/ego_item_type.hpp +++ b/src/ego_item_type.hpp @@ -1,5 +1,6 @@ #pragma once +#include "ego_flag_set.hpp" #include "h-basic.h" #include "object_flag_set.hpp" @@ -44,7 +45,7 @@ struct ego_item_type std::array flags; std::array oflags; - u32b fego[FLAG_RARITY_MAX] = { 0 }; /* ego flags */ + std::array fego; object_flag_set need_flags; object_flag_set forbid_flags; diff --git a/src/init1.cc b/src/init1.cc index 53e9d851..7b15440a 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -6,6 +6,7 @@ #include "cave_type.hpp" #include "dungeon_info_type.hpp" #include "dungeon_flag.hpp" +#include "ego_flag.hpp" #include "ego_item_type.hpp" #include "feature_flag.hpp" #include "feature_type.hpp" @@ -157,44 +158,6 @@ static cptr r_info_blow_effect[] = }; -/* Specially handled properties for ego-items */ - -static cptr ego_flags[] = -{ - "SUSTAIN", - "OLD_RESIST", - "ABILITY", - "R_ELEM", - "R_LOW", - "R_HIGH", - "R_ANY", - "R_DRAGON", - "SLAY_WEAP", - "DAM_DIE", - "DAM_SIZE", - "PVAL_M1", - "PVAL_M2", - "PVAL_M3", - "PVAL_M5", - "AC_M1", - "AC_M2", - "AC_M3", - "AC_M5", - "TH_M1", - "TH_M2", - "TH_M3", - "TH_M5", - "TD_M1", - "TD_M2", - "TD_M3", - "TD_M5", - "R_P_ABILITY", - "R_STAT", - "R_STAT_SUST", - "R_IMMUNITY", - "LIMIT_BLOWS" -}; - /* * Trap flags */ @@ -3975,12 +3938,28 @@ errr init_ab_info_txt(FILE *fp) } +/* + * Look up ego flag + */ +static ego_flag_set lookup_ego_flag(const char *what) +{ +#define ETR(tier, index, name) \ + if (streq(what, #name)) \ + { \ + return BOOST_PP_CAT(ETR_,name); \ + }; +#include "ego_flag_list.hpp" +#undef ETR + return ego_flag_set(); +} + + /* * Grab one flag in a ego-item_type from a textual string. * * We explicitly allow nullptr for the "ego" parameter. */ -static bool_ grab_one_ego_item_flag(object_flag_set *flags, u32b *ego, cptr what) +static bool_ grab_one_ego_item_flag(object_flag_set *flags, ego_flag_set *ego, cptr what) { /* Lookup as an object_flag */ if (auto f = object_flag_set_from_string(what)) @@ -3992,8 +3971,9 @@ static bool_ grab_one_ego_item_flag(object_flag_set *flags, u32b *ego, cptr what /* Lookup as ego flag */ if (ego) { - if (lookup_flags(what, flag_tie(ego, ego_flags))) + if (auto f = lookup_ego_flag(what)) { + *ego |= f; return (0); } } @@ -4423,7 +4403,7 @@ errr init_ra_info_txt(FILE *fp) ra_ptr->tval[j] = 255; } ra_ptr->flags = object_flag_set(); - ra_ptr->fego = 0; + ra_ptr->fego = ego_flag_set(); /* Next... */ continue; diff --git a/src/object2.cc b/src/object2.cc index 231a67df..8e16fe48 100644 --- a/src/object2.cc +++ b/src/object2.cc @@ -15,6 +15,7 @@ #include "spell_type.hpp" #include "device_allocation.hpp" #include "dungeon_info_type.hpp" +#include "ego_flag.hpp" #include "ego_item_type.hpp" #include "feature_flag.hpp" #include "feature_type.hpp" @@ -3458,9 +3459,9 @@ void trap_hack(object_type *o_ptr) } /* Add a random glag to the ego item */ -void add_random_ego_flag(object_type *o_ptr, int fego, bool_ *limit_blows) +void add_random_ego_flag(object_type *o_ptr, ego_flag_set const &fego, bool_ *limit_blows) { - if (fego & ETR4_SUSTAIN) + if (fego & ETR_SUSTAIN) { /* Make a random sustain */ switch (randint(6)) @@ -3486,7 +3487,7 @@ void add_random_ego_flag(object_type *o_ptr, int fego, bool_ *limit_blows) } } - if (fego & ETR4_OLD_RESIST) + if (fego & ETR_OLD_RESIST) { /* Make a random resist, equal probabilities */ switch (randint(11)) @@ -3527,7 +3528,7 @@ void add_random_ego_flag(object_type *o_ptr, int fego, bool_ *limit_blows) } } - if (fego & ETR4_ABILITY) + if (fego & ETR_ABILITY) { /* Choose an ability */ switch (randint(8)) @@ -3559,35 +3560,35 @@ void add_random_ego_flag(object_type *o_ptr, int fego, bool_ *limit_blows) } } - if (fego & ETR4_R_ELEM) + if (fego & ETR_R_ELEM) { /* Make an acid/elec/fire/cold/poison resist */ random_resistance(o_ptr, randint(14) + 4); } - if (fego & ETR4_R_LOW) + if (fego & ETR_R_LOW) { /* Make an acid/elec/fire/cold resist */ random_resistance(o_ptr, randint(12) + 4); } - if (fego & ETR4_R_HIGH) + if (fego & ETR_R_HIGH) { /* Make a high resist */ random_resistance(o_ptr, randint(22) + 16); } - if (fego & ETR4_R_ANY) + if (fego & ETR_R_ANY) { /* Make any resist */ random_resistance(o_ptr, randint(34) + 4); } - if (fego & ETR4_R_DRAGON) + if (fego & ETR_R_DRAGON) { /* Make "dragon resist" */ dragon_resist(o_ptr); } - if (fego & ETR4_SLAY_WEAP) + if (fego & ETR_SLAY_WEAP) { /* Make a Weapon of Slaying */ @@ -3616,120 +3617,120 @@ void add_random_ego_flag(object_type *o_ptr, int fego, bool_ *limit_blows) } } - if (fego & ETR4_DAM_DIE) + if (fego & ETR_DAM_DIE) { /* Increase damage dice */ o_ptr->dd++; } - if (fego & ETR4_DAM_SIZE) + if (fego & ETR_DAM_SIZE) { /* Increase damage dice size */ o_ptr->ds++; } - if (fego & ETR4_LIMIT_BLOWS) + if (fego & ETR_LIMIT_BLOWS) { /* Swap this flag */ *limit_blows = !(*limit_blows); } - if (fego & ETR4_PVAL_M1) + if (fego & ETR_PVAL_M1) { /* Increase pval */ o_ptr->pval++; } - if (fego & ETR4_PVAL_M2) + if (fego & ETR_PVAL_M2) { /* Increase pval */ o_ptr->pval += m_bonus(2, dun_level); } - if (fego & ETR4_PVAL_M3) + if (fego & ETR_PVAL_M3) { /* Increase pval */ o_ptr->pval += m_bonus(3, dun_level); } - if (fego & ETR4_PVAL_M5) + if (fego & ETR_PVAL_M5) { /* Increase pval */ o_ptr->pval += m_bonus(5, dun_level); } - if (fego & ETR4_AC_M1) + if (fego & ETR_AC_M1) { /* Increase ac */ o_ptr->to_a++; } - if (fego & ETR4_AC_M2) + if (fego & ETR_AC_M2) { /* Increase ac */ o_ptr->to_a += m_bonus(2, dun_level); } - if (fego & ETR4_AC_M3) + if (fego & ETR_AC_M3) { /* Increase ac */ o_ptr->to_a += m_bonus(3, dun_level); } - if (fego & ETR4_AC_M5) + if (fego & ETR_AC_M5) { /* Increase ac */ o_ptr->to_a += m_bonus(5, dun_level); } - if (fego & ETR4_TH_M1) + if (fego & ETR_TH_M1) { /* Increase to hit */ o_ptr->to_h++; } - if (fego & ETR4_TH_M2) + if (fego & ETR_TH_M2) { /* Increase to hit */ o_ptr->to_h += m_bonus(2, dun_level); } - if (fego & ETR4_TH_M3) + if (fego & ETR_TH_M3) { /* Increase to hit */ o_ptr->to_h += m_bonus(3, dun_level); } - if (fego & ETR4_TH_M5) + if (fego & ETR_TH_M5) { /* Increase to hit */ o_ptr->to_h += m_bonus(5, dun_level); } - if (fego & ETR4_TD_M1) + if (fego & ETR_TD_M1) { /* Increase to dam */ o_ptr->to_d++; } - if (fego & ETR4_TD_M2) + if (fego & ETR_TD_M2) { /* Increase to dam */ o_ptr->to_d += m_bonus(2, dun_level); } - if (fego & ETR4_TD_M3) + if (fego & ETR_TD_M3) { /* Increase to dam */ o_ptr->to_d += m_bonus(3, dun_level); } - if (fego & ETR4_TD_M5) + if (fego & ETR_TD_M5) { /* Increase to dam */ o_ptr->to_d += m_bonus(5, dun_level); } - if (fego & ETR4_R_P_ABILITY) + if (fego & ETR_R_P_ABILITY) { /* Add a random pval-affected ability */ /* This might cause boots with + to blows */ @@ -3755,7 +3756,7 @@ void add_random_ego_flag(object_type *o_ptr, int fego, bool_ *limit_blows) break; } } - if (fego & ETR4_R_STAT) + if (fego & ETR_R_STAT) { /* Add a random stat */ switch (randint(6)) @@ -3781,7 +3782,7 @@ void add_random_ego_flag(object_type *o_ptr, int fego, bool_ *limit_blows) } } - if (fego & ETR4_R_STAT_SUST) + if (fego & ETR_R_STAT_SUST) { /* Add a random stat and sustain it */ switch (randint(6)) @@ -3829,7 +3830,7 @@ void add_random_ego_flag(object_type *o_ptr, int fego, bool_ *limit_blows) } } - if (fego & ETR4_R_IMMUNITY) + if (fego & ETR_R_IMMUNITY) { /* Give a random immunity */ switch (randint(4)) diff --git a/src/object2.hpp b/src/object2.hpp index a8d0fab9..8a99753d 100644 --- a/src/object2.hpp +++ b/src/object2.hpp @@ -1,5 +1,6 @@ #pragma once +#include "ego_flag_set.hpp" #include "h-basic.h" #include "object_type_fwd.hpp" #include "obj_theme_fwd.hpp" @@ -13,7 +14,7 @@ extern void inc_stack_size(int item, int delta); extern void inc_stack_size_ex(int item, int delta, optimize_flag opt, describe_flag desc); extern object_type *get_object(int item); extern s32b calc_total_weight(void); -extern void add_random_ego_flag(object_type *o_ptr, int fego, bool_ *limit_blows); +extern void add_random_ego_flag(object_type *o_ptr, ego_flag_set const &fego, bool_ *limit_blows); extern bool init_match_theme(obj_theme const &theme); extern bool_ kind_is_artifactable(int k_idx); extern bool_ kind_is_legal(int k_idx); diff --git a/src/randart_part_type.hpp b/src/randart_part_type.hpp index 39329a57..ad7b0c30 100644 --- a/src/randart_part_type.hpp +++ b/src/randart_part_type.hpp @@ -1,5 +1,6 @@ #pragma once +#include "ego_flag_set.hpp" #include "h-basic.h" #include "object_flag_set.hpp" @@ -27,7 +28,7 @@ struct randart_part_type object_flag_set flags; /* Ego item flags */ - u32b fego = 0; /* ego flags */ + ego_flag_set fego; /* Ego flags */ object_flag_set aflags; /* Antagonistic ego item flags */ -- cgit v1.2.3