From 8e308da25990a965750ec795dd22f9c104b10ceb Mon Sep 17 00:00:00 2001 From: raczman Date: Mon, 30 Mar 2009 23:45:17 +0200 Subject: Allow eventAI creature have events both inside instance and outside, without producing error message. Note that EFLAG_NORMAL/EFLAG_HEROIC must still be defined if this event should trigger in this mode. Creature outside instance will always use all events regardless. --HG-- branch : trunk --- .../scripts/scripts/creature/mob_event_ai.cpp | 38 +++++----------------- 1 file changed, 8 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/bindings/scripts/scripts/creature/mob_event_ai.cpp b/src/bindings/scripts/scripts/creature/mob_event_ai.cpp index 726bd1fb419..b302f1b3837 100644 --- a/src/bindings/scripts/scripts/creature/mob_event_ai.cpp +++ b/src/bindings/scripts/scripts/creature/mob_event_ai.cpp @@ -1377,11 +1377,11 @@ struct TRINITY_DLL_DECL Mob_EventAI : public ScriptedAI } }; -CreatureAI* GetAI_Mob_EventAI(Creature *_Creature) +CreatureAI* GetAI_Mob_EventAI(Creature *pCreature) { //Select events by creature id std::list EventList; - uint32 ID = _Creature->GetEntry(); + uint32 ID = pCreature->GetEntry(); std::list::iterator i; @@ -1394,33 +1394,11 @@ CreatureAI* GetAI_Mob_EventAI(Creature *_Creature) if ((*i).event_flags & EFLAG_DEBUG_ONLY) continue; #endif - if( _Creature->GetMap()->IsDungeon() ) + if( pCreature->GetMap()->IsDungeon() ) { - if( _Creature->GetMap()->IsHeroic() ) - { - if( (*i).event_flags & EFLAG_HEROIC ) - { - EventList.push_back(EventHolder(*i)); - continue; - }else if( (*i).event_flags & EFLAG_NORMAL ) - continue; - } - else - { - if( (*i).event_flags & EFLAG_NORMAL ) - { - EventList.push_back(EventHolder(*i)); - continue; - }else if( (*i).event_flags & EFLAG_HEROIC ) - continue; - } - - if (EAI_ErrorLevel > 1) - { - error_db_log("SD2: Creature %u Event %u. Creature are in instance but neither EFLAG_NORMAL or EFLAG_HEROIC are set.", _Creature->GetEntry(), (*i).event_id); - EventList.push_back(EventHolder(*i)); - } - + if ((pCreature->GetMap()->IsHeroic() && (*i).event_flags & EFLAG_HEROIC) || + (!pCreature->GetMap()->IsHeroic() && (*i).event_flags & EFLAG_NORMAL)) + EventList.push_back(EventHolder(*i)); continue; } @@ -1432,12 +1410,12 @@ CreatureAI* GetAI_Mob_EventAI(Creature *_Creature) if (EventList.empty()) { if (EAI_ErrorLevel > 1) - error_db_log("SD2: Eventlist for Creature %u is empty but creature is using Mob_EventAI. Preventing EventAI on this creature.", _Creature->GetEntry()); + error_db_log("SD2: Eventlist for Creature %u is empty but creature is using Mob_EventAI. Preventing EventAI on this creature.", pCreature->GetEntry()); return NULL; } - return new Mob_EventAI (_Creature, EventList); + return new Mob_EventAI (pCreature, EventList); } void AddSC_mob_event() -- cgit v1.2.3 From 075d8a44a5fae838f7a92da9945fe8b9c71d65f9 Mon Sep 17 00:00:00 2001 From: raczman Date: Tue, 31 Mar 2009 00:15:17 +0200 Subject: Optimize storage for eventAI. Store as Map of creature id's linked to vectors of events used by that creature id Author of both commits: NoFantasy. --HG-- branch : trunk --- src/bindings/scripts/ScriptMgr.cpp | 8 ++++-- .../scripts/scripts/creature/mob_event_ai.cpp | 33 +++++++++++++--------- .../scripts/scripts/creature/mob_event_ai.h | 2 +- 3 files changed, 25 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/bindings/scripts/ScriptMgr.cpp b/src/bindings/scripts/ScriptMgr.cpp index 0d7f47a4c84..156358eddd9 100644 --- a/src/bindings/scripts/ScriptMgr.cpp +++ b/src/bindings/scripts/ScriptMgr.cpp @@ -52,7 +52,7 @@ UNORDERED_MAP TextMap; //*** EventAI data *** //Event AI structure. Used exclusivly by mob_event_ai.cpp (60 bytes each) -std::list EventAI_Event_List; +UNORDERED_MAP > EventAI_Event_Map; //Event AI summon structure. Used exclusivly by mob_event_ai.cpp. UNORDERED_MAP EventAI_Summon_Map; @@ -901,7 +901,7 @@ void LoadDatabase() "FROM eventai_scripts"); //Drop Existing EventAI List - EventAI_Event_List.clear(); + EventAI_Event_Map.clear(); outstring_log("TSCR: Loading EventAI scripts..."); if (result) @@ -919,6 +919,7 @@ void LoadDatabase() temp.event_id = fields[0].GetUInt32(); uint32 i = temp.event_id; temp.creature_id = fields[1].GetUInt32(); + uint32 creature_id = temp.creature_id; temp.event_type = fields[2].GetUInt16(); temp.event_inverse_phase_mask = fields[3].GetUInt32(); temp.event_chance = fields[4].GetUInt8(); @@ -1282,7 +1283,8 @@ void LoadDatabase() } //Add to list - EventAI_Event_List.push_back(temp); + EventAI_Event_Map[creature_id].push_back(temp); + ++Count; } while (result->NextRow()); diff --git a/src/bindings/scripts/scripts/creature/mob_event_ai.cpp b/src/bindings/scripts/scripts/creature/mob_event_ai.cpp index b302f1b3837..233c93d34b1 100644 --- a/src/bindings/scripts/scripts/creature/mob_event_ai.cpp +++ b/src/bindings/scripts/scripts/creature/mob_event_ai.cpp @@ -1381,15 +1381,17 @@ CreatureAI* GetAI_Mob_EventAI(Creature *pCreature) { //Select events by creature id std::list EventList; - uint32 ID = pCreature->GetEntry(); - std::list::iterator i; + //Find creature id in the Event map + UNORDERED_MAP >::iterator CreatureEvents = EventAI_Event_Map.find(pCreature->GetEntry()); - for (i = EventAI_Event_List.begin(); i != EventAI_Event_List.end(); ++i) + if (CreatureEvents != EventAI_Event_Map.end()) { - if ((*i).creature_id == ID) + std::vector::iterator i; + + for (i = (*CreatureEvents).second.begin(); i != (*CreatureEvents).second.end(); ++i) { -//Debug check + //Debug check #ifndef _DEBUG if ((*i).event_flags & EFLAG_DEBUG_ONLY) continue; @@ -1404,16 +1406,19 @@ CreatureAI* GetAI_Mob_EventAI(Creature *pCreature) EventList.push_back(EventHolder(*i)); } - } - - //EventAI is pointless to use without events and may cause crashes - if (EventList.empty()) - { - if (EAI_ErrorLevel > 1) - error_db_log("SD2: Eventlist for Creature %u is empty but creature is using Mob_EventAI. Preventing EventAI on this creature.", pCreature->GetEntry()); - return NULL; - } + //EventMap had events but they were not added because they must be for instance + if (EventList.empty()) + { + if (EAI_ErrorLevel > 1) + error_db_log("SD2: CreatureId has events but no events added to list because of instance flags.", pCreature->GetEntry()); + } + } + else + { + if (EAI_ErrorLevel > 1) + error_db_log("SD2: EventMap for Creature %u is empty but creature is using Mob_EventAI.", pCreature->GetEntry()); + } return new Mob_EventAI (pCreature, EventList); } diff --git a/src/bindings/scripts/scripts/creature/mob_event_ai.h b/src/bindings/scripts/scripts/creature/mob_event_ai.h index 39bf050cd70..aff54b824f4 100644 --- a/src/bindings/scripts/scripts/creature/mob_event_ai.h +++ b/src/bindings/scripts/scripts/creature/mob_event_ai.h @@ -186,7 +186,7 @@ struct EventAI_Event }; //Event_Map -extern std::list EventAI_Event_List; +extern UNORDERED_MAP > EventAI_Event_Map; struct EventAI_Summon { -- cgit v1.2.3 From f2df7bbdcc7ba952083d3eb96230ee2eea391fd8 Mon Sep 17 00:00:00 2001 From: raczman Date: Tue, 31 Mar 2009 08:36:54 +0200 Subject: Probably fix a crash in SocialMgr.cpp --HG-- branch : trunk --- src/game/SocialMgr.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/game/SocialMgr.cpp b/src/game/SocialMgr.cpp index e745d95abb3..a0338f4abb1 100644 --- a/src/game/SocialMgr.cpp +++ b/src/game/SocialMgr.cpp @@ -196,6 +196,9 @@ void SocialMgr::GetFriendInfo(Player *player, uint32 friendGUID, FriendInfo &fri Player *pFriend = ObjectAccessor::FindPlayer(friendGUID); + if(!pFriend) + return; + uint32 team = player->GetTeam(); uint32 security = player->GetSession()->GetSecurity(); bool allowTwoSideWhoList = sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_WHO_LIST); -- cgit v1.2.3