More macro abstraction of the travel opcodes.

This commit is contained in:
Eric S. Raymond 2017-06-28 08:26:36 -04:00
parent fb35c34171
commit aace0b1359
3 changed files with 26 additions and 26 deletions

2
init.c
View file

@ -25,7 +25,7 @@ void initialise(void)
game.abbrev[i] = 0; game.abbrev[i] = 0;
if (!(locations[i].description.big == 0 || tkey[i] == 0)) { if (!(locations[i].description.big == 0 || tkey[i] == 0)) {
int k = tkey[i]; int k = tkey[i];
if (MOD(travel[k].opcode, 1000) == 1) if (T_LOW(travel[k]) == 1)
conditions[i] |= (1 << COND_FORCED); conditions[i] |= (1 << COND_FORCED);
} }
game.atloc[i] = 0; game.atloc[i] = 0;

36
main.c
View file

@ -27,19 +27,6 @@
#define DIM(a) (sizeof(a)/sizeof(a[0])) #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((entry).opcode / 1000, 1000)
#define T_NODWARVES(entry) ((entry).opcode / 1000000 == 100)
#define T_MOTION(entry) MOD((entry).opcode, 1000)
#define T_TERMINATE(entry) (T_MOTION(entry) == 1)
#define T_STOP(entry) ((entry).stop)
#define T_OPCODE(entry) ((entry).opcode)
#define L_SPEAK(loc) ((loc) - 500)
struct game_t game; struct game_t game;
long LNLENG, LNPOSN; long LNLENG, LNPOSN;
@ -619,7 +606,7 @@ static bool playermove(token_t verb, int motion)
} }
++kk; ++kk;
} }
scratchloc = T_OPCODE(travel[kk]) / 1000; scratchloc = T_HIGH(travel[kk]);
do { do {
/* /*
@ -648,7 +635,7 @@ static bool playermove(token_t verb, int motion)
if (T_STOP(travel[kk])) if (T_STOP(travel[kk]))
BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION);
++kk; ++kk;
game.newloc = T_OPCODE(travel[kk]) / 1000; game.newloc = T_HIGH(travel[kk]);
} while } while
(game.newloc == scratchloc); (game.newloc == scratchloc);
scratchloc = game.newloc; scratchloc = game.newloc;
@ -689,7 +676,7 @@ static bool playermove(token_t verb, int motion)
if (T_STOP(travel[kk])) if (T_STOP(travel[kk]))
BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION);
++kk; ++kk;
game.newloc = T_OPCODE(travel[kk]) / 1000; game.newloc = T_HIGH(travel[kk]);
} while } while
(game.newloc == scratchloc); (game.newloc == scratchloc);
scratchloc = game.newloc; scratchloc = game.newloc;
@ -749,15 +736,14 @@ static bool closecheck(void)
* to get out. If he doesn't within clock2 turns, we close the cave; * to get out. If he doesn't within clock2 turns, we close the cave;
* if he does try, we assume he panics, and give him a few additional * if he does try, we assume he panics, and give him a few additional
* turns to get frantic before we close. When clock2 hits zero, we * turns to get frantic before we close. When clock2 hits zero, we
* branch to 11000 to transport him into the final puzzle. Note that * transport him into the final puzzle. Note that the puzzle depends
* the puzzle depends upon all sorts of random things. For instance, * upon all sorts of random things. For instance, there must be no
* there must be no water or oil, since there are beanstalks which we * water or oil, since there are beanstalks which we don't want to be
* don't want to be able to water, since the code can't handle it. * able to water, since the code can't handle it. Also, we can have
* Also, we can have no keys, since there is a grate (having moved * no keys, since there is a grate (having moved the fixed object!)
* the fixed object!) there separating him from all the treasures. * there separating him from all the treasures. Most of these
* Most of these problems arise from the use of negative prop numbers * problems arise from the use of negative prop numbers to suppress
* to suppress the object descriptions until he's actually moved the * the object descriptions until he's actually moved the objects. */
* objects. */
{ {
if (game.tally == 0 && INDEEP(game.loc) && game.loc != LOC_Y2) if (game.tally == 0 && INDEEP(game.loc) && game.loc != LOC_Y2)
--game.clock1; --game.clock1;

View file

@ -142,6 +142,20 @@ typedef struct {{
const bool stop; const bool stop;
}} travelop_t; }} travelop_t;
/* 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((entry).opcode / 1000, 1000)
#define T_NODWARVES(entry) ((entry).opcode / 1000000 == 100)
#define T_MOTION(entry) MOD((entry).opcode, 1000)
#define T_TERMINATE(entry) (T_MOTION(entry) == 1)
#define T_STOP(entry) ((entry).stop)
#define T_HIGH(entry) ((entry).opcode / 1000)
#define T_LOW(entry) ((entry).opcode % 1000)
#define L_SPEAK(loc) ((loc) - 500)
extern const location_t locations[]; extern const location_t locations[];
extern const object_t objects[]; extern const object_t objects[];
extern const char* arbitrary_messages[]; extern const char* arbitrary_messages[];