Add attack_weight & defense_weight attributes to [attack], ...
...which allow units to choose different weapons upon attack of defense if they have several. Closes: #8621
This commit is contained in:
parent
a41ebc7823
commit
9befbee952
3 changed files with 22 additions and 0 deletions
|
@ -251,6 +251,7 @@ battle_stats evaluate_battle_stats(
|
|||
if(defender_attacks[defend_option].range() == attack.range() &&
|
||||
defender_attacks[defend_option].hexes() >= combat_range) {
|
||||
const double rating = a->second.damage_against(defender_attacks[defend_option])*defender_attacks[defend_option].num_attacks();
|
||||
rating *= defender_attacks[defend_option].defense_weight();
|
||||
if(defend == -1 || rating > best_defend_rating) {
|
||||
best_defend_rating = rating;
|
||||
defend = defend_option;
|
||||
|
|
|
@ -42,6 +42,13 @@ attack_type::attack_type(const config& cfg)
|
|||
damage_ = atol(cfg["damage"].c_str());
|
||||
num_attacks_ = atol(cfg["number"].c_str());
|
||||
|
||||
attack_weight_ = atof(cfg["attack_weight"].c_str());
|
||||
defense_weight_ = atof(cfg["defense_weight"].c_str());
|
||||
if ( ! attack_weight_ )
|
||||
attack_weight_ = 1.0;
|
||||
if ( ! defense_weight_ )
|
||||
defense_weight_ = 1.0;
|
||||
|
||||
config::const_child_itors range = cfg.child_range("frame");
|
||||
for(; range.first != range.second; ++range.first){
|
||||
const int beg = atoi((**range.first)["begin"].c_str());
|
||||
|
@ -122,6 +129,16 @@ int attack_type::num_attacks() const
|
|||
return num_attacks_;
|
||||
}
|
||||
|
||||
double attack_type::attack_weight() const
|
||||
{
|
||||
return attack_weight_;
|
||||
}
|
||||
|
||||
double attack_type::defense_weight() const
|
||||
{
|
||||
return defense_weight_;
|
||||
}
|
||||
|
||||
int attack_type::get_first_frame(attack_type::FRAME_TYPE type) const
|
||||
{
|
||||
if(frames_[type].empty())
|
||||
|
|
|
@ -37,6 +37,8 @@ public:
|
|||
int hexes() const;
|
||||
int damage() const;
|
||||
int num_attacks() const;
|
||||
double attack_weight() const;
|
||||
double defense_weight() const;
|
||||
|
||||
enum FRAME_TYPE { UNIT_FRAME, MISSILE_FRAME };
|
||||
enum FRAME_DIRECTION { VERTICAL, DIAGONAL };
|
||||
|
@ -69,6 +71,8 @@ private:
|
|||
int hexes_;
|
||||
int damage_;
|
||||
int num_attacks_;
|
||||
double attack_weight_;
|
||||
double defense_weight_;
|
||||
|
||||
struct frame {
|
||||
frame(int i1, int i2, const std::string& img, int offset)
|
||||
|
|
Loading…
Add table
Reference in a new issue