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

Function splash_lit

src/apply.c:1517–1572  ·  view source on GitHub ↗

called when lit object is hit by water */

Source from the content-addressed store, hash-verified

1515
1516/* called when lit object is hit by water */
1517boolean
1518splash_lit(struct obj *obj)
1519{
1520 boolean result, dunk = FALSE;
1521
1522 /* lantern won't be extinguished by a rust trap or rust monster attack
1523 but will be if submerged or placed into a container or swallowed by
1524 a monster (for mobile light source handling, not because it ought
1525 to stop being lit in all those situations...) */
1526 if (obj->lamplit && obj->otyp == BRASS_LANTERN) {
1527 struct monst *mtmp;
1528 boolean useeit = FALSE, uhearit = FALSE, snuff = TRUE;
1529
1530 if (obj->where == OBJ_INVENT) {
1531 useeit = !Blind;
1532 uhearit = !Deaf;
1533 /* underwater light sources aren't allowed but if hero
1534 is just entering water, Underwater won't be set yet */
1535 dunk = (is_pool(u.ux, u.uy)
1536 && ((!Levitation && !Flying && !Wwalking)
1537 || Is_waterlevel(&u.uz)));
1538 snuff = FALSE;
1539 } else if (obj->where == OBJ_MINVENT
1540 /* don't assume that lit lantern has been swallowed;
1541 a nymph might have stolen it or picked it up */
1542 && ((mtmp = obj->ocarry), humanoid(mtmp->data))) {
1543 coordxy x, y;
1544
1545 useeit = get_obj_location(obj, &x, &y, 0) && cansee(x, y);
1546 uhearit = couldsee(x, y) && distu(x, y) < 5 * 5;
1547 dunk = (is_pool(mtmp->mx, mtmp->my)
1548 && ((!is_flyer(mtmp->data) && !is_floater(mtmp->data))
1549 || Is_waterlevel(&u.uz)));
1550 snuff = FALSE;
1551 if (useeit)
1552 set_msg_xy(x, y);
1553 }
1554
1555 if (useeit || uhearit)
1556 pline("%s %s%s%s.", Yname2(obj),
1557 uhearit ? "crackles" : "",
1558 (uhearit && useeit) ? " and " : "",
1559 useeit ? "flickers" : "");
1560 if (!dunk && !snuff)
1561 return FALSE;
1562 }
1563
1564 result = snuff_lit(obj);
1565
1566 /* this is simpler when we wait until after lantern has been snuffed */
1567 if (dunk) {
1568 /* drain some of the battery but don't short it out entirely */
1569 obj->age -= (obj->age > 200L) ? 100L : (obj->age / 2L);
1570 }
1571 return result;
1572}
1573
1574/* Called when potentially lightable object is affected by fire_damage().

Callers 2

trapeffect_rust_trapFunction · 0.85
water_damageFunction · 0.85

Calls 6

is_poolFunction · 0.85
get_obj_locationFunction · 0.85
set_msg_xyFunction · 0.85
Yname2Function · 0.85
snuff_litFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected