mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-29 21:56:54 +02:00
Fixed transferring of artifacts from backpack in campaigns
This commit is contained in:
parent
e484066772
commit
8a81b3013f
@ -118,28 +118,35 @@ void CGameStateCampaign::trimCrossoverHeroesParameters(std::vector<CampaignHeroR
|
|||||||
//trimming artifacts
|
//trimming artifacts
|
||||||
for(CGHeroInstance * hero : crossoverHeroes)
|
for(CGHeroInstance * hero : crossoverHeroes)
|
||||||
{
|
{
|
||||||
size_t totalArts = GameConstants::BACKPACK_START + hero->artifactsInBackpack.size();
|
auto const & checkAndRemoveArtifact = [&](const ArtifactPosition & artifactPosition )
|
||||||
for (size_t i = 0; i < totalArts; i++ )
|
|
||||||
{
|
{
|
||||||
auto artifactPosition = ArtifactPosition((si32)i);
|
|
||||||
if(artifactPosition == ArtifactPosition::SPELLBOOK)
|
if(artifactPosition == ArtifactPosition::SPELLBOOK)
|
||||||
continue; // do not handle spellbook this way
|
return; // do not handle spellbook this way
|
||||||
|
|
||||||
const ArtSlotInfo *info = hero->getSlot(artifactPosition);
|
const ArtSlotInfo *info = hero->getSlot(artifactPosition);
|
||||||
if(!info)
|
if(!info)
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
// TODO: why would there be nullptr artifacts?
|
// TODO: why would there be nullptr artifacts?
|
||||||
const CArtifactInstance *art = info->artifact;
|
const CArtifactInstance *art = info->artifact;
|
||||||
if(!art)
|
if(!art)
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
bool takeable = travelOptions.artifactsKeptByHero.count(art->artType->getId());
|
bool takeable = travelOptions.artifactsKeptByHero.count(art->artType->getId());
|
||||||
|
|
||||||
ArtifactLocation al(hero, artifactPosition);
|
ArtifactLocation al(hero, artifactPosition);
|
||||||
if(!takeable && !al.getSlot()->locked) //don't try removing locked artifacts -> it crashes #1719
|
if(!takeable && !al.getSlot()->locked) //don't try removing locked artifacts -> it crashes #1719
|
||||||
al.removeArtifact();
|
al.removeArtifact();
|
||||||
}
|
};
|
||||||
|
|
||||||
|
// process on copy - removal of artifact will invalidate container
|
||||||
|
auto artifactsWorn = hero->artifactsWorn;
|
||||||
|
for (auto const & art : artifactsWorn)
|
||||||
|
checkAndRemoveArtifact(art.first);
|
||||||
|
|
||||||
|
// process in reverse - removal of artifact will shift all artifacts after this one
|
||||||
|
for(int slotNumber = hero->artifactsInBackpack.size() - 1; slotNumber >= 0; slotNumber--)
|
||||||
|
checkAndRemoveArtifact(ArtifactPosition(GameConstants::BACKPACK_START + slotNumber));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user