Re-format to consistent indent style with "make indent".

This commit is contained in:
Eric S. Raymond 2017-06-18 06:18:51 -04:00
parent a37e578f63
commit b3057f038b
8 changed files with 2516 additions and 2419 deletions

354
actions.c
View file

@ -44,16 +44,14 @@ static int attack(FILE *input, long verb, token_t obj)
} }
if (obj == BIRD) { if (obj == BIRD) {
spk = UNHAPPY_BIRD; spk = UNHAPPY_BIRD;
if (game.closed) if (game.closed) {
{
RSPEAK(spk); RSPEAK(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
DESTROY(BIRD); DESTROY(BIRD);
game.prop[BIRD] = 0; game.prop[BIRD] = 0;
spk = BIRD_DEAD; spk = BIRD_DEAD;
} } else if (obj == VEND) {
else if (obj == VEND) {
PSPEAK(VEND, game.prop[VEND] + 2); PSPEAK(VEND, game.prop[VEND] + 2);
game.prop[VEND] = 3 - game.prop[VEND]; game.prop[VEND] = 3 - game.prop[VEND];
return GO_CLEAROBJ; return GO_CLEAROBJ;
@ -80,8 +78,7 @@ static int attack(FILE *input, long verb, token_t obj)
} }
} }
spk = (dwarves > 1) ? OGRE_PANIC1 : OGRE_PANIC2; spk = (dwarves > 1) ? OGRE_PANIC1 : OGRE_PANIC2;
} } else if (obj == BEAR)
else if (obj == BEAR)
/* FIXME: Arithmetic on message numbers */ /* FIXME: Arithmetic on message numbers */
spk = BEAR_HANDS + (game.prop[BEAR] + 1) / 2; spk = BEAR_HANDS + (game.prop[BEAR] + 1) / 2;
else if (obj == DRAGON && game.prop[DRAGON] == 0) { else if (obj == DRAGON && game.prop[DRAGON] == 0) {
@ -228,7 +225,10 @@ static int carry(token_t verb, token_t obj)
obj = game.atloc[game.loc]; obj = game.atloc[game.loc];
} }
if (TOTING(obj)) {RSPEAK(ALREADY_CARRYING); return GO_CLEAROBJ;} if (TOTING(obj)) {
RSPEAK(ALREADY_CARRYING);
return GO_CLEAROBJ;
}
spk = YOU_JOKING; spk = YOU_JOKING;
if (obj == PLANT && game.prop[PLANT] <= 0)spk = DEEP_ROOTS; if (obj == PLANT && game.prop[PLANT] <= 0)spk = DEEP_ROOTS;
if (obj == BEAR && game.prop[BEAR] == 1)spk = BEAR_CHAINED; if (obj == BEAR && game.prop[BEAR] == 1)spk = BEAR_CHAINED;
@ -265,8 +265,7 @@ static int carry(token_t verb, token_t obj)
if (game.holdng >= INVLIMIT) { if (game.holdng >= INVLIMIT) {
RSPEAK(spk); RSPEAK(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} } else if (obj == BIRD && game.prop[BIRD] != 1 && -1 - game.prop[BIRD] != 1) {
else if (obj == BIRD && game.prop[BIRD] != 1 && -1-game.prop[BIRD] != 1) {
if (game.prop[BIRD] == 2) { if (game.prop[BIRD] == 2) {
DESTROY(BIRD); DESTROY(BIRD);
RSPEAK(BIRD_CRAP); RSPEAK(BIRD_CRAP);
@ -301,7 +300,10 @@ static int chain(token_t verb)
spk = CHAIN_UNLOCKED; spk = CHAIN_UNLOCKED;
if (game.prop[BEAR] == 0)spk = BEAR_BLOCKS; if (game.prop[BEAR] == 0)spk = BEAR_BLOCKS;
if (game.prop[CHAIN] == 0)spk = ALREADY_UNLOCKED; if (game.prop[CHAIN] == 0)spk = ALREADY_UNLOCKED;
if (spk != CHAIN_UNLOCKED) {RSPEAK(spk); return GO_CLEAROBJ;} if (spk != CHAIN_UNLOCKED) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
game.prop[CHAIN] = 0; game.prop[CHAIN] = 0;
game.fixed[CHAIN] = 0; game.fixed[CHAIN] = 0;
if (game.prop[BEAR] != 3)game.prop[BEAR] = 2; if (game.prop[BEAR] != 3)game.prop[BEAR] = 2;
@ -330,7 +332,10 @@ static int discard(token_t verb, token_t obj, bool just_do_it)
int spk = ACTSPK[verb]; int spk = ACTSPK[verb];
if (!just_do_it) { if (!just_do_it) {
if (TOTING(ROD2) && obj == ROD && !TOTING(ROD))obj = ROD2; if (TOTING(ROD2) && obj == ROD && !TOTING(ROD))obj = ROD2;
if (!TOTING(obj)) {RSPEAK(spk); return GO_CLEAROBJ;} if (!TOTING(obj)) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
if (obj == BIRD && HERE(SNAKE)) { if (obj == BIRD && HERE(SNAKE)) {
RSPEAK(BIRD_ATTACKS); RSPEAK(BIRD_ATTACKS);
if (game.closed) return GO_DWARFWAKE; if (game.closed) return GO_DWARFWAKE;
@ -454,13 +459,11 @@ static int extinguish(token_t verb, int obj)
if (obj == URN) { if (obj == URN) {
game.prop[URN] = game.prop[URN] / 2; game.prop[URN] = game.prop[URN] / 2;
spk = URN_DARK; spk = URN_DARK;
} } else if (obj == LAMP) {
else if (obj == LAMP) {
game.prop[LAMP] = 0; game.prop[LAMP] = 0;
RSPEAK(LAMP_OFF); RSPEAK(LAMP_OFF);
spk = DARK(game.loc) ? PITCH_DARK : NO_MESSAGE; spk = DARK(game.loc) ? PITCH_DARK : NO_MESSAGE;
} } else if (obj == DRAGON || obj == VOLCAN)
else if (obj == DRAGON || obj == VOLCAN)
spk = BEYOND_POWER; spk = BEYOND_POWER;
RSPEAK(spk); RSPEAK(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
@ -474,8 +477,7 @@ static int feed(token_t verb, token_t obj)
if (obj == BIRD) { if (obj == BIRD) {
RSPEAK(BIRD_PINING); RSPEAK(BIRD_PINING);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} } else if (obj == SNAKE || obj == DRAGON || obj == TROLL) {
else if (obj == SNAKE || obj == DRAGON || obj == TROLL) {
spk = NOTHING_EDIBLE; spk = NOTHING_EDIBLE;
if (obj == DRAGON && game.prop[DRAGON] != 0)spk = RIDICULOUS_ATTEMPT; if (obj == DRAGON && game.prop[DRAGON] != 0)spk = RIDICULOUS_ATTEMPT;
if (obj == TROLL)spk = TROLL_VICES; if (obj == TROLL)spk = TROLL_VICES;
@ -484,14 +486,12 @@ static int feed(token_t verb, token_t obj)
game.prop[BIRD] = 0; game.prop[BIRD] = 0;
spk = BIRD_DEVOURED; spk = BIRD_DEVOURED;
} }
} } else if (obj == DWARF) {
else if (obj == DWARF) {
if (HERE(FOOD)) { if (HERE(FOOD)) {
game.dflag += 2; game.dflag += 2;
spk = REALLY_MAD; spk = REALLY_MAD;
} }
} } else if (obj == BEAR) {
else if (obj == BEAR) {
if (game.prop[BEAR] == 0)spk = NOTHING_EDIBLE; if (game.prop[BEAR] == 0)spk = NOTHING_EDIBLE;
if (game.prop[BEAR] == 3)spk = RIDICULOUS_ATTEMPT; if (game.prop[BEAR] == 3)spk = RIDICULOUS_ATTEMPT;
if (HERE(FOOD)) { if (HERE(FOOD)) {
@ -501,8 +501,7 @@ static int feed(token_t verb, token_t obj)
game.prop[AXE] = 0; game.prop[AXE] = 0;
spk = BEAR_TAMED; spk = BEAR_TAMED;
} }
} } else if (obj == OGRE) {
else if (obj == OGRE) {
if (HERE(FOOD)) if (HERE(FOOD))
spk = OGRE_FULL; spk = OGRE_FULL;
} else { } else {
@ -529,25 +528,28 @@ int fill(token_t verb, token_t obj)
game.prop[VASE] = 2; game.prop[VASE] = 2;
game.fixed[VASE] = -1; game.fixed[VASE] = -1;
return (discard(verb, obj, true)); return (discard(verb, obj, true));
} } else if (obj == URN) {
else if (obj == URN) {
spk = FULL_URN; spk = FULL_URN;
if (game.prop[URN] != 0) {RSPEAK(spk); return GO_CLEAROBJ;} if (game.prop[URN] != 0) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
spk = FILL_INVALID; spk = FILL_INVALID;
k = LIQUID(); k = LIQUID();
if (k == 0 || !HERE(BOTTLE)) {RSPEAK(spk); return GO_CLEAROBJ;} if (k == 0 || !HERE(BOTTLE)) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
game.place[k] = NOWHERE; game.place[k] = NOWHERE;
game.prop[BOTTLE] = 1; game.prop[BOTTLE] = 1;
if (k == OIL)game.prop[URN] = 1; if (k == OIL)game.prop[URN] = 1;
spk = WATER_URN + game.prop[URN]; spk = WATER_URN + game.prop[URN];
RSPEAK(spk); RSPEAK(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} } else if (obj != 0 && obj != BOTTLE) {
else if (obj != 0 && obj != BOTTLE) {
RSPEAK(spk); RSPEAK(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} } else if (obj == 0 && !HERE(BOTTLE))
else if (obj == 0 && !HERE(BOTTLE))
return GO_UNKNOWN; return GO_UNKNOWN;
spk = BOTTLED_WATER; spk = BOTTLED_WATER;
if (LIQLOC(game.loc) == 0) if (LIQLOC(game.loc) == 0)
@ -602,7 +604,10 @@ static int fly(token_t verb, token_t obj)
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
spk = RUG_NOTHING1; spk = RUG_NOTHING1;
if (game.prop[RUG] != 2) {RSPEAK(spk); return GO_CLEAROBJ;} if (game.prop[RUG] != 2) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
game.oldlc2 = game.oldloc; game.oldlc2 = game.oldloc;
game.oldloc = game.loc; game.oldloc = game.loc;
game.newloc = game.place[RUG] + game.fixed[RUG] - game.loc; game.newloc = game.place[RUG] + game.fixed[RUG] - game.loc;
@ -652,8 +657,7 @@ static int light(token_t verb, token_t obj)
} }
return GO_CLEAROBJ; return GO_CLEAROBJ;
} else { } else {
if (obj != LAMP) if (obj != LAMP) {
{
RSPEAK(spk); RSPEAK(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
@ -707,7 +711,10 @@ static int lock(token_t verb, token_t obj)
if (AT(GRATE))obj = GRATE; if (AT(GRATE))obj = GRATE;
if (obj != 0 && HERE(CHAIN)) return GO_UNKNOWN; if (obj != 0 && HERE(CHAIN)) return GO_UNKNOWN;
if (HERE(CHAIN))obj = CHAIN; if (HERE(CHAIN))obj = CHAIN;
if (obj == 0) {RSPEAK(spk); return GO_CLEAROBJ;} if (obj == 0) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
} }
/* Lock, unlock object. Special stuff for opening clam/oyster /* Lock, unlock object. Special stuff for opening clam/oyster
@ -746,19 +753,30 @@ static int pour(token_t verb, token_t obj)
int spk = ACTSPK[verb]; int spk = ACTSPK[verb];
if (obj == BOTTLE || obj == 0)obj = LIQUID(); if (obj == BOTTLE || obj == 0)obj = LIQUID();
if (obj == 0) return GO_UNKNOWN; if (obj == 0) return GO_UNKNOWN;
if (!TOTING(obj)) {RSPEAK(spk); return GO_CLEAROBJ;} if (!TOTING(obj)) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
spk = CANT_POUR; spk = CANT_POUR;
if (obj != OIL && obj != WATER) {RSPEAK(spk); return GO_CLEAROBJ;} if (obj != OIL && obj != WATER) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
if (HERE(URN) && game.prop[URN] == 0) if (HERE(URN) && game.prop[URN] == 0)
return fill(verb, URN); return fill(verb, URN);
game.prop[BOTTLE] = 1; game.prop[BOTTLE] = 1;
game.place[obj] = NOWHERE; game.place[obj] = NOWHERE;
spk = GROUND_WET; spk = GROUND_WET;
if (!(AT(PLANT) || AT(DOOR))) if (!(AT(PLANT) || AT(DOOR))) {
{RSPEAK(spk); return GO_CLEAROBJ;} RSPEAK(spk);
return GO_CLEAROBJ;
}
if (!AT(DOOR)) { if (!AT(DOOR)) {
spk = SHAKING_LEAVES; spk = SHAKING_LEAVES;
if (obj != WATER) {RSPEAK(spk); return GO_CLEAROBJ;} if (obj != WATER) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
PSPEAK(PLANT, game.prop[PLANT] + 3); PSPEAK(PLANT, game.prop[PLANT] + 3);
game.prop[PLANT] = MOD(game.prop[PLANT] + 1, 3); game.prop[PLANT] = MOD(game.prop[PLANT] + 1, 3);
game.prop[PLANT2] = game.prop[PLANT]; game.prop[PLANT2] = game.prop[PLANT];
@ -982,7 +1000,10 @@ static int wave(token_t verb, token_t obj)
RSPEAK(spk); RSPEAK(spk);
return GO_DWARFWAKE; return GO_DWARFWAKE;
} }
if (game.closng || !AT(FISSUR)) {RSPEAK(spk); return GO_CLEAROBJ;} if (game.closng || !AT(FISSUR)) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
if (HERE(BIRD))RSPEAK(spk); if (HERE(BIRD))RSPEAK(spk);
game.prop[FISSUR] = 1 - game.prop[FISSUR]; game.prop[FISSUR] = 1 - game.prop[FISSUR];
PSPEAK(FISSUR, 2 - game.prop[FISSUR]); PSPEAK(FISSUR, 2 - game.prop[FISSUR]);
@ -997,8 +1018,7 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj)
{ {
token_t spk = ACTSPK[verb]; token_t spk = ACTSPK[verb];
if (part == unknown) if (part == unknown) {
{
/* Analyse an object word. See if the thing is here, whether /* Analyse an object word. See if the thing is here, whether
* we've got a verb yet, and so on. Object must be here * we've got a verb yet, and so on. Object must be here
* unless verb is "find" or "invent(ory)" (and no new verb * unless verb is "find" or "invent(ory)" (and no new verb
@ -1016,30 +1036,25 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj)
obj = ENTRNC; obj = ENTRNC;
if (obj != GRATE) if (obj != GRATE)
return GO_MOVE; return GO_MOVE;
} } else if (obj == DWARF && ATDWRF(game.loc) > 0)
else if (obj == DWARF && ATDWRF(game.loc) > 0)
/* FALL THROUGH */; /* FALL THROUGH */;
else if ((LIQUID() == obj && HERE(BOTTLE)) || obj == LIQLOC(game.loc)) else if ((LIQUID() == obj && HERE(BOTTLE)) || obj == LIQLOC(game.loc))
/* FALL THROUGH */; /* FALL THROUGH */;
else if (obj == OIL && HERE(URN) && game.prop[URN] != 0) { else if (obj == OIL && HERE(URN) && game.prop[URN] != 0) {
obj = URN; obj = URN;
/* FALL THROUGH */; /* FALL THROUGH */;
} } else if (obj == PLANT && AT(PLANT2) && game.prop[PLANT2] != 0) {
else if (obj == PLANT && AT(PLANT2) && game.prop[PLANT2] != 0) {
obj = PLANT2; obj = PLANT2;
/* FALL THROUGH */; /* FALL THROUGH */;
} } else if (obj == KNIFE && game.knfloc == game.loc) {
else if (obj == KNIFE && game.knfloc == game.loc) {
game.knfloc = -1; game.knfloc = -1;
spk = KNIVES_VANISH; spk = KNIVES_VANISH;
RSPEAK(spk); RSPEAK(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} } else if (obj == ROD && HERE(ROD2)) {
else if (obj == ROD && HERE(ROD2)) {
obj = ROD2; obj = ROD2;
/* FALL THROUGH */; /* FALL THROUGH */;
} } else if ((verb == FIND || verb == INVENT) && WD2 <= 0)
else if ((verb == FIND || verb == INVENT) && WD2 <= 0)
/* FALL THROUGH */; /* FALL THROUGH */;
else { else {
SETPRM(1, WD1, WD1X); SETPRM(1, WD1, WD1X);
@ -1053,48 +1068,86 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj)
part = transitive; part = transitive;
} }
switch(part) switch (part) {
{
case intransitive: case intransitive:
if (WD2 > 0 && verb != SAY) return (2800); if (WD2 > 0 && verb != SAY) return (2800);
if (verb == SAY)obj = WD2; if (verb == SAY)obj = WD2;
if (obj == 0 || obj == INTRANSITIVE) { if (obj == 0 || obj == INTRANSITIVE) {
/* Analyse an intransitive verb (ie, no object given yet). */ /* Analyse an intransitive verb (ie, no object given yet). */
switch (verb - 1) { switch (verb - 1) {
case 0: /* CARRY */ return carry(verb, INTRANSITIVE); case 0: /* CARRY */
case 1: /* DROP */ return GO_UNKNOWN; return carry(verb, INTRANSITIVE);
case 2: /* SAY */ return GO_UNKNOWN; case 1: /* DROP */
case 3: /* UNLOC */ return lock(verb, INTRANSITIVE); return GO_UNKNOWN;
case 4: /* NOTHI */ {RSPEAK(OK_MAN); return(GO_CLEAROBJ);} case 2: /* SAY */
case 5: /* LOCK */ return lock(verb, INTRANSITIVE); return GO_UNKNOWN;
case 6: /* LIGHT */ return light(verb, INTRANSITIVE); case 3: /* UNLOC */
case 7: /* EXTIN */ return extinguish(verb, INTRANSITIVE); return lock(verb, INTRANSITIVE);
case 8: /* WAVE */ return GO_UNKNOWN; case 4: { /* NOTHI */
case 9: /* CALM */ return GO_UNKNOWN; RSPEAK(OK_MAN);
case 10: /* WALK */ {RSPEAK(spk); return GO_CLEAROBJ;} return (GO_CLEAROBJ);
case 11: /* ATTAC */ return attack(input, verb, obj); }
case 12: /* POUR */ return pour(verb, obj); case 5: /* LOCK */
case 13: /* EAT */ return eat(verb, INTRANSITIVE); return lock(verb, INTRANSITIVE);
case 14: /* DRINK */ return drink(verb, obj); case 6: /* LIGHT */
case 15: /* RUB */ return GO_UNKNOWN; return light(verb, INTRANSITIVE);
case 16: /* TOSS */ return GO_UNKNOWN; case 7: /* EXTIN */
case 17: /* QUIT */ return quit(input); return extinguish(verb, INTRANSITIVE);
case 18: /* FIND */ return GO_UNKNOWN; case 8: /* WAVE */
case 19: /* INVEN */ return inven(); return GO_UNKNOWN;
case 20: /* FEED */ return GO_UNKNOWN; case 9: /* CALM */
case 21: /* FILL */ return fill(verb, obj); return GO_UNKNOWN;
case 22: /* BLAST */ blast(); return GO_CLEAROBJ; case 10: { /* WALK */
case 23: /* SCOR */ return vscore(); RSPEAK(spk);
case 24: /* FOO */ return bigwords(WD1); return GO_CLEAROBJ;
case 25: /* BRIEF */ return brief(); }
case 26: /* READ */ return read(input, verb, INTRANSITIVE); case 11: /* ATTAC */
case 27: /* BREAK */ return GO_UNKNOWN; return attack(input, verb, obj);
case 28: /* WAKE */ return GO_UNKNOWN; case 12: /* POUR */
case 29: /* SUSP */ return suspend(input); return pour(verb, obj);
case 30: /* RESU */ return resume(input); case 13: /* EAT */
case 31: /* FLY */ return fly(verb, INTRANSITIVE); return eat(verb, INTRANSITIVE);
case 32: /* LISTE */ return listen(); case 14: /* DRINK */
case 33: /* ZZZZ */ return reservoir(); return drink(verb, obj);
case 15: /* RUB */
return GO_UNKNOWN;
case 16: /* TOSS */
return GO_UNKNOWN;
case 17: /* QUIT */
return quit(input);
case 18: /* FIND */
return GO_UNKNOWN;
case 19: /* INVEN */
return inven();
case 20: /* FEED */
return GO_UNKNOWN;
case 21: /* FILL */
return fill(verb, obj);
case 22: /* BLAST */
blast();
return GO_CLEAROBJ;
case 23: /* SCOR */
return vscore();
case 24: /* FOO */
return bigwords(WD1);
case 25: /* BRIEF */
return brief();
case 26: /* READ */
return read(input, verb, INTRANSITIVE);
case 27: /* BREAK */
return GO_UNKNOWN;
case 28: /* WAKE */
return GO_UNKNOWN;
case 29: /* SUSP */
return suspend(input);
case 30: /* RESU */
return resume(input);
case 31: /* FLY */
return fly(verb, INTRANSITIVE);
case 32: /* LISTE */
return listen();
case 33: /* ZZZZ */
return reservoir();
} }
BUG(23); BUG(23);
} }
@ -1102,40 +1155,95 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj)
case transitive: case transitive:
/* Analyse a transitive verb. */ /* Analyse a transitive verb. */
switch (verb - 1) { switch (verb - 1) {
case 0: /* CARRY */ return carry(verb, obj); case 0: /* CARRY */
case 1: /* DROP */ return discard(verb, obj, false); return carry(verb, obj);
case 2: /* SAY */ return say(); case 1: /* DROP */
case 3: /* UNLOC */ return lock(verb, obj); return discard(verb, obj, false);
case 4: /* NOTHI */ {RSPEAK(OK_MAN); return(GO_CLEAROBJ);} case 2: /* SAY */
case 5: /* LOCK */ return lock(verb, obj); return say();
case 6: /* LIGHT */ return light(verb, obj); case 3: /* UNLOC */
case 7: /* EXTI */ return extinguish(verb, obj); return lock(verb, obj);
case 8: /* WAVE */ return wave(verb, obj); case 4: { /* NOTHI */
case 9: /* CALM */ {RSPEAK(spk); return GO_CLEAROBJ;} RSPEAK(OK_MAN);
case 10: /* WALK */ {RSPEAK(spk); return GO_CLEAROBJ;} return (GO_CLEAROBJ);
case 11: /* ATTAC */ return attack(input, verb, obj); }
case 12: /* POUR */ return pour(verb, obj); case 5: /* LOCK */
case 13: /* EAT */ return eat(verb, obj); return lock(verb, obj);
case 14: /* DRINK */ return drink(verb, obj); case 6: /* LIGHT */
case 15: /* RUB */ return rub(verb, obj); return light(verb, obj);
case 16: /* TOSS */ return throw(input, verb, obj); case 7: /* EXTI */
case 17: /* QUIT */ {RSPEAK(spk); return GO_CLEAROBJ;} return extinguish(verb, obj);
case 18: /* FIND */ return find(verb, obj); case 8: /* WAVE */
case 19: /* INVEN */ return find(verb, obj); return wave(verb, obj);
case 20: /* FEED */ return feed(verb, obj); case 9: { /* CALM */
case 21: /* FILL */ return fill(verb, obj); RSPEAK(spk);
case 22: /* BLAST */ blast(); return GO_CLEAROBJ; return GO_CLEAROBJ;
case 23: /* SCOR */ {RSPEAK(spk); return GO_CLEAROBJ;} }
case 24: /* FOO */ {RSPEAK(spk); return GO_CLEAROBJ;} case 10: { /* WALK */
case 25: /* BRIEF */ {RSPEAK(spk); return GO_CLEAROBJ;} RSPEAK(spk);
case 26: /* READ */ return read(input, verb, obj); return GO_CLEAROBJ;
case 27: /* BREAK */ return vbreak(verb, obj); }
case 28: /* WAKE */ return wake(verb, obj); case 11: /* ATTAC */
case 29: /* SUSP */ {RSPEAK(spk); return GO_CLEAROBJ;} return attack(input, verb, obj);
case 30: /* RESU */ {RSPEAK(spk); return GO_CLEAROBJ;} case 12: /* POUR */
case 31: /* FLY */ return fly(verb, obj); return pour(verb, obj);
case 32: /* LISTE */ {RSPEAK(spk); return GO_CLEAROBJ;} case 13: /* EAT */
case 33: /* ZZZZ */ return reservoir(); return eat(verb, obj);
case 14: /* DRINK */
return drink(verb, obj);
case 15: /* RUB */
return rub(verb, obj);
case 16: /* TOSS */
return throw (input, verb, obj);
case 17: { /* QUIT */
RSPEAK(spk);
return GO_CLEAROBJ;
}
case 18: /* FIND */
return find(verb, obj);
case 19: /* INVEN */
return find(verb, obj);
case 20: /* FEED */
return feed(verb, obj);
case 21: /* FILL */
return fill(verb, obj);
case 22: /* BLAST */
blast();
return GO_CLEAROBJ;
case 23: { /* SCOR */
RSPEAK(spk);
return GO_CLEAROBJ;
}
case 24: { /* FOO */
RSPEAK(spk);
return GO_CLEAROBJ;
}
case 25: { /* BRIEF */
RSPEAK(spk);
return GO_CLEAROBJ;
}
case 26: /* READ */
return read(input, verb, obj);
case 27: /* BREAK */
return vbreak(verb, obj);
case 28: /* WAKE */
return wake(verb, obj);
case 29: { /* SUSP */
RSPEAK(spk);
return GO_CLEAROBJ;
}
case 30: { /* RESU */
RSPEAK(spk);
return GO_CLEAROBJ;
}
case 31: /* FLY */
return fly(verb, obj);
case 32: { /* LISTE */
RSPEAK(spk);
return GO_CLEAROBJ;
}
case 33: /* ZZZZ */
return reservoir();
} }
BUG(24); BUG(24);
case unknown: case unknown:

171
dungeon.c
View file

@ -114,7 +114,8 @@ static long GETTXT(long SKIP,long ONEWRD, long UPPER)
return (TEXT); return (TEXT);
} }
static void BUG(long NUM) { static void BUG(long NUM)
{
/* The following conditions are currently considered fatal bugs. Numbers < 20 /* The following conditions are currently considered fatal bugs. Numbers < 20
* are detected while reading the database; the others occur at "run time". * are detected while reading the database; the others occur at "run time".
@ -145,7 +146,8 @@ static void BUG(long NUM) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
static void MAPLIN(FILE *OPENED) { static void MAPLIN(FILE *OPENED)
{
/* Read a line of input, from the specified input source, /* Read a line of input, from the specified input source,
* translate the chars to integers in the range 0-126 and store * translate the chars to integers in the range 0-126 and store
* them in the common array "INLINE". Integer values are as follows: * them in the common array "INLINE". Integer values are as follows:
@ -175,12 +177,10 @@ static void MAPLIN(FILE *OPENED) {
if (NULL == fgets(INLINE + 1, sizeof(INLINE) - 1, OPENED)) { if (NULL == fgets(INLINE + 1, sizeof(INLINE) - 1, OPENED)) {
printf("Failed fgets()\n"); printf("Failed fgets()\n");
} }
} } while (!feof(OPENED) && INLINE[1] == '#');
while (!feof(OPENED) && INLINE[1] == '#');
LNLENG = 0; LNLENG = 0;
for (size_t i = 1; i < sizeof(INLINE) && INLINE[i] != 0; ++i) for (size_t i = 1; i < sizeof(INLINE) && INLINE[i] != 0; ++i) {
{
char val = INLINE[i]; char val = INLINE[i];
INLINE[i] = ascii_to_advent[(unsigned)val]; INLINE[i] = ascii_to_advent[(unsigned)val];
if (INLINE[i] != 0) if (INLINE[i] != 0)
@ -189,7 +189,8 @@ static void MAPLIN(FILE *OPENED) {
LNPOSN = 1; LNPOSN = 1;
} }
static long GETNUM(FILE *source) { static long GETNUM(FILE *source)
{
/* Obtain the next integer from an input line. If K>0, we first read a /* Obtain the next integer from an input line. If K>0, we first read a
* new input line from a file; if K<0, we read a line from the keyboard; * new input line from a file; if K<0, we read a line from the keyboard;
* if K=0 we use a line that has already been read (and perhaps partially * if K=0 we use a line that has already been read (and perhaps partially
@ -206,20 +207,15 @@ static long GETNUM(FILE *source) {
++LNPOSN; ++LNPOSN;
} }
if(INLINE[LNPOSN] != 9) if (INLINE[LNPOSN] != 9) {
{
SIGN = 1; SIGN = 1;
} } else {
else
{
SIGN = -1; SIGN = -1;
LNPOSN = LNPOSN + 1; LNPOSN = LNPOSN + 1;
} }
while (!(LNPOSN > LNLENG || INLINE[LNPOSN] == 0)) while (!(LNPOSN > LNLENG || INLINE[LNPOSN] == 0)) {
{
DIGIT = INLINE[LNPOSN] - 64; DIGIT = INLINE[LNPOSN] - 64;
if(DIGIT < 0 || DIGIT > 9) if (DIGIT < 0 || DIGIT > 9) {
{
GETNUM = 0; GETNUM = 0;
break; break;
} }
@ -236,8 +232,7 @@ static long GETNUM(FILE *source) {
static void read_messages(FILE* database, long sect) static void read_messages(FILE* database, long sect)
{ {
long KK = LINUSE; long KK = LINUSE;
while(true) while (true) {
{
long loc; long loc;
LINUSE = KK; LINUSE = KK;
loc = GETNUM(database); loc = GETNUM(database);
@ -248,42 +243,36 @@ static void read_messages(FILE* database, long sect)
KK = KK + 1; KK = KK + 1;
if (KK >= LINSIZ)BUG(2); if (KK >= LINSIZ)BUG(2);
LINES[KK] = GETTXT(false, false, false); LINES[KK] = GETTXT(false, false, false);
} } while (LINES[KK] != -1);
while(LINES[KK] != -1);
LINES[LINUSE] = KK; LINES[LINUSE] = KK;
if (loc == OLDLOC) continue; if (loc == OLDLOC) continue;
OLDLOC = loc; OLDLOC = loc;
LINES[LINUSE] = -KK; LINES[LINUSE] = -KK;
if(sect == 14) if (sect == 14) {
{
TRNVLS = TRNVLS + 1; TRNVLS = TRNVLS + 1;
if (TRNVLS > TRNSIZ)BUG(11); if (TRNVLS > TRNSIZ)BUG(11);
TTEXT[TRNVLS] = LINUSE; TTEXT[TRNVLS] = LINUSE;
TRNVAL[TRNVLS] = loc; TRNVAL[TRNVLS] = loc;
continue; continue;
} }
if(sect == 10) if (sect == 10) {
{
CLSSES = CLSSES + 1; CLSSES = CLSSES + 1;
if (CLSSES > CLSMAX)BUG(11); if (CLSSES > CLSMAX)BUG(11);
CTEXT[CLSSES] = LINUSE; CTEXT[CLSSES] = LINUSE;
CVAL[CLSSES] = loc; CVAL[CLSSES] = loc;
continue; continue;
} }
if(sect == 6) if (sect == 6) {
{
if (loc > RTXSIZ)BUG(6); if (loc > RTXSIZ)BUG(6);
RTEXT[loc] = LINUSE; RTEXT[loc] = LINUSE;
continue; continue;
} }
if(sect == 5) if (sect == 5) {
{
if (loc > 0 && loc <= NOBJECTS)PTEXT[loc] = LINUSE; if (loc > 0 && loc <= NOBJECTS)PTEXT[loc] = LINUSE;
continue; continue;
} }
if (loc > LOCSIZ)BUG(10); if (loc > LOCSIZ)BUG(10);
if(sect == 1) if (sect == 1) {
{
LTEXT[loc] = LINUSE; LTEXT[loc] = LINUSE;
continue; continue;
} }
@ -300,20 +289,15 @@ static void read_messages(FILE* database, long sect)
static void read_section3_stuff(FILE* database) static void read_section3_stuff(FILE* database)
{ {
long loc; long loc;
while((loc=GETNUM(database)) != -1) while ((loc = GETNUM(database)) != -1) {
{
long newloc = GETNUM(NULL); long newloc = GETNUM(NULL);
long L; long L;
if(KEY[loc] == 0) if (KEY[loc] == 0) {
{
KEY[loc] = TRVS; KEY[loc] = TRVS;
} } else {
else
{
TRAVEL[TRVS - 1] = -TRAVEL[TRVS - 1]; TRAVEL[TRVS - 1] = -TRAVEL[TRVS - 1];
} }
while((L=GETNUM(NULL)) != 0) while ((L = GETNUM(NULL)) != 0) {
{
TRAVEL[TRVS] = newloc * 1000 + L; TRAVEL[TRVS] = newloc * 1000 + L;
TRVS = TRVS + 1; TRVS = TRVS + 1;
if (TRVS == TRVSIZ)BUG(3); if (TRVS == TRVSIZ)BUG(3);
@ -327,8 +311,7 @@ static void read_section3_stuff(FILE* database)
* as an end-marker. */ * as an end-marker. */
static void read_vocabulary(FILE* database) static void read_vocabulary(FILE* database)
{ {
for (TABNDX=1; TABNDX<=TABSIZ; TABNDX++) for (TABNDX = 1; TABNDX <= TABSIZ; TABNDX++) {
{
KTAB[TABNDX] = GETNUM(database); KTAB[TABNDX] = GETNUM(database);
if (KTAB[TABNDX] == -1) return; if (KTAB[TABNDX] == -1) return;
ATAB[TABNDX] = GETTXT(true, true, true); ATAB[TABNDX] = GETTXT(true, true, true);
@ -342,8 +325,7 @@ static void read_vocabulary(FILE* database)
static void read_initial_locations(FILE* database) static void read_initial_locations(FILE* database)
{ {
long OBJ; long OBJ;
while((OBJ=GETNUM(database)) != -1) while ((OBJ = GETNUM(database)) != -1) {
{
PLAC[OBJ] = GETNUM(NULL); PLAC[OBJ] = GETNUM(NULL);
FIXD[OBJ] = GETNUM(NULL); FIXD[OBJ] = GETNUM(NULL);
} }
@ -353,8 +335,7 @@ static void read_initial_locations(FILE* database)
static void read_action_verb_message_nr(FILE* database) static void read_action_verb_message_nr(FILE* database)
{ {
long verb; long verb;
while((verb=GETNUM(database)) != -1) while ((verb = GETNUM(database)) != -1) {
{
ACTSPK[verb] = GETNUM(NULL); ACTSPK[verb] = GETNUM(NULL);
} }
} }
@ -363,11 +344,9 @@ static void read_action_verb_message_nr(FILE* database)
static void read_conditions(FILE* database) static void read_conditions(FILE* database)
{ {
long K; long K;
while((K=GETNUM(database)) != -1) while ((K = GETNUM(database)) != -1) {
{
long loc; long loc;
while((loc=GETNUM(NULL)) != 0) while ((loc = GETNUM(NULL)) != 0) {
{
if (is_set(COND[loc], K)) BUG(8); if (is_set(COND[loc], K)) BUG(8);
COND[loc] = COND[loc] + (1l << K); COND[loc] = COND[loc] + (1l << K);
} }
@ -380,11 +359,9 @@ static void read_hints(FILE* database)
{ {
long K; long K;
HNTMAX = 0; HNTMAX = 0;
while((K=GETNUM(database)) != -1) while ((K = GETNUM(database)) != -1) {
{
if (K <= 0 || K > HNTSIZ)BUG(7); if (K <= 0 || K > HNTSIZ)BUG(7);
for (int I=1; I<=4; I++) for (int I = 1; I <= 4; I++) {
{
HINTS[K][I] = GETNUM(NULL); HINTS[K][I] = GETNUM(NULL);
} /* end loop */ } /* end loop */
HNTMAX = (HNTMAX > K ? HNTMAX : K); HNTMAX = (HNTMAX > K ? HNTMAX : K);
@ -395,12 +372,10 @@ static void read_hints(FILE* database)
static void read_sound_text(FILE* database) static void read_sound_text(FILE* database)
{ {
long K; long K;
while((K=GETNUM(database)) != -1) while ((K = GETNUM(database)) != -1) {
{
long KK = GETNUM(NULL); long KK = GETNUM(NULL);
long I = GETNUM(NULL); long I = GETNUM(NULL);
if(I != 0) if (I != 0) {
{
OBJSND[K] = (KK > 0 ? KK : 0); OBJSND[K] = (KK > 0 ? KK : 0);
OBJTXT[K] = (I > 0 ? I : 0); OBJTXT[K] = (I > 0 ? I : 0);
continue; continue;
@ -411,7 +386,8 @@ static void read_sound_text(FILE* database)
} }
static int read_database(FILE* database) { static int read_database(FILE* database)
{
/* Clear out the various text-pointer arrays. All text is stored in array /* Clear out the various text-pointer arrays. All text is stored in array
* lines; each line is preceded by a word pointing to the next pointer (i.e. * lines; each line is preceded by a word pointing to the next pointer (i.e.
@ -449,28 +425,55 @@ static int read_database(FILE* database) {
/* Start new data section. Sect is the section number. */ /* Start new data section. Sect is the section number. */
while(true) while (true) {
{
long sect = GETNUM(database); long sect = GETNUM(database);
OLDLOC = -1; OLDLOC = -1;
switch (sect) switch (sect) {
{ case 0:
case 0: return(0); return (0);
case 1: read_messages(database, sect); break; case 1:
case 2: read_messages(database, sect); break; read_messages(database, sect);
case 3: read_section3_stuff(database); break; break;
case 4: read_vocabulary(database); break; case 2:
case 5: read_messages(database, sect); break; read_messages(database, sect);
case 6: read_messages(database, sect); break; break;
case 7: read_initial_locations(database); break; case 3:
case 8: read_action_verb_message_nr(database); break; read_section3_stuff(database);
case 9: read_conditions(database); break; break;
case 10: read_messages(database, sect); break; case 4:
case 11: read_hints(database); break; read_vocabulary(database);
case 12: break; break;
case 13: read_sound_text(database); break; case 5:
case 14: read_messages(database, sect); break; read_messages(database, sect);
default: BUG(9); break;
case 6:
read_messages(database, sect);
break;
case 7:
read_initial_locations(database);
break;
case 8:
read_action_verb_message_nr(database);
break;
case 9:
read_conditions(database);
break;
case 10:
read_messages(database, sect);
break;
case 11:
read_hints(database);
break;
case 12:
break;
case 13:
read_sound_text(database);
break;
case 14:
read_messages(database, sect);
break;
default:
BUG(9);
} }
} }
} }
@ -495,10 +498,8 @@ static void write_0d(FILE* header_file, long single, const char* varname)
static void write_1d(FILE* header_file, long array[], long dim, const char* varname) static void write_1d(FILE* header_file, long array[], long dim, const char* varname)
{ {
fprintf(header_file, "LOCATION long %s[] INITIALIZE(= {\n", varname); fprintf(header_file, "LOCATION long %s[] INITIALIZE(= {\n", varname);
for (int i = 0; i < dim; ++i) for (int i = 0; i < dim; ++i) {
{ if (i % 10 == 0) {
if (i % 10 == 0)
{
if (i > 0) if (i > 0)
fprintf(header_file, "\n"); fprintf(header_file, "\n");
fprintf(header_file, " "); fprintf(header_file, " ");
@ -511,11 +512,9 @@ static void write_1d(FILE* header_file, long array[], long dim, const char* varn
static void write_hints(FILE* header_file, long matrix[][HINTLEN], long dim1, long dim2, const char* varname) static void write_hints(FILE* header_file, long matrix[][HINTLEN], long dim1, long dim2, const char* varname)
{ {
fprintf(header_file, "LOCATION long %s[][%ld] INITIALIZE(= {\n", varname, dim2); fprintf(header_file, "LOCATION long %s[][%ld] INITIALIZE(= {\n", varname, dim2);
for (int i = 0; i < dim1; ++i) for (int i = 0; i < dim1; ++i) {
{
fprintf(header_file, " {"); fprintf(header_file, " {");
for (int j = 0; j < dim2; ++j) for (int j = 0; j < dim2; ++j) {
{
fprintf(header_file, "%ld, ", matrix[i][j]); fprintf(header_file, "%ld, ", matrix[i][j]);
} }
fprintf(header_file, "},\n"); fprintf(header_file, "},\n");

65
main.c
View file

@ -185,12 +185,10 @@ static void checkhints(FILE *cmdin)
++game.hintlc[hint]; ++game.hintlc[hint];
/* Come here if he's been long enough at required loc(s) for some /* Come here if he's been long enough at required loc(s) for some
* unused hint. */ * unused hint. */
if (game.hintlc[hint] >= HINTS[hint][1]) if (game.hintlc[hint] >= HINTS[hint][1]) {
{
int i; int i;
switch (hint-1) switch (hint - 1) {
{
case 0: case 0:
/* cave */ /* cave */
if (game.prop[GRATE] == 0 && !HERE(KEYS)) if (game.prop[GRATE] == 0 && !HERE(KEYS))
@ -561,8 +559,7 @@ static bool playermove(FILE *cmdin, token_t verb, int motion)
RSPEAK(k2); RSPEAK(k2);
return true; return true;
} }
} } else if (motion == LOOK) {
else if (motion == LOOK) {
/* Look. Can't give more detail. Pretend it wasn't dark /* Look. Can't give more detail. Pretend it wasn't dark
* (though it may now be dark) so he won't fall into a * (though it may now be dark) so he won't fall into a
* pit while staring into the gloom. */ * pit while staring into the gloom. */
@ -572,13 +569,11 @@ static bool playermove(FILE *cmdin, token_t verb, int motion)
game.wzdark = false; game.wzdark = false;
game.abbrev[game.loc] = 0; game.abbrev[game.loc] = 0;
return true; return true;
} } else if (motion == CAVE) {
else if (motion == CAVE) {
/* Cave. Different messages depending on whether above ground. */ /* Cave. Different messages depending on whether above ground. */
RSPEAK((OUTSID(game.loc) && game.loc != LOC_GRATE) ? FOLLOW_STREAM : NEED_DETAIL); RSPEAK((OUTSID(game.loc) && game.loc != LOC_GRATE) ? FOLLOW_STREAM : NEED_DETAIL);
return true; return true;
} } else {
else {
/* none of the specials */ /* none of the specials */
game.oldlc2 = game.oldloc; game.oldlc2 = game.oldloc;
game.oldloc = game.loc; game.oldloc = game.loc;
@ -623,11 +618,11 @@ static bool playermove(FILE *cmdin, token_t verb, int motion)
if (game.newloc == 0 || PCT(game.newloc)) if (game.newloc == 0 || PCT(game.newloc))
break; break;
/* else fall through */ /* else fall through */
} if (TOTING(motion) || (game.newloc > 200 && AT(motion))) }
if (TOTING(motion) || (game.newloc > 200 && AT(motion)))
break; break;
/* else fall through */ /* else fall through */
} } else if (game.prop[motion] != game.newloc / 100 - 3)
else if (game.prop[motion] != game.newloc/100-3)
break; break;
do { do {
if (TRAVEL[kk] < 0)BUG(25); if (TRAVEL[kk] < 0)BUG(25);
@ -643,8 +638,7 @@ static bool playermove(FILE *cmdin, token_t verb, int motion)
return true; return true;
if (game.newloc <= 500) { if (game.newloc <= 500) {
game.newloc = game.newloc - SPECIALBASE; game.newloc = game.newloc - SPECIALBASE;
switch (game.newloc) switch (game.newloc) {
{
case 1: case 1:
/* Travel 301. Plover-alcove passage. Can carry only /* Travel 301. Plover-alcove passage. Can carry only
* emerald. Note: travel table must include "useless" * emerald. Note: travel table must include "useless"
@ -750,8 +744,7 @@ static bool closecheck(void)
* can refer to it. Also also, he's gotten the pearl, so we * can refer to it. Also also, he's gotten the pearl, so we
* know the bivalve is an oyster. *And*, the dwarves must * know the bivalve is an oyster. *And*, the dwarves must
* have been activated, since we've found chest. */ * have been activated, since we've found chest. */
if (game.clock1 == 0) if (game.clock1 == 0) {
{
game.prop[GRATE] = 0; game.prop[GRATE] = 0;
game.prop[FISSUR] = 0; game.prop[FISSUR] = 0;
for (int i = 1; i <= NDWARVES; i++) { for (int i = 1; i <= NDWARVES; i++) {
@ -840,8 +833,7 @@ static void lampcheck(void)
* Second is for other cases of lamp dying. 12400 is when it * Second is for other cases of lamp dying. 12400 is when it
* goes out. Even then, he can explore outside for a while * goes out. Even then, he can explore outside for a while
* if desired. */ * if desired. */
if (game.limit <= WARNTIME && HERE(BATTER) && game.prop[BATTER]==0 && HERE(LAMP)) if (game.limit <= WARNTIME && HERE(BATTER) && game.prop[BATTER] == 0 && HERE(LAMP)) {
{
RSPEAK(REPLACE_BATTERIES); RSPEAK(REPLACE_BATTERIES);
game.prop[BATTER] = 1; game.prop[BATTER] = 1;
if (TOTING(BATTER)) if (TOTING(BATTER))
@ -1075,17 +1067,25 @@ static bool do_command(FILE *cmdin)
goto L2600; goto L2600;
} }
kmod = MOD(defn, 1000); kmod = MOD(defn, 1000);
switch (defn/1000) switch (defn / 1000) {
{
case 0: case 0:
if (playermove(cmdin, verb, kmod)) if (playermove(cmdin, verb, kmod))
return true; return true;
else else
continue; /* back to top of main interpreter loop */ continue; /* back to top of main interpreter loop */
case 1: part=unknown; obj = kmod; break; case 1:
case 2: part=intransitive; verb = kmod; break; part = unknown;
case 3: RSPEAK(kmod); goto L2012; obj = kmod;
default: BUG(22); break;
case 2:
part = intransitive;
verb = kmod;
break;
case 3:
RSPEAK(kmod);
goto L2012;
default:
BUG(22);
} }
Laction: Laction:
@ -1095,11 +1095,16 @@ static bool do_command(FILE *cmdin)
case GO_MOVE: case GO_MOVE:
playermove(cmdin, verb, NUL); playermove(cmdin, verb, NUL);
return true; return true;
case GO_TOP: continue; /* back to top of main interpreter loop */ case GO_TOP:
case GO_CLEAROBJ: goto L2012; continue; /* back to top of main interpreter loop */
case GO_CHECKHINT: goto L2600; case GO_CLEAROBJ:
case GO_CHECKFOO: goto L2607; goto L2012;
case GO_LOOKUP: goto Lookup; case GO_CHECKHINT:
goto L2600;
case GO_CHECKFOO:
goto L2607;
case GO_LOOKUP:
goto Lookup;
case GO_WORD2: case GO_WORD2:
/* Get second word for analysis. */ /* Get second word for analysis. */
WD1 = WD2; WD1 = WD2;

52
misc.c
View file

@ -13,8 +13,7 @@
char* xstrdup(const char* s) char* xstrdup(const char* s)
{ {
char* ptr = strdup(s); char* ptr = strdup(s);
if (ptr == NULL) if (ptr == NULL) {
{
fprintf(stderr, "Out of memory!\n"); fprintf(stderr, "Out of memory!\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -24,8 +23,7 @@ char* xstrdup(const char* s)
void packed_to_token(long packed, char token[6]) void packed_to_token(long packed, char token[6])
{ {
// Unpack and map back to ASCII. // Unpack and map back to ASCII.
for (int i = 0; i < 5; ++i) for (int i = 0; i < 5; ++i) {
{
char advent = (packed >> i * 6) & 63; char advent = (packed >> i * 6) & 63;
token[4 - i] = advent_to_ascii[(int) advent]; token[4 - i] = advent_to_ascii[(int) advent];
} }
@ -34,8 +32,7 @@ void packed_to_token(long packed, char token[6])
token[5] = '\0'; token[5] = '\0';
// Replace trailing whitespace with \0. // Replace trailing whitespace with \0.
for (int i = 4; i >= 0; --i) for (int i = 4; i >= 0; --i) {
{
if (token[i] == ' ' || token[i] == '\t') if (token[i] == ' ' || token[i] == '\t')
token[i] = '\0'; token[i] = '\0';
else else
@ -67,57 +64,45 @@ void newspeak(const char* msg)
// Handle format specifiers (including the custom %C, %L, %S) by adjusting the parameter accordingly, and replacing the specifier with %s. // Handle format specifiers (including the custom %C, %L, %S) by adjusting the parameter accordingly, and replacing the specifier with %s.
int pi = 0; // parameter index int pi = 0; // parameter index
for (int i = 0; i < (int)strlen(msg); ++i) for (int i = 0; i < (int)strlen(msg); ++i) {
{ if (msg[i] == '%') {
if (msg[i] == '%')
{
++pi; ++pi;
// Integer specifier. In order to accommodate the fact that PARMS can have both legitimate integers *and* packed tokens, stringify everything. Future work may eliminate the need for this. // Integer specifier. In order to accommodate the fact that PARMS can have both legitimate integers *and* packed tokens, stringify everything. Future work may eliminate the need for this.
if (msg[i + 1] == 'd') if (msg[i + 1] == 'd') {
{
copy[i + 1] = 's'; copy[i + 1] = 's';
sprintf(parameters[pi], "%ld", PARMS[pi]); sprintf(parameters[pi], "%ld", PARMS[pi]);
} }
// Unmodified string specifier. // Unmodified string specifier.
if (msg[i + 1] == 's') if (msg[i + 1] == 's') {
{
packed_to_token(PARMS[pi], parameters[pi]); packed_to_token(PARMS[pi], parameters[pi]);
} }
// Singular/plural specifier. // Singular/plural specifier.
if (msg[i + 1] == 'S') if (msg[i + 1] == 'S') {
{
copy[i + 1] = 's'; copy[i + 1] = 's';
if (PARMS[pi - 1] > 1) // look at the *previous* parameter (which by necessity must be numeric) if (PARMS[pi - 1] > 1) { // look at the *previous* parameter (which by necessity must be numeric)
{
sprintf(parameters[pi], "%s", "s"); sprintf(parameters[pi], "%s", "s");
} } else {
else
{
sprintf(parameters[pi], "%s", ""); sprintf(parameters[pi], "%s", "");
} }
} }
// All-lowercase specifier. // All-lowercase specifier.
if (msg[i + 1] == 'L') if (msg[i + 1] == 'L') {
{
copy[i + 1] = 's'; copy[i + 1] = 's';
packed_to_token(PARMS[pi], parameters[pi]); packed_to_token(PARMS[pi], parameters[pi]);
for (int j = 0; j < (int)strlen(parameters[pi]); ++j) for (int j = 0; j < (int)strlen(parameters[pi]); ++j) {
{
parameters[pi][j] = tolower(parameters[pi][j]); parameters[pi][j] = tolower(parameters[pi][j]);
} }
} }
// First char uppercase, rest lowercase. // First char uppercase, rest lowercase.
if (msg[i + 1] == 'C') if (msg[i + 1] == 'C') {
{
copy[i + 1] = 's'; copy[i + 1] = 's';
packed_to_token(PARMS[pi], parameters[pi]); packed_to_token(PARMS[pi], parameters[pi]);
for (int j = 0; j < (int)strlen(parameters[pi]); ++j) for (int j = 0; j < (int)strlen(parameters[pi]); ++j) {
{
parameters[pi][j] = tolower(parameters[pi][j]); parameters[pi][j] = tolower(parameters[pi][j]);
} }
parameters[pi][0] = toupper(parameters[pi][0]); parameters[pi][0] = toupper(parameters[pi][0]);
@ -404,8 +389,7 @@ void DROP(long object, long where)
{ {
if (object > NOBJECTS) if (object > NOBJECTS)
game.fixed[object - NOBJECTS] = where; game.fixed[object - NOBJECTS] = where;
else else {
{
if (game.place[object] == CARRIED) if (game.place[object] == CARRIED)
--game.holdng; --game.holdng;
game.place[object] = where; game.place[object] = where;
@ -490,8 +474,7 @@ long RNDVOC(long second, long force)
long div = 64L * 64L * 64L; long div = 64L * 64L * 64L;
for (int i = 1; i <= TABSIZ; i++) { for (int i = 1; i <= TABSIZ; i++) {
if (MOD(ATAB[i]/div, 64L) == second) if (MOD(ATAB[i] / div, 64L) == second) {
{
ATAB[i] = rnd; ATAB[i] = rnd;
break; break;
} }
@ -586,8 +569,7 @@ bool MAPLIN(FILE *fp)
efp = logfp; efp = logfp;
else if (!isatty(0)) else if (!isatty(0))
efp = stdout; efp = stdout;
if (efp != NULL) if (efp != NULL) {
{
if (prompt && efp == stdout) if (prompt && efp == stdout)
fputs("> ", efp); fputs("> ", efp);
IGNORE(fputs(rawbuf, efp)); IGNORE(fputs(rawbuf, efp));

View file

@ -31,7 +31,8 @@ struct save_t save;
/* Suspend and resume */ /* Suspend and resume */
int suspend(FILE *input) int suspend(FILE *input)
{ /* Suspend. Offer to save things in a file, but charging {
/* Suspend. Offer to save things in a file, but charging
* some points (so can't win by using saved games to retry * some points (so can't win by using saved games to retry
* battles or to start over after learning zzword). * battles or to start over after learning zzword).
* If ADVENT_NOSAVE is defined, do nothing instead. */ * If ADVENT_NOSAVE is defined, do nothing instead. */
@ -71,7 +72,8 @@ int suspend(FILE *input)
} }
int resume(FILE *input) int resume(FILE *input)
{ /* Resume. Read a suspended game back from a file. {
/* Resume. Read a suspended game back from a file.
* If ADVENT_NOSAVE is defined, do nothing instead. */ * If ADVENT_NOSAVE is defined, do nothing instead. */
#ifdef ADVENT_NOSAVE #ifdef ADVENT_NOSAVE
@ -98,7 +100,8 @@ int resume(FILE *input)
} }
int restore(FILE* fp) int restore(FILE* fp)
{ /* Read and restore game state from file, assuming {
/* Read and restore game state from file, assuming
* sane initial state. * sane initial state.
* If ADVENT_NOSAVE is defined, do nothing instead. */ * If ADVENT_NOSAVE is defined, do nothing instead. */
#ifdef ADVENT_NOSAVE #ifdef ADVENT_NOSAVE