The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Namespaces | Classes | Typedefs | Enumerations | Functions
actions Namespace Reference

Namespaces

 undo
 

Classes

struct  clearer_info
 Class that stores the part of a unit's data that is needed for fog clearing. More...
 
class  move_unit_spectator
 
class  shroud_clearer
 Class to encapsulate fog/shroud clearing and the resultant sighted events. More...
 
struct  shroud_clearing_action
 base class for classes that clear srhoud (move/recruit/recall) More...
 
struct  undo_action
 actions that are undoable (this does not include update_shroud and auto_shroud) More...
 
struct  undo_action_base
 Records information to be able to undo an action. More...
 
struct  undo_dummy_action
 entry for player actions that do not need any special code to be performed when undoing such as right-click menu items. More...
 
struct  undo_event
 
class  undo_list
 Class to store the actions that a player can undo and redo. More...
 

Typedefs

typedef boost::tuple< bool,
int, bool > 
place_recruit_result
 Place a unit into the game. More...
 

Enumerations

enum  RECRUIT_CHECK {
  RECRUIT_NO_LEADER, RECRUIT_NO_ABLE_LEADER, RECRUIT_NO_KEEP_LEADER, RECRUIT_NO_VACANCY,
  RECRUIT_ALTERNATE_LOCATION, RECRUIT_OK
}
 The possible results of finding a location for recruiting (or recalling). More...
 

Functions

const std::set< std::stringget_recruits (int side, const map_location &recruit_location)
 Gets the recruitable units from a side's leaders' personal recruit lists who can recruit on or from a specific hex field. More...
 
std::vector< unit_const_ptrget_recalls (int side, const map_location &recall_loc)
 Gets the recallable units for a side, restricted by that side's leaders' personal abilities to recall on or from a specific hex field. More...
 
RECRUIT_CHECK check_recall_location (const int side, map_location &recall_location, map_location &recall_from, const unit &unit_recall)
 Checks if there is a location on which to recall unit_recall. More...
 
std::string find_recall_location (const int side, map_location &recall_location, map_location &recall_from, const unit &unit_recall)
 Finds a location on which to recall unit_recall. More...
 
RECRUIT_CHECK check_recruit_location (const int side, map_location &recruit_location, map_location &recruited_from, const std::string &unit_type)
 Checks if there is a location on which to place a recruited unit. More...
 
std::string find_recruit_location (const int side, map_location &recruit_location, map_location &recruited_from, const std::string &unit_type)
 Finds a location on which to place a unit. More...
 
place_recruit_result place_recruit (unit_ptr u, const map_location &recruit_location, const map_location &recruited_from, int cost, bool is_recall, bool show, bool fire_event, bool full_movement, bool wml_triggered)
 
void recruit_unit (const unit_type &u_type, int side_num, const map_location &loc, const map_location &from, bool show, bool use_undo)
 Recruits a unit of the given type for the given side. More...
 
bool recall_unit (const std::string &id, team &current_team, const map_location &loc, const map_location &from, bool show, bool use_undo)
 Recalls the unit with the indicated ID for the provided team. More...
 
bool get_village (const map_location &loc, int side, bool *time_bonus=nullptr, bool fire_event=true)
 Makes it so the village at the given location is owned by the given side. More...
 
static size_t move_unit_internal (undo_list *undo_stack, bool show_move, bool *interrupted, unit_mover &mover)
 
size_t move_unit_and_record (const std::vector< map_location > &steps, undo_list *undo_stack, bool continued_move, bool show_move, bool *interrupted, move_unit_spectator *move_spectator)
 Moves a unit across the board. More...
 
size_t move_unit_from_replay (const std::vector< map_location > &steps, undo_list *undo_stack, bool continued_move, bool skip_ally_sighted, bool show_move=true)
 Moves a unit across the board. More...
 
std::vector< intget_sides_not_seeing (const unit &target)
 Returns the sides that cannot currently see target. More...
 
bool actor_sighted (const unit &target, const std::vector< int > *cache)
 Fires sighted events for the sides that can see target. More...
 
void recalculate_fog (int side)
 Function that recalculates the fog of war. More...
 
bool clear_shroud (int side, bool reset_fog, bool fire_events)
 Function that will clear shroud (and fog) based on current unit positions. More...
 

Typedef Documentation

typedef boost::tuple<bool , int , bool > actions::place_recruit_result

Place a unit into the game.

The unit will be placed on recruit_location, which should be retrieved through a call to recruit_location().

Returns
true if an event (or fog clearing) has mutated the game state.

Definition at line 151 of file create.hpp.

Enumeration Type Documentation

The possible results of finding a location for recruiting (or recalling).

Enumerator
RECRUIT_NO_LEADER 
RECRUIT_NO_ABLE_LEADER 

No leaders exist.

RECRUIT_NO_KEEP_LEADER 

No leaders able to recall/recruit the given unit/type.

RECRUIT_NO_VACANCY 

No able leaders are on a keep.

RECRUIT_ALTERNATE_LOCATION 

No vacant castle tiles around a leader on a keep.

RECRUIT_OK 

Recruitment OK, but not at the specified location.

Recruitment OK.

Definition at line 39 of file create.hpp.

Function Documentation

bool actions::actor_sighted ( const unit target,
const std::vector< int > *  cache 
)

Fires sighted events for the sides that can see target.

If cache is supplied, only those sides might get events. If cache is nullptr, all sides might get events. This function is for the sighting of units that clear the shroud; it is the complement of shroud_clearer::fire_events(), which handles sighting by units that clear the shroud.

See get_sides_not_seeing() for a way to obtain a cache.

Returns
true if an event has mutated the game state.

Definition at line 623 of file vision.cpp.

References can_see(), create_jamming_map(), distance_between(), resources::game_events, resources::gameboard, unit::get_location(), i, unit::is_visible_to_team(), game_board::map(), game_events::manager::pump(), game_events::t_pump::raise(), unit::side(), sighted_str(), resources::teams, teams, and resources::units.

Referenced by advance_unit(), place_recruit(), and SYNCED_COMMAND_HANDLER_FUNCTION().

RECRUIT_CHECK actions::check_recall_location ( const int  side,
map_location recall_location,
map_location recall_from,
const unit unit_recall 
)

Checks if there is a location on which to recall unit_recall.

A leader of the side must be on a keep connected by castle to a legal recalling location to get an "OK" or "ALTERNATE_LOCATION" result.

If "OK" is returned, then the location provided in recall_location is legal. If "ALTERNATE_LOCATION" is returned, the provided location was illegal, so its value was replaced by a location where recalling can occur.

The location of the recalling leader is stored in recall_from. The incoming value of this parameter is used as a hint for finding a legal recaller, but this hint is given lower priority than finding a leader who can recall at recall_location.

Definition at line 276 of file create.cpp.

References unit_map::begin(), unit_map::end(), unit_map::find(), map_location::null_location(), RECRUIT_ALTERNATE_LOCATION, RECRUIT_NO_LEADER, RECRUIT_OK, resources::units, and map_location::valid().

Referenced by ai::recall_result::do_check_before(), and find_recall_location().

RECRUIT_CHECK actions::check_recruit_location ( const int  side,
map_location recruit_location,
map_location recruited_from,
const std::string unit_type 
)

Checks if there is a location on which to place a recruited unit.

A leader of the side must be on a keep connected by castle to a legal recruiting location to get an "OK" or "ALTERNATE_LOCATION" result.

If "OK" is returned, then the location provided in recruit_location is legal. If "ALTERNATE_LOCATION" is returned, the provided location was illegal, so its value was replaced by a location where recruitment can occur.

The location of the recruiting leader is stored in recruited_from. The incoming value of this parameter is used as a hint for finding a legal recruiter, but this hint is given lower priority than finding a leader who can recruit at recruit_location.

The unit_type is needed in case this is a leader-specific recruit.

Definition at line 406 of file create.cpp.

References unit_map::begin(), util::contains(), unit_map::end(), unit_map::find(), map_location::null_location(), RECRUIT_ALTERNATE_LOCATION, RECRUIT_NO_LEADER, RECRUIT_OK, resources::teams, unit_type(), resources::units, and map_location::valid().

Referenced by ai::recruit_result::do_check_before(), and find_recruit_location().

bool actions::clear_shroud ( int  side,
bool  reset_fog,
bool  fire_events 
)

Function that will clear shroud (and fog) based on current unit positions.

This will not re-fog hexes unless reset_fog is set to true. This function will do nothing if the side uses neither shroud nor fog. This function ignores the "delayed shroud updates" setting. The display is invalidated as needed.

Parameters
[in]sideThe side whose shroud (and fog) will be cleared.
[in]reset_fogIf set to true, the fog will also be recalculated (refogging hexes that can no longer be seen).
[in]fire_eventsIf set to false, sighted events will not be fired.
Returns
true if some shroud/fog is actually cleared away.

Definition at line 754 of file vision.cpp.

References actions::shroud_clearer::clear_unit(), actions::shroud_clearer::drop_events(), actions::shroud_clearer::fire_events(), actions::shroud_clearer::invalidate_after_clear(), recalculate_fog(), resources::units, team::uses_fog(), and team::uses_shroud().

Referenced by actions::undo_list::apply_shroud_changes(), play_controller::do_init_side(), play_controller::finish_side_turn(), game_lua_kernel::intf_redraw(), game_lua_kernel::intf_teleport(), play_controller::start_game(), and SYNCED_COMMAND_HANDLER_FUNCTION().

std::string actions::find_recall_location ( const int  side,
map_location recall_location,
map_location recall_from,
const unit unit_recall 
)

Finds a location on which to recall unit_recall.

A leader of the side must be on a keep connected by castle to a legal recalling location. Otherwise, an error message explaining this is returned.

If no errors are encountered, the location where a unit can be recalled is stored in recall_location. Its value is considered first, if it is a legal option. Also, the location of the recalling leader is stored in recall_from. The incoming value of this parameter is used as a hint for finding a legal recaller, but this hint is given lower priority than finding a leader who can recall at recall_location.

Returns
an empty string on success. Otherwise a human-readable message describing the failure is returned.

Definition at line 328 of file create.cpp.

References _(), check_recall_location(), ERR_NG, unit::id(), LOG_NG, RECRUIT_ALTERNATE_LOCATION, RECRUIT_NO_ABLE_LEADER, RECRUIT_NO_KEEP_LEADER, RECRUIT_NO_LEADER, RECRUIT_NO_VACANCY, and RECRUIT_OK.

Referenced by events::menu_handler::recall(), and actions::undo::recall_action::redo().

std::string actions::find_recruit_location ( const int  side,
map_location recruit_location,
map_location recruited_from,
const std::string unit_type 
)

Finds a location on which to place a unit.

A leader of the side must be on a keep connected by castle to a legal recruiting location. Otherwise, an error message explaining this is returned.

If no errors are encountered, the location where a unit can be recruited is stored in recruit_location. Its value is considered first, if it is a legal option. Also, the location of the recruiting leader is stored in recruited_from. The incoming value of recruited_from is used as a hint for finding a legal recruiter, but this hint is given lower priority than finding a leader who can recruit at recruit_location.

The unit_type is needed in case this is a leader-specific recruit.

Returns
an empty string on success. Otherwise a human-readable message describing the failure is returned.

Definition at line 464 of file create.cpp.

References _(), check_recruit_location(), ERR_NG, LOG_NG, RECRUIT_ALTERNATE_LOCATION, RECRUIT_NO_ABLE_LEADER, RECRUIT_NO_KEEP_LEADER, RECRUIT_NO_LEADER, RECRUIT_NO_VACANCY, and RECRUIT_OK.

Referenced by events::menu_handler::do_recruit(), actions::undo::recruit_action::redo(), and SYNCED_COMMAND_HANDLER_FUNCTION().

std::vector< unit_const_ptr > actions::get_recalls ( int  side,
const map_location recall_loc 
)

Gets the recallable units for a side, restricted by that side's leaders' personal abilities to recall on or from a specific hex field.

If no leader is able to recall on or from the given location, the full recall list of the side is returned.

Parameters
sideof the leaders to search for their personal recall filters.
recall_locthe hex field being part of the castle the player wants to recruit on or from.
Returns
a set of units that can be recalled by side on (or from) recall_loc or the full recall list of side.

Definition at line 163 of file create.cpp.

References unit_map::begin(), unit_map::end(), resources::filter_con, unit_map::find(), resources::gameboard, unit_map::iterator_base< iter_types >::get_shared_ptr(), gamemap::is_castle(), gamemap::is_keep(), LOG_NG, game_board::map(), resources::teams, and resources::units.

Referenced by events::menu_handler::recall().

const std::set< std::string > actions::get_recruits ( int  side,
const map_location recruit_location 
)

Gets the recruitable units from a side's leaders' personal recruit lists who can recruit on or from a specific hex field.

Parameters
sideof the leaders to search for their personal recruit lists.
recruit_locationthe hex field being part of the castle the player wants to recruit on or from.
Returns
a set of units that can be recruited either by the leader on recruit_location or by leaders on keeps connected by castle tiles to recruit_location.

Definition at line 63 of file create.cpp.

References unit_map::begin(), unit_map::end(), resources::filter_con, unit_map::find(), resources::gameboard, gamemap::is_castle(), gamemap::is_keep(), LOG_NG, game_board::map(), team::recruits(), and resources::units.

Referenced by events::menu_handler::do_recruit(), events::menu_handler::recruit(), and actions::undo::recruit_action::redo().

std::vector< int > actions::get_sides_not_seeing ( const unit target)

Returns the sides that cannot currently see target.

(Used to cache visibility before a move.)

Definition at line 596 of file vision.cpp.

References resources::gameboard, i, unit::is_visible_to_team(), game_board::map(), resources::teams, and teams.

Referenced by advance_unit().

bool actions::get_village ( const map_location loc,
int  side,
bool *  time_bonus = nullptr,
bool  fire_event = true 
)
size_t actions::move_unit_and_record ( const std::vector< map_location > &  steps,
undo_list *  undo_stack,
bool  continued_move,
bool  show_move,
bool *  interrupted,
move_unit_spectator *  move_spectator 
)

Moves a unit across the board.

This function handles actual movement, checking terrain costs as well as things that might interrupt movement (e.g. ambushes). If the full path cannot be reached this turn, the remainder is stored as the unit's "goto" instruction. (The unit itself is whatever unit is at the beginning of the supplied path.)

