From aafad18121dc0b257b9645cad2a4dc03b2cc670a Mon Sep 17 00:00:00 2001 From: Dydzio Date: Tue, 12 Feb 2019 19:47:19 +0100 Subject: [PATCH] Style fixes --- AI/VCAI/VCAI.cpp | 12 ++++++++---- lib/CCreatureSet.cpp | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index d47a53d47..5bf3b8fd4 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -1147,26 +1147,30 @@ void VCAI::pickBestCreatures(const CArmedInstance * destinationArmy, const CArme if(armyPtr->getCreature(SlotID(j)) == bestArmy[i] && (i != j || armyPtr != destinationArmy)) //it's a searched creature not in dst SLOT { if(!(armyPtr->needsLastStack() && armyPtr->stacksCount() == 1)) //can't take away last creature without split + { cb->mergeOrSwapStacks(armyPtr, destinationArmy, SlotID(j), SlotID(i)); + } else { //TODO: Improve logic by splitting weakest creature, instead of creature that becomes last stack SlotID sourceSlot = SlotID(j); - int lastStackCount = armyPtr->getStackCount(sourceSlot); + auto lastStackCount = armyPtr->getStackCount(sourceSlot); if(lastStackCount > 1) //we can perform exchange if we need creature and split is possible { SlotID destinationSlot = SlotID(i); - for(int candidateSlot = 0; candidateSlot < GameConstants::ARMY_SIZE; candidateSlot++) //check if there are some creatures of same type in destination army slots - add to them instead of first available empty slot + //check if there are some creatures of same type in destination army slots - add to them instead of first available empty slot if possible + for(int candidateSlot = 0; candidateSlot < GameConstants::ARMY_SIZE; candidateSlot++) { - if(destinationArmy->getCreature(SlotID(candidateSlot)) && (destinationArmy->getCreature(SlotID(candidateSlot))->idNumber == armyPtr->getCreature(SlotID(j))->idNumber)) + auto creatureInSlot = destinationArmy->getCreature(SlotID(candidateSlot)); + if(creatureInSlot && (creatureInSlot->idNumber == armyPtr->getCreature(SlotID(j))->idNumber)) { destinationSlot = SlotID(candidateSlot); break; } } //last cb->splitStack argument is total amount of creatures expected after exchange so if slot is not empty we need to add to existing creatures - int destinationSlotCreatureCount = destinationArmy->getStackCount(destinationSlot); + auto destinationSlotCreatureCount = destinationArmy->getStackCount(destinationSlot); cb->splitStack(armyPtr, destinationArmy, sourceSlot, destinationSlot, lastStackCount + destinationSlotCreatureCount - 1); } } diff --git a/lib/CCreatureSet.cpp b/lib/CCreatureSet.cpp index ab79edc04..d1450d571 100644 --- a/lib/CCreatureSet.cpp +++ b/lib/CCreatureSet.cpp @@ -93,7 +93,7 @@ SlotID CCreatureSet::getFreeSlot(ui32 slotsAmount) const return SlotID(); //no slot available } -int CCreatureSet::getStackCount(SlotID slot) const +TQuantity CCreatureSet::getStackCount(SlotID slot) const { auto i = stacks.find(slot); if (i != stacks.end())