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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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