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

Function use_lamp

src/apply.c:1627–1700  ·  view source on GitHub ↗

light a lamp or candle */

Source from the content-addressed store, hash-verified

1625
1626/* light a lamp or candle */
1627staticfn void
1628use_lamp(struct obj *obj)
1629{
1630 char buf[BUFSZ];
1631 const char *lamp = (obj->otyp == OIL_LAMP
1632 || obj->otyp == MAGIC_LAMP) ? "lamp"
1633 : (obj->otyp == BRASS_LANTERN) ? "lantern"
1634 : NULL;
1635
1636 /*
1637 * When blind, lamps' and candles' on/off state can be distinguished
1638 * by heat. For brass lantern assume that there is an on/off switch
1639 * that can be felt.
1640 */
1641
1642 if (obj->lamplit) {
1643 if (lamp) /* lamp or lantern */
1644 pline("%s%s is now off.", Shk_Your(buf, obj), lamp);
1645 else
1646 You("snuff out %s.", yname(obj));
1647 end_burn(obj, TRUE);
1648 return;
1649 }
1650 if (Underwater) {
1651 pline("%s.",
1652 !Is_candle(obj) ? "This is not a diving lamp"
1653 : "Sorry, fire and water don't mix");
1654 return;
1655 }
1656 /* magic lamps with an spe == 0 (wished for) cannot be lit */
1657 if ((!Is_candle(obj) && obj->age == 0)
1658 || (obj->otyp == MAGIC_LAMP && obj->spe == 0)) {
1659 if (obj->otyp == BRASS_LANTERN) {
1660 if (!Blind)
1661 Your("lantern is out of power.");
1662 else
1663 pline("%s", nothing_seems_to_happen);
1664 } else {
1665 pline("This %s has no oil.", xname(obj));
1666 }
1667 return;
1668 }
1669 if (obj->cursed && !rn2(2)) {
1670 if ((obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP) && !rn2(3)) {
1671 pline_The("lamp spills and covers your %s with oil.",
1672 fingers_or_gloves(TRUE));
1673 make_glib((int) (Glib & TIMEOUT) + d(2, 10));
1674 } else if (!Blind) {
1675 pline("%s for a moment, then %s.", Tobjnam(obj, "flicker"),
1676 otense(obj, "die"));
1677 } else {
1678 pline("%s", nothing_seems_to_happen);
1679 }
1680 } else {
1681 if (lamp) { /* lamp or lantern */
1682 check_unpaid(obj);
1683 pline("%s%s is now on.", Shk_Your(buf, obj), lamp);
1684 } else { /* candle(s) */

Callers 2

use_candleFunction · 0.85
doapplyFunction · 0.85

Calls 15

Shk_YourFunction · 0.85
YouFunction · 0.85
ynameFunction · 0.85
end_burnFunction · 0.85
YourFunction · 0.85
xnameFunction · 0.85
rn2Function · 0.85
pline_TheFunction · 0.85
fingers_or_glovesFunction · 0.85
make_glibFunction · 0.85
dFunction · 0.85
TobjnamFunction · 0.85

Tested by

no test coverage detected