diff options
-rw-r--r-- | src/defines.h | 15 | ||||
-rw-r--r-- | src/init1.cc | 59 | ||||
-rw-r--r-- | src/store.cc | 53 | ||||
-rw-r--r-- | src/store_flag.hpp | 12 | ||||
-rw-r--r-- | src/store_flag_list.hpp | 17 | ||||
-rw-r--r-- | src/store_flag_set.hpp | 7 | ||||
-rw-r--r-- | src/store_info_type.hpp | 3 | ||||
-rw-r--r-- | src/wild.cc | 9 |
8 files changed, 86 insertions, 89 deletions
diff --git a/src/defines.h b/src/defines.h index 52ce7c3e..6337e6b7 100644 --- a/src/defines.h +++ b/src/defines.h @@ -2628,21 +2628,6 @@ /* - * Store flags - */ -#define SF1_DEPEND_LEVEL 0x00000001L -#define SF1_SHALLOW_LEVEL 0x00000002L -#define SF1_MEDIUM_LEVEL 0x00000004L -#define SF1_DEEP_LEVEL 0x00000008L -#define SF1_RARE 0x00000010L -#define SF1_VERY_RARE 0x00000020L -#define SF1_COMMON 0x00000040L -#define SF1_ALL_ITEM 0x00000080L /* Works as the BM */ -#define SF1_RANDOM 0x00000100L -#define SF1_FORCE_LEVEL 0x00000200L -#define SF1_MUSEUM 0x00000400L - -/* * Shield effect options */ #define SHIELD_NONE 0x0000 diff --git a/src/init1.cc b/src/init1.cc index e4c2bc98..37cc9de3 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -39,6 +39,7 @@ #include "skills.hpp" #include "spells5.hpp" #include "store_action_type.hpp" +#include "store_flag.hpp" #include "store_info_type.hpp" #include "store_type.hpp" #include "tables.hpp" @@ -197,45 +198,6 @@ static cptr t_info_flags[] = "XXX32" }; -/* - * Stores flags - */ -static cptr st_info_flags1[] = -{ - "DEPEND_LEVEL", - "SHALLOW_LEVEL", - "MEDIUM_LEVEL", - "DEEP_LEVEL", - "RARE", - "VERY_RARE", - "COMMON", - "ALL_ITEM", - "RANDOM", - "FORCE_LEVEL", - "MUSEUM", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1" -}; - /* Skill flags */ static cptr s_info_flags1[] = { @@ -5994,13 +5956,15 @@ static errr grab_one_race_flag(owner_type *ow_ptr, int state, cptr what) /* * Grab one store flag from a textual string */ -static errr grab_one_store_flag(store_info_type *st_ptr, cptr what) +static errr grab_one_store_flag(store_flag_set *flags, cptr what) { - /* Scan store flags */ - if (lookup_flags(what, flag_tie(&st_ptr->flags1, st_info_flags1))) - { - return 0; - } +#define STF(tier, index, name) \ + if (streq(what, #name)) { \ + *flags |= BOOST_PP_CAT(STF_,name); \ + return 0; \ + } +#include "store_flag_list.hpp" +#undef STF /* Oops */ msg_format("Unknown store flag '%s'.", what); @@ -6183,7 +6147,10 @@ errr init_st_info_txt(FILE *fp) /* Process 'F' for "store Flags" (multiple lines) */ if (buf[0] == 'F') { - if (0 != grab_one_store_flag(st_ptr, buf + 2)) return (5); + if (0 != grab_one_store_flag(&st_ptr->flags, buf + 2)) + { + return (5); + } /* Next... */ continue; diff --git a/src/store.cc b/src/store.cc index 72ae4eb0..63f9f0d1 100644 --- a/src/store.cc +++ b/src/store.cc @@ -30,6 +30,7 @@ #include "spells5.hpp" #include "stats.hpp" #include "store_action_type.hpp" +#include "store_flag.hpp" #include "store_type.hpp" #include "store_info_type.hpp" #include "tables.hpp" @@ -308,7 +309,7 @@ static s32b price_item(object_type *o_ptr, int greed, bool_ flip) if (adjust > 100) adjust = 100; /* Mega-Hack -- Black market sucks */ - if (st_info[st_ptr->st_idx].flags1 & SF1_ALL_ITEM) price = price / 2; + if (st_info[st_ptr->st_idx].flags & STF_ALL_ITEM) price = price / 2; /* No selling means you get no money */ if (no_selling) price = 0; @@ -324,7 +325,7 @@ static s32b price_item(object_type *o_ptr, int greed, bool_ flip) if (adjust < 100) adjust = 100; /* Mega-Hack -- Black market sucks */ - if (st_info[st_ptr->st_idx].flags1 & SF1_ALL_ITEM) price = price * 2; + if (st_info[st_ptr->st_idx].flags & STF_ALL_ITEM) price = price * 2; /* Never give items away for free */ if (price <= 0L) price = 1L; @@ -589,7 +590,7 @@ static bool_ store_check_num(object_type *o_ptr) } /* The "home" acts like the player */ - if ((cur_store_num == 7) || (st_info[st_ptr->st_idx].flags1 & SF1_MUSEUM)) + if ((cur_store_num == 7) || (st_info[st_ptr->st_idx].flags & STF_MUSEUM)) { /* Check all the items */ for (auto const &o_ref: st_ptr->stock) @@ -644,7 +645,7 @@ static bool store_will_buy(object_type const *o_ptr) return true; } - if (st_info[st_ptr->st_idx].flags1 & SF1_MUSEUM) + if (st_info[st_ptr->st_idx].flags & STF_MUSEUM) { return true; } @@ -1096,7 +1097,7 @@ static bool_ black_market_crap(object_type *o_ptr) for (std::size_t i = 0; i < max_st_idx; i++) { if (i == STORE_HOME) continue; - if (st_info[i].flags1 & SF1_MUSEUM) continue; + if (st_info[i].flags & STF_MUSEUM) continue; /* Check every item in the store */ for (auto const &stock_obj: town_info[p_ptr->town_num].store[i].stock) @@ -1146,16 +1147,16 @@ int return_level() store_info_type *sti_ptr = &st_info[st_ptr->st_idx]; int level; - if (sti_ptr->flags1 & SF1_RANDOM) level = 0; + if (sti_ptr->flags & STF_RANDOM) level = 0; else level = rand_range(1, STORE_OBJ_LEVEL); - if (sti_ptr->flags1 & SF1_DEPEND_LEVEL) level += dun_level; + if (sti_ptr->flags & STF_DEPEND_LEVEL) level += dun_level; - if (sti_ptr->flags1 & SF1_SHALLOW_LEVEL) level += 5 + rand_int(5); - if (sti_ptr->flags1 & SF1_MEDIUM_LEVEL) level += 25 + rand_int(25); - if (sti_ptr->flags1 & SF1_DEEP_LEVEL) level += 45 + rand_int(45); + if (sti_ptr->flags & STF_SHALLOW_LEVEL) level += 5 + rand_int(5); + if (sti_ptr->flags & STF_MEDIUM_LEVEL) level += 25 + rand_int(25); + if (sti_ptr->flags & STF_DEEP_LEVEL) level += 45 + rand_int(45); - if (sti_ptr->flags1 & SF1_ALL_ITEM) level += p_ptr->lev; + if (sti_ptr->flags & STF_ALL_ITEM) level += p_ptr->lev; return (level); } @@ -1248,7 +1249,7 @@ static void store_create(void) } /* Black Market */ - else if (st_info[st_ptr->st_idx].flags1 & SF1_ALL_ITEM) + else if (st_info[st_ptr->st_idx].flags & STF_ALL_ITEM) { /* No themes */ init_match_theme(obj_theme::no_theme()); @@ -1305,8 +1306,14 @@ static void store_create(void) store_tval = i - 10000; /* Do we forbid too shallow items ? */ - if (st_info[st_ptr->st_idx].flags1 & SF1_FORCE_LEVEL) store_level = level; - else store_level = 0; + if (st_info[st_ptr->st_idx].flags & STF_FORCE_LEVEL) + { + store_level = level; + } + else + { + store_level = 0; + } /* Prepare allocation table */ get_obj_num_prep(); @@ -1363,7 +1370,7 @@ static void store_create(void) if (q_ptr->tval == TV_CHEST) continue; /* Prune the black market */ - if (st_info[st_ptr->st_idx].flags1 & SF1_ALL_ITEM) + if (st_info[st_ptr->st_idx].flags & STF_ALL_ITEM) { /* Hack -- No "crappy" items */ if (black_market_crap(q_ptr)) continue; @@ -1429,7 +1436,7 @@ static void display_entry(int pos) /* Describe an item in the home */ if ((cur_store_num == 7) || - (st_info[st_ptr->st_idx].flags1 & SF1_MUSEUM)) + (st_info[st_ptr->st_idx].flags & STF_MUSEUM)) { int maxwid = 75; @@ -1565,7 +1572,7 @@ void display_store(void) put_str("Weight", 5, 70); } - else if (st_info[st_ptr->st_idx].flags1 & SF1_MUSEUM) + else if (st_info[st_ptr->st_idx].flags & STF_MUSEUM) { /* Show the name of the store */ strnfmt(buf, 80, "%s", st_info[cur_store_num].name); @@ -2078,7 +2085,7 @@ void store_stole(void) void store_purchase(void) { /* Museum? */ - if (st_info[st_ptr->st_idx].flags1 & SF1_MUSEUM) + if (st_info[st_ptr->st_idx].flags & STF_MUSEUM) { msg_print("You cannot take items from the museum!"); return; @@ -2400,7 +2407,7 @@ void store_sell(void) char o_name[80]; - bool_ museum = (st_info[st_ptr->st_idx].flags1 & SF1_MUSEUM) ? TRUE : FALSE; + bool museum = bool(st_info[st_ptr->st_idx].flags & STF_MUSEUM); /* Prepare prompt */ cptr q, s; @@ -2695,7 +2702,7 @@ void store_examine(void) if (st_ptr->stock.empty()) { if (cur_store_num == 7) msg_print("Your home is empty."); - else if (st_info[st_ptr->st_idx].flags1 & SF1_MUSEUM) msg_print("The museum is empty."); + else if (st_info[st_ptr->st_idx].flags & STF_MUSEUM) msg_print("The museum is empty."); else msg_print("I am currently out of stock."); return; } @@ -3380,7 +3387,7 @@ void store_shuffle(int which) if (which == STORE_HOME) return; /* Ignoer Museum */ - if (st_info[st_ptr->st_idx].flags1 & SF1_MUSEUM) return; + if (st_info[st_ptr->st_idx].flags & STF_MUSEUM) return; /* Save the store index */ @@ -3434,13 +3441,13 @@ void store_maint(int town_num, int store_num) st_ptr = &town_info[town_num].store[store_num]; /* Ignoer Museum */ - if (st_info[st_ptr->st_idx].flags1 & SF1_MUSEUM) return; + if (st_info[st_ptr->st_idx].flags & STF_MUSEUM) return; /* Activate the owner */ ot_ptr = &ow_info[st_ptr->owner]; /* Mega-Hack -- prune the black market */ - if (st_info[st_ptr->st_idx].flags1 & SF1_ALL_ITEM) + if (st_info[st_ptr->st_idx].flags & STF_ALL_ITEM) { /* Destroy crappy black market items */ for (int j = st_ptr->stock.size() - 1; j >= 0; j--) diff --git a/src/store_flag.hpp b/src/store_flag.hpp new file mode 100644 index 00000000..6844bd84 --- /dev/null +++ b/src/store_flag.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "store_flag_set.hpp" +#include <boost/preprocessor/cat.hpp> + +// +// Define flag set for each flag. +// +#define STF(tier, index, name) \ + DECLARE_FLAG(store_flag_set, BOOST_PP_CAT(STF_,name), tier, index) +#include "store_flag_list.hpp" +#undef STF diff --git a/src/store_flag_list.hpp b/src/store_flag_list.hpp new file mode 100644 index 00000000..f8e4b177 --- /dev/null +++ b/src/store_flag_list.hpp @@ -0,0 +1,17 @@ +/** + * X-macro list of all the store flags + */ + +/* STF(<tier>, <index>, <name>) */ + +STF(1, 0, DEPEND_LEVEL ) +STF(1, 1, SHALLOW_LEVEL) +STF(1, 2, MEDIUM_LEVEL ) +STF(1, 3, DEEP_LEVEL ) +STF(1, 4, RARE ) +STF(1, 5, VERY_RARE ) +STF(1, 6, COMMON ) +STF(1, 7, ALL_ITEM ) +STF(1, 8, RANDOM ) +STF(1, 9, FORCE_LEVEL ) +STF(1, 10, MUSEUM ) diff --git a/src/store_flag_set.hpp b/src/store_flag_set.hpp new file mode 100644 index 00000000..0529baed --- /dev/null +++ b/src/store_flag_set.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "flag_set.hpp" + +constexpr std::size_t STF_MAX_TIERS = 1; + +typedef flag_set<STF_MAX_TIERS> store_flag_set; diff --git a/src/store_info_type.hpp b/src/store_info_type.hpp index 3923438f..a735fdfc 100644 --- a/src/store_info_type.hpp +++ b/src/store_info_type.hpp @@ -1,6 +1,7 @@ #pragma once #include "h-basic.h" +#include "store_flag_set.hpp" /** * Number of items to choose stock from @@ -30,5 +31,5 @@ struct store_info_type byte x_attr = 0; /* Desired building attribute */ char x_char = '\0'; /* Desired building character */ - u32b flags1 = 0; /* Flags */ + store_flag_set flags; /* Flags */ }; diff --git a/src/wild.cc b/src/wild.cc index 7e7b20d0..d928b4a3 100644 --- a/src/wild.cc +++ b/src/wild.cc @@ -21,6 +21,7 @@ #include "options.hpp" #include "player_type.hpp" #include "store_info_type.hpp" +#include "store_flag.hpp" #include "tables.hpp" #include "town_type.hpp" #include "util.hpp" @@ -890,9 +891,9 @@ static int get_shops(int *rooms) { int chance = 50; - if (st_info[n].flags1 & SF1_COMMON) chance += 30; - if (st_info[n].flags1 & SF1_RARE) chance -= 20; - if (st_info[n].flags1 & SF1_VERY_RARE) chance -= 30; + if (st_info[n].flags & STF_COMMON) chance += 30; + if (st_info[n].flags & STF_RARE) chance -= 20; + if (st_info[n].flags & STF_VERY_RARE) chance -= 30; if (!magik(chance)) continue; @@ -900,7 +901,7 @@ static int get_shops(int *rooms) if (rooms[i] == n) continue; - if (st_info[n].flags1 & SF1_RANDOM) rooms[num++] = n; + if (st_info[n].flags & STF_RANDOM) rooms[num++] = n; } return num; |