The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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:
Inheritance graph

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 (size_t team_index, bool hidden, unit &mover, const pathfind::marked_route &route, arrow_ptr arrow, fake_unit_ptr fake_unit)
 
 move (config const &, 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 fake_unit_ptr get_fake_unit ()
 
virtual map_location get_source_hex () const
 
virtual map_location get_dest_hex () const
 
virtual void set_route (const pathfind::marked_route &route)
 
virtual const
pathfind::marked_route
get_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 (map_location const &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 (size_t team_index, bool hidden)
 
 action (config const &, 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...
 
size_t get_unit_id () const
 Returns the id of the unit targeted by this action. More...
 
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

boost::shared_ptr< moveshared_from_this ()
 
void calculate_move_cost ()
 

Protected Attributes

size_t unit_underlying_id_
 
std::string unit_id_
 
boost::scoped_ptr
< pathfind::marked_route
route_
 
int movement_cost_
 
int turn_number_
 Turn end number to draw if greater than zero. Assigned by the map builder. 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 ()
 
void update_arrow_style ()
 

Private Attributes

boost::scoped_ptr
< temporary_unit_mover
mover_
 
bool fake_unit_hidden_
 

Additional Inherited Members

- Static Public Member Functions inherited from wb::action
static action_ptr from_config (config const &, 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 33 of file move.hpp.

Member Enumeration Documentation

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

Definition at line 89 of file move.hpp.

Enumerator
ARROW_TEXTURE_VALID 
ARROW_TEXTURE_INVALID 

Definition at line 91 of file move.hpp.

Constructor & Destructor Documentation

wb::move::move ( size_t  team_index,
bool  hidden,
unit mover,
const pathfind::marked_route route,
arrow_ptr  arrow,
fake_unit_ptr  fake_unit 
)

Definition at line 63 of file move.cpp.

References fake_unit_, init(), and route_.

wb::move::move ( config const &  cfg,
bool  hidden 
)
wb::move::~move ( )
virtual

Definition at line 198 of file move.cpp.

Member Function Documentation

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

Implements wb::action.

Reimplemented in wb::attack.

Definition at line 200 of file move.cpp.

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

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 327 of file move.cpp.

References DBG_WB, unit_map::end(), fake_unit_, unit_map::find(), get_dest_hex(), get_source_hex(), unit::id(), movement_cost_, unit::movement_left(), mover_, and unit::name().

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

void wb::move::calculate_move_cost ( )
protected
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 313 of file move.cpp.

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

action::error wb::move::check_validity ( ) const
virtual
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 396 of file move.cpp.

References arrow_, fake_unit_, and fake_unit_hidden_.

void wb::move::do_show ( )
privatevirtual

Reimplemented from wb::action.

Reimplemented in wb::attack.

Definition at line 403 of file move.cpp.

References arrow_, fake_unit_, and fake_unit_hidden_.

void wb::move::draw_hex ( map_location const &  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 385 of file move.cpp.

References display::draw_text_in_hex(), get_dest_hex(), display::LAYER_MOVE_INFO, font::NORMAL_COLOR, resources::screen, and turn_number_.

void wb::move::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.

Implements wb::action.

Reimplemented in wb::attack.

Definition at line 205 of file move.cpp.

References arrow_, ARROW_BRIGHTNESS_HIGHLIGHTED, ARROW_BRIGHTNESS_STANDARD, resources::controller, unit_map::find(), get_dest_hex(), play_controller::get_mouse_handler_base(), get_source_hex(), hide_fake_unit(), LOG_WB, events::mouse_handler::move_unit_along_route(), route_, set_arrow_brightness(), shared_from_this(), show_fake_unit(), unit_id_, resources::units, wb::action::valid(), and WRN_WB.

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

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

Definition at line 69 of file move.hpp.

References arrow_.

map_location wb::move::get_dest_hex ( ) const
virtual
virtual fake_unit_ptr wb::move::get_fake_unit ( )
inlinevirtual
Returns
pointer to the fake unit used only for visuals

Implements wb::action.

Definition at line 58 of file move.hpp.

References fake_unit_.

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

Implements wb::action.

Definition at line 424 of file move.cpp.

References get_dest_hex().

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

Definition at line 64 of file move.hpp.

References route_.

Referenced by check_validity().

map_location wb::move::get_source_hex ( ) const
virtual
unit_ptr wb::move::get_unit ( ) const
virtual
void wb::move::hide_fake_unit ( )
private

Definition at line 410 of file move.cpp.

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

Referenced by execute().

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

Implements wb::action.

Reimplemented in wb::attack.

Definition at line 56 of file move.cpp.

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

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

void wb::move::redraw ( )
virtual

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

Reimplemented from wb::action.

Definition at line 554 of file move.cpp.

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

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

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 362 of file move.cpp.

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

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

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

Definition at line 90 of file move.hpp.

References arrow_brightness_.

Referenced by execute().

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

Definition at line 92 of file move.hpp.

References arrow_texture_.

Referenced by check_validity().

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

Definition at line 306 of file move.cpp.

References arrow_, calculate_move_cost(), and route_.

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 82 of file move.hpp.

References turn_number_.

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

Definition at line 96 of file move.hpp.

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

void wb::move::show_fake_unit ( )
private

Definition at line 417 of file move.cpp.

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

Referenced by execute().

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 493 of file move.cpp.

References config::add_child(), route_, wb::action::to_config(), unit_underlying_id_, map_location::x, and map_location::y.

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

void wb::move::update_arrow_style ( )
private

Member Data Documentation

arrow_ptr wb::move::arrow_
protected

Definition at line 109 of file move.hpp.

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

ARROW_BRIGHTNESS wb::move::arrow_brightness_
mutableprotected

Definition at line 112 of file move.hpp.

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

ARROW_TEXTURE wb::move::arrow_texture_
mutableprotected

Definition at line 113 of file move.hpp.

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

fake_unit_ptr wb::move::fake_unit_
protected
bool wb::move::fake_unit_hidden_
private

Definition at line 125 of file move.hpp.

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

int wb::move::movement_cost_
protected

Definition at line 105 of file move.hpp.

Referenced by apply_temp_modifier(), calculate_move_cost(), and remove_temp_modifier().

boost::scoped_ptr<temporary_unit_mover> wb::move::mover_
private

Definition at line 124 of file move.hpp.

Referenced by apply_temp_modifier(), and remove_temp_modifier().

boost::scoped_ptr<pathfind::marked_route> wb::move::route_
protected
int wb::move::turn_number_
protected

Turn end number to draw if greater than zero. Assigned by the map builder.

Definition at line 107 of file move.hpp.

Referenced by draw_hex(), and set_turn_number().

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

Definition at line 103 of file move.hpp.

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

size_t wb::move::unit_underlying_id_
protected

Definition at line 102 of file move.hpp.

Referenced by check_validity(), get_unit(), move(), and to_config().


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