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 () | |
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, 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 58 of file vision.hpp.
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_.
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 69 of file vision.hpp.
References calculate_jamming().
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 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.
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().
|
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 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.
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 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.
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 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().
|
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.
instant | If false, then drawing delays (used to make movement look better) are allowed. |
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.
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.
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().
|
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().
|
private |
Definition at line 136 of file vision.hpp.
Referenced by calculate_jamming(), and clear_unit().
|
private |
Definition at line 137 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 139 of file vision.hpp.
Referenced by calculate_jamming(), and clear_unit().