1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Allow replacing war machine if hero has a different machine in the slot

This commit is contained in:
Ivan Savenko
2024-08-23 15:42:23 +00:00
parent 8ef8ffa5c4
commit a1a194d904
2 changed files with 12 additions and 1 deletions

View File

@@ -841,7 +841,7 @@ void CCastleBuildings::enterBlacksmith(BuildingID building, ArtifactID artifactI
{ {
for(auto slot : art->getPossibleSlots().at(ArtBearer::HERO)) for(auto slot : art->getPossibleSlots().at(ArtBearer::HERO))
{ {
if(hero->getArt(slot) == nullptr) if(hero->getArt(slot) == nullptr || hero->getArt(slot)->getTypeId() != artifactID)
{ {
possible = true; possible = true;
break; break;

View File

@@ -2800,6 +2800,17 @@ bool CGameHandler::buyArtifact(ObjectInstanceID hid, ArtifactID aid)
if(town->isWarMachineAvailable(aid)) if(town->isWarMachineAvailable(aid))
{ {
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));
}
giveResource(hero->getOwner(),EGameResID::GOLD,-price); giveResource(hero->getOwner(),EGameResID::GOLD,-price);
return giveHeroNewArtifact(hero, art); return giveHeroNewArtifact(hero, art);
} }