Changeset 48
- Timestamp:
- 09/30/09 21:44:28 (3 years ago)
- Location:
- trunk/src/hearthstone-world
- Files:
-
- 4 modified
-
CritterAI.h (modified) (1 diff)
-
GenericAI.cpp (modified) (4 diffs)
-
GenericAI.h (modified) (3 diffs)
-
GuardianAI.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/hearthstone-world/CritterAI.h
r47 r48 31 31 32 32 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); }42 33 virtual uint32 GetAIFlags() { return 0; } 43 34 }; -
trunk/src/hearthstone-world/GenericAI.cpp
r47 r48 24 24 m_lastUpdateTime = 0; 25 25 m_lastAttackTime = 0; 26 m_forceSpell = NULL; 26 27 27 28 ai->GetMoveGenerator()->SetThreatReference(&m_threat); … … 142 143 143 144 return true; 145 } 146 147 AI_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; 144 175 } 145 176 … … 172 203 173 204 // 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()) ) 175 206 { 176 207 // just because we're in range doesn't mean we are good to go. … … 199 230 } 200 231 201 bool GenericAI:: IsInAttackRange(Unit *u)202 { 203 return m_unit->GetAIInterface()->IsInAttackRange(u) ;232 bool GenericAI::CanMeleeAttack(Unit *u) 233 { 234 return m_unit->GetAIInterface()->IsInAttackRange(u) && !m_unit->GetCurrentSpell(); 204 235 } 205 236 -
trunk/src/hearthstone-world/GenericAI.h
r47 r48 39 39 virtual bool NeedToReturnHome(); 40 40 virtual bool MeetsAttackCriteria(Unit* u); 41 virtual bool IsInAttackRange(Unit* u);41 virtual bool CanMeleeAttack(Unit* u); 42 42 virtual uint32 GetAttackTime(); 43 43 … … 47 47 virtual bool CanMoveToNextWaypoint(); 48 48 49 AI_Spell* GetNextSpell(); 50 49 51 private: 50 52 ThreatTable m_threat; … … 52 54 uint32 m_lastUpdateTime; 53 55 uint32 m_lastAttackTime; 56 AI_Spell* m_forceSpell; 54 57 }; 55 58 -
trunk/src/hearthstone-world/GuardianAI.h
r47 r48 33 33 pUnit->GetAIInterface()->GetMoveGenerator()->SetBehavior(MOVEMENT_GENERATOR_FOLLOW); 34 34 } 35 36 virtual void OnDamageTaken(Unit * pAttacker, uint32 damage) { GenericAI::OnDamageTaken(pAttacker, damage); }37 virtual void OnDeath(Unit* pKiller) { GenericAI::OnDeath(pKiller); }38 35 virtual void OnSpawn() { GenericAI::OnSpawn(); } 39 36 virtual void Update() … … 46 43 GenericAI::Update(); 47 44 } 48 49 virtual bool IsAttackOrMoveEligible() { return GenericAI::IsAttackOrMoveEligible(); }50 45 virtual bool NeedsToResetThreat() { return false; } 51 46 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(); }55 47 virtual bool CanMoveToNextWaypoint() { return false; } 56 48 57 virtual void OnRemoveInRangeUnit(Unit* u) { GenericAI::OnRemoveInRangeUnit(u); }58 49 virtual uint32 GetAIFlags() { return AI_FLAG_GENERIC_AI | AI_FLAG_GUARDIAN_AI; } 59 virtual ThreatTable* GetThreat() { return GenericAI::GetThreat(); }60 50 61 51 virtual void SetOwner(Unit* u) { m_owner = u; m_unit->GetAIInterface()->GetMoveGenerator()->SetFollowTarget(m_owner); }