world.monster = 0;
world.item = 0;
init_map_object_defs(&world, "defs");
- uint8_t fail = 0;
+ uint8_t err = 0;
/* For interactive mode, try to load world state from savefile. */
FILE * file;
if (1 == world.interactive && 0 == access("savefile", F_OK))
{
file = fopen("savefile", "r");
- fail = fail | read_uint32_bigendian(file, &world.seed);
- fail = fail | read_uint32_bigendian(file, &world.turn);
- fail = fail | read_uint16_bigendian(file, &player.pos.y);
- fail = fail | read_uint16_bigendian(file, &player.pos.x);
+ err = err | read_uint32_bigendian(file, &world.seed);
+ err = err | read_uint32_bigendian(file, &world.turn);
+ err = err | read_uint16_bigendian(file, &player.pos.y);
+ err = err | read_uint16_bigendian(file, &player.pos.x);
player.pos.y--;
player.pos.x--;
- fail = fail | read_uint8(file, &player.hitpoints);
- fail = fail | read_map_objects(&world, &world.monster, file);
- fail = fail | read_map_objects(&world, &world.item, file);
+ err = err | read_uint8(file, &player.hitpoints);
+ err = err | read_map_objects(&world, &world.monster, file);
+ err = err | read_map_objects(&world, &world.item, file);
fclose(file);
}
if (0 == world.interactive)
{
file = fopen("record", "r");
- fail = fail | read_uint32_bigendian(file, &world.seed);
+ err = err | read_uint32_bigendian(file, &world.seed);
}
/* For interactive-mode in newly started world, generate a start seed
{
file = fopen("record", "w");
world.seed = time(NULL);
- fail = fail | write_uint32_bigendian(world.seed, file);
+ err = err | write_uint32_bigendian(world.seed, file);
fclose(file);
}
}
- exit_err(fail, &world, "Failure initializing game.");
+ exit_err(err, &world, "Failure initializing game.");
/* Generate map from seed and, if newly generated world, start positions of
{
struct MapObj * map_obj;
struct MapObjDef * mod;
- uint8_t fail = 0;
+ uint8_t err = 0;
for (map_obj = start; map_obj != 0; map_obj = map_obj->next)
{
- fail = fail | write_uint8(map_obj->type, file);
- fail = fail | write_uint16_bigendian(map_obj->pos.y + 1, file);
- fail = fail | write_uint16_bigendian(map_obj->pos.x + 1, file);
+ err = err | write_uint8(map_obj->type, file);
+ err = err | write_uint16_bigendian(map_obj->pos.y + 1, file);
+ err = err | write_uint16_bigendian(map_obj->pos.x + 1, file);
mod = get_map_obj_def(world, map_obj->type);
if ('m' == mod->m_or_i)
{
- fail = fail | write_map_objects_monsterdata(map_obj, file);
+ err = err | write_map_objects_monsterdata(map_obj, file);
}
}
- return (fail | write_uint16_bigendian(0, file));
+ return (err | write_uint16_bigendian(0, file));
}
char first = 1;
long pos;
uint16_t read_uint16 = 0;
- uint8_t fail = 0;
+ uint8_t err = 0;
while (1)
{
pos = ftell(file);
- fail = fail | read_uint16_bigendian(file, &read_uint16);
+ err = err | read_uint16_bigendian(file, &read_uint16);
if (0 == read_uint16)
{
break;
}
fseek(file, pos, SEEK_SET);
- fail = fail | read_uint8(file, &type);
+ err = err | read_uint8(file, &type);
mod = get_map_obj_def(world, type);
if ('m' == mod->m_or_i)
{
}
map_obj = get_next_map_obj(start, &first, size, map_obj);
map_obj->type = type;
- fail = fail | read_uint16_bigendian(file, &map_obj->pos.y);
- fail = fail | read_uint16_bigendian(file, &map_obj->pos.x);
+ err = err | read_uint16_bigendian(file, &map_obj->pos.y);
+ err = err | read_uint16_bigendian(file, &map_obj->pos.x);
map_obj->pos.y--;
map_obj->pos.x--;
if ('m' == mod->m_or_i)
{
- fail = fail | read_map_objects_monsterdata(map_obj, file);
+ err = err | read_map_objects_monsterdata(map_obj, file);
}
}
if (!first)
{
map_obj->next = 0;
}
- return fail;
+ return err;
}
extern void save_game(struct World * world)
{
- uint8_t fail;
+ uint8_t err;
FILE * file = fopen("savefile", "w");
- fail = write_uint32_bigendian(world->seed, file);
- fail = fail | write_uint32_bigendian(world->turn, file);
- fail = fail | write_uint16_bigendian(world->player->pos.y + 1, file);
- fail = fail | write_uint16_bigendian(world->player->pos.x + 1, file);
- fail = fail | write_uint8(world->player->hitpoints, file);
- fail = fail | write_map_objects(world, world->monster, file);
- fail = fail | write_map_objects(world, world->item, file);
- exit_err(fail, world, "Error saving game.");
+ err = write_uint32_bigendian(world->seed, file);
+ err = err | write_uint32_bigendian(world->turn, file);
+ err = err | write_uint16_bigendian(world->player->pos.y + 1, file);
+ err = err | write_uint16_bigendian(world->player->pos.x + 1, file);
+ err = err | write_uint8(world->player->hitpoints, file);
+ err = err | write_map_objects(world, world->monster, file);
+ err = err | write_map_objects(world, world->item, file);
+ exit_err(err, world, "Error saving game.");
fclose(file);
}
extern uint8_t read_uint8(FILE * file, uint8_t * x)
{
uint32_t y = * x;
- uint8_t fail = read_uintX_bigendian(file, &y, 8);
+ uint8_t err = read_uintX_bigendian(file, &y, 8);
* x = (uint8_t) y;
- return fail;
+ return err;
}
extern uint8_t read_uint16_bigendian(FILE * file, uint16_t * x)
{
uint32_t y = * x;
- uint8_t fail = read_uintX_bigendian(file, &y, 16);
+ uint8_t err = read_uintX_bigendian(file, &y, 16);
* x = (uint16_t) y;
- return fail;
+ return err;
}
-extern void exit_err(unsigned char fail, struct World * world, char * msg)
+extern void exit_err(unsigned char err, struct World * world, char * msg)
{
- if (0 == fail)
+ if (0 == err)
{
return;
}
-/* If fail != 0, exit with an error message "msg" and clean up. (For "fail",
+/* If "err" != 0, exit with an error message "msg" and clean up. (For "err",
* pass the result of functions that return non-zero as an error status and
* thereby avoid bloating up the code with if-error-conditionals.)
*/
-extern void exit_err(unsigned char fail, struct World * world, char * msg);
+extern void exit_err(unsigned char err, struct World * world, char * msg);