From f874d27797d7a2961e87692f2cd0b4d656e727c6 Mon Sep 17 00:00:00 2001 From: Maxim Korotkov Date: Tue, 26 Sep 2023 15:48:21 +0300 Subject: [PATCH 1/4] AI: removed redundant checks The pointers "up" and "down" were checked against nullptr but it's always non-null Also added curly braces for if statement. It's good practice for avoiding shooting yourself to the foot Signed-off-by: Maxim Korotkov --- AI/Nullkiller/AIGateway.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/AI/Nullkiller/AIGateway.cpp b/AI/Nullkiller/AIGateway.cpp index 1cd731f43..74f101883 100644 --- a/AI/Nullkiller/AIGateway.cpp +++ b/AI/Nullkiller/AIGateway.cpp @@ -702,8 +702,8 @@ void AIGateway::showGarrisonDialog(const CArmedInstance * up, const CGHeroInstan LOG_TRACE_PARAMS(logAi, "removableUnits '%i', queryID '%i'", removableUnits % queryID); NET_EVENT_HANDLER; - std::string s1 = up ? up->nodeName() : "NONE"; - std::string s2 = down ? down->nodeName() : "NONE"; + std::string s1 = up->nodeName(); + std::string s2 = down->nodeName(); status.addQuery(queryID, boost::str(boost::format("Garrison dialog with %s and %s") % s1 % s2)); @@ -711,7 +711,9 @@ void AIGateway::showGarrisonDialog(const CArmedInstance * up, const CGHeroInstan requestActionASAP([=]() { if(removableUnits && up->tempOwner == down->tempOwner) + { pickBestCreatures(down, up); + } answerQuery(queryID, 0); }); From 56061d116eefe9174be3f291d4a41c045afda3c6 Mon Sep 17 00:00:00 2001 From: Maxim Korotkov Date: Tue, 26 Sep 2023 16:11:40 +0300 Subject: [PATCH 2/4] vcai: Combined cases with the same actions --- AI/VCAI/Goals/CollectRes.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/AI/VCAI/Goals/CollectRes.cpp b/AI/VCAI/Goals/CollectRes.cpp index f5ec1d873..27e168fa6 100644 --- a/AI/VCAI/Goals/CollectRes.cpp +++ b/AI/VCAI/Goals/CollectRes.cpp @@ -60,14 +60,11 @@ TGoalVec CollectRes::getAllPossibleSubgoals() return false; } break; - case Obj::WATER_WHEEL: - if (resID != GameResID(EGameResID::GOLD)) - return false; - break; case Obj::MYSTICAL_GARDEN: if ((resID != GameResID(EGameResID::GOLD)) && (resID != GameResID(EGameResID::GEMS))) return false; break; + case Obj::WATER_WHEEL: case Obj::LEAN_TO: case Obj::WAGON: if (resID != GameResID(EGameResID::GOLD)) From 59acf639da870879cfc298680627c8557bb9d9ad Mon Sep 17 00:00:00 2001 From: Maxim Korotkov Date: Tue, 26 Sep 2023 16:39:16 +0300 Subject: [PATCH 3/4] client: render: fixed copy-past errror in genFromJson() Signed-off-by: Maxim Korotkov --- client/render/ColorFilter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/render/ColorFilter.cpp b/client/render/ColorFilter.cpp index 327813f64..3f13db8a2 100644 --- a/client/render/ColorFilter.cpp +++ b/client/render/ColorFilter.cpp @@ -138,7 +138,7 @@ ColorFilter ColorFilter::genFromJson(const JsonNode & entry) r.a = entry["red"].Vector()[3].Float(); } - if (!entry["red"].isNull()) + if (!entry["green"].isNull()) { g.r = entry["green"].Vector()[0].Float(); g.g = entry["green"].Vector()[1].Float(); @@ -146,7 +146,7 @@ ColorFilter ColorFilter::genFromJson(const JsonNode & entry) g.a = entry["green"].Vector()[3].Float(); } - if (!entry["red"].isNull()) + if (!entry["blue"].isNull()) { b.r = entry["blue"].Vector()[0].Float(); b.g = entry["blue"].Vector()[1].Float(); From ade7a035f5367bae5e298ca7e77db819106e3857 Mon Sep 17 00:00:00 2001 From: Maxim Korotkov Date: Tue, 26 Sep 2023 17:04:43 +0300 Subject: [PATCH 4/4] artifactUtils: reduced cyclomatic complexity in check Signed-off-by: Maxim Korotkov --- lib/ArtifactUtils.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/ArtifactUtils.cpp b/lib/ArtifactUtils.cpp index eeb94c2c6..7654a8b29 100644 --- a/lib/ArtifactUtils.cpp +++ b/lib/ArtifactUtils.cpp @@ -87,10 +87,9 @@ DLL_LINKAGE bool ArtifactUtils::checkSpellbookIsNeeded(const CGHeroInstance * he // Titan's Thunder creates new spellbook on equip if(artID == ArtifactID::TITANS_THUNDER && slot == ArtifactPosition::RIGHT_HAND) { - if(heroPtr) + if(heroPtr && !heroPtr->hasSpellbook()) { - if(heroPtr && !heroPtr->hasSpellbook()) - return true; + return true; } } return false;