X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=main.c;h=ecc9ca03a2f1a13ccc522d464249e67d58692a77;hb=c818a10f2875b8b9f63c6cf6d5ef1389e37bf857;hp=1c5749dc632245ccd9f54d074d3ebf1a9d8dae55;hpb=c3453db345aee46e5e0e6ad5657a10c62139b815;p=open-adventure.git diff --git a/main.c b/main.c index 1c5749d..ecc9ca0 100644 --- a/main.c +++ b/main.c @@ -46,7 +46,6 @@ FILE *logfp; bool oldstyle = false; bool editline = true; bool prompt = true; -lcg_state lcgstate; extern void initialise(); extern void score(long); @@ -114,9 +113,9 @@ int main(int argc, char *argv[]) /* Initialize our LCG PRNG with parameters tested against * Knuth vol. 2. by the original authors */ - lcgstate.a = 1093; - lcgstate.c = 221587; - lcgstate.m = 1048576; + game.lcg_a = 1093; + game.lcg_c = 221587; + game.lcg_m = 1048576; srand(time(NULL)); long seedval = (long)rand(); set_seed(seedval); @@ -269,49 +268,52 @@ bool spotted_by_pirate(int i) * (game.prop=0). */ if (game.loc == game.chloc || game.prop[CHEST] >= 0) return true; - int k=0; + int snarfed=0; + bool movechest = false, robplayer = false; for (int j=MINTRS; j<=MAXTRS; j++) { /* Pirate won't take pyramid from plover room or dark * room (too easy!). */ if (j==PYRAM && (game.loc==PLAC[PYRAM] || game.loc==PLAC[EMRALD])) { - return true; + continue; } + if (TOTING(j) || HERE(j)) + ++snarfed; if (TOTING(j)) { - if (game.place[CHEST] == 0) { - /* Install chest only once, to insure it is - * the last treasure in the list. */ - MOVE(CHEST,game.chloc); - MOVE(MESSAG,game.chloc2); - } - RSPEAK(128); - for (int j=MINTRS; j<=MAXTRS; j++) { - if (!(j == PYRAM && (game.loc == PLAC[PYRAM] || game.loc == PLAC[EMRALD]))) { - if (AT(j) && game.fixed[j] == 0) - CARRY(j,game.loc); - if (TOTING(j)) - DROP(j,game.chloc); - } - } - game.dloc[PIRATE]=game.chloc; - game.odloc[PIRATE]=game.chloc; - game.dseen[PIRATE]=false; - return true; + movechest = true; + robplayer = true; } - if (HERE(j)) - k=1; } /* Force chest placement before player finds last treasure */ - if (game.tally == 1 && k == 0 && game.place[CHEST] == 0 && HERE(LAMP) && game.prop[LAMP] == 1) { + if (game.tally == 1 && snarfed == 0 && game.place[CHEST] == 0 && HERE(LAMP) && game.prop[LAMP] == 1) { RSPEAK(186); + movechest = true; + } + /* Do things in this order (chest move before robbery) so chest is listed + * last at the maze location. */ + if (movechest) { MOVE(CHEST,game.chloc); MOVE(MESSAG,game.chloc2); game.dloc[PIRATE]=game.chloc; game.odloc[PIRATE]=game.chloc; game.dseen[PIRATE]=false; - return true; + } else { + /* You might get a hint of the pirate's presence even if the + * chest doesn't move... */ + if (game.odloc[PIRATE] != game.dloc[PIRATE] && PCT(20)) + RSPEAK(127); + } + if (robplayer) { + RSPEAK(128); + for (int j=MINTRS; j<=MAXTRS; j++) { + if (!(j == PYRAM && (game.loc == PLAC[PYRAM] || game.loc == PLAC[EMRALD]))) { + if (AT(j) && game.fixed[j] == 0) + CARRY(j,game.loc); + if (TOTING(j)) + DROP(j,game.chloc); + } + } } - if (game.odloc[PIRATE] != game.dloc[PIRATE] && PCT(20)) - RSPEAK(127); + return true; } @@ -467,14 +469,13 @@ static bool dwarfmove(void) static void croak(FILE *cmdin) /* Okay, he's dead. Let's get on with it. */ { + ++game.numdie; if (game.closng) { /* He died during closing time. No resurrection. Tally up a * death and exit. */ RSPEAK(131); - ++game.numdie; score(0); } else { - ++game.numdie; if (!YES(cmdin,79+game.numdie*2,80+game.numdie*2,54)) score(0); if (game.numdie == MAXDIE) @@ -486,10 +487,8 @@ static void croak(FILE *cmdin) for (int j=1; j<=NOBJECTS; j++) { int i=NOBJECTS + 1 - j; if (TOTING(i)) { - int k=game.oldlc2; - if (i == LAMP) - k=1; - DROP(i,k); + /* Always leave lamp where it's accessible aboveground */ + DROP(i, (i == LAMP) ? 1 : game.oldlc2); } } game.loc=3; @@ -861,10 +860,9 @@ static void listobjects(void) * get full score. */ { if (!DARK(game.loc)) { - long obj; ++game.abbrev[game.loc]; for (int i=game.atloc[game.loc]; i != 0; i=game.link[i]) { - obj=i; + long obj=i; if (obj > NOBJECTS)obj=obj-NOBJECTS; if (obj == STEPS && TOTING(NUGGET)) continue;