X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=main.c;h=79355834d50d6639c73dfebbe5205ee230e5b7e1;hb=9d072a8c444465369612c603649ff99c97cc086e;hp=cfad7b075ac488d3bd23f7d4c3e43998aa0f2c17;hpb=dd2a9497309ca258ac495deb52f1e9c94a589ab6;p=open-adventure.git diff --git a/main.c b/main.c index cfad7b0..7935583 100644 --- a/main.c +++ b/main.c @@ -1,7 +1,16 @@ /* + * There used to be a note that said this: + * * The author - Don Woods - apologises for the style of the code; it * is a result of running the original Fortran IV source through a * home-brew Fortran-to-C converter.) + * + * Now that the code has been restructured into idiomatic C, the following + * is more appropriate: + * + * ESR apologizes for the remaing gotos (now confined to two functions in this + * file - they used to be *everywhere*), and the offensive globals. Applying + * the Structured Program Theorem can be hard. */ #include #include @@ -501,27 +510,28 @@ static bool playermove(FILE *cmdin, token_t verb) if (K == game.loc)K2=91; if (CNDBIT(game.loc,4))K2=274; if (K2 == 0) { - L21: - LL=MOD((labs(TRAVEL[KK])/1000),1000); - if (LL != K) { - if (LL <= 300) { - if (FORCED(LL) && MOD((labs(TRAVEL[KEY[LL]])/1000),1000) == K) - K2=KK; - } - if (TRAVEL[KK] >= 0) { - ++KK; - goto L21; - } - KK=K2; - if (KK == 0) { - RSPEAK(140); - return true; + for (;;) { + LL=MOD((labs(TRAVEL[KK])/1000),1000); + if (LL != K) { + if (LL <= 300) { + if (FORCED(LL) && MOD((labs(TRAVEL[KEY[LL]])/1000),1000) == K) + K2=KK; + } + if (TRAVEL[KK] >= 0) { + ++KK; + continue; + } + KK=K2; + if (KK == 0) { + RSPEAK(140); + return true; + } } - } - K=MOD(labs(TRAVEL[KK]),1000); - KK=KEY[game.loc]; - goto L9; + K=MOD(labs(TRAVEL[KK]),1000); + KK=KEY[game.loc]; + break; /* fall through to ordinary travel */ + } } else { RSPEAK(K2); return true; @@ -542,10 +552,13 @@ static bool playermove(FILE *cmdin, token_t verb) RSPEAK((OUTSID(game.loc) && game.loc != 8) ? 57 : 58); return true; } - game.oldlc2=game.oldloc; - game.oldloc=game.loc; + else { + /* none of the specials */ + game.oldlc2=game.oldloc; + game.oldloc=game.loc; + } -L9: + /* ordinary travel */ for (;;) { LL=labs(TRAVEL[KK]); if (MOD(LL,1000) == 1 || MOD(LL,1000) == K) @@ -823,20 +836,47 @@ L2607: game.foobar=(game.foobar>0 ? -game.foobar : 0); if (game.clock2 == 0) goto L11000; if (game.prop[LAMP] == 1) --game.limit; - if (game.limit <= 30 && HERE(BATTER) && game.prop[BATTER] == 0 && HERE(LAMP)) - goto L12000; - if (game.limit == 0) goto L12400; - if (game.limit <= 30) goto L12200; + + /* 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<=30 && HERE(BATTER) && game.prop[BATTER]==0 && HERE(LAMP)) + { + RSPEAK(188); + 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(184); + } else if (game.limit <= 30) { + if (game.lmwarn || !HERE(LAMP)) goto L19999; + game.lmwarn=true; + SPK=187; + if (game.place[BATTER] == 0)SPK=183; + if (game.prop[BATTER] == 1)SPK=189; + RSPEAK(SPK); + } L19999: K=43; if (LIQLOC(game.loc) == WATER)K=70; V1=VOCAB(WD1,-1); V2=VOCAB(WD2,-1); - if (V1 == ENTER && (V2 == STREAM || V2 == 1000+WATER)) goto L2010; - if (V1 == ENTER && WD2 > 0) goto L2800; - if ((V1 != 1000+WATER && V1 != 1000+OIL) || (V2 != 1000+PLANT && V2 != - 1000+DOOR)) goto L2610; - {long x = V2-1000; if (AT(x))WD2=MAKEWD(16152118);} -L2610: if (V1 == 1000+CAGE && V2 == 1000+BIRD && HERE(CAGE) && HERE(BIRD)) + if (V1 == ENTER && (V2 == STREAM || V2 == 1000+WATER)) + goto L2010; + if (V1 == ENTER && WD2 > 0) + goto L2800; + if (!((V1 != 1000+WATER && V1 != 1000+OIL) || + (V2 != 1000+PLANT && V2 != 1000+DOOR))) { + if (AT(V2-1000)) + WD2=MAKEWD(16152118); + } + if (V1 == 1000+CAGE && V2 == 1000+BIRD && HERE(CAGE) && HERE(BIRD)) WD1=MAKEWD(301200308); L2620: if (WD1 == MAKEWD(23051920)) { ++game.iwest; @@ -1010,32 +1050,6 @@ L11000: game.prop[BOTTLE]=PUT(BOTTLE,115,1); game.closed=true; return true; -/* 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. We go to 12000 if the lamp - * and fresh batteries are here, in which case we replace the batteries and - * continue. 12200 is for other cases of lamp dying. 12400 is when it goes - * out. Even then, he can explore outside for a while if desired. */ - -L12000: RSPEAK(188); - game.prop[BATTER]=1; - if (TOTING(BATTER))DROP(BATTER,game.loc); - game.limit=game.limit+2500; - game.lmwarn=false; - goto L19999; - -L12200: if (game.lmwarn || !HERE(LAMP)) goto L19999; - game.lmwarn=true; - SPK=187; - if (game.place[BATTER] == 0)SPK=183; - if (game.prop[BATTER] == 1)SPK=189; - RSPEAK(SPK); - goto L19999; - -L12400: game.limit= -1; - game.prop[LAMP]=0; - if (HERE(LAMP))RSPEAK(184); - goto L19999; - /* Oh dear, he's disturbed the dwarves. */ L18999: RSPEAK(SPK);