Changeset 48

Show
Ignore:
Timestamp:
09/30/09 21:44:28 (3 years ago)
Author:
valroft
Message:

- Some work on bringing spell cast AI support to GenericAI.
- Removed unnecessary code.

Location:
trunk/src/hearthstone-world
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/hearthstone-world/CritterAI.h

    r47 r48  
    3131 
    3232        virtual void OnDamageTaken(Unit * pAttacker, uint32 damage); 
    33         virtual void OnDeath(Unit* pKiller) { BaseAI::OnDeath(pKiller); } 
    34         virtual void OnSpawn() { BaseAI::OnSpawn(); } 
    35         virtual void Update() { BaseAI::Update(); } 
    36  
    37         virtual bool NeedsToResetThreat() { return false; } 
    38         virtual bool NeedToReturnHome() { return false; } 
    39         virtual bool CanMoveToNextWaypoint() { return false; } 
    40  
    41         virtual void OnRemoveInRangeUnit(Unit* u) { BaseAI::OnRemoveInRangeUnit(u); } 
    4233        virtual uint32 GetAIFlags() { return 0; } 
    4334}; 
  • trunk/src/hearthstone-world/GenericAI.cpp

    r47 r48  
    2424        m_lastUpdateTime = 0; 
    2525        m_lastAttackTime = 0; 
     26        m_forceSpell = NULL; 
    2627 
    2728        ai->GetMoveGenerator()->SetThreatReference(&m_threat); 
     
    142143 
    143144        return true; 
     145} 
     146 
     147AI_Spell* GenericAI::GetNextSpell() 
     148{ 
     149        uint32 msTime = getMSTime(); 
     150        AISpellStorage::iterator itr = m_unit->GetAIInterface()->GetAvailableSpellsBegin(); 
     151        for(; itr != m_unit->GetAIInterface()->GetAvailableSpellsEnd(); ++itr) 
     152        { 
     153                AI_Spell* sp = (*itr); 
     154                if( sp->cooldowntime > msTime ) // We're still on cooldown. 
     155                        continue; 
     156 
     157                if( sp->procChance < 100 && !Rand(sp->procChance) ) // It just ain't proccing. 
     158                        continue;  
     159 
     160                // not enough mana? 
     161                if( sp->spell->manaCost && m_unit->GetUInt32Value(UNIT_FIELD_POWER1+POWER_TYPE_MANA) < sp->spell->manaCost ) 
     162                        continue; 
     163 
     164                // not enough mana? 
     165                if( sp->spell->ManaCostPercentage && m_unit->GetManaPct() < sp->spell->ManaCostPercentage ) 
     166                        continue; 
     167 
     168                ++sp->procCount; 
     169                sp->cooldowntime = msTime + sp->cooldown; 
     170 
     171                return sp; 
     172        } 
     173 
     174        return NULL; 
    144175} 
    145176 
     
    172203 
    173204        // Attack our current target, if we have one. 
    174         if( m_threat.GetAttackTarget() && IsInAttackRange(m_threat.GetAttackTarget()) ) 
     205        if( m_threat.GetAttackTarget() && CanMeleeAttack(m_threat.GetAttackTarget()) ) 
    175206        { 
    176207                // just because we're in range doesn't mean we are good to go. 
     
    199230} 
    200231 
    201 bool GenericAI::IsInAttackRange(Unit *u) 
    202 { 
    203         return m_unit->GetAIInterface()->IsInAttackRange(u); 
     232bool GenericAI::CanMeleeAttack(Unit *u) 
     233{ 
     234        return m_unit->GetAIInterface()->IsInAttackRange(u) && !m_unit->GetCurrentSpell(); 
    204235} 
    205236 
  • trunk/src/hearthstone-world/GenericAI.h

    r47 r48  
    3939        virtual bool NeedToReturnHome(); 
    4040        virtual bool MeetsAttackCriteria(Unit* u); 
    41         virtual bool IsInAttackRange(Unit* u); 
     41        virtual bool CanMeleeAttack(Unit* u); 
    4242        virtual uint32 GetAttackTime(); 
    4343 
     
    4747        virtual bool CanMoveToNextWaypoint(); 
    4848 
     49        AI_Spell* GetNextSpell(); 
     50 
    4951private: 
    5052        ThreatTable m_threat; 
     
    5254        uint32 m_lastUpdateTime; 
    5355        uint32 m_lastAttackTime; 
     56        AI_Spell* m_forceSpell; 
    5457}; 
    5558 
  • trunk/src/hearthstone-world/GuardianAI.h

    r47 r48  
    3333                pUnit->GetAIInterface()->GetMoveGenerator()->SetBehavior(MOVEMENT_GENERATOR_FOLLOW); 
    3434        } 
    35  
    36         virtual void OnDamageTaken(Unit * pAttacker, uint32 damage) { GenericAI::OnDamageTaken(pAttacker, damage); } 
    37         virtual void OnDeath(Unit* pKiller) { GenericAI::OnDeath(pKiller); } 
    3835        virtual void OnSpawn() { GenericAI::OnSpawn(); } 
    3936        virtual void Update() 
     
    4643                GenericAI::Update(); 
    4744        } 
    48  
    49         virtual bool IsAttackOrMoveEligible() { return GenericAI::IsAttackOrMoveEligible(); } 
    5045        virtual bool NeedsToResetThreat() { return false; } 
    5146        virtual bool NeedToReturnHome() { return false; } 
    52         virtual bool MeetsAttackCriteria(Unit* u) { return GenericAI::MeetsAttackCriteria(u); } 
    53         virtual bool IsInAttackRange(Unit* u) { return GenericAI::IsInAttackRange(u); } 
    54         virtual uint32 GetAttackTime() { return GenericAI::GetAttackTime(); } 
    5547        virtual bool CanMoveToNextWaypoint() { return false; } 
    5648 
    57         virtual void OnRemoveInRangeUnit(Unit* u) { GenericAI::OnRemoveInRangeUnit(u); } 
    5849        virtual uint32 GetAIFlags() { return AI_FLAG_GENERIC_AI | AI_FLAG_GUARDIAN_AI; } 
    59         virtual ThreatTable* GetThreat() { return GenericAI::GetThreat(); } 
    6050 
    6151        virtual void SetOwner(Unit* u) { m_owner = u; m_unit->GetAIInterface()->GetMoveGenerator()->SetFollowTarget(m_owner); }