Changeset 14 for trunk

Show
Ignore:
Timestamp:
11/19/08 13:23:07 (17 years ago)
Author:
yumileroy
Message:

[svn] * Added fleeing and call assistance in script until we move all AI functions to core

Original author: Neo2003
Date: 2008-10-05 12:10:02-05:00

Location:
trunk/src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/bindings/scripts/include/sc_creature.h

    r13 r14  
    7272    //Bool for if we are in combat or not 
    7373    bool InCombat; 
     74 
     75    //For fleeing 
     76    bool IsFleeing; 
    7477 
    7578    //************* 
  • trunk/src/bindings/scripts/scripts/creature/mob_event_ai.cpp

    r6 r14  
    8080    uint32 AttackDistance;                                  //Distance to attack from 
    8181    float AttackAngle;                                      //Angle of attack 
     82    uint32 TimetoFleeLeft;                                  //For fleeing 
    8283 
    8384    void AttackTarget(Unit* pTarget, bool Follow) 
     
    775776        case ACTION_T_FLEE: 
    776777            { 
    777                 //TODO: Replace with Flee movement generator 
    778                 m_creature->CastSpell(m_creature, SPELL_RUN_AWAY, true); 
     778                TimetoFleeLeft = 8000; 
     779                m_creature->DoFleeToGetAssistance(); 
     780                IsFleeing = true; 
    779781            } 
    780782            break; 
     
    955957    { 
    956958        InCombat = false; 
     959        IsFleeing = false; 
    957960        Reset(); 
    958961 
     
    10151018 
    10161019        InCombat = false; 
     1020        IsFleeing = false; 
    10171021        Reset(); 
    10181022 
     
    10351039    { 
    10361040        InCombat = false; 
     1041        IsFleeing = false; 
    10371042        Reset(); 
    10381043 
     
    11321137            return; 
    11331138 
    1134         if (who->isTargetableForAttack()) 
     1139        if (who->isTargetableForAttack() && !IsFleeing) 
    11351140        { 
    11361141            //Begin melee attack if we are within range 
     
    12241229        //Must return if creature isn't alive. Normally select hostil target and get victim prevent this 
    12251230        if (!m_creature->isAlive()) 
     1231            return; 
     1232 
     1233        if ((TimetoFleeLeft < diff || (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() != POINT_MOTION_TYPE && m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() != FLEEING_MOTION_TYPE)) && IsFleeing) 
     1234        { 
     1235            m_creature->GetMotionMaster()->Clear(false); 
     1236            m_creature->SetNoCallAssistence(false); 
     1237            m_creature->CallAssistence(); 
     1238            m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim()); 
     1239            IsFleeing = false; 
     1240        }  
     1241        else 
     1242            TimetoFleeLeft -= diff; 
     1243 
     1244        if(IsFleeing) 
    12261245            return; 
    12271246 
  • trunk/src/game/Creature.cpp

    r6 r14  
    16451645} 
    16461646 
     1647void Creature::DoFleeToGetAssistance(float radius) // Optional parameter 
     1648{ 
     1649    if (!getVictim()) 
     1650        return; 
     1651 
     1652    Creature* pCreature = NULL; 
     1653 
     1654    CellPair p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY())); 
     1655    Cell cell(p); 
     1656    cell.data.Part.reserved = ALL_DISTRICT; 
     1657    cell.SetNoCreate(); 
     1658 
     1659    MaNGOS::NearestAssistCreatureInCreatureRangeCheck u_check(this,getVictim(),radius); 
     1660    MaNGOS::CreatureLastSearcher<MaNGOS::NearestAssistCreatureInCreatureRangeCheck> searcher(pCreature, u_check); 
     1661 
     1662    TypeContainerVisitor<MaNGOS::CreatureLastSearcher<MaNGOS::NearestAssistCreatureInCreatureRangeCheck>, GridTypeMapContainer >  grid_creature_searcher(searcher); 
     1663 
     1664    CellLock<GridReadGuard> cell_lock(cell, p); 
     1665    cell_lock->Visit(cell_lock, grid_creature_searcher, *(GetMap())); 
     1666 
     1667    if(!GetMotionMaster()->empty() && (GetMotionMaster()->GetCurrentMovementGeneratorType() != POINT_MOTION_TYPE)) 
     1668        GetMotionMaster()->Clear(false); 
     1669    if(pCreature == NULL) 
     1670    { 
     1671        GetMotionMaster()->MoveIdle(); 
     1672        GetMotionMaster()->MoveFleeing(getVictim()); 
     1673    } 
     1674    else 
     1675    { 
     1676        GetMotionMaster()->MoveIdle(); 
     1677        GetMotionMaster()->MovePoint(0,pCreature->GetPositionX(),pCreature->GetPositionY(),pCreature->GetPositionZ()); 
     1678    } 
     1679} 
     1680 
    16471681void Creature::CallAssistence() 
    16481682{ 
  • trunk/src/game/Creature.h

    r6 r14  
    511511        void CallAssistence(); 
    512512        void SetNoCallAssistence(bool val) { m_AlreadyCallAssistence = val; } 
     513        void DoFleeToGetAssistance(float radius = 50); 
    513514 
    514515        MovementGeneratorType GetDefaultMovementType() const { return m_defaultMovementType; }