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) {
spk = UNHAPPY_BIRD;
if (game.closed)
{
if (game.closed) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
DESTROY(BIRD);
game.prop[BIRD] = 0;
spk = BIRD_DEAD;
}
else if (obj == VEND) {
} else if (obj == VEND) {
PSPEAK(VEND, game.prop[VEND] + 2);
game.prop[VEND] = 3 - game.prop[VEND];
return GO_CLEAROBJ;
@ -80,8 +78,7 @@ static int attack(FILE *input, long verb, token_t obj)
}
}
spk = (dwarves > 1) ? OGRE_PANIC1 : OGRE_PANIC2;
}
else if (obj == BEAR)
} else if (obj == BEAR)
/* FIXME: Arithmetic on message numbers */
spk = BEAR_HANDS + (game.prop[BEAR] + 1) / 2;
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];
}
if (TOTING(obj)) {RSPEAK(ALREADY_CARRYING); return GO_CLEAROBJ;}
if (TOTING(obj)) {
RSPEAK(ALREADY_CARRYING);
return GO_CLEAROBJ;
}
spk = YOU_JOKING;
if (obj == PLANT && game.prop[PLANT] <= 0)spk = DEEP_ROOTS;
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) {
RSPEAK(spk);
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) {
DESTROY(BIRD);
RSPEAK(BIRD_CRAP);
@ -301,7 +300,10 @@ static int chain(token_t verb)
spk = CHAIN_UNLOCKED;
if (game.prop[BEAR] == 0)spk = BEAR_BLOCKS;
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.fixed[CHAIN] = 0;
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];
if (!just_do_it) {
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)) {
RSPEAK(BIRD_ATTACKS);
if (game.closed) return GO_DWARFWAKE;
@ -454,13 +459,11 @@ static int extinguish(token_t verb, int obj)
if (obj == URN) {
game.prop[URN] = game.prop[URN] / 2;
spk = URN_DARK;
}
else if (obj == LAMP) {
} else if (obj == LAMP) {
game.prop[LAMP] = 0;
RSPEAK(LAMP_OFF);
spk = DARK(game.loc) ? PITCH_DARK : NO_MESSAGE;
}
else if (obj == DRAGON || obj == VOLCAN)
} else if (obj == DRAGON || obj == VOLCAN)
spk = BEYOND_POWER;
RSPEAK(spk);
return GO_CLEAROBJ;
@ -474,8 +477,7 @@ static int feed(token_t verb, token_t obj)
if (obj == BIRD) {
RSPEAK(BIRD_PINING);
return GO_CLEAROBJ;
}
else if (obj == SNAKE || obj == DRAGON || obj == TROLL) {
} else if (obj == SNAKE || obj == DRAGON || obj == TROLL) {
spk = NOTHING_EDIBLE;
if (obj == DRAGON && game.prop[DRAGON] != 0)spk = RIDICULOUS_ATTEMPT;
if (obj == TROLL)spk = TROLL_VICES;
@ -484,14 +486,12 @@ static int feed(token_t verb, token_t obj)
game.prop[BIRD] = 0;
spk = BIRD_DEVOURED;
}
}
else if (obj == DWARF) {
} else if (obj == DWARF) {
if (HERE(FOOD)) {
game.dflag += 2;
spk = REALLY_MAD;
}
}
else if (obj == BEAR) {
} else if (obj == BEAR) {
if (game.prop[BEAR] == 0)spk = NOTHING_EDIBLE;
if (game.prop[BEAR] == 3)spk = RIDICULOUS_ATTEMPT;
if (HERE(FOOD)) {
@ -501,8 +501,7 @@ static int feed(token_t verb, token_t obj)
game.prop[AXE] = 0;
spk = BEAR_TAMED;
}
}
else if (obj == OGRE) {
} else if (obj == OGRE) {
if (HERE(FOOD))
spk = OGRE_FULL;
} else {
@ -529,25 +528,28 @@ int fill(token_t verb, token_t obj)
game.prop[VASE] = 2;
game.fixed[VASE] = -1;
return (discard(verb, obj, true));
}
else if (obj == URN) {
} else if (obj == 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;
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.prop[BOTTLE] = 1;
if (k == OIL)game.prop[URN] = 1;
spk = WATER_URN + game.prop[URN];
RSPEAK(spk);
return GO_CLEAROBJ;
}
else if (obj != 0 && obj != BOTTLE) {
} else if (obj != 0 && obj != BOTTLE) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
else if (obj == 0 && !HERE(BOTTLE))
} else if (obj == 0 && !HERE(BOTTLE))
return GO_UNKNOWN;
spk = BOTTLED_WATER;
if (LIQLOC(game.loc) == 0)
@ -602,7 +604,10 @@ static int fly(token_t verb, token_t obj)
return GO_CLEAROBJ;
}
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.oldloc = 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;
} else {
if (obj != LAMP)
{
if (obj != LAMP) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
@ -707,7 +711,10 @@ static int lock(token_t verb, token_t obj)
if (AT(GRATE))obj = GRATE;
if (obj != 0 && HERE(CHAIN)) return GO_UNKNOWN;
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
@ -746,19 +753,30 @@ static int pour(token_t verb, token_t obj)
int spk = ACTSPK[verb];
if (obj == BOTTLE || obj == 0)obj = LIQUID();
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;
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)
return fill(verb, URN);
game.prop[BOTTLE] = 1;
game.place[obj] = NOWHERE;
spk = GROUND_WET;
if (!(AT(PLANT) || AT(DOOR)))
{RSPEAK(spk); return GO_CLEAROBJ;}
if (!(AT(PLANT) || AT(DOOR))) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
if (!AT(DOOR)) {
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);
game.prop[PLANT] = MOD(game.prop[PLANT] + 1, 3);
game.prop[PLANT2] = game.prop[PLANT];
@ -982,7 +1000,10 @@ static int wave(token_t verb, token_t obj)
RSPEAK(spk);
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);
game.prop[FISSUR] = 1 - 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];
if (part == unknown)
{
if (part == unknown) {
/* Analyse an object word. See if the thing is here, whether
* we've got a verb yet, and so on. Object must be here
* 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;
if (obj != GRATE)
return GO_MOVE;
}
else if (obj == DWARF && ATDWRF(game.loc) > 0)
} else if (obj == DWARF && ATDWRF(game.loc) > 0)
/* FALL THROUGH */;
else if ((LIQUID() == obj && HERE(BOTTLE)) || obj == LIQLOC(game.loc))
/* FALL THROUGH */;
else if (obj == OIL && HERE(URN) && game.prop[URN] != 0) {
obj = URN;
/* FALL THROUGH */;
}
else if (obj == PLANT && AT(PLANT2) && game.prop[PLANT2] != 0) {
} else if (obj == PLANT && AT(PLANT2) && game.prop[PLANT2] != 0) {
obj = PLANT2;
/* FALL THROUGH */;
}
else if (obj == KNIFE && game.knfloc == game.loc) {
} else if (obj == KNIFE && game.knfloc == game.loc) {
game.knfloc = -1;
spk = KNIVES_VANISH;
RSPEAK(spk);
return GO_CLEAROBJ;
}
else if (obj == ROD && HERE(ROD2)) {
} else if (obj == ROD && HERE(ROD2)) {
obj = ROD2;
/* FALL THROUGH */;
}
else if ((verb == FIND || verb == INVENT) && WD2 <= 0)
} else if ((verb == FIND || verb == INVENT) && WD2 <= 0)
/* FALL THROUGH */;
else {
SETPRM(1, WD1, WD1X);
@ -1053,48 +1068,86 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj)
part = transitive;
}
switch(part)
{
switch (part) {
case intransitive:
if (WD2 > 0 && verb != SAY) return (2800);
if (verb == SAY)obj = WD2;
if (obj == 0 || obj == INTRANSITIVE) {
/* Analyse an intransitive verb (ie, no object given yet). */
switch (verb - 1) {
case 0: /* CARRY */ return carry(verb, INTRANSITIVE);
case 1: /* DROP */ return GO_UNKNOWN;
case 2: /* SAY */ return GO_UNKNOWN;
case 3: /* UNLOC */ return lock(verb, INTRANSITIVE);
case 4: /* NOTHI */ {RSPEAK(OK_MAN); return(GO_CLEAROBJ);}
case 5: /* LOCK */ return lock(verb, INTRANSITIVE);
case 6: /* LIGHT */ return light(verb, INTRANSITIVE);
case 7: /* EXTIN */ return extinguish(verb, INTRANSITIVE);
case 8: /* WAVE */ return GO_UNKNOWN;
case 9: /* CALM */ return GO_UNKNOWN;
case 10: /* WALK */ {RSPEAK(spk); return GO_CLEAROBJ;}
case 11: /* ATTAC */ return attack(input, verb, obj);
case 12: /* POUR */ return pour(verb, obj);
case 13: /* EAT */ return eat(verb, INTRANSITIVE);
case 14: /* DRINK */ 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();
case 0: /* CARRY */
return carry(verb, INTRANSITIVE);
case 1: /* DROP */
return GO_UNKNOWN;
case 2: /* SAY */
return GO_UNKNOWN;
case 3: /* UNLOC */
return lock(verb, INTRANSITIVE);
case 4: { /* NOTHI */
RSPEAK(OK_MAN);
return (GO_CLEAROBJ);
}
case 5: /* LOCK */
return lock(verb, INTRANSITIVE);
case 6: /* LIGHT */
return light(verb, INTRANSITIVE);
case 7: /* EXTIN */
return extinguish(verb, INTRANSITIVE);
case 8: /* WAVE */
return GO_UNKNOWN;
case 9: /* CALM */
return GO_UNKNOWN;
case 10: { /* WALK */
RSPEAK(spk);
return GO_CLEAROBJ;
}
case 11: /* ATTAC */
return attack(input, verb, obj);
case 12: /* POUR */
return pour(verb, obj);
case 13: /* EAT */
return eat(verb, INTRANSITIVE);
case 14: /* DRINK */
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);
}
@ -1102,40 +1155,95 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj)
case transitive:
/* Analyse a transitive verb. */
switch (verb - 1) {
case 0: /* CARRY */ return carry(verb, obj);
case 1: /* DROP */ return discard(verb, obj, false);
case 2: /* SAY */ return say();
case 3: /* UNLOC */ return lock(verb, obj);
case 4: /* NOTHI */ {RSPEAK(OK_MAN); return(GO_CLEAROBJ);}
case 5: /* LOCK */ return lock(verb, obj);
case 6: /* LIGHT */ return light(verb, obj);
case 7: /* EXTI */ return extinguish(verb, obj);
case 8: /* WAVE */ return wave(verb, obj);
case 9: /* CALM */ {RSPEAK(spk); return GO_CLEAROBJ;}
case 10: /* WALK */ {RSPEAK(spk); return GO_CLEAROBJ;}
case 11: /* ATTAC */ return attack(input, verb, obj);
case 12: /* POUR */ return pour(verb, obj);
case 13: /* EAT */ 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();
case 0: /* CARRY */
return carry(verb, obj);
case 1: /* DROP */
return discard(verb, obj, false);
case 2: /* SAY */
return say();
case 3: /* UNLOC */
return lock(verb, obj);
case 4: { /* NOTHI */
RSPEAK(OK_MAN);
return (GO_CLEAROBJ);
}
case 5: /* LOCK */
return lock(verb, obj);
case 6: /* LIGHT */
return light(verb, obj);
case 7: /* EXTI */
return extinguish(verb, obj);
case 8: /* WAVE */
return wave(verb, obj);
case 9: { /* CALM */
RSPEAK(spk);
return GO_CLEAROBJ;
}
case 10: { /* WALK */
RSPEAK(spk);
return GO_CLEAROBJ;
}
case 11: /* ATTAC */
return attack(input, verb, obj);
case 12: /* POUR */
return pour(verb, obj);
case 13: /* EAT */
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);
case unknown:

171
dungeon.c
View file

@ -114,7 +114,8 @@ static long GETTXT(long SKIP,long ONEWRD, long UPPER)
return (TEXT);
}
static void BUG(long NUM) {
static void BUG(long NUM)
{
/* The following conditions are currently considered fatal bugs. Numbers < 20
* are detected while reading the database; the others occur at "run time".
@ -145,7 +146,8 @@ static void BUG(long NUM) {
exit(EXIT_FAILURE);
}
static void MAPLIN(FILE *OPENED) {
static void MAPLIN(FILE *OPENED)
{
/* Read a line of input, from the specified input source,
* translate the chars to integers in the range 0-126 and store
* 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)) {
printf("Failed fgets()\n");
}
}
while (!feof(OPENED) && INLINE[1] == '#');
} while (!feof(OPENED) && INLINE[1] == '#');
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];
INLINE[i] = ascii_to_advent[(unsigned)val];
if (INLINE[i] != 0)
@ -189,7 +189,8 @@ static void MAPLIN(FILE *OPENED) {
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
* 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
@ -206,20 +207,15 @@ static long GETNUM(FILE *source) {
++LNPOSN;
}
if(INLINE[LNPOSN] != 9)
{
if (INLINE[LNPOSN] != 9) {
SIGN = 1;
}
else
{
} else {
SIGN = -1;
LNPOSN = LNPOSN + 1;
}
while (!(LNPOSN > LNLENG || INLINE[LNPOSN] == 0))
{
while (!(LNPOSN > LNLENG || INLINE[LNPOSN] == 0)) {
DIGIT = INLINE[LNPOSN] - 64;
if(DIGIT < 0 || DIGIT > 9)
{
if (DIGIT < 0 || DIGIT > 9) {
GETNUM = 0;
break;
}
@ -236,8 +232,7 @@ static long GETNUM(FILE *source) {
static void read_messages(FILE* database, long sect)
{
long KK = LINUSE;
while(true)
{
while (true) {
long loc;
LINUSE = KK;
loc = GETNUM(database);
@ -248,42 +243,36 @@ static void read_messages(FILE* database, long sect)
KK = KK + 1;
if (KK >= LINSIZ)BUG(2);
LINES[KK] = GETTXT(false, false, false);
}
while(LINES[KK] != -1);
} while (LINES[KK] != -1);
LINES[LINUSE] = KK;
if (loc == OLDLOC) continue;
OLDLOC = loc;
LINES[LINUSE] = -KK;
if(sect == 14)
{
if (sect == 14) {
TRNVLS = TRNVLS + 1;
if (TRNVLS > TRNSIZ)BUG(11);
TTEXT[TRNVLS] = LINUSE;
TRNVAL[TRNVLS] = loc;
continue;
}
if(sect == 10)
{
if (sect == 10) {
CLSSES = CLSSES + 1;
if (CLSSES > CLSMAX)BUG(11);
CTEXT[CLSSES] = LINUSE;
CVAL[CLSSES] = loc;
continue;
}
if(sect == 6)
{
if (sect == 6) {
if (loc > RTXSIZ)BUG(6);
RTEXT[loc] = LINUSE;
continue;
}
if(sect == 5)
{
if (sect == 5) {
if (loc > 0 && loc <= NOBJECTS)PTEXT[loc] = LINUSE;
continue;
}
if (loc > LOCSIZ)BUG(10);
if(sect == 1)
{
if (sect == 1) {
LTEXT[loc] = LINUSE;
continue;
}
@ -300,20 +289,15 @@ static void read_messages(FILE* database, long sect)
static void read_section3_stuff(FILE* database)
{
long loc;
while((loc=GETNUM(database)) != -1)
{
while ((loc = GETNUM(database)) != -1) {
long newloc = GETNUM(NULL);
long L;
if(KEY[loc] == 0)
{
if (KEY[loc] == 0) {
KEY[loc] = TRVS;
}
else
{
} else {
TRAVEL[TRVS - 1] = -TRAVEL[TRVS - 1];
}
while((L=GETNUM(NULL)) != 0)
{
while ((L = GETNUM(NULL)) != 0) {
TRAVEL[TRVS] = newloc * 1000 + L;
TRVS = TRVS + 1;
if (TRVS == TRVSIZ)BUG(3);
@ -327,8 +311,7 @@ static void read_section3_stuff(FILE* database)
* as an end-marker. */
static void read_vocabulary(FILE* database)
{
for (TABNDX=1; TABNDX<=TABSIZ; TABNDX++)
{
for (TABNDX = 1; TABNDX <= TABSIZ; TABNDX++) {
KTAB[TABNDX] = GETNUM(database);
if (KTAB[TABNDX] == -1) return;
ATAB[TABNDX] = GETTXT(true, true, true);
@ -342,8 +325,7 @@ static void read_vocabulary(FILE* database)
static void read_initial_locations(FILE* database)
{
long OBJ;
while((OBJ=GETNUM(database)) != -1)
{
while ((OBJ = GETNUM(database)) != -1) {
PLAC[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)
{
long verb;
while((verb=GETNUM(database)) != -1)
{
while ((verb = GETNUM(database)) != -1) {
ACTSPK[verb] = GETNUM(NULL);
}
}
@ -363,11 +344,9 @@ static void read_action_verb_message_nr(FILE* database)
static void read_conditions(FILE* database)
{
long K;
while((K=GETNUM(database)) != -1)
{
while ((K = GETNUM(database)) != -1) {
long loc;
while((loc=GETNUM(NULL)) != 0)
{
while ((loc = GETNUM(NULL)) != 0) {
if (is_set(COND[loc], K)) BUG(8);
COND[loc] = COND[loc] + (1l << K);
}
@ -380,11 +359,9 @@ static void read_hints(FILE* database)
{
long K;
HNTMAX = 0;
while((K=GETNUM(database)) != -1)
{
while ((K = GETNUM(database)) != -1) {
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);
} /* end loop */
HNTMAX = (HNTMAX > K ? HNTMAX : K);
@ -395,12 +372,10 @@ static void read_hints(FILE* database)
static void read_sound_text(FILE* database)
{
long K;
while((K=GETNUM(database)) != -1)
{
while ((K = GETNUM(database)) != -1) {
long KK = GETNUM(NULL);
long I = GETNUM(NULL);
if(I != 0)
{
if (I != 0) {
OBJSND[K] = (KK > 0 ? KK : 0);
OBJTXT[K] = (I > 0 ? I : 0);
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
* 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. */
while(true)
{
while (true) {
long sect = GETNUM(database);
OLDLOC = -1;
switch (sect)
{
case 0: return(0);
case 1: read_messages(database, sect); break;
case 2: read_messages(database, sect); break;
case 3: read_section3_stuff(database); break;
case 4: read_vocabulary(database); break;
case 5: read_messages(database, sect); 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);
switch (sect) {
case 0:
return (0);
case 1:
read_messages(database, sect);
break;
case 2:
read_messages(database, sect);
break;
case 3:
read_section3_stuff(database);
break;
case 4:
read_vocabulary(database);
break;
case 5:
read_messages(database, sect);
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)
{
fprintf(header_file, "LOCATION long %s[] INITIALIZE(= {\n", varname);
for (int i = 0; i < dim; ++i)
{
if (i % 10 == 0)
{
for (int i = 0; i < dim; ++i) {
if (i % 10 == 0) {
if (i > 0)
fprintf(header_file, "\n");
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)
{
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, " {");
for (int j = 0; j < dim2; ++j)
{
for (int j = 0; j < dim2; ++j) {
fprintf(header_file, "%ld, ", matrix[i][j]);
}
fprintf(header_file, "},\n");

65
main.c
View file

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

52
misc.c
View file

@ -13,8 +13,7 @@
char* xstrdup(const char* s)
{
char* ptr = strdup(s);
if (ptr == NULL)
{
if (ptr == NULL) {
fprintf(stderr, "Out of memory!\n");
exit(EXIT_FAILURE);
}
@ -24,8 +23,7 @@ char* xstrdup(const char* s)
void packed_to_token(long packed, char token[6])
{
// 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;
token[4 - i] = advent_to_ascii[(int) advent];
}
@ -34,8 +32,7 @@ void packed_to_token(long packed, char token[6])
token[5] = '\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')
token[i] = '\0';
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.
int pi = 0; // parameter index
for (int i = 0; i < (int)strlen(msg); ++i)
{
if (msg[i] == '%')
{
for (int i = 0; i < (int)strlen(msg); ++i) {
if (msg[i] == '%') {
++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.
if (msg[i + 1] == 'd')
{
if (msg[i + 1] == 'd') {
copy[i + 1] = 's';
sprintf(parameters[pi], "%ld", PARMS[pi]);
}
// Unmodified string specifier.
if (msg[i + 1] == 's')
{
if (msg[i + 1] == 's') {
packed_to_token(PARMS[pi], parameters[pi]);
}
// Singular/plural specifier.
if (msg[i + 1] == 'S')
{
if (msg[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");
}
else
{
} else {
sprintf(parameters[pi], "%s", "");
}
}
// All-lowercase specifier.
if (msg[i + 1] == 'L')
{
if (msg[i + 1] == 'L') {
copy[i + 1] = 's';
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]);
}
}
// First char uppercase, rest lowercase.
if (msg[i + 1] == 'C')
{
if (msg[i + 1] == 'C') {
copy[i + 1] = 's';
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][0] = toupper(parameters[pi][0]);
@ -404,8 +389,7 @@ void DROP(long object, long where)
{
if (object > NOBJECTS)
game.fixed[object - NOBJECTS] = where;
else
{
else {
if (game.place[object] == CARRIED)
--game.holdng;
game.place[object] = where;
@ -490,8 +474,7 @@ long RNDVOC(long second, long force)
long div = 64L * 64L * 64L;
for (int i = 1; i <= TABSIZ; i++) {
if (MOD(ATAB[i]/div, 64L) == second)
{
if (MOD(ATAB[i] / div, 64L) == second) {
ATAB[i] = rnd;
break;
}
@ -586,8 +569,7 @@ bool MAPLIN(FILE *fp)
efp = logfp;
else if (!isatty(0))
efp = stdout;
if (efp != NULL)
{
if (efp != NULL) {
if (prompt && efp == stdout)
fputs("> ", efp);
IGNORE(fputs(rawbuf, efp));

View file

@ -31,7 +31,8 @@ struct save_t save;
/* Suspend and resume */
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
* battles or to start over after learning zzword).
* If ADVENT_NOSAVE is defined, do nothing instead. */
@ -71,7 +72,8 @@ int suspend(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. */
#ifdef ADVENT_NOSAVE
@ -98,7 +100,8 @@ int resume(FILE *input)
}
int restore(FILE* fp)
{ /* Read and restore game state from file, assuming
{
/* Read and restore game state from file, assuming
* sane initial state.
* If ADVENT_NOSAVE is defined, do nothing instead. */
#ifdef ADVENT_NOSAVE