… | |
… | |
30 | #include <skills.h> |
30 | #include <skills.h> |
31 | #include <tod.h> |
31 | #include <tod.h> |
32 | |
32 | |
33 | #include <sproto.h> |
33 | #include <sproto.h> |
34 | |
34 | |
35 | typedef bitset<NUM_TYPES> types_t; |
|
|
36 | |
|
|
37 | // these must be in the inventory before they can be applied |
35 | // these must be in the inventory before they can be applied |
38 | |
36 | |
39 | static const struct may_attempt_inv : types_t |
37 | static const struct apply_types_inv_only : typeset |
40 | { |
38 | { |
41 | may_attempt_inv () |
39 | apply_types_inv_only () |
42 | { |
40 | { |
43 | set (WEAPON); |
41 | set (WEAPON); |
44 | set (ARMOUR); |
42 | set (ARMOUR); |
45 | set (BOOTS); |
43 | set (BOOTS); |
46 | set (GLOVES); |
44 | set (GLOVES); |
… | |
… | |
59 | set (BOW); |
57 | set (BOW); |
60 | set (RANGED); |
58 | set (RANGED); |
61 | set (BUILDER); |
59 | set (BUILDER); |
62 | set (SKILL_TOOL); |
60 | set (SKILL_TOOL); |
63 | } |
61 | } |
64 | } may_attempt_inv; |
62 | } apply_types_inv_only; |
65 | |
63 | |
66 | // these only make sense for the player |
64 | // these only make sense for the player |
67 | |
65 | |
68 | static const struct may_attempt_player : types_t |
66 | static const struct apply_types_player_only : typeset |
69 | { |
67 | { |
70 | may_attempt_player () |
68 | apply_types_player_only () |
71 | { |
69 | { |
72 | set (EXIT); |
70 | set (EXIT); |
73 | set (BOOK); |
71 | set (BOOK); |
74 | set (SKILLSCROLL); |
72 | set (SKILLSCROLL); |
75 | set (SPELLBOOK); |
73 | set (SPELLBOOK); |
… | |
… | |
82 | set (LIGHTER); /* for lighting torches/lanterns/etc */ |
80 | set (LIGHTER); /* for lighting torches/lanterns/etc */ |
83 | set (INSCRIBABLE); |
81 | set (INSCRIBABLE); |
84 | set (SIGN); |
82 | set (SIGN); |
85 | set (BOOK); |
83 | set (BOOK); |
86 | } |
84 | } |
87 | } may_attempt_player; |
85 | } apply_types_player_only; |
88 | |
86 | |
89 | // applying these _can_ be attempted, others cannot |
87 | // applying these _can_ be attempted, others cannot |
90 | // be applied at all. used by e.g. apply below. |
88 | // be applied at all. used by e.g. apply below. |
91 | |
89 | |
92 | static const struct may_attempt : types_t |
90 | static const struct apply_types : typeset |
93 | { |
91 | { |
94 | may_attempt () |
92 | apply_types () |
95 | : types_t ((types_t)may_attempt_player | (types_t)may_attempt_inv) |
93 | : typeset ((typeset)apply_types_player_only | (typeset)apply_types_inv_only) |
96 | { |
94 | { |
97 | set (T_HANDLE); |
95 | set (T_HANDLE); |
98 | set (TRIGGER); |
96 | set (TRIGGER); |
99 | set (SCROLL); |
97 | set (SCROLL); |
100 | set (POTION); |
98 | set (POTION); |
… | |
… | |
107 | set (FLESH); |
105 | set (FLESH); |
108 | set (POISON); |
106 | set (POISON); |
109 | set (POWER_CRYSTAL); |
107 | set (POWER_CRYSTAL); |
110 | set (ITEM_TRANSFORMER); |
108 | set (ITEM_TRANSFORMER); |
111 | } |
109 | } |
112 | } may_attempt; |
110 | } apply_types; |
113 | |
111 | |
114 | /**************************************************************************** |
112 | /**************************************************************************** |
115 | * Weapon improvement code follows |
113 | * Weapon improvement code follows |
116 | ****************************************************************************/ |
114 | ****************************************************************************/ |
117 | |
115 | |
… | |
… | |
3403 | return 0; /* monsters just skip unpaid items */ |
3401 | return 0; /* monsters just skip unpaid items */ |
3404 | } |
3402 | } |
3405 | |
3403 | |
3406 | if (INVOKE_OBJECT (APPLY, op, ARG_OBJECT (who))) |
3404 | if (INVOKE_OBJECT (APPLY, op, ARG_OBJECT (who))) |
3407 | return RESULT_INT (0); |
3405 | return RESULT_INT (0); |
3408 | else if (may_attempt_inv [op->type]) |
3406 | else if (apply_types_inv_only [op->type]) |
3409 | { |
3407 | { |
3410 | // special item, using slot system, needs to be in inv |
3408 | // special item, using slot system, needs to be in inv |
3411 | if (op->env == who) |
3409 | if (op->env == who) |
3412 | return apply_special (who, op, aflag); |
3410 | return apply_special (who, op, aflag); |
3413 | |
3411 | |
3414 | who->failmsg (format ("You must get it first! H<You can only apply the %s if it is in your inventory.>\n", query_name (op))); |
3412 | who->failmsg (format ("You must get it first! H<You can only apply the %s if it is in your inventory.>\n", query_name (op))); |
3415 | } |
3413 | } |
3416 | else if (!who->contr && may_attempt_player [op->type]) |
3414 | else if (!who->contr && apply_types_player_only [op->type]) |
3417 | return 0; // monsters shouldn't try to apply player-only stuff |
3415 | return 0; // monsters shouldn't try to apply player-only stuff |
3418 | else if (may_attempt [op->type]) |
3416 | else if (apply_types [op->type]) |
3419 | { |
3417 | { |
3420 | // ordinary stuff, may be on the floor |
3418 | // ordinary stuff, may be on the floor |
3421 | switch (op->type) |
3419 | switch (op->type) |
3422 | { |
3420 | { |
3423 | case T_HANDLE: |
3421 | case T_HANDLE: |
… | |
… | |
3579 | */ |
3577 | */ |
3580 | |
3578 | |
3581 | // first try to apply "applyables" |
3579 | // first try to apply "applyables" |
3582 | for (object *tmp = top; tmp; tmp = tmp->below) |
3580 | for (object *tmp = top; tmp; tmp = tmp->below) |
3583 | // the tmp->cb is a hack to allow user-extendable types... |
3581 | // the tmp->cb is a hack to allow user-extendable types... |
3584 | if (!tmp->invisible && (may_attempt [tmp->type] || tmp->cb)) |
3582 | if (!tmp->invisible && (apply_types [tmp->type] || tmp->cb)) |
3585 | { |
3583 | { |
3586 | // If it is visible, player can apply it. |
3584 | // If it is visible, player can apply it. |
3587 | pl->apply (tmp); |
3585 | pl->apply (tmp); |
3588 | return; |
3586 | return; |
3589 | } |
3587 | } |