1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Merge pull request #3841 from vcmi/fix-3754

Fix #3754, #2316
This commit is contained in:
Ivan Savenko 2024-04-27 16:33:38 +03:00 committed by GitHub
commit 90fa1718a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 7 deletions

View File

@ -1056,7 +1056,8 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
if(location.slot == ArtifactPosition::MACH4) // don't attempt to move catapult
continue;
auto s = cb->getHero(location.artHolder)->getSlot(location.slot);
auto artHolder = cb->getHero(location.artHolder);
auto s = artHolder->getSlot(location.slot);
if(!s || s->locked) //we can't move locks
continue;
auto artifact = s->artifact;
@ -1084,10 +1085,27 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
if(otherSlot && otherSlot->artifact) //we need to exchange artifact for better one
{
//if that artifact is better than what we have, pick it
if(compareArtifacts(artifact, otherSlot->artifact) && artifact->canBePutAt(target, slot, true)) //combined artifacts are not always allowed to move
if(compareArtifacts(artifact, otherSlot->artifact)
&& artifact->canBePutAt(target, slot, true)) //combined artifacts are not always allowed to move
{
ArtifactLocation destLocation(target->id, slot);
cb->swapArtifacts(location, ArtifactLocation(target->id, target->getArtPos(otherSlot->artifact)));
logAi->trace(
"Exchange artifacts %s <-> %s",
artifact->artType->getNameTranslated(),
otherSlot->artifact->artType->getNameTranslated());
if(!otherSlot->artifact->canBePutAt(artHolder, location.slot, true))
{
ArtifactLocation destLocation(target->id, slot);
ArtifactLocation backpack(artHolder->id, ArtifactPosition::BACKPACK_START);
cb->swapArtifacts(destLocation, backpack);
cb->swapArtifacts(location, destLocation);
}
else
{
cb->swapArtifacts(location, ArtifactLocation(target->id, target->getArtPos(otherSlot->artifact)));
}
changeMade = true;
break;
}

View File

@ -136,8 +136,9 @@ void ClientCommandManager::handleControlaiCommand(std::istringstream& singleWord
for(auto & elem : CSH->client->gameState()->players)
{
if(elem.second.human ||
(colorName.length() && elem.first.getNum() != vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, colorName)))
if(!elem.first.isValidPlayer()
|| elem.second.human
|| (colorName.length() && elem.first.getNum() != vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, colorName)))
{
continue;
}

View File

@ -47,7 +47,7 @@ void ActiveModsInSaveList::verifyActiveMods(const std::map<TModID, ModVerificati
missingMods.push_back(VLC->modh->getModInfo(compared.first).getVerificationInfo().name);
if (compared.second == ModVerificationStatus::EXCESSIVE)
excessiveMods.push_back(modList.at(compared.first).name);
excessiveMods.push_back(VLC->modh->getModInfo(compared.first).getVerificationInfo().name);
}
if(!missingMods.empty() || !excessiveMods.empty())