本文整理汇总了C++中unit::get_location方法的典型用法代码示例。如果您正苦于以下问题:C++ unit::get_location方法的具体用法?C++ unit::get_location怎么用?C++ unit::get_location使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unit
的用法示例。
在下文中一共展示了unit::get_location方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: teleport_unit_between
static void teleport_unit_between( const map_location& a, const map_location& b, unit& temp_unit)
{
game_display* disp = game_display::get_singleton();
if(!disp || disp->video().update_locked() || disp->video().faked() || (disp->fogged(a) && disp->fogged(b))) {
return;
}
disp->scroll_to_tiles(a,b,game_display::ONSCREEN,true,0.0,false);
temp_unit.set_location(a);
if (!disp->fogged(a)) { // teleport
disp->invalidate(temp_unit.get_location());
temp_unit.set_facing(a.get_relative_dir(b));
unit_animator animator;
animator.add_animation(&temp_unit,"pre_teleport",a);
animator.start_animations();
animator.wait_for_end();
}
temp_unit.set_location(b);
if (!disp->fogged(b)) { // teleport
disp->invalidate(temp_unit.get_location());
temp_unit.set_facing(a.get_relative_dir(b));
disp->scroll_to_tiles(b,a,game_display::ONSCREEN,true,0.0,false);
unit_animator animator;
animator.add_animation(&temp_unit,"post_teleport",b);
animator.start_animations();
animator.wait_for_end();
}
temp_unit.set_standing();
disp->update_display();
events::pump();
}
示例2: find_backup_leader
unit_const_ptr find_backup_leader(const unit & leader)
{
assert(leader.can_recruit());
assert(resources::gameboard->map().is_keep(leader.get_location()));
for (unit_map::const_iterator unit = resources::units->begin(); unit != resources::units->end(); unit++)
{
if (unit->can_recruit() && unit->id() != leader.id())
{
if ( dynamic_cast<game_state*>(resources::filter_con)->can_recruit_on(*unit, leader.get_location()) )
return unit.get_shared_ptr();
}
}
return unit_const_ptr();
}
示例3: test_suitable_recruit_location
bool recruit_result::test_suitable_recruit_location(const gamemap &map, const unit_map &units, const unit &my_leader, bool)
{
recruit_location_ = where_;
//if we have not-on-board location, such as null_location, then the caller wants us to recruit on 'any' possible tile.
if (!map.on_board(recruit_location_)) {
recruit_location_ = pathfind::find_vacant_tile(map, units, my_leader.get_location(), pathfind::VACANT_CASTLE);
}
if (!can_recruit_on(map, my_leader.get_location(), recruit_location_)) {
set_error(E_BAD_RECRUIT_LOCATION);
return false;
}
return true;
}
示例4: test_route
bool move_result::test_route(const unit &un, const team &my_team, const unit_map &units, const std::vector<team> &teams, const gamemap &map, bool)
{
if (from_== to_) {
if (!remove_movement_ || (un.movement_left() == 0) ) {
set_error(E_EMPTY_MOVE);
return false;
}
return true;
}
if (un.movement_left() == 0 ) {
set_error(E_EMPTY_MOVE);
return false;
}
if (!to_.valid()) {
set_error(E_NO_ROUTE);
return false;
}
const pathfind::shortest_path_calculator calc(un, my_team, units, teams,map);
//allowed teleports
std::set<map_location> allowed_teleports = pathfind::get_teleport_locations(un, units, my_team, true);//@todo 1.9: see_all -> false
//do an A*-search
route_ = pathfind::a_star_search(un.get_location(), to_, 10000.0, &calc, map.w(), map.h(), &allowed_teleports);
if (route_.steps.empty()) {
set_error(E_NO_ROUTE);
return false;
}
return true;
}
示例5: clear_dest
/**
* Clears shroud (and fog) at the provided location and its immediate neighbors.
* This is an aid for the [teleport] action, allowing the destination to be
* cleared before teleporting, while the unit's full visual range gets cleared
* after.
* The @a viewer is needed for correct firing of sighted events.
*
* @return whether or not information was uncovered (i.e. returns true if the
* locations in question were fogged/shrouded under shared vision/maps).
*/
bool shroud_clearer::clear_dest(const map_location &dest, const unit &viewer)
{
team & viewing_team = resources::gameboard->get_team(viewer.side());
// A pair of dummy variables needed to simplify some logic.
std::size_t enemies, friends;
// Abort if there is nothing to clear.
if ( !viewing_team.fog_or_shroud() )
return false;
// Cache some values.
const map_location & real_loc = viewer.get_location();
const std::size_t viewer_id = viewer.underlying_id();
// Clear the destination.
bool cleared_something = clear_loc(viewing_team, dest, dest, real_loc,
viewer_id, true, enemies, friends);
// Clear the adjacent hexes (will be seen even if vision is 0, and the
// graphics do not work so well for an isolated cleared hex).
adjacent_loc_array_t adjacent;
get_adjacent_tiles(dest, adjacent.data());
for (unsigned i = 0; i < adjacent.size(); ++i )
if ( clear_loc(viewing_team, adjacent[i], dest, real_loc, viewer_id,
true, enemies, friends) )
cleared_something = true;
if ( cleared_something )
invalidate_after_clear();
return cleared_something;
}
示例6: unit_can_move
bool display_context::unit_can_move(const unit &u) const
{
if(!u.attacks_left() && u.movement_left()==0)
return false;
// Units with goto commands that have already done their gotos this turn
// (i.e. don't have full movement left) should have red globes.
if(u.has_moved() && u.has_goto()) {
return false;
}
const team ¤t_team = get_team(u.side());
map_location locs[6];
get_adjacent_tiles(u.get_location(), locs);
for(int n = 0; n != 6; ++n) {
if (map().on_board(locs[n])) {
const unit_map::const_iterator i = units().find(locs[n]);
if (i.valid() && !i->incapacitated() &&
current_team.is_enemy(i->side())) {
return true;
}
if (u.movement_cost(map()[locs[n]]) <= u.movement_left()) {
return true;
}
}
}
return false;
}
示例7: filter
void pathfind::teleport_group::get_teleport_pair(
teleport_pair& loc_pair
, const unit& u
, const bool ignore_units) const
{
const map_location &loc = u.get_location();
static unit_map empty_unit_map;
unit_map *units;
if (ignore_units) {
units = &empty_unit_map;
} else {
units = resources::units;
}
vconfig filter(cfg_.child_or_empty("filter"), true);
vconfig source(cfg_.child_or_empty("source"), true);
vconfig target(cfg_.child_or_empty("target"), true);
if (u.matches_filter(filter, loc)) {
scoped_xy_unit teleport_unit("teleport_unit", loc.x, loc.y, *resources::units);
terrain_filter source_filter(source, *units);
source_filter.get_locations(reversed_ ? loc_pair.second : loc_pair.first);
terrain_filter target_filter(target, *units);
target_filter.get_locations(reversed_ ? loc_pair.first : loc_pair.second);
}
}
示例8: get_teleport_pair
void teleport_group::get_teleport_pair(
teleport_pair& loc_pair
, const unit& u
, const bool ignore_units) const
{
const map_location &loc = u.get_location();
const filter_context * fc = resources::filter_con;
assert(fc);
if (ignore_units) {
fc = new ignore_units_filter_context(*resources::filter_con);
}
vconfig filter(cfg_.child_or_empty("filter"), true);
vconfig source(cfg_.child_or_empty("source"), true);
vconfig target(cfg_.child_or_empty("target"), true);
const unit_filter ufilt(filter, resources::filter_con); //Note: Don't use the ignore units filter context here, only for the terrain filters. (That's how it worked before the filter contexts were introduced)
if (ufilt.matches(u, loc)) {
scoped_xy_unit teleport_unit("teleport_unit", loc.x, loc.y, *resources::units);
terrain_filter source_filter(source, fc);
source_filter.get_locations(reversed_ ? loc_pair.second : loc_pair.first);
terrain_filter target_filter(target, fc);
target_filter.get_locations(reversed_ ? loc_pair.first : loc_pair.second);
}
if (ignore_units) {
delete fc;
}
}
示例9: test_leader_on_keep
bool recruit_result::test_leader_on_keep(const gamemap &map, const unit &my_leader, bool)
{
if (!map.is_keep(my_leader.get_location())) {
set_error(E_LEADER_NOT_ON_KEEP);
return false;
}
return true;
}
示例10: clear_unit
/**
* Clears shroud (and fog) around the provided location for @a view_team
* as if @a viewer was standing there.
* This will also record sighted events, which should be either fired or
* explicitly dropped.
*
* 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 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,
const unit &viewer, team &view_team,
const std::set<map_location>* known_units,
std::size_t * enemy_count, std::size_t * friend_count,
move_unit_spectator * spectator, bool instant)
{
// This is just a translation to the more general interface. It is
// not inlined so that vision.hpp does not have to include unit.hpp.
return clear_unit(view_loc, view_team, viewer.underlying_id(),
viewer.vision(), viewer.get_state(unit::STATE_SLOWED),
viewer.movement_type().get_vision(), viewer.get_location(),
known_units, enemy_count, friend_count, spectator, instant);
}
示例11: can_see
/**
* Determines if @a loc is within @a viewer's visual range.
* This is a moderately expensive function (vision is recalculated
* with each call), so avoid using it heavily.
* If @a jamming is left as nullptr, the jamming map is also calculated
* with each invocation.
*/
static bool can_see(const unit & viewer, const map_location & loc,
const std::map<map_location, int> * jamming = nullptr)
{
// Make sure we have a "jamming" map.
std::map<map_location, int> local_jamming;
if ( jamming == nullptr ) {
create_jamming_map(local_jamming, resources::gameboard->get_team(viewer.side()));
jamming = &local_jamming;
}
// Determine which hexes this unit can see.
pathfind::vision_path sight(viewer, viewer.get_location(), *jamming);
return sight.destinations.contains(loc) || sight.edges.count(loc) != 0;
}
示例12: move_unit_between
static void move_unit_between(const map_location& a, const map_location& b, unit& temp_unit,unsigned int step_num,unsigned int step_left)
{
game_display* disp = game_display::get_singleton();
if(!disp || disp->video().update_locked() || disp->video().faked() || (disp->fogged(a) && disp->fogged(b))) {
return;
}
temp_unit.set_location(a);
disp->invalidate(temp_unit.get_location());
temp_unit.set_facing(a.get_relative_dir(b));
unit_animator animator;
animator.replace_anim_if_invalid(&temp_unit,"movement",a,b,step_num,
false,"",0,unit_animation::INVALID,NULL,NULL,step_left);
animator.start_animations();
animator.pause_animation();
disp->scroll_to_tiles(a,b,game_display::ONSCREEN,true,0.0,false);
animator.restart_animation();
// useless now, previous short draw() just did one
// new_animation_frame();
int target_time = animator.get_animation_time_potential();
// target_time must be short to avoid jumpy move
// std::cout << "target time: " << target_time << "\n";
// we round it to the next multile of 200
target_time += 200;
target_time -= target_time%200;
// This code causes backwards teleport because the time > 200 causes offset > 1.0
// which will not match with the following -1.0
// if( target_time - animator.get_animation_time_potential() < 100 ) target_time +=200;
animator.wait_until(target_time);
// debug code, see unit_frame::redraw()
// std::cout << " end\n";
map_location arr[6];
get_adjacent_tiles(a, arr);
unsigned int i;
for (i = 0; i < 6; ++i) {
disp->invalidate(arr[i]);
}
get_adjacent_tiles(b, arr);
for (i = 0; i < 6; ++i) {
disp->invalidate(arr[i]);
}
}
示例13: destinations
/**
* Construct a list of paths for the specified unit.
*
* This function is used for several purposes, including showing a unit's
* potential moves and generating currently possible paths.
* @param u The unit whose moves and movement type will be used.
* @param force_ignore_zoc Set to true to completely ignore zones of control.
* @param allow_teleport Set to true to consider teleportation abilities.
* @param viewing_team Usually the current team, except for "show enemy moves", etc.
* @param additional_turns The number of turns to account for, in addition to the current.
* @param see_all Set to true to remove unit visibility from consideration.
* @param ignore_units Set to true if units should never obstruct paths (implies ignoring ZoC as well).
*/
paths::paths(const unit& u, bool force_ignore_zoc,
bool allow_teleport, const team &viewing_team,
int additional_turns, bool see_all, bool ignore_units)
: destinations()
{
std::vector<team> const &teams = *resources::teams;
if (u.side() < 1 || u.side() > int(teams.size())) {
return;
}
find_routes(u.get_location(), u.movement_type().get_movement(),
u.get_state(unit::STATE_SLOWED), u.movement_left(),
u.total_movement(), additional_turns, destinations, NULL,
allow_teleport ? &u : NULL,
ignore_units ? NULL : &teams[u.side()-1],
force_ignore_zoc ? NULL : &u,
see_all ? NULL : &viewing_team);
}
示例14: add_unit_entry
static stuff_list_adder add_unit_entry(stuff_list_adder& progress, const unit& u, const display_context& dc)
{
Uint32 team_color = game_config::tc_info(dc.get_team(u.side()).color())[0];
std::stringstream s;
s << '(' << u.get_location() << ')';
progress.widget("loc", s.str());
s.str("");
s << "<span color='#" << std::hex << team_color << std::dec;
s << "'>side=" << u.side() << "</span>";
progress.widget("side", s.str(), true);
if(u.can_recruit()) {
progress.widget("leader", "<span color='yellow'>LEADER</span> ", true);
}
s.str("");
s << "id=\"" << u.id() << '"';
progress.widget("id", s.str());
progress.widget("type", u.type_id());
s.str("");
s << "L" << u.level();
progress.widget("level", s.str());
s.str("");
s << u.experience() << '/' << u.max_experience() << " xp";
progress.widget("xp", s.str());
s.str("");
s << u.hitpoints() << '/' << u.max_hitpoints() << " hp";
progress.widget("hp", s.str());
progress.widget("traits", utils::join(u.get_traits_list(), ", "));
return progress;
}
示例15:
std::set<map_location> get_teleport_locations(const unit &u,
const unit_map &units, const team &viewing_team,
bool see_all, bool ignore_units)
{
std::set<map_location> res;
if (!u.get_ability_bool("teleport")) return res;
const team ¤t_team = (*resources::teams)[u.side() - 1];
const map_location &loc = u.get_location();
foreach (const map_location &l, current_team.villages())
{
// This must be a vacant village (or occupied by the unit)
// to be able to teleport.
if (!see_all && viewing_team.is_enemy(u.side()) && viewing_team.fogged(l))
continue;
if (!ignore_units && l != loc &&
get_visible_unit(units, l, viewing_team, see_all))
continue;
res.insert(l);
}
return res;
}