X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=blobdiff_plain;f=main.c;h=a975a948557d15ffedb6607caddb30c044669661;hp=ad2fdb1c16ae600391696c3e6601df623101d2f9;hb=e42458868261932e435fd4ff3521face75334627;hpb=6d571c18b8a243f6c2d6aae100deb0051675de69 diff --git a/main.c b/main.c index ad2fdb1..a975a94 100644 --- a/main.c +++ b/main.c @@ -27,6 +27,17 @@ #define DIM(a) (sizeof(a)/sizeof(a[0])) +/* Abstract out the encoding of words in the travel array. Gives us + * some hope of getting to a less cryptic representation than we + * inherited from FORTRAN, someday. To understand these, read the + * encoding description for TRAVEL. + */ +#define T_DESTINATION(entry) MOD(labs(entry) / 1000, 1000) +#define T_NODWARVES(entry) labs(entry) / 1000000 == 100 +#define T_MOTION(entry) MOD(labs(entry), 1000) +#define L_SPEAK(loc) ((loc) - 500) +#define T_TERMINATE(entry) (T_MOTION(entry) == 1) + struct game_t game; long LNLENG, LNPOSN; @@ -410,7 +421,7 @@ static bool dwarfmove(void) kk = KEY[game.dloc[i]]; if (kk != 0) do { - game.newloc = MOD(labs(TRAVEL[kk]) / 1000, 1000); + game.newloc = T_DESTINATION(TRAVEL[kk]); /* Have we avoided a dwarf encounter? */ bool avoided = (SPECIAL(game.newloc) || !INDEEP(game.newloc) || @@ -420,7 +431,7 @@ static bool dwarfmove(void) game.newloc == game.dloc[i] || FORCED(game.newloc) || (i == PIRATE && CNDBIT(game.newloc, COND_NOARRR)) || - labs(TRAVEL[kk]) / 1000000 == 100); + T_NODWARVES(TRAVEL[kk])); if (!avoided) { tk[j++] = game.newloc; } @@ -550,24 +561,25 @@ static bool playermove(token_t verb, int motion) if (CNDBIT(game.loc, COND_NOBACK))k2 = TWIST_TURN; if (k2 == 0) { for (;;) { - scratchloc = MOD((labs(TRAVEL[kk]) / 1000), 1000); + scratchloc = T_DESTINATION(TRAVEL[kk]); if (scratchloc != motion) { if (!SPECIAL(scratchloc)) { - if (FORCED(scratchloc) && MOD((labs(TRAVEL[KEY[scratchloc]]) / 1000), 1000) == motion) + if (FORCED(scratchloc) && T_DESTINATION(TRAVEL[KEY[scratchloc]]) == motion) k2 = kk; } if (TRAVEL[kk] >= 0) { - ++kk; + ++kk; /* go to next travel entry for this location */ continue; } - kk = k2; + /* we've reached the end of travel entries for game.loc */ + kk = k2; if (kk == 0) { rspeak(NOT_CONNECTED); return true; } } - motion = MOD(labs(TRAVEL[kk]), 1000); + motion = T_MOTION(TRAVEL[kk]); kk = KEY[game.loc]; break; /* fall through to ordinary travel */ } @@ -595,15 +607,15 @@ static bool playermove(token_t verb, int motion) game.oldloc = game.loc; } - /* ordinary travel */ + /* Look for a way to fulfil the motion - kk indexes the beginning + * of the motion entries for here (game.loc). */ for (;;) { - scratchloc = labs(TRAVEL[kk]); - if (MOD(scratchloc, 1000) == 1 || MOD(scratchloc, 1000) == motion) + if (T_TERMINATE(TRAVEL[kk]) || T_MOTION(TRAVEL[kk]) == motion) break; if (TRAVEL[kk] < 0) { /* FIXME: Magic numbers! */ - /* Non-applicable motion. Various messages depending on - * word given. */ + /* Couldn't find an entry matching the motion word passed + * in. Various messages depending on word given. */ int spk = CANT_APPLY; if (motion >= 43 && motion <= 50)spk = BAD_DIRECTION; if (motion == 29 || motion == 30)spk = BAD_DIRECTION; @@ -617,7 +629,7 @@ static bool playermove(token_t verb, int motion) } ++kk; } - scratchloc = scratchloc / 1000; + scratchloc = labs(TRAVEL[kk]) / 1000; do { /* @@ -723,8 +735,9 @@ static bool playermove(token_t verb, int motion) } } while (false); - /* FIXME: Arithmetic on location number, becoming a message number */ - rspeak(game.newloc - 500); + + /* Execute a speak rule */ + rspeak(L_SPEAK(game.newloc)); game.newloc = game.loc; return true; } @@ -750,7 +763,7 @@ static bool closecheck(void) * to suppress the object descriptions until he's actually moved the * objects. */ { - if (game.tally == 0 && INDEEP(game.loc) && game.loc != 33) + if (game.tally == 0 && INDEEP(game.loc) && game.loc != LOC_Y2) --game.clock1; /* When the first warning comes, we lock the grate, destroy @@ -792,7 +805,7 @@ static bool closecheck(void) 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 + * hardwired as LOC_NE and LOC_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