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

vcmi: use std::variant

This commit is contained in:
Konstantin
2023-04-15 04:33:00 +03:00
parent 8dcb041917
commit 0d35606a44
12 changed files with 131 additions and 119 deletions

View File

@@ -662,7 +662,7 @@ void CGameHandler::endBattleConfirm(const BattleInfo * battleInfo)
if (finishingBattle->loserHero)
{
//TODO: wrap it into a function, somehow (boost::variant -_-)
//TODO: wrap it into a function, somehow (std::variant -_-)
auto artifactsWorn = finishingBattle->loserHero->artifactsWorn;
for (auto artSlot : artifactsWorn)
{
@@ -3930,11 +3930,11 @@ bool CGameHandler::moveArtifact(const ArtifactLocation &al1, const ArtifactLocat
try
{
auto hero = boost::get<ConstTransitivePtr<CGHeroInstance>>(dst.artHolder);
auto hero = std::get<ConstTransitivePtr<CGHeroInstance>>(dst.artHolder);
if(ArtifactUtils::checkSpellbookIsNeeded(hero, srcArtifact->artType->getId(), dst.slot))
giveHeroNewArtifact(hero, VLC->arth->objects[ArtifactID::SPELLBOOK], ArtifactPosition::SPELLBOOK);
}
catch(const boost::bad_get &)
catch(const std::bad_variant_access &)
{
// object other than hero received an art - ignore
}

View File

@@ -360,11 +360,11 @@ bool CGarrisonDialogQuery::blocksPack(const CPack * pack) const
if(auto arts = dynamic_ptr_cast<ExchangeArtifacts>(pack))
{
if(auto id1 = boost::apply_visitor(GetEngagedHeroIds(), arts->src.artHolder))
if(auto id1 = std::visit(GetEngagedHeroIds(), arts->src.artHolder))
if(!vstd::contains(ourIds, *id1))
return true;
if(auto id2 = boost::apply_visitor(GetEngagedHeroIds(), arts->dst.artHolder))
if(auto id2 = std::visit(GetEngagedHeroIds(), arts->dst.artHolder))
if(!vstd::contains(ourIds, *id2))
return true;
return false;
@@ -377,7 +377,7 @@ bool CGarrisonDialogQuery::blocksPack(const CPack * pack) const
if(auto art = dynamic_ptr_cast<EraseArtifactByClient>(pack))
{
if (auto id = boost::apply_visitor(GetEngagedHeroIds(), art->al.artHolder))
if (auto id = std::visit(GetEngagedHeroIds(), art->al.artHolder))
return !vstd::contains(ourIds, *id);
}