The Battle for Wesnoth  1.15.0+dev
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
wb::action Class Referenceabstract

Abstract base class for all the whiteboard planned actions. More...

#include <action.hpp>

Inheritance diagram for wb::action:
Inheritance graph

Classes

struct  ctor_err
 

Public Types

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

 action (std::size_t team_index, bool hidden)
 
 action (const config &, bool hidden)
 
virtual ~action ()
 
virtual std::ostream & print (std::ostream &s) const =0
 
virtual void accept (visitor &v)=0
 
virtual void execute (bool &success, bool &complete)=0
 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 void apply_temp_modifier (unit_map &unit_map)=0
 Applies temporarily the result of this action to the specified unit map. More...
 
virtual void remove_temp_modifier (unit_map &unit_map)=0
 Removes the result of this action from the specified unit map. More...
 
virtual void draw_hex (const map_location &hex)=0
 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...
 
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 map_location get_numbering_hex () const =0
 
virtual unit_ptr get_unit () const =0
 Return the unit targeted by this action. More...
 
virtual bool places_new_unit () const
 Returns true for recall and recruit actions. More...
 
virtual std::size_t get_unit_id () const
 Returns the id of the unit targeted by this action. More...
 
virtual fake_unit_ptr get_fake_unit ()=0
 
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...
 
virtual config to_config () const
 Constructs and returns a config object representing this object. More...
 
virtual error check_validity () const =0
 Check the validity of the action. More...
 
bool valid ()
 Returns whether this action is valid or not. More...
 

Static Public Member Functions

static action_ptr from_config (const config &, bool hidden)
 Constructs an object of a subclass of wb::action using a config. More...
 

Private Member Functions

virtual void do_hide ()
 Called by the non-virtual hide() and show(), respectively. More...
 
virtual void do_show ()
 

Private Attributes

std::size_t team_index_
 
bool hidden_
 

Detailed Description

Abstract base class for all the whiteboard planned actions.

Definition at line 32 of file action.hpp.

Member Enumeration Documentation

◆ error

Possible errors.

Returned by the check function.

Enumerator
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 

Definition at line 105 of file action.hpp.

Constructor & Destructor Documentation

◆ action() [1/2]

wb::action::action ( std::size_t  team_index,
bool  hidden 
)

Definition at line 95 of file action.cpp.

◆ action() [2/2]

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

Definition at line 101 of file action.cpp.

References resources::gameboard, utf8::size(), and team_index_.

◆ ~action()

wb::action::~action ( )
virtual

Definition at line 113 of file action.cpp.

Member Function Documentation

◆ accept()

virtual void wb::action::accept ( visitor v)
pure virtual

◆ apply_temp_modifier()

virtual void wb::action::apply_temp_modifier ( unit_map unit_map)
pure virtual

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

Implemented in wb::move, wb::suppose_dead, wb::recruit, wb::attack, wb::recall, and dummy_action.

◆ check_validity()

virtual error wb::action::check_validity ( ) const
pure 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.)

Implemented in wb::suppose_dead, wb::move, wb::recruit, wb::attack, wb::recall, and dummy_action.

Referenced by valid().

◆ do_hide()

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

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

Reimplemented in wb::move, wb::recruit, wb::recall, and wb::attack.

Definition at line 138 of file action.hpp.

Referenced by hide().

◆ do_show()

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

Reimplemented in wb::move, wb::recruit, wb::recall, and wb::attack.

Definition at line 139 of file action.hpp.

Referenced by show().

◆ draw_hex()

virtual void wb::action::draw_hex ( const map_location hex)
pure virtual

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

Implemented in wb::move, wb::suppose_dead, wb::recruit, wb::attack, wb::recall, and dummy_action.

Referenced by wb::manager::draw_hex().

◆ execute()

virtual void wb::action::execute ( bool &  success,
bool &  complete 
)
pure 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.

Implemented in wb::suppose_dead, wb::move, wb::recruit, wb::attack, wb::recall, and dummy_action.

◆ from_config()

action_ptr wb::action::from_config ( const config cfg,
bool  hidden 
)
static

Constructs an object of a subclass of wb::action using a config.

Current behavior is to return a null pointer for unrecognized config.

Definition at line 59 of file action.cpp.

Referenced by wb::side_actions::execute_net_cmd(), and side_number().

◆ get_fake_unit()

virtual fake_unit_ptr wb::action::get_fake_unit ( )
pure virtual
Returns
pointer to the fake unit used only for visuals

Implemented in wb::recruit, wb::recall, wb::move, dummy_action, and wb::suppose_dead.

Referenced by places_new_unit().

◆ get_numbering_hex()

virtual map_location wb::action::get_numbering_hex ( ) const
pure virtual

◆ get_unit()

virtual unit_ptr wb::action::get_unit ( ) const
pure virtual

Return the unit targeted by this action.

Null if unit doesn't exist.

Implemented in wb::recruit, wb::recall, wb::move, dummy_action, and wb::suppose_dead.

Referenced by get_unit_id(), and is_numbering_hex().

◆ get_unit_id()

std::size_t wb::action::get_unit_id ( ) const
virtual

Returns the id of the unit targeted by this action.

Return values
0no unit is targeted.

Reimplemented in wb::move.

Definition at line 117 of file action.cpp.

References get_unit().

Referenced by places_new_unit().

◆ hidden()

bool wb::action::hidden ( ) const
inline

Definition at line 63 of file action.hpp.

References hidden_.

Referenced by wb::move::hide_fake_unit(), and wb::move::show_fake_unit().

◆ hide()

void wb::action::hide ( )

Sets whether or not the action should be drawn on the screen.

Definition at line 79 of file action.cpp.

References do_hide(), and hidden_.

Referenced by redraw().

◆ is_numbering_hex()

bool wb::action::is_numbering_hex ( const map_location hex) const
inline

Indicates whether this hex is the preferred hex to draw the numbering for this action.

Definition at line 66 of file action.hpp.

References get_numbering_hex(), and get_unit().

◆ places_new_unit()

virtual bool wb::action::places_new_unit ( ) const
inlinevirtual

Returns true for recall and recruit actions.

Reimplemented in wb::recruit, and wb::recall.

Definition at line 73 of file action.hpp.

References get_fake_unit(), and get_unit_id().

◆ print()

std::ostream & wb::action::print ( std::ostream &  s) const
pure virtual

Implemented in wb::suppose_dead, wb::move, wb::recruit, wb::attack, wb::recall, and dummy_action.

Definition at line 45 of file action.cpp.

References s.

◆ redraw()

virtual void wb::action::redraw ( )
inlinevirtual

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

Reimplemented in wb::move, wb::suppose_dead, wb::recruit, wb::attack, and wb::recall.

Definition at line 58 of file action.hpp.

References hide(), and show().

◆ remove_temp_modifier()

virtual void wb::action::remove_temp_modifier ( unit_map unit_map)
pure virtual

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

Implemented in wb::move, wb::suppose_dead, wb::recruit, wb::attack, wb::recall, and dummy_action.

◆ show()

void wb::action::show ( )

Definition at line 87 of file action.cpp.

References do_show(), and hidden_.

Referenced by redraw().

◆ side_number()

int wb::action::side_number ( ) const
inline

Returns the number of the side that owns this action, i.e.

the team index + 1.

Definition at line 85 of file action.hpp.

References from_config(), team_index_, and to_config().

Referenced by wb::move::move().

◆ team_index()

std::size_t wb::action::team_index ( ) const
inline

◆ to_config()

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

Constructs and returns a config object representing this object.

Reimplemented in wb::move, wb::recruit, wb::recall, wb::suppose_dead, and wb::attack.

Definition at line 50 of file action.cpp.

References team_index_.

Referenced by side_number(), wb::suppose_dead::to_config(), wb::recall::to_config(), wb::recruit::to_config(), and wb::move::to_config().

◆ valid()

bool wb::action::valid ( )
inline

Returns whether this action is valid or not.

Note
This value is now calculated each time the function is called.

Definition at line 134 of file action.hpp.

References check_validity(), and OK.

Referenced by wb::recall::apply_temp_modifier(), wb::recruit::apply_temp_modifier(), wb::move::calculate_moves_left(), wb::move::check_validity(), wb::suppose_dead::check_validity(), wb::recall::execute(), wb::attack::execute(), wb::recruit::execute(), and wb::move::execute().

Member Data Documentation

◆ hidden_

bool wb::action::hidden_
private

Definition at line 142 of file action.hpp.

Referenced by hidden(), hide(), and show().

◆ team_index_

std::size_t wb::action::team_index_
private

Definition at line 141 of file action.hpp.

Referenced by action(), side_number(), team_index(), and to_config().


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