57 #include <boost/intrusive_ptr.hpp>
58 #include <boost/shared_ptr.hpp>
63 #include <SDL_mouse.h>
64 #include <SDL_video.h>
66 namespace gui {
class slider; }
69 #define ERR_NG LOG_STREAM(err, log_engine)
70 #define LOG_NG LOG_STREAM(info, log_engine)
85 unselected_paths_(false),
89 reachmap_invalid_(false),
90 show_partial_move_(false)
117 SDL_GetMouseState(&x,&y);
128 lk->mouse_over_hex_callback(new_hex);
152 bool selected_hex_has_unit;
206 !selected_unit->incapacitated() && !browse)
208 if (attack_from.
valid()) {
211 else if (!mouseover_unit &&
223 && mouseover_unit->side() ==
side_num_ ) {
248 if (attack_from.
valid()) {
264 if (selected_unit && !selected_unit->incapacitated()) {
278 && mouseover_unit.
valid()
288 }
else if (!selected_unit) {
373 bool source_eligible = source_unit.
valid();
389 source_eligible &= source_unit->attacks_left() != 0;
399 bool target_eligible = target_unit.
valid();
403 target_eligible &= viewer.
is_enemy(target_unit->side());
407 assert(source_unit->side() != target_unit->side());
409 target_eligible &= !target_unit->incapacitated();
416 int best_rating = 100;
421 for(
size_t n = 0;
n != 6; ++
n) {
433 unsigned int difference = abs(
int(preferred - n));
434 if(difference > NDIRECTIONS/2) {
435 difference = NDIRECTIONS - difference;
437 unsigned int second_difference = abs(
int(second_preferred - n));
438 if(second_difference > NDIRECTIONS/2) {
439 second_difference = NDIRECTIONS - second_difference;
441 const int rating = difference * 2 + (second_difference > difference);
442 if(rating < best_rating || res.
valid() ==
false) {
443 best_rating = rating;
482 if (s && s->value_change())
490 if (s && s->value_change())
498 if (s && s->value_change())
506 if (s && s->value_change())
514 if (s && s->value_change())
532 (clicked_u->side() ==
side_num_ && clicked_u->id() != selected_u->id())) )
605 attack_enemy(u->get_location(), clicked_u->get_location(), choice);
616 pathfind::paths::dest_vect::const_iterator
itor =
709 u ? &*u : &*clicked_u )) {
762 u->anim_comp().set_selecting();
785 bool invisible = u->invisible(u->get_location());
787 if (!
gui_->
fogged(u->get_location()) && !u->incapacitated() && !invisible)
835 bool interrupted =
false;
836 if ( steps.size() > 1 )
840 interrupted = interrupted || num_moves + 1 < steps.size();
885 if ( u && u->can_recruit() &&
890 _(
"You cannot move your leader away from the keep with some planned recruits or recalls left."));
895 LOG_NG <<
"move unit along route from " << steps.front() <<
" to " << steps.back() <<
"\n";
904 if ( interrupted && moves + 1 < steps.size() ) {
906 select_hex(steps[moves],
false,
false,
false);
941 pc_.
get_whiteboard()->save_temp_attack(attacker_loc, defender_loc, weapon_choice);
948 for (
unsigned int i = 0;
i < attacker->attacks().size();
i++) {
950 if (attacker->attacks()[
i].attack_weight() > 0) {
952 bc_vector.push_back(bc);
953 if (bc.better_attack(bc_vector[best], 0.5)) {
955 best = bc_vector.size() - 1;
968 if(!attacker || !defender) {
969 ERR_NG <<
"One fighter is missing, can't attack";
973 if ((*attacker).attacks().empty()) {
975 _(
"This unit has no usable weapons."));
980 std::vector<battle_context> bc_vector;
1002 }
catch(std::bad_alloc) {
1003 lg::wml_error() <<
"Memory exhausted a unit has either a lot hitpoints or a negative amount.\n";
1020 || attacker->incapacitated())
1026 || defender->incapacitated())
1029 std::vector<battle_context> bc_vector;
1032 if(
size_t(choice) >= bc_vector.size()) {
1058 attacker->type_id(), defender->type_id(), att.
level,
1064 std::set<map_location>
res;
1072 if (i && uteam.
is_enemy(i->side()))
1087 if (u->attacks_left() == 0)
1120 if (it->side() !=
side_num_ || it->user_end_turn()
1125 it->invisible(it->get_location()))
1128 if (it->get_hidden())
bool mouse_motion_default(int x, int y, bool update)
This handles minimap scrolling and click-drag.
virtual void highlight_hex(map_location hex)
Function to highlight a location.
void set_current_paths(const pathfind::paths &new_paths)
bool fogged(const map_location &loc) const
Returns true if location (x,y) is covered in fog.
plain_route a_star_search(const map_location &src, const map_location &dst, double stop_at, const cost_calculator *calc, const size_t width, const size_t height, const teleport_map *teleports, bool border)
virtual const unit_map & units() const
const map_location & get_location() const
marked_route mark_route(const plain_route &rt)
Add marks on a route rt assuming that the unit located at the first hex of rt travels along it...
int fill_weapon_choices(std::vector< battle_context > &bc_vector, unit_map::iterator attacker, unit_map::iterator defender)
void invalidate_game_status()
Function to invalidate the game status displayed on the sidebar.
std::shared_ptr< gui::zoom_slider > find_slider(const std::string &id)
void mouse_press(const SDL_MouseButtonEvent &event, const bool browse)
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
size_t move_unit_and_record(const std::vector< map_location > &steps, undo_list *undo_stack, bool continued_move, bool show_move, bool *interrupted, move_unit_spectator *move_spectator)
Moves a unit across the board.
map_location selected_hex_
unit_map::const_iterator find_unit(const map_location &hex) const
bool dragging_started_
Actual drag flag.
Various functions that implement attacks and attack calculations.
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
const time_of_day & get_time_of_day(int for_turn=0) const
Returns global time of day for the passed turn.
pathfind::marked_route get_route(const unit *un, map_location go_to, team &team) const
pathfind::paths current_paths_
bool is_enemy(int n) const
const_iterator find(const map_location &) const
const map_location hex_clicked_on(int x, int y) const
given x,y co-ordinates of an onscreen pixel, will return the location of the hex that this pixel corr...
bool fire(const std::string &event, const entity_location &loc1=entity_location::null_entity, const entity_location &loc2=entity_location::null_entity, const config &data=config())
Function to fire an event.
virtual const std::vector< team > & teams() const
void show_transient_message(CVideo &video, const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup, const bool restore_background)
Shows a transient message to the user.
bool move_unit_along_current_route()
Moves a unit along the currently cached route.
bool unit_in_cycle(unit_map::const_iterator it)
DIRECTION get_relative_dir(const map_location &loc, map_location::RELATIVE_DIR_MODE mode) const
GLint GLint GLint GLint GLint GLint y
virtual void draw()
Draws invalidated items.
map_location previous_hex_
void mouse_motion(int x, int y, const bool browse, bool update=false, map_location loc=map_location::null_location())
Use update to force an update of the mouse state.
bool unit_can_move(const unit &u) const
Will return true iff the unit u has any possible moves it can do (including attacking etc)...
void select_hex(const map_location &hex, const bool browse, const bool highlight=true, const bool fire_event=true)
Definitions for the interface to Wesnoth Markup Language (WML).
const gamemap & get_map_const() const
static mouse_handler * singleton_
boost::scoped_ptr< game_lua_kernel > lua_kernel_
virtual void mouse_press(const SDL_MouseButtonEvent &event, const bool browse)
bool contains(const map_location &) const
game_events::t_pump & pump()
This class stores all the data for a single 'side' (in game nomenclature).
static UNUSEDNOWARN std::string _(const char *str)
bool incapacitated() const
GLsizei const char ** path
Dialog is closed with ok button.
int current_side() const
Returns the number of the side whose turn it is.
std::vector< team > teams_
pointer get_shared_ptr() const
Structure which holds a single route between one location and another.
virtual void select_hex(map_location hex)
Function to display a location as selected.
map_location current_unit_attacks_from(const map_location &loc) const
Contains typedefs for the whiteboard.
int w() const
Effective map width.
Computes the statistics of a battle between an attacker and a defender unit.
Object which temporarily resets a unit's movement.
void highlight_another_reach(const pathfind::paths &paths_list)
Add more paths to highlight.
void highlight_reach(const pathfind::paths &paths_list)
Sets the paths that are currently displayed as available for the unit to move along.
int attack_num
Index into unit->attacks() or -1 for none.
Structure describing the statistics of a unit involved in the battle.
Structure which holds a single route and marks for special events.
static const map_location & null_location()
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
hotkey::command_executor * get_hotkey_command_executor()
Get (optionally) a command executor to handle context menu events.
void mouse_wheel_right(int x, int y, const bool)
Called when the mouse wheel is scrolled right.
bool right_click_show_menu(int x, int y, const bool browse)
Called in the default right_click when the context menu is about to be shown, can be used for preproc...
Encapsulates the map of the game.
Various functions related to moving units.
void left_mouse_up(int x, int y, const bool)
Called when the left mouse button is up.
actions::undo_list & get_undo_stack()
static lg::log_domain log_engine("engine")
std::map< std::string, tfilter >::iterator itor
std::stringstream & wml_error()
Use this logger to send errors due to deprecated WML.
int h() const
Effective map height.
void scroll_to_tile(const map_location &loc, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, bool force=true)
Scroll such that location loc is on-screen.
void unhighlight_reach()
Reset highlighting of paths.
void attack_enemy(const map_location &attacker_loc, const map_location &defender_loc, int choice)
unit_map::iterator selected_unit()
void save_whiteboard_attack(const map_location &attacker_loc, const map_location &defender_loc, int weapon_choice)
Define the game's event mechanism.
map_location previous_free_hex_
ONLY IF whiteboard is currently active, applies the planned unit map for the duration of the struct's...
GLint GLint GLint GLint GLint x
DIRECTION
Valid directions which can be moved in our hexagonal world.
mouse_handler(game_display *gui, play_controller &pc)
const tod_manager & get_tod_manager_const() const
void cycle_units(const bool browse, const bool reverse=false)
bool fire_event(const tevent event, std::vector< std::pair< twidget *, tevent > > &event_chain, twidget *dispatcher, twidget *widget, F functor)
Helper function for fire_event.
int get_selected_weapon() const
Handling of system events.
virtual const gamemap & map() const
size_t move_unit_along_route(const std::vector< map_location > &steps, bool &interrupted)
Moves a unit across the board for a player.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
static bool run_and_throw(const std::string &commandname, const config &data, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
map_location last_hex_
last highlighted hex
int drag_threshold() const
void show_attack_options(const unit_map::const_iterator &u)
Causes attackable hexes to be highlighted.
boost::shared_ptr< wb::manager > get_whiteboard()
void mouse_wheel_down(int x, int y, const bool)
Called when the mouse wheel is scrolled down.
virtual void set_button_state()
Various functions that implement the undoing (and redoing) of in-game commands.
void play_UI_sound(const std::string &files)
void set_action_bonus_count(const int count)
Standard logging facilities (interface).
pathfind::marked_route current_route_
CVideo & video()
Gets the underlying screen object.
Object which contains all the possible locations a unit can move to, with associated best routes to t...
void mouse_wheel_left(int x, int y, const bool)
Called when the mouse wheel is scrolled left.
void mouse_wheel_up(int x, int y, const bool)
Called when the mouse wheel is scrolled up.
size_t viewing_team() const
The viewing team is the team currently viewing the game.
unit_iterator find(size_t id)
const teleport_map get_teleport_locations(const unit &u, const team &viewing_team, bool see_all, bool ignore_units)
void set_side(int side_number)
Ensures that the real unit map is active for the duration of the struct's life.
void attack_enemy_(const map_location &attacker_loc, const map_location &defender_loc, int choice)
static config get_attack(const map_location &a, const map_location &b, int att_weapon, int def_weapon, const std::string &attacker_type_id, const std::string &defender_type_id, int attacker_lvl, int defender_lvl, const size_t turn, const time_of_day &t)
void set_route(const pathfind::marked_route *route)
Sets the route along which footsteps are drawn to show movement of a unit.
game_display & gui()
Due to the way this class is constructed we can assume that the display* gui_ member actually points ...
void clear_attack_indicator()
void display_unit_hex(map_location hex)
Change the unit to be displayed in the sidebar.
std::set< map_location > get_adj_enemies(const map_location &loc, int side) const
unit_map::iterator find_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)
void set_attack_indicator(const map_location &src, const map_location &dst)
Set the attack direction indicator.
std::vector< map_location > & steps
void insert(const map_location &)
This object is used to temporary move a unit in the unit map, swapping out any unit that is already t...
bool is_keep(const map_location &loc) const
int show_attack_dialog(const map_location &attacker_loc, const map_location &defender_loc)
bool set_zoom(int amount, bool absolute=false)
Zooms the display by the specified amount.
void move_action(bool browse)
Overridden in derived class.
void select_or_action(bool browse)