Exemple #1
0
/**
 * Clears shroud (and fog) around the provided location for @a view_team
 * based on @a sight_range, @a costs, and @a slowed.
 * This will also record sighted events, which should be either fired or
 * explicitly dropped. (The sighter is the unit with underlying id @a 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.
 *
 * @param real_loc         The actual location of the viewing unit.
 *                         (This is used to avoid having a unit sight itself.)
 * @param known_units      These locations are not checked for uncovered units.
 * @param enemy_count      Incremented for each enemy uncovered (excluding known_units).
 * @param friend_count     Incremented for each friend uncovered (excluding known_units).
 * @param spectator        Will be told of uncovered units (excluding known_units).
 * @param instant          If false, then drawing delays (used to make movement look better) are allowed.
 *
 * @return whether or not information was uncovered (i.e. returns true if any
 *         locations in visual range were fogged/shrouded under shared vision/maps).
 */
bool shroud_clearer::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,
                                std::size_t * enemy_count, std::size_t * friend_count,
                                move_unit_spectator * spectator, bool instant)
{
	// Give animations a chance to progress; see bug #20324.
	if ( !instant  && display::get_singleton() )
		display::get_singleton()->draw(true);

	bool cleared_something = false;
	// Dummy variables to make some logic simpler.
	std::size_t enemies=0, friends=0;
	if ( enemy_count == nullptr )
		enemy_count = &enemies;
	if ( friend_count == nullptr )
		friend_count = &friends;

	// Make sure the jamming map is up-to-date.
	if ( view_team_ != &view_team ) {
		calculate_jamming(&view_team);
		// Give animations a chance to progress; see bug #20324.
		if ( !instant  && display::get_singleton() )
			display::get_singleton()->draw(true);
	}

	// Determine the hexes to clear.
	pathfind::vision_path sight(costs, slowed, sight_range, view_loc, jamming_);
	// Give animations a chance to progress; see bug #20324.
	if ( !instant  && display::get_singleton() )
		display::get_singleton()->draw(true);

	// Clear the fog.
	for (const pathfind::paths::step &dest : sight.destinations) {
		bool known = known_units  &&  known_units->count(dest.curr) != 0;
		if ( clear_loc(view_team, dest.curr, view_loc, real_loc, viewer_id, !known,
		               *enemy_count, *friend_count, spectator) )
			cleared_something = true;
	}
	//TODO guard with game_config option
	for (const map_location &dest : sight.edges) {
		bool known = known_units  &&  known_units->count(dest) != 0;
		if ( clear_loc(view_team, dest, view_loc, real_loc, viewer_id, !known,
		               *enemy_count, *friend_count, spectator) )
			cleared_something = true;
	}

	return cleared_something;
}
Exemple #2
0
	/// 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.
	/// @param[in] new_team  The team whose vision will be used. If left as
	///                      NULL, the cache will be just be cleared (to be
	///                      recalculated later as needed).
	void cache_units(const team * new_team=NULL) { calculate_jamming(new_team); }
Exemple #3
0
	/// 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.
	/// @param[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).
	void cache_units(const team * new_team=nullptr) { calculate_jamming(new_team); }