浏览代码

Style fixes

Dydzio 6 年之前
父节点
当前提交
aafad18121
共有 2 个文件被更改,包括 9 次插入5 次删除
  1. 8 4
      AI/VCAI/VCAI.cpp
  2. 1 1
      lib/CCreatureSet.cpp

+ 8 - 4
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);
 						}
 					}

+ 1 - 1
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())