From 843f789f58b73b5af6d8be46fe97448a341ceb8d Mon Sep 17 00:00:00 2001 From: Neo2003 Date: Sun, 5 Oct 2008 12:10:02 -0500 Subject: [svn] * Added fleeing and call assistance in script until we move all AI functions to core --HG-- branch : trunk --- src/bindings/scripts/include/sc_creature.h | 3 ++ .../scripts/scripts/creature/mob_event_ai.cpp | 25 ++++++++++++++-- src/game/Creature.cpp | 34 ++++++++++++++++++++++ src/game/Creature.h | 1 + 4 files changed, 60 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/bindings/scripts/include/sc_creature.h b/src/bindings/scripts/include/sc_creature.h index 9433a6b7331..949689bffc7 100644 --- a/src/bindings/scripts/include/sc_creature.h +++ b/src/bindings/scripts/include/sc_creature.h @@ -72,6 +72,9 @@ struct MANGOS_DLL_DECL ScriptedAI : public CreatureAI //Bool for if we are in combat or not bool InCombat; + //For fleeing + bool IsFleeing; + //************* //Pure virtual functions //************* diff --git a/src/bindings/scripts/scripts/creature/mob_event_ai.cpp b/src/bindings/scripts/scripts/creature/mob_event_ai.cpp index 4e772ed4b23..4298156af84 100644 --- a/src/bindings/scripts/scripts/creature/mob_event_ai.cpp +++ b/src/bindings/scripts/scripts/creature/mob_event_ai.cpp @@ -79,6 +79,7 @@ struct MANGOS_DLL_DECL Mob_EventAI : public ScriptedAI bool MeleeEnabled; //If we allow melee auto attack uint32 AttackDistance; //Distance to attack from float AttackAngle; //Angle of attack + uint32 TimetoFleeLeft; //For fleeing void AttackTarget(Unit* pTarget, bool Follow) { @@ -774,8 +775,9 @@ struct MANGOS_DLL_DECL Mob_EventAI : public ScriptedAI break; case ACTION_T_FLEE: { - //TODO: Replace with Flee movement generator - m_creature->CastSpell(m_creature, SPELL_RUN_AWAY, true); + TimetoFleeLeft = 8000; + m_creature->DoFleeToGetAssistance(); + IsFleeing = true; } break; case ACTION_T_QUEST_EVENT_ALL: @@ -954,6 +956,7 @@ struct MANGOS_DLL_DECL Mob_EventAI : public ScriptedAI void JustRespawned() { InCombat = false; + IsFleeing = false; Reset(); //Handle Spawned Events @@ -1014,6 +1017,7 @@ struct MANGOS_DLL_DECL Mob_EventAI : public ScriptedAI m_creature->SetLootRecipient(NULL); InCombat = false; + IsFleeing = false; Reset(); //Handle Evade events @@ -1034,6 +1038,7 @@ struct MANGOS_DLL_DECL Mob_EventAI : public ScriptedAI void JustDied(Unit* killer) { InCombat = false; + IsFleeing = false; Reset(); //Handle Evade events @@ -1131,7 +1136,7 @@ struct MANGOS_DLL_DECL Mob_EventAI : public ScriptedAI if (!who) return; - if (who->isTargetableForAttack()) + if (who->isTargetableForAttack() && !IsFleeing) { //Begin melee attack if we are within range if (CombatMovementEnabled) @@ -1225,6 +1230,20 @@ struct MANGOS_DLL_DECL Mob_EventAI : public ScriptedAI if (!m_creature->isAlive()) return; + if ((TimetoFleeLeft < diff || (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() != POINT_MOTION_TYPE && m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() != FLEEING_MOTION_TYPE)) && IsFleeing) + { + m_creature->GetMotionMaster()->Clear(false); + m_creature->SetNoCallAssistence(false); + m_creature->CallAssistence(); + m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim()); + IsFleeing = false; + } + else + TimetoFleeLeft -= diff; + + if(IsFleeing) + return; + //Events are only updated once every EVENT_UPDATE_TIME ms to prevent lag with large amount of events if (EventUpdateTime < diff) { diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index b8943f55061..d0800c9b77f 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -1644,6 +1644,40 @@ bool Creature::IsVisibleInGridForPlayer(Player* pl) const return false; } +void Creature::DoFleeToGetAssistance(float radius) // Optional parameter +{ + if (!getVictim()) + return; + + Creature* pCreature = NULL; + + CellPair p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY())); + Cell cell(p); + cell.data.Part.reserved = ALL_DISTRICT; + cell.SetNoCreate(); + + MaNGOS::NearestAssistCreatureInCreatureRangeCheck u_check(this,getVictim(),radius); + MaNGOS::CreatureLastSearcher searcher(pCreature, u_check); + + TypeContainerVisitor, GridTypeMapContainer > grid_creature_searcher(searcher); + + CellLock cell_lock(cell, p); + cell_lock->Visit(cell_lock, grid_creature_searcher, *(GetMap())); + + if(!GetMotionMaster()->empty() && (GetMotionMaster()->GetCurrentMovementGeneratorType() != POINT_MOTION_TYPE)) + GetMotionMaster()->Clear(false); + if(pCreature == NULL) + { + GetMotionMaster()->MoveIdle(); + GetMotionMaster()->MoveFleeing(getVictim()); + } + else + { + GetMotionMaster()->MoveIdle(); + GetMotionMaster()->MovePoint(0,pCreature->GetPositionX(),pCreature->GetPositionY(),pCreature->GetPositionZ()); + } +} + void Creature::CallAssistence() { if( !m_AlreadyCallAssistence && getVictim() && !isPet() && !isCharmed()) diff --git a/src/game/Creature.h b/src/game/Creature.h index 394d75f5355..2ade7c48695 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -510,6 +510,7 @@ class MANGOS_DLL_SPEC Creature : public Unit void CallAssistence(); void SetNoCallAssistence(bool val) { m_AlreadyCallAssistence = val; } + void DoFleeToGetAssistance(float radius = 50); MovementGeneratorType GetDefaultMovementType() const { return m_defaultMovementType; } void SetDefaultMovementType(MovementGeneratorType mgt) { m_defaultMovementType = mgt; } -- cgit v1.2.3