From 82d6b1d84158748757619db03defd3aee4546636 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Mon, 7 Jul 2014 14:32:36 +0200
Subject: [PATCH] Server: Fix bugs in map and FOV generation on large maps.

---
 TODO                       | 2 --
 src/server/field_of_view.c | 7 +++++--
 src/server/io.c            | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/TODO b/TODO
index c48735b..76c8a47 100644
--- a/TODO
+++ b/TODO
@@ -23,8 +23,6 @@ SERVER:
 
 - ensure atomic re-writing of savefile
 
-- FOV algorithm is buggy in large maps
-
 CLIENT:
 
 - enable toggling of window borders
diff --git a/src/server/field_of_view.c b/src/server/field_of_view.c
index 7436f05..e41d837 100644
--- a/src/server/field_of_view.c
+++ b/src/server/field_of_view.c
@@ -13,8 +13,11 @@
 
 
 
-/* Number of degrees a circle is divided into. */
-#define CIRCLE 36000000
+/* Number of degrees a circle is divided into. The greater it is, the greater
+ * the angle precision. But make it one whole zero larger and bizarre FOV bugs
+ * appear on large maps, probably due to value overflows.
+ */
+#define CIRCLE 3600000
 
 
 
diff --git a/src/server/io.c b/src/server/io.c
index b2d8005..4d1b609 100644
--- a/src/server/io.c
+++ b/src/server/io.c
@@ -248,7 +248,7 @@ static char * build_visible_map(struct Thing * player)
     memset(visible_map, ' ', map_size);
     if (player->fov_map) /* May fail if player thing was created / positioned */
     {                    /* by god command after turning off FOV building.    */
-        uint16_t pos_i;
+        uint32_t pos_i;
         for (pos_i = 0; pos_i < map_size; pos_i++)
         {
             if (player->fov_map[pos_i] & VISIBLE)
-- 
2.30.2