本文整理汇总了C++中readonly_context::get_caution方法的典型用法代码示例。如果您正苦于以下问题:C++ readonly_context::get_caution方法的具体用法?C++ readonly_context::get_caution怎么用?C++ readonly_context::get_caution使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类readonly_context
的用法示例。
在下文中一共展示了readonly_context::get_caution方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rating
double attack_analysis::rating(double aggression, const readonly_context& ai_obj) const
{
if(leader_threat) {
aggression = 1.0;
}
if(uses_leader) {
aggression = ai_obj.get_leader_aggression();
}
double value = chance_to_kill*target_value - avg_losses*(1.0-aggression);
if(terrain_quality > alternative_terrain_quality) {
// This situation looks like it might be a bad move:
// we are moving our attackers out of their optimal terrain
// into sub-optimal terrain.
// Calculate the 'exposure' of our units to risk.
#ifdef SUOKKO
//FIXME: this code was in sukko's r29531 Correct?
const double exposure_mod = uses_leader ? ai_obj.current_team().caution()* 8.0 : ai_obj.current_team().caution() * 4.0;
const double exposure = exposure_mod*resources_used*((terrain_quality - alternative_terrain_quality)/10)*vulnerability/std::max<double>(0.01,support);
#else
const double exposure_mod = uses_leader ? 2.0 : ai_obj.get_caution();
const double exposure = exposure_mod*resources_used*(terrain_quality - alternative_terrain_quality)*vulnerability/std::max<double>(0.01,support);
#endif
LOG_AI << "attack option has base value " << value << " with exposure " << exposure << ": "
<< vulnerability << "/" << support << " = " << (vulnerability/std::max<double>(support,0.1)) << "\n";
value -= exposure*(1.0-aggression);
}
// Prefer to attack already damaged targets.
value += ((target_starting_damage/3 + avg_damage_inflicted) - (1.0-aggression)*avg_damage_taken)/10.0;
// If the unit is surrounded and there is no support,
// or if the unit is surrounded and the average damage is 0,
// the unit skips its sanity check and tries to break free as good as possible.
if(!is_surrounded || (support != 0 && avg_damage_taken != 0))
{
// Sanity check: if we're putting ourselves at major risk,
// and have no chance to kill, and we're not aiding our allies
// who are also attacking, then don't do it.
if(vulnerability > 50.0 && vulnerability > support*2.0
&& chance_to_kill < 0.02 && aggression < 0.75
&& !attack_close(target)) {
return -1.0;
}
}
if(!leader_threat && vulnerability*terrain_quality > 0.0 && !is_surrounded) {
value *= support/(vulnerability*terrain_quality);
}
value /= ((resources_used/2) + (resources_used/2)*terrain_quality);
if(leader_threat) {
value *= 5.0;
}
LOG_AI << "attack on " << target << ": attackers: " << movements.size()
<< " value: " << value << " chance to kill: " << chance_to_kill
<< " damage inflicted: " << avg_damage_inflicted
<< " damage taken: " << avg_damage_taken
<< " vulnerability: " << vulnerability
<< " support: " << support
<< " quality: " << terrain_quality
<< " alternative quality: " << alternative_terrain_quality << "\n";
return value;
}