The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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>

Inheritance diagram for actions::shroud_clearer:
Inheritance graph

Classes

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

Public Member Functions

 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, 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, size_t *enemy_count=nullptr, 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, size_t *enemy_count=nullptr, 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...
 
bool 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, size_t viewer_id, bool check_units, size_t &enemy_count, 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, 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, intjamming_
 
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 58 of file vision.hpp.

Constructor & Destructor Documentation

actions::shroud_clearer::shroud_clearer ( )

Default constructor.

Definition at line 170 of file vision.cpp.

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 179 of file vision.cpp.

References ERR_NG, and sightings_.

Member Function Documentation

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 69 of file vision.hpp.

References 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 193 of file vision.cpp.

References create_jamming_map(), jamming_, and view_team_.

Referenced by cache_units(), and clear_unit().

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 495 of file vision.cpp.

References clear_loc(), team::fog_or_shroud(), get_adjacent_tiles(), unit::get_location(), i, invalidate_after_clear(), unit::side(), and unit::underlying_id().

Referenced by game_lua_kernel::intf_teleport().

bool actions::shroud_clearer::clear_loc ( team tm,
const map_location loc,
const map_location view_loc,
const map_location event_non_loc,
size_t  viewer_id,
bool  check_units,
size_t &  enemy_count,
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 227 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(), game_board::find_visible_unit(), team::fogged(), resources::gameboard, get_adjacent_tiles(), gamemap::h(), i, display::invalidate(), team::is_enemy(), is_even(), is_odd(), game_board::map(), gamemap::on_board(), gamemap::on_board_with_border(), record_sighting(), resources::screen, unit::STATE_PETRIFIED, unit_map::iterator_base< iter_types >::valid(), gamemap::w(), map_location::x, and map_location::y.

Referenced by clear_dest(), and clear_unit().

bool actions::shroud_clearer::clear_unit ( const map_location view_loc,
team view_team,
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,
size_t *  enemy_count = nullptr,
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
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 331 of file vision.cpp.

References calculate_jamming(), clear_loc(), pathfind::paths::step::curr, pathfind::paths::destinations, display::draw(), pathfind::vision_path::edges, jamming_, resources::screen, 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().

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,
size_t *  enemy_count = nullptr,
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
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 402 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().

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 93 of file vision.hpp.

References clear_unit().

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
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 431 of file vision.cpp.

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

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 462 of file vision.cpp.

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

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 534 of file vision.cpp.

References DBG_NG, and sightings_.

Referenced by actions::clear_shroud().

bool 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 547 of file vision.cpp.

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

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

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 582 of file vision.cpp.

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

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

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

Convenience wrapper for adding sighting data to the sightings_ vector.

Definition at line 158 of file vision.cpp.

References sightings_, and unit::underlying_id().

Referenced by clear_loc().

Member Data Documentation

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

Definition at line 136 of file vision.hpp.

Referenced by calculate_jamming(), and clear_unit().

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

Definition at line 137 of file vision.hpp.

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

const team* actions::shroud_clearer::view_team_
private

Keeps track of the team associated with jamming_.

Definition at line 139 of file vision.hpp.

Referenced by calculate_jamming(), and clear_unit().


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