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_clearer & | operator= (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_data > | sightings_ |
const team * | view_team_ |
Keeps track of the team associated with jamming_. More... | |
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.
|
delete |
actions::shroud_clearer::shroud_clearer | ( | ) |
Default constructor.
Definition at line 165 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 174 of file vision.cpp.
References ERR_NG, and sightings_.
|
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.
[in] | new_team | The 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().
|
private |
Causes this object's "jamming" map to be recalculated.
This gets called as needed, and can also be manually invoked via cache_units().
[in] | new_team | The 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().
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.
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().
|
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.
tm | The team whose fog/shroud is affected. |
loc | The location to clear. |
view_loc | The location viewer is assumed at (for sighted events). |
event_non_loc | The unit at this location cannot be sighted (used to prevent a unit from sighting itself). |
viewer_id | The underlying ID of the unit doing the sighting (for events). |
check_units | If false, there is no checking for an uncovered unit. |
enemy_count | Incremented if an enemy is uncovered. |
friend_count | Incremented if a friend is uncovered. |
spectator | Will be told if a unit is uncovered. |
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().
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.
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().
|
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().
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.
view_loc | The location to clear fog from. |
viewer | The unit whose vision range will be used to clear the fog. |
view_team | The team who will have the fog cleared from their map. |
known_units | These locations are not checked for uncovered units. |
enemy_count | Incremented for each enemy uncovered (excluding known_units). |
friend_count | Incremented for each friend uncovered (excluding known_units). |
spectator | Will be told of uncovered units (excluding known_units). |
instant | If false, then drawing delays (used to make movement look better) are allowed. |
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().
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.
view_loc | The location to clear fog from. |
viewer | The unit whose vision range will be used to clear the fog. |
view_team | The team who will have the fog cleared from their map. |
instant | If false, then drawing delays (used to make movement look better) are allowed. |
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().
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.
view_loc | The location to clear fog from. |
view_team | The team who will have the fog cleared from their map. |
viewer_id | The underlying ID of the unit doing the sighting (for events). |
sight_range | |
slowed | Whether the unit is slowed. |
costs | The terrain costs for the unit. |
real_loc | The actual location of the viewing unit. (This is used to avoid having a unit sight itself.) |
known_units | These locations are not checked for uncovered units. |
enemy_count | Incremented for each enemy uncovered (excluding known_units). |
friend_count | Incremented for each friend uncovered (excluding known_units). |
spectator | Will be told of uncovered units (excluding known_units). |
instant | If false, then drawing delays (used to make movement look better) are allowed. |
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().
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().
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.
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().
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().
|
delete |
|
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().
|
private |
Definition at line 165 of file vision.hpp.
Referenced by calculate_jamming(), and clear_unit().
|
private |
Definition at line 166 of file vision.hpp.
Referenced by drop_events(), fire_events(), record_sighting(), and ~shroud_clearer().
|
private |
Keeps track of the team associated with jamming_.
Definition at line 168 of file vision.hpp.
Referenced by calculate_jamming(), and clear_unit().