Author: darthfool
Date: Sun Apr 8 20:13:46 2007
New Revision: 16696
URL: http://svn.gna.org/viewcvs/wesnoth?rev=16696&view=rev
Log:
correct shortest path calculation to properly calculate the movment cost of
paths passing through ZOCS.
Modified:
trunk/src/mouse_events.cpp
trunk/src/pathfind.cpp
trunk/src/pathfind.hpp
trunk/src/unit_abilities.cpp
Modified: trunk/src/mouse_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.cpp?rev=16696&r1=16695&r2=16696&view=diff
==============================================================================
--- trunk/src/mouse_events.cpp (original)
+++ trunk/src/mouse_events.cpp Sun Apr 8 20:13:46 2007
@@ -918,7 +918,7 @@
}
paths::route route = a_star_search(un->first, go_to, 10000.0, &calc,
map_.x(), map_.y(), teleports);
- route.move_left = route_turns_to_complete(u,map_,route);
+ route.move_left = route_turns_to_complete(u,map_,route,units_,teams_);
return route;
}
Modified: trunk/src/pathfind.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/pathfind.cpp?rev=16696&r1=16695&r2=16696&view=diff
==============================================================================
--- trunk/src/pathfind.cpp (original)
+++ trunk/src/pathfind.cpp Sun Apr 8 20:13:46 2007
@@ -419,7 +419,6 @@
//if a better route to that tile has already
been found
if(rtit != routes.end() &&
rtit->second.move_left >= total_movement)
continue;
-
const bool skirmisher = force_ignore_zocs |
u.get_ability_bool("skirmisher",currentloc);
const bool zoc = !skirmisher &&
enemy_zoc(map,units,teams,currentloc, viewing_team,u.side(),see_all);
paths::route new_route = routes[loc];
@@ -459,7 +458,7 @@
allow_teleport,additional_turns,true,viewing_team, see_all);
}
-int route_turns_to_complete(unit const &u, gamemap const &map, paths::route
&rt)
+int route_turns_to_complete(unit const &u, gamemap const &map, paths::route
&rt,unit_map units, const std::vector<team>& teams)
{
if(rt.steps.empty())
return 0;
@@ -470,6 +469,7 @@
wassert(map.on_board(*i));
const int move_cost = u.movement_cost(map[i->x][i->y]);
movement -= move_cost;
+
if (movement < 0) {
++turns;
rt.turn_waypoints.insert(std::make_pair(*(i-1), turns));
@@ -478,6 +478,30 @@
return -1;
}
}
+
+ if (!u.get_ability_bool("skirmisher",*i)) {
+ gamemap::location adj[6];
+ get_adjacent_tiles(*i, adj);
+
+ for (size_t j = 0; j != 6; ++j) {
+ unit_map::const_iterator
+ enemy_unit = find_visible_unit(units, adj[j], map,
teams, teams[u.side()-1]),
+ units_end = units.end();
+
+ if (enemy_unit != units_end &&
teams[u.side()-1].is_enemy(enemy_unit->second.side()) &&
+ enemy_unit->second.emits_zoc()){
+
+ ++turns;
+ rt.turn_waypoints.insert(std::make_pair(*(i), turns));
+ movement = u.total_movement() - move_cost;
+ if(movement < 0) {
+ return -1;
+ }
+
+ }
+ }
+ }
+
}
//add "end-of-path" to waypoints.
@@ -507,9 +531,11 @@
//the location is not valid
//1. if the loc is shrouded, or
//2. if moving in it costs more than the total movement of the unit, or
- //3. if there is a visible enemy on the hex, or
+ //3. if there is a visible enemy on the hex, or
//4. if the unit is not a skirmisher and there is a visible enemy with
// a ZoC on an adjacent hex in the middle of the route
+ // #4 is a bad criteria! It should be that moving into a ZOC uses up
+ // the rest of your moves
if (team_.shrouded(loc.x, loc.y))
return getNoPathValue();
@@ -526,18 +552,6 @@
if (enemy_unit != units_end &&
team_.is_enemy(enemy_unit->second.side()))
return getNoPathValue();
- if (!isDst && !unit_.get_ability_bool("skirmisher",loc)) {
- gamemap::location adj[6];
- get_adjacent_tiles(loc, adj);
-
- for (size_t i = 0; i != 6; ++i) {
- enemy_unit = find_visible_unit(units_, adj[i], map_,
teams_, team_);
-
- if (enemy_unit != units_end &&
team_.is_enemy(enemy_unit->second.side()) &&
- enemy_unit->second.emits_zoc())
- return getNoPathValue();
- }
- }
//compute how many movement points are left in the game turn needed to
//reach the previous hex
@@ -550,6 +564,22 @@
//takes 3 movement, it's going to cost us 5 movement in total, since we
//sacrifice this turn's movement. Take that into account here.
int additional_cost = base_cost > remaining_movement ?
remaining_movement : 0;
+
+ if (!isDst && !unit_.get_ability_bool("skirmisher",loc)) {
+ gamemap::location adj[6];
+ get_adjacent_tiles(loc, adj);
+
+ for (size_t i = 0; i != 6; ++i) {
+ enemy_unit = find_visible_unit(units_, adj[i], map_,
teams_, team_);
+
+ if (enemy_unit != units_end &&
team_.is_enemy(enemy_unit->second.side()) &&
+ enemy_unit->second.emits_zoc())
+ // return getNoPathValue();
+ //should cost us all are remaining movement.
+ return total_movement_ + additional_cost;
+ }
+ }
+
return base_cost + additional_cost;
}
Modified: trunk/src/pathfind.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/pathfind.hpp?rev=16696&r1=16695&r2=16696&view=diff
==============================================================================
--- trunk/src/pathfind.hpp (original)
+++ trunk/src/pathfind.hpp Sun Apr 8 20:13:46 2007
@@ -110,7 +110,8 @@
//return the number of turns it will take the unit to traverse the route.
//adds "turn waypoints" to rt.turn_waypoints. note that "end of path" is also
added.
int route_turns_to_complete(const unit& u, const gamemap& map,
- paths::route& rt);
+ paths::route& rt, unit_map units,
+ const std::vector<team>& teams);
struct shortest_path_calculator : cost_calculator
{
Modified: trunk/src/unit_abilities.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_abilities.cpp?rev=16696&r1=16695&r2=16696&view=diff
==============================================================================
--- trunk/src/unit_abilities.cpp (original)
+++ trunk/src/unit_abilities.cpp Sun Apr 8 20:13:46 2007
@@ -117,6 +117,9 @@
}
}
}
+
+ if(units_== NULL) std::cout<<"ability:"<<ability<<"\n";
+
wassert(units_ != NULL);
wassert(teams_ != NULL);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits