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())
114 underlying_id(cfg[
"underlying_id"].to_size_t()),
115 sight_range(cfg[
"vision"].to_int()),
116 slowed(cfg.child_or_empty(
"status")[
"slowed"].to_bool()),
117 costs(cfg.child_or_empty(
"vision_costs"))
131 cfg.
add_child(
"status")[
"slowed"] =
true;
163 sighter_id, sighter_loc));
182 ERR_NG <<
sightings_.size() <<
" sighted events were ignored." << std::endl;
230 size_t viewer_id,
bool check_units,
231 size_t &enemy_count,
size_t &friend_count,
238 bool was_fogged = tm.
fogged(loc);
254 if ( loc.
x == 0 && loc.
y == map.
h()-1 ) {
260 else if (
is_odd(map.
w()) && loc.
x == map.
w()-1 && loc.
y == map.
h()-1 ) {
266 else if (
is_even(map.
w()) && loc.
x == map.
w()-1 && loc.
y == 0) {
281 for (
int i = 0;
i != 6; ++
i )
286 if ( result && check_units && loc != event_non_loc ) {
289 if ( sight_it.
valid() ) {
294 if ( tm.
is_enemy(sight_it->side()) ) {
332 size_t viewer_id,
int sight_range,
bool slowed,
335 const std::set<map_location>* known_units,
336 size_t * enemy_count,
size_t * friend_count,
343 bool cleared_something =
false;
345 size_t enemies=0, friends=0;
346 if ( enemy_count ==
nullptr )
347 enemy_count = &enemies;
348 if ( friend_count ==
nullptr )
349 friend_count = &friends;
367 bool known = known_units && known_units->count(dest.
curr) != 0;
368 if (
clear_loc(view_team, dest.
curr, view_loc, real_loc, viewer_id, !known,
369 *enemy_count, *friend_count, spectator) )
370 cleared_something =
true;
374 bool known = known_units && known_units->count(dest) != 0;
375 if (
clear_loc(view_team, dest, view_loc, real_loc, viewer_id, !known,
376 *enemy_count, *friend_count, spectator) )
377 cleared_something =
true;
380 return cleared_something;
403 const unit &viewer,
team &view_team,
404 const std::set<map_location>* known_units,
405 size_t * enemy_count,
size_t * friend_count,
413 known_units, enemy_count, friend_count, spectator, instant);
438 find_it->get_location();
442 real_loc,
nullptr,
nullptr,
nullptr,
nullptr, instant);
463 bool can_delay,
bool invalidate,
bool instant)
465 team & viewing_team = (*resources::teams)[viewer.
side()-1];
474 if ( !
clear_unit(view_loc, viewer, viewing_team, instant) )
497 team & viewing_team = (*resources::teams)[viewer.
side()-1];
499 size_t enemies, friends;
510 bool cleared_something =
clear_loc(viewing_team, dest, dest, real_loc,
511 viewer_id,
true, enemies, friends);
517 for (
int i = 0;
i != 6; ++
i )
518 if (
clear_loc(viewing_team, adjacent[
i], dest, real_loc, viewer_id,
519 true, enemies, friends) )
520 cleared_something =
true;
522 if ( cleared_something )
525 return cleared_something;
556 std::vector<sight_data> sight_list;
564 find_it->get_location();
599 std::vector<int> not_seeing;
601 size_t team_size = teams.size();
602 for (
size_t i = 0;
i != team_size; ++
i)
605 not_seeing.push_back(i+1);
635 const size_t teams_size = teams.size();
639 std::vector<bool> needs_event(teams_size, cache ==
nullptr);
640 if ( cache !=
nullptr ) {
642 for (
int side : *cache)
643 needs_event[side-1] =
true;
646 needs_event[target.
side()-1] =
false;
648 for (
size_t i = 0;
i != teams_size; ++
i )
652 std::vector< std::map<map_location, int> > jamming_cache(teams_size);
653 for (
size_t i = 0; i != teams_size; ++
i )
654 if ( needs_event[i] )
658 std::vector<const unit *> second_units(teams_size,
nullptr);
659 std::vector<size_t> distances(teams_size, UINT_MAX);
661 const size_t index = viewer.side() - 1;
663 if ( needs_event[index] && distances[index] != 0 ) {
664 if (
can_see(viewer, target_loc, &jamming_cache[index]) ) {
666 second_units[
index] = &viewer;
667 distances[
index] = 0;
671 size_t viewer_distance =
673 if ( viewer_distance < distances[index] ) {
674 second_units[
index] = &viewer;
675 distances[
index] = viewer_distance;
683 for (
size_t i = 0; i != teams_size; ++
i )
684 if ( second_units[i] !=
nullptr ) {
707 team &tm = (*resources::teams)[side - 1];
713 std::set<map_location> visible_locs;
717 if ( !tm.
fogged(u_location) )
718 visible_locs.insert(u_location);
727 for (
const unit &u : *resources::units)
729 if ( u.side() == side )
730 clearer.
clear_unit(u.get_location(), u, tm, &visible_locs);
756 team &tm = (*resources::teams)[side - 1];
765 if ( u.side() == side )
766 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
bool on_board_with_border(const map_location &loc) const
void recalculate_shroud()
Stores a set of terrain costs (for movement, vision, or "jamming").
bool is_visible_to_team(team const &team, gamemap const &map, bool const see_all=true) const
const map_location & get_location() const
std::vector< sight_data > sightings_
void invalidate_game_status()
Function to invalidate the game status displayed on the sidebar.
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
bool get_state(const std::string &state) const
size_t underlying_id() const
The unique internal ID of the unit.
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.
A record of a sighting event.
Various functions implementing vision (through fog of war and shroud).
bool clear_fog(const map_location &loc)
void write(config &cfg, const std::string &child_name="", bool merged=true) const
Writes our data to a config.
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
bool is_enemy(int n) const
A refinement of paths for use when calculating jamming.
bool actor_sighted(const unit &target, const std::vector< int > *cache)
Fires sighted events for the sides that can see target.
~shroud_clearer()
Destructor.
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.
clearer_info(const unit &viewer)
Constructor from a unit.
virtual void draw()
Draws invalidated items.
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_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.
static std::vector< team > *& teams
bool contains(const map_location &) const
This class stores all the data for a single 'side' (in game nomenclature).
bool fog_or_shroud() const
static lg::log_domain log_engine("engine")
bool auto_shroud_updates() const
int current_side() const
Returns the number of the side whose turn it is.
std::vector< team > * teams
void add_seen_enemy(const unit_map::const_iterator &u)
add the location of new seen enemy
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 recalculate_minimap()
Schedule the minimap for recalculation.
sight_data(size_t viewed_id, const map_location &viewed_loc, size_t viewer_id, const map_location &viewer_loc)
int w() const
Effective map width.
terrain_costs & get_vision()
Encapsulates the map of the game.
void recalculate_fog(int side)
Function that recalculates the fog of war.
config & add_child(const std::string &key)
static const map_location & null_location()
void invalidate_all()
Function to invalidate all tiles.
game_events::manager * game_events
Encapsulates the map of the game.
Various functions related to moving units.
void drop_events()
Erases the record of sighted events from earlier fog/shroud clearing.
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)
int h() const
Effective map height.
Define the game's event mechanism.
bool fogged(const map_location &loc) const
A refinement of paths for use when calculating vision.
void raise(const std::string &event, const entity_location &loc1=entity_location::null_entity, const entity_location &loc2=entity_location::null_entity, const config &data=config())
game_events::t_pump & pump()
virtual const gamemap & map() const
bool clear_shroud(int side, bool reset_fog, bool fire_events)
Function that will clear shroud (and fog) based on current unit positions.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
bool fire_events()
Fires the sighted events that were earlier recorded by fog/shroud clearing.
const team * view_team_
Keeps track of the team associated with jamming_.
void write(config &cfg) const
Writes to a config.
void add_seen_friend(const unit_map::const_iterator &u)
add a location of a seen friend
const movetype & movement_type() const
std::map< map_location, int > jamming_
std::set< map_location > edges
The edges are the non-destination hexes bordering the destinations.
Standard logging facilities (interface).
Container associating units to locations.
Class to encapsulate fog/shroud clearing and the resultant sighted events.
unit_iterator find(size_t id)
movetype::terrain_costs costs
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.
GLsizei const GLcharARB ** string
unit_map::iterator find_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)