Untangling variable reuse
This commit is contained in:
parent
5697a8de63
commit
d48504f22f
1 changed files with 29 additions and 27 deletions
56
main.c
56
main.c
|
@ -521,9 +521,9 @@ static void croak(void)
|
||||||
|
|
||||||
static bool playermove(token_t verb, int motion)
|
static bool playermove(token_t verb, int motion)
|
||||||
{
|
{
|
||||||
int scratchloc, k2, kk = tkey[game.loc];
|
int scratchloc, k2, travel_entry = tkey[game.loc];
|
||||||
game.newloc = game.loc;
|
game.newloc = game.loc;
|
||||||
if (kk == 0)
|
if (travel_entry == 0)
|
||||||
BUG(LOCATION_HAS_NO_TRAVEL_ENTRIES); // LCOV_EXCL_LINE
|
BUG(LOCATION_HAS_NO_TRAVEL_ENTRIES); // LCOV_EXCL_LINE
|
||||||
if (motion == NUL)
|
if (motion == NUL)
|
||||||
return true;
|
return true;
|
||||||
|
@ -536,35 +536,37 @@ static bool playermove(token_t verb, int motion)
|
||||||
motion = game.oldlc2;
|
motion = game.oldlc2;
|
||||||
game.oldlc2 = game.oldloc;
|
game.oldlc2 = game.oldloc;
|
||||||
game.oldloc = game.loc;
|
game.oldloc = game.loc;
|
||||||
k2 = 0;
|
int spk = 0;
|
||||||
if (motion == game.loc)k2 = FORGOT_PATH;
|
if (motion == game.loc)
|
||||||
if (CNDBIT(game.loc, COND_NOBACK))k2 = TWIST_TURN;
|
spk = FORGOT_PATH;
|
||||||
if (k2 == 0) {
|
if (CNDBIT(game.loc, COND_NOBACK))
|
||||||
|
spk = TWIST_TURN;
|
||||||
|
if (spk == 0) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
scratchloc = T_DESTINATION(travel[kk]);
|
scratchloc = T_DESTINATION(travel[travel_entry]);
|
||||||
if (scratchloc != motion) {
|
if (scratchloc != motion) {
|
||||||
if (!SPECIAL(scratchloc)) {
|
if (!SPECIAL(scratchloc)) {
|
||||||
if (FORCED(scratchloc) && T_DESTINATION(travel[tkey[scratchloc]]) == motion)
|
if (FORCED(scratchloc) && T_DESTINATION(travel[tkey[scratchloc]]) == motion)
|
||||||
k2 = kk;
|
k2 = travel_entry;
|
||||||
}
|
}
|
||||||
if (!travel[kk].stop) {
|
if (!travel[travel_entry].stop) {
|
||||||
++kk; /* go to next travel entry for this location */
|
++travel_entry; /* go to next travel entry for this location */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* we've reached the end of travel entries for game.loc */
|
/* we've reached the end of travel entries for game.loc */
|
||||||
kk = k2;
|
travel_entry = k2;
|
||||||
if (kk == 0) {
|
if (travel_entry == 0) {
|
||||||
rspeak(NOT_CONNECTED);
|
rspeak(NOT_CONNECTED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
motion = travel[kk].motion;
|
motion = travel[travel_entry].motion;
|
||||||
kk = tkey[game.loc];
|
travel_entry = tkey[game.loc];
|
||||||
break; /* fall through to ordinary travel */
|
break; /* fall through to ordinary travel */
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rspeak(k2);
|
rspeak(spk);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (motion == LOOK) {
|
} else if (motion == LOOK) {
|
||||||
|
@ -587,12 +589,12 @@ static bool playermove(token_t verb, int motion)
|
||||||
game.oldloc = game.loc;
|
game.oldloc = game.loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look for a way to fulfil the motion verb passed in - kk indexes
|
/* Look for a way to fulfil the motion verb passed in - travel_entry indexes
|
||||||
* the beginning of the motion entries for here (game.loc). */
|
* the beginning of the motion entries for here (game.loc). */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (T_TERMINATE(travel[kk]) || travel[kk].motion == motion)
|
if (T_TERMINATE(travel[travel_entry]) || travel[travel_entry].motion == motion)
|
||||||
break;
|
break;
|
||||||
if (travel[kk].stop) {
|
if (travel[travel_entry].stop) {
|
||||||
/* FIXME: Magic numbers! */
|
/* FIXME: Magic numbers! */
|
||||||
/* Couldn't find an entry matching the motion word passed
|
/* Couldn't find an entry matching the motion word passed
|
||||||
* in. Various messages depending on word given. */
|
* in. Various messages depending on word given. */
|
||||||
|
@ -607,7 +609,7 @@ static bool playermove(token_t verb, int motion)
|
||||||
rspeak(spk);
|
rspeak(spk);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
++kk;
|
++travel_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (ESR) We've found a destination that goes with the motion verb.
|
/* (ESR) We've found a destination that goes with the motion verb.
|
||||||
|
@ -616,7 +618,7 @@ static bool playermove(token_t verb, int motion)
|
||||||
do {
|
do {
|
||||||
for (;;) { /* L12 loop */
|
for (;;) { /* L12 loop */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
long cond = T_CONDITION(travel[kk]);
|
long cond = T_CONDITION(travel[travel_entry]);
|
||||||
long arg = MOD(cond, 100);
|
long arg = MOD(cond, 100);
|
||||||
if (!SPECIAL(cond)) {
|
if (!SPECIAL(cond)) {
|
||||||
/* YAML N and [pct N] conditionals */
|
/* YAML N and [pct N] conditionals */
|
||||||
|
@ -634,18 +636,18 @@ static bool playermove(token_t verb, int motion)
|
||||||
|
|
||||||
/* We arrive here on conditional failure.
|
/* We arrive here on conditional failure.
|
||||||
* Skip to next non-matching destination */
|
* Skip to next non-matching destination */
|
||||||
long k3 = kk;
|
long k3 = travel_entry;
|
||||||
do {
|
do {
|
||||||
if (travel[k3].stop)
|
if (travel[k3].stop)
|
||||||
BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE
|
BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE
|
||||||
++k3;
|
++k3;
|
||||||
} while
|
} while
|
||||||
(T_HIGH(travel[kk]) == T_HIGH(travel[k3]));
|
(T_HIGH(travel[travel_entry]) == T_HIGH(travel[k3]));
|
||||||
kk = k3;
|
travel_entry = k3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Found an eligible rule, now execute it */
|
/* Found an eligible rule, now execute it */
|
||||||
game.newloc = T_DESTINATION(travel[kk]);
|
game.newloc = T_DESTINATION(travel[travel_entry]);
|
||||||
if (!SPECIAL(game.newloc))
|
if (!SPECIAL(game.newloc))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -676,14 +678,14 @@ static bool playermove(token_t verb, int motion)
|
||||||
* to get it out. Having dropped it, go back and
|
* to get it out. Having dropped it, go back and
|
||||||
* pretend he wasn't carrying it after all. */
|
* pretend he wasn't carrying it after all. */
|
||||||
drop(EMERALD, game.loc);
|
drop(EMERALD, game.loc);
|
||||||
k2 = kk;
|
k2 = travel_entry;
|
||||||
do {
|
do {
|
||||||
if (travel[k2].stop)
|
if (travel[k2].stop)
|
||||||
BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE
|
BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE
|
||||||
++k2;
|
++k2;
|
||||||
} while
|
} while
|
||||||
(T_HIGH(travel[kk]) == T_HIGH(travel[k2]));
|
(T_HIGH(travel[travel_entry]) == T_HIGH(travel[k2]));
|
||||||
kk = k2;
|
travel_entry = k2;
|
||||||
continue; /* goto L12 */
|
continue; /* goto L12 */
|
||||||
case 3:
|
case 3:
|
||||||
/* Travel 303. Troll bridge. Must be done only
|
/* Travel 303. Troll bridge. Must be done only
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue