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:
parent
31b04780c9
commit
24d25730ad
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user