Introduce a typedef to make some of the code more readable.
This commit is contained in:
parent
2da6f3cd3b
commit
177605fbaf
3 changed files with 13 additions and 17 deletions
|
@ -1201,8 +1201,7 @@ const map_location& readonly_context_impl::suitable_keep(const map_location& lea
|
|||
|
||||
|
||||
/** Weapon choice cache, to speed simulations. */
|
||||
std::map<std::pair<map_location,const unit_type *>,
|
||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> >& readonly_context_impl::unit_stats_cache() const
|
||||
readonly_context::unit_stats_cache_t & readonly_context_impl::unit_stats_cache() const
|
||||
{
|
||||
return unit_stats_cache_;
|
||||
}
|
||||
|
|
|
@ -388,8 +388,10 @@ public:
|
|||
virtual config to_readonly_context_config() const = 0;
|
||||
|
||||
|
||||
virtual std::map<std::pair<map_location,const unit_type *>,
|
||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> >& unit_stats_cache() const = 0;
|
||||
typedef std::map<std::pair<map_location,const unit_type *>,
|
||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> >
|
||||
unit_stats_cache_t;
|
||||
virtual unit_stats_cache_t & unit_stats_cache() const = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -945,8 +947,7 @@ public:
|
|||
}
|
||||
|
||||
|
||||
virtual std::map<std::pair<map_location,const unit_type *>,
|
||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> >& unit_stats_cache() const
|
||||
virtual unit_stats_cache_t & unit_stats_cache() const
|
||||
{
|
||||
return target_->unit_stats_cache();
|
||||
}
|
||||
|
@ -1419,8 +1420,7 @@ public:
|
|||
virtual config to_readonly_context_config() const;
|
||||
|
||||
|
||||
virtual std::map<std::pair<map_location,const unit_type *>,
|
||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> >& unit_stats_cache() const;
|
||||
virtual unit_stats_cache_t & unit_stats_cache() const;
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
|
@ -1471,8 +1471,7 @@ private:
|
|||
aspect_type< bool >::typesafe_ptr simple_targeting_;
|
||||
mutable move_map srcdst_;
|
||||
aspect_type< bool >::typesafe_ptr support_villages_;
|
||||
mutable std::map<std::pair<map_location,const unit_type *>,
|
||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> > unit_stats_cache_;
|
||||
mutable unit_stats_cache_t unit_stats_cache_;
|
||||
aspect_type< double >::typesafe_ptr village_value_;
|
||||
aspect_type< int >::typesafe_ptr villages_per_scout_;
|
||||
|
||||
|
|
|
@ -114,9 +114,8 @@ void attack_analysis::analyze(const gamemap& map, unit_map& units,
|
|||
|
||||
// This cache is only about 99% correct, but speeds up evaluation by about 1000 times.
|
||||
// We recalculate when we actually attack.
|
||||
std::map<std::pair<map_location, const unit_type *>,std::pair<battle_context_unit_stats,battle_context_unit_stats> >::iterator usc;
|
||||
const unit_type &up_type = up->type();
|
||||
usc = ai_obj.unit_stats_cache().find(std::pair<map_location, const unit_type *>(target, &up_type));
|
||||
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 <
|
||||
|
@ -135,10 +134,9 @@ void attack_analysis::analyze(const gamemap& map, unit_map& units,
|
|||
prev_def = &bc->get_defender_combatant(prev_def);
|
||||
|
||||
if ( !from_cache ) {
|
||||
ai_obj.unit_stats_cache().insert(std::pair<std::pair<map_location, const unit_type *>,std::pair<battle_context_unit_stats,battle_context_unit_stats> >
|
||||
(std::pair<map_location, const unit_type *>(target, &up_type),
|
||||
std::pair<battle_context_unit_stats,battle_context_unit_stats>(bc->get_attacker_stats(),
|
||||
bc->get_defender_stats())));
|
||||
ai_obj.unit_stats_cache().insert(
|
||||
std::make_pair(cache_key, std::make_pair(bc->get_attacker_stats(),
|
||||
bc->get_defender_stats())));
|
||||
}
|
||||
|
||||
// Note we didn't fight at all if defender is already dead.
|
||||
|
|
Loading…
Add table
Reference in a new issue