mail[Wesnoth-commits] r20654 - in /trunk/src: map.cpp map.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by alinktomine on September 22, 2007 - 02:02:
Author: alink
Date: Sat Sep 22 02:02:14 2007
New Revision: 20654

URL: http://svn.gna.org/viewcvs/wesnoth?rev=20654&view=rev
Log:
Enhance get_direction() to allow to do more than one step in a direction
(also support negative number of steps by giving backward direction)

Modified:
    trunk/src/map.cpp
    trunk/src/map.hpp

Modified: trunk/src/map.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map.cpp?rev=20654&r1=20653&r2=20654&view=diff
==============================================================================
--- trunk/src/map.cpp (original)
+++ trunk/src/map.cpp Sat Sep 22 02:02:14 2007
@@ -218,15 +218,19 @@
 }
 
 gamemap::location gamemap::location::get_direction(
-                                     gamemap::location::DIRECTION dir) const
-{
+                       gamemap::location::DIRECTION dir, int n) const
+{
+       if (n < 0 ) {
+               dir = get_opposite_dir(dir);
+               n = -n;
+       }
        switch(dir) {
-               case NORTH:      return gamemap::location(x,y-1);
-               case NORTH_EAST: return gamemap::location(x+1,y-is_even(x));
-               case SOUTH_EAST: return gamemap::location(x+1,y+is_odd(x));
-               case SOUTH:      return gamemap::location(x,y+1);
-               case SOUTH_WEST: return gamemap::location(x-1,y+is_odd(x));
-               case NORTH_WEST: return gamemap::location(x-1,y-is_even(x));
+               case NORTH:      return gamemap::location(x, y - n);
+               case SOUTH:      return gamemap::location(x, y + n);
+               case SOUTH_EAST: return gamemap::location(x + n, y + 
(n+is_odd(x))/2 );
+               case SOUTH_WEST: return gamemap::location(x - n, y + 
(n+is_odd(x))/2 );
+               case NORTH_EAST: return gamemap::location(x + n, y - 
(n+is_even(x))/2 );
+               case NORTH_WEST: return gamemap::location(x - n, y - 
(n+is_even(x))/2 );
                default:
                        wassert(false);
                        return gamemap::location();

Modified: trunk/src/map.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map.hpp?rev=20654&r1=20653&r2=20654&view=diff
==============================================================================
--- trunk/src/map.hpp (original)
+++ trunk/src/map.hpp Sat Sep 22 02:02:14 2007
@@ -92,7 +92,8 @@
                location operator-(const location &a) const;
                location &operator-=(const location &a);
 
-               location get_direction(DIRECTION d) const;
+               // do n step in the direction d 
+               location get_direction(DIRECTION d, int n = 1) const;
                DIRECTION get_relative_dir(location loc) const;
                static DIRECTION get_opposite_dir(DIRECTION d);
 




Related Messages


Powered by MHonArc, Updated Sat Sep 22 02:20:40 2007