本文整理汇总了C++中unit_map::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ unit_map::insert方法的具体用法?C++ unit_map::insert怎么用?C++ unit_map::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unit_map
的用法示例。
在下文中一共展示了unit_map::insert方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: apply_temp_modifier
void recall::apply_temp_modifier(unit_map& unit_map)
{
assert(valid_);
temp_unit_->set_location(recall_hex_);
DBG_WB << "Inserting future recall " << temp_unit_->name() << " [" << temp_unit_->id()
<< "] at position " << temp_unit_->get_location() << ".\n";
//temporarily remove unit from recall list
std::vector<unit>& recalls = resources::teams->at(team_index()).recall_list();
std::vector<unit>::iterator it = std::find_if(recalls.begin(), recalls.end(),
unit_comparator_predicate(*temp_unit_));
assert(it != recalls.end());
recalls.erase(it);
// Temporarily insert unit into unit_map
unit_map.insert(temp_unit_);
//unit map takes ownership of temp_unit
temp_unit_ = NULL;
//Add cost to money spent on recruits.
temp_cost_ = resources::teams->at(team_index()).recall_cost();
resources::teams->at(team_index()).get_side_actions()->change_gold_spent_by(temp_cost_);
// Update gold in top bar
resources::screen->invalidate_game_status();
}
示例2: apply_temp_modifier
void recall::apply_temp_modifier(unit_map& unit_map)
{
assert(valid());
temp_unit_->set_location(recall_hex_);
DBG_WB << "Inserting future recall " << temp_unit_->name() << " [" << temp_unit_->id()
<< "] at position " << temp_unit_->get_location() << ".\n";
//temporarily remove unit from recall list
UnitPtr it = resources::teams->at(team_index()).recall_list().extract_if_matches_id(temp_unit_->id());
assert(it);
//Add cost to money spent on recruits.
int cost = resources::teams->at(team_index()).recall_cost();
if (it->recall_cost() > -1) {
cost = it->recall_cost();
}
// Temporarily insert unit into unit_map
//unit map takes ownership of temp_unit
unit_map.insert(temp_unit_);
resources::teams->at(team_index()).get_side_actions()->change_gold_spent_by(cost);
// Update gold in top bar
resources::screen->invalidate_game_status();
}
示例3: install_
bool install_(const std::string& key, const T& value)
{
std::string fpath;
if(!create_full_path(key, fpath)) {
return false;
}
bool f = false;
utils::strings ss = split_text(fpath, "/");
std::string p;
for(uint32_t i = 0; i < ss.size(); ++i) {
p += '/';
p += ss[i];
unit_t u;
u.value = value;
u.set_id(serial_id_);
std::pair<unit_map_it, bool> ret = unit_map_.insert(unit_pair(p, u));
if(ret.second) {
++serial_id_;
auto prev = utils::get_file_path(p);
if(p != prev) {
unit_map_it it = unit_map_.find(prev);
if(it != unit_map_.end()) {
unit_t& t = it->second;
t.install_child(utils::get_file_name(p));
}
}
f = true;
} else {
f = false;
}
}
return f;
}
示例4: apply_temp_modifier
void recruit::apply_temp_modifier(unit_map& unit_map)
{
assert(valid());
temp_unit_->set_location(recruit_hex_);
DBG_WB << "Inserting future recruit [" << temp_unit_->id()
<< "] at position " << temp_unit_->get_location() << ".\n";
// Add cost to money spent on recruits.
resources::gameboard->teams().at(team_index()).get_side_actions()->change_gold_spent_by(cost_);
// Temporarily insert unit into unit_map
// unit map takes ownership of temp_unit
unit_map.insert(temp_unit_);
// Update gold in the top bar
game_display::get_singleton()->invalidate_game_status();
}
示例5: apply_temp_modifier
void recruit::apply_temp_modifier(unit_map& unit_map)
{
assert(valid_);
temp_unit_->set_location(recruit_hex_);
DBG_WB << "Inserting future recruit [" << temp_unit_->id()
<< "] at position " << temp_unit_->get_location() << ".\n";
temp_cost_ = temp_unit_->type()->cost();
// Add cost to money spent on recruits.
resources::teams->at(team_index()).get_side_actions()->change_gold_spent_by(temp_cost_);
// Temporarily insert unit into unit_map
unit_map.insert(temp_unit_);
// unit map takes ownership of temp_unit
temp_unit_ = NULL;
// Update gold in the top bar
resources::screen->invalidate_game_status();
}
示例6: analyze
void attack_analysis::analyze(const gamemap& map, unit_map& units,
const readonly_context& ai_obj,
const move_map& dstsrc, const move_map& srcdst,
const move_map& enemy_dstsrc, double aggression)
{
const unit_map::const_iterator defend_it = units.find(target);
assert(defend_it != units.end());
// See if the target is a threat to our leader or an ally's leader.
map_location adj[6];
get_adjacent_tiles(target,adj);
size_t tile;
for(tile = 0; tile != 6; ++tile) {
const unit_map::const_iterator leader = units.find(adj[tile]);
if(leader != units.end() && leader->can_recruit() && !ai_obj.current_team().is_enemy(leader->side())) {
break;
}
}
leader_threat = (tile != 6);
uses_leader = false;
target_value = defend_it->cost();
target_value += (double(defend_it->experience())/
double(defend_it->max_experience()))*target_value;
target_starting_damage = defend_it->max_hitpoints() -
defend_it->hitpoints();
// Calculate the 'alternative_terrain_quality' -- the best possible defensive values
// the attacking units could hope to achieve if they didn't attack and moved somewhere.
// This is used for comparative purposes, to see just how vulnerable the AI is
// making itself.
alternative_terrain_quality = 0.0;
double cost_sum = 0.0;
for(size_t i = 0; i != movements.size(); ++i) {
const unit_map::const_iterator att = units.find(movements[i].first);
const double cost = att->cost();
cost_sum += cost;
alternative_terrain_quality += cost*ai_obj.best_defensive_position(movements[i].first,dstsrc,srcdst,enemy_dstsrc).chance_to_hit;
}
alternative_terrain_quality /= cost_sum*100;
avg_damage_inflicted = 0.0;
avg_damage_taken = 0.0;
resources_used = 0.0;
terrain_quality = 0.0;
avg_losses = 0.0;
chance_to_kill = 0.0;
double def_avg_experience = 0.0;
double first_chance_kill = 0.0;
double prob_dead_already = 0.0;
assert(!movements.empty());
std::vector<std::pair<map_location,map_location> >::const_iterator m;
battle_context *prev_bc = NULL;
const combatant *prev_def = NULL;
for (m = movements.begin(); m != movements.end(); ++m) {
// We fix up units map to reflect what this would look like.
unit_ptr up = units.extract(m->first);
up->set_location(m->second);
units.insert(up);
double m_aggression = aggression;
if (up->can_recruit()) {
uses_leader = true;
// FIXME: suokko's r29531 omitted this line
leader_threat = false;
m_aggression = ai_obj.get_leader_aggression();
}
bool from_cache = false;
battle_context *bc;
// This cache is only about 99% correct, but speeds up evaluation by about 1000 times.
// We recalculate when we actually attack.
const readonly_context::unit_stats_cache_t::key_type cache_key = std::make_pair(target, &up->type());
const readonly_context::unit_stats_cache_t::iterator usc = ai_obj.unit_stats_cache().find(cache_key);
// Just check this attack is valid for this attacking unit (may be modified)
if (usc != ai_obj.unit_stats_cache().end() &&
usc->second.first.attack_num <
static_cast<int>(up->attacks().size())) {
from_cache = true;
bc = new battle_context(usc->second.first, usc->second.second);
} else {
bc = new battle_context(units, m->second, target, -1, -1, m_aggression, prev_def);
}
const combatant &att = bc->get_attacker_combatant(prev_def);
const combatant &def = bc->get_defender_combatant(prev_def);
delete prev_bc;
prev_bc = bc;
prev_def = &bc->get_defender_combatant(prev_def);
if ( !from_cache ) {
ai_obj.unit_stats_cache().insert(
std::make_pair(cache_key, std::make_pair(bc->get_attacker_stats(),
//.........这里部分代码省略.........