1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Simplified code

This commit is contained in:
Ivan Savenko 2024-05-02 17:36:44 +03:00
parent 08ce3a8338
commit 47c3e6f4b6

View File

@ -327,23 +327,15 @@ int CGCreature::takenAction(const CGHeroInstance *h, bool allowJoin) const
else
powerFactor = -3;
std::set<CreatureID> myKindCres; //what creatures are the same kind as we
const CCreature * myCreature = getCreature().toCreature();
myKindCres.insert(myCreature->getId()); //we
myKindCres.insert(myCreature->upgrades.begin(), myCreature->upgrades.end()); //our upgrades
for(const auto & crea : VLC->creh->objects)
{
if(vstd::contains(crea->upgrades, myCreature->getId())) //it's our base creatures
myKindCres.insert(crea->getId());
}
int count = 0; //how many creatures of similar kind has hero
int totalCount = 0;
for(const auto & elem : h->Slots())
{
if(vstd::contains(myKindCres,elem.second->type->getId()))
bool isOurUpgrade = vstd::contains(getCreature().toCreature()->upgrades, elem.second->getCreatureID());
bool isOurDowngrade = vstd::contains(elem.second->type->upgrades, getCreature());
if(isOurUpgrade || isOurDowngrade)
count += elem.second->count;
totalCount += elem.second->count;
}
@ -368,7 +360,7 @@ int CGCreature::takenAction(const CGHeroInstance *h, bool allowJoin) const
if(diplomacy * 2 + sympathy + 1 >= character)
{
int32_t recruitCost = VLC->creatures()->getById(getCreature())->getRecruitCost(EGameResID::GOLD);
uint32_t stackCount = getStackCount(SlotID(0));
int32_t stackCount = getStackCount(SlotID(0));
return recruitCost * stackCount; //join for gold
}
}