mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Refactoring: use cleaner CCreatureSet::stacksCount everywhere
This commit is contained in:
parent
62bab27e7e
commit
6f5c52a229
@ -945,7 +945,7 @@ bool VCAI::canGetArmy (const CGHeroInstance * army, const CGHeroInstance * sourc
|
||||
if(armyPtr->getCreature(SlotID(j)) == bestArmy[i] && armyPtr != army) //it's a searched creature not in dst ARMY
|
||||
{
|
||||
//FIXME: line below is useless when simulating exchange between two non-singular armies
|
||||
if (!(armyPtr->needsLastStack() && armyPtr->Slots().size() == 1)) //can't take away last creature
|
||||
if(!(armyPtr->needsLastStack() && armyPtr->stacksCount() == 1)) //can't take away last creature
|
||||
return true; //at least one exchange will be performed
|
||||
else
|
||||
return false; //no further exchange possible
|
||||
@ -992,7 +992,7 @@ void VCAI::pickBestCreatures(const CArmedInstance * army, const CArmedInstance *
|
||||
for (int j = 0; j < GameConstants::ARMY_SIZE; j++)
|
||||
{
|
||||
if(armyPtr->getCreature(SlotID(j)) == bestArmy[i] && (i != j || armyPtr != army)) //it's a searched creature not in dst SLOT
|
||||
if (!(armyPtr->needsLastStack() && armyPtr->Slots().size() == 1)) //can't take away last creature
|
||||
if(!(armyPtr->needsLastStack() && armyPtr->stacksCount() == 1)) //can't take away last creature
|
||||
cb->mergeOrSwapStacks(armyPtr, army, SlotID(j), SlotID(i));
|
||||
}
|
||||
}
|
||||
|
@ -861,7 +861,7 @@ void CMarketplaceWindow::selectionChanged(bool side)
|
||||
if(itemsType[1] == RESOURCE)
|
||||
newAmount = LOCPLINT->cb->getResourceAmount(static_cast<Res::ERes>(soldItemId));
|
||||
else if(itemsType[1] == CREATURE)
|
||||
newAmount = hero->getStackCount(SlotID(hLeft->serial)) - (hero->Slots().size() == 1 && hero->needsLastStack());
|
||||
newAmount = hero->getStackCount(SlotID(hLeft->serial)) - (hero->stacksCount() == 1 && hero->needsLastStack());
|
||||
else
|
||||
assert(0);
|
||||
|
||||
|
@ -292,9 +292,9 @@ void CBank::doVisit(const CGHeroInstance * hero) const
|
||||
loot.addReplacement(*elem.second);
|
||||
}
|
||||
|
||||
if (ourArmy.Slots().size())
|
||||
if(ourArmy.stacksCount())
|
||||
{
|
||||
if (ourArmy.Slots().size() == 1 && ourArmy.Slots().begin()->second->count == 1)
|
||||
if(ourArmy.stacksCount() == 1 && ourArmy.Slots().begin()->second->count == 1)
|
||||
iw.text.addTxt (MetaString::ADVOB_TXT, 185);
|
||||
else
|
||||
iw.text.addTxt (MetaString::ADVOB_TXT, 186);
|
||||
|
@ -43,7 +43,7 @@ static void showInfoDialog(const CGHeroInstance* h, const ui32 txtID, const ui16
|
||||
|
||||
static int lowestSpeed(const CGHeroInstance * chi)
|
||||
{
|
||||
if(!chi->Slots().size())
|
||||
if(!chi->stacksCount())
|
||||
{
|
||||
logGlobal->errorStream() << "Error! Hero " << chi->id.getNum() << " ("<<chi->name<<") has no army!";
|
||||
return 20;
|
||||
|
@ -235,7 +235,7 @@ void CGPandoraBox::giveContentsAfterExp(const CGHeroInstance *h) const
|
||||
iw.components.clear();
|
||||
iw.text.clear();
|
||||
|
||||
if (creatures.Slots().size())
|
||||
if(creatures.stacksCount())
|
||||
{ //this part is taken straight from creature bank
|
||||
MetaString loot;
|
||||
for(auto & elem : creatures.Slots())
|
||||
@ -245,7 +245,7 @@ void CGPandoraBox::giveContentsAfterExp(const CGHeroInstance *h) const
|
||||
loot.addReplacement(*elem.second);
|
||||
}
|
||||
|
||||
if (creatures.Slots().size() == 1 && creatures.Slots().begin()->second->count == 1)
|
||||
if(creatures.stacksCount() == 1 && creatures.Slots().begin()->second->count == 1)
|
||||
iw.text.addTxt(MetaString::ADVOB_TXT, 185);
|
||||
else
|
||||
iw.text.addTxt(MetaString::ADVOB_TXT, 186);
|
||||
@ -303,17 +303,17 @@ void CGPandoraBox::battleFinished(const CGHeroInstance *hero, const BattleResult
|
||||
|
||||
void CGPandoraBox::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
|
||||
{
|
||||
if (answer)
|
||||
if(answer)
|
||||
{
|
||||
if (stacksCount() > 0) //if pandora's box is protected by army
|
||||
if(stacksCount() > 0) //if pandora's box is protected by army
|
||||
{
|
||||
showInfoDialog(hero,16,0);
|
||||
cb->startBattleI(hero, this); //grants things after battle
|
||||
}
|
||||
else if (message.size() == 0 && resources.size() == 0
|
||||
else if(message.size() == 0 && resources.size() == 0
|
||||
&& primskills.size() == 0 && abilities.size() == 0
|
||||
&& abilityLevels.size() == 0 && artifacts.size() == 0
|
||||
&& spells.size() == 0 && creatures.Slots().size() > 0
|
||||
&& abilityLevels.size() == 0 && artifacts.size() == 0
|
||||
&& spells.size() == 0 && creatures.stacksCount() > 0
|
||||
&& gainedExp == 0 && manaDiff == 0 && moraleDiff == 0 && luckDiff == 0) //if it gives nothing without battle
|
||||
{
|
||||
showInfoDialog(hero,15,0);
|
||||
|
@ -1126,10 +1126,10 @@ void CGWhirlpool::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer
|
||||
cb->moveHero(hero->id, dPos, true);
|
||||
}
|
||||
|
||||
bool CGWhirlpool::isProtected( const CGHeroInstance * h )
|
||||
bool CGWhirlpool::isProtected(const CGHeroInstance * h)
|
||||
{
|
||||
if(h->hasBonusOfType(Bonus::WHIRLPOOL_PROTECTION)
|
||||
|| (h->Slots().size() == 1 && h->Slots().begin()->second->count == 1)) //we can't remove last unit
|
||||
if(h->hasBonusOfType(Bonus::WHIRLPOOL_PROTECTION) ||
|
||||
(h->stacksCount() == 1 && h->Slots().begin()->second->count == 1)) //we can't remove last unit
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -3223,8 +3223,8 @@ bool CGameHandler::sellCreatures(ui32 count, const IMarket *market, const CGHero
|
||||
|
||||
const CStackInstance &s = hero->getStack(slot);
|
||||
|
||||
if( s.count < count //can't sell more creatures than have
|
||||
|| (hero->Slots().size() == 1 && hero->needsLastStack() && s.count == count)) //can't sell last stack
|
||||
if( s.count < count //can't sell more creatures than have
|
||||
|| (hero->stacksCount() == 1 && hero->needsLastStack() && s.count == count)) //can't sell last stack
|
||||
{
|
||||
COMPLAIN_RET("Not enough creatures in army!");
|
||||
}
|
||||
@ -5103,7 +5103,7 @@ bool CGameHandler::sacrificeCreatures(const IMarket *market, const CGHeroInstanc
|
||||
|
||||
if(oldCount < count)
|
||||
COMPLAIN_RET("Not enough creatures to sacrifice!")
|
||||
else if(oldCount == count && hero->Slots().size() == 1 && hero->needsLastStack())
|
||||
else if(oldCount == count && hero->stacksCount() == 1 && hero->needsLastStack())
|
||||
COMPLAIN_RET("Cannot sacrifice last creature!");
|
||||
|
||||
int crid = hero->getStack(slot).type->idNumber;
|
||||
@ -5167,7 +5167,7 @@ bool CGameHandler::eraseStack(const StackLocation &sl, bool forceRemoval/* = fal
|
||||
if(!sl.army->hasStackAtSlot(sl.slot))
|
||||
COMPLAIN_RET("Cannot find a stack to erase");
|
||||
|
||||
if(sl.army->Slots().size() == 1 //from the last stack
|
||||
if(sl.army->stacksCount() == 1 //from the last stack
|
||||
&& sl.army->needsLastStack() //that must be left
|
||||
&& !forceRemoval) //ignore above conditions if we are forcing removal
|
||||
{
|
||||
@ -5270,7 +5270,7 @@ bool CGameHandler::moveStack(const StackLocation &src, const StackLocation &dst,
|
||||
|
||||
if(src.army != dst.army //moving away
|
||||
&& count == src.army->getStackCount(src.slot) //all creatures
|
||||
&& src.army->Slots().size() == 1 //from the last stack
|
||||
&& src.army->stacksCount() == 1 //from the last stack
|
||||
&& src.army->needsLastStack()) //that must be left
|
||||
{
|
||||
COMPLAIN_RET("Cannot move away the last creature!");
|
||||
|
Loading…
Reference in New Issue
Block a user