📄 turn.c
字号:
/* program TURN.C */#include <stdio.h>#include <stdlib.h>#include "advent.h"#include "advdec.h"_PROTOTYPE(void descitem, (void));_PROTOTYPE(void domove, (void));_PROTOTYPE(void goback, (void));_PROTOTYPE(void copytrv, (struct trav *, struct trav *));_PROTOTYPE(void dotrav, (void));_PROTOTYPE(void badmove, (void));_PROTOTYPE(void spcmove, (int));_PROTOTYPE(void death, (void));_PROTOTYPE(void dwarves, (void));_PROTOTYPE(void dopirate, (void));_PROTOTYPE(int stimer, (void));_PROTOTYPE(void do_hint, (int));/* Routine to take 1 turn*/void turn(){ int i, hint; static int waste = 0; if (newtravel) { /* If closing, then he can't leave except via the main office. */ if (outside(g.newloc) && g.newloc != 0 && g.closing) { rspeak(130); g.newloc = g.loc; if (!g.panic) g.clock2 = 15; g.panic = TRUE; } /* See if a dwarf has seen him and has come from where he wants to go. */ if (g.newloc != g.loc && !forced(g.loc) && g.loc_attrib[g.loc] & NOPIRAT == 0) for (i = 1; i < (DWARFMAX - 1); ++i) if (g.odloc[i] == g.newloc && g.dseen[i]) { g.newloc = g.loc; rspeak(2); break; } g.loc = g.newloc; dwarves(); /* & special dwarf(pirate who steals) */ /* Check for death */ if (g.loc == 0) { death(); return; } /* Check for forced move */ if (forced(g.loc)) { desclg(g.loc); ++g.visited[g.loc]; domove(); return; } /* Check for wandering in dark */ if (g.wzdark && dark() && pct(35)) { rspeak(23); g.oldloc2 = g.loc; death(); return; } /* see if he is wasting his batteies out in the open */ if (outside(g.loc) && g.prop[LAMP]) { waste++; if (waste > 11) { rspeak(324); waste = 0; } } else waste = 0; /* If wumpus is chasing stooge, see if wumpus gets him */ if (g.chase) { g.chase++; g.prop[WUMPUS] = g.chase / 2; move(WUMPUS, g.loc); if (g.chase >= 10) { if (dark()) rspeak(270); pspeak(WUMPUS, 5); death(); return; } } /* check for radiation poisoning. */ g.health += (outside(g.loc)) ? 3 : 1; if (g.health > 100) g.health = 100; if (here(RADIUM) && (g.place[RADIUM] != -SHIELD || ajar(SHIELD))) g.health -= 7; if (g.health < 60) { rspeak(391 + (60 - g.health) / 10); if (g.health < 0) { death(); return; } } if ((g.oldloc == 188) && (g.loc != 188 && g.loc != 189) && (g.prop[BOOTH] == 1)) { move(GNOME, 0); g.prop[BOOTH] = 0; } /* Describe his situation */ describe(); if (!blind()) { ++g.visited[g.loc]; descitem(); } } /* end of newtravel start for second entry point */ /* Check if this location is eligible for any hints. If been here long enough, branch to help section. Ignore "hints" < HNTMIN (special stuff, see database notes. */ for (hint = HNTMIN; hint <= HNTMAX; hint++) { if (g.hinted[hint]) continue; if (g.loc_attrib[g.loc] / 256 != hint - 6) g.hintlc[hint] = -1; g.hintlc[hint]++; if (g.hintlc[hint] >= g.hints[hint][1]) do_hint(hint); } if (g.closed) { if (g.prop[OYSTER] < 0 && toting(OYSTER)) pspeak(OYSTER, 1); for (i = 1; i < MAXOBJ; ++i) if (toting(i) && g.prop[i] < 0) g.prop[i] = -1 - g.prop[i]; } g.wzdark = dark(); if (g.knfloc > 0 && g.knfloc != g.loc) g.knfloc = 0; ++g.turns; i = rand(); if (stimer()) /* as the grains of sand slip by */ return; while (!english()) /* retrieve player instructions */ ; vrbx = 1; objx = objs[1] ? 1 : 0; iobx = iobjs[1] ? 1 : 0; verb = VAL(verbs[vrbx]); do { object = objx ? objs[objx] : 0; iobj = iobx ? iobjs[iobx] : 0; if (object && (objs[2] || iobjs[2])) { pspeak(object, -1); printf(" "); } switch (CLASS(verbs[vrbx])) { case MOTION: motion = verb; domove(); break; case NOUN: bug(22); case ACTION: if (object || iobj) trverb(); else itverb(); break; case MISC: rspeak(verb); if (verb == 51) g.hinted[1] = TRUE; break; default: bug(22); } if (objx) { objx++; if (objs[objx] == 0) objx = 0; } if ((!objx || !objs[objx]) && iobx) { iobx++; if (iobjs[iobx] == 0) iobx = 0; if (iobx && iobjs[1]) objx = 1; } } while (objx || iobx); return;}/* Routine to describe current location*/void describe(){ if (toting(BEAR)) rspeak(141); if (dark()) rspeak(16); else if ((g.terse && verb != LOOK) || g.visited[g.loc] % g.abbnum) descsh(g.loc); else desclg(g.loc); if (g.loc == 33 && pct(25) && !g.closing) rspeak(8); if (g.loc == 147 && !g.visited[g.loc]) rspeak(216); return;}/* Routine to describe visible items*/void descitem(){ int i, state; for (i = 1; i < MAXOBJ; ++i) { if (at(i)) { if (i == STEPS && toting(NUGGET)) continue; if (g.prop[i] < 0) { if (g.closed) continue; else { g.prop[i] = 0; if (i == RUG || i == CHAIN || i == SWORD || i == CASK) g.prop[i] = 1; if (i == CLOAK || i == RING) g.prop[i] = 2; --g.tally; } } if (i == STEPS && g.loc == g.fixed[STEPS]) state = 1; else state = g.prop[i] % 8; pspeak(i, state); lookin(i); } } /* If remaining treasures too elusive, zap his lamp */ if (g.tally == g.tally2 && g.tally != 0 && g.limit > 35) g.limit = 35; return;}/* Routine to handle player's demise via waking up the dwarves...*/void dwarfend(){ rspeak(136); normend(); return;}/* normal end of game*/void normend(){ score(FALSE); gaveup = TRUE; return;}/* Routine to handle the passing on of one of the player's incarnations...*/void death(){ int yea, j; if (!g.closing) { if (g.limit < 0) { rspeak(185); normend(); return; } yea = yes(81 + g.numdie * 2, 82 + g.numdie * 2, 54); if (++g.numdie >= MAXDIE || !yea) normend(); if (g.chase) { g.chase = FALSE; g.prop[WUMPUS] = 0; move(WUMPUS, 174); } if (toting(LAMP)) g.prop[LAMP] = 0; for (j = 1; j < MAXOBJ; ++j) { if (toting(j)) drop(j, j == LAMP ? 1 : g.oldloc2); if (wearng(j)) { g.prop[j] = 0; bitoff(j, WEARBT); } } g.newloc = 3; g.oldloc = g.loc; g.health = 100; return; } /* Closing -- no resurrection... */ rspeak(131); ++g.numdie; normend(); return;}/* dwarf stuff.*/void dwarves(){ int i, j, k, attack, stick, dtotal; /* See if dwarves allowed here */ if (g.newloc == 0 || forced(g.newloc) || g.loc_attrib[g.newloc] & NOPIRAT) return; /* See if dwarves are active. */ if (!g.dflag) { if (inside(g.newloc)) ++g.dflag; return; } /* If first close encounter (of 3rd kind) */ if (g.dflag == 1) { if (!inside(g.newloc) || pct(85)) return; ++g.dflag; /* kill 0, 1 or 2 of the dwarfs */ for (i = 1; i < 3; ++i) if (pct(50)) g.dloc[(ranz(DWARFMAX - 1)) + 1] = 0; /* If any of the survivors is at location, use alternate choise */ for (i = 1; i <= DWARFMAX; ++i) { if (g.dloc[i] == g.newloc) g.dloc[i] = g.daltloc; g.odloc[i] = g.dloc[i]; } rspeak(3); drop(AXE, g.newloc); return; } /* Things are in full swing. Move each dwarf at random, except if he's seen us then he sticks with us. Dwarfs never go to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -