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

#include <recruit.hpp>

Inheritance diagram for wb::recruit:
Inheritance graph

Public Member Functions

 recruit (std::size_t team_index, bool hidden, const std::string &unit_name, const map_location &recruit_hex)
 
 recruit (const config &, bool hidden)
 
virtual ~recruit ()
 
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 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...
 
virtual void redraw ()
 Redrawing function, called each time the action situation might have changed. More...
 
virtual map_location get_numbering_hex () const
 
virtual unit_ptr get_unit () const
 
virtual bool places_new_unit () const
 Returns true for recall and recruit actions. More...
 
virtual fake_unit_ptr get_fake_unit ()
 
map_location const get_recruit_hex () const
 
virtual config to_config () const
 Constructs and returns a config object representing this object. More...
 
- 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 std::size_t get_unit_id () const
 Returns the id of the unit targeted by this action. 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< recruitshared_from_this ()
 

Protected Attributes

std::string unit_name_
 
map_location recruit_hex_
 
unit_ptr temp_unit_
 
fake_unit_ptr fake_unit_
 
int cost_
 

Private Member Functions

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

Additional Inherited Members

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

Definition at line 32 of file recruit.hpp.

Constructor & Destructor Documentation

◆ recruit() [1/2]

wb::recruit::recruit ( std::size_t  team_index,
bool  hidden,
const std::string &  unit_name,
const map_location recruit_hex 
)

Definition at line 56 of file recruit.cpp.

References init().

◆ recruit() [2/2]

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

◆ ~recruit()

wb::recruit::~recruit ( )
virtual

Definition at line 100 of file recruit.cpp.

Member Function Documentation

◆ accept()

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

Implements wb::action.

Definition at line 104 of file recruit.cpp.

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

◆ apply_temp_modifier()

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

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

Implements wb::action.

Definition at line 133 of file recruit.cpp.

References cost_, DBG_WB, resources::gameboard, display::get_singleton(), unit_map::insert(), display::invalidate_game_status(), recruit_hex_, wb::action::team_index(), game_board::teams(), temp_unit_, and wb::action::valid().

◆ check_validity()

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

Implements wb::action.

Definition at line 203 of file recruit.cpp.

References wb::any_recruiter(), gui2::event::find(), wb::find_recruiter(), resources::gameboard, get_recruit_hex(), wb::action::LOCATION_OCCUPIED, wb::action::NO_LEADER, wb::action::NOT_ENOUGH_GOLD, wb::action::OK, recruit_hex_, unit::recruits(), wb::action::team_index(), game_board::teams(), temp_unit_, unit_name_, and wb::action::UNIT_UNAVAILABLE.

◆ create_corresponding_unit()

unit_ptr wb::recruit::create_corresponding_unit ( )
private

Definition at line 190 of file recruit.cpp.

References unit::create(), unit_type_data::find(), wb::action::team_index(), unit_name_, and unit_types.

Referenced by recruit().

◆ do_hide()

void wb::recruit::do_hide ( )
privatevirtual

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

Reimplemented from wb::action.

Definition at line 247 of file recruit.cpp.

References fake_unit_.

◆ do_show()

void wb::recruit::do_show ( )
privatevirtual

Reimplemented from wb::action.

Definition at line 248 of file recruit.cpp.

References fake_unit_.

◆ draw_hex()

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

Definition at line 168 of file recruit.cpp.

References cost_, display::draw_text_in_hex(), gui::font_size, display::get_singleton(), display::LAYER_ACTIONS_NUMBERING, recruit_hex_, and font::unicode_minus.

◆ execute()

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

Definition at line 109 of file recruit.cpp.

References resources::controller, cost_, events::menu_handler::do_recruit(), fake_unit_, unit_map::find(), resources::gameboard, play_controller::get_menu_handler(), recruit_hex_, wb::action::team_index(), game_board::teams(), unit_name_, game_board::units(), wb::action::valid(), and wb::viewer_actions().

◆ get_fake_unit()

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

Implements wb::action.

Definition at line 72 of file recruit.hpp.

References fake_unit_.

◆ get_numbering_hex()

virtual map_location wb::recruit::get_numbering_hex ( ) const
inlinevirtual
Returns
the preferred hex to draw the numbering for this action.

Implements wb::action.

Definition at line 66 of file recruit.hpp.

References recruit_hex_.

◆ get_recruit_hex()

map_location const wb::recruit::get_recruit_hex ( ) const
inline

Definition at line 74 of file recruit.hpp.

References recruit_hex_, and to_config().

Referenced by check_validity().

◆ get_unit()

virtual unit_ptr wb::recruit::get_unit ( ) const
inlinevirtual
Returns
pointer to a fake unit representing the one that will eventually be recruited.

Implements wb::action.

Definition at line 69 of file recruit.hpp.

References temp_unit_.

◆ init()

void wb::recruit::init ( )
private

◆ places_new_unit()

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

Returns true for recall and recruit actions.

Reimplemented from wb::action.

Definition at line 70 of file recruit.hpp.

◆ print()

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

Implements wb::action.

Definition at line 50 of file recruit.cpp.

References recruit_hex_, s, and unit_name_.

◆ redraw()

void wb::recruit::redraw ( )
virtual

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

Reimplemented from wb::action.

Definition at line 184 of file recruit.cpp.

References display::get_singleton(), display::invalidate(), and recruit_hex_.

◆ remove_temp_modifier()

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

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

Implements wb::action.

Definition at line 156 of file recruit.cpp.

References unit_map::extract(), recruit_hex_, and temp_unit_.

◆ shared_from_this()

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

Definition at line 80 of file recruit.hpp.

Referenced by accept().

◆ to_config()

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

Constructs and returns a config object representing this object.

Reimplemented from wb::action.

Definition at line 231 of file recruit.cpp.

References config::add_child(), recruit_hex_, wb::action::to_config(), unit_name_, map_location::wml_x(), and map_location::wml_y().

Referenced by get_recruit_hex().

Member Data Documentation

◆ cost_

int wb::recruit::cost_
protected

Definition at line 89 of file recruit.hpp.

Referenced by apply_temp_modifier(), draw_hex(), execute(), and init().

◆ fake_unit_

fake_unit_ptr wb::recruit::fake_unit_
protected

Definition at line 88 of file recruit.hpp.

Referenced by do_hide(), do_show(), execute(), get_fake_unit(), init(), and recruit().

◆ recruit_hex_

map_location wb::recruit::recruit_hex_
protected

◆ temp_unit_

unit_ptr wb::recruit::temp_unit_
protected

◆ unit_name_

std::string wb::recruit::unit_name_
protected

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