1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Style fixes

This commit is contained in:
Dydzio
2019-02-12 19:47:19 +01:00
parent 18e139d9e3
commit aafad18121
2 changed files with 9 additions and 5 deletions

View File

@@ -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->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 if(!(armyPtr->needsLastStack() && armyPtr->stacksCount() == 1)) //can't take away last creature without split
{
cb->mergeOrSwapStacks(armyPtr, destinationArmy, SlotID(j), SlotID(i)); cb->mergeOrSwapStacks(armyPtr, destinationArmy, SlotID(j), SlotID(i));
}
else else
{ {
//TODO: Improve logic by splitting weakest creature, instead of creature that becomes last stack //TODO: Improve logic by splitting weakest creature, instead of creature that becomes last stack
SlotID sourceSlot = SlotID(j); 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 if(lastStackCount > 1) //we can perform exchange if we need creature and split is possible
{ {
SlotID destinationSlot = SlotID(i); 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); destinationSlot = SlotID(candidateSlot);
break; 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 //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); cb->splitStack(armyPtr, destinationArmy, sourceSlot, destinationSlot, lastStackCount + destinationSlotCreatureCount - 1);
} }
} }

View File

@@ -93,7 +93,7 @@ SlotID CCreatureSet::getFreeSlot(ui32 slotsAmount) const
return SlotID(); //no slot available return SlotID(); //no slot available
} }
int CCreatureSet::getStackCount(SlotID slot) const TQuantity CCreatureSet::getStackCount(SlotID slot) const
{ {
auto i = stacks.find(slot); auto i = stacks.find(slot);
if (i != stacks.end()) if (i != stacks.end())