[10277] Use typedef CreatureEventAIList, some other code style cleanups in EventAI code.

This commit is contained in:
VladimirMangos 2010-07-27 12:19:05 +04:00
parent 8827c72a79
commit 61d076442f
3 changed files with 103 additions and 101 deletions

View file

@ -55,11 +55,10 @@ int CreatureEventAI::Permissible(const Creature *creature)
CreatureEventAI::CreatureEventAI(Creature *c ) : CreatureAI(c)
{
// Need make copy for filter unneeded steps and safe in case table reload
CreatureEventAI_Event_Map::const_iterator CreatureEvents = sEventAIMgr.GetCreatureEventAIMap().find(m_creature->GetEntry());
if (CreatureEvents != sEventAIMgr.GetCreatureEventAIMap().end())
CreatureEventAI_Event_Map::const_iterator creatureEventsItr = sEventAIMgr.GetCreatureEventAIMap().find(m_creature->GetEntry());
if (creatureEventsItr != sEventAIMgr.GetCreatureEventAIMap().end())
{
std::vector<CreatureEventAI_Event>::const_iterator i;
for (i = (*CreatureEvents).second.begin(); i != (*CreatureEvents).second.end(); ++i)
for (CreatureEventAI_Event_Vec::const_iterator i = (*creatureEventsItr).second.begin(); i != (*creatureEventsItr).second.end(); ++i)
{
//Debug check
@ -72,32 +71,32 @@ CreatureEventAI::CreatureEventAI(Creature *c ) : CreatureAI(c)
if ((1 << (m_creature->GetMap()->GetSpawnMode()+1)) & (*i).event_flags)
{
//event flagged for instance mode
CreatureEventAIList.push_back(CreatureEventAIHolder(*i));
m_CreatureEventAIList.push_back(CreatureEventAIHolder(*i));
}
continue;
}
CreatureEventAIList.push_back(CreatureEventAIHolder(*i));
else
m_CreatureEventAIList.push_back(CreatureEventAIHolder(*i));
}
//EventMap had events but they were not added because they must be for instance
if (CreatureEventAIList.empty())
if (m_CreatureEventAIList.empty())
sLog.outError("CreatureEventAI: Creature %u has events but no events added to list because of instance flags.", m_creature->GetEntry());
}
else
sLog.outError("CreatureEventAI: EventMap for Creature %u is empty but creature is using CreatureEventAI.", m_creature->GetEntry());
bEmptyList = CreatureEventAIList.empty();
Phase = 0;
CombatMovementEnabled = true;
MeleeEnabled = true;
AttackDistance = 0.0f;
AttackAngle = 0.0f;
m_bEmptyList = m_CreatureEventAIList.empty();
m_Phase = 0;
m_CombatMovementEnabled = true;
m_MeleeEnabled = true;
m_AttackDistance = 0.0f;
m_AttackAngle = 0.0f;
InvinceabilityHpLevel = 0;
m_InvinceabilityHpLevel = 0;
//Handle Spawned Events
if (!bEmptyList)
if (!m_bEmptyList)
{
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i)
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
if (SpawnedEventConditionsCheck((*i).Event))
ProcessEvent(*i);
}
@ -110,7 +109,7 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
return false;
//Check the inverse phase mask (event doesn't trigger if current phase bit is set in mask)
if (pHolder.Event.event_inverse_phase_mask & (1 << Phase))
if (pHolder.Event.event_inverse_phase_mask & (1 << m_Phase))
return false;
CreatureEventAI_Event const& event = pHolder.Event;
@ -476,11 +475,11 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
{
case CHASE_MOTION_TYPE:
case FOLLOW_MOTION_TYPE:
AttackDistance = 0.0f;
AttackAngle = 0.0f;
m_AttackDistance = 0.0f;
m_AttackAngle = 0.0f;
m_creature->GetMotionMaster()->Clear(false);
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), AttackDistance, AttackAngle);
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_AttackDistance, m_AttackAngle);
break;
}
}
@ -562,17 +561,17 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
target->RemoveFlag(UNIT_FIELD_FLAGS, action.unit_flag.value);
break;
case ACTION_T_AUTO_ATTACK:
MeleeEnabled = action.auto_attack.state != 0;
m_MeleeEnabled = action.auto_attack.state != 0;
break;
case ACTION_T_COMBAT_MOVEMENT:
// ignore no affect case
if(CombatMovementEnabled==(action.combat_movement.state!=0))
if(m_CombatMovementEnabled==(action.combat_movement.state!=0))
return;
CombatMovementEnabled = action.combat_movement.state != 0;
m_CombatMovementEnabled = action.combat_movement.state != 0;
//Allow movement (create new targeted movement gen only if idle)
if (CombatMovementEnabled)
if (m_CombatMovementEnabled)
{
if(action.combat_movement.melee && m_creature->isInCombat())
if(Unit* victim = m_creature->getVictim())
@ -581,7 +580,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == IDLE_MOTION_TYPE)
{
m_creature->GetMotionMaster()->Clear(false);
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), AttackDistance, AttackAngle);
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_AttackDistance, m_AttackAngle);
}
}
else
@ -599,23 +598,23 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
}
break;
case ACTION_T_SET_PHASE:
Phase = action.set_phase.phase;
m_Phase = action.set_phase.phase;
break;
case ACTION_T_INC_PHASE:
{
int32 new_phase = int32(Phase)+action.set_inc_phase.step;
int32 new_phase = int32(m_Phase)+action.set_inc_phase.step;
if (new_phase < 0)
{
sLog.outErrorDb( "CreatureEventAI: Event %d decrease Phase under 0. CreatureEntry = %d", EventId, m_creature->GetEntry());
Phase = 0;
m_Phase = 0;
}
else if (new_phase >= MAX_PHASE)
{
sLog.outErrorDb( "CreatureEventAI: Event %d incremented Phase above %u. Phase mask cannot be used with phases past %u. CreatureEntry = %d", EventId, MAX_PHASE-1, MAX_PHASE-1, m_creature->GetEntry());
Phase = MAX_PHASE-1;
m_Phase = MAX_PHASE-1;
}
else
Phase = new_phase;
m_Phase = new_phase;
break;
}
@ -647,25 +646,25 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
target->RemoveAurasDueToSpell(action.remove_aura.spellId);
break;
case ACTION_T_RANGED_MOVEMENT:
AttackDistance = (float)action.ranged_movement.distance;
AttackAngle = action.ranged_movement.angle/180.0f*M_PI_F;
m_AttackDistance = (float)action.ranged_movement.distance;
m_AttackAngle = action.ranged_movement.angle/180.0f*M_PI_F;
if (CombatMovementEnabled)
if (m_CombatMovementEnabled)
{
if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE)
{
//Drop current movement gen
m_creature->GetMotionMaster()->Clear(false);
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), AttackDistance, AttackAngle);
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_AttackDistance, m_AttackAngle);
}
}
break;
case ACTION_T_RANDOM_PHASE:
Phase = GetRandActionParam(rnd, action.random_phase.phase1, action.random_phase.phase2, action.random_phase.phase3);
m_Phase = GetRandActionParam(rnd, action.random_phase.phase1, action.random_phase.phase2, action.random_phase.phase3);
break;
case ACTION_T_RANDOM_PHASE_RANGE:
if (action.random_phase_range.phaseMax > action.random_phase_range.phaseMin)
Phase = action.random_phase_range.phaseMin + (rnd % (action.random_phase_range.phaseMax - action.random_phase_range.phaseMin));
m_Phase = action.random_phase_range.phaseMin + (rnd % (action.random_phase_range.phaseMax - action.random_phase_range.phaseMin));
else
sLog.outErrorDb( "CreatureEventAI: ACTION_T_RANDOM_PHASE_RANGE cannot have Param2 <= Param1. Divide by Zero. Event = %d. CreatureEntry = %d", EventId, m_creature->GetEntry());
break;
@ -778,9 +777,9 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
case ACTION_T_SET_INVINCIBILITY_HP_LEVEL:
{
if(action.invincibility_hp_level.is_percent)
InvinceabilityHpLevel = m_creature->GetMaxHealth()*action.invincibility_hp_level.hp_level/100;
m_InvinceabilityHpLevel = m_creature->GetMaxHealth()*action.invincibility_hp_level.hp_level/100;
else
InvinceabilityHpLevel = action.invincibility_hp_level.hp_level;
m_InvinceabilityHpLevel = action.invincibility_hp_level.hp_level;
break;
}
}
@ -790,25 +789,25 @@ void CreatureEventAI::JustRespawned()
{
Reset();
if (bEmptyList)
if (m_bEmptyList)
return;
//Handle Spawned Events
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i)
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
if (SpawnedEventConditionsCheck((*i).Event))
ProcessEvent(*i);
}
void CreatureEventAI::Reset()
{
EventUpdateTime = EVENT_UPDATE_TIME;
EventDiff = 0;
m_EventUpdateTime = EVENT_UPDATE_TIME;
m_EventDiff = 0;
if (bEmptyList)
if (m_bEmptyList)
return;
//Reset all events to enabled
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i)
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{
CreatureEventAI_Event const& event = (*i).Event;
switch (event.event_type)
@ -833,9 +832,9 @@ void CreatureEventAI::JustReachedHome()
{
m_creature->LoadCreaturesAddon();
if (!bEmptyList)
if (!m_bEmptyList)
{
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i)
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{
if ((*i).Event.event_type == EVENT_T_REACHED_HOME)
ProcessEvent(*i);
@ -856,11 +855,11 @@ void CreatureEventAI::EnterEvadeMode()
m_creature->SetLootRecipient(NULL);
if (bEmptyList)
if (m_bEmptyList)
return;
//Handle Evade events
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i)
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{
if ((*i).Event.event_type == EVENT_T_EVADE)
ProcessEvent(*i);
@ -878,26 +877,26 @@ void CreatureEventAI::JustDied(Unit* killer)
m_creature->SendZoneUnderAttackMessage(pKiller);
}
if (bEmptyList)
if (m_bEmptyList)
return;
//Handle Evade events
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i)
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{
if ((*i).Event.event_type == EVENT_T_DEATH)
ProcessEvent(*i, killer);
}
// reset phase after any death state events
Phase = 0;
m_Phase = 0;
}
void CreatureEventAI::KilledUnit(Unit* victim)
{
if (bEmptyList || victim->GetTypeId() != TYPEID_PLAYER)
if (m_bEmptyList || victim->GetTypeId() != TYPEID_PLAYER)
return;
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i)
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{
if ((*i).Event.event_type == EVENT_T_KILL)
ProcessEvent(*i, victim);
@ -906,10 +905,10 @@ void CreatureEventAI::KilledUnit(Unit* victim)
void CreatureEventAI::JustSummoned(Creature* pUnit)
{
if (bEmptyList || !pUnit)
if (m_bEmptyList || !pUnit)
return;
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i)
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{
if ((*i).Event.event_type == EVENT_T_SUMMONED_UNIT)
ProcessEvent(*i, pUnit);
@ -918,10 +917,10 @@ void CreatureEventAI::JustSummoned(Creature* pUnit)
void CreatureEventAI::SummonedCreatureJustDied(Creature* pUnit)
{
if (bEmptyList || !pUnit)
if (m_bEmptyList || !pUnit)
return;
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i)
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{
if ((*i).Event.event_type == EVENT_T_SUMMONED_JUST_DIED)
ProcessEvent(*i, pUnit);
@ -930,10 +929,10 @@ void CreatureEventAI::SummonedCreatureJustDied(Creature* pUnit)
void CreatureEventAI::SummonedCreatureDespawn(Creature* pUnit)
{
if (bEmptyList || !pUnit)
if (m_bEmptyList || !pUnit)
return;
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i)
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{
if ((*i).Event.event_type == EVENT_T_SUMMONED_JUST_DESPAWN)
ProcessEvent(*i, pUnit);
@ -943,9 +942,9 @@ void CreatureEventAI::SummonedCreatureDespawn(Creature* pUnit)
void CreatureEventAI::EnterCombat(Unit *enemy)
{
//Check for on combat start events
if (!bEmptyList)
if (!m_bEmptyList)
{
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i)
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{
CreatureEventAI_Event const& event = (*i).Event;
switch (event.event_type)
@ -968,8 +967,8 @@ void CreatureEventAI::EnterCombat(Unit *enemy)
}
}
EventUpdateTime = EVENT_UPDATE_TIME;
EventDiff = 0;
m_EventUpdateTime = EVENT_UPDATE_TIME;
m_EventDiff = 0;
}
void CreatureEventAI::AttackStart(Unit *who)
@ -977,15 +976,15 @@ void CreatureEventAI::AttackStart(Unit *who)
if (!who)
return;
if (m_creature->Attack(who, MeleeEnabled))
if (m_creature->Attack(who, m_MeleeEnabled))
{
m_creature->AddThreat(who);
m_creature->SetInCombatWith(who);
who->SetInCombatWith(m_creature);
if (CombatMovementEnabled)
if (m_CombatMovementEnabled)
{
m_creature->GetMotionMaster()->MoveChase(who, AttackDistance, AttackAngle);
m_creature->GetMotionMaster()->MoveChase(who, m_AttackDistance, m_AttackAngle);
}
else
{
@ -1001,9 +1000,9 @@ void CreatureEventAI::MoveInLineOfSight(Unit *who)
return;
//Check for OOC LOS Event
if (!bEmptyList && !m_creature->getVictim())
if (!m_bEmptyList && !m_creature->getVictim())
{
for (std::vector<CreatureEventAIHolder>::iterator itr = CreatureEventAIList.begin(); itr != CreatureEventAIList.end(); ++itr)
for (CreatureEventAIList::iterator itr = m_CreatureEventAIList.begin(); itr != m_CreatureEventAIList.end(); ++itr)
{
if ((*itr).Event.event_type == EVENT_T_OOC_LOS)
{
@ -1051,10 +1050,10 @@ void CreatureEventAI::MoveInLineOfSight(Unit *who)
void CreatureEventAI::SpellHit(Unit* pUnit, const SpellEntry* pSpell)
{
if (bEmptyList)
if (m_bEmptyList)
return;
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i)
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
if ((*i).Event.event_type == EVENT_T_SPELLHIT)
//If spell id matches (or no spell id) & if spell school matches (or no spell school)
if (!(*i).Event.spell_hit.spellId || pSpell->Id == (*i).Event.spell_hit.spellId)
@ -1071,24 +1070,24 @@ void CreatureEventAI::UpdateAI(const uint32 diff)
if (!m_creature->isAlive())
return;
if (!bEmptyList)
if (!m_bEmptyList)
{
//Events are only updated once every EVENT_UPDATE_TIME ms to prevent lag with large amount of events
if (EventUpdateTime < diff)
if (m_EventUpdateTime < diff)
{
EventDiff += diff;
m_EventDiff += diff;
//Check for time based events
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i)
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{
//Decrement Timers
if ((*i).Time)
{
if ((*i).Time > EventDiff)
if ((*i).Time > m_EventDiff)
{
//Do not decrement timers if event cannot trigger in this phase
if (!((*i).Event.event_inverse_phase_mask & (1 << Phase)))
(*i).Time -= EventDiff;
if (!((*i).Event.event_inverse_phase_mask & (1 << m_Phase)))
(*i).Time -= m_EventDiff;
//Skip processing of events that have time remaining
continue;
@ -1122,18 +1121,18 @@ void CreatureEventAI::UpdateAI(const uint32 diff)
}
}
EventDiff = 0;
EventUpdateTime = EVENT_UPDATE_TIME;
m_EventDiff = 0;
m_EventUpdateTime = EVENT_UPDATE_TIME;
}
else
{
EventDiff += diff;
EventUpdateTime -= diff;
m_EventDiff += diff;
m_EventUpdateTime -= diff;
}
}
//Melee Auto-Attack
if (Combat && MeleeEnabled)
if (Combat && m_MeleeEnabled)
DoMeleeAttackIfReady();
}
@ -1340,10 +1339,10 @@ bool CreatureEventAI::CanCast(Unit* Target, SpellEntry const *Spell, bool Trigge
void CreatureEventAI::ReceiveEmote(Player* pPlayer, uint32 text_emote)
{
if (bEmptyList)
if (m_bEmptyList)
return;
for (std::vector<CreatureEventAIHolder>::iterator itr = CreatureEventAIList.begin(); itr != CreatureEventAIList.end(); ++itr)
for (CreatureEventAIList::iterator itr = m_CreatureEventAIList.begin(); itr != m_CreatureEventAIList.end(); ++itr)
{
if ((*itr).Event.event_type == EVENT_T_RECEIVE_EMOTE)
{
@ -1362,12 +1361,12 @@ void CreatureEventAI::ReceiveEmote(Player* pPlayer, uint32 text_emote)
void CreatureEventAI::DamageTaken( Unit* /*done_by*/, uint32& damage )
{
if(InvinceabilityHpLevel > 0 && m_creature->GetHealth() < InvinceabilityHpLevel+damage)
if(m_InvinceabilityHpLevel > 0 && m_creature->GetHealth() < m_InvinceabilityHpLevel+damage)
{
if(m_creature->GetHealth() <= InvinceabilityHpLevel)
if(m_creature->GetHealth() <= m_InvinceabilityHpLevel)
damage = 0;
else
damage = m_creature->GetHealth() - InvinceabilityHpLevel;
damage = m_creature->GetHealth() - m_InvinceabilityHpLevel;
}
}