[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src pathfind.cpp
From: |
Guillaume Melquiond |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src pathfind.cpp |
Date: |
Fri, 10 Dec 2004 19:01:20 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Guillaume Melquiond <address@hidden> 04/12/10 23:43:30
Modified files:
src : pathfind.cpp
Log message:
Fix pathfinding bug with many-turns-ahead computations (#11196). Also
remove some ugliness along the way.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/pathfind.cpp.diff?tr1=1.49&tr2=1.50&r1=text&r2=text
Patches:
Index: wesnoth/src/pathfind.cpp
diff -u wesnoth/src/pathfind.cpp:1.49 wesnoth/src/pathfind.cpp:1.50
--- wesnoth/src/pathfind.cpp:1.49 Fri Dec 10 23:20:06 2004
+++ wesnoth/src/pathfind.cpp Fri Dec 10 23:43:29 2004
@@ -1,4 +1,4 @@
-/* $Id: pathfind.cpp,v 1.49 2004/12/10 23:20:06 silene Exp $ */
+/* $Id: pathfind.cpp,v 1.50 2004/12/10 23:43:29 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -507,8 +507,7 @@
}
}
- const double base_cost(
- unit_.movement_cost(map_,map_[loc.x][loc.y]));
+ int const base_cost = unit_.movement_cost(map_, map_[loc.x][loc.y]);
//supposing we had 2 movement left, and wanted to move onto a hex which
//takes 3 movement, it's going to cost us 5 movement in total, since we
@@ -516,12 +515,13 @@
const int current_cost(static_cast<int>(so_far));
const int starting_movement = unit_.movement_left();
- const int remaining_movement = current_cost <= starting_movement ?
- starting_movement - current_cost :
- (current_cost-starting_movement)%unit_.total_movement();
+ int remaining_movement = starting_movement - current_cost;
+ if (remaining_movement < 0) {
+ int total = unit_.total_movement();
+ remaining_movement = total - (-remaining_movement) % total;
+ }
- const double additional_cost = int(base_cost) > remaining_movement ?
- double(remaining_movement) : double(0);
+ int additional_cost = base_cost > remaining_movement ?
remaining_movement : 0;
return base_cost + additional_cost;
}