X-Git-Url: https://plomlompom.com/repos/index.html?a=blobdiff_plain;f=src%2Fmain.c;h=eaddfa68ebc9cf3295775cb2fbbafc48506ac8d6;hb=4d9b6ac142740aa337fc3e622902c9595c36f6d0;hp=7096f6c65a536f7c9d74323602e0526997099ced;hpb=81eaa1110b9721b7e7167dcb49bd1077d7b3f016;p=plomrogue
diff --git a/src/main.c b/src/main.c
index 7096f6c..eaddfa6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -13,9 +13,7 @@
* draw_log_win()
*/
#include "keybindings.h" /* for initkeybindings(), get_action_key() */
-#include "readwrite.h" /* for read_uint16_bigendian, read_uint32_bigendian,
- * write_uint32_bigendian
- */
+#include "readwrite.h" /* for [read/write]_uint[8/16/32][_bigendian]() */
#include "map_objects.h" /* for structs Monster, Item, Player,
* init_map_object_defs(), read_map_objects(),
* build_map_objects()
@@ -62,19 +60,22 @@ int main(int argc, char *argv[])
world.monster = 0;
world.item = 0;
init_map_object_defs(&world, "defs");
+ 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");
- world.seed = read_uint32_bigendian(file);
- world.turn = read_uint32_bigendian(file);
- player.pos.y = read_uint16_bigendian(file) - 1;
- player.pos.x = read_uint16_bigendian(file) - 1;
- player.hitpoints = fgetc(file);
- read_map_objects(&world, &world.monster, file);
- read_map_objects(&world, &world.item, file);
+ 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--;
+ 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);
}
@@ -85,20 +86,23 @@ int main(int argc, char *argv[])
if (0 == world.interactive)
{
file = fopen("record", "r");
- world.seed = read_uint32_bigendian(file);
+ err = err | read_uint32_bigendian(file, &world.seed);
+ }
+
+ /* For interactive-mode in newly started world, generate a start seed
+ * from the current time.
+ */
+ else
+ {
+ file = fopen("record", "w");
+ world.seed = time(NULL);
+ err = err | write_uint32_bigendian(world.seed, file);
+ fclose(file);
}
+ }
+
+ exit_err(err, &world, "Failure initializing game.");
- /* For interactive-mode in newly started world, generate a start seed
- * from the current time.
- */
- else
- {
- file = fopen("record", "w");
- world.seed = time(NULL);
- write_uint32_bigendian(world.seed, file);
- fclose(file);
- }
- }
/* Generate map from seed and, if newly generated world, start positions of
* actors.