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

Function use_candle

src/apply.c:1386–1468  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1384}
1385
1386staticfn void
1387use_candle(struct obj **optr)
1388{
1389 struct obj *obj = *optr;
1390 struct obj *otmp;
1391 const char *s = (obj->quan != 1) ? "candles" : "candle";
1392 char qbuf[QBUFSZ], qsfx[QBUFSZ], *q;
1393 boolean was_lamplit;
1394
1395 if (u.uswallow) {
1396 You(no_elbow_room);
1397 return;
1398 }
1399
1400 /* obj is the candle; otmp is the candelabrum */
1401 otmp = carrying(CANDELABRUM_OF_INVOCATION);
1402 if (!otmp || otmp->spe == 7) {
1403 use_lamp(obj);
1404 return;
1405 }
1406
1407 /* first, minimal candelabrum suffix for formatting candles */
1408 Sprintf(qsfx, " to\033%s?", thesimpleoname(otmp));
1409 /* next, format the candles as a prefix for the candelabrum */
1410 (void) safe_qbuf(qbuf, "Attach ", qsfx, obj, yname, thesimpleoname, s);
1411 /* strip temporary candelabrum suffix */
1412 if ((q = strstri(qbuf, " to\033")) != 0)
1413 Strcpy(q, " to ");
1414 /* last, format final "attach candles to candelabrum?" query */
1415 if (y_n(safe_qbuf(qbuf, qbuf, "?", otmp, yname, thesimpleoname, "it"))
1416 == 'n') {
1417 use_lamp(obj);
1418 return;
1419 } else {
1420 if ((long) otmp->spe + obj->quan > 7L) {
1421 obj = splitobj(obj, 7L - (long) otmp->spe);
1422 /* avoid a grammatical error if obj->quan gets
1423 reduced to 1 candle from more than one */
1424 s = (obj->quan != 1) ? "candles" : "candle";
1425 } else
1426 *optr = 0;
1427
1428 /* The candle's age field doesn't correctly reflect the amount
1429 of fuel in it while it's lit, because the fuel is measured
1430 by the timer. So to get accurate age updating, we need to
1431 end the burn temporarily while attaching the candle. */
1432 was_lamplit = obj->lamplit;
1433 if (was_lamplit)
1434 end_burn(obj, TRUE);
1435
1436 You("attach %ld%s %s to %s.", obj->quan, !otmp->spe ? "" : " more", s,
1437 the(xname(otmp)));
1438 if (!otmp->spe || otmp->age > obj->age)
1439 otmp->age = obj->age;
1440 otmp->spe += (int) obj->quan;
1441 if (otmp->lamplit && !was_lamplit)
1442 pline_The("new %s magically %s!", s, vtense(s, "ignite"));
1443 else if (!otmp->lamplit && was_lamplit)

Callers 1

doapplyFunction · 0.85

Calls 15

YouFunction · 0.85
carryingFunction · 0.85
use_lampFunction · 0.85
thesimpleonameFunction · 0.85
safe_qbufFunction · 0.85
strstriFunction · 0.85
splitobjFunction · 0.85
end_burnFunction · 0.85
theFunction · 0.85
xnameFunction · 0.85
pline_TheFunction · 0.85
vtenseFunction · 0.85

Tested by

no test coverage detected