diff --git a/src/actions/move.cpp b/src/actions/move.cpp index ec380d36c7f6..4e403a51883f 100644 --- a/src/actions/move.cpp +++ b/src/actions/move.cpp @@ -1288,37 +1288,5 @@ size_t move_unit_from_replay(const std::vector &steps, return move_unit_internal(undo_stack, show_move, NULL, mover); } -bool unit_can_move(const unit &u) -{ - const team ¤t_team = (*resources::teams)[u.side() - 1]; - - if(!u.attacks_left() && u.movement_left()==0) - return false; - - // Units with goto commands that have already done their gotos this turn - // (i.e. don't have full movement left) should have red globes. - if(u.has_moved() && u.has_goto()) { - return false; - } - - map_location locs[6]; - get_adjacent_tiles(u.get_location(), locs); - for(int n = 0; n != 6; ++n) { - if (resources::gameboard->map().on_board(locs[n])) { - const unit_map::const_iterator i = resources::units->find(locs[n]); - if (i.valid() && !i->incapacitated() && - current_team.is_enemy(i->side())) { - return true; - } - - if (u.movement_cost((resources::gameboard->map())[locs[n]]) <= u.movement_left()) { - return true; - } - } - } - - return false; -} - }//namespace actions diff --git a/src/actions/move.hpp b/src/actions/move.hpp index f9c5d4e0e5ad..2e83800c5192 100644 --- a/src/actions/move.hpp +++ b/src/actions/move.hpp @@ -114,13 +114,6 @@ size_t move_unit_from_replay(const std::vector &steps, bool continued_move, bool skip_ally_sighted, bool show_move = true); -/** - * Will return true iff the unit @a u has any possible moves - * it can do (including attacking etc). - */ -bool unit_can_move(const unit &u); - - }//namespace actions diff --git a/src/display_context.cpp b/src/display_context.cpp index 0b3690e10ce5..7385e1d6fdd8 100644 --- a/src/display_context.cpp +++ b/src/display_context.cpp @@ -29,3 +29,41 @@ const unit * display_context::get_visible_unit(const map_location & loc, const t } return &*u; } + +/** + * Will return true iff the unit @a u has any possible moves + * it can do (including attacking etc). + */ + +bool display_context::unit_can_move(const unit &u) +{ + if(!u.attacks_left() && u.movement_left()==0) + return false; + + // Units with goto commands that have already done their gotos this turn + // (i.e. don't have full movement left) should have red globes. + if(u.has_moved() && u.has_goto()) { + return false; + } + + const team ¤t_team = teams()[u.side() - 1]; + + map_location locs[6]; + get_adjacent_tiles(u.get_location(), locs); + for(int n = 0; n != 6; ++n) { + if (map().on_board(locs[n])) { + const unit_map::const_iterator i = units().find(locs[n]); + if (i.valid() && !i->incapacitated() && + current_team.is_enemy(i->side())) { + return true; + } + + if (u.movement_cost(map()[locs[n]]) <= u.movement_left()) { + return true; + } + } + } + + return false; +} + diff --git a/src/display_context.hpp b/src/display_context.hpp index b506fff6e473..218f101b7c7b 100644 --- a/src/display_context.hpp +++ b/src/display_context.hpp @@ -37,8 +37,16 @@ class display_context { virtual const gamemap & map() const = 0; virtual const unit_map & units() const = 0; + // Needed for reports + const unit * get_visible_unit(const map_location &loc, const team ¤t_team, bool see_all = false) const; + // From actions:: namespace + + bool unit_can_move(const unit & u); + + // Dtor + virtual ~display_context() {} }; diff --git a/src/menu_events.cpp b/src/menu_events.cpp index f93a0bdeed05..4ba0f6cecc43 100644 --- a/src/menu_events.cpp +++ b/src/menu_events.cpp @@ -810,7 +810,7 @@ namespace { // Helpers for menu_handler::end_turn() if ( un->side() == side_num ) { // @todo whiteboard should take into consideration units that have // a planned move but can still plan more movement in the same turn - if ( actions::unit_can_move(*un) && !un->user_end_turn() + if ( resources::gameboard->unit_can_move(*un) && !un->user_end_turn() && !resources::whiteboard->unit_has_actions(&*un) ) return true; } @@ -825,7 +825,7 @@ namespace { // Helpers for menu_handler::end_turn() { for ( unit_map::const_iterator un = units.begin(); un != units.end(); ++un ) { if ( un->side() == side_num ) { - if ( actions::unit_can_move(*un) && !un->has_moved() && !un->user_end_turn() + if ( resources::gameboard->unit_can_move(*un) && !un->has_moved() && !un->user_end_turn() && !resources::whiteboard->unit_has_actions(&*un) ) return true; } diff --git a/src/mouse_events.cpp b/src/mouse_events.cpp index 614e73eed4c1..7fce837152ff 100644 --- a/src/mouse_events.cpp +++ b/src/mouse_events.cpp @@ -1192,7 +1192,7 @@ bool mouse_handler::unit_in_cycle(unit_map::const_iterator it) return false; if (it->side() != side_num_ || it->user_end_turn() - || gui().fogged(it->get_location()) || !actions::unit_can_move(*it)) + || gui().fogged(it->get_location()) || !board_.unit_can_move(*it)) return false; if (current_team().is_enemy(int(gui().viewing_team()+1)) && diff --git a/src/unit.cpp b/src/unit.cpp index a424ebce87d9..ea156ed97e8d 100644 --- a/src/unit.cpp +++ b/src/unit.cpp @@ -2032,7 +2032,7 @@ void unit::redraw_unit () const if (preferences::show_unmoved_orb()) orb_img = &unmoved_orb; else orb_img = NULL; - } else if ( actions::unit_can_move(*this) ) { + } else if ( resources::gameboard->unit_can_move(*this) ) { if (preferences::show_partial_orb()) orb_img = &partmoved_orb; else orb_img = NULL;