MCPcopy Create free account
hub / github.com/NetHack/NetHack / steal

Function steal

src/steal.c:342–614  ·  view source on GitHub ↗

Returns 1 when something was stolen (or at least, when N should flee now), * returns -1 if the monster died in the attempt. * Avoid stealing the object 'stealoid'. * Nymphs and monkeys won't steal coins (so that their "steal item" attack * doesn't become a superset of leprechaun's "steal gold" attack). */

Source from the content-addressed store, hash-verified

340 * doesn't become a superset of leprechaun's "steal gold" attack).
341 */
342int
343steal(struct monst *mtmp, char *objnambuf)
344{
345 struct obj *otmp;
346 char Monnambuf[BUFSZ];
347 int tmp, could_petrify, armordelay, olddelay, icnt,
348 named = 0, retrycnt = 0;
349 boolean monkey_business = is_animal(mtmp->data),
350 seen = canspotmon(mtmp),
351 was_doffing, was_punished = Punished;
352
353 if (objnambuf)
354 *objnambuf = '\0';
355 /* the following is true if successful on first of two attacks. */
356 if (!monnear(mtmp, u.ux, u.uy))
357 return 0;
358
359 /* stealing a worn item might drop hero into water or lava where
360 teleporting to safety could result in a previously visible thief
361 no longer being visible; it could also be a case of a blinded
362 hero being able to see via wearing the Eyes of the Overworld and
363 having those stolen; remember the name as it is now; if unseen,
364 nymphs will be "Someone" and monkeys will be "Something" */
365 Strcpy(Monnambuf, Some_Monnam(mtmp));
366
367 /* food being eaten might already be used up but will not have
368 been removed from inventory yet; we don't want to steal that,
369 so this will cause it to be removed now */
370 if (go.occupation)
371 (void) maybe_finished_meal(FALSE);
372
373 icnt = inv_cnt(FALSE); /* don't include gold */
374 if (!icnt || (icnt == 1 && uskin)) {
375 /* Not even a thousand men in armor can strip a naked man. */
376 nothing_to_steal:
377 /* nymphs might target uchain if invent is empty; monkeys won't;
378 hero becomes unpunished but nymph ends up empty handed */
379 if (Punished && !monkey_business && rn2(4)) {
380 /* uball is not carried (uchain never is) */
381 assert(uball != NULL && uball->where == OBJ_FLOOR);
382 worn_item_removal(mtmp, uchain);
383 } else if (u.utrap && u.utraptype == TT_BURIEDBALL
384 && !monkey_business && !rn2(4)) {
385 boolean dummy;
386
387 /* buried ball is not tracked via 'uball' and there is no chain
388 at all (hence no uchain to take off) */
389 pline("%s takes off your unseen chain.", Monnambuf);
390 (void) openholdingtrap(&gy.youmonst, &dummy);
391 } else if (Blind) {
392 pline("Somebody tries to rob you, but finds nothing to steal.");
393 } else if (inv_cnt(TRUE) > inv_cnt(FALSE)) {
394 pline("%s tries to rob you, but isn't interested in gold.",
395 Monnambuf);
396 } else {
397 pline("%s tries to rob you, but there is nothing to steal!",
398 Monnambuf);
399 }

Callers 1

mhitm_ad_seduFunction · 0.85

Calls 15

monnearFunction · 0.85
Some_MonnamFunction · 0.85
maybe_finished_mealFunction · 0.85
inv_cntFunction · 0.85
rn2Function · 0.85
worn_item_removalFunction · 0.85
openholdingtrapFunction · 0.85
weldedFunction · 0.85
can_carryFunction · 0.85
armor_simple_nameFunction · 0.85
ynameFunction · 0.85
o_unleashFunction · 0.85

Tested by

no test coverage detected