diff --git a/src/include/spells.h b/src/include/spells.h index 2b3b8003b2..3695525e7c 100644 --- a/src/include/spells.h +++ b/src/include/spells.h @@ -41,6 +41,9 @@ #include "unitsound.h" #include "vec2i.h" +#include +#include + /*---------------------------------------------------------------------------- -- Declarations ----------------------------------------------------------------------------*/ @@ -83,6 +86,13 @@ enum TargetType { TargetUnit }; +enum class ECondition +{ + Ignore, + ShouldBeFalse, + ShouldBeTrue +}; + /* ** ******************* ** Target definition. @@ -111,7 +121,7 @@ class ConditionInfoVariable public: ConditionInfoVariable() = default; - char Enable = 0; /// Target is 'user defined variable'. + ECondition Enable = ECondition::Ignore; /// Target is 'user defined variable'. bool Check = false; /// True if need to check that variable. int ExactValue = 0; /// Target must have exactly ExactValue of it's value. @@ -138,14 +148,11 @@ class ConditionInfo // // Conditions that check specific flags. Possible values are the defines below. // -#define CONDITION_FALSE 1 -#define CONDITION_TRUE 0 -#define CONDITION_ONLY 2 - char Alliance = 0; /// Target is allied. (neutral is neither allied, nor opponent) - char Opponent = 0; /// Target is opponent. (neutral is neither allied, nor opponent) - char TargetSelf = 1; /// Target is the same as the caster. + ECondition Alliance = ECondition::Ignore; /// Target is allied. (neutral is neither allied, nor opponent) + ECondition Opponent = ECondition::Ignore; /// Target is opponent. (neutral is neither allied, nor opponent) + ECondition TargetSelf = ECondition::ShouldBeFalse; /// Target is the same as the caster. - std::vector BoolFlag; /// User defined boolean flag. + std::vector BoolFlag; /// User defined boolean flag. std::vector Variable; std::unique_ptr CheckFunc; @@ -176,9 +183,9 @@ class AutoCastInfo /// Detailed generic conditions (not per-target, where Condition is evaluated.) /// Combat mode is when there are hostile non-coward units around - int Combat = 0; /// If it should be casted in combat - int Attacker = 0; /// If it should be casted on unit which attacks - int Corpse = CONDITION_FALSE; /// If it should be casted on corpses + ECondition Combat = ECondition::Ignore; /// If it should be casted in combat + ECondition Attacker = ECondition::Ignore; /// If it should be casted on unit which attacks + ECondition Corpse = ECondition::ShouldBeFalse; /// If it should be casted on corpses // Position autocast callback std::unique_ptr PositionAutoCast; @@ -263,8 +270,11 @@ extern bool AutoCastSpell(CUnit &caster, const SpellType &spell); /// return spell type by ident string extern SpellType &SpellTypeByIdent(const std::string_view &ident); -/// return 0, 1, 2 for true, only, false. -extern char Ccl2Condition(lua_State *l, std::string_view value); +/// return ECondition. +extern ECondition Ccl2Condition(lua_State *l, std::string_view value); + +std::variant Ccl2ConditionOrNumber(lua_State *l, std::string_view value); + //@} diff --git a/src/include/ui.h b/src/include/ui.h index 00ef34ccab..13556fac54 100644 --- a/src/include/ui.h +++ b/src/include/ui.h @@ -70,6 +70,7 @@ class CFile; class CFont; class LuaActionListener; class CPopup; +enum class ECondition; /*---------------------------------------------------------------------------- -- Definitions @@ -185,8 +186,8 @@ class ConditionPanel bool HideAllied = false; /// if true, don't show for allied unit. (but show own units) bool ShowOpponent = false; /// if true, show for opponent unit. - std::vector BoolFlags; /// array of condition about user flags. - std::vector Variables; /// array of variable to verify (enable and max > 0) + std::vector BoolFlags; /// array of condition about user flags. + std::vector> Variables; /// array of variable to verify (enable and max > 0) }; /** diff --git a/src/include/ui/popup.h b/src/include/ui/popup.h index 0eae7de8f8..ac5b6e8d28 100644 --- a/src/include/ui/popup.h +++ b/src/include/ui/popup.h @@ -49,6 +49,7 @@ class ButtonAction; class CFont; class CPopup; enum class ButtonCmd; +enum class ECondition; #define MARGIN_X 4 #define MARGIN_Y 2 @@ -65,8 +66,8 @@ class PopupConditionPanel std::optional ButtonAction; /// action type of button std::string ButtonValue; /// value used in ValueStr field of button - std::vector BoolFlags; /// array of condition about user flags. - std::vector Variables; /// array of variable to verify (enable and max > 0) + std::vector BoolFlags; /// array of condition about user flags. + std::vector Variables; /// array of variable to verify (enable and max > 0) }; class CPopupContentType diff --git a/src/include/unittype.h b/src/include/unittype.h index ddc56eb38f..7c8203ac9f 100644 --- a/src/include/unittype.h +++ b/src/include/unittype.h @@ -51,6 +51,7 @@ #include "color.h" #include "luacallback.h" #include "missileconfig.h" +#include "spells.h" #include "vec2i.h" #include @@ -562,7 +563,7 @@ class CUnitType Vec2i GetHalfTileSize() const { return Vec2i(TileWidth / 2, TileHeight / 2); } PixelSize GetPixelSize() const; - bool CheckUserBoolFlags(const std::vector &BoolFlags) const; + bool CheckUserBoolFlags(const std::vector &BoolFlags) const; bool CanTransport() const { return MaxOnBoard > 0 && !GivesResource; } bool CanMove() const; @@ -677,9 +678,9 @@ class CUnitType CUnitStats MapDefaultStat; struct BoolFlags { bool value = false; /// User defined flag. Used for (dis)allow target. - char CanTransport = 0; /// Can transport units with this flag. - char CanTargetFlag = 0; /// Flag needed to target with missile. - char AiPriorityTarget = 0; /// Attack this units first. + ECondition CanTransport = ECondition::Ignore; /// Can transport units with this flag. + ECondition CanTargetFlag = ECondition::Ignore; /// Flag needed to target with missile. + ECondition AiPriorityTarget = ECondition::Ignore; /// Attack this units first. }; std::vector BoolFlag; diff --git a/src/spell/script_spell.cpp b/src/spell/script_spell.cpp index d6071e809b..7f67bb963c 100644 --- a/src/spell/script_spell.cpp +++ b/src/spell/script_spell.cpp @@ -111,19 +111,33 @@ static std::unique_ptr CclSpellAction(lua_State *l) ** @param l Lua state. ** @param value scm value to convert. ** -** @return CONDITION_TRUE, CONDITION_FALSE, CONDITION_ONLY or -1 on error. -** @note This is a helper function to make CclSpellCondition shorter -** and easier to understand. +** @return ECondition. */ -char Ccl2Condition(lua_State *l, std::string_view value) +ECondition Ccl2Condition(lua_State *l, std::string_view value) { if (value == "true") { - return CONDITION_TRUE; + return ECondition::Ignore; } else if (value == "false") { - return CONDITION_FALSE; + return ECondition::ShouldBeFalse; } else if (value == "only") { - return CONDITION_ONLY; - } else if (value[0] == '<') { + return ECondition::ShouldBeTrue; + } else { + LuaError(l, "Bad condition result: %s", value.data()); + ExitFatal(-1); + } +} + +/** +** Get a condition value from a scm object. +** +** @param l Lua state. +** @param value scm value to convert. +** +** @return ECondition. +*/ +std::variant Ccl2ConditionOrNumber(lua_State *l, std::string_view value) +{ + if (value[0] == '<') { int v = to_number(value.substr(1)); if (v > 100) { LuaError(l, "Can only encode condition '<' up to 100%%, got %d", v); @@ -134,13 +148,13 @@ char Ccl2Condition(lua_State *l, std::string_view value) if (v > 100) { LuaError(l, "Can only encode condition '<' up to 100%%, got %d", v); } - return v + CONDITION_ONLY; + return v; } else { - LuaError(l, "Bad condition result: %s", value.data()); - return -1; + return Ccl2Condition(l, value); } } + /** ** Parse the Condition for spell. ** @@ -151,11 +165,11 @@ char Ccl2Condition(lua_State *l, std::string_view value) */ static void CclSpellCondition(lua_State *l, ConditionInfo *condition) { - // Flags are defaulted to 0(CONDITION_TRUE) + // Flags are defaulted to ECondition::Ignore size_t new_bool_size = UnitTypeVar.GetNumberBoolFlag(); condition->BoolFlag.resize(new_bool_size); - std::fill(std::begin(condition->BoolFlag), std::end(condition->BoolFlag), 0); + std::fill(std::begin(condition->BoolFlag), std::end(condition->BoolFlag), ECondition::Ignore); condition->Variable.resize(UnitTypeVar.GetNumberVariable()); // Initialize min/max stuff to values with no effect. diff --git a/src/spell/spells.cpp b/src/spell/spells.cpp index c337cf0ddb..a1bd7c4639 100644 --- a/src/spell/spells.cpp +++ b/src/spell/spells.cpp @@ -131,8 +131,9 @@ static bool PassCondition(const CUnit &caster, const SpellType &spell, const CUn if (unit == nullptr) { continue; } - if (condition->Variable[i].Enable != CONDITION_TRUE) { - if ((condition->Variable[i].Enable == CONDITION_ONLY) ^ (unit->Variable[i].Enable)) { + if (condition->Variable[i].Enable != ECondition::Ignore) { + if ((condition->Variable[i].Enable == ECondition::ShouldBeTrue) + ^ (unit->Variable[i].Enable)) { return false; } } @@ -184,21 +185,20 @@ static bool PassCondition(const CUnit &caster, const SpellType &spell, const CUn return true; } - if (condition->Alliance != CONDITION_TRUE) { - if ((condition->Alliance == CONDITION_ONLY) ^ - // own units could be not allied ? - (caster.IsAllied(*target) || target->Player == caster.Player)) { + if (condition->Alliance != ECondition::Ignore) { + // own units could be not allied ? + if ((condition->Alliance == ECondition::ShouldBeTrue) + ^ (caster.IsAllied(*target) || target->Player == caster.Player)) { return false; } } - if (condition->Opponent != CONDITION_TRUE) { - if ((condition->Opponent == CONDITION_ONLY) ^ - (caster.IsEnemy(*target) && 1)) { + if (condition->Opponent != ECondition::Ignore) { + if ((condition->Opponent == ECondition::ShouldBeTrue) ^ caster.IsEnemy(*target)) { return false; } } - if (condition->TargetSelf != CONDITION_TRUE) { - if ((condition->TargetSelf == CONDITION_ONLY) ^ (&caster == target)) { + if (condition->TargetSelf != ECondition::Ignore) { + if ((condition->TargetSelf == ECondition::ShouldBeTrue) ^ (&caster == target)) { return false; } } @@ -263,7 +263,7 @@ static std::unique_ptr SelectTargetUnitsOfAutoCast(CUnit &caster, const table.push_back(&caster); // Allow self as target (we check conditions later) // Check generic conditions. FIXME: a better way to do this? - if (autocast->Combat != CONDITION_TRUE) { + if (autocast->Combat != ECondition::Ignore) { // Check each unit if it is hostile. const bool inCombat = ranges::find_if(table, @@ -275,7 +275,7 @@ static std::unique_ptr SelectTargetUnitsOfAutoCast(CUnit &caster, const || CanTarget(*target->Type, *caster.Type)); }) != table.end(); - if ((autocast->Combat == CONDITION_ONLY) ^ (inCombat)) { + if ((autocast->Combat == ECondition::ShouldBeTrue) ^ (inCombat)) { return nullptr; } } @@ -292,11 +292,11 @@ static std::unique_ptr SelectTargetUnitsOfAutoCast(CUnit &caster, const size_t count = 0; for (size_t i = 0; i != table.size(); ++i) { // Check for corpse - if (autocast->Corpse == CONDITION_ONLY) { + if (autocast->Corpse == ECondition::ShouldBeTrue) { if (table[i]->CurrentAction() != UnitAction::Die) { continue; } - } else if (autocast->Corpse == CONDITION_FALSE) { + } else if (autocast->Corpse == ECondition::ShouldBeFalse) { if (table[i]->CurrentAction() == UnitAction::Die || table[i]->IsAlive() == false) { continue; } @@ -332,7 +332,7 @@ static std::unique_ptr SelectTargetUnitsOfAutoCast(CUnit &caster, const int n = 0; for (size_t i = 0; i != table.size(); ++i) { // Check if unit in battle - if (autocast->Attacker == CONDITION_ONLY) { + if (autocast->Attacker == ECondition::ShouldBeTrue) { const int range = table[i]->Player->Type == PlayerTypes::PlayerPerson ? table[i]->Type->ReactRangePerson : table[i]->Type->ReactRangeComputer; if ((table[i]->CurrentAction() != UnitAction::Attack && table[i]->CurrentAction() != UnitAction::AttackGround @@ -343,11 +343,11 @@ static std::unique_ptr SelectTargetUnitsOfAutoCast(CUnit &caster, const } } // Check for corpse - if (autocast->Corpse == CONDITION_ONLY) { + if (autocast->Corpse == ECondition::ShouldBeTrue) { if (table[i]->CurrentAction() != UnitAction::Die) { continue; } - } else if (autocast->Corpse == CONDITION_FALSE) { + } else if (autocast->Corpse == ECondition::ShouldBeFalse) { if (table[i]->CurrentAction() == UnitAction::Die) { continue; } diff --git a/src/ui/botpanel.cpp b/src/ui/botpanel.cpp index 9e710c3196..3858298a93 100644 --- a/src/ui/botpanel.cpp +++ b/src/ui/botpanel.cpp @@ -344,8 +344,9 @@ static bool CanShowPopupContent(const PopupConditionPanel *condition, if (!condition->Variables.empty() && type) { for (unsigned int i = 0; i < UnitTypeVar.GetNumberVariable(); ++i) { - if (condition->Variables[i] != CONDITION_TRUE) { - if ((condition->Variables[i] == CONDITION_ONLY) ^ type->Stats[ThisPlayer->Index].Variables[i].Enable) { + if (condition->Variables[i] != ECondition::Ignore) { + if ((condition->Variables[i] == ECondition::ShouldBeTrue) + ^ type->Stats[ThisPlayer->Index].Variables[i].Enable) { return false; } } diff --git a/src/ui/mainscr.cpp b/src/ui/mainscr.cpp index 18832512ec..46c80f601e 100644 --- a/src/ui/mainscr.cpp +++ b/src/ui/mainscr.cpp @@ -212,7 +212,7 @@ static void UiDrawManaBar(const CUnit &unit, int x, int y) ** @param condition condition to verify. ** @param unit unit that certain condition can refer. ** -** @return 0 if we can't show the content, else 1. +** @return false if we can't show the content, else true. */ static bool CanShowContent(const ConditionPanel *condition, const CUnit &unit) { @@ -220,9 +220,9 @@ static bool CanShowContent(const ConditionPanel *condition, const CUnit &unit) return true; } if ((condition->ShowOnlySelected && !unit.Selected) - || (unit.Player->Type == PlayerTypes::PlayerNeutral && condition->HideNeutral) - || (ThisPlayer->IsEnemy(unit) && !condition->ShowOpponent) - || ((ThisPlayer->IsAllied(unit) || unit.Player == ThisPlayer) && condition->HideAllied)) { + || (unit.Player->Type == PlayerTypes::PlayerNeutral && condition->HideNeutral) + || (ThisPlayer->IsEnemy(unit) && !condition->ShowOpponent) + || ((ThisPlayer->IsAllied(unit) || unit.Player == ThisPlayer) && condition->HideAllied)) { return false; } if (!unit.Type->CheckUserBoolFlags(condition->BoolFlags)) { @@ -230,33 +230,42 @@ static bool CanShowContent(const ConditionPanel *condition, const CUnit &unit) } if (!condition->Variables.empty()) { for (unsigned int i = 0; i < UnitTypeVar.GetNumberVariable(); ++i) { - char v = condition->Variables[i]; - if (v < 0) { - // only show for less than -v% - if (unit.Variable[i].Enable) { - const int f = (100 * unit.Variable[i].Value) / unit.Variable[i].Max; - if (f >= -v) { - return false; - } - } else if (v != -1) { - // special case: the condition "<1" should apply - // to units that do not have the variable at all - return false; - } - } else if (v > CONDITION_ONLY) { - // only show for more than (v-CONDITION_ONLY)% - if (unit.Variable[i].Enable) { - const int f = (100 * unit.Variable[i].Value) / unit.Variable[i].Max; - if (f <= v - CONDITION_ONLY) { - return false; + const auto is_variable_compatible = [&](auto v) { + if constexpr (std::is_same_v) { + if (v != ECondition::Ignore) { + if ((v == ECondition::ShouldBeTrue) ^ unit.Variable[i].Enable) { + return false; + } } } else { - return false; - } - } else if (v != CONDITION_TRUE) { - if ((v == CONDITION_ONLY) ^ unit.Variable[i].Enable) { - return false; + if (v < 0) { + // only show for less than -v% + if (unit.Variable[i].Enable) { + const int f = (100 * unit.Variable[i].Value) / unit.Variable[i].Max; + if (f >= -v) { + return false; + } + } else if (v != -1) { + // special case: the condition "<1" should apply + // to units that do not have the variable at all + return false; + } + } else if (v > 0) { + // only show for more than v% + if (unit.Variable[i].Enable) { + const int f = (100 * unit.Variable[i].Value) / unit.Variable[i].Max; + if (f <= v) { + return false; + } + } else { + return false; + } + } } + return true; + }; + if (!std::visit(is_variable_compatible, condition->Variables[i])) { + return false; } } } diff --git a/src/ui/mouse.cpp b/src/ui/mouse.cpp index 914e9f10e0..724207bf98 100644 --- a/src/ui/mouse.cpp +++ b/src/ui/mouse.cpp @@ -1443,7 +1443,8 @@ static int SendSpellCast(const Vec2i &tilePos) fprintf(stderr, "unknown spell-id: %d\n", CursorValue); ExitFatal(1); } - if (dest && dest == unit && (!spell->Condition || spell->Condition->TargetSelf == CONDITION_FALSE)) { + if (dest && dest == unit + && (!spell->Condition || spell->Condition->TargetSelf == ECondition::ShouldBeFalse)) { // Only spells with explicit 'self: true' allows self targetting continue; } diff --git a/src/ui/script_ui.cpp b/src/ui/script_ui.cpp index 4dd3688475..d2e14cd5f4 100644 --- a/src/ui/script_ui.cpp +++ b/src/ui/script_ui.cpp @@ -499,7 +499,7 @@ static std::unique_ptr ParseConditionPanel(lua_State *l) index = UnitTypeVar.VariableNameLookup[key]; if (index != -1) { condition->Variables.resize(UnitTypeVar.GetNumberVariable()); - condition->Variables[index] = Ccl2Condition(l, LuaToString(l, -1)); + condition->Variables[index] = Ccl2ConditionOrNumber(l, LuaToString(l, -1)); continue; } LuaError(l, "'%s' invalid for Condition in DefinePanelContents", key.data()); diff --git a/src/unit/unit.cpp b/src/unit/unit.cpp index aa71356fce..11389694d9 100644 --- a/src/unit/unit.cpp +++ b/src/unit/unit.cpp @@ -2594,11 +2594,13 @@ int ThreatCalculate(const CUnit &unit, const CUnit &dest) } for (unsigned int i = 0; i < UnitTypeVar.GetNumberBoolFlag(); i++) { - if (type.BoolFlag[i].AiPriorityTarget != CONDITION_TRUE) { - if ((type.BoolFlag[i].AiPriorityTarget == CONDITION_ONLY) & (dtype.BoolFlag[i].value)) { + if (type.BoolFlag[i].AiPriorityTarget != ECondition::Ignore) { + if ((type.BoolFlag[i].AiPriorityTarget == ECondition::ShouldBeTrue) + & (dtype.BoolFlag[i].value)) { cost -= AIPRIORITY_BONUS; } - if ((type.BoolFlag[i].AiPriorityTarget == CONDITION_FALSE) & (dtype.BoolFlag[i].value)) { + if ((type.BoolFlag[i].AiPriorityTarget == ECondition::ShouldBeFalse) + & (dtype.BoolFlag[i].value)) { cost += AIPRIORITY_BONUS; } } @@ -2680,11 +2682,13 @@ int TargetPriorityCalculate(const CUnit *const attacker, const CUnit *const dest // AI Priority for (unsigned int i = 0; i < UnitTypeVar.GetNumberBoolFlag(); i++) { - if (type.BoolFlag[i].AiPriorityTarget != CONDITION_TRUE) { - if (((type.BoolFlag[i].AiPriorityTarget == CONDITION_ONLY) & !dtype.BoolFlag[i].value) - || ((type.BoolFlag[i].AiPriorityTarget == CONDITION_FALSE) & dtype.BoolFlag[i].value)) { - return INT_MIN; - } + if (type.BoolFlag[i].AiPriorityTarget != ECondition::Ignore) { + if (((type.BoolFlag[i].AiPriorityTarget == ECondition::ShouldBeTrue) + & !dtype.BoolFlag[i].value) + || ((type.BoolFlag[i].AiPriorityTarget == ECondition::ShouldBeFalse) + & dtype.BoolFlag[i].value)) { + return INT_MIN; + } } } } @@ -3276,9 +3280,9 @@ int ViewPointDistanceToUnit(const CUnit &dest) bool CanTarget(const CUnitType &source, const CUnitType &dest) { for (unsigned int i = 0; i < UnitTypeVar.GetNumberBoolFlag(); i++) { - if (source.BoolFlag[i].CanTargetFlag != CONDITION_TRUE) { - if ((source.BoolFlag[i].CanTargetFlag == CONDITION_ONLY) ^ - (dest.BoolFlag[i].value)) { + if (source.BoolFlag[i].CanTargetFlag != ECondition::Ignore) { + if ((source.BoolFlag[i].CanTargetFlag == ECondition::ShouldBeTrue) + ^ (dest.BoolFlag[i].value)) { return false; } } @@ -3331,8 +3335,9 @@ bool CanTransport(const CUnit &transporter, const CUnit &unit) return false; } for (unsigned int i = 0; i < UnitTypeVar.GetNumberBoolFlag(); i++) { - if (transporter.Type->BoolFlag[i].CanTransport != CONDITION_TRUE) { - if ((transporter.Type->BoolFlag[i].CanTransport == CONDITION_ONLY) ^ unit.Type->BoolFlag[i].value) { + if (transporter.Type->BoolFlag[i].CanTransport != ECondition::Ignore) { + if ((transporter.Type->BoolFlag[i].CanTransport == ECondition::ShouldBeTrue) + ^ unit.Type->BoolFlag[i].value) { return false; } } diff --git a/src/unit/unit_find.cpp b/src/unit/unit_find.cpp index 95b12af463..fb88298dbf 100644 --- a/src/unit/unit_find.cpp +++ b/src/unit/unit_find.cpp @@ -726,13 +726,13 @@ class BestTargetFinder } for (unsigned int i = 0; i < UnitTypeVar.GetNumberBoolFlag(); i++) { - if (type.BoolFlag[i].AiPriorityTarget != CONDITION_TRUE) { - if ((type.BoolFlag[i].AiPriorityTarget == CONDITION_ONLY) & - (dtype.BoolFlag[i].value)) { + if (type.BoolFlag[i].AiPriorityTarget != ECondition::Ignore) { + if ((type.BoolFlag[i].AiPriorityTarget == ECondition::ShouldBeTrue) + & (dtype.BoolFlag[i].value)) { cost -= AIPRIORITY_BONUS; } - if ((type.BoolFlag[i].AiPriorityTarget == CONDITION_FALSE) & - (dtype.BoolFlag[i].value)) { + if ((type.BoolFlag[i].AiPriorityTarget == ECondition::ShouldBeFalse) + & (dtype.BoolFlag[i].value)) { cost += AIPRIORITY_BONUS; } } @@ -851,12 +851,12 @@ class BestRangeTargetFinder cost += dtype.DefaultStat.Variables[PRIORITY_INDEX].Value * PRIORITY_FACTOR; for (unsigned int i = 0; i < UnitTypeVar.GetNumberBoolFlag(); i++) { - if (type.BoolFlag[i].AiPriorityTarget != CONDITION_TRUE) { - if ((type.BoolFlag[i].AiPriorityTarget == CONDITION_ONLY) & - (dtype.BoolFlag[i].value)) { + if (type.BoolFlag[i].AiPriorityTarget != ECondition::Ignore) { + if ((type.BoolFlag[i].AiPriorityTarget == ECondition::ShouldBeTrue) + & (dtype.BoolFlag[i].value)) { cost -= AIPRIORITY_BONUS; - } else if ((type.BoolFlag[i].AiPriorityTarget == CONDITION_FALSE) & - (dtype.BoolFlag[i].value)) { + } else if ((type.BoolFlag[i].AiPriorityTarget == ECondition::ShouldBeFalse) + & (dtype.BoolFlag[i].value)) { cost += AIPRIORITY_BONUS; } } diff --git a/src/unit/unittype.cpp b/src/unit/unittype.cpp index 5beb1f686e..bb6348bf37 100644 --- a/src/unit/unittype.cpp +++ b/src/unit/unittype.cpp @@ -559,14 +559,14 @@ PixelSize CUnitType::GetPixelSize() const return PixelSize(TileWidth * PixelTileSize.x, TileHeight * PixelTileSize.y); } -bool CUnitType::CheckUserBoolFlags(const std::vector &BoolFlags) const +bool CUnitType::CheckUserBoolFlags(const std::vector &BoolFlags) const { if (BoolFlags.empty()) { return true; } for (unsigned int i = 0; i < UnitTypeVar.GetNumberBoolFlag(); ++i) { // User defined flags - if (BoolFlags[i] != CONDITION_TRUE && - ((BoolFlags[i] == CONDITION_ONLY) ^ (this->BoolFlag[i].value))) { + if (BoolFlags[i] != ECondition::Ignore + && ((BoolFlags[i] == ECondition::ShouldBeTrue) ^ (this->BoolFlag[i].value))) { return false; } }