The Battle for Wesnoth  1.19.0-dev
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
wb::attack Class Reference

#include <attack.hpp>

Inheritance diagram for wb::attack:

Public Member Functions

 attack (std::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 (const config &, bool hidden)
 
virtual ~attack ()
 
virtual std::ostream & print (std::ostream &s) const
 
virtual void accept (visitor &v)
 
virtual void execute (bool &success, bool &complete)
 Output parameters: success: Whether or not to continue an execute-all after this execution complete: Whether or not to delete this action after execution. More...
 
virtual error check_validity () const
 Check the validity of the action. More...
 
virtual void apply_temp_modifier (unit_map &unit_map)
 Applies temporarily the result of this action to the specified unit map. More...
 
virtual void remove_temp_modifier (unit_map &unit_map)
 Removes the result of this action from the specified unit map. More...
 
virtual void draw_hex (const map_location &hex)
 Gets called by display when drawing a hex, to allow actions to draw to the screen. More...
 
virtual void redraw ()
 Redrawing function, called each time the action situation might have changed. More...
 
const map_locationget_target_hex () const
 
virtual config to_config () const
 Constructs and returns a config object representing this object. More...
 
- Public Member Functions inherited from wb::move
 move (std::size_t team_index, bool hidden, unit &mover, const pathfind::marked_route &route, arrow_ptr arrow, fake_unit_ptr fake_unit)
 
 move (const config &, bool hidden)
 
virtual ~move ()
 
virtual unit_ptr get_unit () const
 Return the unit targeted by this action. More...
 
virtual size_t get_unit_id () const
 Returns the id of the unit targeted by this action. More...
 
virtual fake_unit_ptr get_fake_unit ()
 
virtual map_location get_source_hex () const
 
virtual map_location get_dest_hex () const
 
std::size_t raw_uid () const
 
void modify_unit (unit &new_unit)
 
virtual void set_route (const pathfind::marked_route &route)
 
virtual const pathfind::marked_routeget_route () const
 
virtual bool calculate_new_route (const map_location &source_hex, const map_location &dest_hex)
 attempts to pathfind a new marked route for this path between these two hexes; returns true and assigns it to the internal route if successful. More...
 
virtual arrow_ptr get_arrow ()
 
void redraw ()
 Redrawing function, called each time the action situation might have changed. More...
 
virtual void set_turn_number (int turn)
 Assigns a turn number to display to this planned move. More...
 
virtual map_location get_numbering_hex () const
 
void set_arrow_brightness (ARROW_BRIGHTNESS x) const
 
void set_arrow_texture (ARROW_TEXTURE x) const
 
- Public Member Functions inherited from wb::action
 action (std::size_t team_index, bool hidden)
 
 action (const config &, bool hidden)
 
virtual ~action ()
 
void hide ()
 Sets whether or not the action should be drawn on the screen. More...
 
void show ()
 
bool hidden () const
 
bool is_numbering_hex (const map_location &hex) const
 Indicates whether this hex is the preferred hex to draw the numbering for this action. More...
 
virtual bool places_new_unit () const
 Returns true for recall and recruit actions. More...
 
std::size_t team_index () const
 Returns the index of the team that owns this action. More...
 
int side_number () const
 Returns the number of the side that owns this action, i.e. More...
 
bool valid ()
 Returns whether this action is valid or not. More...
 

Protected Member Functions

std::shared_ptr< attackshared_from_this ()
 
- Protected Member Functions inherited from wb::move
std::shared_ptr< moveshared_from_this ()
 
int calculate_moves_left (unit &u)
 

Private Member Functions

void init ()
 
virtual void do_hide ()
 Called by the non-virtual hide() and show(), respectively. More...
 
virtual void do_show ()
 
void invalidate ()
 invalidates the move-destination and attack-target hexes More...
 

Private Attributes

map_location target_hex_
 the target of the attack More...
 
int weapon_choice_
 
int attack_movement_cost_
 
int temp_movement_subtracted_
 
int attack_count_
 
int temp_attacks_subtracted_
 

Additional Inherited Members

- Public Types inherited from wb::move
enum  ARROW_BRIGHTNESS { ARROW_BRIGHTNESS_STANDARD , ARROW_BRIGHTNESS_HIGHLIGHTED , ARROW_BRIGHTNESS_FOCUS }
 
enum  ARROW_TEXTURE { ARROW_TEXTURE_VALID , ARROW_TEXTURE_INVALID }
 
- Public Types inherited from wb::action
enum  error {
  OK , INVALID_LOCATION , NO_UNIT , UNIT_CHANGED ,
  LOCATION_OCCUPIED , TOO_FAR , NO_TARGET , NO_ATTACK_LEFT ,
  NOT_AN_ENEMY , UNIT_UNAVAILABLE , NOT_ENOUGH_GOLD , NO_LEADER
}
 Possible errors. More...
 
- Static Public Member Functions inherited from wb::action
static action_ptr from_config (const config &, bool hidden)
 Constructs an object of a subclass of wb::action using a config. More...
 
- Protected Attributes inherited from wb::move
std::size_t unit_underlying_id_
 
std::string unit_id_
 
std::unique_ptr< pathfind::marked_routeroute_
 
int movement_cost_
 
int turn_number_
 Turn end number to draw if greater than zero. More...
 
arrow_ptr arrow_
 
fake_unit_ptr fake_unit_
 
ARROW_BRIGHTNESS arrow_brightness_
 
ARROW_TEXTURE arrow_texture_
 

Detailed Description

Definition at line 27 of file attack.hpp.

Constructor & Destructor Documentation

◆ attack() [1/2]

wb::attack::attack ( std::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 
)

Definition at line 55 of file attack.cpp.

References init().

◆ attack() [2/2]

wb::attack::attack ( const config cfg,
bool  hidden 
)

◆ ~attack()

wb::attack::~attack ( )
virtual

Definition at line 98 of file attack.cpp.

References invalidate().

Member Function Documentation

◆ accept()

void wb::attack::accept ( visitor v)
virtual

Reimplemented from wb::move.

Definition at line 103 of file attack.cpp.

References shared_from_this(), and wb::visitor::visit().

◆ apply_temp_modifier()

void wb::attack::apply_temp_modifier ( unit_map unit_map)
virtual

◆ check_validity()

action::error wb::attack::check_validity ( ) const
virtual

Check the validity of the action.

Returns
the error preventing the action from being executed.
Return values
OKif there isn't any error (the action can be executed.)

Reimplemented from wb::move.

Definition at line 226 of file attack.cpp.

References wb::move::check_validity(), resources::gameboard, wb::move::get_unit(), wb::action::INVALID_LOCATION, wb::action::NO_ATTACK_LEFT, wb::action::NO_TARGET, wb::action::NO_UNIT, wb::action::NOT_AN_ENEMY, target_hex_, and map_location::valid().

◆ do_hide()

virtual void wb::attack::do_hide ( )
inlineprivatevirtual

Called by the non-virtual hide() and show(), respectively.

Reimplemented from wb::move.

Definition at line 73 of file attack.hpp.

References invalidate().

◆ do_show()

virtual void wb::attack::do_show ( )
inlineprivatevirtual

Reimplemented from wb::move.

Definition at line 74 of file attack.hpp.

References invalidate().

◆ draw_hex()

void wb::attack::draw_hex ( const map_location hex)
virtual

Gets called by display when drawing a hex, to allow actions to draw to the screen.

Reimplemented from wb::move.

Definition at line 198 of file attack.cpp.

References draw::blit(), d, display::drawing_buffer_add(), wb::move::get_dest_hex(), display::get_singleton(), image::get_texture(), image::HEXED, display::LAYER_FOOTSTEPS, target_hex_, and map_location::write_direction().

◆ execute()

void wb::attack::execute ( bool &  success,
bool &  complete 
)
virtual

Output parameters: success: Whether or not to continue an execute-all after this execution complete: Whether or not to delete this action after execution.

Reimplemented from wb::move.

Definition at line 119 of file attack.cpp.

References events::mouse_handler::attack_enemy(), resources::controller, wb::move::execute(), unit_map::find(), resources::gameboard, wb::move::get_dest_hex(), play_controller::get_mouse_handler_base(), get_target_hex(), LOG_WB, wb::move::route_, shared_from_this(), wb::move::unit_id_, game_board::units(), wb::action::valid(), unit_map::iterator_base< iter_types >::valid(), and weapon_choice_.

◆ get_target_hex()

const map_location& wb::attack::get_target_hex ( ) const
inline

Definition at line 59 of file attack.hpp.

References target_hex_.

Referenced by execute(), and print().

◆ init()

void wb::attack::init ( )
private

Definition at line 93 of file attack.cpp.

References display::get_singleton(), display::invalidate(), and target_hex_.

Referenced by attack().

◆ invalidate()

void wb::attack::invalidate ( )
private

invalidates the move-destination and attack-target hexes

Definition at line 109 of file attack.cpp.

References wb::move::get_dest_hex(), display::get_singleton(), display::invalidate(), and target_hex_.

Referenced by do_hide(), do_show(), and ~attack().

◆ print()

std::ostream & wb::attack::print ( std::ostream &  s) const
virtual

Reimplemented from wb::move.

Definition at line 48 of file attack.cpp.

References get_target_hex(), wb::move::print(), and s.

Referenced by wb::operator<<().

◆ redraw()

void wb::attack::redraw ( )
virtual

Redrawing function, called each time the action situation might have changed.

Reimplemented from wb::action.

Definition at line 220 of file attack.cpp.

References display::get_singleton(), display::invalidate(), wb::move::redraw(), and target_hex_.

◆ remove_temp_modifier()

void wb::attack::remove_temp_modifier ( unit_map unit_map)
virtual

◆ shared_from_this()

std::shared_ptr<attack> wb::attack::shared_from_this ( )
inlineprotected

Definition at line 65 of file attack.hpp.

References wb::move::shared_from_this().

Referenced by accept(), and execute().

◆ to_config()

config wb::attack::to_config ( ) const
virtual

Constructs and returns a config object representing this object.

Reimplemented from wb::move.

Definition at line 254 of file attack.cpp.

References config::add_child(), target_hex_, wb::move::to_config(), weapon_choice_, map_location::wml_x(), and map_location::wml_y().

Member Data Documentation

◆ attack_count_

int wb::attack::attack_count_
private

Definition at line 85 of file attack.hpp.

Referenced by apply_temp_modifier(), and attack().

◆ attack_movement_cost_

int wb::attack::attack_movement_cost_
private

Definition at line 83 of file attack.hpp.

Referenced by apply_temp_modifier(), and attack().

◆ target_hex_

map_location wb::attack::target_hex_
private

the target of the attack

Definition at line 80 of file attack.hpp.

Referenced by attack(), check_validity(), draw_hex(), get_target_hex(), init(), invalidate(), redraw(), and to_config().

◆ temp_attacks_subtracted_

int wb::attack::temp_attacks_subtracted_
private

Definition at line 86 of file attack.hpp.

Referenced by apply_temp_modifier(), and remove_temp_modifier().

◆ temp_movement_subtracted_

int wb::attack::temp_movement_subtracted_
private

Definition at line 84 of file attack.hpp.

Referenced by apply_temp_modifier(), and remove_temp_modifier().

◆ weapon_choice_

int wb::attack::weapon_choice_
private

Definition at line 82 of file attack.hpp.

Referenced by attack(), execute(), and to_config().


The documentation for this class was generated from the following files: