-/* Dwarves move. Return true if player survives, false if he dies. */
- int kk, stick, attack;
- loc_t tk[21];
-
- /* Dwarf stuff. See earlier comments for description of
- * variables. Remember sixth dwarf is pirate and is thus
- * very different except for motion rules. */
-
- /* First off, don't let the dwarves follow him into a pit or a
- * wall. Activate the whole mess the first time he gets as far
- * as the Hall of Mists (what INDEEP() tests). If game.newloc
- * is forbidden to pirate (in particular, if it's beyond the
- * troll bridge), bypass dwarf stuff. That way pirate can't
- * steal return toll, and dwarves can't meet the bear. Also
- * means dwarves won't follow him into dead end in maze, but
- * c'est la vie. They'll wait for him outside the dead end. */
- if (game.loc == LOC_NOWHERE || FORCED(game.loc) || CNDBIT(game.newloc, COND_NOARRR)) {
- return true;
- }
-
- /* Dwarf activity level ratchets up */
- if (game.dflag == 0) {
- if (INDEEP(game.loc))
- game.dflag = 1;
- return true;
- }
-
- /* When we encounter the first dwarf, we kill 0, 1, or 2 of
- * the 5 dwarves. If any of the survivors is at game.loc,
- * replace him with the alternate. */
- if (game.dflag == 1) {
- if (!INDEEP(game.loc) ||
- (PCT(95) && (!CNDBIT(game.loc, COND_NOBACK) || PCT(85)))) {
- return true;
+ /* Dwarves move. Return true if player survives, false if he dies. */
+ int kk, stick, attack;
+ loc_t tk[21];
+
+ /* Dwarf stuff. See earlier comments for description of
+ * variables. Remember sixth dwarf is pirate and is thus
+ * very different except for motion rules. */
+
+ /* First off, don't let the dwarves follow him into a pit or a
+ * wall. Activate the whole mess the first time he gets as far
+ * as the Hall of Mists (what INDEEP() tests). If game.newloc
+ * is forbidden to pirate (in particular, if it's beyond the
+ * troll bridge), bypass dwarf stuff. That way pirate can't
+ * steal return toll, and dwarves can't meet the bear. Also
+ * means dwarves won't follow him into dead end in maze, but
+ * c'est la vie. They'll wait for him outside the dead end. */
+ if (game.loc == LOC_NOWHERE || FORCED(game.loc) ||
+ CNDBIT(game.newloc, COND_NOARRR)) {
+ return true;
+ }
+
+ /* Dwarf activity level ratchets up */
+ if (game.dflag == 0) {
+ if (INDEEP(game.loc))
+ game.dflag = 1;
+ return true;
+ }
+
+ /* When we encounter the first dwarf, we kill 0, 1, or 2 of
+ * the 5 dwarves. If any of the survivors is at game.loc,
+ * replace him with the alternate. */
+ if (game.dflag == 1) {
+ if (!INDEEP(game.loc) ||
+ (PCT(95) && (!CNDBIT(game.loc, COND_NOBACK) || PCT(85)))) {
+ return true;
+ }
+ game.dflag = 2;
+ for (int i = 1; i <= 2; i++) {
+ int j = 1 + randrange(NDWARVES - 1);
+ if (PCT(50)) {
+ game.dwarves[j].loc = 0;
+ }
+ }
+
+ /* Alternate initial loc for dwarf, in case one of them
+ * starts out on top of the adventurer. */
+ for (int i = 1; i <= NDWARVES - 1; i++) {
+ if (game.dwarves[i].loc == game.loc) {
+ game.dwarves[i].loc = DALTLC;
+ }
+ game.dwarves[i].oldloc = game.dwarves[i].loc;
+ }
+ rspeak(DWARF_RAN);
+ drop(AXE, game.loc);
+ return true;
+ }
+
+ /* Things are in full swing. Move each dwarf at random,
+ * except if he's seen us he sticks with us. Dwarves stay
+ * deep inside. If wandering at random, they don't back up
+ * unless there's no alternative. If they don't have to
+ * move, they attack. And, of course, dead dwarves don't do
+ * much of anything. */
+ game.dtotal = 0;
+ attack = 0;
+ stick = 0;
+ for (int i = 1; i <= NDWARVES; i++) {
+ if (game.dwarves[i].loc == 0) {
+ continue;
+ }
+ /* Fill tk array with all the places this dwarf might go. */
+ unsigned int j = 1;
+ kk = tkey[game.dwarves[i].loc];
+ if (kk != 0)
+ do {
+ enum desttype_t desttype = travel[kk].desttype;
+ game.newloc = travel[kk].destval;
+ /* Have we avoided a dwarf encounter? */
+ if (desttype != dest_goto)
+ continue;
+ else if (!INDEEP(game.newloc))
+ continue;
+ else if (game.newloc == game.dwarves[i].oldloc)
+ continue;
+ else if (j > 1 && game.newloc == tk[j - 1])
+ continue;
+ else if (j >= DIM(tk) - 1)
+ /* This can't actually happen. */
+ continue; // LCOV_EXCL_LINE
+ else if (game.newloc == game.dwarves[i].loc)
+ continue;
+ else if (FORCED(game.newloc))
+ continue;
+ else if (i == PIRATE &&
+ CNDBIT(game.newloc, COND_NOARRR))
+ continue;
+ else if (travel[kk].nodwarves)
+ continue;
+ tk[j++] = game.newloc;
+ } while (!travel[kk++].stop);
+ tk[j] = game.dwarves[i].oldloc;
+ if (j >= 2) {
+ --j;
+ }
+ j = 1 + randrange(j);
+ game.dwarves[i].oldloc = game.dwarves[i].loc;
+ game.dwarves[i].loc = tk[j];
+ game.dwarves[i].seen =
+ (game.dwarves[i].seen && INDEEP(game.loc)) ||
+ (game.dwarves[i].loc == game.loc ||
+ game.dwarves[i].oldloc == game.loc);
+ if (!game.dwarves[i].seen) {
+ continue;
+ }
+ game.dwarves[i].loc = game.loc;
+ if (spotted_by_pirate(i)) {
+ continue;
+ }
+ /* This threatening little dwarf is in the room with him! */
+ ++game.dtotal;
+ if (game.dwarves[i].oldloc == game.dwarves[i].loc) {
+ ++attack;
+ if (game.knfloc >= LOC_NOWHERE) {
+ game.knfloc = game.loc;
+ }
+ if (randrange(1000) < 95 * (game.dflag - 2)) {
+ ++stick;
+ }
+ }
+ }
+
+ /* Now we know what's happening. Let's tell the poor sucker about it.
+ */
+ if (game.dtotal == 0) {
+ return true;