combine filter_base_value conditions...

...with "and" instead of "or" and made resistance_filter_matches()
also check the filter_base_value (fixes steadfast)
This commit is contained in:
Gunter Labes 2009-06-10 11:41:45 +00:00
parent a7a8b08f76
commit bc66d8b60b
4 changed files with 29 additions and 29 deletions

View file

@ -2266,7 +2266,7 @@ int unit::defense_modifier(t_translation::t_terrain terrain, int recurse_count)
return res;
}
bool unit::resistance_filter_matches(const config& cfg,bool attacker,const std::string& damage_name) const
bool unit::resistance_filter_matches(const config& cfg, bool attacker, const std::string& damage_name, int res) const
{
if(!(cfg["active_on"]=="" || (attacker && cfg["active_on"]=="offense") || (!attacker && cfg["active_on"]=="defense"))) {
return false;
@ -2286,6 +2286,7 @@ bool unit::resistance_filter_matches(const config& cfg,bool attacker,const std::
}
}
}
if (!unit_abilities::filter_base_matches(cfg, res)) return false;
return true;
}
@ -2303,7 +2304,7 @@ int unit::resistance_against(const std::string& damage_name,bool attacker,const
unit_ability_list resistance_abilities = get_abilities("resistance",loc);
for (std::vector<std::pair<const config *,map_location> >::iterator i = resistance_abilities.cfgs.begin(); i != resistance_abilities.cfgs.end();) {
if(!resistance_filter_matches(*i->first,attacker,damage_name)) {
if(!resistance_filter_matches(*i->first, attacker, damage_name, res)) {
i = resistance_abilities.cfgs.erase(i);
} else {
++i;

View file

@ -364,9 +364,7 @@ private:
bool ability_active(const std::string& ability,const config& cfg,const map_location& loc) const;
bool ability_affects_adjacent(const std::string& ability,const config& cfg,int dir,const map_location& loc) const;
bool ability_affects_self(const std::string& ability,const config& cfg,const map_location& loc) const;
bool resistance_filter_matches(const config& cfg,bool attacker,const std::string& damage_name) const;
bool resistance_filter_matches(const config& cfg,bool attacker,const attack_type& damage_type) const
{return resistance_filter_matches(cfg, attacker, damage_type.type()); };
bool resistance_filter_matches(const config& cfg,bool attacker,const std::string& damage_name, int res) const;
int movement_cost_internal(t_translation::t_terrain terrain, int recurse_count=0) const;
bool has_ability_by_id(const std::string& ability) const;

View file

@ -20,11 +20,9 @@
#include "foreach.hpp"
#include "unit.hpp"
#include "unit_abilities.hpp"
#include "terrain_filter.hpp"
#define LOG_NG LOG_STREAM(info, engine)
/*
*
@ -780,6 +778,28 @@ void individual_effect::set(value_modifier t, int val, const config *abil, const
loc=l;
}
bool filter_base_matches(const config& cfg, int def)
{
if (const config &apply_filter = cfg.child("filter_base_value")) {
std::string const &cond_eq = apply_filter["equals"];
std::string const &cond_ne = apply_filter["not_equals"];
std::string const &cond_lt = apply_filter["less_than"];
std::string const &cond_gt = apply_filter["greater_than"];
std::string const &cond_ge = apply_filter["greater_than_equal_to"];
std::string const &cond_le = apply_filter["less_than_equal_to"];
if ((cond_eq.empty() || def == lexical_cast_default<int>(cond_eq))
&& (cond_ne.empty() || def != lexical_cast_default<int>(cond_ne))
&& (cond_lt.empty() || def < lexical_cast_default<int>(cond_lt))
&& (cond_gt.empty() || def > lexical_cast_default<int>(cond_gt))
&& (cond_ge.empty() || def >= lexical_cast_default<int>(cond_ge))
&& (cond_le.empty() || def <= lexical_cast_default<int>(cond_le)))
return true;
else
return false;
}
return true;
}
effect::effect(const unit_ability_list& list, int def, bool backstab) :
effect_list_(),
composite_value_(0)
@ -799,28 +819,9 @@ effect::effect(const unit_ability_list& list, int def, bool backstab) :
if (!backstab && utils::string_bool(cfg["backstab"]))
continue;
if (!filter_base_matches(cfg, def))
continue;
if (const config &apply_filter = cfg.child("filter_base_value"))
{
std::string const &cond_eq = apply_filter["equals"];
if (!cond_eq.empty() && lexical_cast_default<int>(cond_eq) != def)
continue;
std::string const &cond_ne = apply_filter["not_equals"];
if (!cond_ne.empty() && lexical_cast_default<int>(cond_ne) == def)
continue;
std::string const &cond_lt = apply_filter["less_than"];
if (!cond_lt.empty() && lexical_cast_default<int>(cond_lt) <= def)
continue;
std::string const &cond_gt = apply_filter["greater_than"];
if (!cond_gt.empty() && lexical_cast_default<int>(cond_gt) >= def)
continue;
std::string const &cond_ge = apply_filter["greater_than_equal_to"];
if (!cond_ge.empty() && lexical_cast_default<int>(cond_ge) > def)
continue;
std::string const &cond_le = apply_filter["less_than_equal_to"];
if (!cond_le.empty() && lexical_cast_default<int>(cond_le) < def)
continue;
}
std::string const &cfg_value = cfg["value"];
if (!cfg_value.empty()) {
int value = lexical_cast_default<int>(cfg_value);

View file

@ -23,7 +23,7 @@ class unit_ability_list;
namespace unit_abilities
{
bool filter_base_matches(const config& cfg, int def);
enum value_modifier {NOT_USED,SET,ADD,MUL};