if (AT(TROLL))obj = obj * NOBJECTS + TROLL;
if (AT(OGRE))obj = obj * NOBJECTS + OGRE;
if (HERE(BEAR) && game.prop[BEAR] == UNTAMED_BEAR)
- obj = obj * NOBJECTS + BEAR;
+ obj = obj * NOBJECTS + BEAR;
if (obj > NOBJECTS) return GO_UNKNOWN;
if (obj == 0) {
/* Can't attack bird or machine by throwing axe. */
DESTROY(BIRD);
spk = BIRD_DEAD;
} else if (obj == VEND) {
- state_change(VEND,
- game.prop[VEND]==VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS);
+ state_change(VEND,
+ game.prop[VEND] == VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS);
return GO_CLEAROBJ;
}
* fixed), move rug there (not fixed), and move him there,
* too. Then do a null motion to get new description. */
rspeak(BARE_HANDS_QUERY);
- if(silent_yes())
- {
- // FIXME: setting wd1 is a workaround for broken logic
- command->wd1 = token_to_packed("Y");
- }
- else
- {
- // FIXME: setting wd1 is a workaround for broken logic
- command->wd1 = token_to_packed("N");
- return GO_CHECKFOO;
- }
+ if (silent_yes()) {
+ // FIXME: setting wd1 is a workaround for broken logic
+ command->wd1 = token_to_packed("Y");
+ } else {
+ // FIXME: setting wd1 is a workaround for broken logic
+ command->wd1 = token_to_packed("N");
+ return GO_CHECKFOO;
+ }
pspeak(DRAGON, look, 3);
game.prop[DRAGON] = 1;
game.prop[RUG] = 0;
spk = YOU_JOKING;
if (obj == PLANT && game.prop[PLANT] <= 0)spk = DEEP_ROOTS;
if (obj == BEAR && game.prop[BEAR] == SITTING_BEAR)
- spk = BEAR_CHAINED;
+ spk = BEAR_CHAINED;
if (obj == CHAIN && game.prop[BEAR] != UNTAMED_BEAR)
- spk = STILL_LOCKED;
+ spk = STILL_LOCKED;
if (obj == URN)spk = URN_NOBUDGE;
if (obj == CAVITY)spk = DOUGHNUT_HOLES;
if (obj == BLOOD)spk = FEW_DROPS;
return (fill(verb, BOTTLE));
else {
if (game.prop[BOTTLE] != EMPTY_BOTTLE)
- spk = BOTTLE_FULL;
+ spk = BOTTLE_FULL;
if (!TOTING(BOTTLE))spk = NO_CONTAINER;
rspeak(spk);
return GO_CLEAROBJ;
if (verb != LOCK) {
spk = CHAIN_UNLOCKED;
if (game.prop[BEAR] == UNTAMED_BEAR)
- spk = BEAR_BLOCKS;
+ spk = BEAR_BLOCKS;
if (game.prop[CHAIN] == 0)
- spk = ALREADY_UNLOCKED;
+ spk = ALREADY_UNLOCKED;
if (spk != CHAIN_UNLOCKED) {
rspeak(spk);
return GO_CLEAROBJ;
game.prop[CHAIN] = 0;
game.fixed[CHAIN] = 0;
if (game.prop[BEAR] != BEAR_DEAD)
- game.prop[BEAR] = CONTENTED_BEAR;
- /* FIXME: Arithmetic on state numbers */
+ game.prop[BEAR] = CONTENTED_BEAR;
+ /* FIXME: Arithmetic on state numbers */
game.fixed[BEAR] = 2 - game.prop[BEAR];
} else {
spk = CHAIN_LOCKED;
if (game.prop[CHAIN] != 0)
- spk = ALREADY_LOCKED;
+ spk = ALREADY_LOCKED;
if (game.loc != objects[CHAIN].plac)
- spk = NO_LOCKSITE;
+ spk = NO_LOCKSITE;
if (spk != CHAIN_LOCKED) {
rspeak(spk);
return GO_CLEAROBJ;
}
game.prop[CHAIN] = 2;
if (TOTING(CHAIN))
- drop(CHAIN, game.loc);
+ drop(CHAIN, game.loc);
game.fixed[CHAIN] = -1;
}
rspeak(spk);
if (obj == BOTTLE && k != 0)
game.place[k] = LOC_NOWHERE;
if (obj == CAGE && game.prop[BIRD] == BIRD_CAGED)
- drop(BIRD, game.loc);
+ drop(BIRD, game.loc);
drop(obj, game.loc);
if (obj != BIRD) return GO_CLEAROBJ;
game.prop[BIRD] = BIRD_UNCAGED;
if (FOREST(game.loc))
- game.prop[BIRD] = BIRD_FOREST_UNCAGED;
+ game.prop[BIRD] = BIRD_FOREST_UNCAGED;
return GO_CLEAROBJ;
}
int spk = actions[verb].message;
if (obj == INTRANSITIVE) {
if (HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT)
- obj = LAMP;
+ obj = LAMP;
if (HERE(URN) && game.prop[URN] == 2)obj = obj * NOBJECTS + URN;
if (obj == INTRANSITIVE || obj == 0 || obj > NOBJECTS) return GO_UNKNOWN;
}
game.prop[URN] = game.prop[URN] / 2;
spk = URN_DARK;
} else if (obj == LAMP) {
- state_change(LAMP, LAMP_DARK);
+ state_change(LAMP, LAMP_DARK);
spk = DARK(game.loc) ? PITCH_DARK : NO_MESSAGE;
} else if (obj == DRAGON || obj == VOLCANO)
spk = BEYOND_POWER;
}
} else if (obj == BEAR) {
if (game.prop[BEAR] == UNTAMED_BEAR)
- spk = NOTHING_EDIBLE;
+ spk = NOTHING_EDIBLE;
if (game.prop[BEAR] == BEAR_DEAD)
- spk = RIDICULOUS_ATTEMPT;
+ spk = RIDICULOUS_ATTEMPT;
if (HERE(FOOD)) {
DESTROY(FOOD);
game.prop[BEAR] = SITTING_BEAR;
if (LIQUID() != 0)
spk = BOTTLE_FULL;
if (spk == BOTTLED_WATER) {
- /* FIXME: Arithmetic on property values */
+ /* FIXME: Arithmetic on property values */
game.prop[BOTTLE] = MOD(conditions[game.loc], 4) / 2 * 2;
k = LIQUID();
if (TOTING(BOTTLE))
int spk = actions[verb].message;
if (obj == INTRANSITIVE) {
if (HERE(LAMP) && game.prop[LAMP] == LAMP_DARK && game.limit >= 0)
- obj = LAMP;
+ obj = LAMP;
if (HERE(URN) && game.prop[URN] == 1)obj = obj * NOBJECTS + URN;
if (obj == INTRANSITIVE || obj == 0 || obj > NOBJECTS) return GO_UNKNOWN;
}
rspeak(spk);
return GO_CLEAROBJ;
}
- state_change(LAMP, LAMP_BRIGHT);
+ state_change(LAMP, LAMP_BRIGHT);
if (game.wzdark)
return GO_TOP;
else
if (k != SILENT) {
rspeak(k);
if (locations[game.loc].loud)
- return GO_CLEAROBJ;
- else
- spk = NO_MESSAGE;
+ return GO_CLEAROBJ;
+ else
+ spk = NO_MESSAGE;
}
for (int i = 1; i <= NOBJECTS; i++) {
if (!HERE(i) || objects[i].sounds[0] == NULL || game.prop[i] < 0)
continue;
- int mi = game.prop[i];
- if (i == BIRD)
- mi += 3 * game.blooded;
- long packed_zzword = token_to_packed(game.zzword);
+ int mi = game.prop[i];
+ if (i == BIRD)
+ mi += 3 * game.blooded;
+ long packed_zzword = token_to_packed(game.zzword);
pspeak(i, hear, mi, packed_zzword);
spk = NO_MESSAGE;
- /* FIXME: Magic number, sensitive to bird state logic */
- if (i == BIRD && game.prop[i] == 5)
+ /* FIXME: Magic number, sensitive to bird state logic */
+ if (i == BIRD && game.prop[i] == 5)
DESTROY(BIRD);
}
rspeak(spk);
if (!game.panic)game.clock2 = PANICTIME;
game.panic = true;
} else {
- state_change(GRATE, (verb == LOCK) ? GRATE_CLOSED : GRATE_OPEN);
- return GO_CLEAROBJ;
+ state_change(GRATE, (verb == LOCK) ? GRATE_CLOSED : GRATE_OPEN);
+ return GO_CLEAROBJ;
}
}
}
}
/* FIXME: Arithemetic on proprty values */
if (HERE(BIRD))
- spk = FREE_FLY + MOD(game.prop[BIRD], 2);
+ spk = FREE_FLY + MOD(game.prop[BIRD], 2);
if (spk == FREE_FLY && game.loc == game.place[STEPS] && game.prop[JADE] < 0) {
drop(JADE, game.loc);
game.prop[JADE] = 0;
switch (command->part) {
case intransitive:
if (command->wd2 > 0 && command->verb != SAY)
- return GO_WORD2;
+ return GO_WORD2;
if (command->verb == SAY)command->obj = command->wd2;
if (command->obj == 0 || command->obj == INTRANSITIVE) {
/* Analyse an intransitive verb (ie, no object given yet). */
case BRIEF:
return brief();
case READ:
- command->obj = INTRANSITIVE;
+ command->obj = INTRANSITIVE;
return read(*command);
case BREAK:
return GO_UNKNOWN;
return listen();
case PART:
return reservoir();
- default:
- BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
+ default:
+ BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
}
}
/* FALLTHRU */
rspeak(spk);
return GO_CLEAROBJ;
}
- case GO: {
+ case GO: {
rspeak(spk);
return GO_CLEAROBJ;
}
case RUB:
return rub(command->verb, command->obj);
case THROW:
- return throw(command);
+ return throw (command);
case QUIT: {
rspeak(spk);
return GO_CLEAROBJ;
rspeak(spk);
return GO_CLEAROBJ;
}
- case PART:
+ case PART:
return reservoir();
- default:
- BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
- }
+ default:
+ BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
+ }
case unknown:
/* Unknown verb, couldn't deduce object - might need hint */
rspeak(WHAT_DO, command->wd1, command->wd1x);
// autogenerated, so don't charge user time for it.
--game.turns;
// here we reconfigure any global game state that uses random numbers
- make_zzword(game.zzword);
+ make_zzword(game.zzword);
return true;
}
return false;
int snarfed = 0;
bool movechest = false, robplayer = false;
for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
- if (!objects[treasure].is_treasure)
- continue;
+ if (!objects[treasure].is_treasure)
+ continue;
/* Pirate won't take pyramid from plover room or dark
* room (too easy!). */
if (treasure == PYRAMID && (game.loc == objects[PYRAMID].plac || game.loc == objects[EMERALD].plac)) {
}
if (robplayer) {
rspeak(PIRATE_POUNCES);
- for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
- if (!objects[treasure].is_treasure)
- continue;
+ for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
+ if (!objects[treasure].is_treasure)
+ continue;
if (!(treasure == PYRAMID && (game.loc == objects[PYRAMID].plac || game.loc == objects[EMERALD].plac))) {
if (AT(treasure) && game.fixed[treasure] == 0)
carry(treasure, game.loc);
kk = tkey[game.dloc[i]];
if (kk != 0)
do {
- game.newloc = T_DESTINATION(travel[kk]);
+ game.newloc = T_DESTINATION(travel[kk]);
/* Have we avoided a dwarf encounter? */
bool avoided = (SPECIAL(game.newloc) ||
!INDEEP(game.newloc) ||
}
++kk;
} while
- (!travel[kk - 1].stop);
+ (!travel[kk - 1].stop);
tk[j] = game.odloc[i];
if (j >= 2)
--j;
++kk; /* go to next travel entry for this location */
continue;
}
- /* we've reached the end of travel entries for game.loc */
- kk = k2;
+ /* we've reached the end of travel entries for game.loc */
+ kk = k2;
if (kk == 0) {
rspeak(NOT_CONNECTED);
return true;
long cond = T_CONDITION(travel[kk]);
long arg = MOD(cond, 100);
if (!SPECIAL(cond)) {
- /* YAML N and [pct N] conditionals */
+ /* YAML N and [pct N] conditionals */
if (cond <= 100) {
if (cond == 0 || PCT(cond))
break;
/* else fall through */
}
- /* YAML [with OBJ] clause */
+ /* YAML [with OBJ] clause */
if (TOTING(arg) || (cond > 200 && AT(arg)))
break;
/* else fall through to check [not OBJ STATE] */
} else if (game.prop[arg] != cond / 100 - 3)
break;
- /* We arrive here on conditional failure.
- * Skip to next non-matching destination */
- long k2 = kk;
- do {
- if (travel[k2].stop)
+ /* We arrive here on conditional failure.
+ * Skip to next non-matching destination */
+ long k3 = kk;
+ do {
+ if (travel[k3].stop)
BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE
- ++k2;
+ ++k3;
} while
- (T_HIGH(travel[kk]) == T_HIGH(travel[k2]));
- kk = k2;
+ (T_HIGH(travel[kk]) == T_HIGH(travel[k3]));
+ kk = k3;
}
- /* Found an eligible rule, now execute it */
+ /* Found an eligible rule, now execute it */
game.newloc = T_DESTINATION(travel[kk]);
if (!SPECIAL(game.newloc))
return true;
- if (game.newloc > 500) {
- /* Execute a speak rule */
- rspeak(L_SPEAK(game.newloc));
- game.newloc = game.loc;
- return true;
- } else {
- game.newloc -= SPECIALBASE;
+ if (game.newloc > 500) {
+ /* Execute a speak rule */
+ rspeak(L_SPEAK(game.newloc));
+ game.newloc = game.loc;
+ return true;
+ } else {
+ game.newloc -= SPECIALBASE;
switch (game.newloc) {
case 1:
/* Travel 301. Plover-alcove passage. Can carry only
* to get it out. Having dropped it, go back and
* pretend he wasn't carrying it after all. */
drop(EMERALD, game.loc);
- k2 = kk;
+ k2 = kk;
do {
if (travel[k2].stop)
BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE
++k2;
} while
- (T_HIGH(travel[kk]) == T_HIGH(travel[k2]));
+ (T_HIGH(travel[kk]) == T_HIGH(travel[k2]));
kk = k2;
continue; /* goto L12 */
case 3:
* entries check for game.prop(TROLL)=0.) Special
* stuff for bear. */
if (game.prop[TROLL] == 1) {
- pspeak(TROLL,look, 1);
+ pspeak(TROLL, look, 1);
game.prop[TROLL] = 0;
move(TROLL2, 0);
move(TROLL2 + NOBJECTS, 0);
croak();
return true;
}
- default:
- BUG(SPECIAL_TRAVEL_500_GT_L_GT_300_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
+ default:
+ BUG(SPECIAL_TRAVEL_500_GT_L_GT_300_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
}
}
break; /* Leave L12 loop */
move(TROLL2 + NOBJECTS, objects[TROLL].fixd);
juggle(CHASM);
if (game.prop[BEAR] != BEAR_DEAD)
- DESTROY(BEAR);
+ DESTROY(BEAR);
game.prop[CHAIN] = 0;
game.fixed[CHAIN] = 0;
game.prop[AXE] = 0;
int spk = GET_BATTERIES;
if (game.place[BATTERY] == LOC_NOWHERE)spk = LAMP_DIM;
if (game.prop[BATTERY] == DEAD_BATTERIES)
- spk = MISSING_BATTERIES;
+ spk = MISSING_BATTERIES;
rspeak(spk);
}
}
game.knfloc = 0;
/* This is where we get a new command from the user */
- char* input;
- for (;;) {
- input = get_input();
- if (input == NULL)
- return(false);
- if (word_count(input) > 2)
- {
- rspeak(TWO_WORDS);
- continue;
- }
- if (strcmp(input, "") != 0)
- break;
- }
- long tokens[4];
- tokenize(input, tokens);
- command.wd1 = tokens[0];
+ char* input;
+ for (;;) {
+ input = get_input();
+ if (input == NULL)
+ return (false);
+ if (word_count(input) > 2) {
+ rspeak(TWO_WORDS);
+ continue;
+ }
+ if (strcmp(input, "") != 0)
+ break;
+ }
+ long tokens[4];
+ tokenize(input, tokens);
+ command.wd1 = tokens[0];
command.wd1x = tokens[1];
command.wd2 = tokens[2];
command.wd2x = tokens[3];
game.foobar = (game.foobar > 0 ? -game.foobar : 0);
++game.turns;
- /* If a turn threshold has been met, apply penalties and tell
- * the player about it. */
- for (int i = 0; i < NTHRESHOLDS; ++i)
- {
- if (game.turns == turn_thresholds[i].threshold + 1)
- {
- game.trnluz += turn_thresholds[i].point_loss;
- speak(turn_thresholds[i].message);
- }
- }
+ /* If a turn threshold has been met, apply penalties and tell
+ * the player about it. */
+ for (int i = 0; i < NTHRESHOLDS; ++i) {
+ if (game.turns == turn_thresholds[i].threshold + 1) {
+ game.trnluz += turn_thresholds[i].point_loss;
+ speak(turn_thresholds[i].message);
+ }
+ }
if (command.verb == SAY && command.wd2 > 0)
command.verb = 0;
} else
lampcheck();
- char word1[6];
- char word2[6];
- packed_to_token(command.wd1, word1);
- packed_to_token(command.wd2, word2);
- V1 = get_vocab_id(word1);
- V2 = get_vocab_id(word2);
+ char word1[6];
+ char word2[6];
+ packed_to_token(command.wd1, word1);
+ packed_to_token(command.wd2, word2);
+ V1 = get_vocab_id(word1);
+ V2 = get_vocab_id(word2);
if (V1 == ENTER && (V2 == STREAM || V2 == 1000 + WATER)) {
if (LIQLOC(game.loc) == WATER) {
rspeak(FEET_WET);
if (!((V1 != 1000 + WATER && V1 != 1000 + OIL) ||
(V2 != 1000 + PLANT && V2 != 1000 + DOOR))) {
if (AT(V2 - 1000))
- command.wd2 = token_to_packed("POUR");
+ command.wd2 = token_to_packed("POUR");
}
if (V1 == 1000 + CAGE && V2 == 1000 + BIRD && HERE(CAGE) && HERE(BIRD))
- command.wd1 = token_to_packed("CATCH");
+ command.wd1 = token_to_packed("CATCH");
}
L2620:
if (wordeq(command.wd1, token_to_packed("WEST"))) {
rspeak(GO_UNNEEDED);
}
Lookup:
- packed_to_token(command.wd1, word1);
- defn = get_vocab_id(word1);
+ packed_to_token(command.wd1, word1);
+ defn = get_vocab_id(word1);
if (defn == -1) {
/* Gee, I don't understand. */
if (fallback_handler(input))
default:
BUG(ACTION_RETURNED_PHASE_CODE_BEYOND_END_OF_SWITCH); // LCOV_EXCL_LINE
}
- linenoiseFree(input);
+ linenoiseFree(input);
}
}
#include "dungeon.h"
const char new_advent_to_ascii[] = {
- ' ', '!', '"', '#', '$', '%', '&', '\'',
- '(', ')', '*', '+', ',', '-', '.', '/',
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', ':', ';', '<', '=', '>', '?',
- '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
- 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
- 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
- 'X', 'Y', 'Z', '\0', '\0', '\0', '\0', '\0',
+ ' ', '!', '"', '#', '$', '%', '&', '\'',
+ '(', ')', '*', '+', ',', '-', '.', '/',
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', ':', ';', '<', '=', '>', '?',
+ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
+ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
+ 'X', 'Y', 'Z', '\0', '\0', '\0', '\0', '\0',
};
const char new_ascii_to_advent[] = {
- 63, 63, 63, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 63, 63, 63, 63,
-
- 0, 1, 2, 3, 4, 5, 6, 7,
- 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39,
- 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55,
- 56, 57, 58, 59, 60, 61, 62, 63,
-
- 63, 63, 63, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 63, 63, 63, 63,
+ 63, 63, 63, 63, 63, 63, 63, 63,
+ 63, 63, 63, 63, 63, 63, 63, 63,
+ 63, 63, 63, 63, 63, 63, 63, 63,
+ 63, 63, 63, 63, 63, 63, 63, 63,
+
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39,
+ 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55,
+ 56, 57, 58, 59, 60, 61, 62, 63,
+
+ 63, 63, 63, 63, 63, 63, 63, 63,
+ 63, 63, 63, 63, 63, 63, 63, 63,
+ 63, 63, 63, 63, 63, 63, 63, 63,
+ 63, 63, 63, 63, 63, 63, 63, 63,
};
char* xstrdup(const char* s)
{
- char* ptr = strdup(s);
- if (ptr == NULL) {
- // LCOV_EXCL_START
- // exclude from coverage analysis because we can't simulate an out of memory error in testing
- fprintf(stderr, "Out of memory!\n");
- exit(EXIT_FAILURE);
- }
- return(ptr);
+ char* ptr = strdup(s);
+ if (ptr == NULL) {
+ // LCOV_EXCL_START
+ // exclude from coverage analysis because we can't simulate an out of memory error in testing
+ fprintf(stderr, "Out of memory!\n");
+ exit(EXIT_FAILURE);
+ }
+ return (ptr);
}
void* xmalloc(size_t size)
// exclude from coverage analysis because we can't simulate an out of memory error in testing
fprintf(stderr, "Out of memory!\n");
exit(EXIT_FAILURE);
- // LCOV_EXCL_STOP
+ // LCOV_EXCL_STOP
}
return (ptr);
}
{
// Unpack and map back to ASCII.
for (int i = 0; i < 5; ++i) {
- char advent = (packed >> i * 6) & 63;
+ char advent = (packed >> i * 6) & 63;
token[i] = new_advent_to_ascii[(int) advent];
}
long token_to_packed(const char token[6])
{
- size_t t_len = strlen(token);
- long packed = 0;
- for (size_t i = 0; i < t_len; ++i)
- {
- char mapped = new_ascii_to_advent[(int) token[i]];
- packed |= (mapped << (6 * i));
+ size_t t_len = strlen(token);
+ long packed = 0;
+ for (size_t i = 0; i < t_len; ++i) {
+ char mapped = new_ascii_to_advent[(int) token[i]];
+ packed |= (mapped << (6 * i));
}
- return(packed);
+ return (packed);
}
void tokenize(char* raw, long tokens[4])
{
- // set each token to 0
- for (int i = 0; i < 4; ++i)
- tokens[i] = 0;
-
- // grab the first two words
- char* words[2];
- words[0] = (char*) xmalloc(strlen(raw));
- words[1] = (char*) xmalloc(strlen(raw));
- int word_count = sscanf(raw, "%s%s", words[0], words[1]);
-
- // make space for substrings and zero it out
- char chunk_data[][6] = {
- {"\0\0\0\0\0"},
- {"\0\0\0\0\0"},
- {"\0\0\0\0\0"},
- {"\0\0\0\0\0"},
- };
-
- // break the words into up to 4 5-char substrings
- sscanf(words[0], "%5s%5s", chunk_data[0], chunk_data[1]);
- if (word_count == 2)
- sscanf(words[1], "%5s%5s", chunk_data[2], chunk_data[3]);
- free(words[0]);
- free(words[1]);
-
- // uppercase all the substrings
- for (int i = 0; i < 4; ++i)
- for (unsigned int j = 0; j < strlen(chunk_data[i]); ++j)
- chunk_data[i][j] = (char) toupper(chunk_data[i][j]);
-
- // pack the substrings
- for (int i = 0; i < 4; ++i)
- tokens[i] = token_to_packed(chunk_data[i]);
+ // set each token to 0
+ for (int i = 0; i < 4; ++i)
+ tokens[i] = 0;
+
+ // grab the first two words
+ char* words[2];
+ words[0] = (char*) xmalloc(strlen(raw));
+ words[1] = (char*) xmalloc(strlen(raw));
+ int word_count = sscanf(raw, "%s%s", words[0], words[1]);
+
+ // make space for substrings and zero it out
+ char chunk_data[][6] = {
+ {"\0\0\0\0\0"},
+ {"\0\0\0\0\0"},
+ {"\0\0\0\0\0"},
+ {"\0\0\0\0\0"},
+ };
+
+ // break the words into up to 4 5-char substrings
+ sscanf(words[0], "%5s%5s", chunk_data[0], chunk_data[1]);
+ if (word_count == 2)
+ sscanf(words[1], "%5s%5s", chunk_data[2], chunk_data[3]);
+ free(words[0]);
+ free(words[1]);
+
+ // uppercase all the substrings
+ for (int i = 0; i < 4; ++i)
+ for (unsigned int j = 0; j < strlen(chunk_data[i]); ++j)
+ chunk_data[i][j] = (char) toupper(chunk_data[i][j]);
+
+ // pack the substrings
+ for (int i = 0; i < 4; ++i)
+ tokens[i] = token_to_packed(chunk_data[i]);
}
/* Hide the fact that wods are corrently packed longs */
size--;
} else {
long arg = va_arg(ap, long);
- if (arg == -1)
- arg = 0;
+ if (arg == -1)
+ arg = 0;
i++;
// 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] == 'd') {
switch (mode) {
case touch:
vspeak(objects[msg].inventory, ap);
- break;
- case look:
+ break;
+ case look:
vspeak(objects[msg].descriptions[skip], ap);
- break;
+ break;
case hear:
vspeak(objects[msg].sounds[skip], ap);
- break;
+ break;
case study:
vspeak(objects[msg].texts[skip], ap);
- break;
+ break;
case change:
vspeak(objects[msg].changes[skip], ap);
- break;
+ break;
}
va_end(ap);
}
int word_count(char* s)
{
- char* copy = xstrdup(s);
- char delims[] = " \t";
- int count = 0;
- char* word;
+ char* copy = xstrdup(s);
+ char delims[] = " \t";
+ int count = 0;
+ char* word;
- word = strtok(copy, delims);
- while(word != NULL)
- {
- word = strtok(NULL, delims);
- ++count;
+ word = strtok(copy, delims);
+ while (word != NULL) {
+ word = strtok(NULL, delims);
+ ++count;
}
- free(copy);
- return(count);
+ free(copy);
+ return (count);
}
char* get_input()
input = NULL;
size_t n = 0;
if (isatty(0))
- // LCOV_EXCL_START
- // Should be unreachable in tests, as they will use a non-interactive shell.
+ // LCOV_EXCL_START
+ // Should be unreachable in tests, as they will use a non-interactive shell.
printf("%s", input_prompt);
- // LCOV_EXCL_STOP
+ // LCOV_EXCL_STOP
ssize_t numread = getline(&input, &n, stdin);
- if (numread == -1) // Got EOF; return with it.
- return(NULL);
+ if (numread == -1) // Got EOF; return with it.
+ return (NULL);
}
if (input == NULL) // Got EOF; return with it.
- return(input);
+ return (input);
else if (input[0] == '#') // Ignore comments.
continue;
else // We have a 'normal' line; leave the loop.
bool silent_yes()
{
- char* reply;
- bool outcome;
-
- for (;;) {
- reply = get_input();
- if (reply == NULL) {
- // LCOV_EXCL_START
- // Should be unreachable. Reply should never be NULL
- linenoiseFree(reply);
- exit(EXIT_SUCCESS);
- // LCOV_EXCL_STOP
- }
+ char* reply;
+ bool outcome;
- char* firstword = (char*) xmalloc(strlen(reply)+1);
- sscanf(reply, "%s", firstword);
+ for (;;) {
+ reply = get_input();
+ if (reply == NULL) {
+ // LCOV_EXCL_START
+ // Should be unreachable. Reply should never be NULL
+ linenoiseFree(reply);
+ exit(EXIT_SUCCESS);
+ // LCOV_EXCL_STOP
+ }
- for (int i = 0; i < (int)strlen(firstword); ++i)
- firstword[i] = tolower(firstword[i]);
+ char* firstword = (char*) xmalloc(strlen(reply) + 1);
+ sscanf(reply, "%s", firstword);
+
+ for (int i = 0; i < (int)strlen(firstword); ++i)
+ firstword[i] = tolower(firstword[i]);
- int yes = strncmp("yes", firstword, sizeof("yes") - 1);
- int y = strncmp("y", firstword, sizeof("y") - 1);
- int no = strncmp("no", firstword, sizeof("no") - 1);
- int n = strncmp("n", firstword, sizeof("n") - 1);
+ int yes = strncmp("yes", firstword, sizeof("yes") - 1);
+ int y = strncmp("y", firstword, sizeof("y") - 1);
+ int no = strncmp("no", firstword, sizeof("no") - 1);
+ int n = strncmp("n", firstword, sizeof("n") - 1);
- free(firstword);
+ free(firstword);
- if (yes == 0 || y == 0) {
- outcome = true;
- break;
- } else if (no == 0 || n == 0) {
- outcome = false;
- break;
- } else
- rspeak(PLEASE_ANSWER);
- }
- linenoiseFree(reply);
- return (outcome);
+ if (yes == 0 || y == 0) {
+ outcome = true;
+ break;
+ } else if (no == 0 || n == 0) {
+ outcome = false;
+ break;
+ } else
+ rspeak(PLEASE_ANSWER);
+ }
+ linenoiseFree(reply);
+ return (outcome);
}
// Should be unreachable. Reply should never be NULL
linenoiseFree(reply);
exit(EXIT_SUCCESS);
- // LCOV_EXCL_STOP
+ // LCOV_EXCL_STOP
}
- char* firstword = (char*) xmalloc(strlen(reply)+1);
+ char* firstword = (char*) xmalloc(strlen(reply) + 1);
sscanf(reply, "%s", firstword);
for (int i = 0; i < (int)strlen(firstword); ++i)
free(firstword);
if (yes == 0 || y == 0) {
- speak(yes_response);
+ speak(yes_response);
outcome = true;
break;
} else if (no == 0 || n == 0) {
int get_motion_vocab_id(const char* word)
// Return the first motion number that has 'word' as one of its words.
{
- for (int i = 0; i < NMOTIONS; ++i)
- {
- for (int j = 0; j < motions[i].words.n; ++j)
- {
- if (strcasecmp(word, motions[i].words.strs[j]) == 0)
- return(i);
- }
+ for (int i = 0; i < NMOTIONS; ++i) {
+ for (int j = 0; j < motions[i].words.n; ++j) {
+ if (strcasecmp(word, motions[i].words.strs[j]) == 0)
+ return (i);
+ }
}
- // If execution reaches here, we didn't find the word.
- return(WORD_NOT_FOUND);
+ // If execution reaches here, we didn't find the word.
+ return (WORD_NOT_FOUND);
}
int get_object_vocab_id(const char* word)
// Return the first object number that has 'word' as one of its words.
{
- for (int i = 0; i < NOBJECTS + 1; ++i) // FIXME: the + 1 should go when 1-indexing for objects is removed
- {
- for (int j = 0; j < objects[i].words.n; ++j)
- {
- if (strcasecmp(word, objects[i].words.strs[j]) == 0)
- return(i);
- }
+ for (int i = 0; i < NOBJECTS + 1; ++i) { // FIXME: the + 1 should go when 1-indexing for objects is removed
+ for (int j = 0; j < objects[i].words.n; ++j) {
+ if (strcasecmp(word, objects[i].words.strs[j]) == 0)
+ return (i);
+ }
}
- // If execution reaches here, we didn't find the word.
- return(WORD_NOT_FOUND);
+ // If execution reaches here, we didn't find the word.
+ return (WORD_NOT_FOUND);
}
int get_action_vocab_id(const char* word)
// Return the first motion number that has 'word' as one of its words.
{
- for (int i = 0; i < NACTIONS; ++i)
- {
- for (int j = 0; j < actions[i].words.n; ++j)
- {
- if (strcasecmp(word, actions[i].words.strs[j]) == 0)
- return(i);
- }
+ for (int i = 0; i < NACTIONS; ++i) {
+ for (int j = 0; j < actions[i].words.n; ++j) {
+ if (strcasecmp(word, actions[i].words.strs[j]) == 0)
+ return (i);
+ }
}
- // If execution reaches here, we didn't find the word.
- return(WORD_NOT_FOUND);
+ // If execution reaches here, we didn't find the word.
+ return (WORD_NOT_FOUND);
}
int get_special_vocab_id(const char* word)
// Return the first special number that has 'word' as one of its words.
{
- for (int i = 0; i < NSPECIALS; ++i)
- {
- for (int j = 0; j < specials[i].words.n; ++j)
- {
- if (strcasecmp(word, specials[i].words.strs[j]) == 0)
- return(i);
- }
+ for (int i = 0; i < NSPECIALS; ++i) {
+ for (int j = 0; j < specials[i].words.n; ++j) {
+ if (strcasecmp(word, specials[i].words.strs[j]) == 0)
+ return (i);
+ }
}
- // If execution reaches here, we didn't find the word.
- return(WORD_NOT_FOUND);
+ // If execution reaches here, we didn't find the word.
+ return (WORD_NOT_FOUND);
}
long get_vocab_id(const char* word)
// Search the vocab categories in order for the supplied word.
{
- long ref_num;
-
- ref_num = get_motion_vocab_id(word);
- if (ref_num != WORD_NOT_FOUND)
- return(ref_num + 0); // FIXME: replace with a proper hash
+ long ref_num;
- ref_num = get_object_vocab_id(word);
- if (ref_num != WORD_NOT_FOUND)
- return(ref_num + 1000); // FIXME: replace with a proper hash
+ ref_num = get_motion_vocab_id(word);
+ if (ref_num != WORD_NOT_FOUND)
+ return (ref_num + 0); // FIXME: replace with a proper hash
- ref_num = get_action_vocab_id(word);
- if (ref_num != WORD_NOT_FOUND)
- return(ref_num + 2000); // FIXME: replace with a proper hash
+ ref_num = get_object_vocab_id(word);
+ if (ref_num != WORD_NOT_FOUND)
+ return (ref_num + 1000); // FIXME: replace with a proper hash
- ref_num = get_special_vocab_id(word);
- if (ref_num != WORD_NOT_FOUND)
- return(ref_num + 3000); // FIXME: replace with a proper hash
+ ref_num = get_action_vocab_id(word);
+ if (ref_num != WORD_NOT_FOUND)
+ return (ref_num + 2000); // FIXME: replace with a proper hash
- // Check for the reservoir magic word.
- if (strcasecmp(word, game.zzword) == 0)
- return(PART + 2000); // FIXME: replace with a proper hash
+ ref_num = get_special_vocab_id(word);
+ if (ref_num != WORD_NOT_FOUND)
+ return (ref_num + 3000); // FIXME: replace with a proper hash
- return(WORD_NOT_FOUND);
+ // Check for the reservoir magic word.
+ if (strcasecmp(word, game.zzword) == 0)
+ return (PART + 2000); // FIXME: replace with a proper hash
+
+ return (WORD_NOT_FOUND);
}
void juggle(long object)
void make_zzword(char zzword[6])
{
- for (int i = 0; i < 5; ++i)
- {
- zzword[i] = 'A' + randrange(26);
+ for (int i = 0; i < 5; ++i) {
+ zzword[i] = 'A' + randrange(26);
}
- zzword[1] = '\''; // force second char to apostrophe
- zzword[5] = '\0';
+ zzword[1] = '\''; // force second char to apostrophe
+ zzword[5] = '\0';
}
void datime(long* d, long* t)