From 99164fe3f9425f3c841a9bead5d6eb52f2973490 Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Tue, 27 Jan 2015 21:28:38 -0500 Subject: [PATCH] Switch AI timers to smart pointers --- zone/mob.h | 17 +++++++++-------- zone/mob_ai.cpp | 44 ++++++++++++++++++++++---------------------- zone/npc.h | 4 ++-- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/zone/mob.h b/zone/mob.h index e2d25a952..00b1ea416 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -25,6 +25,7 @@ #include "position.h" #include #include +#include char* strn0cpy(char* dest, const char* source, uint32 size); @@ -879,8 +880,8 @@ public: virtual FACTION_VALUE GetReverseFactionCon(Mob* iOther) { return FACTION_INDIFFERENT; } inline bool IsTrackable() const { return(trackable); } - Timer* GetAIThinkTimer() { return AIthink_timer; } - Timer* GetAIMovementTimer() { return AImovement_timer; } + const Timer* GetAIThinkTimer() { return AIthink_timer.get(); } + const Timer* GetAIMovementTimer() { return AImovement_timer.get(); } Timer GetAttackTimer() { return attack_timer; } Timer GetAttackDWTimer() { return attack_dw_timer; } inline bool IsFindable() { return findable; } @@ -1170,14 +1171,14 @@ protected: uint32 maxLastFightingDelayMoving; float pAggroRange; float pAssistRange; - Timer* AIthink_timer; - Timer* AImovement_timer; - Timer* AItarget_check_timer; + std::unique_ptr AIthink_timer; + std::unique_ptr AImovement_timer; + std::unique_ptr AItarget_check_timer; bool movetimercompleted; bool permarooted; - Timer* AIscanarea_timer; - Timer* AIwalking_timer; - Timer* AIfeignremember_timer; + std::unique_ptr AIscanarea_timer; + std::unique_ptr AIwalking_timer; + std::unique_ptr AIfeignremember_timer; uint32 pLastFightingDelayMoving; HateList hate_list; std::set feign_memory_list; diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index e6b3c514d..371a8e523 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -425,12 +425,12 @@ bool EntityList::AICheckCloseBeneficialSpells(NPC* caster, uint8 iChance, float void Mob::AI_Init() { pAIControlled = false; - AIthink_timer = nullptr; - AIwalking_timer = nullptr; - AImovement_timer = nullptr; - AItarget_check_timer = nullptr; - AIfeignremember_timer = nullptr; - AIscanarea_timer = nullptr; + AIthink_timer.reset(nullptr); + AIwalking_timer.reset(nullptr); + AImovement_timer.reset(nullptr); + AItarget_check_timer.reset(nullptr); + AIfeignremember_timer.reset(nullptr); + AIscanarea_timer.reset(nullptr); minLastFightingDelayMoving = RuleI(NPC, LastFightingDelayMovingMin); maxLastFightingDelayMoving = RuleI(NPC, LastFightingDelayMovingMax); @@ -444,7 +444,7 @@ void Mob::AI_Init() void NPC::AI_Init() { - AIautocastspell_timer = nullptr; + AIautocastspell_timer.reset(nullptr); casting_spell_AIindex = static_cast(AIspells.size()); roambox_max_x = 0; @@ -474,13 +474,13 @@ void Mob::AI_Start(uint32 iMoveDelay) { pLastFightingDelayMoving = 0; pAIControlled = true; - AIthink_timer = new Timer(AIthink_duration); + AIthink_timer = std::unique_ptr(new Timer(AIthink_duration)); AIthink_timer->Trigger(); - AIwalking_timer = new Timer(0); - AImovement_timer = new Timer(AImovement_duration); - AItarget_check_timer = new Timer(AItarget_check_duration); - AIfeignremember_timer = new Timer(AIfeignremember_delay); - AIscanarea_timer = new Timer(AIscanarea_delay); + AIwalking_timer = std::unique_ptr(new Timer(0)); + AImovement_timer = std::unique_ptr(new Timer(AImovement_duration)); + AItarget_check_timer = std::unique_ptr(new Timer(AItarget_check_duration)); + AIfeignremember_timer = std::unique_ptr(new Timer(AIfeignremember_delay)); + AIscanarea_timer = std::unique_ptr(new Timer(AIscanarea_delay)); #ifdef REVERSE_AGGRO if(IsNPC() && !CastToNPC()->WillAggroNPCs()) AIscanarea_timer->Disable(); @@ -516,10 +516,10 @@ void NPC::AI_Start(uint32 iMoveDelay) { return; if (AIspells.size() == 0) { - AIautocastspell_timer = new Timer(1000); + AIautocastspell_timer = std::unique_ptr(new Timer(1000)); AIautocastspell_timer->Disable(); } else { - AIautocastspell_timer = new Timer(750); + AIautocastspell_timer = std::unique_ptr(new Timer(750)); AIautocastspell_timer->Start(RandomTimer(0, 15000), false); } @@ -540,19 +540,19 @@ void Mob::AI_Stop() { pAIControlled = false; - safe_delete(AIthink_timer); - safe_delete(AIwalking_timer); - safe_delete(AImovement_timer); - safe_delete(AItarget_check_timer); - safe_delete(AIscanarea_timer); - safe_delete(AIfeignremember_timer); + AIthink_timer.reset(nullptr); + AIwalking_timer.reset(nullptr); + AImovement_timer.reset(nullptr); + AItarget_check_timer.reset(nullptr); + AIscanarea_timer.reset(nullptr); + AIfeignremember_timer.reset(nullptr); hate_list.WipeHateList(); } void NPC::AI_Stop() { Waypoints.clear(); - safe_delete(AIautocastspell_timer); + AIautocastspell_timer.reset(nullptr); } void Client::AI_Stop() { diff --git a/zone/npc.h b/zone/npc.h index e38aa85aa..6cb31ed87 100644 --- a/zone/npc.h +++ b/zone/npc.h @@ -436,7 +436,7 @@ protected: uint32 npc_spells_id; uint8 casting_spell_AIindex; - Timer* AIautocastspell_timer; + std::unique_ptr AIautocastspell_timer; uint32* pDontCastBefore_casting_spell; std::vector AIspells; bool HasAISpell; @@ -444,7 +444,7 @@ protected: virtual bool AIDoSpellCast(uint8 i, Mob* tar, int32 mana_cost, uint32* oDontDoAgainBefore = 0); AISpellsVar_Struct AISpellVar; int16 GetFocusEffect(focusType type, uint16 spell_id); - + uint32 npc_spells_effects_id; std::vector AIspellsEffects; bool HasAISpellEffects;