本文整理汇总了C++中unit::side方法的典型用法代码示例。如果您正苦于以下问题:C++ unit::side方法的具体用法?C++ unit::side怎么用?C++ unit::side使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unit
的用法示例。
在下文中一共展示了unit::side方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: destinations
pathfind::paths::paths(gamemap const &map, unit_map const &units,
const unit& u, std::vector<team> const &teams,
bool force_ignore_zoc, bool allow_teleport, const team &viewing_team,
int additional_turns, bool see_all, bool ignore_units)
: destinations()
{
if (u.side() < 1 || u.side() > int(teams.size())) {
return;
}
find_routes(map, units, u,
u.movement_left(), destinations, teams, force_ignore_zoc,
allow_teleport,additional_turns,viewing_team,
see_all, ignore_units);
}
示例2: rate_terrain
int aspect_attacks::rate_terrain(const unit& u, const map_location& loc)
{
gamemap &map_ = *resources::game_map;
const t_translation::t_terrain terrain = map_.get_terrain(loc);
const int defense = u.defense_modifier(terrain);
int rating = 100 - defense;
const int healing_value = 10;
const int friendly_village_value = 5;
const int neutral_village_value = 10;
const int enemy_village_value = 15;
if(map_.gives_healing(terrain) && u.get_ability_bool("regenerate",loc) == false) {
rating += healing_value;
}
if(map_.is_village(terrain)) {
int owner = village_owner(loc, *resources::teams) + 1;
if(owner == u.side()) {
rating += friendly_village_value;
} else if(owner == 0) {
rating += neutral_village_value;
} else {
rating += enemy_village_value;
}
}
return rating;
}
示例3: 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;
}
示例4:
ttactic2::ttactic2(game_display& gui, std::vector<team>& teams, unit_map& units, hero_map& heros, unit& tactician, int operate)
: gui_(gui)
, teams_(teams)
, units_(units)
, heros_(heros)
, tactician_(tactician)
, operate_(operate)
, candidate_()
, valid_()
, cannot_valid_(false)
, selected_(-1)
{
if (tactician_.master().tactic_ != HEROS_NO_TACTIC) {
candidate_.push_back(&tactician_.master());
}
if (tactician_.second().valid() && tactician_.second().tactic_ != HEROS_NO_TACTIC) {
candidate_.push_back(&tactician_.second());
}
if (tactician_.third().valid() && tactician_.third().tactic_ != HEROS_NO_TACTIC) {
candidate_.push_back(&tactician_.third());
}
if (operate_ == ACTIVE) {
std::vector<unit*> actives = teams_[tactician.side() - 1].active_tactics();
if ((int)actives.size() >= game_config::active_tactic_slots ||
std::find(actives.begin(), actives.end(), &tactician) != actives.end()) {
cannot_valid_ = true;
}
}
}
示例5:
pathfind::teleport_map::teleport_map(
const std::vector<teleport_group>& groups
, const unit& u
, const team &viewing_team
, const bool see_all
, const bool ignore_units)
: teleport_map_()
, sources_()
, targets_()
{
foreach(const teleport_group& group, groups) {
teleport_pair locations;
group.get_teleport_pair(locations, u, ignore_units);
if (!see_all && !group.always_visible() && viewing_team.is_enemy(u.side())) {
teleport_pair filter_locs;
foreach(const map_location &loc, locations.first)
if(!viewing_team.fogged(loc))
filter_locs.first.insert(loc);
foreach(const map_location &loc, locations.second)
if(!viewing_team.fogged(loc))
filter_locs.second.insert(loc);
locations.first.swap(filter_locs.first);
locations.second.swap(filter_locs.second);
}
示例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: path_cost
int path_cost(std::vector<map_location> const& path, unit const& u)
{
if(path.size() < 2)
return 0;
map_location const& dest = path.back();
if((resources::game_map->is_village(dest) && !resources::teams->at(u.side()-1).owns_village(dest))
|| pathfind::enemy_zoc(*resources::teams,dest,resources::teams->at(u.side()-1),u.side()))
return u.total_movement();
int result = 0;
gamemap const& map = *resources::game_map;
BOOST_FOREACH(map_location const& loc, std::make_pair(path.begin()+1,path.end()))
result += u.movement_cost(map[loc]);
return result;
}
示例8: post_create
void unit_creator::post_create(const map_location &loc, const unit &new_unit, bool anim)
{
if (discover_) {
preferences::encountered_units().insert(new_unit.type_id());
}
bool show = show_ && (resources::screen !=nullptr) && !resources::screen->fogged(loc);
bool animate = show && anim;
if (get_village_) {
assert(resources::gameboard);
if (board_->map().is_village(loc)) {
actions::get_village(loc, new_unit.side());
}
}
// Only fire the events if it's safe; it's not if we're in the middle of play_controller::reset_gamestate()
if (resources::lua_kernel != nullptr) {
resources::game_events->pump().fire("unit_placed", loc);
}
if (resources::screen!=nullptr) {
if (invalidate_ ) {
resources::screen->invalidate(loc);
}
if (animate) {
unit_display::unit_recruited(loc);
} else if (show) {
resources::screen->draw();
}
}
}
示例9: calc
std::vector<map_location> fake_unit_path(const unit& fake_unit, const std::vector<std::string>& xvals, const std::vector<std::string>& yvals)
{
const gamemap *game_map = & resources::gameboard->map();
std::vector<map_location> path;
map_location src;
map_location dst;
for(size_t i = 0; i != std::min(xvals.size(),yvals.size()); ++i) {
if(i==0){
src.x = atoi(xvals[i].c_str())-1;
src.y = atoi(yvals[i].c_str())-1;
if (!game_map->on_board(src)) {
ERR_CF << "invalid move_unit_fake source: " << src << '\n';
break;
}
path.push_back(src);
continue;
}
pathfind::shortest_path_calculator calc(fake_unit,
(*resources::teams)[fake_unit.side()-1],
*resources::teams,
*game_map);
dst.x = atoi(xvals[i].c_str())-1;
dst.y = atoi(yvals[i].c_str())-1;
if (!game_map->on_board(dst)) {
ERR_CF << "invalid move_unit_fake destination: " << dst << '\n';
break;
}
pathfind::plain_route route = pathfind::a_star_search(src, dst, 10000, &calc,
game_map->w(), game_map->h());
if (route.steps.empty()) {
WRN_NG << "Could not find move_unit_fake route from " << src << " to " << dst << ": ignoring complexities" << std::endl;
pathfind::emergency_path_calculator calc(fake_unit, *game_map);
route = pathfind::a_star_search(src, dst, 10000, &calc,
game_map->w(), game_map->h());
if(route.steps.empty()) {
// This would occur when trying to do a MUF of a unit
// over locations which are unreachable to it (infinite movement
// costs). This really cannot fail.
WRN_NG << "Could not find move_unit_fake route from " << src << " to " << dst << ": ignoring terrain" << std::endl;
pathfind::dummy_path_calculator calc(fake_unit, *game_map);
route = a_star_search(src, dst, 10000, &calc, game_map->w(), game_map->h());
assert(!route.steps.empty());
}
}
// we add this section to the end of the complete path
// skipping section's head because already included
// by the previous iteration
path.insert(path.end(),
route.steps.begin()+1, route.steps.end());
src = dst;
}
return path;
}
示例10: 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);
}
示例11: clear_unit
/**
* Clears shroud (and fog) around the provided location as if @a viewer
* was standing there.
* This version of shroud_clearer::clear_unit() will abort if the viewer's
* team uses neither fog nor shroud. If @a can_delay is left as true, then
* this function also aborts on the viewing team's turn if delayed shroud
* updates is on. (Not supplying a team suggests that it would be inconvenient
* for the caller to check these.)
* In addition, if @a invalidate is left as true, invalidate_after_clear()
* will be called.
* Setting @a instant to false allows some drawing delays that are used to
* make movement look better.
*
* @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,
bool can_delay, bool invalidate, bool instant)
{
team & viewing_team = resources::gameboard->get_team(viewer.side());
// Abort if there is nothing to clear.
if ( !viewing_team.fog_or_shroud() )
return false;
if ( can_delay && !viewing_team.auto_shroud_updates() &&
viewer.side() == resources::controller->current_side() )
return false;
if ( !clear_unit(view_loc, viewer, viewing_team, instant) )
// Nothing uncovered.
return false;
if ( invalidate )
invalidate_after_clear();
return true;
}
示例12: 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;
}
示例13:
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;
}
示例14: 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;
}
示例15:
static std::string get_image_mods(const unit& u)
{
std::string res
= "~RC(" + u.team_color() + ">" + team::get_side_color_index(u.side()) + ")";
if (u.can_recruit()) {
res += "~BLIT(" + unit::leader_crown() + ")";
}
BOOST_FOREACH(const std::string& overlay, u.overlays()) {
res += "~BLIT(" + overlay + ")";
}
return res;
}