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

Changed checks for null with checks for hasValue

This commit is contained in:
Ivan Savenko 2024-01-20 16:41:10 +02:00
parent 31b04780c9
commit 24d25730ad
6 changed files with 19 additions and 17 deletions

View File

@ -750,7 +750,7 @@ void BattleActionsController::actionRealize(PossiblePlayerBattleAction action, B
if (!spellcastingModeActive())
{
if (action.spell().toSpell())
if (action.spell().hasValue())
{
owner.giveCommand(EActionType::MONSTER_SPELL, targetHex, action.spell());
}
@ -887,17 +887,17 @@ void BattleActionsController::tryActivateStackSpellcasting(const CStack *casterS
{
// faerie dragon can cast only one, randomly selected spell until their next move
//TODO: faerie dragon type spell should be selected by server
const auto * spellToCast = owner.getBattle()->getRandomCastedSpell(CRandomGenerator::getDefault(), casterStack).toSpell();
const auto spellToCast = owner.getBattle()->getRandomCastedSpell(CRandomGenerator::getDefault(), casterStack);
if (spellToCast)
creatureSpells.push_back(spellToCast);
if (spellToCast.hasValue())
creatureSpells.push_back(spellToCast.toSpell());
}
TConstBonusListPtr bl = casterStack->getBonuses(Selector::type()(BonusType::SPELLCASTER));
for(const auto & bonus : *bl)
{
if (bonus->additionalInfo[0] <= 0)
if (bonus->additionalInfo[0] <= 0 && bonus->subtype.as<SpellID>().hasValue())
creatureSpells.push_back(bonus->subtype.as<SpellID>().toSpell());
}
}

View File

@ -352,13 +352,13 @@ void BattleInterface::spellCast(const BattleSpellCast * sc)
CCS->curh->set(Cursor::Combat::BLOCKED);
const SpellID spellID = sc->spellID;
if(!spellID.hasValue())
return;
const CSpell * spell = spellID.toSpell();
auto targetedTile = sc->tile;
assert(spell);
if(!spell)
return;
const AudioPath & castSoundPath = spell->getCastSound();
if (!castSoundPath.empty())

View File

@ -867,9 +867,10 @@ bool CBattleInfoCallback::handleObstacleTriggersForUnit(SpellCastEnvironment & s
auto shouldReveal = !spellObstacle->hidden || !battleIsObstacleVisibleForSide(*obstacle, (BattlePerspective::BattlePerspective)side);
const auto * hero = battleGetFightingHero(spellObstacle->casterSide);
auto caster = spells::ObstacleCasterProxy(getBattle()->getSidePlayer(spellObstacle->casterSide), hero, *spellObstacle);
const auto * sp = obstacle->getTrigger().toSpell();
if(obstacle->triggersEffects() && sp)
if(obstacle->triggersEffects() && obstacle->getTrigger().hasValue())
{
const auto * sp = obstacle->getTrigger().toSpell();
auto cast = spells::BattleCast(this, &caster, spells::Mode::PASSIVE, sp);
spells::detail::ProblemImpl ignored;
auto target = spells::Target(1, spells::Destination(&unit));

View File

@ -3955,14 +3955,14 @@ bool CGameHandler::moveStack(const StackLocation &src, const StackLocation &dst,
void CGameHandler::castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos)
{
const CSpell * s = spellID.toSpell();
if(!s)
if (!spellID.hasValue())
return;
AdventureSpellCastParameters p;
p.caster = caster;
p.pos = pos;
const CSpell * s = spellID.toSpell();
s->adventureCast(spellEnv, p);
}

View File

@ -327,9 +327,9 @@ void ApplyGhNetPackVisitor::visitCastAdvSpell(CastAdvSpell & pack)
{
gh.throwIfWrongOwner(&pack, pack.hid);
const CSpell * s = pack.sid.toSpell();
if(!s)
if (!pack.sid.hasValue())
gh.throwNotAllowedAction(&pack);
const CGHeroInstance * h = gh.getHero(pack.hid);
if(!h)
gh.throwNotAllowedAction(&pack);
@ -338,6 +338,7 @@ void ApplyGhNetPackVisitor::visitCastAdvSpell(CastAdvSpell & pack)
p.caster = h;
p.pos = pack.pos;
const CSpell * s = pack.sid.toSpell();
result = s->adventureCast(gh.spellEnv, p);
}

View File

@ -102,13 +102,13 @@ bool BattleActionProcessor::doHeroSpellAction(const CBattleInfoCallback & battle
return false;
}
const CSpell * s = ba.spell.toSpell();
if (!s)
if (!ba.spell.hasValue())
{
logGlobal->error("Wrong spell id (%d)!", ba.spell.getNum());
return false;
}
const CSpell * s = ba.spell.toSpell();
spells::BattleCast parameters(&battle, h, spells::Mode::HERO, s);
spells::detail::ProblemImpl problem;