[9362] Make specs work at least for action bars
[getmangos.git] / src / game / ReactorAI.cpp
blob2ea08d446820833bcffcb267837bbe9aca52789a
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "ByteBuffer.h"
20 #include "ReactorAI.h"
21 #include "Errors.h"
22 #include "Creature.h"
23 #include "Log.h"
24 #include "ObjectAccessor.h"
26 #define REACTOR_VISIBLE_RANGE (26.46f)
28 int
29 ReactorAI::Permissible(const Creature *creature)
31 if( creature->isCivilian() || creature->IsNeutralToAll() )
32 return PERMIT_BASE_REACTIVE;
34 return PERMIT_BASE_NO;
37 void
38 ReactorAI::MoveInLineOfSight(Unit *)
42 void
43 ReactorAI::AttackStart(Unit *p)
45 if(!p)
46 return;
48 if(m_creature->Attack(p,true))
50 DEBUG_LOG("Tag unit GUID: %u (TypeId: %u) as a victim", p->GetGUIDLow(), p->GetTypeId());
51 i_victimGuid = p->GetGUID();
52 m_creature->AddThreat(p);
54 m_creature->SetInCombatWith(p);
55 p->SetInCombatWith(m_creature);
57 m_creature->GetMotionMaster()->MoveChase(p);
61 bool
62 ReactorAI::IsVisible(Unit *) const
64 return false;
67 void
68 ReactorAI::UpdateAI(const uint32 /*time_diff*/)
70 // update i_victimGuid if i_creature.getVictim() !=0 and changed
71 if(!m_creature->SelectHostileTarget() || !m_creature->getVictim())
72 return;
74 i_victimGuid = m_creature->getVictim()->GetGUID();
76 if( m_creature->isAttackReady() )
78 if( m_creature->IsWithinDistInMap(m_creature->getVictim(), ATTACK_DISTANCE))
80 m_creature->AttackerStateUpdate(m_creature->getVictim());
81 m_creature->resetAttackTimer();
86 void
87 ReactorAI::EnterEvadeMode()
89 if (!m_creature->isAlive())
91 DEBUG_LOG("Creature stopped attacking, he is dead [guid=%u]", m_creature->GetGUIDLow());
92 m_creature->GetMotionMaster()->MovementExpired();
93 m_creature->GetMotionMaster()->MoveIdle();
94 i_victimGuid = 0;
95 m_creature->CombatStop(true);
96 m_creature->DeleteThreatList();
97 return;
100 Unit* victim = ObjectAccessor::GetUnit(*m_creature, i_victimGuid );
102 if (!victim)
104 DEBUG_LOG("Creature stopped attacking, no victim [guid=%u]", m_creature->GetGUIDLow());
106 else if (victim->HasStealthAura())
108 DEBUG_LOG("Creature stopped attacking, victim is in stealth [guid=%u]", m_creature->GetGUIDLow());
110 else if (victim->isInFlight())
112 DEBUG_LOG("Creature stopped attacking, victim is in flight [guid=%u]", m_creature->GetGUIDLow());
114 else
116 DEBUG_LOG("Creature stopped attacking, victim %s [guid=%u]", victim->isAlive() ? "out run him" : "is dead", m_creature->GetGUIDLow());
119 m_creature->RemoveAllAuras();
120 m_creature->DeleteThreatList();
121 i_victimGuid = 0;
122 m_creature->CombatStop(true);
123 m_creature->SetLootRecipient(NULL);
125 // Remove ChaseMovementGenerator from MotionMaster stack list, and add HomeMovementGenerator instead
126 if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE)
127 m_creature->GetMotionMaster()->MoveTargetedHome();