mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-04 02:41:19 +00:00
Implement PCVisionBonus functions
This commit is contained in:
parent
5815faecda
commit
489c7a10b6
@ -15,6 +15,7 @@
|
||||
Bug #6974: Only harmful effects are reflected
|
||||
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
|
||||
------
|
||||
|
@ -1027,6 +1027,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
|
||||
|
@ -1293,6 +1293,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;
|
||||
@ -1471,6 +1513,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -537,6 +537,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…
Reference in New Issue
Block a user