mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-19 19:10:12 +00:00
Implement HitAttemptOnMe function (Bug #2078)
This commit is contained in:
parent
5f00a3d5c3
commit
886903d70e
10 changed files with 54 additions and 5 deletions
apps/openmw
mwclass
mwmechanics
mwscript
components
|
@ -346,10 +346,11 @@ namespace MWClass
|
||||||
setOnPcHitMe = MWBase::Environment::get().getMechanicsManager()->actorAttacked(ptr, attacker);
|
setOnPcHitMe = MWBase::Environment::get().getMechanicsManager()->actorAttacked(ptr, attacker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!object.isEmpty())
|
||||||
|
getCreatureStats(ptr).setLastHitAttemptObject(object.getClass().getId(object));
|
||||||
|
|
||||||
if(!successful)
|
if(!successful)
|
||||||
{
|
{
|
||||||
// TODO: Handle HitAttemptOnMe script function
|
|
||||||
|
|
||||||
// Missed
|
// Missed
|
||||||
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "miss", 1.0f, 1.0f);
|
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "miss", 1.0f, 1.0f);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -654,10 +654,11 @@ namespace MWClass
|
||||||
setOnPcHitMe = MWBase::Environment::get().getMechanicsManager()->actorAttacked(ptr, attacker);
|
setOnPcHitMe = MWBase::Environment::get().getMechanicsManager()->actorAttacked(ptr, attacker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!object.isEmpty())
|
||||||
|
getCreatureStats(ptr).setLastHitAttemptObject(object.getClass().getId(object));
|
||||||
|
|
||||||
if(!successful)
|
if(!successful)
|
||||||
{
|
{
|
||||||
// TODO: Handle HitAttemptOnMe script function
|
|
||||||
|
|
||||||
// Missed
|
// Missed
|
||||||
sndMgr->playSound3D(ptr, "miss", 1.0f, 1.0f);
|
sndMgr->playSound3D(ptr, "miss", 1.0f, 1.0f);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -359,6 +359,16 @@ namespace MWMechanics
|
||||||
return mLastHitObject;
|
return mLastHitObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CreatureStats::setLastHitAttemptObject(const std::string& objectid)
|
||||||
|
{
|
||||||
|
mLastHitAttemptObject = objectid;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &CreatureStats::getLastHitAttemptObject() const
|
||||||
|
{
|
||||||
|
return mLastHitAttemptObject;
|
||||||
|
}
|
||||||
|
|
||||||
void CreatureStats::addToFallHeight(float height)
|
void CreatureStats::addToFallHeight(float height)
|
||||||
{
|
{
|
||||||
mFallHeight += height;
|
mFallHeight += height;
|
||||||
|
@ -510,6 +520,7 @@ namespace MWMechanics
|
||||||
state.mAttackStrength = mAttackStrength;
|
state.mAttackStrength = mAttackStrength;
|
||||||
state.mFallHeight = mFallHeight; // TODO: vertical velocity (move from PhysicActor to CreatureStats?)
|
state.mFallHeight = mFallHeight; // TODO: vertical velocity (move from PhysicActor to CreatureStats?)
|
||||||
state.mLastHitObject = mLastHitObject;
|
state.mLastHitObject = mLastHitObject;
|
||||||
|
state.mLastHitAttemptObject = mLastHitAttemptObject;
|
||||||
state.mRecalcDynamicStats = mRecalcMagicka;
|
state.mRecalcDynamicStats = mRecalcMagicka;
|
||||||
state.mDrawState = mDrawState;
|
state.mDrawState = mDrawState;
|
||||||
state.mLevel = mLevel;
|
state.mLevel = mLevel;
|
||||||
|
@ -558,6 +569,7 @@ namespace MWMechanics
|
||||||
mAttackStrength = state.mAttackStrength;
|
mAttackStrength = state.mAttackStrength;
|
||||||
mFallHeight = state.mFallHeight;
|
mFallHeight = state.mFallHeight;
|
||||||
mLastHitObject = state.mLastHitObject;
|
mLastHitObject = state.mLastHitObject;
|
||||||
|
mLastHitAttemptObject = state.mLastHitAttemptObject;
|
||||||
mRecalcMagicka = state.mRecalcDynamicStats;
|
mRecalcMagicka = state.mRecalcDynamicStats;
|
||||||
mDrawState = DrawState_(state.mDrawState);
|
mDrawState = DrawState_(state.mDrawState);
|
||||||
mLevel = state.mLevel;
|
mLevel = state.mLevel;
|
||||||
|
|
|
@ -52,6 +52,7 @@ namespace MWMechanics
|
||||||
float mFallHeight;
|
float mFallHeight;
|
||||||
|
|
||||||
std::string mLastHitObject; // The last object to hit this actor
|
std::string mLastHitObject; // The last object to hit this actor
|
||||||
|
std::string mLastHitAttemptObject; // The last object to attempt to hit this actor
|
||||||
|
|
||||||
bool mRecalcMagicka;
|
bool mRecalcMagicka;
|
||||||
|
|
||||||
|
@ -241,7 +242,9 @@ namespace MWMechanics
|
||||||
bool getStance (Stance flag) const;
|
bool getStance (Stance flag) const;
|
||||||
|
|
||||||
void setLastHitObject(const std::string &objectid);
|
void setLastHitObject(const std::string &objectid);
|
||||||
|
void setLastHitAttemptObject(const std::string &objectid);
|
||||||
const std::string &getLastHitObject() const;
|
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.
|
// 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?
|
// TODO: Put it somewhere else?
|
||||||
|
|
|
@ -436,5 +436,7 @@ op 0x20002f5: ToggleWorld
|
||||||
op 0x20002f6: PCForce1stPerson
|
op 0x20002f6: PCForce1stPerson
|
||||||
op 0x20002f7: PCForce3rdPerson
|
op 0x20002f7: PCForce3rdPerson
|
||||||
op 0x20002f8: PCGet3rdPerson
|
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>
|
template <bool Enable>
|
||||||
class OpEnableTeleporting : public Interpreter::Opcode0
|
class OpEnableTeleporting : public Interpreter::Opcode0
|
||||||
{
|
{
|
||||||
|
@ -1085,6 +1104,8 @@ namespace MWScript
|
||||||
interpreter.installSegment5 (Compiler::Misc::opcodeGetWindSpeed, new OpGetWindSpeed);
|
interpreter.installSegment5 (Compiler::Misc::opcodeGetWindSpeed, new OpGetWindSpeed);
|
||||||
interpreter.installSegment5 (Compiler::Misc::opcodeHitOnMe, new OpHitOnMe<ImplicitRef>);
|
interpreter.installSegment5 (Compiler::Misc::opcodeHitOnMe, new OpHitOnMe<ImplicitRef>);
|
||||||
interpreter.installSegment5 (Compiler::Misc::opcodeHitOnMeExplicit, new OpHitOnMe<ExplicitRef>);
|
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::opcodeDisableTeleporting, new OpEnableTeleporting<false>);
|
||||||
interpreter.installSegment5 (Compiler::Misc::opcodeEnableTeleporting, new OpEnableTeleporting<true>);
|
interpreter.installSegment5 (Compiler::Misc::opcodeEnableTeleporting, new OpEnableTeleporting<true>);
|
||||||
interpreter.installSegment5 (Compiler::Misc::opcodeShowVars, new OpShowVars<ImplicitRef>);
|
interpreter.installSegment5 (Compiler::Misc::opcodeShowVars, new OpShowVars<ImplicitRef>);
|
||||||
|
|
|
@ -295,6 +295,7 @@ namespace Compiler
|
||||||
extensions.registerInstruction ("hurtcollidingactor", "f", opcodeHurtCollidingActor, opcodeHurtCollidingActorExplicit);
|
extensions.registerInstruction ("hurtcollidingactor", "f", opcodeHurtCollidingActor, opcodeHurtCollidingActorExplicit);
|
||||||
extensions.registerFunction ("getwindspeed", 'f', "", opcodeGetWindSpeed);
|
extensions.registerFunction ("getwindspeed", 'f', "", opcodeGetWindSpeed);
|
||||||
extensions.registerFunction ("hitonme", 'l', "S", opcodeHitOnMe, opcodeHitOnMeExplicit);
|
extensions.registerFunction ("hitonme", 'l', "S", opcodeHitOnMe, opcodeHitOnMeExplicit);
|
||||||
|
extensions.registerFunction ("hitattemptonme", 'l', "S", opcodeHitAttemptOnMe, opcodeHitAttemptOnMeExplicit);
|
||||||
extensions.registerInstruction ("disableteleporting", "", opcodeDisableTeleporting);
|
extensions.registerInstruction ("disableteleporting", "", opcodeDisableTeleporting);
|
||||||
extensions.registerInstruction ("enableteleporting", "", opcodeEnableTeleporting);
|
extensions.registerInstruction ("enableteleporting", "", opcodeEnableTeleporting);
|
||||||
extensions.registerInstruction ("showvars", "", opcodeShowVars, opcodeShowVarsExplicit);
|
extensions.registerInstruction ("showvars", "", opcodeShowVars, opcodeShowVarsExplicit);
|
||||||
|
|
|
@ -269,6 +269,8 @@ namespace Compiler
|
||||||
const int opcodePayFineThief = 0x2000237;
|
const int opcodePayFineThief = 0x2000237;
|
||||||
const int opcodeHitOnMe = 0x2000213;
|
const int opcodeHitOnMe = 0x2000213;
|
||||||
const int opcodeHitOnMeExplicit = 0x2000214;
|
const int opcodeHitOnMeExplicit = 0x2000214;
|
||||||
|
const int opcodeHitAttemptOnMe = 0x20002f9;
|
||||||
|
const int opcodeHitAttemptOnMeExplicit = 0x20002fa;
|
||||||
const int opcodeDisableTeleporting = 0x2000215;
|
const int opcodeDisableTeleporting = 0x2000215;
|
||||||
const int opcodeEnableTeleporting = 0x2000216;
|
const int opcodeEnableTeleporting = 0x2000216;
|
||||||
const int opcodeShowVars = 0x200021d;
|
const int opcodeShowVars = 0x200021d;
|
||||||
|
|
|
@ -68,6 +68,8 @@ void ESM::CreatureStats::load (ESMReader &esm)
|
||||||
|
|
||||||
mLastHitObject = esm.getHNOString ("LHIT");
|
mLastHitObject = esm.getHNOString ("LHIT");
|
||||||
|
|
||||||
|
mLastHitAttemptObject = esm.getHNOString ("LHAT");
|
||||||
|
|
||||||
mRecalcDynamicStats = false;
|
mRecalcDynamicStats = false;
|
||||||
esm.getHNOT (mRecalcDynamicStats, "CALC");
|
esm.getHNOT (mRecalcDynamicStats, "CALC");
|
||||||
|
|
||||||
|
@ -179,6 +181,9 @@ void ESM::CreatureStats::save (ESMWriter &esm) const
|
||||||
if (!mLastHitObject.empty())
|
if (!mLastHitObject.empty())
|
||||||
esm.writeHNString ("LHIT", mLastHitObject);
|
esm.writeHNString ("LHIT", mLastHitObject);
|
||||||
|
|
||||||
|
if (!mLastHitAttemptObject.empty())
|
||||||
|
esm.writeHNString ("LHAT", mLastHitAttemptObject);
|
||||||
|
|
||||||
if (mRecalcDynamicStats)
|
if (mRecalcDynamicStats)
|
||||||
esm.writeHNT ("CALC", mRecalcDynamicStats);
|
esm.writeHNT ("CALC", mRecalcDynamicStats);
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ namespace ESM
|
||||||
float mAttackStrength;
|
float mAttackStrength;
|
||||||
float mFallHeight;
|
float mFallHeight;
|
||||||
std::string mLastHitObject;
|
std::string mLastHitObject;
|
||||||
|
std::string mLastHitAttemptObject;
|
||||||
bool mRecalcDynamicStats;
|
bool mRecalcDynamicStats;
|
||||||
int mDrawState;
|
int mDrawState;
|
||||||
unsigned char mDeathAnimation;
|
unsigned char mDeathAnimation;
|
||||||
|
|
Loading…
Reference in a new issue