MCPcopy Index your code
hub / github.com/NetHack/NetHack / attack_checks

Function attack_checks

src/uhitm.c:188–327  ·  view source on GitHub ↗

FALSE means it's OK to attack */

Source from the content-addressed store, hash-verified

186
187/* FALSE means it's OK to attack */
188boolean
189attack_checks(
190 struct monst *mtmp, /* target */
191 struct obj *wep) /* uwep for do_attack(), null for kick_monster() */
192{
193 int glyph;
194
195 /* if you're close enough to attack, alert any waiting monster */
196 mtmp->mstrategy &= ~STRAT_WAITMASK;
197
198 if (engulfing_u(mtmp))
199 return FALSE;
200
201 if (svc.context.forcefight) {
202 /* Do this in the caller, after we have checked that the monster
203 * didn't die from the blow. Reason: putting the 'I' there
204 * causes the hero to forget the square's contents since
205 * both 'I' and remembered contents are stored in .glyph.
206 * If the monster dies immediately from the blow, the 'I' will
207 * not stay there, so the player will have suddenly forgotten
208 * the square's contents for no apparent reason.
209 if (!canspotmon(mtmp)
210 && !glyph_is_invisible(levl[gb.bhitpos.x][gb.bhitpos.y].glyph))
211 map_invisible(gb.bhitpos.x, gb.bhitpos.y);
212 */
213 return FALSE;
214 }
215
216 /* cache the shown glyph;
217 cases which might change it (by placing or removing
218 'remembered, unseen monster' glyph or revealing a mimic)
219 always return without further reference to this */
220 glyph = glyph_at(gb.bhitpos.x, gb.bhitpos.y);
221
222 /* Put up an invisible monster marker, but with exceptions for
223 * monsters that hide and monsters you've been warned about.
224 * The former already prints a warning message and
225 * prevents you from hitting the monster just via the hidden monster
226 * code below; if we also did that here, similar behavior would be
227 * happening two turns in a row. The latter shows a glyph on
228 * the screen, so you know something is there.
229 */
230 if (!canspotmon(mtmp)
231 && !glyph_is_warning(glyph) && !glyph_is_invisible(glyph)
232 && !(!Blind && mtmp->mundetected && hides_under(mtmp->data))) {
233 pline("Wait! There's %s there you can't see!", something);
234 map_invisible(gb.bhitpos.x, gb.bhitpos.y);
235 /* if it was an invisible mimic, treat it as if we stumbled
236 * onto a visible mimic
237 */
238 if (M_AP_TYPE(mtmp) && !Protection_from_shape_changers) {
239 if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK)
240 /* applied pole-arm attack is too far to get stuck */
241 && m_next2u(mtmp))
242 set_ustuck(mtmp);
243 }
244 /* #H7329 - if hero is on engraved "Elbereth", this will end up
245 * assessing an alignment penalty and removing the engraving

Callers 4

do_attackFunction · 0.85
maybe_kick_monsterFunction · 0.85
use_poleFunction · 0.85
use_grappleFunction · 0.85

Calls 15

glyph_atFunction · 0.85
map_invisibleFunction · 0.85
dmgtypeFunction · 0.85
set_ustuckFunction · 0.85
wakeupFunction · 0.85
sensemonFunction · 0.85
seemimicFunction · 0.85
stumble_onto_mimicFunction · 0.85
canseemonFunction · 0.85
newsymFunction · 0.85
tp_sensemonFunction · 0.85
l_monnamFunction · 0.85

Tested by

no test coverage detected