11 #include "mon-death.h"
23 bool actor::has_equipped(equipment_type eq
, int sub_type
) const
25 const item_def
*item
= slot_item(eq
, false);
26 return (item
&& item
->sub_type
== sub_type
);
29 bool actor::will_trigger_shaft() const
31 return (!(airborne() || is_wall_clinging())
32 && total_weight() > 0 && is_valid_shaft_level()
33 // let's pretend that they always make their saving roll
34 && !(atype() == ACT_MONSTER
35 && mons_is_elven_twin(static_cast<const monster
* >(this))));
38 level_id
actor::shaft_dest(bool known
= false) const
40 return generic_shaft_dest(pos(), known
);
43 bool actor::airborne() const
45 return (is_levitating() || (flight_mode() == FL_FLY
&& !cannot_move()));
49 * Check if the actor is on the ground (or in water).
51 bool actor::ground_level() const
53 return (!airborne() && !is_wall_clinging());
56 bool actor::can_wield(const item_def
* item
, bool ignore_curse
,
57 bool ignore_brand
, bool ignore_shield
,
58 bool ignore_transform
) const
64 fake
.base_type
= OBJ_UNASSIGNED
;
65 return can_wield(fake
, ignore_curse
, ignore_brand
, ignore_transform
);
68 return can_wield(*item
, ignore_curse
, ignore_brand
, ignore_transform
);
71 bool actor::can_pass_through(int x
, int y
) const
73 return can_pass_through_feat(grd
[x
][y
]);
76 bool actor::can_pass_through(const coord_def
&c
) const
78 return can_pass_through_feat(grd(c
));
81 bool actor::is_habitable(const coord_def
&_pos
) const
83 if (can_cling_to(_pos
))
86 return is_habitable_feat(grd(_pos
));
89 bool actor::handle_trap()
91 trap_def
* trap
= find_trap(pos());
94 return (trap
!= NULL
);
98 int actor::res_holy_fire() const
100 if (is_evil() || is_unholy())
107 int actor::check_res_magic(int power
)
109 const int mrs
= res_magic();
111 if (mrs
== MAG_IMMUNE
)
114 // Evil, evil hack to make weak one hd monsters easier for first level
115 // characters who have resistable 1st level spells. Six is a very special
116 // value because mrs = hd * 2 * 3 for most monsters, and the weak, low
117 // level monsters have been adjusted so that the "3" is typically a 1.
118 // There are some notable one hd monsters that shouldn't fall under this,
119 // so we do < 6, instead of <= 6... or checking mons->hit_dice. The
120 // goal here is to make the first level easier for these classes and give
121 // them a better shot at getting to level two or three and spells that can
122 // help them out (or building a level or two of their base skill so they
123 // aren't resisted as often). - bwr
124 if (atype() == ACT_MONSTER
&& mrs
< 6 && coinflip())
127 power
= stepdown_value(power
, 30, 40, 100, 120);
129 const int mrchance
= (100 + mrs
) - power
;
130 const int mrch2
= random2(100) + random2(101);
132 dprf("Power: %d, MR: %d, target: %d, roll: %d",
133 power
, mrs
, mrchance
, mrch2
);
135 return (mrchance
- mrch2
);
138 void actor::set_position(const coord_def
&c
)
140 const coord_def oldpos
= position
;
142 los_actor_moved(this, oldpos
);
143 areas_actor_moved(this, oldpos
);
146 bool actor::can_hibernate(bool holi_only
) const
148 // Undead, nonliving, and plants don't sleep.
149 const mon_holy_type holi
= holiness();
150 if (holi
== MH_UNDEAD
|| holi
== MH_NONLIVING
|| holi
== MH_PLANT
)
155 // The monster is berserk or already asleep.
159 // The monster is cold-resistant and can't be hibernated.
163 // The monster has slept recently.
164 if (atype() == ACT_MONSTER
165 && static_cast<const monster
* >(this)->has_ench(ENCH_SLEEP_WARY
))
174 bool actor::can_sleep() const
176 const mon_holy_type holi
= holiness();
177 if (holi
== MH_UNDEAD
|| holi
== MH_NONLIVING
|| holi
== MH_PLANT
)
179 return !(berserk() || asleep());
182 void actor::shield_block_succeeded(actor
*foe
)
184 item_def
*sh
= shield();
185 unrandart_entry
*unrand_entry
;
188 && sh
->base_type
== OBJ_ARMOUR
189 && get_armour_slot(*sh
) == EQ_SHIELD
191 && is_unrandom_artefact(*sh
)
192 && (unrand_entry
= get_unrand_entry(sh
->special
))
193 && unrand_entry
->fight_func
.melee_effects
)
195 unrand_entry
->fight_func
.melee_effects(sh
, this, foe
, false);
199 int actor::body_weight(bool base
) const
201 switch (body_size(PSIZE_BODY
, base
))
220 mpr("ERROR: invalid body weight");
221 perror("actor::body_weight(): invalid body weight");
227 kill_category
actor_kill_alignment(const actor
*act
)
229 return (act
? act
->kill_alignment() : KC_OTHER
);
232 bool actor_slime_wall_immune(const actor
*act
)
234 return (act
->atype() == ACT_PLAYER
?
235 you
.religion
== GOD_JIYVA
&& !you
.penance
[GOD_JIYVA
]
236 : act
->res_acid() == 3);
239 bool actor::is_wall_clinging() const
244 bool actor::can_cling_to(const coord_def
& p
) const
249 if (!is_wall_clinging())
252 if (!can_pass_through_feat(grd(p
)))
255 for (orth_adjacent_iterator
ai(p
); ai
; ++ai
)
256 if (feat_is_wall(env
.grid(*ai
)))
257 for (orth_adjacent_iterator
ai2(*ai
, false); ai2
; ++ai2
)
258 for (int i
= 0, size
= cling_to
.size(); i
< size
; ++i
)
259 if (cling_to
[i
] == *ai2
)
265 void actor::check_clinging()
267 if (!can_cling_to_walls())
271 for (orth_adjacent_iterator
ai(pos()); ai
; ++ai
)
272 if (feat_is_wall(env
.grid(*ai
)))
273 cling_to
.push_back(*ai
);
275 clinging
= (cling_to
.size() > 0) ? true : false;