Unshadowed k2 into k3 in main.c
Reindented everything
This commit is contained in:
parent
5f44fccf4d
commit
bf2fa227f0
7 changed files with 323 additions and 342 deletions
11
actions.c
11
actions.c
|
@ -51,7 +51,7 @@ static int attack(struct command_t *command)
|
|||
spk = BIRD_DEAD;
|
||||
} else if (obj == VEND) {
|
||||
state_change(VEND,
|
||||
game.prop[VEND]==VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS);
|
||||
game.prop[VEND] == VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS);
|
||||
return GO_CLEAROBJ;
|
||||
}
|
||||
|
||||
|
@ -85,13 +85,10 @@ static int attack(struct command_t *command)
|
|||
* 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())
|
||||
{
|
||||
if (silent_yes()) {
|
||||
// FIXME: setting wd1 is a workaround for broken logic
|
||||
command->wd1 = token_to_packed("Y");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// FIXME: setting wd1 is a workaround for broken logic
|
||||
command->wd1 = token_to_packed("N");
|
||||
return GO_CHECKFOO;
|
||||
|
@ -1213,7 +1210,7 @@ int action(struct command_t *command)
|
|||
case RUB:
|
||||
return rub(command->verb, command->obj);
|
||||
case THROW:
|
||||
return throw(command);
|
||||
return throw (command);
|
||||
case QUIT: {
|
||||
rspeak(spk);
|
||||
return GO_CLEAROBJ;
|
||||
|
|
6
cheat.c
6
cheat.c
|
@ -59,8 +59,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if (savefilename == NULL)
|
||||
{
|
||||
if (savefilename == NULL) {
|
||||
fprintf(stderr,
|
||||
usage, argv[0]);
|
||||
fprintf(stderr,
|
||||
|
@ -90,8 +89,7 @@ int main(int argc, char *argv[])
|
|||
game.saved = saved;
|
||||
|
||||
fp = fopen(savefilename, WRITE_MODE);
|
||||
if (fp == NULL)
|
||||
{
|
||||
if (fp == NULL) {
|
||||
fprintf(stderr,
|
||||
"Can't open file %s. Exiting.\n", savefilename);
|
||||
exit(-1);
|
||||
|
|
23
main.c
23
main.c
|
@ -634,14 +634,14 @@ static bool playermove(token_t verb, int motion)
|
|||
|
||||
/* We arrive here on conditional failure.
|
||||
* Skip to next non-matching destination */
|
||||
long k2 = kk;
|
||||
long k3 = kk;
|
||||
do {
|
||||
if (travel[k2].stop)
|
||||
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 */
|
||||
|
@ -696,7 +696,7 @@ static bool playermove(token_t verb, int motion)
|
|||
* 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);
|
||||
|
@ -1020,9 +1020,8 @@ L2600:
|
|||
for (;;) {
|
||||
input = get_input();
|
||||
if (input == NULL)
|
||||
return(false);
|
||||
if (word_count(input) > 2)
|
||||
{
|
||||
return (false);
|
||||
if (word_count(input) > 2) {
|
||||
rspeak(TWO_WORDS);
|
||||
continue;
|
||||
}
|
||||
|
@ -1045,10 +1044,8 @@ L2607:
|
|||
|
||||
/* 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
|
75
misc.c
75
misc.c
|
@ -51,7 +51,7 @@ char* xstrdup(const char* s)
|
|||
fprintf(stderr, "Out of memory!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return(ptr);
|
||||
return (ptr);
|
||||
}
|
||||
|
||||
void* xmalloc(size_t size)
|
||||
|
@ -91,12 +91,11 @@ 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)
|
||||
{
|
||||
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])
|
||||
|
@ -300,13 +299,12 @@ int word_count(char* s)
|
|||
char* word;
|
||||
|
||||
word = strtok(copy, delims);
|
||||
while(word != NULL)
|
||||
{
|
||||
while (word != NULL) {
|
||||
word = strtok(NULL, delims);
|
||||
++count;
|
||||
}
|
||||
free(copy);
|
||||
return(count);
|
||||
return (count);
|
||||
}
|
||||
|
||||
char* get_input()
|
||||
|
@ -334,11 +332,11 @@ char* get_input()
|
|||
// LCOV_EXCL_STOP
|
||||
ssize_t numread = getline(&input, &n, stdin);
|
||||
if (numread == -1) // Got EOF; return with it.
|
||||
return(NULL);
|
||||
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.
|
||||
|
@ -374,7 +372,7 @@ bool silent_yes()
|
|||
// 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)
|
||||
|
@ -420,7 +418,7 @@ bool yes(const char* question, const char* yes_response, const char* no_response
|
|||
// 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)
|
||||
|
@ -453,61 +451,53 @@ bool yes(const char* question, const char* yes_response, const char* no_response
|
|||
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)
|
||||
{
|
||||
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);
|
||||
return (i);
|
||||
}
|
||||
}
|
||||
// If execution reaches here, we didn't find the word.
|
||||
return(WORD_NOT_FOUND);
|
||||
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)
|
||||
{
|
||||
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);
|
||||
return (i);
|
||||
}
|
||||
}
|
||||
// If execution reaches here, we didn't find the word.
|
||||
return(WORD_NOT_FOUND);
|
||||
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)
|
||||
{
|
||||
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);
|
||||
return (i);
|
||||
}
|
||||
}
|
||||
// If execution reaches here, we didn't find the word.
|
||||
return(WORD_NOT_FOUND);
|
||||
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)
|
||||
{
|
||||
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);
|
||||
return (i);
|
||||
}
|
||||
}
|
||||
// If execution reaches here, we didn't find the word.
|
||||
return(WORD_NOT_FOUND);
|
||||
return (WORD_NOT_FOUND);
|
||||
}
|
||||
|
||||
long get_vocab_id(const char* word)
|
||||
|
@ -517,25 +507,25 @@ long get_vocab_id(const char* word)
|
|||
|
||||
ref_num = get_motion_vocab_id(word);
|
||||
if (ref_num != WORD_NOT_FOUND)
|
||||
return(ref_num + 0); // FIXME: replace with a proper hash
|
||||
return (ref_num + 0); // 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
|
||||
return (ref_num + 1000); // 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
|
||||
return (ref_num + 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 (ref_num + 3000); // 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
|
||||
return (PART + 2000); // FIXME: replace with a proper hash
|
||||
|
||||
return(WORD_NOT_FOUND);
|
||||
return (WORD_NOT_FOUND);
|
||||
}
|
||||
|
||||
void juggle(long object)
|
||||
|
@ -673,8 +663,7 @@ long randrange(long range)
|
|||
|
||||
void make_zzword(char zzword[6])
|
||||
{
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
zzword[i] = 'A' + randrange(26);
|
||||
}
|
||||
zzword[1] = '\''; // force second char to apostrophe
|
||||
|
|
|
@ -27,7 +27,7 @@ struct save_t {
|
|||
struct save_t save;
|
||||
|
||||
int savefile(FILE *fp, long version)
|
||||
/* Save game to file. No input or output from user. */
|
||||
/* Save game to file. No input or output from user. */
|
||||
{
|
||||
long i, k;
|
||||
datime(&i, &k);
|
||||
|
@ -39,7 +39,7 @@ int savefile(FILE *fp, long version)
|
|||
|
||||
memcpy(&save.game, &game, sizeof(struct game_t));
|
||||
IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Suspend and resume */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue