home · contact · privacy
Server: Read in former "config" data as normal server god commands.
[plomrogue] / src / client / io.c
index 1995b14a67aca61f74fb9b710ebaa33a13169b89..c047f6985d3f9526cc45eb4fa845be77ad9677e2 100644 (file)
@@ -31,7 +31,7 @@
 static void read_inventory(char * read_buf, uint32_t linemax, FILE * file);
 
 /* Read the next characters in "file" into world.map.cells. In detail: Read
- * world.map.size.y times world.map.size.x characters, followed by one ignored
+ * world.map.length times world.map.length characters, followed by one ignored
  * character (that we assume is a newline).
  */
 static void read_map_cells(FILE * file);
@@ -68,8 +68,8 @@ static FILE * changed_worldstate_file(char * path);
  * out file wasn't read for supposedly not having changed since a last
  * read_world() call.
  *
- * map_center() is triggered by the first successful read_world() or on turn 1,
- * so the client focuses the map window on the player on client and world start.
+ * map_center() is triggered by either, the first successful read_world() (thus
+ * on client start), or on turn 1 (thus on world start).
  */
 static uint8_t read_world();
 
@@ -106,7 +106,8 @@ static void read_inventory(char * read_buf, uint32_t linemax, FILE * file)
         int new_size = strlen(read_buf);
         char * new_inventory = try_malloc(old_size + new_size + 1, f_name);
         memcpy(new_inventory, world.player_inventory, old_size);
-        sprintf(new_inventory + old_size, "%s", read_buf);
+        int test = sprintf(new_inventory + old_size, "%s", read_buf);
+        exit_trouble(test < 0, f_name, "sprintf()");
         free(world.player_inventory);
         world.player_inventory = new_inventory;
     }
@@ -120,14 +121,14 @@ static void read_map_cells(FILE * file)
 {
     char * f_name = "read_map_cells()";
     free(world.map.cells);
-    world.map.cells = try_malloc(world.map.size.y * world.map.size.x, f_name);
+    world.map.cells = try_malloc(world.map.length * world.map.length, f_name);
     uint16_t y, x;
-    for (y = 0; y < world.map.size.y; y++)
+    for (y = 0; y < world.map.length; y++)
     {
-        for (x = 0; x < world.map.size.x; x++)
+        for (x = 0; x < world.map.length; x++)
         {
             char c = try_fgetc(file, f_name);
-            world.map.cells[(y * world.map.size.x) + x] = c;
+            world.map.cells[(y * world.map.length) + x] = c;
         }
         try_fgetc(file, f_name);
     }
@@ -150,7 +151,8 @@ static void read_log(char * read_buf, uint32_t linemax, FILE * file)
         int new_size = strlen(read_buf);
         char * new_log = try_malloc(old_size + new_size + 1, f_name);
         memcpy(new_log, world.log, old_size);
-        sprintf(new_log + old_size, "%s", read_buf);
+        int test = sprintf(new_log + old_size, "%s", read_buf);
+        exit_trouble(test < 0, f_name, "sprintf()");
         free(world.log);
         world.log = new_log;
     }
@@ -216,8 +218,7 @@ static uint8_t read_world()
         map_center();
         first_read = 0;
     }
-    world.map.size.y = read_value_from_line(read_buf, linemax, file);
-    world.map.size.x = read_value_from_line(read_buf, linemax, file);
+    world.map.length = read_value_from_line(read_buf, linemax, file);
     read_map_cells(file);
     read_log(read_buf, linemax, file);
     free(read_buf);
@@ -282,6 +283,7 @@ extern char * io_loop()
     world.halfdelay = 1;            /* Ensures read_world() is only called 10 */
     halfdelay(world.halfdelay);     /* times a second during user inactivity. */
     uint8_t change_in_client = 0;
+    uint16_t last_focused_turn = world.turn;
     time_t last_server_answer_time = time(0);
     while (1)
     {
@@ -293,8 +295,13 @@ extern char * io_loop()
             world.winch = 0;
             change_in_client++;
         }
-        if (read_world() || change_in_client)
+        if (change_in_client || read_world())
         {
+            if (world.turn != last_focused_turn && world.focus_each_turn)
+            {
+                last_focused_turn = world.turn;
+                map_center();
+            }
             draw_all_wins();
         }
         change_in_client = 0;