40 #define DBG_NG LOG_STREAM(debug, log_engine) 
   41 #define ERR_NG LOG_STREAM(err, log_engine) 
   48                                  const team & view_team)
 
   56         if ( u.jamming() < 1  ||  !view_team.
is_enemy(u.side()) )
 
   76                     const std::map<map_location, int> * jamming = 
nullptr)
 
   79     std::map<map_location, int> local_jamming;
 
   80     if ( jamming == 
nullptr ) {
 
   82         jamming = &local_jamming;
 
   99     underlying_id(viewer.underlying_id()),
 
  100     sight_range(viewer.vision()),
 
  102     costs(viewer.movement_type().get_vision().make_standalone())
 
  110     underlying_id(
cfg[
"underlying_id"].to_size_t()),
 
  111     sight_range(
cfg[
"vision"].to_int()),
 
  112     slowed(
cfg.child_or_empty(
"status")[
"slowed"].to_bool()),
 
  113     costs(
movetype::read_terrain_costs(
cfg.child_or_empty(
"vision_costs")))
 
  139                std::size_t viewer_id, 
const map_location & viewer_loc) :
 
  156     std::size_t sighter_id, 
const map_location & sighter_loc)
 
  225                                std::size_t viewer_id, 
bool check_units,
 
  226                                std::size_t &enemy_count, std::size_t &friend_count,
 
  249             if ( 
loc.
x == 0  &&  
loc.
y == map.
h()-1 ) {
 
  279     if ( result  &&  check_units  &&  
loc != event_non_loc ) {
 
  282         if ( sight_it.
valid() ) {
 
  287                 if ( tm.
is_enemy(sight_it->side()) ) {
 
  331                                 std::size_t viewer_id, 
int sight_range, 
bool slowed,
 
  334                                 const std::set<map_location>* known_units,
 
  335                                 std::size_t * enemy_count, std::size_t * friend_count,
 
  338     bool cleared_something = 
false;
 
  340     std::size_t enemies=0, friends=0;
 
  341     if ( enemy_count == 
nullptr )
 
  342         enemy_count = &enemies;
 
  343     if ( friend_count == 
nullptr )
 
  344         friend_count = &friends;
 
  356         bool known = known_units  &&  known_units->count(dest.
curr) != 0;
 
  357         if ( 
clear_loc(view_team, dest.
curr, view_loc, real_loc, viewer_id, !known,
 
  358                        *enemy_count, *friend_count, spectator) )
 
  359             cleared_something = 
true;
 
  363         bool known = known_units  &&  known_units->count(dest) != 0;
 
  364         if ( 
clear_loc(view_team, dest, view_loc, real_loc, viewer_id, !known,
 
  365                        *enemy_count, *friend_count, spectator) )
 
  366             cleared_something = 
true;
 
  369     return cleared_something;
 
  395                                 const unit &viewer, 
team &view_team,
 
  396                                 const std::set<map_location>* known_units,
 
  397                                 std::size_t * enemy_count, std::size_t * friend_count,
 
  405                       known_units, enemy_count, friend_count, spectator, instant);
 
  433                                         find_it->get_location();
 
  437                       real_loc, 
nullptr, 
nullptr, 
nullptr, 
nullptr, instant);
 
  458                                 bool can_delay, 
bool invalidate, 
bool instant)
 
  469     if ( !
clear_unit(view_loc, viewer, viewing_team, instant) )
 
  494     std::size_t enemies, friends;
 
  505     bool cleared_something = 
clear_loc(viewing_team, dest, dest, real_loc,
 
  506                                        viewer_id, 
true, enemies, friends);
 
  511         if(
clear_loc(viewing_team, adj, dest, real_loc, viewer_id, 
true, enemies, friends)) {
 
  512             cleared_something = 
true;
 
  516     if ( cleared_something )
 
  519     return cleared_something;
 
  550     std::vector<sight_data> sight_list;
 
  558                                      find_it->get_location();
 
  592     std::vector<int> not_seeing;
 
  595             not_seeing.push_back(
t.side());
 
  626     const std::size_t teams_size = teams.size();
 
  630     boost::dynamic_bitset<> needs_event;
 
  631     needs_event.resize(teams_size, cache == 
nullptr);
 
  632     if ( cache != 
nullptr ) {
 
  634         for (
int side : *cache)
 
  635             needs_event[side-1] = 
true;
 
  638     needs_event[target.
side()-1] = 
false;
 
  640     for ( std::size_t 
i = 0; 
i != teams_size; ++
i )
 
  644     std::vector< std::map<map_location, int>> jamming_cache(teams_size);
 
  645     for ( std::size_t 
i = 0; 
i != teams_size; ++
i )
 
  646         if ( needs_event[
i] )
 
  650     std::vector<const unit *> second_units(teams_size, 
nullptr);
 
  651     std::vector<std::size_t> distances(teams_size, std::numeric_limits<unsigned>::max());
 
  653         const std::size_t 
index = viewer.side() - 1;
 
  655         if ( needs_event[
index]  &&  distances[
index] != 0 ) {
 
  656             if ( 
can_see(viewer, target_loc, &jamming_cache[
index]) ) {
 
  658                 second_units[
index] = &viewer;
 
  659                 distances[
index] = 0;
 
  663                 std::size_t viewer_distance =
 
  665                 if ( viewer_distance < distances[
index] ) {
 
  666                     second_units[
index] = &viewer;
 
  667                     distances[
index] = viewer_distance;
 
  675     for ( std::size_t 
i = 0; 
i != teams_size; ++
i )
 
  676         if ( second_units[
i] != 
nullptr ) {
 
  705     std::set<map_location> visible_locs;
 
  709         if ( !tm.
fogged(u_location) )
 
  710             visible_locs.insert(u_location);
 
  721         if ( u.side() == side )
 
  722             clearer.
clear_unit(u.get_location(), u, tm, &visible_locs);
 
  757         if ( u.side() == side )
 
  758             result |= clearer.
clear_unit(u.get_location(), u, tm);
 
Various functions related to moving units.
void add_seen_friend(const unit_map::const_iterator &u)
add a location of a seen friend
void add_seen_enemy(const unit_map::const_iterator &u)
add the location of new seen enemy
Class to encapsulate fog/shroud clearing and the resultant sighted events.
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.
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.
void invalidate_after_clear()
The invalidations that should occur after invoking clear_unit().
void drop_events()
Erases the record of sighted events from earlier fog/shroud clearing.
const team * view_team_
Keeps track of the team associated with jamming_.
void calculate_jamming(const team *new_team)
Causes this object's "jamming" map to be recalculated.
std::vector< sight_data > sightings_
shroud_clearer()
Default constructor.
~shroud_clearer()
Destructor.
std::map< map_location, int > jamming_
bool clear_dest(const map_location &dest, const unit &viewer)
Clears shroud (and fog) at the provided location and its immediate neighbors.
game_events::pump_result_t fire_events()
Fires the sighted events that were earlier recorded by fog/shroud clearing.
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,...
A config object defines a single node in a WML file, with access to child nodes.
config & add_child(std::string_view key)
void recalculate_minimap()
Schedule the minimap for recalculation.
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
void invalidate_game_status()
Function to invalidate the game status displayed on the sidebar.
void invalidate_all()
Function to invalidate all tiles.
static display * get_singleton()
Returns the display object if a display object exists.
virtual const std::vector< team > & teams() const override
unit_map::iterator find_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)
virtual const unit_map & units() const override
virtual const gamemap & map() const override
game_events::wml_event_pump & pump()
void raise(const std::string &event, const std::string &id, const entity_location &loc1=entity_location::null_entity, const entity_location &loc2=entity_location::null_entity, const config &data=config())
int w() const
Effective map width.
int h() const
Effective map height.
bool on_board_with_border(const map_location &loc) const
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Encapsulates the map of the game.
void recalculate_shroud()
A const-only interface for how many (movement, vision, or "jamming") points a unit needs for each hex...
The basic "size" of the unit - flying, small land, large land, etc.
const terrain_costs & get_vision() const
int current_side() const
Returns the number of the side whose turn it is.
This class stores all the data for a single 'side' (in game nomenclature).
bool clear_shroud(const map_location &loc)
bool fog_or_shroud() const
bool auto_shroud_updates() const
bool clear_fog(const map_location &loc)
bool is_enemy(int n) const
bool fogged(const map_location &loc) const
Container associating units to locations.
unit_iterator find(std::size_t id)
This class represents a single unit of a specific type.
Definitions for the interface to Wesnoth Markup Language (WML).
bool is_visible_to_team(const team &team, bool const see_all=true) const
bool get_state(const std::string &state) const
Check if the unit is affected by a status effect.
int side() const
The side this unit belongs to.
std::size_t underlying_id() const
This unit's unique internal ID.
@ STATE_PETRIFIED
The unit is poisoned - it loses health each turn.
const map_location & get_location() const
The current map location this unit is at.
const movetype & movement_type() const
Get the unit's movement type.
int vision() const
Gets the unit's vision points.
std::size_t distance_between(const map_location &a, const map_location &b)
Function which gives the number of hexes between two tiles (i.e.
void get_adjacent_tiles(const map_location &a, utils::span< map_location, 6 > res)
Function which, given a location, will place all adjacent locations in res.
Standard logging facilities (interface).
constexpr bool is_even(T num)
constexpr bool is_odd(T num)
std::vector< int > get_sides_not_seeing(const unit &target)
Returns the sides that cannot currently see target.
bool clear_shroud(int side, bool reset_fog, bool fire_events)
Function that will clear shroud (and fog) based on current unit positions.
game_events::pump_result_t actor_sighted(const unit &target, const std::vector< int > *cache)
Fires sighted events for the sides that can see target.
void create_jamming_map(std::map< map_location, int > &jamming, const team &view_team)
Helper function that creates the map of enemy anti-vision that's needed when creating a pathfinding::...
void recalculate_fog(int side)
Function that recalculates the fog of war.
std::tuple< bool, bool > pump_result_t
game_events::manager * game_events
play_controller * controller
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
This module contains various pathfinding functions and utilities.
Define the game's event mechanism.
Class that stores the part of a unit's data that is needed for fog clearing.
void write(config &cfg) const
Writes to a config.
std::size_t underlying_id
clearer_info(const unit &viewer)
Constructor from a unit.
std::unique_ptr< movetype::terrain_costs > costs
costs is always non-null, all of the constructors initialize it
A record of a sighting event.
sight_data(std::size_t viewed_id, const map_location &viewed_loc, std::size_t viewer_id, const map_location &viewer_loc)
Encapsulates the map of the game.
static const map_location & null_location()
A refinement of paths for use when calculating jamming.
bool contains(const map_location &) const
A refinement of paths for use when calculating vision.
std::set< map_location > edges
The edges are the non-destination hexes bordering the destinations.
static lg::log_domain log_engine("engine")
static bool can_see(const unit &viewer, const map_location &loc, const std::map< map_location, int > *jamming=nullptr)
Determines if loc is within viewer's visual range.
static const std::string sighted_str("sighted")
Various functions implementing vision (through fog of war and shroud).