The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 (size_t team_index, bool hidden)
 
 action (config const &, 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...
 
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
 
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 (config const &, 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

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

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

Constructor & Destructor Documentation

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

Definition at line 95 of file action.cpp.

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

Definition at line 101 of file action.cpp.

References team_index_, and resources::teams.

wb::action::~action ( )
virtual

Definition at line 113 of file action.cpp.

Member Function Documentation

virtual void wb::action::accept ( visitor v)
pure virtual
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.

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

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

Referenced by hide().

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

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

Definition at line 138 of file action.hpp.

Referenced by show().

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

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.

action_ptr wb::action::from_config ( config const &  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().

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.

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

size_t wb::action::get_unit_id ( ) const

Returns the id of the unit targeted by this action.

Return values
0no unit is targeted.

Definition at line 117 of file action.cpp.

References get_unit().

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

Definition at line 64 of file action.hpp.

References hidden_.

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

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

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

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.

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

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.

void wb::action::show ( )

Definition at line 87 of file action.cpp.

References do_show(), and hidden_.

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

References team_index_.

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

size_t wb::action::team_index ( ) const
inline
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 wb::suppose_dead::to_config(), wb::recall::to_config(), wb::recruit::to_config(), and wb::move::to_config().

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

References check_validity(), and OK.

Referenced by wb::recall::apply_temp_modifier(), wb::recruit::apply_temp_modifier(), wb::move::calculate_move_cost(), 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

bool wb::action::hidden_
private

Definition at line 141 of file action.hpp.

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

size_t wb::action::team_index_
private

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