Parameters
[in]stepsThe route to be traveled. The unit to be moved is at the beginning of this route.
undo_stackIf supplied, then either this movement will be added to the stack or the stack will be cleared.
[in]continued_moveIf set to true, this is a continuation of an earlier move (movement is not interrupted should units be spotted).
[in]show_moveControls whether or not the movement is animated for the player.
[out]interruptedIf supplied, then this is set to true if information was uncovered that warrants interrupting a chain of actions (and set to false otherwise).
[out]move_spectatorIf supplied, this will be given the information uncovered by the move (and the unit's "goto" instruction will be preserved).
Returns
The number of hexes entered. This can safely be used as an index into steps to get the location where movement ended, provided steps is not empty (the return value is guaranteed to be less than steps.size() ).

And enters the synced context.

Definition at line 1225 of file move.cpp.

References replay::add_synced_command(), play_controller::check_victory(), resources::controller, DBG_NG, set_scontext_synced::do_final_checkup(), gui2::event::find(), unit_map::find(), team::fog_or_shroud(), replay_helper::get_movement(), synced_context::get_synced_state(), preferences::interrupt_when_ally_sighted(), play_controller::maybe_throw_return_to_play_side(), move_unit_internal(), map_location::null_location(), resources::recorder, synced_context::SYNCED, and resources::units.

Referenced by ai::move_result::do_execute(), events::menu_handler::execute_gotos(), events::mouse_handler::move_unit_along_route(), and events::menu_handler::move_unit_to_loc().

size_t actions::move_unit_from_replay ( const std::vector< map_location > &  steps,
undo_list *  undo_stack,
bool  continued_move,
bool  skip_ally_sighted,
bool  show_move = true 
)

Moves a unit across the board.

to be called from replay when we are already in the synced context.

Definition at line 1271 of file move.cpp.

References move_unit_internal(), and replay::process_error().

Referenced by SYNCED_COMMAND_HANDLER_FUNCTION().

static size_t actions::move_unit_internal ( undo_list *  undo_stack,
bool  show_move,
bool *  interrupted,
unit_mover &  mover 
)
static
place_recruit_result actions::place_recruit ( unit_ptr  u,
const map_location recruit_location,
const map_location recruited_from,
int  cost,
bool  is_recall,
bool  show,
bool  fire_event,
bool  full_movement,
bool  wml_triggered 
)
void actions::recalculate_fog ( int  side)

Function that recalculates the fog of war.

This is used at the end of a turn and for the defender at the end of combat. As a back-up, it is also called when clearing shroud at the beginning of a turn. This function does nothing if the indicated side does not use fog. This function ignores the "delayed shroud updates" setting. The display is invalidated as needed.

Parameters
[in]sideThe side whose fog will be recalculated.

Definition at line 705 of file vision.cpp.

References actions::shroud_clearer::clear_unit(), actions::shroud_clearer::fire_events(), team::fogged(), actions::shroud_clearer::invalidate_after_clear(), display::invalidate_all(), team::refog(), resources::screen, resources::units, and team::uses_fog().

Referenced by clear_shroud(), play_controller::finish_side_turn(), events::menu_handler::kill_unit(), and SYNCED_COMMAND_HANDLER_FUNCTION().

bool actions::recall_unit ( const std::string id,
team current_team,
const map_location loc,
const map_location from,
bool  show = true,
bool  use_undo = true 
)

Recalls the unit with the indicated ID for the provided team.

The ID can be a reference to data in the recall list. This is the point at which the code merges for recalls originating from players, the AI, and replays. It starts just after the recall location is successfully found, and it handles moving the unit to the board, paying gold, firing events, tracking statistics, updating the undo stack (unless use_undo is false), and recording the recall (unless use_recorder is false).

Returns
false if the recall could not be found in the team's recall list.

Definition at line 731 of file create.cpp.

References actions::undo_list::add_recall(), synced_context::can_undo(), actions::undo_list::clear(), recall_list_manager::extract_if_matches_id(), display::invalidate_game_status(), place_recruit(), team::recall_cost(), team::recall_list(), statistics::recall_unit(), resources::screen, gui2::tip::show(), and resources::undo_stack.

Referenced by ai::default_recruitment::recruitment::get_appropriate_recall(), wb::recall::recall(), actions::undo::recall_action::redo(), ai::simulated_recall(), and SYNCED_COMMAND_HANDLER_FUNCTION().

void actions::recruit_unit ( const unit_type u_type,
int  side_num,
const map_location loc,
const map_location from,
bool  show = true,
bool  use_undo = true 
)

Recruits a unit of the given type for the given side.

This is the point at which the code merges for recruits originating from players, the AI, and replays. It starts just after the recruit location is successfully found, and it handles creating the unit, paying gold, firing events, tracking statistics, and (unless is_ai) updating the undo stack.

Definition at line 699 of file create.cpp.

References actions::undo_list::add_recruit(), synced_context::can_undo(), actions::undo_list::clear(), unit_type::cost(), display::invalidate_game_status(), place_recruit(), statistics::recruit_unit(), resources::screen, gui2::tip::show(), and resources::undo_stack.

Referenced by actions::undo::recruit_action::redo(), ai::simulated_recruit(), and SYNCED_COMMAND_HANDLER_FUNCTION().