From 5d3ab08d30f6e2e73d00f382d66c8468aa57b3fd Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Fri, 13 Oct 2023 23:29:48 +0800 Subject: [PATCH] cast time strategy & relieve memory leak --- src/strategy/Engine.cpp | 11 ++++++++++- src/strategy/generic/CastTimeStrategy.cpp | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/strategy/Engine.cpp b/src/strategy/Engine.cpp index 6c86c23a..af19ccc6 100644 --- a/src/strategy/Engine.cpp +++ b/src/strategy/Engine.cpp @@ -8,6 +8,7 @@ #include "Queue.h" #include "PerformanceMonitor.h" #include "Playerbots.h" +#include "Strategy.h" Engine::Engine(PlayerbotAI* botAI, AiObjectContext* factory) : PlayerbotAIAware(botAI), aiObjectContext(factory) { @@ -70,6 +71,14 @@ Engine::~Engine(void) { Reset(); + for (std::map::iterator i = strategies.begin(); i != strategies.end(); i++) + { + Strategy* strategy = i->second; + if (strategy) { + delete strategy; + } + } + strategies.clear(); } @@ -200,7 +209,7 @@ bool Engine::DoNextAction(Unit* unit, uint32 depth, bool minimal) if (actionExecuted) { LogAction("A:%s - OK", action->getName().c_str()); - MultiplyAndPush(actionNode->getContinuers(), 0, false, event, "cont"); + MultiplyAndPush(actionNode->getContinuers(), relevance, false, event, "cont"); lastRelevance = relevance; delete actionNode; break; diff --git a/src/strategy/generic/CastTimeStrategy.cpp b/src/strategy/generic/CastTimeStrategy.cpp index e7360731..82ba6836 100644 --- a/src/strategy/generic/CastTimeStrategy.cpp +++ b/src/strategy/generic/CastTimeStrategy.cpp @@ -40,11 +40,11 @@ float CastTimeMultiplier::GetValue(Action* action) Unit* target = action->GetTarget(); if (!target || !target->IsAlive() || !target->IsInWorld()) { - return false; + return 1.0f; } if (castTime > (1000 * target->GetHealth() / AI_VALUE(float, "expected group dps"))) { - return 0.0f; + return 0.1f; } } // if (castTime >= 3000)