Fixed 2 bugs.

Fixed: planning multi-turn moves that conflict with allies at some point.

Fixed: crash when planning multi-turn moves through the fog.
This commit is contained in:
Tommy Schmitz 2011-08-22 10:07:35 +00:00
parent 97755aec92
commit 79e294f9c8
8 changed files with 18 additions and 24 deletions

View file

@ -49,9 +49,9 @@ std::ostream& attack::print(std::ostream& s) const
return s;
}
attack::attack(size_t team_index, bool hidden, const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route,
attack::attack(size_t team_index, bool hidden, unit& u, const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route,
arrow_ptr arrow, fake_unit_ptr fake_unit)
: move(team_index, hidden, route, arrow, fake_unit),
: move(team_index, hidden, u, route, arrow, fake_unit),
target_hex_(target_hex),
weapon_choice_(weapon_choice),
attack_movement_cost_(get_unit()->attacks()[weapon_choice_].movement_used()),

View file

@ -31,8 +31,7 @@ public:
friend class validate_visitor;
friend class highlight_visitor;
///Future unit map must be valid during construction, so that attack can find its units
attack(size_t team_index, bool hidden, const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route,
attack(size_t team_index, bool hidden, unit& mover, const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route,
arrow_ptr arrow, fake_unit_ptr fake_unit);
attack(config const&, bool hidden); // For deserialization
virtual ~attack();

View file

@ -655,7 +655,7 @@ void manager::save_temp_move()
if (has_temp_move() && !executing_actions_ && !resources::controller->is_linger_mode())
{
side_actions& sa = *viewer_actions();
unit const *const u = future_visible_unit(route_->steps.front());
unit* u = future_visible_unit(route_->steps.front());
assert(u);
size_t first_turn = sa.get_turn_num_of(*u);
@ -673,7 +673,7 @@ void manager::save_temp_move()
route.steps = move_arrow->get_path();
route.move_cost = path_cost(route.steps,*u);
sa.queue_move(turn,route,move_arrow,fake_unit);
sa.queue_move(turn,*u,route,move_arrow,fake_unit);
}
erase_temp_move();
@ -712,7 +712,7 @@ void manager::save_temp_attack(const map_location& attack_from, const map_locati
route_->steps.push_back(attack_from);
}
unit const* attacking_unit = future_visible_unit(source_hex);
unit* attacking_unit = future_visible_unit(source_hex);
assert(attacking_unit);
int weapon_choice = resources::controller->get_mouse_handler_base().show_attack_dialog(
@ -721,7 +721,7 @@ void manager::save_temp_attack(const map_location& attack_from, const map_locati
if (weapon_choice >= 0)
{
side_actions& sa = *viewer_actions();
sa.queue_attack(sa.get_turn_num_of(*attacking_unit),target_hex,weapon_choice,*route_,move_arrow,fake_unit);
sa.queue_attack(sa.get_turn_num_of(*attacking_unit),*attacking_unit,target_hex,weapon_choice,*route_,move_arrow,fake_unit);
on_save_action();

View file

@ -85,7 +85,7 @@ bool mapbuilder::visit(size_t, team&, side_actions&, side_actions::iterator itor
action_ptr act = *itor;
unit* u = act->get_unit();
if(acted_this_turn_.find(u) == acted_this_turn_.end())
if(acted_this_turn_.find(u) != acted_this_turn_.end())
visit_helper(itor,act);
else //gotta restore MP first
{

View file

@ -58,10 +58,10 @@ std::ostream& move::print(std::ostream &s) const
return s;
}
move::move(size_t team_index, bool hidden, const pathfind::marked_route& route,
move::move(size_t team_index, bool hidden, unit& u, const pathfind::marked_route& route,
arrow_ptr arrow, fake_unit_ptr fake_unit)
: action(team_index,hidden),
unit_(NULL),
unit_(&u),
unit_id_(),
route_(new pathfind::marked_route(route)),
movement_cost_(0),
@ -73,16 +73,11 @@ move::move(size_t team_index, bool hidden, const pathfind::marked_route& route,
mover_(),
fake_unit_hidden_(false)
{
//Future unit map must be valid during construction, so that move can find its unit
scoped_planned_unit_map raii;
assert(!route_->steps.empty());
if(hidden)
fake_unit_->set_hidden(true);
unit_ = wb::future_visible_unit(get_source_hex());
this->init();
}

View file

@ -37,8 +37,8 @@ public:
friend class validate_visitor;
friend class highlight_visitor;
move(size_t team_index, bool hidden, const pathfind::marked_route& route, arrow_ptr arrow,
fake_unit_ptr fake_unit);
move(size_t team_index, bool hidden, unit& mover, const pathfind::marked_route& route,
arrow_ptr arrow, fake_unit_ptr fake_unit);
move(config const&, bool hidden); // For deserialization
virtual ~move();

View file

@ -249,19 +249,19 @@ void side_actions::show()
act->show();
}
side_actions::iterator side_actions::queue_move(size_t turn, const pathfind::marked_route& route, arrow_ptr arrow, fake_unit_ptr fake_unit)
side_actions::iterator side_actions::queue_move(size_t turn, unit& mover, const pathfind::marked_route& route, arrow_ptr arrow, fake_unit_ptr fake_unit)
{
move_ptr new_move;
new_move.reset(new move(team_index(), hidden_, route, arrow, fake_unit));
new_move.reset(new move(team_index(), hidden_, mover, route, arrow, fake_unit));
return queue_action(turn,new_move);
}
side_actions::iterator side_actions::queue_attack(size_t turn, const map_location& target_hex, int weapon_choice,
side_actions::iterator side_actions::queue_attack(size_t turn, unit& mover, const map_location& target_hex, int weapon_choice,
const pathfind::marked_route& route,
arrow_ptr arrow, fake_unit_ptr fake_unit)
{
attack_ptr new_attack;
new_attack.reset(new attack(team_index(), hidden_, target_hex, weapon_choice, route, arrow, fake_unit));
new_attack.reset(new attack(team_index(), hidden_, mover, target_hex, weapon_choice, route, arrow, fake_unit));
return queue_action(turn,new_attack);
}

View file

@ -144,14 +144,14 @@ public:
* Queues a move to be executed last
* @return The queued move's position
*/
iterator queue_move(size_t turn_num, const pathfind::marked_route& route,
iterator queue_move(size_t turn_num, unit& mover, const pathfind::marked_route& route,
arrow_ptr arrow, fake_unit_ptr fake_unit);
/**
* Queues an attack or attack-move to be executed last
* @return The queued attack's position
*/
iterator queue_attack(size_t turn_num, const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route,
iterator queue_attack(size_t turn_num, unit& mover, const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route,
arrow_ptr arrow, fake_unit_ptr fake_unit);
/**