+{
+ if (game.tally == 0 && INDEEP(game.loc) && game.loc != 33)
+ --game.clock1;
+
+ /* When the first warning comes, we lock the grate, destroy
+ * the bridge, kill all the dwarves (and the pirate), remove
+ * the troll and bear (unless dead), and set "closng" to
+ * true. Leave the dragon; too much trouble to move it.
+ * from now until clock2 runs out, he cannot unlock the
+ * grate, move to any location outside the cave, or create
+ * the bridge. Nor can he be resurrected if he dies. Note
+ * that the snake is already gone, since he got to the
+ * treasure accessible only via the hall of the mountain
+ * king. Also, he's been in giant room (to get eggs), so we
+ * can refer to it. Also also, he's gotten the pearl, so we
+ * know the bivalve is an oyster. *And*, the dwarves must
+ * have been activated, since we've found chest. */
+ if (game.clock1 == 0) {
+ game.prop[GRATE] = 0;
+ game.prop[FISSUR] = 0;
+ for (int i = 1; i <= NDWARVES; i++) {
+ game.dseen[i] = false;
+ game.dloc[i] = 0;
+ }
+ MOVE(TROLL, 0);
+ MOVE(TROLL + NOBJECTS, 0);
+ MOVE(TROLL2, PLAC[TROLL]);
+ MOVE(TROLL2 + NOBJECTS, FIXD[TROLL]);
+ JUGGLE(CHASM);
+ if (game.prop[BEAR] != 3)DESTROY(BEAR);
+ game.prop[CHAIN] = 0;
+ game.fixed[CHAIN] = 0;
+ game.prop[AXE] = 0;
+ game.fixed[AXE] = 0;
+ RSPEAK(CAVE_CLOSING);
+ game.clock1 = -1;
+ game.closng = true;
+ return true;
+ } else if (game.clock1 < 0)
+ --game.clock2;
+ if (game.clock2 == 0) {
+ /* Once he's panicked, and clock2 has run out, we come here
+ * to set up the storage room. The room has two locs,
+ * hardwired as 115 (ne) and 116 (sw). At the ne end, we
+ * place empty bottles, a nursery of plants, a bed of
+ * oysters, a pile of lamps, rods with stars, sleeping
+ * dwarves, and him. At the sw end we place grate over
+ * treasures, snake pit, covey of caged birds, more rods, and
+ * pillows. A mirror stretches across one wall. Many of the
+ * objects come from known locations and/or states (e.g. the
+ * snake is known to have been destroyed and needn't be
+ * carried away from its old "place"), making the various
+ * objects be handled differently. We also drop all other
+ * objects he might be carrying (lest he have some which
+ * could cause trouble, such as the keys). We describe the
+ * flash of light and trundle back. */
+ game.prop[BOTTLE] = PUT(BOTTLE, LOC_NE, 1);
+ game.prop[PLANT] = PUT(PLANT, LOC_NE, 0);
+ game.prop[OYSTER] = PUT(OYSTER, LOC_NE, 0);
+ OBJTXT[OYSTER] = 3;
+ game.prop[LAMP] = PUT(LAMP, LOC_NE, 0);
+ game.prop[ROD] = PUT(ROD, LOC_NE, 0);
+ game.prop[DWARF] = PUT(DWARF, LOC_NE, 0);
+ game.loc = LOC_NE;
+ game.oldloc = LOC_NE;
+ game.newloc = LOC_NE;
+ /* Leave the grate with normal (non-negative) property.
+ * Reuse sign. */
+ PUT(GRATE, LOC_SW, 0);
+ PUT(SIGN, LOC_SW, 0);
+ ++OBJTXT[SIGN];
+ game.prop[SNAKE] = PUT(SNAKE, LOC_SW, 1);
+ game.prop[BIRD] = PUT(BIRD, LOC_SW, 1);
+ game.prop[CAGE] = PUT(CAGE, LOC_SW, 0);
+ game.prop[ROD2] = PUT(ROD2, LOC_SW, 0);
+ game.prop[PILLOW] = PUT(PILLOW, LOC_SW, 0);
+
+ game.prop[MIRROR] = PUT(MIRROR, LOC_NE, 0);
+ game.fixed[MIRROR] = LOC_SW;
+
+ for (int i = 1; i <= NOBJECTS; i++) {
+ if (TOTING(i))
+ DESTROY(i);
+ }
+
+ RSPEAK(CAVE_CLOSED);
+ game.closed = true;
+ return true;
+ }
+
+ return false;
+}
+
+static void lampcheck(void)
+/* Check game limit and lamp timers */
+{
+ if (game.prop[LAMP] == 1)
+ --game.limit;
+
+ /* Another way we can force an end to things is by having the
+ * lamp give out. When it gets close, we come here to warn
+ * him. First following ar, if the lamp and fresh batteries are
+ * here, in which case we replace the batteries and continue.
+ * Second is for other cases of lamp dying. 12400 is when it
+ * goes out. Even then, he can explore outside for a while
+ * if desired. */
+ if (game.limit <= WARNTIME && HERE(BATTER) && game.prop[BATTER] == 0 && HERE(LAMP)) {
+ RSPEAK(REPLACE_BATTERIES);
+ game.prop[BATTER] = 1;
+ if (TOTING(BATTER))
+ DROP(BATTER, game.loc);
+ game.limit = game.limit + 2500;
+ game.lmwarn = false;
+ } else if (game.limit == 0) {
+ game.limit = -1;
+ game.prop[LAMP] = 0;
+ if (HERE(LAMP))
+ RSPEAK(LAMP_OUT);
+ } else if (game.limit <= WARNTIME) {
+ if (!game.lmwarn && HERE(LAMP)) {
+ game.lmwarn = true;
+ int spk = GET_BATTERIES;
+ if (game.place[BATTER] == NOWHERE)spk = LAMP_DIM;
+ if (game.prop[BATTER] == 1)spk = MISSING_BATTERIES;
+ RSPEAK(spk);
+ }
+ }
+}
+
+static void listobjects(void)
+/* Print out descriptions of objects at this location. If
+ * not closing and property value is negative, tally off
+ * another treasure. Rug is special case; once seen, its
+ * game.prop is 1 (dragon on it) till dragon is killed.
+ * Similarly for chain; game.prop is initially 1 (locked to
+ * bear). These hacks are because game.prop=0 is needed to
+ * get full score. */
+{
+ if (!DARK(game.loc)) {
+ ++game.abbrev[game.loc];
+ for (int i = game.atloc[game.loc]; i != 0; i = game.link[i]) {
+ long obj = i;
+ if (obj > NOBJECTS)obj = obj - NOBJECTS;
+ if (obj == STEPS && TOTING(NUGGET))
+ continue;
+ if (game.prop[obj] < 0) {
+ if (game.closed)
+ continue;
+ game.prop[obj] = 0;
+ if (obj == RUG || obj == CHAIN)
+ game.prop[obj] = 1;
+ --game.tally;
+ /* Note: There used to be a test here to see whether the
+ * player had blown it so badly that he could never ever see
+ * the remaining treasures, and if so the lamp was zapped to
+ * 35 turns. But the tests were too simple-minded; things
+ * like killing the bird before the snake was gone (can never
+ * see jewelry), and doing it "right" was hopeless. E.G.,
+ * could cross troll bridge several times, using up all
+ * available treasures, breaking vase, using coins to buy
+ * batteries, etc., and eventually never be able to get
+ * across again. If bottle were left on far side, could then
+ * never get eggs or trident, and the effects propagate. So
+ * the whole thing was flushed. anyone who makes such a
+ * gross blunder isn't likely to find everything else anyway
+ * (so goes the rationalisation). */
+ }
+ int kk = game.prop[obj];
+ if (obj == STEPS && game.loc == game.fixed[STEPS])
+ kk = 1;
+ PSPEAK(obj, kk);
+ }
+ }
+}
+
+static bool do_command(FILE *cmdin)
+/* Get and execute a command */
+{
+ long verb = 0, V1, V2;
+ long kmod, defn;
+ static long igo = 0;
+ static long obj = 0;
+ enum speechpart part;
+
+ /* Can't leave cave once it's closing (except by main office). */
+ if (OUTSID(game.newloc) && game.newloc != 0 && game.closng) {
+ RSPEAK(EXIT_CLOSED);
+ game.newloc = game.loc;
+ if (!game.panic)game.clock2 = PANICTIME;
+ game.panic = true;
+ }
+
+ /* See if a dwarf has seen him and has come from where he
+ * wants to go. If so, the dwarf's blocking his way. If
+ * coming from place forbidden to pirate (dwarves rooted in
+ * place) let him get out (and attacked). */
+ if (game.newloc != game.loc && !FORCED(game.loc) && !CNDBIT(game.loc, NOARRR)) {
+ for (size_t i = 1; i <= NDWARVES - 1; i++) {
+ if (game.odloc[i] == game.newloc && game.dseen[i]) {
+ game.newloc = game.loc;
+ RSPEAK(DWARF_BLOCK);
+ break;
+ }
+ }
+ }
+ game.loc = game.newloc;