Magic-number elimination.
This commit is contained in:
parent
f48ec1eb36
commit
eba8015059
4 changed files with 11 additions and 10 deletions
|
@ -171,7 +171,7 @@ static int bigwords(token_t foo)
|
|||
* Look up foo in special section of vocab to determine which word we've got.
|
||||
* Last word zips the eggs back to the giant room (unless already there). */
|
||||
{
|
||||
char word[6];
|
||||
char word[TOKLEN+1];
|
||||
packed_to_token(foo, word);
|
||||
int k = (int) get_special_vocab_id(word);
|
||||
int spk = NOTHING_HAPPENS;
|
||||
|
@ -1043,7 +1043,7 @@ static int say(struct command_t *command)
|
|||
b = command->wd2x;
|
||||
command->wd1 = command->wd2;
|
||||
}
|
||||
char word1[6];
|
||||
char word1[TOKLEN+1];
|
||||
packed_to_token(command->wd1, word1);
|
||||
int wd = (int) get_vocab_id(word1);
|
||||
/* FIXME: magic numbers */
|
||||
|
|
5
advent.h
5
advent.h
|
@ -6,6 +6,7 @@
|
|||
#include "dungeon.h"
|
||||
|
||||
#define LINESIZE 1024
|
||||
#define TOKLEN 5 // # sigificant character sin a token */
|
||||
#define NDWARVES 6 // number of dwarves
|
||||
#define PIRATE NDWARVES // must be NDWARVES-1 when zero-origin
|
||||
#define DALTLC LOC_NUGGET // alternate dwarf location
|
||||
|
@ -151,7 +152,7 @@ struct game_t {
|
|||
long trnluz; // # points lost so far due to number of turns used
|
||||
long turns; // how many commands he's given (ignores yes/no)
|
||||
bool wzdark; // whether the loc he's leaving was dark
|
||||
char zzword[6]; // randomly generated magic word from bird
|
||||
char zzword[TOKLEN+1]; // randomly generated magic word from bird
|
||||
bool blooded; // has player drunk of dragon's blood?
|
||||
long abbrev[NLOCATIONS + 1];
|
||||
long atloc[NLOCATIONS + 1];
|
||||
|
@ -190,7 +191,7 @@ extern struct settings_t settings;
|
|||
extern char* xstrdup(const char* s);
|
||||
extern void* xmalloc(size_t size);
|
||||
extern void packed_to_token(long, char token[]);
|
||||
extern long token_to_packed(const char token[6]);
|
||||
extern long token_to_packed(const char token[TOKLEN+1]);
|
||||
extern void tokenize(char*, long tokens[4]);
|
||||
extern void vspeak(const char*, bool, va_list);
|
||||
extern bool wordeq(token_t, token_t);
|
||||
|
|
4
main.c
4
main.c
|
@ -1089,8 +1089,8 @@ L2607:
|
|||
} else
|
||||
lampcheck();
|
||||
|
||||
char word1[6];
|
||||
char word2[6];
|
||||
char word1[TOKLEN+1];
|
||||
char word2[TOKLEN+1];
|
||||
packed_to_token(command.wd1, word1);
|
||||
packed_to_token(command.wd2, word2);
|
||||
V1 = get_vocab_id(word1);
|
||||
|
|
8
misc.c
8
misc.c
|
@ -35,7 +35,7 @@ void* xmalloc(size_t size)
|
|||
return (ptr);
|
||||
}
|
||||
|
||||
void packed_to_token(long packed, char token[6])
|
||||
void packed_to_token(long packed, char token[TOKLEN+1])
|
||||
{
|
||||
// The advent->ascii mapping.
|
||||
const char advent_to_ascii[] = {
|
||||
|
@ -68,7 +68,7 @@ void packed_to_token(long packed, char token[6])
|
|||
}
|
||||
}
|
||||
|
||||
long token_to_packed(const char token[6])
|
||||
long token_to_packed(const char token[TOKLEN+1])
|
||||
{
|
||||
const char ascii_to_advent[] = {
|
||||
63, 63, 63, 63, 63, 63, 63, 63,
|
||||
|
@ -113,7 +113,7 @@ void tokenize(char* raw, long tokens[4])
|
|||
int word_count = sscanf(raw, "%s%s", words[0], words[1]);
|
||||
|
||||
// make space for substrings and zero it out
|
||||
char chunk_data[][6] = {
|
||||
char chunk_data[][TOKLEN+1] = {
|
||||
{"\0\0\0\0\0"},
|
||||
{"\0\0\0\0\0"},
|
||||
{"\0\0\0\0\0"},
|
||||
|
@ -679,7 +679,7 @@ long randrange(long range)
|
|||
return range * get_next_lcg_value() / game.lcg_m;
|
||||
}
|
||||
|
||||
void make_zzword(char zzword[6])
|
||||
void make_zzword(char zzword[TOKLEN+1])
|
||||
{
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
zzword[i] = 'A' + randrange(26);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue