diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-06-02 21:46:20 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-06-02 22:19:03 +0200 |
commit | 3756182bf99335d02f7872c105b5ae5f9b5c4e57 (patch) | |
tree | eb96de37a1c0994406ef2e50f8d44fe17ee817fb /src | |
parent | 53bf1478ad25f03d6df584371b0653f83ead1b6d (diff) |
Lua: Move store handling to C
Diffstat (limited to 'src')
-rw-r--r-- | src/defines.h | 9 | ||||
-rw-r--r-- | src/store.c | 211 | ||||
-rw-r--r-- | src/util.pkg | 18 |
3 files changed, 206 insertions, 32 deletions
diff --git a/src/defines.h b/src/defines.h index 9b0a512a..9c0ba654 100644 --- a/src/defines.h +++ b/src/defines.h @@ -142,15 +142,7 @@ * Total number of stores (see "store.c", etc) */ #define STORE_GENERAL 0 -#define STORE_ARMOURY 1 -#define STORE_WEAPON 2 -#define STORE_TEMPLE 3 -#define STORE_ALCHEMIST 4 -#define STORE_MAGIC 5 -#define STORE_BLACK 6 #define STORE_HOME 7 -#define STORE_BOOK 8 -#define STORE_PET 9 /* * Maximum number of player "sex" types (see "table.c", etc) @@ -4505,7 +4497,6 @@ #define HOOK_BUILDING_ACTION 44 #define HOOK_WIELD_SLOT 46 #define HOOK_STORE_STOCK 47 -#define HOOK_STORE_BUY 48 #define HOOK_GEN_LEVEL_BEGIN 49 #define HOOK_GET 50 #define HOOK_REDRAW 51 diff --git a/src/store.c b/src/store.c index d290785a..e62701d9 100644 --- a/src/store.c +++ b/src/store.c @@ -12,6 +12,19 @@ #include "angband.h" +#define STORE_GENERAL_STORE "General Store" +#define STORE_ARMOURY "Armoury" +#define STORE_WEAPONSMITH "Weaponsmith" +#define STORE_TEMPLE "Temple" +#define STORE_ALCHEMY "Alchemy shop" +#define STORE_MAGIC "Magic shop" +#define STORE_BLACK_MARKET "Black Market" +#define STORE_BOOKS "Book Store" +#define STORE_PETS "Pet Shop" +#define STORE_HUNTING_SUPPLIES "Hunting Supply Store" +#define STORE_RUNIC_MAGIC "Runic Magic Shop" +#define STORE_CONSTRUCTION_SUPPLIES "Construction Supply Store" +#define STORE_MUSIC "Music Store" #define RUMOR_CHANCE 8 @@ -742,6 +755,8 @@ bool_ is_blessed(object_type *o_ptr) */ static bool_ store_will_buy(object_type *o_ptr) { + cptr store_name = st_info[st_ptr->st_idx].name + st_name; + /* Hack -- The Home is simple */ if (cur_store_num == 7) return (TRUE); @@ -750,10 +765,196 @@ static bool_ store_will_buy(object_type *o_ptr) /* XXX XXX XXX Ignore "worthless" items */ if (object_value(o_ptr) <= 0) return (FALSE); - /* Lua can define things to buy */ - if (process_hooks_ret(HOOK_STORE_BUY, "d", "(d,s,O)", st_ptr->st_idx, st_info[st_ptr->st_idx].name + st_name, o_ptr)) + /* What do stores buy? */ + if (streq(store_name, STORE_GENERAL_STORE)) + { + switch (o_ptr->tval) + { + case TV_CORPSE: + case TV_FOOD: + case TV_LITE: + case TV_FLASK: + case TV_SPIKE: + case TV_SHOT: + case TV_ARROW: + case TV_BOLT: + case TV_DIGGING: + case TV_CLOAK: + case TV_BOTTLE: + return TRUE; + } + } + else if (streq(store_name, STORE_ARMOURY)) + { + switch (o_ptr->tval) + { + case TV_BOOTS: + case TV_GLOVES: + case TV_CROWN: + case TV_HELM: + case TV_SHIELD: + case TV_CLOAK: + case TV_SOFT_ARMOR: + case TV_HARD_ARMOR: + case TV_DRAG_ARMOR: + return TRUE; + } + } + else if (streq(store_name, STORE_WEAPONSMITH)) + { + switch (o_ptr->tval) + { + case TV_SHOT: + case TV_BOLT: + case TV_ARROW: + case TV_BOOMERANG: + case TV_BOW: + case TV_DIGGING: + case TV_HAFTED: + case TV_POLEARM: + case TV_SWORD: + case TV_AXE: + case TV_MSTAFF: + return TRUE; + } + } + else if (streq(store_name, STORE_TEMPLE)) + { + switch (o_ptr->tval) + { + case TV_DRUID_BOOK: + case TV_SCROLL: + case TV_POTION2: + case TV_POTION: + case TV_HAFTED: + return TRUE; + } + + if ((o_ptr->tval == TV_BOOK) && + (o_ptr->sval == BOOK_RANDOM) && + (can_spell_random(o_ptr->pval) == SKILL_SPIRITUALITY)) + { + return TRUE; + } + else if ((o_ptr->tval == TV_POLEARM) && + is_blessed(o_ptr)) + { + return TRUE; + } + else if ((o_ptr->tval == TV_SWORD) && + is_blessed(o_ptr)) + { + return TRUE; + } + else if ((o_ptr->tval == TV_AXE) && + is_blessed(o_ptr)) + { + return TRUE; + } + else if ((o_ptr->tval == TV_BOOMERANG) && + is_blessed(o_ptr)) + { + return TRUE; + } + } + else if (streq(store_name, STORE_ALCHEMY)) + { + switch (o_ptr->tval) + { + case TV_SCROLL: + case TV_POTION2: + case TV_POTION: + case TV_BATERIE: + case TV_BOTTLE: + return TRUE; + } + } + else if (streq(store_name, STORE_MAGIC)) + { + switch (o_ptr->tval) + { + case TV_SYMBIOTIC_BOOK: + case TV_AMULET: + case TV_RING: + case TV_STAFF: + case TV_WAND: + case TV_ROD: + case TV_ROD_MAIN: + case TV_SCROLL: + case TV_POTION2: + case TV_POTION: + case TV_MSTAFF: + case TV_RANDART: + return TRUE; + } + + if ((o_ptr->tval == TV_BOOK) && + (o_ptr->sval == BOOK_RANDOM) && + (can_spell_random(o_ptr->pval) == SKILL_MAGIC)) + { + return TRUE; + } + else if ((o_ptr->tval == TV_BOOK) && + (o_ptr->sval != BOOK_RANDOM)) + { + return TRUE; + } + } + else if (streq(store_name, STORE_BLACK_MARKET)) + { + return TRUE; + } + else if (streq(store_name, STORE_BOOKS)) + { + switch (o_ptr->tval) + { + case TV_BOOK: + case TV_SYMBIOTIC_BOOK: + case TV_MUSIC_BOOK: + case TV_DAEMON_BOOK: + case TV_DRUID_BOOK: + return TRUE; + } + } + else if (streq(store_name, STORE_PETS)) + { + return (o_ptr->tval == TV_EGG); + } + else if (streq(store_name, STORE_HUNTING_SUPPLIES)) + { + switch (o_ptr->tval) + { + case TV_TRAPKIT: + case TV_BOOMERANG: + case TV_SHOT: + case TV_BOLT: + case TV_ARROW: + case TV_BOW: + case TV_POTION2: + return TRUE; + } + } + else if (streq(store_name, STORE_RUNIC_MAGIC)) + { + switch (o_ptr->tval) + { + case TV_RUNE1: + case TV_RUNE2: + return TRUE; + } + } + else if (streq(store_name, STORE_CONSTRUCTION_SUPPLIES)) + { + switch (o_ptr->tval) + { + case TV_LITE: + case TV_DIGGING: + return TRUE; + } + } + else if (streq(store_name, STORE_MUSIC)) { - return process_hooks_return[0].num; + return (o_ptr->tval == TV_INSTRUMENT); } /* Assume not okay */ @@ -1165,7 +1366,7 @@ static void store_create(void) } /* Magic Shop */ - else if (streq(st_info[st_ptr->st_idx].name + st_name, "Magic shop") && + else if (streq(st_info[st_ptr->st_idx].name + st_name, STORE_MAGIC) && magik(20)) { s16b spell; @@ -1181,7 +1382,7 @@ static void store_create(void) } /* Temple */ - else if (streq(st_info[st_ptr->st_idx].name + st_name, "Temple") && + else if (streq(st_info[st_ptr->st_idx].name + st_name, STORE_TEMPLE) && magik(20)) { s16b spell; diff --git a/src/util.pkg b/src/util.pkg index a32ef927..cb49a3e3 100644 --- a/src/util.pkg +++ b/src/util.pkg @@ -556,24 +556,6 @@ typedef unsigned int u32b; */ #define HOOK_STORE_STOCK 47 -/** @def HOOK_STORE_BUY - * @brief Store buys an item.\n - * @param Number st_idx \n the index of the store in st_info array. - * @brief Store index - * @param String name \n the name of the store. - * @brief Store name - * @param Object o_ptr \n the object to buy. - * @brief Object - * @return Boolean \n TRUE if the hook has processed the object, otherwise - * FALSE. - * @return Number buy \n TRUE if the store will buy the object, otherwise - * FALSE. - * @note - * If the hook returns TRUE, store_will_buy() will return "buy". - * @note (see file store.c) - */ -#define HOOK_STORE_BUY 48 - /** @def HOOK_GEN_LEVEL_BEGIN * @brief Generate a random dungeon level. * @note (see file generate.c) |