Skip to content

Commit

Permalink
-Performance fix (again): Reintroduce attackers value sharing. Hopefu…
Browse files Browse the repository at this point in the history
…lly without the value getting stuck or sharing incorrect mark targets.
  • Loading branch information
mostlikely4r committed Dec 14, 2023
1 parent 459e50a commit 1b34105
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
2 changes: 0 additions & 2 deletions playerbot/strategy/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace ai
virtual string Format() { return "?"; }
virtual string Save() { return "?"; }
virtual bool Load(string value) { return false; }
virtual int32 ExpireTime() { return -99; }
virtual bool Expired() { return false; }
virtual bool Expired(uint32 interval) { return false; }
virtual bool Protected() { return false; }
Expand Down Expand Up @@ -76,7 +75,6 @@ namespace ai
virtual void Set(T value) { this->value = value; }
virtual void Update() { }
virtual void Reset() { lastCheckTime = 0; }
virtual int32 ExpireTime() { return checkInterval / 2 - (time(0) - lastCheckTime); }
virtual bool Expired() { return Expired(checkInterval / 2); }
virtual bool Expired(uint32 interval) { return time(0) - lastCheckTime >= interval; }
protected:
Expand Down
58 changes: 26 additions & 32 deletions playerbot/strategy/values/AttackersValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ list<ObjectGuid> AttackersValue::Calculate()
if (bot->IsFlying() && WorldPosition(bot).currentHeight() > 10.0f)
return result;

/*

// Try to get the value from nearby friendly bots.
list<ObjectGuid> nearGuids = ai->GetAiObjectContext()->GetValue<list<ObjectGuid> >("nearest friendly players")->Get();
for (auto& i : nearGuids)
Expand All @@ -46,61 +46,55 @@ list<ObjectGuid> AttackersValue::Calculate()
if (!botAi)
continue;

string valueName = "attackers" + !qualifier.empty() ? "::" + qualifier : "";

// Ignore bots without the value.
if (!PHAS_AI_VALUE2("attackers", qualifier))
if (!PHAS_AI_VALUE(valueName))
continue;

UntypedValue* pValue = botAi->GetAiObjectContext()->GetUntypedValue("attackers::" + qualifier);
// Ignore expired values.
if (pValue->Expired())
continue;
UntypedValue* pValue = botAi->GetAiObjectContext()->GetUntypedValue(valueName);

AttackersValue* pAttackersValue = dynamic_cast<AttackersValue*>(pValue);

if (!pAttackersValue)
continue;

// Ignore expired values.
if (pAttackersValue->Expired())
continue;

if (pAttackersValue->calculatePos.sqDistance2d(bot) > 100.0f)
continue;

// Make the value expire at the same time as the copied value.
lastCheckTime = time(0) - botAi->GetAiObjectContext()->GetUntypedValue("attackers::" + qualifier)->ExpireTime();
calculatePos = pAttackersValue->calculatePos;
lastCheckTime = pAttackersValue->lastCheckTime;

result = PAI_VALUE2(list<ObjectGuid>, "attackers", qualifier);
calculatePos = pAttackersValue->calculatePos;

// Add the current target
Unit* currentTarget = AI_VALUE(Unit*, "current target");
if (currentTarget)
{
result.push_back(currentTarget->GetObjectGuid());
}
result = PAI_VALUE(list<ObjectGuid>, valueName);

// Add the previous target
Unit* oldTarget = AI_VALUE(Unit*, "old target");
if (oldTarget)
{
result.push_back(oldTarget->GetObjectGuid());
}
vector<string> specificTargetNames = { "current target","old target","attack target","pull target" };
Unit* target;

// Add the pull and attack targets (Only consider the owner bot)
Unit* attackTarget = ai->GetUnit(AI_VALUE(ObjectGuid, "attack target"));
if (attackTarget)
//Remove bot specific targets of the other bot.
for (auto& targetName : specificTargetNames)
{
result.push_back(attackTarget->GetObjectGuid());
target = (targetName == "attack target") ? ai->GetUnit(PAI_VALUE(ObjectGuid, targetName)) : PAI_VALUE(Unit*, targetName);
if (target)
result.remove(target->GetObjectGuid());
}

Unit* pullTarget = AI_VALUE(Unit*, "pull target");
if (pullTarget)
//Add bot specific targets of this bot.
for (auto& targetName : specificTargetNames)
{
result.push_back(pullTarget->GetObjectGuid());
target = (targetName == "attack target") ? ai->GetUnit(AI_VALUE(ObjectGuid, targetName)) : AI_VALUE(Unit*, targetName);
if (target)
result.push_back(target->GetObjectGuid());
}
return result;
}
*/


calculatePos = bot;

set<Unit*> targets;
Expand Down

0 comments on commit 1b34105

Please sign in to comment.