Implement RemoveSpellEffects instruction

This commit is contained in:
scrawl 2014-01-03 04:56:54 +01:00
parent 366801f3d5
commit 7d8ca91286
6 changed files with 37 additions and 2 deletions

View file

@ -150,6 +150,12 @@ namespace MWMechanics
mSpellsChanged = true; mSpellsChanged = true;
} }
void ActiveSpells::removeEffects(const std::string &id)
{
mSpells.erase(Misc::StringUtils::lowerCase(id));
mSpellsChanged = true;
}
void ActiveSpells::visitEffectSources(EffectSourceVisitor &visitor) const void ActiveSpells::visitEffectSources(EffectSourceVisitor &visitor) const
{ {
for (TContainer::const_iterator it = begin(); it != end(); ++it) for (TContainer::const_iterator it = begin(); it != end(); ++it)

View file

@ -81,7 +81,10 @@ namespace MWMechanics
void addSpell (const std::string& id, bool stack, std::vector<Effect> effects, void addSpell (const std::string& id, bool stack, std::vector<Effect> effects,
const std::string& displayName, const std::string& casterHandle); const std::string& displayName, const std::string& casterHandle);
/// Remove all active effects with this id /// Removes the active effects from this spell/potion/.. with \a id
void removeEffects (const std::string& id);
/// Remove all active effects with this effect id
void purgeEffect (short effectId); void purgeEffect (short effectId);
/// Remove all active effects, if roll succeeds (for each effect) /// Remove all active effects, if roll succeeds (for each effect)

View file

@ -362,4 +362,6 @@ op 0x2000227: Cast
op 0x2000228: Cast, explicit op 0x2000228: Cast, explicit
op 0x2000229: ExplodeSpell op 0x2000229: ExplodeSpell
op 0x200022a: ExplodeSpell, explicit op 0x200022a: ExplodeSpell, explicit
opcodes 0x200022b-0x3ffffff unused op 0x200022b: RemoveSpellEffects
op 0x200022c: RemoveSpellEffects, explicit
opcodes 0x200022d-0x3ffffff unused

View file

@ -459,6 +459,22 @@ namespace MWScript
} }
}; };
template<class R>
class OpRemoveSpellEffects : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
std::string spellid = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::Class::get (ptr).getCreatureStats (ptr).getActiveSpells().removeEffects(spellid);
}
};
template<class R> template<class R>
class OpGetSpell : public Interpreter::Opcode0 class OpGetSpell : public Interpreter::Opcode0
{ {
@ -1135,6 +1151,9 @@ namespace MWScript
interpreter.installSegment5 (Compiler::Stats::opcodeRemoveSpell, new OpRemoveSpell<ImplicitRef>); interpreter.installSegment5 (Compiler::Stats::opcodeRemoveSpell, new OpRemoveSpell<ImplicitRef>);
interpreter.installSegment5 (Compiler::Stats::opcodeRemoveSpellExplicit, interpreter.installSegment5 (Compiler::Stats::opcodeRemoveSpellExplicit,
new OpRemoveSpell<ExplicitRef>); new OpRemoveSpell<ExplicitRef>);
interpreter.installSegment5 (Compiler::Stats::opcodeRemoveSpellEffects, new OpRemoveSpellEffects<ImplicitRef>);
interpreter.installSegment5 (Compiler::Stats::opcodeRemoveSpellEffectsExplicit,
new OpRemoveSpellEffects<ExplicitRef>);
interpreter.installSegment5 (Compiler::Stats::opcodeGetSpell, new OpGetSpell<ImplicitRef>); interpreter.installSegment5 (Compiler::Stats::opcodeGetSpell, new OpGetSpell<ImplicitRef>);
interpreter.installSegment5 (Compiler::Stats::opcodeGetSpellExplicit, new OpGetSpell<ExplicitRef>); interpreter.installSegment5 (Compiler::Stats::opcodeGetSpellExplicit, new OpGetSpell<ExplicitRef>);

View file

@ -391,6 +391,8 @@ namespace Compiler
extensions.registerInstruction ("addspell", "c", opcodeAddSpell, opcodeAddSpellExplicit); extensions.registerInstruction ("addspell", "c", opcodeAddSpell, opcodeAddSpellExplicit);
extensions.registerInstruction ("removespell", "c", opcodeRemoveSpell, extensions.registerInstruction ("removespell", "c", opcodeRemoveSpell,
opcodeRemoveSpellExplicit); opcodeRemoveSpellExplicit);
extensions.registerInstruction ("removespelleffects", "c", opcodeRemoveSpellEffects,
opcodeRemoveSpellEffectsExplicit);
extensions.registerFunction ("getspell", 'l', "c", opcodeGetSpell, opcodeGetSpellExplicit); extensions.registerFunction ("getspell", 'l', "c", opcodeGetSpell, opcodeGetSpellExplicit);
extensions.registerInstruction("pcraiserank","/S",opcodePCRaiseRank); extensions.registerInstruction("pcraiserank","/S",opcodePCRaiseRank);

View file

@ -369,6 +369,9 @@ namespace Compiler
const int opcodeIsWerewolfExplicit = 0x20001fe; const int opcodeIsWerewolfExplicit = 0x20001fe;
const int opcodeGetWerewolfKills = 0x20001e2; const int opcodeGetWerewolfKills = 0x20001e2;
const int opcodeRemoveSpellEffects = 0x200022b;
const int opcodeRemoveSpellEffectsExplicit = 0x200022c;
} }
namespace Transformation namespace Transformation