From 08ce3a8338ee6294757e270a02ed5276d8ee6f26 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Thu, 2 May 2024 17:32:38 +0300 Subject: [PATCH] Clarified code --- lib/mapObjects/CGCreature.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/mapObjects/CGCreature.cpp b/lib/mapObjects/CGCreature.cpp index a7e7e5115..bb45f8c98 100644 --- a/lib/mapObjects/CGCreature.cpp +++ b/lib/mapObjects/CGCreature.cpp @@ -332,7 +332,7 @@ int CGCreature::takenAction(const CGHeroInstance *h, bool allowJoin) const myKindCres.insert(myCreature->getId()); //we myKindCres.insert(myCreature->upgrades.begin(), myCreature->upgrades.end()); //our upgrades - for(auto const & crea : VLC->creh->objects) + for(const auto & crea : VLC->creh->objects) { if(vstd::contains(crea->upgrades, myCreature->getId())) //it's our base creatures myKindCres.insert(crea->getId()); @@ -365,8 +365,12 @@ int CGCreature::takenAction(const CGHeroInstance *h, bool allowJoin) const if(diplomacy + sympathy + 1 >= character) return JOIN_FOR_FREE; - else if(diplomacy * 2 + sympathy + 1 >= character) - return VLC->creatures()->getById(getCreature())->getRecruitCost(EGameResID::GOLD) * getStackCount(SlotID(0)); //join for gold + if(diplomacy * 2 + sympathy + 1 >= character) + { + int32_t recruitCost = VLC->creatures()->getById(getCreature())->getRecruitCost(EGameResID::GOLD); + uint32_t stackCount = getStackCount(SlotID(0)); + return recruitCost * stackCount; //join for gold + } } //we are still here - creatures have not joined hero, flee or fight @@ -598,7 +602,7 @@ void CGCreature::giveReward(const CGHeroInstance * h) const if(!resources.empty()) { cb->giveResources(h->tempOwner, resources); - for(auto const & res : GameResID::ALL_RESOURCES()) + for(const auto & res : GameResID::ALL_RESOURCES()) { if(resources[res] > 0) iw.components.emplace_back(ComponentType::RESOURCE, res, resources[res]);