Author: ilor
Date: Sun Jul 20 22:45:45 2008
New Revision: 28110

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28110&view=rev
Log:
Fix gamemap::location arithmetic by making negation actually work and removing 
a workaround for that from addition, simplifying things and making locations an 
abelian group with regards to the + operator.

Modified:
    trunk/src/map.cpp

Modified: trunk/src/map.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map.cpp?rev=28110&r1=28109&r2=28110&view=diff
==============================================================================
--- trunk/src/map.cpp (original)
+++ trunk/src/map.cpp Sun Jul 20 22:45:45 2008
@@ -204,10 +204,8 @@
 
 gamemap::location gamemap::location::operator-() const
 {
-       location ret;
-       ret.x = -x;
-       ret.y = -y;
-
+       location ret(-x, -y);
+       ret.y -= x & 1; //subtract one if we're on an odd x coordinate
        return ret;
 }
 
@@ -220,16 +218,9 @@
 
 gamemap::location& gamemap::location::operator+=(const gamemap::location &a)
 {
-       bool parity = (x & 1) != 0;
-
+       y += (x & 1) * (a.x & 1); //add one if both x coords are odd
        x += a.x;
        y += a.y;
-
-       if((a.x > 0) && (a.x % 2) && parity)
-               y++;
-       if((a.x < 0) && (a.x % 2) && !parity)
-               y--;
-
        return *this;
 }
 


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to