Skip to content

Commit

Permalink
wb: fix future unit sprite missing
Browse files Browse the repository at this point in the history
fixes #2124

(cherry-picked from commit 9277a6c)
  • Loading branch information
gfgtdf authored and Vultraz committed Oct 7, 2018
1 parent 42cdcbc commit 6e943d6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
12 changes: 11 additions & 1 deletion src/fake_unit_ptr.cpp
Expand Up @@ -26,7 +26,17 @@ fake_unit_ptr::fake_unit_ptr(const internal_ptr & u, fake_unit_manager * mgr) :
{
place_on_fake_unit_manager(mgr);
}
fake_unit_ptr::fake_unit_ptr(const fake_unit_ptr & ptr) : unit_(ptr.unit_), my_manager_(nullptr) {}
fake_unit_ptr::fake_unit_ptr(const fake_unit_ptr & ptr)
: unit_(ptr.unit_)
, my_manager_(nullptr)
{}

fake_unit_ptr::fake_unit_ptr(fake_unit_ptr && ptr)
: unit_(std::move(ptr.unit_))
, my_manager_(ptr.my_manager_)
{
ptr.my_manager_ = nullptr;
}

void fake_unit_ptr::swap (fake_unit_ptr & o) {
boost::swap(unit_, o.unit_);
Expand Down
1 change: 1 addition & 0 deletions src/fake_unit_ptr.hpp
Expand Up @@ -37,6 +37,7 @@ class fake_unit_ptr {
explicit fake_unit_ptr(const internal_ptr & u); //!< Construct a fake unit pointer wrapping a normal unit pointer, marking it as a fake unit.
fake_unit_ptr(const internal_ptr & u, fake_unit_manager * mgr); //!< Construct a fake unit pointer, and simultaenously register with a manager.
fake_unit_ptr(const fake_unit_ptr & ptr); //!< Copy construct a fake unit pointer. Does not reallocate the underlying unit.
fake_unit_ptr(fake_unit_ptr && ptr);

void swap (fake_unit_ptr & o); //!< Pointer swap.

Expand Down
2 changes: 1 addition & 1 deletion src/whiteboard/attack.cpp
Expand Up @@ -54,7 +54,7 @@ std::ostream& attack::print(std::ostream& s) const

attack::attack(std::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, u, route, arrow, fake_unit),
: move(team_index, hidden, u, route, arrow, std::move(fake_unit)),
target_hex_(target_hex),
weapon_choice_(weapon_choice),
attack_movement_cost_(get_unit()->attacks()[weapon_choice_].movement_used()),
Expand Down
11 changes: 5 additions & 6 deletions src/whiteboard/manager.cpp
Expand Up @@ -782,15 +782,14 @@ void manager::save_temp_move()
continue;

std::size_t turn = first_turn + i;
fake_unit_ptr fake_unit = fake_units_[i];

//@todo Using a marked_route here is wrong, since right now it's not marked
//either switch over to a plain route for planned moves, or mark it correctly
pathfind::marked_route route;
route.steps = move_arrow->get_path();
route.move_cost = path_cost(route.steps,*u);

sa.queue_move(turn,*u,route,move_arrow,fake_unit);
sa.queue_move(turn, *u, route, move_arrow, std::move(fake_units_[i]));
}
erase_temp_move();

Expand All @@ -811,7 +810,7 @@ void manager::save_temp_attack(const map_location& attacker_loc, const map_locat
assert(weapon_choice >= 0);

arrow_ptr move_arrow;
fake_unit_ptr fake_unit;
fake_unit_ptr* fake_unit = nullptr;
map_location source_hex;

if (route_ && !route_->steps.empty())
Expand All @@ -820,12 +819,12 @@ void manager::save_temp_attack(const map_location& attacker_loc, const map_locat
assert(move_arrows_.size() == 1);
assert(fake_units_.size() == 1);
move_arrow = move_arrows_.front();
fake_unit = fake_units_.front();
fake_unit = &fake_units_.front();

assert(route_->steps.back() == attacker_loc);
source_hex = route_->steps.front();

fake_unit->anim_comp().set_disabled_ghosted(true);
(**fake_unit).anim_comp().set_disabled_ghosted(true);
}
else
{
Expand All @@ -843,7 +842,7 @@ void manager::save_temp_attack(const map_location& attacker_loc, const map_locat
validate_viewer_actions();

side_actions& sa = *viewer_actions();
sa.queue_attack(sa.get_turn_num_of(*attacking_unit),*attacking_unit,defender_loc,weapon_choice,*route_,move_arrow,fake_unit);
sa.queue_attack(sa.get_turn_num_of(*attacking_unit), *attacking_unit, defender_loc, weapon_choice, *route_, move_arrow, fake_unit ? std::move(*fake_unit) : fake_unit_ptr());

print_help_once();

Expand Down
2 changes: 1 addition & 1 deletion src/whiteboard/move.cpp
Expand Up @@ -71,7 +71,7 @@ move::move(std::size_t team_index, bool hidden, unit& u, const pathfind::marked_
movement_cost_(0),
turn_number_(0),
arrow_(arrow),
fake_unit_(fake_unit),
fake_unit_(std::move(fake_unit)),
arrow_brightness_(),
arrow_texture_(),
mover_(),
Expand Down
4 changes: 2 additions & 2 deletions src/whiteboard/side_actions.cpp
Expand Up @@ -674,13 +674,13 @@ side_actions::iterator side_actions::safe_erase(const iterator& itor)
}
side_actions::iterator side_actions::queue_move(std::size_t turn, unit& mover, const pathfind::marked_route& route, arrow_ptr arrow, fake_unit_ptr fake_unit)
{
move_ptr new_move(std::make_shared<move>(team_index(), hidden_, std::ref(mover), route, arrow, fake_unit));
move_ptr new_move(std::make_shared<move>(team_index(), hidden_, std::ref(mover), route, arrow, std::move(fake_unit)));
return queue_action(turn, new_move);
}

side_actions::iterator side_actions::queue_attack(std::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(std::make_shared<attack>(team_index(), hidden_, std::ref(mover), target_hex, weapon_choice, route, arrow, fake_unit));
attack_ptr new_attack(std::make_shared<attack>(team_index(), hidden_, std::ref(mover), target_hex, weapon_choice, route, arrow, std::move(fake_unit)));
return queue_action(turn, new_attack);
}

Expand Down

0 comments on commit 6e943d6

Please sign in to comment.