Author: alink
Date: Tue Jul 8 00:24:15 2008
New Revision: 27831
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27831&view=rev
Log:
Improve numerical precision and safety in the linear path calculations.
Modified:
trunk/src/astarnode.hpp
Modified: trunk/src/astarnode.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/astarnode.hpp?rev=27831&r1=27830&r2=27831&view=diff
==============================================================================
--- trunk/src/astarnode.hpp (original)
+++ trunk/src/astarnode.hpp Tue Jul 8 00:24:15 2008
@@ -52,13 +52,15 @@
// we must add 0.5 to the y coordinate when x is odd
double ydiff = (src.y - dst.y) + ((src.x & 1) - (dst.x & 1)) *
0.5;
- // 0.0001 is to avoid interfering with the defense cost (see
shortest_path_calculator::cost)
- return distance_between(src, dst)-(
- 0.0001 / sqrt( xdiff*xdiff + ydiff*ydiff)
- );
+ // we assume a map with a maximum diagonal of 300 (bigger than
a 200x200)
+ // and we divide by 300 * 10000 to avoid interfering with the
defense subcost
+ // (see shortest_path_calculator::cost)
+ return distance_between(src, dst) -
+ (300.0 - sqrt( xdiff*xdiff + ydiff*ydiff)) /
3000000.0;
+
// TODO: move the heuristic function into the cost_calculator
// so we can use case-specific heuristic
- // and clean the definition of 0.0001
+ // and clean the definition of these numbers
}
};
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits