The Battle for Wesnoth  1.19.7+dev
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
wb::move Class Reference

A planned move, represented on the map by an arrow and a ghosted unit in the destination hex. More...

#include <move.hpp>

Inheritance diagram for wb::move:

Public Types

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...
 

Public Member Functions

 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 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 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 ()
 
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...
 
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
 
virtual config to_config () const
 Constructs and returns a config object representing this object. More...
 
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< moveshared_from_this ()
 
int calculate_moves_left (unit &u)
 

Protected Attributes

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_
 

Private Member Functions

virtual void do_hide ()
 Called by the non-virtual hide() and show(), respectively. More...
 
virtual void do_show ()
 
void hide_fake_unit ()
 
void show_fake_unit ()
 
void init (unit *u=nullptr)
 
void update_arrow_style ()
 

Private Attributes

std::unique_ptr< temporary_unit_movermover_
 
bool fake_unit_hidden_
 

Additional Inherited Members

- 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...
 

Detailed Description

A planned move, represented on the map by an arrow and a ghosted unit in the destination hex.

Definition at line 35 of file move.hpp.

Member Enumeration Documentation

◆ ARROW_BRIGHTNESS

Todo:
Make use of safe_enum idiom?
Enumerator
ARROW_BRIGHTNESS_STANDARD 
ARROW_BRIGHTNESS_HIGHLIGHTED 
ARROW_BRIGHTNESS_FOCUS 

Definition at line 97 of file move.hpp.

◆ ARROW_TEXTURE

Enumerator
ARROW_TEXTURE_VALID 
ARROW_TEXTURE_INVALID 

Definition at line 99 of file move.hpp.

Constructor & Destructor Documentation

◆ move() [1/2]

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 
)

Definition at line 70 of file move.cpp.

References fake_unit_, wb::action::hidden(), init(), and route_.

◆ move() [2/2]

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

◆ ~move()

wb::move::~move ( )
virtual

Definition at line 199 of file move.cpp.

Member Function Documentation

◆ accept()

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

Implements wb::action.

Reimplemented in wb::attack.

Definition at line 201 of file move.cpp.

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

◆ apply_temp_modifier()

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

Applies temporarily the result of this action to the specified unit map.

Implements wb::action.

Reimplemented in wb::attack.

Definition at line 335 of file move.cpp.

References calculate_moves_left(), DBG_WB, unit_map::end(), fake_unit_, unit_map::find(), get_dest_hex(), get_route(), get_source_hex(), unit::id(), pathfind::mark_route(), pathfind::marked_route::move_cost, unit::movement_left(), mover_, unit::name(), and route_.

Referenced by wb::attack::apply_temp_modifier().

◆ calculate_moves_left()

int wb::move::calculate_moves_left ( unit u)
protected

◆ calculate_new_route()

bool wb::move::calculate_new_route ( const map_location source_hex,
const map_location dest_hex 
)
virtual

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.

Definition at line 322 of file move.cpp.

References pathfind::a_star_search(), schema_validation::at(), resources::gameboard, get_unit(), pathfind::cost_calculator::getNoPathValue(), h, pathfind::mark_route(), pathfind::plain_route::move_cost, route_, wb::action::team_index(), and w.

◆ check_validity()

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

◆ do_hide()

void wb::move::do_hide ( )
privatevirtual

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

Reimplemented from wb::action.

Reimplemented in wb::attack.

Definition at line 407 of file move.cpp.

References arrow_, fake_unit_, and fake_unit_hidden_.

◆ do_show()

void wb::move::do_show ( )
privatevirtual

Reimplemented from wb::action.

Reimplemented in wb::attack.

Definition at line 414 of file move.cpp.

References arrow_, fake_unit_, and fake_unit_hidden_.

◆ draw_hex()

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

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

Implements wb::action.

Reimplemented in wb::attack.

Definition at line 396 of file move.cpp.

References display::draw_text_in_hex(), get_dest_hex(), display::get_singleton(), move_info, font::NORMAL_COLOR, and turn_number_.

◆ execute()

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

◆ get_arrow()

virtual arrow_ptr wb::move::get_arrow ( )
inlinevirtual

◆ get_dest_hex()

map_location wb::move::get_dest_hex ( ) const
virtual

◆ get_fake_unit()

virtual fake_unit_ptr wb::move::get_fake_unit ( )
inlinevirtual

◆ get_numbering_hex()

map_location wb::move::get_numbering_hex ( ) const
virtual

Implements wb::action.

Definition at line 435 of file move.cpp.

References get_dest_hex().

◆ get_route()

virtual const pathfind::marked_route& wb::move::get_route ( ) const
inlinevirtual

Definition at line 70 of file move.hpp.

References route_.

Referenced by apply_temp_modifier(), check_validity(), and wb::mapbuilder::post_visit_team().

◆ get_source_hex()

map_location wb::move::get_source_hex ( ) const
virtual

◆ get_unit()

unit_ptr wb::move::get_unit ( ) const
virtual

◆ get_unit_id()

virtual size_t wb::move::get_unit_id ( ) const
inlinevirtual

Returns the id of the unit targeted by this action.

Return values
0no unit is targeted.

Reimplemented from wb::action.

Definition at line 59 of file move.hpp.

References unit_underlying_id_.

Referenced by wb::highlighter::last_action_redraw().

◆ hide_fake_unit()

void wb::move::hide_fake_unit ( )
private

Definition at line 421 of file move.cpp.

References fake_unit_, fake_unit_hidden_, and wb::action::hidden().

Referenced by execute().

◆ init()

void wb::move::init ( unit u = nullptr)
private

◆ modify_unit()

void wb::move::modify_unit ( unit new_unit)

◆ print()

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

Implements wb::action.

Reimplemented in wb::attack.

Definition at line 58 of file move.cpp.

References get_dest_hex(), get_source_hex(), get_unit(), s, and unit_underlying_id_.

Referenced by wb::operator<<(), and wb::attack::print().

◆ raw_uid()

std::size_t wb::move::raw_uid ( ) const
inline

Definition at line 66 of file move.hpp.

References unit_underlying_id_.

◆ redraw()

void wb::move::redraw ( )
virtual

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

Reimplemented from wb::action.

Definition at line 567 of file move.cpp.

References get_dest_hex(), display::get_singleton(), get_source_hex(), display::invalidate(), and update_arrow_style().

Referenced by wb::attack::redraw().

◆ remove_temp_modifier()

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

Removes the result of this action from the specified unit map.

Implements wb::action.

Reimplemented in wb::attack.

Definition at line 373 of file move.cpp.

References calculate_moves_left(), DBG_WB, lg::debug(), unit_map::find(), resources::gameboard, get_dest_hex(), get_source_hex(), unit::id(), log_whiteboard, unit::movement_left(), mover_, unit::name(), and game_board::units().

Referenced by wb::attack::remove_temp_modifier().

◆ set_arrow_brightness()

void wb::move::set_arrow_brightness ( ARROW_BRIGHTNESS  x) const
inline

◆ set_arrow_texture()

void wb::move::set_arrow_texture ( ARROW_TEXTURE  x) const
inline

Definition at line 100 of file move.hpp.

References arrow_texture_.

Referenced by check_validity().

◆ set_route()

void wb::move::set_route ( const pathfind::marked_route route)
virtual

Definition at line 310 of file move.cpp.

References arrow_, and route_.

◆ set_turn_number()

virtual void wb::move::set_turn_number ( int  turn)
inlinevirtual

Assigns a turn number to display to this planned move.

Assigning zero removes any turn number.

Definition at line 90 of file move.hpp.

References turn_number_.

Referenced by wb::mapbuilder::post_visit_team().

◆ shared_from_this()

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

Definition at line 104 of file move.hpp.

Referenced by accept(), calculate_moves_left(), execute(), and wb::attack::shared_from_this().

◆ show_fake_unit()

void wb::move::show_fake_unit ( )
private

Definition at line 428 of file move.cpp.

References fake_unit_, fake_unit_hidden_, and wb::action::hidden().

Referenced by execute().

◆ to_config()

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

Constructs and returns a config object representing this object.

Reimplemented from wb::action.

Reimplemented in wb::attack.

Definition at line 506 of file move.cpp.

References config::add_child(), loc, route_, wb::action::to_config(), unit_underlying_id_, map_location::wml_x(), and map_location::wml_y().

Referenced by wb::attack::to_config().

◆ update_arrow_style()

void wb::move::update_arrow_style ( )
private

Member Data Documentation

◆ arrow_

arrow_ptr wb::move::arrow_
protected

Definition at line 117 of file move.hpp.

Referenced by do_hide(), do_show(), execute(), get_arrow(), init(), move(), set_route(), and update_arrow_style().

◆ arrow_brightness_

ARROW_BRIGHTNESS wb::move::arrow_brightness_
mutableprotected

Definition at line 120 of file move.hpp.

Referenced by init(), set_arrow_brightness(), and update_arrow_style().

◆ arrow_texture_

ARROW_TEXTURE wb::move::arrow_texture_
mutableprotected

Definition at line 121 of file move.hpp.

Referenced by check_validity(), init(), set_arrow_texture(), and update_arrow_style().

◆ fake_unit_

fake_unit_ptr wb::move::fake_unit_
protected

◆ fake_unit_hidden_

bool wb::move::fake_unit_hidden_
private

Definition at line 133 of file move.hpp.

Referenced by do_hide(), do_show(), hide_fake_unit(), and show_fake_unit().

◆ movement_cost_

int wb::move::movement_cost_
protected

Definition at line 113 of file move.hpp.

◆ mover_

std::unique_ptr<temporary_unit_mover> wb::move::mover_
private

Definition at line 132 of file move.hpp.

Referenced by apply_temp_modifier(), and remove_temp_modifier().

◆ route_

std::unique_ptr<pathfind::marked_route> wb::move::route_
protected

◆ turn_number_

int wb::move::turn_number_
protected

Turn end number to draw if greater than zero.

Assigned by the map builder.

Definition at line 115 of file move.hpp.

Referenced by draw_hex(), and set_turn_number().

◆ unit_id_

std::string wb::move::unit_id_
protected

Definition at line 111 of file move.hpp.

Referenced by check_validity(), wb::attack::execute(), execute(), init(), and modify_unit().

◆ unit_underlying_id_

std::size_t wb::move::unit_underlying_id_
protected

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