home · contact · privacy
Server: Start hardcoded_strings s's enum names with prefix "S_".
[plomrogue] / src / server / field_of_view.c
index 7436f055854464194cc3fcdd429fb870f0382393..177143a26389758d053f93d3121321f453eb29dc 100644 (file)
 
 
 
-/* Number of degrees a circle is divided into. */
-#define CIRCLE 36000000
-
-
-
-/* Values for mv_yx_in_dir_wrap()'s wrapping directory memory. */
-enum wraps
-{
-    WRAP_N = 0x01,
-    WRAP_S = 0x02,
-    WRAP_E = 0x04,
-    WRAP_W = 0x08
-};
+/* 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 (TODO: more research!).
+ */
+#define CIRCLE 3600000
 
 
 
@@ -131,10 +123,11 @@ static void mv_yx_in_hex_dir(char d, struct yx_uint8 * yx)
 
 static uint8_t mv_yx_in_dir_wrap(char d, struct yx_uint8 * yx, uint8_t unwrap)
 {
-    static uint8_t wrap = 0;
+    static int8_t wrap_west_east   = 0;
+    static int8_t wrap_north_south = 0;
     if (unwrap)
     {
-        wrap = 0;
+        wrap_west_east = wrap_north_south = 0;
         return 0;
     }
     struct yx_uint8 original;
@@ -143,21 +136,21 @@ static uint8_t mv_yx_in_dir_wrap(char d, struct yx_uint8 * yx, uint8_t unwrap)
     mv_yx_in_hex_dir(d, yx);
     if      (strchr("edc", d) && yx->x < original.x)
     {
-        wrap = wrap & WRAP_W ? wrap ^ WRAP_W : wrap | WRAP_E;
+        wrap_west_east++;
     }
     else if (strchr("xsw", d) && yx->x > original.x)
     {
-        wrap = wrap & WRAP_E ? wrap ^ WRAP_E : wrap | WRAP_W;
+        wrap_west_east--;
     }
     if      (strchr("we", d) && yx->y > original.y)
     {
-        wrap = wrap & WRAP_S ? wrap ^ WRAP_S : wrap | WRAP_N;
+        wrap_north_south--;
     }
     else if (strchr("xc", d) && yx->y < original.y)
     {
-        wrap = wrap & WRAP_N ? wrap ^ WRAP_N : wrap | WRAP_S;
+        wrap_north_south++;
     }
-    return wrap;
+    return (wrap_west_east != 0) + (wrap_north_south != 0);
 }