mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
Changed checks for null with checks for hasValue
This commit is contained in:
@@ -750,7 +750,7 @@ void BattleActionsController::actionRealize(PossiblePlayerBattleAction action, B
|
|||||||
|
|
||||||
if (!spellcastingModeActive())
|
if (!spellcastingModeActive())
|
||||||
{
|
{
|
||||||
if (action.spell().toSpell())
|
if (action.spell().hasValue())
|
||||||
{
|
{
|
||||||
owner.giveCommand(EActionType::MONSTER_SPELL, targetHex, action.spell());
|
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
|
// faerie dragon can cast only one, randomly selected spell until their next move
|
||||||
//TODO: faerie dragon type spell should be selected by server
|
//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)
|
if (spellToCast.hasValue())
|
||||||
creatureSpells.push_back(spellToCast);
|
creatureSpells.push_back(spellToCast.toSpell());
|
||||||
}
|
}
|
||||||
|
|
||||||
TConstBonusListPtr bl = casterStack->getBonuses(Selector::type()(BonusType::SPELLCASTER));
|
TConstBonusListPtr bl = casterStack->getBonuses(Selector::type()(BonusType::SPELLCASTER));
|
||||||
|
|
||||||
for(const auto & bonus : *bl)
|
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());
|
creatureSpells.push_back(bonus->subtype.as<SpellID>().toSpell());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -352,13 +352,13 @@ void BattleInterface::spellCast(const BattleSpellCast * sc)
|
|||||||
CCS->curh->set(Cursor::Combat::BLOCKED);
|
CCS->curh->set(Cursor::Combat::BLOCKED);
|
||||||
|
|
||||||
const SpellID spellID = sc->spellID;
|
const SpellID spellID = sc->spellID;
|
||||||
|
|
||||||
|
if(!spellID.hasValue())
|
||||||
|
return;
|
||||||
|
|
||||||
const CSpell * spell = spellID.toSpell();
|
const CSpell * spell = spellID.toSpell();
|
||||||
auto targetedTile = sc->tile;
|
auto targetedTile = sc->tile;
|
||||||
|
|
||||||
assert(spell);
|
|
||||||
if(!spell)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const AudioPath & castSoundPath = spell->getCastSound();
|
const AudioPath & castSoundPath = spell->getCastSound();
|
||||||
|
|
||||||
if (!castSoundPath.empty())
|
if (!castSoundPath.empty())
|
||||||
|
|||||||
@@ -867,9 +867,10 @@ bool CBattleInfoCallback::handleObstacleTriggersForUnit(SpellCastEnvironment & s
|
|||||||
auto shouldReveal = !spellObstacle->hidden || !battleIsObstacleVisibleForSide(*obstacle, (BattlePerspective::BattlePerspective)side);
|
auto shouldReveal = !spellObstacle->hidden || !battleIsObstacleVisibleForSide(*obstacle, (BattlePerspective::BattlePerspective)side);
|
||||||
const auto * hero = battleGetFightingHero(spellObstacle->casterSide);
|
const auto * hero = battleGetFightingHero(spellObstacle->casterSide);
|
||||||
auto caster = spells::ObstacleCasterProxy(getBattle()->getSidePlayer(spellObstacle->casterSide), hero, *spellObstacle);
|
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);
|
auto cast = spells::BattleCast(this, &caster, spells::Mode::PASSIVE, sp);
|
||||||
spells::detail::ProblemImpl ignored;
|
spells::detail::ProblemImpl ignored;
|
||||||
auto target = spells::Target(1, spells::Destination(&unit));
|
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)
|
void CGameHandler::castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos)
|
||||||
{
|
{
|
||||||
const CSpell * s = spellID.toSpell();
|
if (!spellID.hasValue())
|
||||||
if(!s)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AdventureSpellCastParameters p;
|
AdventureSpellCastParameters p;
|
||||||
p.caster = caster;
|
p.caster = caster;
|
||||||
p.pos = pos;
|
p.pos = pos;
|
||||||
|
|
||||||
|
const CSpell * s = spellID.toSpell();
|
||||||
s->adventureCast(spellEnv, p);
|
s->adventureCast(spellEnv, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -327,9 +327,9 @@ void ApplyGhNetPackVisitor::visitCastAdvSpell(CastAdvSpell & pack)
|
|||||||
{
|
{
|
||||||
gh.throwIfWrongOwner(&pack, pack.hid);
|
gh.throwIfWrongOwner(&pack, pack.hid);
|
||||||
|
|
||||||
const CSpell * s = pack.sid.toSpell();
|
if (!pack.sid.hasValue())
|
||||||
if(!s)
|
|
||||||
gh.throwNotAllowedAction(&pack);
|
gh.throwNotAllowedAction(&pack);
|
||||||
|
|
||||||
const CGHeroInstance * h = gh.getHero(pack.hid);
|
const CGHeroInstance * h = gh.getHero(pack.hid);
|
||||||
if(!h)
|
if(!h)
|
||||||
gh.throwNotAllowedAction(&pack);
|
gh.throwNotAllowedAction(&pack);
|
||||||
@@ -338,6 +338,7 @@ void ApplyGhNetPackVisitor::visitCastAdvSpell(CastAdvSpell & pack)
|
|||||||
p.caster = h;
|
p.caster = h;
|
||||||
p.pos = pack.pos;
|
p.pos = pack.pos;
|
||||||
|
|
||||||
|
const CSpell * s = pack.sid.toSpell();
|
||||||
result = s->adventureCast(gh.spellEnv, p);
|
result = s->adventureCast(gh.spellEnv, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,13 +102,13 @@ bool BattleActionProcessor::doHeroSpellAction(const CBattleInfoCallback & battle
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CSpell * s = ba.spell.toSpell();
|
if (!ba.spell.hasValue())
|
||||||
if (!s)
|
|
||||||
{
|
{
|
||||||
logGlobal->error("Wrong spell id (%d)!", ba.spell.getNum());
|
logGlobal->error("Wrong spell id (%d)!", ba.spell.getNum());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CSpell * s = ba.spell.toSpell();
|
||||||
spells::BattleCast parameters(&battle, h, spells::Mode::HERO, s);
|
spells::BattleCast parameters(&battle, h, spells::Mode::HERO, s);
|
||||||
|
|
||||||
spells::detail::ProblemImpl problem;
|
spells::detail::ProblemImpl problem;
|
||||||
|
|||||||
Reference in New Issue
Block a user