The Battle for Wesnoth  1.19.0-dev
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
actions::shroud_clearer Class Reference

Class to encapsulate fog/shroud clearing and the resultant sighted events. More...

#include <vision.hpp>

Classes

struct  sight_data
 A record of a sighting event. More...
 

Public Member Functions

 shroud_clearer (const shroud_clearer &)=delete
 
shroud_cleareroperator= (const shroud_clearer &)=delete
 
 shroud_clearer ()
 Default constructor. More...
 
 ~shroud_clearer ()
 Destructor. More...
 
void cache_units (const team *new_team=nullptr)
 Function to be called if units have moved or otherwise changed. More...
 
bool clear_unit (const map_location &view_loc, team &view_team, std::size_t viewer_id, int sight_range, bool slowed, const movetype::terrain_costs &costs, const map_location &real_loc, const std::set< map_location > *known_units=nullptr, std::size_t *enemy_count=nullptr, std::size_t *friend_count=nullptr, move_unit_spectator *spectator=nullptr, bool instant=true)
 Clears shroud (and fog) around the provided location for view_team based on sight_range, costs, and slowed. More...
 
bool clear_unit (const map_location &view_loc, const unit &viewer, team &view_team, const std::set< map_location > *known_units=nullptr, std::size_t *enemy_count=nullptr, std::size_t *friend_count=nullptr, move_unit_spectator *spectator=nullptr, bool instant=true)
 Clears shroud (and fog) around the provided location for view_team as if viewer was standing there. More...
 
bool clear_unit (const map_location &view_loc, const unit &viewer, team &view_team, bool instant)
 Clears shroud (and fog) around the provided location for view_team as if viewer was standing there. More...
 
bool clear_unit (const map_location &view_loc, team &view_team, const clearer_info &viewer, bool instant)
 Clears shroud (and fog) around the provided location for view_team as if viewer was standing there. More...
 
bool clear_unit (const map_location &view_loc, const unit &viewer, bool can_delay=false, bool invalidate=true, bool instant=true)
 Clears shroud (and fog) around the provided location as if viewer was standing there. More...
 
bool clear_dest (const map_location &dest, const unit &viewer)
 Clears shroud (and fog) at the provided location and its immediate neighbors. More...
 
void drop_events ()
 Erases the record of sighted events from earlier fog/shroud clearing. More...
 
game_events::pump_result_t fire_events ()
 Fires the sighted events that were earlier recorded by fog/shroud clearing. More...
 
void invalidate_after_clear ()
 The invalidations that should occur after invoking clear_unit(). More...
 

Private Member Functions

void calculate_jamming (const team *new_team)
 Causes this object's "jamming" map to be recalculated. More...
 
bool clear_loc (team &tm, const map_location &loc, const map_location &view_loc, const map_location &event_non_loc, std::size_t viewer_id, bool check_units, std::size_t &enemy_count, std::size_t &friend_count, move_unit_spectator *spectator=nullptr)
 Clears shroud from a single location. More...
 
void record_sighting (const unit &seen, const map_location &seen_loc, std::size_t sighter_id, const map_location &sighter_loc)
 Convenience wrapper for adding sighting data to the sightings_ vector. More...
 

Private Attributes

std::map< map_location, int > jamming_
 
std::vector< sight_datasightings_
 
const teamview_team_
 Keeps track of the team associated with jamming_. More...
 

Detailed Description

Class to encapsulate fog/shroud clearing and the resultant sighted events.

Note: This class uses teams as parameters (instead of sides) since a function using this should first check to see if fog/shroud is in use (to save processing when it is not), which implies the team is readily available.

Definition at line 72 of file vision.hpp.

Constructor & Destructor Documentation

◆ shroud_clearer() [1/2]

actions::shroud_clearer::shroud_clearer ( const shroud_clearer )
delete

◆ shroud_clearer() [2/2]

actions::shroud_clearer::shroud_clearer ( )

Default constructor.

Definition at line 165 of file vision.cpp.

◆ ~shroud_clearer()

actions::shroud_clearer::~shroud_clearer ( )

Destructor.

The purpose of explicitly defining this is so we can log an error if the sighted events were neither fired nor explicitly ignored.

Definition at line 174 of file vision.cpp.

References ERR_NG, and sightings_.

Member Function Documentation

◆ cache_units()

void actions::shroud_clearer::cache_units ( const team new_team = nullptr)
inline

Function to be called if units have moved or otherwise changed.

It can also be called if it is desirable to calculate the cache in advance of fog clearing.

Parameters
[in]new_teamThe team whose vision will be used. If left as nullptr, the cache will be just be cleared (to be recalculated later as needed).

Definition at line 88 of file vision.hpp.

References calculate_jamming().

◆ calculate_jamming()

void actions::shroud_clearer::calculate_jamming ( const team new_team)
private

Causes this object's "jamming" map to be recalculated.

This gets called as needed, and can also be manually invoked via cache_units().

Parameters
[in]new_teamThe team whose vision will be used. If nullptr, the jamming map will be cleared.

Definition at line 188 of file vision.cpp.

References actions::create_jamming_map(), jamming_, and view_team_.

Referenced by cache_units(), and clear_unit().

◆ clear_dest()

bool actions::shroud_clearer::clear_dest ( const map_location dest,
const unit viewer 
)

Clears shroud (and fog) at the provided location and its immediate neighbors.

This is an aid for the [teleport] action, allowing the destination to be cleared before teleporting, while the unit's full visual range gets cleared after. The viewer is needed for correct firing of sighted events.

Returns
whether or not information was uncovered (i.e. returns true if the locations in question were fogged/shrouded under shared vision/maps).

Definition at line 490 of file vision.cpp.

References clear_loc(), team::fog_or_shroud(), resources::gameboard, get_adjacent_tiles(), unit::get_location(), game_board::get_team(), invalidate_after_clear(), unit::side(), and unit::underlying_id().

Referenced by game_lua_kernel::intf_teleport().

◆ clear_loc()

bool actions::shroud_clearer::clear_loc ( team tm,
const map_location loc,
const map_location view_loc,
const map_location event_non_loc,
std::size_t  viewer_id,
bool  check_units,
std::size_t &  enemy_count,
std::size_t &  friend_count,
move_unit_spectator spectator = nullptr 
)
private

Clears shroud from a single location.

This also records sighted events for later firing.

In a few cases, this will also clear corner hexes that otherwise would not normally get cleared.

Parameters
tmThe team whose fog/shroud is affected.
locThe location to clear.
view_locThe location viewer is assumed at (for sighted events).
event_non_locThe unit at this location cannot be sighted (used to prevent a unit from sighting itself).
viewer_idThe underlying ID of the unit doing the sighting (for events).
check_unitsIf false, there is no checking for an uncovered unit.
enemy_countIncremented if an enemy is uncovered.
friend_countIncremented if a friend is uncovered.
spectatorWill be told if a unit is uncovered.
Returns
whether or not information was uncovered (i.e. returns true if the specified location was fogged/ shrouded under shared vision/maps).

Definition at line 222 of file vision.cpp.

References actions::move_unit_spectator::add_seen_enemy(), actions::move_unit_spectator::add_seen_friend(), team::clear_fog(), team::clear_shroud(), actions::clear_shroud(), game_board::find_visible_unit(), team::fogged(), resources::gameboard, get_adjacent_tiles(), display::get_singleton(), gamemap_base::h(), display::invalidate(), team::is_enemy(), is_even(), is_odd(), game_board::map(), gamemap_base::on_board(), gamemap_base::on_board_with_border(), record_sighting(), unit::STATE_PETRIFIED, unit_map::iterator_base< iter_types >::valid(), gamemap_base::w(), map_location::x, and map_location::y.

Referenced by clear_dest(), and clear_unit().

◆ clear_unit() [1/5]

bool actions::shroud_clearer::clear_unit ( const map_location view_loc,
const unit viewer,
bool  can_delay = false,
bool  invalidate = true,
bool  instant = true 
)

Clears shroud (and fog) around the provided location as if viewer was standing there.

This version of shroud_clearer::clear_unit() will abort if the viewer's team uses neither fog nor shroud. If can_delay is left as true, then this function also aborts on the viewing team's turn if delayed shroud updates is on. (Not supplying a team suggests that it would be inconvenient for the caller to check these.) In addition, if invalidate is left as true, invalidate_after_clear() will be called. Setting instant to false allows some drawing delays that are used to make movement look better.

Returns
whether or not information was uncovered (i.e. returns true if any locations in visual range were fogged/shrouded under shared vision/maps).

Definition at line 457 of file vision.cpp.

References team::auto_shroud_updates(), clear_unit(), resources::controller, play_controller::current_side(), team::fog_or_shroud(), resources::gameboard, game_board::get_team(), invalidate_after_clear(), and unit::side().

◆ clear_unit() [2/5]

bool actions::shroud_clearer::clear_unit ( const map_location view_loc,
const unit viewer,
team view_team,
bool  instant 
)
inline

Clears shroud (and fog) around the provided location for view_team as if viewer was standing there.

Setting instant to false allows some drawing delays that are used to make movement look better.

Definition at line 118 of file vision.hpp.

References clear_unit().

◆ clear_unit() [3/5]

bool actions::shroud_clearer::clear_unit ( const map_location view_loc,
const unit viewer,
team view_team,
const std::set< map_location > *  known_units = nullptr,
std::size_t *  enemy_count = nullptr,
std::size_t *  friend_count = nullptr,
move_unit_spectator spectator = nullptr,
bool  instant = true 
)

Clears shroud (and fog) around the provided location for view_team as if viewer was standing there.

This will also record sighted events, which should be either fired or explicitly dropped.

This should only be called if delayed shroud updates is off. It is wasteful to call this if view_team uses neither fog nor shroud.

Parameters
view_locThe location to clear fog from.
viewerThe unit whose vision range will be used to clear the fog.
view_teamThe team who will have the fog cleared from their map.
known_unitsThese locations are not checked for uncovered units.
enemy_countIncremented for each enemy uncovered (excluding known_units).
friend_countIncremented for each friend uncovered (excluding known_units).
spectatorWill be told of uncovered units (excluding known_units).
instantIf false, then drawing delays (used to make movement look better) are allowed.
Returns
whether or not information was uncovered (i.e. returns true if any locations in visual range were fogged/shrouded under shared vision/maps).

Definition at line 394 of file vision.cpp.

References clear_unit(), unit::get_location(), unit::get_state(), movetype::get_vision(), unit::movement_type(), unit::STATE_SLOWED, unit::underlying_id(), and unit::vision().

◆ clear_unit() [4/5]

bool actions::shroud_clearer::clear_unit ( const map_location view_loc,
team view_team,
const clearer_info viewer,
bool  instant 
)

Clears shroud (and fog) around the provided location for view_team as if viewer was standing there.

This will also record sighted events, which should be either fired or explicitly dropped.

This should only be called if delayed shroud updates is off. It is wasteful to call this if view_team uses neither fog nor shroud.

Parameters
view_locThe location to clear fog from.
viewerThe unit whose vision range will be used to clear the fog.
view_teamThe team who will have the fog cleared from their map.
instantIf false, then drawing delays (used to make movement look better) are allowed.
Returns
whether or not information was uncovered (i.e. returns true if any locations in visual range were fogged/shrouded under shared vision/maps).

Definition at line 426 of file vision.cpp.

References clear_unit(), actions::clearer_info::costs, unit_map::end(), unit_map::find(), resources::gameboard, map_location::null_location(), actions::clearer_info::sight_range, actions::clearer_info::slowed, actions::clearer_info::underlying_id, and game_board::units().

◆ clear_unit() [5/5]

bool actions::shroud_clearer::clear_unit ( const map_location view_loc,
team view_team,
std::size_t  viewer_id,
int  sight_range,
bool  slowed,
const movetype::terrain_costs costs,
const map_location real_loc,
const std::set< map_location > *  known_units = nullptr,
std::size_t *  enemy_count = nullptr,
std::size_t *  friend_count = nullptr,
move_unit_spectator spectator = nullptr,
bool  instant = true 
)

Clears shroud (and fog) around the provided location for view_team based on sight_range, costs, and slowed.

This will also record sighted events, which should be either fired or explicitly dropped. (The sighter is the unit with underlying id viewer_id.)

This should only be called if delayed shroud updates is off. It is wasteful to call this if view_team uses neither fog nor shroud.

Parameters
view_locThe location to clear fog from.
view_teamThe team who will have the fog cleared from their map.
viewer_idThe underlying ID of the unit doing the sighting (for events).
sight_range
slowedWhether the unit is slowed.
costsThe terrain costs for the unit.
real_locThe actual location of the viewing unit. (This is used to avoid having a unit sight itself.)
known_unitsThese locations are not checked for uncovered units.
enemy_countIncremented for each enemy uncovered (excluding known_units).
friend_countIncremented for each friend uncovered (excluding known_units).
spectatorWill be told of uncovered units (excluding known_units).
instantIf false, then drawing delays (used to make movement look better) are allowed.
Returns
whether or not information was uncovered (i.e. returns true if any locations in visual range were fogged/shrouded under shared vision/maps).

Definition at line 330 of file vision.cpp.

References calculate_jamming(), clear_loc(), pathfind::paths::step::curr, pathfind::paths::destinations, pathfind::vision_path::edges, jamming_, game_config::sounds::status::slowed, and view_team_.

Referenced by advance_unit(), actions::undo_list::apply_shroud_changes(), actions::clear_shroud(), clear_unit(), game_lua_kernel::intf_teleport(), actions::place_recruit(), actions::recalculate_fog(), and SYNCED_COMMAND_HANDLER_FUNCTION().

◆ drop_events()

void actions::shroud_clearer::drop_events ( )

Erases the record of sighted events from earlier fog/shroud clearing.

Clears the record of sighted events from earlier fog/shroud clearing.

This should be called if the events are to be ignored and not fired. (Non-cleared, non-fired events will be logged as an error.)

Definition at line 528 of file vision.cpp.

References DBG_NG, and sightings_.

Referenced by actions::clear_shroud().

◆ fire_events()

game_events::pump_result_t actions::shroud_clearer::fire_events ( )

Fires the sighted events that were earlier recorded by fog/shroud clearing.

Fires the sighted events that were recorded by earlier fog/shroud clearing.

Returns
true if the events have mutated the game state.

Definition at line 541 of file vision.cpp.

References unit_map::end(), unit_map::find(), resources::game_events, resources::gameboard, map_location::null_location(), game_events::manager::pump(), game_events::wml_event_pump::raise(), sighted_str(), sightings_, and game_board::units().

Referenced by advance_unit(), actions::undo_list::apply_shroud_changes(), actions::clear_shroud(), game_lua_kernel::intf_teleport(), actions::place_recruit(), actions::recalculate_fog(), and SYNCED_COMMAND_HANDLER_FUNCTION().

◆ invalidate_after_clear()

void actions::shroud_clearer::invalidate_after_clear ( )

The invalidations that should occur after invoking clear_unit().

This is separate since clear_unit() might be invoked several times in a row, and the invalidations might only need to be done once.

Definition at line 576 of file vision.cpp.

References display::get_singleton(), display::invalidate_game_status(), display::labels(), display::recalculate_minimap(), and map_labels::recalculate_shroud().

Referenced by actions::undo_list::apply_shroud_changes(), clear_dest(), actions::clear_shroud(), clear_unit(), and actions::recalculate_fog().

◆ operator=()

shroud_clearer& actions::shroud_clearer::operator= ( const shroud_clearer )
delete

◆ record_sighting()

void actions::shroud_clearer::record_sighting ( const unit seen,
const map_location seen_loc,
std::size_t  sighter_id,
const map_location sighter_loc 
)
inlineprivate

Convenience wrapper for adding sighting data to the sightings_ vector.

Definition at line 154 of file vision.cpp.

References sightings_, and unit::underlying_id().

Referenced by clear_loc().

Member Data Documentation

◆ jamming_

std::map<map_location, int> actions::shroud_clearer::jamming_
private

Definition at line 165 of file vision.hpp.

Referenced by calculate_jamming(), and clear_unit().

◆ sightings_

std::vector<sight_data> actions::shroud_clearer::sightings_
private

Definition at line 166 of file vision.hpp.

Referenced by drop_events(), fire_events(), record_sighting(), and ~shroud_clearer().

◆ view_team_

const team* actions::shroud_clearer::view_team_
private

Keeps track of the team associated with jamming_.

Definition at line 168 of file vision.hpp.

Referenced by calculate_jamming(), and clear_unit().


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