summaryrefslogtreecommitdiff
path: root/src/traps.cc
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-06-21 13:37:02 +0200
committerBardur Arantsson <bardur@scientician.net>2016-06-21 13:37:02 +0200
commit073ad3584fbf781ce10bef61ad4ff38850282f47 (patch)
treeeb2db284b91ad7987655401406a2d57843337875 /src/traps.cc
parentb9e4f471c2e23283945ba9324912c7e29dd8fbd8 (diff)
Rework TR{1,2,3,4,5}_* flags to flag_set<>
Diffstat (limited to 'src/traps.cc')
-rw-r--r--src/traps.cc67
1 files changed, 30 insertions, 37 deletions
diff --git a/src/traps.cc b/src/traps.cc
index 8786e858..2f8578d4 100644
--- a/src/traps.cc
+++ b/src/traps.cc
@@ -25,6 +25,7 @@
#include "monster_type.hpp"
#include "object1.hpp"
#include "object2.hpp"
+#include "object_flag.hpp"
#include "object_kind.hpp"
#include "player_race.hpp"
#include "player_race_mod.hpp"
@@ -974,7 +975,6 @@ bool_ player_activate_trap_type(s16b y, s16b x, object_type *i_ptr, s16b item)
{
s16b i, j, slot1, slot2;
object_type *j_ptr, *k_ptr;
- u32b f1, f2, f3, f4, f5, esp;
for (i = INVEN_WIELD; i < INVEN_TOTAL; i++)
{
@@ -983,8 +983,8 @@ bool_ player_activate_trap_type(s16b y, s16b x, object_type *i_ptr, s16b item)
if (!j_ptr->k_idx) continue;
/* Do not allow this trap to touch the One Ring */
- object_flags(j_ptr, &f1, &f2, &f3, &f4, &f5, &esp);
- if(f3 & TR3_PERMA_CURSE) continue;
+ auto const j_flags = object_flags(j_ptr);
+ if(j_flags & TR_PERMA_CURSE) continue;
slot1 = wield_slot(j_ptr);
@@ -995,8 +995,8 @@ bool_ player_activate_trap_type(s16b y, s16b x, object_type *i_ptr, s16b item)
if (!k_ptr->k_idx) continue;
/* Do not allow this trap to touch the One Ring */
- object_flags(k_ptr, &f1, &f2, &f3, &f4, &f5, &esp);
- if(f3 & TR3_PERMA_CURSE) continue;
+ auto const k_flags = object_flags(k_ptr);
+ if(k_flags & TR_PERMA_CURSE) continue;
/* this is a crude hack, but it prevent wielding 6 torches... */
if (k_ptr->number > 1) continue;
@@ -1424,9 +1424,7 @@ bool_ player_activate_trap_type(s16b y, s16b x, object_type *i_ptr, s16b item)
case TRAP_OF_DRAIN_SPEED:
{
- object_type *j_ptr;
s16b j, chance = 75;
- u32b f1, f2, f3, f4, f5, esp;
for (j = 0; j < INVEN_TOTAL; j++)
{
@@ -1435,11 +1433,11 @@ bool_ player_activate_trap_type(s16b y, s16b x, object_type *i_ptr, s16b item)
if (!p_ptr->inventory[j].k_idx) continue;
- j_ptr = &p_ptr->inventory[j];
- object_flags(j_ptr, &f1, &f2, &f3, &f4, &f5, &esp);
+ auto j_ptr = &p_ptr->inventory[j];
+ auto const flags = object_flags(j_ptr);
/* is it a non-artifact speed item? */
- if ((!j_ptr->name1) && (f1 & TR1_SPEED))
+ if ((!j_ptr->name1) && (flags & TR_SPEED))
{
if (randint(100) < chance)
{
@@ -2091,8 +2089,6 @@ void do_cmd_set_trap(void)
object_type object_type_body;
- u32b f1, f2, f3, f4, f5, esp;
-
/* Check some conditions */
if (p_ptr->blind)
{
@@ -2167,11 +2163,11 @@ void do_cmd_set_trap(void)
/* In some cases, take multiple objects to load */
if (o_ptr->sval != SV_TRAPKIT_DEVICE)
{
- object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp);
+ auto const flags = object_flags(o_ptr);
- if ((f3 & TR3_XTRA_SHOTS) && (o_ptr->pval > 0)) num += o_ptr->pval;
+ if ((flags & TR_XTRA_SHOTS) && (o_ptr->pval > 0)) num += o_ptr->pval;
- if (f2 & (TRAP2_AUTOMATIC_5 | TRAP2_AUTOMATIC_99)) num = 99;
+ if (flags & (TR_AUTOMATIC_5 | TR_AUTOMATIC_99)) num = 99;
if (num > j_ptr->number) num = j_ptr->number;
@@ -2648,8 +2644,6 @@ bool_ mon_hit_trap(int m_idx)
monster_type *m_ptr = &m_list[m_idx];
monster_race *r_ptr = &r_info[m_ptr->r_idx];
- u32b f1, f2, f3, f4, f5, esp;
-
object_type object_type_body;
int mx = m_ptr->fx;
@@ -2680,21 +2674,21 @@ bool_ mon_hit_trap(int m_idx)
auto j_ptr = &object_type_body;
/* Get trap properties */
- object_flags(kit_o_ptr, &f1, &f2, &f3, &f4, &f5, &esp);
+ auto const flags = object_flags(kit_o_ptr);
/* Can set off check */
/* Ghosts only set off Ghost traps */
- if ((r_ptr->flags & RF_PASS_WALL) && !(f2 & TRAP2_KILL_GHOST)) return (FALSE);
+ if ((r_ptr->flags & RF_PASS_WALL) && !(flags & TR_KILL_GHOST)) return (FALSE);
/* Some traps are specialized to some creatures */
- if (f2 & TRAP2_ONLY_MASK)
+ if (flags & (TR_ONLY_DRAGON | TR_ONLY_DEMON | TR_ONLY_ANIMAL | TR_ONLY_UNDEAD | TR_ONLY_EVIL))
{
bool_ affect = FALSE;
- if ((f2 & TRAP2_ONLY_DRAGON) && (r_ptr->flags & RF_DRAGON)) affect = TRUE;
- if ((f2 & TRAP2_ONLY_DEMON) && (r_ptr->flags & RF_DEMON)) affect = TRUE;
- if ((f2 & TRAP2_ONLY_UNDEAD) && (r_ptr->flags & RF_UNDEAD)) affect = TRUE;
- if ((f2 & TRAP2_ONLY_EVIL) && (r_ptr->flags & RF_EVIL)) affect = TRUE;
- if ((f2 & TRAP2_ONLY_ANIMAL) && (r_ptr->flags & RF_ANIMAL)) affect = TRUE;
+ if ((flags & TR_ONLY_DRAGON) && (r_ptr->flags & RF_DRAGON)) affect = TRUE;
+ if ((flags & TR_ONLY_DEMON) && (r_ptr->flags & RF_DEMON)) affect = TRUE;
+ if ((flags & TR_ONLY_UNDEAD) && (r_ptr->flags & RF_UNDEAD)) affect = TRUE;
+ if ((flags & TR_ONLY_EVIL) && (r_ptr->flags & RF_EVIL)) affect = TRUE;
+ if ((flags & TR_ONLY_ANIMAL) && (r_ptr->flags & RF_ANIMAL)) affect = TRUE;
/* Don't set it off if forbidden */
if (!affect) return (FALSE);
@@ -2704,7 +2698,7 @@ bool_ mon_hit_trap(int m_idx)
difficulty = 25;
/* Some traps are well-hidden */
- if (f1 & TR1_STEALTH)
+ if (flags & TR_STEALTH)
{
difficulty += 10 * (kit_o_ptr->pval);
}
@@ -2795,7 +2789,7 @@ bool_ mon_hit_trap(int m_idx)
{
/* Get number of shots */
shots = 1;
- if (f3 & TR3_XTRA_SHOTS) shots += kit_o_ptr->pval;
+ if (flags & TR_XTRA_SHOTS) shots += kit_o_ptr->pval;
if (shots <= 0) shots = 1;
if (shots > load_o_ptr->number) shots = load_o_ptr->number;
@@ -2811,7 +2805,7 @@ bool_ mon_hit_trap(int m_idx)
if (kit_o_ptr->sval == SV_TRAPKIT_BOW) mul = 3;
if (kit_o_ptr->sval == SV_TRAPKIT_XBOW) mul = 4;
if (kit_o_ptr->sval == SV_TRAPKIT_SLING) mul = 2;
- if (f3 & TR3_XTRA_MIGHT) mul += kit_o_ptr->pval;
+ if (flags & TR_XTRA_MIGHT) mul += kit_o_ptr->pval;
if (mul < 0) mul = 0;
/* Multiply damage */
@@ -2932,7 +2926,7 @@ bool_ mon_hit_trap(int m_idx)
{
/* Get number of shots */
shots = 1;
- if (f3 & TR3_XTRA_SHOTS) shots += kit_o_ptr->pval;
+ if (flags & TR_XTRA_SHOTS) shots += kit_o_ptr->pval;
if (shots <= 0) shots = 1;
if (shots > load_o_ptr->number) shots = load_o_ptr->number;
@@ -2973,7 +2967,7 @@ bool_ mon_hit_trap(int m_idx)
{
/* Get number of shots */
shots = 1;
- if (f3 & TR3_XTRA_SHOTS) shots += kit_o_ptr->pval;
+ if (flags & TR_XTRA_SHOTS) shots += kit_o_ptr->pval;
if (shots <= 0) shots = 1;
if (shots > load_o_ptr->number) shots = load_o_ptr->number;
@@ -3015,16 +3009,15 @@ bool_ mon_hit_trap(int m_idx)
if (load_o_ptr->tval == TV_ROD_MAIN)
{
/* Extract mana cost of the rod tip */
- u32b tf1, tf2, tf3, tf4, tf5, tesp;
object_kind *tip_o_ptr = &k_info[lookup_kind(TV_ROD, load_o_ptr->pval)];
- object_flags(load_o_ptr, &tf1, &tf2, &tf3, &tf4, &tf5, &tesp);
- cost = (tf4 & TR4_CHEAPNESS) ? tip_o_ptr->pval / 2 : tip_o_ptr->pval;
+ auto const tflags = object_flags(load_o_ptr);
+ cost = (tflags & TR_CHEAPNESS) ? tip_o_ptr->pval / 2 : tip_o_ptr->pval;
if (cost <= 0) cost = 1;
}
/* Get number of shots */
shots = 1;
- if (f3 & TR3_XTRA_SHOTS) shots += kit_o_ptr->pval;
+ if (flags & TR_XTRA_SHOTS) shots += kit_o_ptr->pval;
if (shots <= 0) shots = 1;
if (load_o_ptr->tval == TV_ROD_MAIN)
@@ -3073,16 +3066,16 @@ bool_ mon_hit_trap(int m_idx)
}
/* Non-automatic traps are removed */
- if (!(f2 & (TRAP2_AUTOMATIC_5 | TRAP2_AUTOMATIC_99)))
+ if (!(flags & (TR_AUTOMATIC_5 | TR_AUTOMATIC_99)))
{
remove = TRUE;
}
- else if (f2 & TRAP2_AUTOMATIC_5) remove = (randint(5) == 1);
+ else if (flags & TR_AUTOMATIC_5) remove = (randint(5) == 1);
}
/* Special trap effect -- teleport to */
- if ((f2 & TRAP2_TELEPORT_TO) && (!disarm) && (!dead))
+ if ((flags & TR_TELEPORT_TO) && (!disarm) && (!dead))
{
teleport_monster_to(m_idx, p_ptr->py, p_ptr->px);
}