Merge branch 'pcvisionbonus' into 'master'

Implement PCVisionBonus functions

Closes #6983

See merge request OpenMW/openmw!2371
crashfix_debugdraw
psi29a 2 years ago
commit 1859c6eded

@ -20,6 +20,7 @@
Bug #6993: Shooting your last round of ammunition causes the attack animation to cancel
Feature #6945: Support S3TC-compressed and BGR/BGRA NiPixelData
Feature #6979: Add support of loading and displaying LOD assets purely based on their filename extension
Feature #6983: PCVisionBonus script functions
0.48.0
------

@ -1036,6 +1036,19 @@ void removeMagicEffect(const MWWorld::Ptr& target, ActiveSpells::ActiveSpellPara
case ESM::MagicEffect::DemoralizeHumanoid:
modifyAiSetting(target, effect, ESM::MagicEffect::DemoralizeCreature, AiSetting::Flee, -effect.mMagnitude, invalid);
break;
case ESM::MagicEffect::NightEye:
{
const MWMechanics::EffectParam nightEye = magnitudes.get(effect.mEffectId);
if(nightEye.getMagnitude() < 0.f && nightEye.getBase() < 0)
{
// The PCVisionBonus functions are different from every other magic effect function in that they clamp the value to [0, 1].
// Morrowind.exe applies the same clamping to the night-eye effect, which can create situations where an effect is still active
// (i.e. shown in the menu) but the screen is no longer bright. Modifying the base value here should prevent that while preserving their function.
float delta = std::clamp(-nightEye.getMagnitude(), 0.f, -static_cast<float>(nightEye.getBase()));
magnitudes.modifyBase(effect.mEffectId, static_cast<int>(delta));
}
}
break;
case ESM::MagicEffect::RallyCreature:
case ESM::MagicEffect::RallyHumanoid:
modifyAiSetting(target, effect, ESM::MagicEffect::RallyCreature, AiSetting::Flee, effect.mMagnitude, invalid);

@ -481,5 +481,8 @@ op 0x200031e: GetDistance
op 0x200031f: GetDistance, explicit
op 0x2000320: Help
op 0x2000321: ReloadLua
op 0x2000322: GetPCVisionBonus
op 0x2000323: SetPCVisionBonus
op 0x2000324: ModPCVisionBonus
opcodes 0x2000322-0x3ffffff unused
opcodes 0x2000325-0x3ffffff unused

@ -1296,6 +1296,48 @@ namespace MWScript
}
};
class OpGetPCVisionBonus : public Interpreter::Opcode0
{
public:
void execute(Interpreter::Runtime& runtime) override
{
MWWorld::Ptr player = MWMechanics::getPlayer();
MWMechanics::EffectParam nightEye = player.getClass().getCreatureStats(player).getMagicEffects().get(ESM::MagicEffect::NightEye);
runtime.push(std::clamp(nightEye.getMagnitude() / 100.f, 0.f, 1.f));
}
};
class OpSetPCVisionBonus : public Interpreter::Opcode0
{
public:
void execute(Interpreter::Runtime& runtime) override
{
float arg = runtime[0].mFloat;
runtime.pop();
MWWorld::Ptr player = MWMechanics::getPlayer();
auto& effects = player.getClass().getCreatureStats(player).getMagicEffects();
float delta = std::clamp(arg * 100.f, 0.f, 100.f) - effects.get(ESM::MagicEffect::NightEye).getMagnitude();
effects.modifyBase(ESM::MagicEffect::NightEye, static_cast<int>(delta));
}
};
class OpModPCVisionBonus : public Interpreter::Opcode0
{
public:
void execute(Interpreter::Runtime& runtime) override
{
float arg = runtime[0].mFloat;
runtime.pop();
MWWorld::Ptr player = MWMechanics::getPlayer();
auto& effects = player.getClass().getCreatureStats(player).getMagicEffects();
const MWMechanics::EffectParam nightEye = effects.get(ESM::MagicEffect::NightEye);
float newBase = std::clamp(nightEye.getMagnitude() + arg * 100.f, 0.f, 100.f);
newBase -= nightEye.getModifier();
float delta = std::clamp(newBase, 0.f, 100.f) - nightEye.getMagnitude();
effects.modifyBase(ESM::MagicEffect::NightEye, static_cast<int>(delta));
}
};
struct MagicEffect
{
int mPositiveEffect;
@ -1474,6 +1516,10 @@ namespace MWScript
interpreter.installSegment5<OpModMagicEffect<ImplicitRef>>(Compiler::Stats::opcodeModMagicEffect + i, positive, negative);
interpreter.installSegment5<OpModMagicEffect<ExplicitRef>>(Compiler::Stats::opcodeModMagicEffectExplicit + i, positive, negative);
}
interpreter.installSegment5<OpGetPCVisionBonus>(Compiler::Stats::opcodeGetPCVisionBonus);
interpreter.installSegment5<OpSetPCVisionBonus>(Compiler::Stats::opcodeSetPCVisionBonus);
interpreter.installSegment5<OpModPCVisionBonus>(Compiler::Stats::opcodeModPCVisionBonus);
}
}
}

@ -538,6 +538,10 @@ namespace Compiler
extensions.registerInstruction("becomewerewolf", "", opcodeBecomeWerewolf, opcodeBecomeWerewolfExplicit);
extensions.registerInstruction("undowerewolf", "", opcodeUndoWerewolf, opcodeUndoWerewolfExplicit);
extensions.registerInstruction("setwerewolfacrobatics", "", opcodeSetWerewolfAcrobatics, opcodeSetWerewolfAcrobaticsExplicit);
extensions.registerFunction("getpcvisionbonus", 'f', "", opcodeGetPCVisionBonus);
extensions.registerInstruction("setpcvisionbonus", "f", opcodeSetPCVisionBonus);
extensions.registerInstruction("modpcvisionbonus", "f", opcodeModPCVisionBonus);
}
}

@ -484,6 +484,10 @@ namespace Compiler
const int opcodeGetStat = 0x200024e;
const int opcodeGetStatExplicit = 0x200024f;
const int opcodeGetPCVisionBonus = 0x2000322;
const int opcodeSetPCVisionBonus = 0x2000323;
const int opcodeModPCVisionBonus = 0x2000324;
}
namespace Transformation

Loading…
Cancel
Save