Commit 886903d7 authored by scrawl's avatar scrawl

Implement HitAttemptOnMe function (Bug #2078)

parent 5f00a3d5
......@@ -346,10 +346,11 @@ namespace MWClass
setOnPcHitMe = MWBase::Environment::get().getMechanicsManager()->actorAttacked(ptr, attacker);
}
if(!object.isEmpty())
getCreatureStats(ptr).setLastHitAttemptObject(object.getClass().getId(object));
if(!successful)
{
// TODO: Handle HitAttemptOnMe script function
// Missed
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "miss", 1.0f, 1.0f);
return;
......
......@@ -654,10 +654,11 @@ namespace MWClass
setOnPcHitMe = MWBase::Environment::get().getMechanicsManager()->actorAttacked(ptr, attacker);
}
if(!object.isEmpty())
getCreatureStats(ptr).setLastHitAttemptObject(object.getClass().getId(object));
if(!successful)
{
// TODO: Handle HitAttemptOnMe script function
// Missed
sndMgr->playSound3D(ptr, "miss", 1.0f, 1.0f);
return;
......
......@@ -359,6 +359,16 @@ namespace MWMechanics
return mLastHitObject;
}
void CreatureStats::setLastHitAttemptObject(const std::string& objectid)
{
mLastHitAttemptObject = objectid;
}
const std::string &CreatureStats::getLastHitAttemptObject() const
{
return mLastHitAttemptObject;
}
void CreatureStats::addToFallHeight(float height)
{
mFallHeight += height;
......@@ -510,6 +520,7 @@ namespace MWMechanics
state.mAttackStrength = mAttackStrength;
state.mFallHeight = mFallHeight; // TODO: vertical velocity (move from PhysicActor to CreatureStats?)
state.mLastHitObject = mLastHitObject;
state.mLastHitAttemptObject = mLastHitAttemptObject;
state.mRecalcDynamicStats = mRecalcMagicka;
state.mDrawState = mDrawState;
state.mLevel = mLevel;
......@@ -558,6 +569,7 @@ namespace MWMechanics
mAttackStrength = state.mAttackStrength;
mFallHeight = state.mFallHeight;
mLastHitObject = state.mLastHitObject;
mLastHitAttemptObject = state.mLastHitAttemptObject;
mRecalcMagicka = state.mRecalcDynamicStats;
mDrawState = DrawState_(state.mDrawState);
mLevel = state.mLevel;
......
......@@ -52,6 +52,7 @@ namespace MWMechanics
float mFallHeight;
std::string mLastHitObject; // The last object to hit this actor
std::string mLastHitAttemptObject; // The last object to attempt to hit this actor
bool mRecalcMagicka;
......@@ -241,7 +242,9 @@ namespace MWMechanics
bool getStance (Stance flag) const;
void setLastHitObject(const std::string &objectid);
void setLastHitAttemptObject(const std::string &objectid);
const std::string &getLastHitObject() const;
const std::string &getLastHitAttemptObject() const;
// Note, this is just a cache to avoid checking the whole container store every frame. We don't need to store it in saves.
// TODO: Put it somewhere else?
......
......@@ -436,5 +436,7 @@ op 0x20002f5: ToggleWorld
op 0x20002f6: PCForce1stPerson
op 0x20002f7: PCForce3rdPerson
op 0x20002f8: PCGet3rdPerson
op 0x20002f9: HitAttemptOnMe
op 0x20002fa: HitAttemptOnMe, explicit
opcodes 0x20002f9-0x3ffffff unused
opcodes 0x20002fb-0x3ffffff unused
......@@ -737,6 +737,25 @@ namespace MWScript
}
};
template <class R>
class OpHitAttemptOnMe : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
std::string objectID = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr);
runtime.push(::Misc::StringUtils::ciEqual(objectID, stats.getLastHitAttemptObject()));
stats.setLastHitAttemptObject(std::string());
}
};
template <bool Enable>
class OpEnableTeleporting : public Interpreter::Opcode0
{
......@@ -1085,6 +1104,8 @@ namespace MWScript
interpreter.installSegment5 (Compiler::Misc::opcodeGetWindSpeed, new OpGetWindSpeed);
interpreter.installSegment5 (Compiler::Misc::opcodeHitOnMe, new OpHitOnMe<ImplicitRef>);
interpreter.installSegment5 (Compiler::Misc::opcodeHitOnMeExplicit, new OpHitOnMe<ExplicitRef>);
interpreter.installSegment5 (Compiler::Misc::opcodeHitAttemptOnMe, new OpHitAttemptOnMe<ImplicitRef>);
interpreter.installSegment5 (Compiler::Misc::opcodeHitAttemptOnMeExplicit, new OpHitAttemptOnMe<ExplicitRef>);
interpreter.installSegment5 (Compiler::Misc::opcodeDisableTeleporting, new OpEnableTeleporting<false>);
interpreter.installSegment5 (Compiler::Misc::opcodeEnableTeleporting, new OpEnableTeleporting<true>);
interpreter.installSegment5 (Compiler::Misc::opcodeShowVars, new OpShowVars<ImplicitRef>);
......
......@@ -295,6 +295,7 @@ namespace Compiler
extensions.registerInstruction ("hurtcollidingactor", "f", opcodeHurtCollidingActor, opcodeHurtCollidingActorExplicit);
extensions.registerFunction ("getwindspeed", 'f', "", opcodeGetWindSpeed);
extensions.registerFunction ("hitonme", 'l', "S", opcodeHitOnMe, opcodeHitOnMeExplicit);
extensions.registerFunction ("hitattemptonme", 'l', "S", opcodeHitAttemptOnMe, opcodeHitAttemptOnMeExplicit);
extensions.registerInstruction ("disableteleporting", "", opcodeDisableTeleporting);
extensions.registerInstruction ("enableteleporting", "", opcodeEnableTeleporting);
extensions.registerInstruction ("showvars", "", opcodeShowVars, opcodeShowVarsExplicit);
......
......@@ -269,6 +269,8 @@ namespace Compiler
const int opcodePayFineThief = 0x2000237;
const int opcodeHitOnMe = 0x2000213;
const int opcodeHitOnMeExplicit = 0x2000214;
const int opcodeHitAttemptOnMe = 0x20002f9;
const int opcodeHitAttemptOnMeExplicit = 0x20002fa;
const int opcodeDisableTeleporting = 0x2000215;
const int opcodeEnableTeleporting = 0x2000216;
const int opcodeShowVars = 0x200021d;
......
......@@ -68,6 +68,8 @@ void ESM::CreatureStats::load (ESMReader &esm)
mLastHitObject = esm.getHNOString ("LHIT");
mLastHitAttemptObject = esm.getHNOString ("LHAT");
mRecalcDynamicStats = false;
esm.getHNOT (mRecalcDynamicStats, "CALC");
......@@ -179,6 +181,9 @@ void ESM::CreatureStats::save (ESMWriter &esm) const
if (!mLastHitObject.empty())
esm.writeHNString ("LHIT", mLastHitObject);
if (!mLastHitAttemptObject.empty())
esm.writeHNString ("LHAT", mLastHitAttemptObject);
if (mRecalcDynamicStats)
esm.writeHNT ("CALC", mRecalcDynamicStats);
......
......@@ -56,6 +56,7 @@ namespace ESM
float mAttackStrength;
float mFallHeight;
std::string mLastHitObject;
std::string mLastHitAttemptObject;
bool mRecalcDynamicStats;
int mDrawState;
unsigned char mDeathAnimation;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment