The Battle for Wesnoth  1.19.7+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:

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 33 of file action.hpp.

Member Enumeration Documentation

◆ error

Possible errors.

Returned by the check_validity 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 106 of file action.hpp.

Constructor & Destructor Documentation

◆ action() [1/2]

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

Definition at line 97 of file action.cpp.

◆ action() [2/2]

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

Definition at line 103 of file action.cpp.

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

◆ ~action()

wb::action::~action ( )
virtual

Definition at line 115 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::suppose_dead, wb::recruit, wb::recall, wb::move, wb::attack, and dummy_action.

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

◆ 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::recruit, wb::recall, wb::move, wb::attack, and dummy_action.

Referenced by wb::mapbuilder::process(), and valid().

◆ do_hide()

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

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

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

Definition at line 139 of file action.hpp.

Referenced by hide().

◆ do_show()

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

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

Definition at line 140 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::suppose_dead, wb::recruit, wb::recall, wb::move, wb::attack, 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::recruit, wb::recall, wb::move, wb::attack, and dummy_action.

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

◆ 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 60 of file action.cpp.

References hidden().

Referenced by wb::side_actions::execute_net_cmd().

◆ 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::suppose_dead, wb::recruit, wb::recall, wb::move, and dummy_action.

◆ 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::suppose_dead, wb::recruit, wb::recall, wb::move, and dummy_action.

Referenced by get_unit_id(), wb::manager::post_delete_action(), and wb::mapbuilder::process().

◆ 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 119 of file action.cpp.

References get_unit().

◆ hidden()

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

Definition at line 64 of file action.hpp.

References hidden_.

Referenced by from_config(), wb::move::hide_fake_unit(), wb::move::move(), 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 81 of file action.cpp.

References do_hide(), and hidden_.

◆ 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 67 of file action.hpp.

References get_numbering_hex().

◆ 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 74 of file action.hpp.

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

◆ print()

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

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

Definition at line 46 of file action.cpp.

References s.

Referenced by wb::operator<<().

◆ redraw()

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

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

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

Definition at line 59 of file action.hpp.

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

◆ 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::suppose_dead, wb::recruit, wb::recall, wb::move, wb::attack, and dummy_action.

◆ show()

void wb::action::show ( )

Definition at line 89 of file action.cpp.

References do_show(), and hidden_.

◆ 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 86 of file action.hpp.

References team_index_.

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::suppose_dead, wb::recruit, wb::recall, wb::move, and wb::attack.

Definition at line 51 of file action.cpp.

References team_index_.

Referenced by wb::move::to_config(), wb::recall::to_config(), wb::recruit::to_config(), and wb::suppose_dead::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 135 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::attack::execute(), wb::move::execute(), wb::recall::execute(), wb::recruit::execute(), and wb::side_actions::execute().

Member Data Documentation

◆ hidden_

bool wb::action::hidden_
private

Definition at line 143 of file action.hpp.

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

◆ team_index_

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

Definition at line 142 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: