Show
Ignore:
Timestamp:
11/22/08 00:35:41 (17 years ago)
Author:
yumileroy
Message:

Delete possessed AI only on creature delete.

Original author: gvcoman
Date: 2008-11-16 14:38:02-05:00

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/game/Creature.cpp

    r267 r272  
    123123m_lootMoney(0), m_lootRecipient(0), 
    124124m_deathTimer(0), m_respawnTime(0), m_respawnDelay(25), m_corpseDelay(60), m_respawnradius(0.0f), 
    125 m_gossipOptionLoaded(false), m_emoteState(0), m_isPet(false), m_isTotem(false), m_isAggressive(true), 
     125m_gossipOptionLoaded(false), m_emoteState(0), m_isPet(false), m_isTotem(false), 
    126126m_regenTimer(2000), m_defaultMovementType(IDLE_MOTION_TYPE), m_equipmentId(0), 
    127127m_AlreadyCallAssistence(false), m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false), 
     
    148148    i_AI = NULL; 
    149149 
    150     DeletePossessedAI(); 
     150    if (i_AI_possessed) 
     151    { 
     152        delete i_AI_possessed; 
     153        i_AI_possessed = NULL; 
     154    } 
    151155} 
    152156 
     
    178182    float x,y,z,o; 
    179183    GetRespawnCoord(x, y, z, &o); 
    180     GetMap()->CreatureRelocation(this,x,y,z,o); 
     184    MapManager::Instance().GetMap(GetMapId(), this)->CreatureRelocation(this,x,y,z,o); 
    181185} 
    182186 
     
    210214    } 
    211215 
    212     SetEntry(Entry);                                        // normal entry always 
     216    SetUInt32Value(OBJECT_FIELD_ENTRY, Entry);              // normal entry always 
    213217    m_creatureInfo = cinfo;                                 // map mode related always 
    214218 
     
    294298    SetUInt32Value(UNIT_DYNAMIC_FLAGS,GetCreatureInfo()->dynamicflags); 
    295299 
    296     SetMeleeDamageSchool(SpellSchools(GetCreatureInfo()->dmgschool)); 
    297300    SetModifierValue(UNIT_MOD_ARMOR,             BASE_VALUE, float(GetCreatureInfo()->armor)); 
    298301    SetModifierValue(UNIT_MOD_RESISTANCE_HOLY,   BASE_VALUE, float(GetCreatureInfo()->resistance1)); 
     
    325328        SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); 
    326329 
    327     if(isTotem() || isCivilian() || GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER 
    328         || GetCreatureType() == CREATURE_TYPE_CRITTER) 
    329         m_isAggressive = false; 
    330     else 
    331         m_isAggressive = true; 
    332  
    333330    return true; 
    334331} 
     
    360357                lootForBody         = false; 
    361358 
    362                 if(m_originalEntry != GetEntry()) 
     359                if(m_originalEntry != GetUInt32Value(OBJECT_FIELD_ENTRY)) 
    363360                    UpdateEntry(m_originalEntry); 
    364361 
     
    379376 
    380377                //Call AI respawn virtual function 
    381                 i_AI->JustRespawned(); 
    382  
    383                 GetMap()->Add(this); 
     378                AI()->JustRespawned(); 
     379 
     380                MapManager::Instance().GetMap(GetMapId(), this)->Add(this); 
    384381            } 
    385382            break; 
     
    443440                // do not allow the AI to be changed during update 
    444441                m_AI_locked = true; 
    445                 i_AI->UpdateAI(diff); 
     442                AI()->UpdateAI(diff); 
    446443                m_AI_locked = false; 
    447444            } 
     
    563560} 
    564561 
    565 void Creature::DeletePossessedAI() 
     562void Creature::DisablePossessedAI() 
    566563{ 
    567564    if (!i_AI_possessed) return; 
    568  
    569     delete i_AI_possessed; 
    570     i_AI_possessed = NULL; 
    571565 
    572566    // Signal the old AI that it's been re-enabled 
     
    14181412    SetPower(POWER_MANA,data->curmana); 
    14191413 
     1414    SetMeleeDamageSchool(SpellSchools(GetCreatureInfo()->dmgschool)); 
     1415 
    14201416    // checked at creature_template loading 
    14211417    m_defaultMovementType = MovementGeneratorType(data->movementType); 
     
    15421538{ 
    15431539    return IsWithinDistInMap(u, sWorld.getConfig(CONFIG_SIGHT_MONSTER)); 
    1544 } 
    1545  
    1546 bool Creature::canStartAttack(Unit const* who) const 
    1547 { 
    1548     if(!who->isInAccessiblePlaceFor(this) 
    1549         || !canFly() && GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE 
    1550         || !IsWithinDistInMap(who, GetAttackDistance(who))) 
    1551         return false; 
    1552  
    1553     if(!canAttack(who)) 
    1554         return false; 
    1555  
    1556     return IsWithinLOSInMap(who); 
    15571540} 
    15581541 
     
    18361819} 
    18371820 
    1838 Unit* Creature::SelectNearestTarget(float dist) const 
    1839 { 
    1840     CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); 
    1841     Cell cell(p); 
    1842     cell.data.Part.reserved = ALL_DISTRICT; 
    1843     cell.SetNoCreate(); 
    1844  
    1845     Unit *target = NULL; 
    1846  
    1847     { 
    1848         Trinity::NearestHostileUnitInAttackDistanceCheck u_check(this, dist); 
    1849         Trinity::UnitLastSearcher<Trinity::NearestHostileUnitInAttackDistanceCheck> searcher(target, u_check); 
    1850  
    1851         TypeContainerVisitor<Trinity::UnitLastSearcher<Trinity::NearestHostileUnitInAttackDistanceCheck>, WorldTypeMapContainer > world_unit_searcher(searcher); 
    1852         TypeContainerVisitor<Trinity::UnitLastSearcher<Trinity::NearestHostileUnitInAttackDistanceCheck>, GridTypeMapContainer >  grid_unit_searcher(searcher); 
    1853  
    1854         CellLock<GridReadGuard> cell_lock(cell, p); 
    1855         cell_lock->Visit(cell_lock, world_unit_searcher, *GetMap()); 
    1856         cell_lock->Visit(cell_lock, grid_unit_searcher, *GetMap()); 
    1857     } 
    1858  
    1859     return target; 
    1860 } 
    1861  
    18621821void Creature::CallAssistence() 
    18631822{ 
     
    21392098} 
    21402099 
    2141 std::string Creature::GetScriptName() 
    2142 { 
    2143     return objmgr.GetScriptName(GetScriptId()); 
    2144 } 
    2145  
    2146 uint32 Creature::GetScriptId() 
    2147 { 
    2148     return ObjectMgr::GetCreatureTemplate(GetEntry())->ScriptID; 
     2100char const* Creature::GetScriptName() const 
     2101{ 
     2102    return ObjectMgr::GetCreatureTemplate(GetEntry())->ScriptName; 
    21492103} 
    21502104