extern void ai(struct Thing * t)
{
- t->command = get_thing_action_id_by_name(s[CMD_WAIT]);
+ t->command = get_thing_action_id_by_name(s[S_CMD_WAIT]);
char sel = t->fov_map ? get_dir_to_nearest_enemy(t) : 0;/* t->fov_map may */
if (0 != sel) /* be absent due */
{ /* to god command.*/
- t->command = get_thing_action_id_by_name(s[CMD_MOVE]);
+ t->command = get_thing_action_id_by_name(s[S_CMD_MOVE]);
t->arg = sel;
}
}
free(world.map.cells);
if (cleanup_flags & CLEANUP_WORLDSTATE)
{
- unlink(s[PATH_WORLDSTATE]);
+ unlink(s[S_PATH_WORLDSTATE]);
}
if (cleanup_flags & CLEANUP_THINGS)
{
if (cleanup_flags & CLEANUP_IN)
{
try_fclose(world.file_in, f_name);
- unlink(s[PATH_IN]);
+ unlink(s[S_PATH_IN]);
}
if (cleanup_flags & CLEANUP_OUT)
{
try_fclose(world.file_out, f_name);
free(world.server_test);
- unlink(s[PATH_OUT]);
+ unlink(s[S_PATH_OUT]);
}
}
&& parse_flagval(token0, token1, "NAME", action_flags,
NAME_SET, 's', (char *) &ta->name))
{
- if (!( try_func_name(ta, s[CMD_MOVE], actor_move)
- || try_func_name(ta, s[CMD_PICKUP], actor_pick)
- || try_func_name(ta, s[CMD_DROP], actor_drop)
- || try_func_name(ta, s[CMD_USE], actor_use)))
+ if (!( try_func_name(ta, s[S_CMD_MOVE], actor_move)
+ || try_func_name(ta, s[S_CMD_PICKUP], actor_pick)
+ || try_func_name(ta, s[S_CMD_DROP], actor_drop)
+ || try_func_name(ta, s[S_CMD_USE], actor_use)))
{
ta->func = actor_wait;
}
extern void read_config_file()
{
- parse_file(s[PATH_CONFIG], tokens_into_entries);
+ parse_file(s[S_PATH_CONFIG], tokens_into_entries);
exit_err(!world.map.length, "Map size not defined in config file.");
uint8_t player_type_is_valid = 0;
struct ThingType * tt;
extern void init_strings()
{
- s[PATH_CONFIG] = "confserver/world";
- s[PATH_WORLDSTATE] = "server/worldstate";
- s[PATH_OUT] = "server/out";
- s[PATH_IN] = "server/in";
- s[PATH_RECORD] = "record";
- s[PATH_SUFFIX_TMP] = "_tmp";
- s[PATH_SAVE] = "savefile";
- s[CMD_MAKE_WORLD] = "MAKE_WORLD";
- s[CMD_DO_FOV] = "BUILD_FOVS";
- s[CMD_SEED_MAP] = "SEED_MAP";
- s[CMD_SEED_RAND] = "SEED_RANDOMNESS";
- s[CMD_TURN] = "TURN";
- s[CMD_THING] = "THING";
- s[CMD_TYPE] = "TYPE";
- s[CMD_POS_Y] = "POS_Y";
- s[CMD_POS_X] = "POS_X";
- s[CMD_COMMAND] = "COMMAND";
- s[CMD_ARGUMENT] = "ARGUMENT";
- s[CMD_PROGRESS] = "PROGRESS";
- s[CMD_LIFEPOINTS] = "LIFEPOINTS";
- s[CMD_CARRIES] = "CARRIES";
- s[CMD_WAIT] = "wait";
- s[CMD_MOVE] = "move";
- s[CMD_PICKUP] = "pick_up";
- s[CMD_DROP] = "drop";
- s[CMD_USE] = "use";
+ s[S_PATH_CONFIG] = "confserver/world";
+ s[S_PATH_WORLDSTATE] = "server/worldstate";
+ s[S_PATH_OUT] = "server/out";
+ s[S_PATH_IN] = "server/in";
+ s[S_PATH_RECORD] = "record";
+ s[S_PATH_SUFFIX_TMP] = "_tmp";
+ s[S_PATH_SAVE] = "savefile";
+ s[S_CMD_MAKE_WORLD] = "MAKE_WORLD";
+ s[S_CMD_DO_FOV] = "BUILD_FOVS";
+ s[S_CMD_SEED_MAP] = "SEED_MAP";
+ s[S_CMD_SEED_RAND] = "SEED_RANDOMNESS";
+ s[S_CMD_TURN] = "TURN";
+ s[S_CMD_THING] = "THING";
+ s[S_CMD_TYPE] = "TYPE";
+ s[S_CMD_POS_Y] = "POS_Y";
+ s[S_CMD_POS_X] = "POS_X";
+ s[S_CMD_COMMAND] = "COMMAND";
+ s[S_CMD_ARGUMENT] = "ARGUMENT";
+ s[S_CMD_PROGRESS] = "PROGRESS";
+ s[S_CMD_LIFEPOINTS] = "LIFEPOINTS";
+ s[S_CMD_CARRIES] = "CARRIES";
+ s[S_CMD_WAIT] = "wait";
+ s[S_CMD_MOVE] = "move";
+ s[S_CMD_PICKUP] = "pick_up";
+ s[S_CMD_DROP] = "drop";
+ s[S_CMD_USE] = "use";
}
enum string_num
{
- PATH_CONFIG,
- PATH_WORLDSTATE,
- PATH_OUT,
- PATH_IN,
- PATH_RECORD,
- PATH_SUFFIX_TMP,
- PATH_SAVE,
- CMD_MAKE_WORLD,
- CMD_DO_FOV,
- CMD_SEED_MAP,
- CMD_SEED_RAND,
- CMD_TURN,
- CMD_THING,
- CMD_TYPE,
- CMD_POS_Y,
- CMD_POS_X,
- CMD_COMMAND,
- CMD_ARGUMENT,
- CMD_PROGRESS,
- CMD_LIFEPOINTS,
- CMD_CARRIES,
- CMD_WAIT,
- CMD_MOVE,
- CMD_PICKUP,
- CMD_DROP,
- CMD_USE
+ S_S_PATH_CONFIG,
+ S_S_PATH_WORLDSTATE,
+ S_S_PATH_OUT,
+ S_S_PATH_IN,
+ S_S_PATH_RECORD,
+ S_S_PATH_SUFFIX_TMP,
+ S_S_PATH_SAVE,
+ S_S_CMD_MAKE_WORLD,
+ S_S_CMD_DO_FOV,
+ S_S_CMD_SEED_MAP,
+ S_S_CMD_SEED_RAND,
+ S_S_CMD_TURN,
+ S_S_CMD_THING,
+ S_S_CMD_TYPE,
+ S_S_CMD_POS_Y,
+ S_S_CMD_POS_X,
+ S_S_CMD_COMMAND,
+ S_S_CMD_ARGUMENT,
+ S_S_CMD_PROGRESS,
+ S_S_CMD_LIFEPOINTS,
+ S_S_CMD_CARRIES,
+ S_S_CMD_WAIT,
+ S_S_CMD_MOVE,
+ S_S_CMD_PICKUP,
+ S_S_CMD_DROP,
+ S_S_CMD_USE
};
extern void init_strings();
static void replay_game()
{
char * f_name = "replay_game()";
- exit_err(access(s[PATH_RECORD], F_OK), "No record found to replay.");
- FILE * file = try_fopen(s[PATH_RECORD], "r", f_name);
+ exit_err(access(s[S_PATH_RECORD], F_OK), "No record found to replay.");
+ FILE * file = try_fopen(s[S_PATH_RECORD], "r", f_name);
uint32_t linemax = textfile_width(file);
char * line = try_malloc(linemax + 1, f_name);
while ( world.turn < world.replay
char * f_name = "setup_server_io()";
int test = mkdir("server", 0700);
exit_trouble(test && EEXIST != errno, f_name, "mkdir()");
- world.file_out = try_fopen(s[PATH_OUT], "w", f_name);
+ world.file_out = try_fopen(s[S_PATH_OUT], "w", f_name);
world.server_test = try_malloc(10 + 1 + 10 + 1 + 1, f_name);
test = sprintf(world.server_test, "%d %d\n", getpid(), (int) time(0));
exit_trouble(test < 0, f_name, "sprintf()");
world.file_out, f_name);
fflush(world.file_out);
set_cleanup_flag(CLEANUP_OUT);
- char * path_in = s[PATH_IN];
+ char * path_in = s[S_PATH_IN];
if (!access(path_in, F_OK)) /* This keeps out input from old input */
{ /* file streams of clients */
unlink(path_in) ; /* communicating with server processes */
{
t->fov_map = t->lifepoints ? build_fov_map(t) : NULL;
}
- if (!world.replay && !access(s[PATH_RECORD], F_OK))
+ if (!world.replay && !access(s[S_PATH_RECORD], F_OK))
{
- exit_trouble(unlink(s[PATH_RECORD]), f_name, "unlink()");
+ exit_trouble(unlink(s[S_PATH_RECORD]), f_name, "unlink()");
}
world.turn = 1;
}
replay_game();
return;
}
- char * path_savefile = s[PATH_SAVE];
+ char * path_savefile = s[S_PATH_SAVE];
if (!access(path_savefile, F_OK))
{
FILE * file = try_fopen(path_savefile, "r", f_name);
}
else
{
- char * command = s[CMD_MAKE_WORLD];
+ char * command = s[S_CMD_MAKE_WORLD];
char * msg = try_malloc(strlen(command) + 1 + 11 + 1, f_name);
int test = sprintf(msg, "%s %d", command, (int) time(NULL));
exit_trouble(test < 0, f_name, "sprintf()");
{
write_thing(file, o);
}
- write_key_value(file, s[CMD_THING], t->id);
- write_key_value(file, s[CMD_TYPE], t->type);
- write_key_value(file, s[CMD_POS_Y], t->pos.y);
- write_key_value(file, s[CMD_POS_X], t->pos.x);
- write_key_value(file, s[CMD_COMMAND], t->command);
- write_key_value(file, s[CMD_ARGUMENT], t->arg);
- write_key_value(file, s[CMD_PROGRESS], t->progress);
- write_key_value(file, s[CMD_LIFEPOINTS], t->lifepoints);
+ write_key_value(file, s[S_CMD_THING], t->id);
+ write_key_value(file, s[S_CMD_TYPE], t->type);
+ write_key_value(file, s[S_CMD_POS_Y], t->pos.y);
+ write_key_value(file, s[S_CMD_POS_X], t->pos.x);
+ write_key_value(file, s[S_CMD_COMMAND], t->command);
+ write_key_value(file, s[S_CMD_ARGUMENT], t->arg);
+ write_key_value(file, s[S_CMD_PROGRESS], t->progress);
+ write_key_value(file, s[S_CMD_LIFEPOINTS], t->lifepoints);
for (o = t->owns; o; o = o->next)
{
- write_key_value(file, s[CMD_CARRIES], o->id);
+ write_key_value(file, s[S_CMD_CARRIES], o->id);
}
try_fputc('\n', file, f_name);
}
static void update_worldstate_file()
{
char * f_name = "update_worldstate_file()";
- uint16_t size = strlen(s[PATH_WORLDSTATE]) + strlen(s[PATH_SUFFIX_TMP]) + 1;
+ uint16_t size = strlen(s[S_PATH_WORLDSTATE])+strlen(s[S_PATH_SUFFIX_TMP])+1;
char * path_tmp = try_malloc(size, f_name);
- int test = sprintf(path_tmp, "%s%s", s[PATH_WORLDSTATE],s[PATH_SUFFIX_TMP]);
+ int test=sprintf(path_tmp,"%s%s",s[S_PATH_WORLDSTATE],s[S_PATH_SUFFIX_TMP]);
exit_trouble(test < 0, f_name, "sprintf()");
FILE * file = try_fopen(path_tmp, "w", f_name);
struct Thing * player = get_player();
{
try_fwrite(world.log, strlen(world.log), 1, file, f_name);
}
- try_fclose_unlink_rename(file, path_tmp, s[PATH_WORLDSTATE], f_name);
+ try_fclose_unlink_rename(file, path_tmp, s[S_PATH_WORLDSTATE], f_name);
free(path_tmp);
set_cleanup_flag(CLEANUP_WORLDSTATE);
char * dot = ".\n";;
extern void save_world()
{
char * f_name = "save_world()";
- char * path = s[PATH_SAVE];
+ char * path = s[S_PATH_SAVE];
FILE * file = try_fopen(path, "w", f_name);
- write_key_value(file, s[CMD_DO_FOV], 0);
+ write_key_value(file, s[S_CMD_DO_FOV], 0);
try_fputc('\n', file, f_name);
- write_key_value(file, s[CMD_SEED_MAP], world.seed_map);
- write_key_value(file, s[CMD_SEED_RAND], world.seed);
- write_key_value(file, s[CMD_TURN], world.turn);
+ write_key_value(file, s[S_CMD_SEED_MAP], world.seed_map);
+ write_key_value(file, s[S_CMD_SEED_RAND], world.seed);
+ write_key_value(file, s[S_CMD_TURN], world.turn);
try_fputc('\n', file, f_name);
struct Thing * t;
for (t = world.things; t; t = t->next)
{
write_thing(file, t);
}
- write_key_value(file, s[CMD_DO_FOV], 1);
+ write_key_value(file, s[S_CMD_DO_FOV], 1);
try_fclose(file, f_name);
}
static uint8_t parse_carry(char * tok0, char * tok1, struct Thing * t)
{
uint8_t id;
- if (parse_val(tok0, tok1, s[CMD_CARRIES], '8', (char *) &id))
+ if (parse_val(tok0, tok1, s[S_CMD_CARRIES], '8', (char *) &id))
{
if (!err_line(id == t->id, "Thing cannot carry itself."))
{
static uint8_t parse_position(char* tok0, char * tok1, struct Thing * t)
{
char axis = 0;
- if (!strcmp(tok0, s[CMD_POS_Y]))
+ if (!strcmp(tok0, s[S_CMD_POS_Y]))
{
axis = 'y';
}
- else if (!strcmp(tok0, s[CMD_POS_X]))
+ else if (!strcmp(tok0, s[S_CMD_POS_X]))
{
axis = 'x';
}
static uint8_t parse_thing_type(char * tok0, char * tok1, struct Thing * t)
{
uint8_t type;
- if (parse_val(tok0, tok1, s[CMD_TYPE], '8', (char *) &type))
+ if (parse_val(tok0, tok1, s[S_CMD_TYPE], '8', (char *) &type))
{
struct ThingType * tt = world.thing_types;
for (; NULL != tt && type != tt->id; tt = tt->next);
static uint8_t parse_thing_command(char * tok0, char * tok1, struct Thing * t)
{
uint8_t command;
- if (parse_val(tok0, tok1, s[CMD_COMMAND], '8', (char *) &command))
+ if (parse_val(tok0, tok1, s[S_CMD_COMMAND], '8', (char *) &command))
{
if (!command)
{
static uint8_t parse_do_fov(char * tok0, char * tok1)
{
- if (parse_val(tok0, tok1, s[CMD_DO_FOV], '8', (char *) &do_fov))
+ if (parse_val(tok0, tok1, s[S_CMD_DO_FOV], '8', (char *) &do_fov))
{
if (do_fov)
{
static struct Thing * t = NULL;
if (t && ( parse_thing_type(tok0, tok1, t)
|| parse_thing_command(tok0, tok1, t)
- || parse_val(tok0, tok1, s[CMD_ARGUMENT], '8', (char *)&t->arg)
- || parse_val(tok0, tok1, s[CMD_PROGRESS],'8',(char *)&t->progress)
- || parse_val(tok0, tok1, s[CMD_LIFEPOINTS],'8',
+ || parse_val(tok0, tok1, s[S_CMD_ARGUMENT], '8', (char *)&t->arg)
+ || parse_val(tok0,tok1,s[S_CMD_PROGRESS],'8',(char *)&t->progress)
+ || parse_val(tok0, tok1, s[S_CMD_LIFEPOINTS], '8',
(char *) &t->lifepoints)
|| parse_position(tok0, tok1, t)
|| parse_carry(tok0, tok1, t)));
- else if (parse_val(tok0, tok1, s[CMD_THING], '8', (char *) &id))
+ else if (parse_val(tok0, tok1, s[S_CMD_THING], '8', (char *) &id))
{
t = get_thing(world.things, id, 1);
if (!t)
static uint8_t parse_player_command(char * tok0, char * tok1)
{
struct Thing * player = get_player();
- if ( parse_val(tok0, tok1, s[CMD_WAIT], '8', (char *) &player->arg)
- || parse_val(tok0, tok1, s[CMD_MOVE], '8', (char *) &player->arg)
- || parse_val(tok0, tok1, s[CMD_PICKUP], '8', (char *) &player->arg)
- || parse_val(tok0, tok1, s[CMD_DROP], '8', (char *) &player->arg)
- || parse_val(tok0, tok1, s[CMD_USE], '8', (char *) &player->arg))
+ if ( parse_val(tok0, tok1, s[S_CMD_WAIT], '8', (char *) &player->arg)
+ || parse_val(tok0, tok1, s[S_CMD_MOVE], '8', (char *) &player->arg)
+ || parse_val(tok0, tok1, s[S_CMD_PICKUP], '8', (char *) &player->arg)
+ || parse_val(tok0, tok1, s[S_CMD_DROP], '8', (char *) &player->arg)
+ || parse_val(tok0, tok1, s[S_CMD_USE], '8', (char *) &player->arg))
{
player->command = get_thing_action_id_by_name(tok0);
turn_over();
{
char * f_name = "server_test()";
char test[10 + 1 + 10 + 1 + 1];
- FILE * file = try_fopen(s[PATH_OUT], "r", f_name);
+ FILE * file = try_fopen(s[S_PATH_OUT], "r", f_name);
try_fgets(test, 10 + 10 + 1 + 1, file, f_name);
try_fclose(file, f_name);
if (strcmp(test, world.server_test))
static void record_msg(char * msg)
{
char * f_name = "record_msg()";
- uint16_t size = strlen(s[PATH_RECORD]) + strlen(s[PATH_SUFFIX_TMP]) + 1;
+ uint16_t size = strlen(s[S_PATH_RECORD]) + strlen(s[S_PATH_SUFFIX_TMP]) + 1;
char * path_tmp = try_malloc(size, f_name);
- int test = sprintf(path_tmp, "%s%s", s[PATH_RECORD], s[PATH_SUFFIX_TMP]);
+ int test = sprintf(path_tmp, "%s%s", s[S_PATH_RECORD],s[S_PATH_SUFFIX_TMP]);
exit_trouble(test < 0, f_name, "sprintf()");
FILE * file_tmp = try_fopen(path_tmp, "w", f_name);
- if (!access(s[PATH_RECORD], F_OK))
+ if (!access(s[S_PATH_RECORD], F_OK))
{
- FILE * file_read = try_fopen(s[PATH_RECORD], "r", f_name);
+ FILE * file_read = try_fopen(s[S_PATH_RECORD], "r", f_name);
uint32_t linemax = textfile_width(file_read);
char * line = try_malloc(linemax + 1, f_name);
while (try_fgets(line, linemax + 1, file_read, f_name))
}
try_fwrite(msg, strlen(msg), 1, file_tmp, f_name);
try_fputc('\n', file_tmp, f_name);
- try_fclose_unlink_rename(file_tmp, path_tmp, s[PATH_RECORD], f_name);
+ try_fclose_unlink_rename(file_tmp, path_tmp, s[S_PATH_RECORD], f_name);
free(path_tmp);
}
}
if ( parse_thing_manipulation(tok0, tok1)
|| parse_player_command(tok0, tok1)
- || parse_val(tok0, tok1, s[CMD_SEED_RAND], 'U', (char *) &world.seed)
- || parse_val(tok0, tok1, s[CMD_TURN], 'u', (char *) &world.turn)
+ || parse_val(tok0, tok1, s[S_CMD_SEED_RAND], 'U', (char *) &world.seed)
+ || parse_val(tok0, tok1, s[S_CMD_TURN], 'u', (char *) &world.turn)
|| parse_do_fov(tok0, tok1));
- else if (parse_val(tok0, tok1, s[CMD_SEED_MAP],'U',(char *)&world.seed_map))
+ else if (parse_val(tok0,tok1,s[S_CMD_SEED_MAP],'U',(char *)&world.seed_map))
{
remake_map();
}
- else if (parse_val(tok0, tok1, s[CMD_MAKE_WORLD],'U', (char *) &world.seed))
+ else if (parse_val(tok0, tok1, s[S_CMD_MAKE_WORLD],'U',(char *)&world.seed))
{
remake_world();
}