attack_weight=0 disables the attack when attacking

defense_weight=0 disables the attack when defending
This commit is contained in:
Benoît Timbert 2006-01-07 20:09:09 +00:00
parent 6b1c54a0da
commit e362f2f5fb
6 changed files with 73 additions and 58 deletions

View file

@ -9,8 +9,10 @@ SVN trunk (1.1+svn):
* updated translations: German, Hebrew, Norwegian, Polish, Russian
* units
* gave names to mermaids
* gameplay change :
* gameplay changes :
* improved default weapon selection on player attack (patch #500)
* attack_weight=0 disables the attack when attacking
* defense_weight=0 disables the attack when defending
* user interface
* centered BFW title logo on main screen for 1024x768 (still off-center for
800x600)

View file

@ -370,14 +370,16 @@ battle_stats evaluate_battle_stats(const gamemap& map,
res.ndefends = 0;
for(int defend_option = 0; defend_option != int(defender_attacks.size()); ++defend_option) {
if(defender_attacks[defend_option].range() == attack.range()) {
const double rating = a->second.damage_against(defender_attacks[defend_option])
*defender_attacks[defend_option].damage()
* defender_attacks[defend_option].num_swarm_attacks(
d->second.hitpoints(), d->second.max_hitpoints())
*defender_attacks[defend_option].defense_weight();
if(defend_with == -1 || rating > best_defend_rating) {
best_defend_rating = rating;
defend_with = defend_option;
if (defender_attacks[defend_option].defense_weight() > 0) {
const double rating = a->second.damage_against(defender_attacks[defend_option])
*defender_attacks[defend_option].damage()
*defender_attacks[defend_option].num_swarm_attacks(
d->second.hitpoints(), d->second.max_hitpoints())
*defender_attacks[defend_option].defense_weight();
if(defend_with == -1 || rating > best_defend_rating) {
best_defend_rating = rating;
defend_with = defend_option;
}
}
}
}

View file

@ -104,12 +104,14 @@ protected:
int best_attack_rating = -1;
int best_attack = -1;
for(size_t n = 0; n != attacks.size(); ++n) {
if (attacks[n].attack_weight() > 0){
const battle_stats stats = evaluate_battle_stats(get_info().map, get_info().teams, attacker, defender, n, get_info().units, get_info().state);
const int attack_rating = stats.damage_defender_takes*stats.nattacks*stats.chance_to_hit_defender;
if(best_attack == -1 || attack_rating > best_attack_rating) {
best_attack = n;
best_attack_rating = attack_rating;
}
best_attack = n;
best_attack_rating = attack_rating;
}
}
}
return best_attack;

View file

@ -325,19 +325,21 @@ int ai::choose_weapon(const location& att, const location& def,
int a_hitpoints = itor->second.hitpoints();
for(size_t a = 0; a != attacks.size(); ++a) {
const battle_stats stats = evaluate_battle_stats(map_, teams_, att, def, a, units_,
if (attacks[a].attack_weight() > 0){
const battle_stats stats = evaluate_battle_stats(map_, teams_, att, def, a, units_,
state_, terrain);
//TODO: improve this rating formula!
const double rating =
(double(stats.chance_to_hit_defender)/100.0)*
minimum<int>(stats.damage_defender_takes,d_hitpoints)*stats.nattacks -
(double(stats.chance_to_hit_attacker)/100.0)*
minimum<int>(stats.damage_attacker_takes,a_hitpoints)*stats.ndefends;
if(rating > current_rating || current_choice == -1) {
current_choice = a;
current_rating = rating;
cur_stats = stats;
//TODO: improve this rating formula!
const double rating =
(double(stats.chance_to_hit_defender)/100.0)*
minimum<int>(stats.damage_defender_takes,d_hitpoints)*stats.nattacks -
(double(stats.chance_to_hit_attacker)/100.0)*
minimum<int>(stats.damage_attacker_takes,a_hitpoints)*stats.ndefends;
if(rating > current_rating || current_choice == -1) {
current_choice = a;
current_rating = rating;
cur_stats = stats;
}
}
}

View file

@ -673,39 +673,40 @@ bool turn_info::attack_enemy(unit_map::iterator attacker, unit_map::iterator def
attack_calculations_displayer::stats_vector stats;
for(size_t a = 0; a != attacks.size(); ++a) {
battle_stats_strings sts;
battle_stats st = evaluate_battle_stats(map_, teams_, attacker_loc, defender_loc,
if (attacks[a].attack_weight() > 0){
battle_stats_strings sts;
battle_stats st = evaluate_battle_stats(map_, teams_, attacker_loc, defender_loc,
a, units_, status_, 0, &sts);
stats.push_back(sts);
stats.push_back(sts);
simple_attack_rating weapon_rating(st);
simple_attack_rating weapon_rating(st);
if (best_weapon_index < 0 || best_weapon_rating < weapon_rating) {
best_weapon_index = items.size();
best_weapon_rating = weapon_rating;
if (best_weapon_index < 0 || best_weapon_rating < weapon_rating) {
best_weapon_index = items.size();
best_weapon_rating = weapon_rating;
}
//if there is an attack special or defend special, we output a single space for the other unit, to make sure
//that the attacks line up nicely.
std::string special_pad = (sts.attack_special.empty() && sts.defend_special.empty()) ? "" : " ";
int damage_defender_takes;
damage_defender_takes = st.damage_defender_takes;
int damage_attacker_takes;
damage_attacker_takes = st.damage_attacker_takes;
std::stringstream att;
att << IMAGE_PREFIX << sts.attack_icon << COLUMN_SEPARATOR
<< font::BOLD_TEXT << sts.attack_name << "\n" << damage_defender_takes << "-"
<< st.nattacks << " " << sts.range << " (" << st.chance_to_hit_defender << "%)\n"
<< sts.attack_special << special_pad
<< COLUMN_SEPARATOR << _("vs") << COLUMN_SEPARATOR
<< font::BOLD_TEXT << sts.defend_name << "\n" << damage_attacker_takes << "-"
<< st.ndefends << " " << sts.range << " (" << st.chance_to_hit_attacker << "%)\n"
<< sts.defend_special << special_pad << COLUMN_SEPARATOR
<< IMAGE_PREFIX << sts.defend_icon;
items.push_back(att.str());
}
//if there is an attack special or defend special, we output a single space for the other unit, to make sure
//that the attacks line up nicely.
std::string special_pad = (sts.attack_special.empty() && sts.defend_special.empty()) ? "" : " ";
int damage_defender_takes;
damage_defender_takes = st.damage_defender_takes;
int damage_attacker_takes;
damage_attacker_takes = st.damage_attacker_takes;
std::stringstream att;
att << IMAGE_PREFIX << sts.attack_icon << COLUMN_SEPARATOR
<< font::BOLD_TEXT << sts.attack_name << "\n" << damage_defender_takes << "-"
<< st.nattacks << " " << sts.range << " (" << st.chance_to_hit_defender << "%)\n"
<< sts.attack_special << special_pad
<< COLUMN_SEPARATOR << _("vs") << COLUMN_SEPARATOR
<< font::BOLD_TEXT << sts.defend_name << "\n" << damage_attacker_takes << "-"
<< st.ndefends << " " << sts.range << " (" << st.chance_to_hit_attacker << "%)\n"
<< sts.defend_special << special_pad << COLUMN_SEPARATOR
<< IMAGE_PREFIX << sts.defend_icon;
items.push_back(att.str());
}
if (best_weapon_index >= 0) {

View file

@ -197,12 +197,18 @@ 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;
const std::string& attack_weight_string=cfg["attack_weight"];
if (attack_weight_string.empty()) {
attack_weight_ = 1.0;
} else {
attack_weight_ = atof(attack_weight_string.c_str());
}
const std::string& defense_weight_string=cfg["defense_weight"];
if (defense_weight_string.empty()) {
defense_weight_ = 1.0;
} else {
defense_weight_ = atof(defense_weight_string.c_str());
}
}
const t_string& attack_type::name() const