Author: cazfi
Date: Thu Sep  3 05:52:22 2015
New Revision: 29763

URL: http://svn.gna.org/viewcvs/freeciv?rev=29763&view=rev
Log:
Refactored base_native_pos_to_tile() to make map wrapping checks just once.

See patch #6305

Modified:
    branches/S2_6/common/map.c

Modified: branches/S2_6/common/map.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/map.c?rev=29763&r1=29762&r2=29763&view=diff
==============================================================================
--- branches/S2_6/common/map.c  (original)
+++ branches/S2_6/common/map.c  Thu Sep  3 05:52:22 2015
@@ -369,19 +369,18 @@
 ****************************************************************************/
 static inline struct tile *base_native_pos_to_tile(int nat_x, int nat_y)
 {
+  /* Wrap in X and Y directions, as needed. */
   /* If the position is out of range in a non-wrapping direction, it is
    * unreal. */
-  if (!((current_topo_has_flag(TF_WRAPX) || (nat_x >= 0 && nat_x < map.xsize))
-       && (current_topo_has_flag(TF_WRAPY) || (nat_y >= 0 && nat_y < 
map.ysize)))) {
-    return NULL;
-  }
-
-  /* Wrap in X and Y directions, as needed. */
   if (current_topo_has_flag(TF_WRAPX)) {
     nat_x = FC_WRAP(nat_x, map.xsize);
+  } else if (nat_x < 0 || nat_x >= map.xsize) {
+    return NULL;
   }
   if (current_topo_has_flag(TF_WRAPY)) {
     nat_y = FC_WRAP(nat_y, map.ysize);
+  } else if (nat_y < 0 || nat_y >= map.ysize) {
+    return NULL;
   }
 
   return map.tiles + native_pos_to_index(nat_x, nat_y);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to