Author: cazfi Date: Thu Sep 3 05:52:16 2015 New Revision: 29762 URL: http://svn.gna.org/viewcvs/freeciv?rev=29762&view=rev Log: Refactored base_native_pos_to_tile() to make map wrapping checks just once.
See patch #6305 Modified: trunk/common/map.c Modified: trunk/common/map.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/map.c?rev=29762&r1=29761&r2=29762&view=diff ============================================================================== --- trunk/common/map.c (original) +++ trunk/common/map.c Thu Sep 3 05:52:16 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