wb: fix 'insufficient movement' wanring when a move is interrupted

(cherry-picked from commit cdb98f75a4)
This commit is contained in:
gfgtdf 2018-05-05 19:13:22 +02:00 committed by Charles Dang
parent 49fbcce2cc
commit c6ab8eb59a
3 changed files with 14 additions and 2 deletions

View file

@ -648,7 +648,7 @@ jamming_path::~jamming_path()
{ {
} }
marked_route mark_route(const plain_route &rt) marked_route mark_route(const plain_route &rt, bool update_move_cost)
{ {
marked_route res; marked_route res;
@ -660,6 +660,7 @@ marked_route mark_route(const plain_route &rt)
const unit& u = *it; const unit& u = *it;
int turns = 0; int turns = 0;
int total_costs = 0;
int movement = u.movement_left(); int movement = u.movement_left();
const team& unit_team = resources::gameboard->get_team(u.side()); const team& unit_team = resources::gameboard->get_team(u.side());
bool zoc = false; bool zoc = false;
@ -691,6 +692,7 @@ marked_route mark_route(const plain_route &rt)
if (last_step) break; // finished and we used dummy move_cost if (last_step) break; // finished and we used dummy move_cost
total_costs += movement;
movement = u.total_movement(); movement = u.total_movement();
if(move_cost > movement) { if(move_cost > movement) {
return res; //we can't reach destination return res; //we can't reach destination
@ -701,12 +703,17 @@ marked_route mark_route(const plain_route &rt)
&& !u.get_ability_bool("skirmisher", *(i+1)); && !u.get_ability_bool("skirmisher", *(i+1));
if (zoc) { if (zoc) {
total_costs += movement;
movement = 0; movement = 0;
} else { } else {
movement -= move_cost; movement -= move_cost;
total_costs += move_cost;
} }
} }
if(update_move_cost) {
res.move_cost = total_costs;
}
return res; return res;
} }

View file

@ -198,7 +198,7 @@ plain_route a_star_search(const map_location& src, const map_location& dst,
* Add marks on a route @a rt assuming that the unit located at the first hex of * Add marks on a route @a rt assuming that the unit located at the first hex of
* rt travels along it. * rt travels along it.
*/ */
marked_route mark_route(const plain_route &rt); marked_route mark_route(const plain_route &rt, bool update_move_cost = false);
struct shortest_path_calculator : cost_calculator struct shortest_path_calculator : cost_calculator
{ {

View file

@ -271,6 +271,9 @@ void move::execute(bool& success, bool& complete)
//FIXME: probably better to use the new calculate_new_route() instead of the above: //FIXME: probably better to use the new calculate_new_route() instead of the above:
//calculate_new_route(final_location, steps.back()); //calculate_new_route(final_location, steps.back());
// Of course, "better" would need to be verified. // Of course, "better" would need to be verified.
//Update route_->move_cost
route_.reset(new pathfind::marked_route(mark_route(route_->route, true)));
arrow_->set_path(route_->steps); arrow_->set_path(route_->steps);
} }
} }
@ -479,8 +482,10 @@ action::error move::check_validity() const
//check that the path is good //check that the path is good
if(get_source_hex() != get_dest_hex()) { //skip zero-hex move used by attack subclass if(get_source_hex() != get_dest_hex()) { //skip zero-hex move used by attack subclass
// Mark the plain route to see if the move can still be done in one turn, // Mark the plain route to see if the move can still be done in one turn,
// which is always the case for planned moves // which is always the case for planned moves
// TODO: this check is rather slow, skip it if the gamestat has not changed.
pathfind::marked_route checked_route = pathfind::mark_route(get_route().route); pathfind::marked_route checked_route = pathfind::mark_route(get_route().route);
if(checked_route.marks[checked_route.steps.back()].turns != 1) { if(checked_route.marks[checked_route.steps.back()].turns != 1) {