forked from mirror/openmw-tes3mp
added GetHealthGetRatio
This commit is contained in:
parent
b13895cf3a
commit
77b2c25d62
2 changed files with 72 additions and 1 deletions
|
@ -74,4 +74,6 @@ op 0x2000063-0x2000065: ModDynamic (health, magicka, fatigue)
|
|||
op 0x2000066-0x2000068: ModDynamic (health, magicka, fatigue), explicit reference
|
||||
op 0x2000069-0x200006b: ModDynamic (health, magicka, fatigue)
|
||||
op 0x200006c-0x200006e: ModDynamic (health, magicka, fatigue), explicit reference
|
||||
opcodes 0x200006f-0x3ffffff unused
|
||||
op 0x200006f-0x2000071: GetDynamic (health, magicka, fatigue)
|
||||
op 0x2000072-0x2000074: GetDynamic (health, magicka, fatigue), explicit reference
|
||||
opcodes 0x2000075-0x3ffffff unused
|
||||
|
|
|
@ -363,6 +363,62 @@ namespace MWScript
|
|||
}
|
||||
};
|
||||
|
||||
class OpGetDynamicGetRatio : public Interpreter::Opcode0
|
||||
{
|
||||
int mIndex;
|
||||
|
||||
public:
|
||||
|
||||
OpGetDynamicGetRatio (int index) : mIndex (index) {}
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
MWScript::InterpreterContext& context
|
||||
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
|
||||
|
||||
MWMechanics::CreatureStats& stats = context.getReference().getCreatureStats();
|
||||
|
||||
Interpreter::Type_Float value = 0;
|
||||
|
||||
Interpreter::Type_Float max = stats.mDynamic[mIndex].getModified();
|
||||
|
||||
if (max>0)
|
||||
value = stats.mDynamic[mIndex].getCurrent() / max;
|
||||
|
||||
runtime.push (value);
|
||||
}
|
||||
};
|
||||
|
||||
class OpGetDynamicGetRatioExplicit : public Interpreter::Opcode0
|
||||
{
|
||||
int mIndex;
|
||||
|
||||
public:
|
||||
|
||||
OpGetDynamicGetRatioExplicit (int index) : mIndex (index) {}
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
MWScript::InterpreterContext& context
|
||||
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
|
||||
|
||||
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
MWMechanics::CreatureStats& stats =
|
||||
context.getWorld().getPtr (id, false).getCreatureStats();
|
||||
|
||||
Interpreter::Type_Float value = 0;
|
||||
|
||||
Interpreter::Type_Float max = stats.mDynamic[mIndex].getModified();
|
||||
|
||||
if (max>0)
|
||||
value = stats.mDynamic[mIndex].getCurrent() / max;
|
||||
|
||||
runtime.push (value);
|
||||
}
|
||||
};
|
||||
|
||||
const int numberOfAttributes = 8;
|
||||
|
||||
const int opcodeGetAttribute = 0x2000027;
|
||||
|
@ -382,6 +438,8 @@ namespace MWScript
|
|||
const int opcodeModDynamicExplicit = 0x2000066;
|
||||
const int opcodeModCurrentDynamic = 0x2000069;
|
||||
const int opcodeModCurrentDynamicExplicit = 0x200006c;
|
||||
const int opcodeGetDynamicGetRatio = 0x200006f;
|
||||
const int opcodeGetDynamicGetRatioExplicit = 0x2000072;
|
||||
|
||||
void registerExtensions (Compiler::Extensions& extensions)
|
||||
{
|
||||
|
@ -400,6 +458,7 @@ namespace MWScript
|
|||
std::string set ("set");
|
||||
std::string mod ("mod");
|
||||
std::string modCurrent ("modcurrent");
|
||||
std::string getRatio ("getratio");
|
||||
|
||||
for (int i=0; i<numberOfAttributes; ++i)
|
||||
{
|
||||
|
@ -426,6 +485,11 @@ namespace MWScript
|
|||
|
||||
extensions.registerInstruction (modCurrent + dynamics[i], "l",
|
||||
opcodeModCurrentDynamic+i, opcodeModCurrentDynamicExplicit+i);
|
||||
|
||||
if (i==0) // GetMagickaGetRatio and GetFatigueGetRatio don't exist in original MW
|
||||
extensions.registerFunction (get + dynamics[i] + getRatio, 'f', "",
|
||||
opcodeGetDynamicGetRatio+i, opcodeGetDynamicGetRatioExplicit+i);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -463,6 +527,11 @@ namespace MWScript
|
|||
interpreter.installSegment5 (opcodeModCurrentDynamic+i, new OpModCurrentDynamic (i));
|
||||
interpreter.installSegment5 (opcodeModCurrentDynamicExplicit+i,
|
||||
new OpModCurrentDynamicExplicit (i));
|
||||
|
||||
interpreter.installSegment5 (opcodeGetDynamicGetRatio+i,
|
||||
new OpGetDynamicGetRatio (i));
|
||||
interpreter.installSegment5 (opcodeGetDynamicGetRatioExplicit+i,
|
||||
new OpGetDynamicGetRatioExplicit (i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue