mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-11-04 07:56:45 +00:00 
			
		
		
		
	Move attackingOrSpell flag to the CharacterController
This commit is contained in:
		
							parent
							
								
									519fb9482a
								
							
						
					
					
						commit
						a1432b0255
					
				
					 11 changed files with 41 additions and 30 deletions
				
			
		| 
						 | 
				
			
			@ -207,7 +207,7 @@ namespace MWInput
 | 
			
		|||
        if (mControlSwitch["playercontrols"])
 | 
			
		||||
        {
 | 
			
		||||
            if (action == A_Use)
 | 
			
		||||
                mPlayer->getPlayer().getClass().getCreatureStats(mPlayer->getPlayer()).setAttackingOrSpell(currentValue != 0);
 | 
			
		||||
                mPlayer->setAttackingOrSpell(currentValue != 0);
 | 
			
		||||
            else if (action == A_Jump)
 | 
			
		||||
                mAttemptJump = (currentValue == 1.0 && previousValue == 0.0);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1086,6 +1086,9 @@ namespace MWMechanics
 | 
			
		|||
 | 
			
		||||
                iter->second->getCharacterController()->setActive(inProcessingRange);
 | 
			
		||||
 | 
			
		||||
                if (iter->first == player)
 | 
			
		||||
                    iter->second->getCharacterController()->setAttackingOrSpell(MWBase::Environment::get().getWorld()->getPlayer().getAttackingOrSpell());
 | 
			
		||||
 | 
			
		||||
                if (!iter->first.getClass().getCreatureStats(iter->first).isDead())
 | 
			
		||||
                {
 | 
			
		||||
                    updateActor(iter->first, duration);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -269,8 +269,7 @@ namespace MWMechanics
 | 
			
		|||
            attack = false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        actorClass.getCreatureStats(actor).setAttackingOrSpell(attack);
 | 
			
		||||
 | 
			
		||||
        characterController.setAttackingOrSpell(attack);
 | 
			
		||||
 | 
			
		||||
        float& actionCooldown = storage.mActionCooldown;
 | 
			
		||||
        actionCooldown -= duration;
 | 
			
		||||
| 
						 | 
				
			
			@ -476,7 +475,7 @@ namespace MWMechanics
 | 
			
		|||
            movement.mPosition[1] = 0;
 | 
			
		||||
            movement.mPosition[2] = 0;
 | 
			
		||||
            readyToAttack = false;
 | 
			
		||||
            actorClass.getCreatureStats(actor).setAttackingOrSpell(false);
 | 
			
		||||
            characterController.setAttackingOrSpell(false);
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -654,6 +654,7 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim
 | 
			
		|||
    , mSecondsOfSwimming(0)
 | 
			
		||||
    , mSecondsOfRunning(0)
 | 
			
		||||
    , mTurnAnimationThreshold(0)
 | 
			
		||||
    , mAttackingOrSpell(false)
 | 
			
		||||
{
 | 
			
		||||
    if(!mAnimation)
 | 
			
		||||
        return;
 | 
			
		||||
| 
						 | 
				
			
			@ -937,7 +938,7 @@ bool CharacterController::updateCreatureState()
 | 
			
		|||
            mAnimation->disable(mCurrentWeapon);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(stats.getAttackingOrSpell())
 | 
			
		||||
    if(mAttackingOrSpell)
 | 
			
		||||
    {
 | 
			
		||||
        if(mUpperBodyState == UpperCharState_Nothing && mHitState == CharState_None)
 | 
			
		||||
        {
 | 
			
		||||
| 
						 | 
				
			
			@ -997,7 +998,7 @@ bool CharacterController::updateCreatureState()
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        stats.setAttackingOrSpell(false);
 | 
			
		||||
        mAttackingOrSpell = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool animPlaying = mAnimation->getInfo(mCurrentWeapon);
 | 
			
		||||
| 
						 | 
				
			
			@ -1142,7 +1143,7 @@ bool CharacterController::updateWeaponState()
 | 
			
		|||
 | 
			
		||||
    float complete;
 | 
			
		||||
    bool animPlaying;
 | 
			
		||||
    if(stats.getAttackingOrSpell())
 | 
			
		||||
    if(mAttackingOrSpell)
 | 
			
		||||
    {
 | 
			
		||||
        if(mUpperBodyState == UpperCharState_WeapEquiped && mHitState == CharState_None)
 | 
			
		||||
        {
 | 
			
		||||
| 
						 | 
				
			
			@ -1152,7 +1153,7 @@ bool CharacterController::updateWeaponState()
 | 
			
		|||
            {
 | 
			
		||||
                // Unset casting flag, otherwise pressing the mouse button down would
 | 
			
		||||
                // continue casting every frame if there is no animation
 | 
			
		||||
                stats.setAttackingOrSpell(false);
 | 
			
		||||
                mAttackingOrSpell = false;
 | 
			
		||||
 | 
			
		||||
                const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2041,6 +2042,11 @@ bool CharacterController::isKnockedOut() const
 | 
			
		|||
    return mHitState == CharState_KnockOut;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CharacterController::setAttackingOrSpell(bool attackingOrSpell)
 | 
			
		||||
{
 | 
			
		||||
    mAttackingOrSpell = attackingOrSpell;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CharacterController::setActive(bool active)
 | 
			
		||||
{
 | 
			
		||||
    mAnimation->setActive(active);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -180,6 +180,9 @@ class CharacterController : public MWRender::Animation::TextKeyListener
 | 
			
		|||
    float mTurnAnimationThreshold; // how long to continue playing turning animation after actor stopped turning
 | 
			
		||||
 | 
			
		||||
    std::string mAttackType; // slash, chop or thrust
 | 
			
		||||
 | 
			
		||||
    bool mAttackingOrSpell;
 | 
			
		||||
 | 
			
		||||
    void determineAttackType();
 | 
			
		||||
 | 
			
		||||
    void refreshCurrentAnims(CharacterState idle, CharacterState movement, bool force=false);
 | 
			
		||||
| 
						 | 
				
			
			@ -235,6 +238,8 @@ public:
 | 
			
		|||
    bool isReadyToBlock() const;
 | 
			
		||||
    bool isKnockedOut() const;
 | 
			
		||||
 | 
			
		||||
    void setAttackingOrSpell(bool attackingOrSpell);
 | 
			
		||||
 | 
			
		||||
    /// @see Animation::setActive
 | 
			
		||||
    void setActive(bool active);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,7 +16,7 @@ namespace MWMechanics
 | 
			
		|||
 | 
			
		||||
    CreatureStats::CreatureStats()
 | 
			
		||||
        : mDrawState (DrawState_Nothing), mDead (false), mDied (false), mMurdered(false), mFriendlyHits (0),
 | 
			
		||||
          mTalkedTo (false), mAlarmed (false), mAttacked (false), mAttackingOrSpell(false),
 | 
			
		||||
          mTalkedTo (false), mAlarmed (false), mAttacked (false),
 | 
			
		||||
          mKnockdown(false), mKnockdownOneFrame(false), mKnockdownOverOneFrame(false),
 | 
			
		||||
          mHitRecovery(false), mBlock(false), mMovementFlags(0),
 | 
			
		||||
          mFallHeight(0), mRecalcMagicka(false), mLastRestock(0,0), mGoldPool(0), mActorId(-1),
 | 
			
		||||
| 
						 | 
				
			
			@ -88,11 +88,6 @@ namespace MWMechanics
 | 
			
		|||
        return mMagicEffects;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool CreatureStats::getAttackingOrSpell() const
 | 
			
		||||
    {
 | 
			
		||||
        return mAttackingOrSpell;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int CreatureStats::getLevel() const
 | 
			
		||||
    {
 | 
			
		||||
        return mLevel;
 | 
			
		||||
| 
						 | 
				
			
			@ -212,11 +207,6 @@ namespace MWMechanics
 | 
			
		|||
        mMagicEffects.setModifiers(effects);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void CreatureStats::setAttackingOrSpell(bool attackingOrSpell)
 | 
			
		||||
    {
 | 
			
		||||
        mAttackingOrSpell = attackingOrSpell;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void CreatureStats::setAiSetting (AiSetting index, Stat<int> value)
 | 
			
		||||
    {
 | 
			
		||||
        mAiSettings[index] = value;
 | 
			
		||||
| 
						 | 
				
			
			@ -487,7 +477,6 @@ namespace MWMechanics
 | 
			
		|||
        state.mTalkedTo = mTalkedTo;
 | 
			
		||||
        state.mAlarmed = mAlarmed;
 | 
			
		||||
        state.mAttacked = mAttacked;
 | 
			
		||||
        state.mAttackingOrSpell = mAttackingOrSpell;
 | 
			
		||||
        // TODO: rewrite. does this really need 3 separate bools?
 | 
			
		||||
        state.mKnockdown = mKnockdown;
 | 
			
		||||
        state.mKnockdownOneFrame = mKnockdownOneFrame;
 | 
			
		||||
| 
						 | 
				
			
			@ -534,7 +523,6 @@ namespace MWMechanics
 | 
			
		|||
        mTalkedTo = state.mTalkedTo;
 | 
			
		||||
        mAlarmed = state.mAlarmed;
 | 
			
		||||
        mAttacked = state.mAttacked;
 | 
			
		||||
        mAttackingOrSpell = state.mAttackingOrSpell;
 | 
			
		||||
        // TODO: rewrite. does this really need 3 separate bools?
 | 
			
		||||
        mKnockdown = state.mKnockdown;
 | 
			
		||||
        mKnockdownOneFrame = state.mKnockdownOneFrame;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,7 +40,6 @@ namespace MWMechanics
 | 
			
		|||
        bool mTalkedTo;
 | 
			
		||||
        bool mAlarmed;
 | 
			
		||||
        bool mAttacked;
 | 
			
		||||
        bool mAttackingOrSpell;
 | 
			
		||||
        bool mKnockdown;
 | 
			
		||||
        bool mKnockdownOneFrame;
 | 
			
		||||
        bool mKnockdownOverOneFrame;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,7 +36,8 @@ namespace MWWorld
 | 
			
		|||
        mForwardBackward(0),
 | 
			
		||||
        mTeleported(false),
 | 
			
		||||
        mCurrentCrimeId(-1),
 | 
			
		||||
        mPaidCrimeId(-1)
 | 
			
		||||
        mPaidCrimeId(-1),
 | 
			
		||||
        mAttackingOrSpell(false)
 | 
			
		||||
    {
 | 
			
		||||
        ESM::CellRef cellRef;
 | 
			
		||||
        cellRef.blank();
 | 
			
		||||
| 
						 | 
				
			
			@ -216,6 +217,16 @@ namespace MWWorld
 | 
			
		|||
        mTeleported = teleported;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void Player::setAttackingOrSpell(bool attackingOrSpell)
 | 
			
		||||
    {
 | 
			
		||||
        mAttackingOrSpell = attackingOrSpell;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool Player::getAttackingOrSpell() const
 | 
			
		||||
    {
 | 
			
		||||
        return mAttackingOrSpell;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool Player::isInCombat() {
 | 
			
		||||
        return MWBase::Environment::get().getMechanicsManager()->getActorsFighting(getPlayer()).size() != 0;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -50,6 +50,8 @@ namespace MWWorld
 | 
			
		|||
        MWMechanics::SkillValue mSaveSkills[ESM::Skill::Length];
 | 
			
		||||
        MWMechanics::AttributeValue mSaveAttributes[ESM::Attribute::Length];
 | 
			
		||||
 | 
			
		||||
        bool mAttackingOrSpell;
 | 
			
		||||
 | 
			
		||||
    public:
 | 
			
		||||
 | 
			
		||||
        Player(const ESM::NPC *player);
 | 
			
		||||
| 
						 | 
				
			
			@ -98,6 +100,9 @@ namespace MWWorld
 | 
			
		|||
        bool wasTeleported() const;
 | 
			
		||||
        void setTeleported(bool teleported);
 | 
			
		||||
 | 
			
		||||
        void setAttackingOrSpell(bool attackingOrSpell);
 | 
			
		||||
        bool getAttackingOrSpell() const;
 | 
			
		||||
 | 
			
		||||
        ///Checks all nearby actors to see if anyone has an aipackage against you
 | 
			
		||||
        bool isInCombat();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,8 +39,8 @@ void ESM::CreatureStats::load (ESMReader &esm)
 | 
			
		|||
    if (esm.isNextSub("HOST"))
 | 
			
		||||
        esm.skipHSub(); // Hostile, no longer used
 | 
			
		||||
 | 
			
		||||
    mAttackingOrSpell = false;
 | 
			
		||||
    esm.getHNOT (mAttackingOrSpell, "ATCK");
 | 
			
		||||
    if (esm.isNextSub("ATCK"))
 | 
			
		||||
        esm.skipHSub(); // attackingOrSpell, no longer used
 | 
			
		||||
 | 
			
		||||
    mKnockdown = false;
 | 
			
		||||
    esm.getHNOT (mKnockdown, "KNCK");
 | 
			
		||||
| 
						 | 
				
			
			@ -149,9 +149,6 @@ void ESM::CreatureStats::save (ESMWriter &esm) const
 | 
			
		|||
    if (mAttacked)
 | 
			
		||||
        esm.writeHNT ("ATKD", mAttacked);
 | 
			
		||||
 | 
			
		||||
    if (mAttackingOrSpell)
 | 
			
		||||
        esm.writeHNT ("ATCK", mAttackingOrSpell);
 | 
			
		||||
 | 
			
		||||
    if (mKnockdown)
 | 
			
		||||
        esm.writeHNT ("KNCK", mKnockdown);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -232,7 +229,6 @@ void ESM::CreatureStats::blank()
 | 
			
		|||
    mTalkedTo = false;
 | 
			
		||||
    mAlarmed = false;
 | 
			
		||||
    mAttacked = false;
 | 
			
		||||
    mAttackingOrSpell = false;
 | 
			
		||||
    mKnockdown = false;
 | 
			
		||||
    mKnockdownOneFrame = false;
 | 
			
		||||
    mKnockdownOverOneFrame = false;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,7 +45,6 @@ namespace ESM
 | 
			
		|||
        bool mTalkedTo;
 | 
			
		||||
        bool mAlarmed;
 | 
			
		||||
        bool mAttacked;
 | 
			
		||||
        bool mAttackingOrSpell;
 | 
			
		||||
        bool mKnockdown;
 | 
			
		||||
        bool mKnockdownOneFrame;
 | 
			
		||||
        bool mKnockdownOverOneFrame;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue