36 #include <boost/dynamic_bitset.hpp> 41 #define DBG_NG LOG_STREAM(debug, log_engine) 42 #define ERR_NG LOG_STREAM(err, log_engine) 52 const team & view_team)
60 if ( u.jamming() < 1 || !view_team.
is_enemy(u.side()) )
80 const std::map<map_location, int> * jamming =
nullptr)
83 std::map<map_location, int> local_jamming;
84 if ( jamming ==
nullptr ) {
86 jamming = &local_jamming;
103 underlying_id(viewer.underlying_id()),
104 sight_range(viewer.vision()),
106 costs(viewer.movement_type().get_vision().make_standalone())
116 slowed(cfg.child_or_empty(
"status")[
"slowed"].to_bool()),
117 costs(
movetype::read_terrain_costs(cfg.child_or_empty(
"vision_costs")))
131 cfg.
add_child(
"status")[
"slowed"] =
true;
132 costs->write(cfg,
"vision_costs");
143 std::size_t viewer_id,
const map_location & viewer_loc) :
144 seen_id(viewed_id), seen_loc(viewed_loc),
145 sighter_id(viewer_id), sighter_loc(viewer_loc)
160 std::size_t sighter_id,
const map_location & sighter_loc)
162 sightings_.emplace_back(seen.
underlying_id(), seen_loc, sighter_id, sighter_loc);
181 ERR_NG <<
sightings_.size() <<
" sighted events were ignored." << std::endl;
229 std::size_t viewer_id,
bool check_units,
230 std::size_t &enemy_count, std::size_t &friend_count,
237 bool was_fogged = tm.
fogged(loc);
238 bool result = was_fogged && map.
on_board(loc);
253 if ( loc.
x == 0 && loc.
y == map.
h()-1 ) {
259 else if (
is_odd(map.
w()) && loc.
x == map.
w()-1 && loc.
y == map.
h()-1 ) {
265 else if (
is_even(map.
w()) && loc.
x == map.
w()-1 && loc.
y == 0) {
283 if ( result && check_units && loc != event_non_loc ) {
286 if ( sight_it.
valid() ) {
291 if ( tm.
is_enemy(sight_it->side()) ) {
335 std::size_t viewer_id,
int sight_range,
bool slowed,
338 const std::set<map_location>* known_units,
339 std::size_t * enemy_count, std::size_t * friend_count,
346 bool cleared_something =
false;
348 std::size_t enemies=0, friends=0;
349 if ( enemy_count ==
nullptr )
350 enemy_count = &enemies;
351 if ( friend_count ==
nullptr )
352 friend_count = &friends;
370 bool known = known_units && known_units->count(dest.
curr) != 0;
371 if (
clear_loc(view_team, dest.
curr, view_loc, real_loc, viewer_id, !known,
372 *enemy_count, *friend_count, spectator) )
373 cleared_something =
true;
377 bool known = known_units && known_units->count(dest) != 0;
378 if (
clear_loc(view_team, dest, view_loc, real_loc, viewer_id, !known,
379 *enemy_count, *friend_count, spectator) )
380 cleared_something =
true;
383 return cleared_something;
409 const unit &viewer,
team &view_team,
410 const std::set<map_location>* known_units,
411 std::size_t * enemy_count, std::size_t * friend_count,
419 known_units, enemy_count, friend_count, spectator, instant);
447 find_it->get_location();
451 real_loc,
nullptr,
nullptr,
nullptr,
nullptr, instant);
472 bool can_delay,
bool invalidate,
bool instant)
483 if ( !
clear_unit(view_loc, viewer, viewing_team, instant) )
508 std::size_t enemies, friends;
519 bool cleared_something =
clear_loc(viewing_team, dest, dest, real_loc,
520 viewer_id,
true, enemies, friends);
525 if(
clear_loc(viewing_team, adj, dest, real_loc, viewer_id,
true, enemies, friends)) {
526 cleared_something =
true;
530 if ( cleared_something )
533 return cleared_something;
564 std::vector<sight_data> sight_list;
572 find_it->get_location();
607 std::vector<int> not_seeing;
609 std::size_t team_size = teams.size();
610 for ( std::size_t
i = 0;
i != team_size; ++
i)
613 not_seeing.push_back(i+1);
643 const std::size_t teams_size = teams.size();
647 boost::dynamic_bitset<> needs_event;
648 needs_event.resize(teams_size, cache ==
nullptr);
649 if ( cache !=
nullptr ) {
651 for (
int side : *cache)
652 needs_event[side-1] =
true;
655 needs_event[target.
side()-1] =
false;
657 for ( std::size_t
i = 0;
i != teams_size; ++
i )
661 std::vector< std::map<map_location, int>> jamming_cache(teams_size);
662 for ( std::size_t i = 0; i != teams_size; ++
i )
663 if ( needs_event[i] )
667 std::vector<const unit *> second_units(teams_size,
nullptr);
668 std::vector<std::size_t> distances(teams_size, UINT_MAX);
670 const std::size_t
index = viewer.side() - 1;
672 if ( needs_event[index] && distances[index] != 0 ) {
673 if (
can_see(viewer, target_loc, &jamming_cache[index]) ) {
675 second_units[
index] = &viewer;
676 distances[
index] = 0;
680 std::size_t viewer_distance =
682 if ( viewer_distance < distances[index] ) {
683 second_units[
index] = &viewer;
684 distances[
index] = viewer_distance;
692 for ( std::size_t i = 0; i != teams_size; ++
i )
693 if ( second_units[i] !=
nullptr ) {
722 std::set<map_location> visible_locs;
726 if ( !tm.
fogged(u_location) )
727 visible_locs.insert(u_location);
738 if ( u.side() == side )
739 clearer.
clear_unit(u.get_location(), u, tm, &visible_locs);
774 if ( u.side() == side )
775 result |= clearer.
clear_unit(u.get_location(), u, tm);
Class that stores the part of a unit's data that is needed for fog clearing.
play_controller * controller
void recalculate_shroud()
A const-only interface for how many (movement, vision, or "jamming") points a unit needs for each hex...
int h() const
Effective map height, in hexes.
static display * get_singleton()
Returns the display object if a display object exists.
std::vector< sight_data > sightings_
virtual const std::vector< team > & teams() const override
void invalidate_game_status()
Function to invalidate the game status displayed on the sidebar.
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
virtual const unit_map & units() const override
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
int vision() const
Gets the unit's vision points.
This class represents a single unit of a specific type.
A record of a sighting event.
Various functions implementing vision (through fog of war and shroud).
bool get_state(const std::string &state) const
Check if the unit is affected by a status effect.
bool clear_fog(const map_location &loc)
const movetype & movement_type() const
Get the unit's movement type.
A refinement of paths for use when calculating jamming.
std::size_t underlying_id
~shroud_clearer()
Destructor.
virtual const gamemap & map() const override
The unit is poisoned - it loses health each turn.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
clearer_info(const unit &viewer)
Constructor from a unit.
virtual void draw()
Draws invalidated items.
The basic "size" of the unit - flying, small land, large land, etc.
void calculate_jamming(const team *new_team)
Causes this object's "jamming" map to be recalculated.
Definitions for the interface to Wesnoth Markup Language (WML).
static void create_jamming_map(std::map< map_location, int > &jamming, const team &view_team)
Sets jamming to the (newly calculated) "jamming" map for view_team.
bool clear_dest(const map_location &dest, const unit &viewer)
Clears shroud (and fog) at the provided location and its immediate neighbors.
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.
This class stores all the data for a single 'side' (in game nomenclature).
game_events::pump_result_t fire_events()
Fires the sighted events that were earlier recorded by fog/shroud clearing.
static lg::log_domain log_engine("engine")
void add_seen_enemy(const unit_map::const_iterator &u)
add the location of new seen enemy
bool on_board_with_border(const map_location &loc) const
void recalculate_minimap()
Schedule the minimap for recalculation.
const terrain_costs & get_vision() const
bool fog_or_shroud() const
Encapsulates the map of the game.
void recalculate_fog(int side)
Function that recalculates the fog of war.
bool is_enemy(int n) const
void invalidate_all()
Function to invalidate all tiles.
game_events::manager * game_events
Encapsulates the map of the game.
bool auto_shroud_updates() const
Various functions related to moving units.
unit_iterator find(std::size_t id)
void drop_events()
Erases the record of sighted events from earlier fog/shroud clearing.
int w() const
Effective map width, in hexes.
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.
bool clear_shroud(const map_location &loc)
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())
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.
Define the game's event mechanism.
A refinement of paths for use when calculating vision.
void write(config &cfg) const
Writes to a config.
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
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.
config & add_child(config_key_type key)
bool is_visible_to_team(const team &team, bool const see_all=true) const
bool clear_shroud(int side, bool reset_fog, bool fire_events)
Function that will clear shroud (and fog) based on current unit positions.
std::unique_ptr< movetype::terrain_costs > costs
costs is always non-null, all of the constructors initialize it
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.
const team * view_team_
Keeps track of the team associated with jamming_.
void add_seen_friend(const unit_map::const_iterator &u)
add a location of a seen friend
const map_location & get_location() const
The current map location this unit is at.
std::map< map_location, int > jamming_
std::set< map_location > edges
The edges are the non-destination hexes bordering the destinations.
bool contains(const map_location &) const
Standard logging facilities (interface).
int current_side() const
Returns the number of the side whose turn it is.
static const map_location & null_location()
Container associating units to locations.
sight_data(std::size_t viewed_id, const map_location &viewed_loc, std::size_t viewer_id, const map_location &viewer_loc)
Class to encapsulate fog/shroud clearing and the resultant sighted events.
bool fogged(const map_location &loc) const
int side() const
The side this unit belongs to.
game_events::wml_event_pump & pump()
std::tuple< bool, bool > pump_result_t
void invalidate_after_clear()
The invalidations that should occur after invoking clear_unit().
A config object defines a single node in a WML file, with access to child nodes.
shroud_clearer()
Default constructor.
std::vector< int > get_sides_not_seeing(const unit &target)
Returns the sides that cannot currently see target.
static const std::string sighted_str("sighted")
This module contains various pathfinding functions and utilities.
std::size_t underlying_id() const
This unit's unique internal ID.
unit_map::iterator find_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)
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.