mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-18 16:21:40 +00:00
Introduce a typedef to make some of the code more readable.
This commit is contained in:
parent
2da6f3cd3b
commit
177605fbaf
@ -1201,8 +1201,7 @@ const map_location& readonly_context_impl::suitable_keep(const map_location& lea
|
|||||||
|
|
||||||
|
|
||||||
/** Weapon choice cache, to speed simulations. */
|
/** Weapon choice cache, to speed simulations. */
|
||||||
std::map<std::pair<map_location,const unit_type *>,
|
readonly_context::unit_stats_cache_t & readonly_context_impl::unit_stats_cache() const
|
||||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> >& readonly_context_impl::unit_stats_cache() const
|
|
||||||
{
|
{
|
||||||
return unit_stats_cache_;
|
return unit_stats_cache_;
|
||||||
}
|
}
|
||||||
|
@ -388,8 +388,10 @@ public:
|
|||||||
virtual config to_readonly_context_config() const = 0;
|
virtual config to_readonly_context_config() const = 0;
|
||||||
|
|
||||||
|
|
||||||
virtual std::map<std::pair<map_location,const unit_type *>,
|
typedef std::map<std::pair<map_location,const unit_type *>,
|
||||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> >& unit_stats_cache() const = 0;
|
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 *>,
|
virtual unit_stats_cache_t & unit_stats_cache() const
|
||||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> >& unit_stats_cache() const
|
|
||||||
{
|
{
|
||||||
return target_->unit_stats_cache();
|
return target_->unit_stats_cache();
|
||||||
}
|
}
|
||||||
@ -1419,8 +1420,7 @@ public:
|
|||||||
virtual config to_readonly_context_config() const;
|
virtual config to_readonly_context_config() const;
|
||||||
|
|
||||||
|
|
||||||
virtual std::map<std::pair<map_location,const unit_type *>,
|
virtual unit_stats_cache_t & unit_stats_cache() const;
|
||||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> >& unit_stats_cache() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -1471,8 +1471,7 @@ private:
|
|||||||
aspect_type< bool >::typesafe_ptr simple_targeting_;
|
aspect_type< bool >::typesafe_ptr simple_targeting_;
|
||||||
mutable move_map srcdst_;
|
mutable move_map srcdst_;
|
||||||
aspect_type< bool >::typesafe_ptr support_villages_;
|
aspect_type< bool >::typesafe_ptr support_villages_;
|
||||||
mutable std::map<std::pair<map_location,const unit_type *>,
|
mutable unit_stats_cache_t unit_stats_cache_;
|
||||||
std::pair<battle_context_unit_stats,battle_context_unit_stats> > unit_stats_cache_;
|
|
||||||
aspect_type< double >::typesafe_ptr village_value_;
|
aspect_type< double >::typesafe_ptr village_value_;
|
||||||
aspect_type< int >::typesafe_ptr villages_per_scout_;
|
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.
|
// This cache is only about 99% correct, but speeds up evaluation by about 1000 times.
|
||||||
// We recalculate when we actually attack.
|
// 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 readonly_context::unit_stats_cache_t::key_type cache_key = std::make_pair(target, &up->type());
|
||||||
const unit_type &up_type = up->type();
|
const readonly_context::unit_stats_cache_t::iterator usc = ai_obj.unit_stats_cache().find(cache_key);
|
||||||
usc = ai_obj.unit_stats_cache().find(std::pair<map_location, const unit_type *>(target, &up_type));
|
|
||||||
// Just check this attack is valid for this attacking unit (may be modified)
|
// Just check this attack is valid for this attacking unit (may be modified)
|
||||||
if (usc != ai_obj.unit_stats_cache().end() &&
|
if (usc != ai_obj.unit_stats_cache().end() &&
|
||||||
usc->second.first.attack_num <
|
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);
|
prev_def = &bc->get_defender_combatant(prev_def);
|
||||||
|
|
||||||
if ( !from_cache ) {
|
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> >
|
ai_obj.unit_stats_cache().insert(
|
||||||
(std::pair<map_location, const unit_type *>(target, &up_type),
|
std::make_pair(cache_key, std::make_pair(bc->get_attacker_stats(),
|
||||||
std::pair<battle_context_unit_stats,battle_context_unit_stats>(bc->get_attacker_stats(),
|
bc->get_defender_stats())));
|
||||||
bc->get_defender_stats())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note we didn't fight at all if defender is already dead.
|
// Note we didn't fight at all if defender is already dead.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user