[Combat formation] Avoid flee repeatly

This commit is contained in:
Yunfan Li
2024-07-09 16:39:50 +08:00
parent b55c9b14d1
commit fe64d9ce00
6 changed files with 79 additions and 19 deletions

View File

@@ -16,6 +16,16 @@
class PlayerbotAI;
class Unit;
class FleeInfo
{
public:
Position fromPos;
float radius;
float angle;
uint32 timestamp;
int GetAngleRangeIndex() { return (angle + 2 * M_PI) / (M_PI / 2); } // [0, 7)
};
struct CreatureData;
class UntypedValue : public AiNamedObject
@@ -37,6 +47,7 @@ class Value
virtual ~Value() { }
virtual T Get() = 0;
virtual T LazyGet() = 0;
virtual T& RefGet() = 0;
virtual void Reset() { }
virtual void Set(T value) = 0;
operator T() { return Get(); }
@@ -79,7 +90,26 @@ class CalculatedValue : public UntypedValue, public Value<T>
return value;
}
T& RefGet() override
{
if (checkInterval < 2) {
// PerformanceMonitorOperation* pmo = sPerformanceMonitor->start(PERF_MON_VALUE, this->getName(), this->context ? &this->context->performanceStack : nullptr);
value = Calculate();
// if (pmo)
// pmo->finish();
} else {
time_t now = getMSTime();
if (!lastCheckTime || now - lastCheckTime >= checkInterval)
{
lastCheckTime = now;
// PerformanceMonitorOperation* pmo = sPerformanceMonitor->start(PERF_MON_VALUE, this->getName(), this->context ? &this->context->performanceStack : nullptr);
value = Calculate();
// if (pmo)
// pmo->finish();
}
}
return value;
}
void Set(T val) override { value = val; }
void Update() override {}
void Reset() override { lastCheckTime = 0; }
@@ -304,6 +334,7 @@ class ManualSetValue : public UntypedValue, public Value<T>
T Get() override { return value; }
T LazyGet() override { return value; }
T& RefGet() override { return value; }
void Set(T val) override { value = val; }
void Update() override {}
void Reset() override
@@ -347,4 +378,11 @@ class LastFleeTimestampValue : public ManualSetValue<uint32>
ManualSetValue<uint32>(botAI, defaultValue, name) { }
};
class RecentlyFleeInfo : public ManualSetValue<std::list<FleeInfo>>
{
public:
RecentlyFleeInfo(PlayerbotAI* botAI, std::list<FleeInfo> defaultValue = {}, std::string const name = "recently flee info") :
ManualSetValue<std::list<FleeInfo>>(botAI, defaultValue, name) { }
};
#endif