1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Stacks of armed instance are now unique_ptr

This commit is contained in:
Ivan Savenko
2025-03-17 21:11:06 +00:00
parent bdae7285ae
commit c02a8a84fd
33 changed files with 101 additions and 115 deletions

View File

@@ -1180,7 +1180,7 @@ void AIGateway::recruitCreatures(const CGDwelling * d, const CArmedInstance * re
if(!recruiter->getSlotFor(creID).validSlot())
{
for(auto stack : recruiter->Slots())
for(const auto & stack : recruiter->Slots())
{
if(!stack.second->getType())
continue;

View File

@@ -633,7 +633,7 @@ int getDuplicatingSlots(const CArmedInstance * army)
{
int duplicatingSlots = 0;
for(auto stack : army->Slots())
for(const auto & stack : army->Slots())
{
if(stack.second->getCreature() && army->getSlotFor(stack.second->getCreature()) != stack.first)
duplicatingSlots++;
@@ -708,7 +708,7 @@ bool shouldVisit(const Nullkiller * ai, const CGHeroInstance * h, const CGObject
}
case Obj::HILL_FORT:
{
for(auto slot : h->Slots())
for(const auto & slot : h->Slots())
{
if(slot.second->getType()->hasUpgrades())
return true; //TODO: check price?

View File

@@ -489,7 +489,7 @@ void ArmyManager::update()
for(auto army : total)
{
for(auto slot : army->Slots())
for(const auto & slot : army->Slots())
{
totalArmy[slot.second->getCreatureID()].count += slot.second->count;
}
@@ -506,7 +506,7 @@ std::vector<SlotInfo> ArmyManager::convertToSlots(const CCreatureSet * army) con
{
std::vector<SlotInfo> result;
for(auto slot : army->Slots())
for(const auto & slot : army->Slots())
{
SlotInfo slotInfo;
@@ -524,7 +524,7 @@ std::vector<StackUpgradeInfo> ArmyManager::getHillFortUpgrades(const CCreatureSe
{
std::vector<StackUpgradeInfo> upgrades;
for(auto creature : army->Slots())
for(const auto & creature : army->Slots())
{
CreatureID initial = creature.second->getCreatureID();
auto possibleUpgrades = initial.toCreature()->upgrades;
@@ -552,7 +552,7 @@ std::vector<StackUpgradeInfo> ArmyManager::getDwellingUpgrades(const CCreatureSe
{
std::vector<StackUpgradeInfo> upgrades;
for(auto creature : army->Slots())
for(const auto & creature : army->Slots())
{
CreatureID initial = creature.second->getCreatureID();
auto possibleUpgrades = initial.toCreature()->upgrades;

View File

@@ -61,7 +61,7 @@ armyStructure evaluateArmyStructure(const CArmedInstance * army)
static const CSelector selectorSTACKS_SPEED = Selector::type()(BonusType::STACKS_SPEED);
static const std::string keySTACKS_SPEED = "type_"+std::to_string((int32_t)BonusType::STACKS_SPEED);
for(auto s : army->Slots())
for(const auto & s : army->Slots())
{
bool walker = true;
auto bearer = s.second->getType()->getBonusBearer();

View File

@@ -696,7 +696,7 @@ int32_t getArmyCost(const CArmedInstance * army)
{
int32_t value = 0;
for(auto stack : army->Slots())
for(const auto & stack : army->Slots())
{
value += stack.second->getCreatureID().toCreature()->getFullRecruitCost().marketValue() * stack.second->count;
}
@@ -990,7 +990,7 @@ public:
std::map<int, float> totalPowerByCreatureID;
// Calculate hero power and total power by CreatureID
for (auto slot : hero->Slots())
for (const auto & slot : hero->Slots())
{
int creatureID = slot.second->getCreatureID();
float slotPower = slot.second->getPower();

View File

@@ -62,7 +62,7 @@ void BuyArmy::accept(AIGateway * ai)
{
SlotID lowestValueSlot;
int lowestValue = std::numeric_limits<int>::max();
for (auto slot : town->getUpperArmy()->Slots())
for (const auto & slot : town->getUpperArmy()->Slots())
{
if (slot.second->getCreatureID() != CreatureID::NONE)
{

View File

@@ -25,7 +25,7 @@ void ArmyFormation::addSingleCreatureStacks(const CGHeroInstance * hero)
while(!freeSlots.empty())
{
auto weakestCreature = vstd::minElementByFun(hero->Slots(), [](const std::pair<SlotID, CStackInstance *> & slot) -> int
TSlots::const_iterator weakestCreature = vstd::minElementByFun(hero->Slots(), [](const auto & slot) -> int
{
return slot.second->getCount() == 1
? std::numeric_limits<int>::max()
@@ -50,8 +50,8 @@ void ArmyFormation::rearrangeArmyForSiege(const CGTownInstance * town, const CGH
{
std::vector<CStackInstance *> stacks;
for(auto slot : attacker->Slots())
stacks.push_back(slot.second);
for(const auto & slot : attacker->Slots())
stacks.push_back(slot.second.get());
boost::sort(
stacks,
@@ -67,7 +67,7 @@ void ArmyFormation::rearrangeArmyForSiege(const CGTownInstance * town, const CGH
for(int i = 0; i < stacks.size(); i++)
{
auto pos = vstd::findKey(attacker->Slots(), stacks[i]);
auto pos = stacks[i]->armyObj->findStack(stacks[i]);
if(pos.getNum() != i)
cb->swapCreatures(attacker, attacker, static_cast<SlotID>(i), pos);

View File

@@ -284,7 +284,7 @@ void AINodeStorage::commit(CDestinationNodeInfo & destination, const PathNodeInf
return;
}
auto weakest = vstd::minElementByFun(dstNode->actor->creatureSet->Slots(), [](std::pair<SlotID, const CStackInstance *> pair) -> int
const auto & weakest = vstd::minElementByFun(dstNode->actor->creatureSet->Slots(), [](const auto & pair) -> int
{
return pair.second->getCount() * pair.second->getCreatureID().toCreature()->getAIValue();
});

View File

@@ -358,9 +358,9 @@ HeroExchangeArmy * HeroExchangeMap::tryUpgrade(
}
else
{
for(auto slot : army->Slots())
for(const auto & slot : army->Slots())
{
auto targetSlot = target->getSlotFor(slot.second->getCreatureID());
const auto & targetSlot = target->getSlotFor(slot.second->getCreatureID());
target->addToSlot(targetSlot, slot.second->getCreatureID(), slot.second->count);
}

View File

@@ -60,7 +60,7 @@ armyStructure evaluateArmyStructure(const CArmedInstance * army)
static const CSelector selectorSTACKS_SPEED = Selector::type()(BonusType::STACKS_SPEED);
static const std::string keySTACKS_SPEED = "type_"+std::to_string((int32_t)BonusType::STACKS_SPEED);
for(auto s : army->Slots())
for(const auto & s : army->Slots())
{
bool walker = true;
auto bearer = s.second->getType()->getBonusBearer();

View File

@@ -29,7 +29,7 @@ int GatherTroops::getCreaturesCount(const CArmedInstance * army)
{
int count = 0;
for(auto stack : army->Slots())
for(const auto & stack : army->Slots())
{
if(objid == stack.second->getCreatureID().num)
{

View File

@@ -2851,7 +2851,7 @@ bool shouldVisit(HeroPtr h, const CGObjectInstance * obj)
}
case Obj::HILL_FORT:
{
for(auto slot : h->Slots())
for(const auto & slot : h->Slots())
{
if(slot.second->getType()->hasUpgrades())
return true; //TODO: check price?