mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-19 21:10:12 +02:00
Fix possible crash on accessing Cannon Yard from HotA
(cherry picked from commit e273263334ef8900c8fee8e0ae04959ec10b6073)
This commit is contained in:
parent
5847d56fa4
commit
751a334e5a
@ -474,9 +474,17 @@ void CGDwelling::heroAcceptsCreatures( const CGHeroInstance *h) const
|
|||||||
SetAvailableCreatures sac;
|
SetAvailableCreatures sac;
|
||||||
sac.tid = id;
|
sac.tid = id;
|
||||||
sac.creatures = creatures;
|
sac.creatures = creatures;
|
||||||
sac.creatures[0].first = !h->getArt(ArtifactPosition::MACH1); //ballista
|
|
||||||
sac.creatures[1].first = !h->getArt(ArtifactPosition::MACH3); //first aid tent
|
for (auto & entry : sac.creatures)
|
||||||
sac.creatures[2].first = !h->getArt(ArtifactPosition::MACH2); //ammo cart
|
{
|
||||||
|
CreatureID creature = entry.second.at(0);
|
||||||
|
ArtifactID warMachine = creature.toCreature()->warMachine;
|
||||||
|
|
||||||
|
if (h->hasArt(warMachine, true, false))
|
||||||
|
entry.first = 0;
|
||||||
|
else
|
||||||
|
entry.first = 1;
|
||||||
|
}
|
||||||
cb->sendAndApply(sac);
|
cb->sendAndApply(sac);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2397,7 +2397,18 @@ bool CGameHandler::recruitCreatures(ObjectInstanceID objid, ObjectInstanceID dst
|
|||||||
COMPLAIN_RET_FALSE_IF(!hero, "Only hero can buy war machines");
|
COMPLAIN_RET_FALSE_IF(!hero, "Only hero can buy war machines");
|
||||||
COMPLAIN_RET_FALSE_IF(artId == ArtifactID::CATAPULT, "Catapult cannot be recruited!");
|
COMPLAIN_RET_FALSE_IF(artId == ArtifactID::CATAPULT, "Catapult cannot be recruited!");
|
||||||
COMPLAIN_RET_FALSE_IF(nullptr == art, "Invalid war machine artifact");
|
COMPLAIN_RET_FALSE_IF(nullptr == art, "Invalid war machine artifact");
|
||||||
|
COMPLAIN_RET_FALSE_IF(hero->hasArt(artId),"Hero already has this machine!");
|
||||||
|
|
||||||
|
bool hasFreeSlot = false;
|
||||||
|
for(auto slot : art->getPossibleSlots().at(ArtBearer::HERO))
|
||||||
|
if (hero->getArt(slot) == nullptr)
|
||||||
|
hasFreeSlot = true;
|
||||||
|
|
||||||
|
if (!hasFreeSlot)
|
||||||
|
{
|
||||||
|
auto slot = art->getPossibleSlots().at(ArtBearer::HERO).front();
|
||||||
|
removeArtifact(ArtifactLocation(hero->id, slot));
|
||||||
|
}
|
||||||
return giveHeroNewArtifact(hero, artId, ArtifactPosition::FIRST_AVAILABLE);
|
return giveHeroNewArtifact(hero, artId, ArtifactPosition::FIRST_AVAILABLE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user