37 #include <boost/dynamic_bitset.hpp>
42 #define DBG_NG LOG_STREAM(debug, log_engine)
43 #define ERR_NG LOG_STREAM(err, log_engine)
50 const team & view_team)
58 if ( u.jamming() < 1 || !view_team.
is_enemy(u.side()) )
78 const std::map<map_location, int> * jamming =
nullptr)
81 std::map<map_location, int> local_jamming;
82 if ( jamming ==
nullptr ) {
84 jamming = &local_jamming;
101 underlying_id(viewer.underlying_id()),
102 sight_range(viewer.vision()),
104 costs(viewer.movement_type().get_vision().make_standalone())
112 underlying_id(cfg[
"underlying_id"].to_size_t()),
113 sight_range(cfg[
"vision"].to_int()),
114 slowed(cfg.child_or_empty(
"status")[
"slowed"].to_bool()),
115 costs(
movetype::read_terrain_costs(cfg.child_or_empty(
"vision_costs")))
129 cfg.
add_child(
"status")[
"slowed"] =
true;
130 costs->write(cfg,
"vision_costs");
141 std::size_t viewer_id,
const map_location & viewer_loc) :
158 std::size_t sighter_id,
const map_location & sighter_loc)
227 std::size_t viewer_id,
bool check_units,
228 std::size_t &enemy_count, std::size_t &friend_count,
235 bool was_fogged = tm.
fogged(loc);
236 bool result = was_fogged && map.
on_board(loc);
251 if ( loc.
x == 0 && loc.
y == map.
h()-1 ) {
257 else if (
is_odd(map.
w()) && loc.
x == map.
w()-1 && loc.
y == map.
h()-1 ) {
263 else if (
is_even(map.
w()) && loc.
x == map.
w()-1 && loc.
y == 0) {
281 if ( result && check_units && loc != event_non_loc ) {
284 if ( sight_it.
valid() ) {
289 if ( tm.
is_enemy(sight_it->side()) ) {
333 std::size_t viewer_id,
int sight_range,
bool slowed,
336 const std::set<map_location>* known_units,
337 std::size_t * enemy_count, std::size_t * friend_count,
340 bool cleared_something =
false;
342 std::size_t enemies=0, friends=0;
343 if ( enemy_count ==
nullptr )
344 enemy_count = &enemies;
345 if ( friend_count ==
nullptr )
346 friend_count = &friends;
358 bool known = known_units && known_units->count(dest.
curr) != 0;
359 if (
clear_loc(view_team, dest.
curr, view_loc, real_loc, viewer_id, !known,
360 *enemy_count, *friend_count, spectator) )
361 cleared_something =
true;
365 bool known = known_units && known_units->count(dest) != 0;
366 if (
clear_loc(view_team, dest, view_loc, real_loc, viewer_id, !known,
367 *enemy_count, *friend_count, spectator) )
368 cleared_something =
true;
371 return cleared_something;
397 const unit &viewer,
team &view_team,
398 const std::set<map_location>* known_units,
399 std::size_t * enemy_count, std::size_t * friend_count,
407 known_units, enemy_count, friend_count, spectator, instant);
435 find_it->get_location();
439 real_loc,
nullptr,
nullptr,
nullptr,
nullptr, instant);
460 bool can_delay,
bool invalidate,
bool instant)
471 if ( !
clear_unit(view_loc, viewer, viewing_team, instant) )
496 std::size_t enemies, friends;
507 bool cleared_something =
clear_loc(viewing_team, dest, dest, real_loc,
508 viewer_id,
true, enemies, friends);
513 if(
clear_loc(viewing_team, adj, dest, real_loc, viewer_id,
true, enemies, friends)) {
514 cleared_something =
true;
518 if ( cleared_something )
521 return cleared_something;
552 std::vector<sight_data> sight_list;
560 find_it->get_location();
595 std::vector<int> not_seeing;
597 std::size_t team_size = teams.size();
598 for ( std::size_t
i = 0;
i != team_size; ++
i)
601 not_seeing.push_back(
i+1);
631 const std::size_t teams_size = teams.size();
635 boost::dynamic_bitset<> needs_event;
636 needs_event.resize(teams_size, cache ==
nullptr);
637 if ( cache !=
nullptr ) {
639 for (
int side : *cache)
640 needs_event[side-1] =
true;
643 needs_event[target.
side()-1] =
false;
645 for ( std::size_t
i = 0;
i != teams_size; ++
i )
649 std::vector< std::map<map_location, int>> jamming_cache(teams_size);
650 for ( std::size_t
i = 0;
i != teams_size; ++
i )
651 if ( needs_event[
i] )
655 std::vector<const unit *> second_units(teams_size,
nullptr);
656 std::vector<std::size_t> distances(teams_size, UINT_MAX);
658 const std::size_t
index = viewer.side() - 1;
660 if ( needs_event[
index] && distances[
index] != 0 ) {
661 if (
can_see(viewer, target_loc, &jamming_cache[
index]) ) {
663 second_units[
index] = &viewer;
664 distances[
index] = 0;
668 std::size_t viewer_distance =
670 if ( viewer_distance < distances[
index] ) {
671 second_units[
index] = &viewer;
672 distances[
index] = viewer_distance;
680 for ( std::size_t
i = 0;
i != teams_size; ++
i )
681 if ( second_units[
i] !=
nullptr ) {
710 std::set<map_location> visible_locs;
714 if ( !tm.
fogged(u_location) )
715 visible_locs.insert(u_location);
726 if ( u.side() == side )
727 clearer.
clear_unit(u.get_location(), u, tm, &visible_locs);
762 if ( u.side() == side )
763 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(config_key_type 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.
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.
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
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.
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(const std::string &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).