From b474dc44bb6323430a84fc17c1ec046f9919a101 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 11 Apr 2024 11:02:42 +0800 Subject: [PATCH 1/6] Performance optim --- src/PlayerbotFactory.cpp | 16 ++++++++-------- src/PlayerbotMgr.cpp | 4 ++-- src/strategy/NamedObjectContext.h | 17 +++++++++-------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index 88a4d1dcd..ddcbef799 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -605,7 +605,7 @@ void PlayerbotFactory::InitPetTalents() return; } pet->resetTalents(); - std::map > spells; + std::unordered_map > spells; for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i) { TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); @@ -625,7 +625,7 @@ void PlayerbotFactory::InitPetTalents() uint32 maxTalentPoints = pet->GetMaxTalentPointsForLevel(pet->GetLevel()); int row = 0; // LOG_INFO("playerbots", "{} learning, max talent points: {}, cur: {}", bot->GetName().c_str(), maxTalentPoints, curTalentPoints); - for (std::map >::iterator i = spells.begin(); i != spells.end(); ++i, ++row) + for (auto i = spells.begin(); i != spells.end(); ++i, ++row) { std::vector &spells_row = i->second; if (spells_row.empty()) @@ -893,7 +893,7 @@ void PlayerbotFactory::InitTalentsBySpecNo(Player* bot, int specNo, bool reset) uint32 cls = bot->getClass(); int startLevel = bot->GetLevel(); uint32 classMask = bot->getClassMask(); - std::map > spells_row; + std::unordered_map > spells_row; for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i) { TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); @@ -954,7 +954,7 @@ void PlayerbotFactory::InitTalentsByParsedSpecLink(Player* bot, std::vectorresetTalents(true); } uint32 classMask = bot->getClassMask(); - std::map > spells_row; + std::unordered_map > spells_row; for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i) { TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); @@ -2248,7 +2248,7 @@ void PlayerbotFactory::InitSpecialSpells() void PlayerbotFactory::InitTalents(uint32 specNo) { uint32 classMask = bot->getClassMask(); - std::map > spells; + std::unordered_map > spells; for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i) { TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); @@ -2266,7 +2266,7 @@ void PlayerbotFactory::InitTalents(uint32 specNo) } uint32 freePoints = bot->GetFreeTalentPoints(); - for (std::map >::iterator i = spells.begin(); i != spells.end(); ++i) + for (auto i = spells.begin(); i != spells.end(); ++i) { std::vector &spells_row = i->second; if (spells_row.empty()) @@ -2308,7 +2308,7 @@ void PlayerbotFactory::InitTalentsByTemplate(uint32 specTab) int startLevel = bot->GetLevel(); uint32 specIndex = sPlayerbotAIConfig->randomClassSpecIndex[cls][specTab]; uint32 classMask = bot->getClassMask(); - std::map > spells_row; + std::unordered_map > spells_row; for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i) { TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); @@ -2648,7 +2648,7 @@ void PlayerbotFactory::InitFood() if (sPlayerbotAIConfig->freeFood) { return; } - std::map > items; + std::unordered_map > items; ItemTemplateContainer const* itemTemplateContainer = sObjectMgr->GetItemTemplateStore(); for (ItemTemplateContainer::const_iterator i = itemTemplateContainer->begin(); i != itemTemplateContainer->end(); ++i) { diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index 49dbf4676..325ebacc0 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -900,7 +900,7 @@ std::vector PlayerbotHolder::HandlePlayerbotCommand(char const* arg std::string const cmdStr = cmd; - std::set bots; + std::unordered_set bots; if (charnameStr == "*" && master) { Group* group = master->GetGroup(); @@ -958,7 +958,7 @@ std::vector PlayerbotHolder::HandlePlayerbotCommand(char const* arg } } - for (std::set::iterator i = bots.begin(); i != bots.end(); ++i) + for (auto i = bots.begin(); i != bots.end(); ++i) { std::string const bot = *i; diff --git a/src/strategy/NamedObjectContext.h b/src/strategy/NamedObjectContext.h index a288a59cb..d621ca93f 100644 --- a/src/strategy/NamedObjectContext.h +++ b/src/strategy/NamedObjectContext.h @@ -7,8 +7,9 @@ #include "Common.h" -#include +#include #include +#include #include #include @@ -46,7 +47,7 @@ class NamedObjectFactory { protected: typedef T*(*ActionCreator)(PlayerbotAI* botAI); - std::map creators; + std::unordered_map creators; public: T* create(std::string name, PlayerbotAI* botAI) @@ -77,7 +78,7 @@ class NamedObjectFactory std::set supports() { std::set keys; - for (typename std::map::iterator it = creators.begin(); it != creators.end(); it++) + for (typename std::unordered_map::iterator it = creators.begin(); it != creators.end(); it++) keys.insert(it->first); return keys; @@ -106,7 +107,7 @@ class NamedObjectContext : public NamedObjectFactory void Clear() { - for (typename std::map::iterator i = created.begin(); i != created.end(); i++) + for (typename std::unordered_map::iterator i = created.begin(); i != created.end(); i++) { if (i->second) delete i->second; @@ -117,7 +118,7 @@ class NamedObjectContext : public NamedObjectFactory void Update() { - for (typename std::map::iterator i = created.begin(); i != created.end(); i++) + for (typename std::unordered_map::iterator i = created.begin(); i != created.end(); i++) { if (i->second) i->second->Update(); @@ -126,7 +127,7 @@ class NamedObjectContext : public NamedObjectFactory void Reset() { - for (typename std::map::iterator i = created.begin(); i != created.end(); i++) + for (typename std::unordered_map::iterator i = created.begin(); i != created.end(); i++) { if (i->second) i->second->Reset(); @@ -139,14 +140,14 @@ class NamedObjectContext : public NamedObjectFactory std::set GetCreated() { std::set keys; - for (typename std::map::iterator it = created.begin(); it != created.end(); it++) + for (typename std::unordered_map::iterator it = created.begin(); it != created.end(); it++) keys.insert(it->first); return keys; } protected: - std::map created; + std::unordered_map created; bool shared; bool supportsSiblings; }; From 9d69e9263bd846b4a61c2368c50756333abd6a7f Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 11 Apr 2024 14:37:15 +0800 Subject: [PATCH 2/6] Reduce string overhead and totem check overhead --- src/PlayerbotAI.cpp | 2 +- src/strategy/NamedObjectContext.h | 2 +- src/strategy/values/HasTotemValue.cpp | 6 ++---- src/strategy/values/NearestNpcsValue.cpp | 12 ++++++++++++ src/strategy/values/NearestNpcsValue.h | 11 +++++++++++ src/strategy/values/ValueContext.h | 2 ++ 6 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 7bda537c5..1fdd2089c 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -1993,7 +1993,7 @@ bool PlayerbotAI::HasAura(std::string const name, Unit* unit, bool maxStack, boo { SpellInfo const* spellInfo = aurEff->GetSpellInfo(); - std::string const auraName = spellInfo->SpellName[0]; + std::string_view const auraName = spellInfo->SpellName[0]; if (auraName.empty() || auraName.length() != wnamepart.length() || !Utf8FitTo(auraName, wnamepart)) continue; diff --git a/src/strategy/NamedObjectContext.h b/src/strategy/NamedObjectContext.h index d621ca93f..7f4509e78 100644 --- a/src/strategy/NamedObjectContext.h +++ b/src/strategy/NamedObjectContext.h @@ -265,7 +265,7 @@ class NamedObjectFactoryList factories.push_front(context); } - T* GetContextObject(std::string const name, PlayerbotAI* botAI) + T* GetContextObject(std::string const &name, PlayerbotAI* botAI) { for (typename std::list*>::iterator i = factories.begin(); i != factories.end(); i++) { diff --git a/src/strategy/values/HasTotemValue.cpp b/src/strategy/values/HasTotemValue.cpp index 3c31fc404..bba4b0693 100644 --- a/src/strategy/values/HasTotemValue.cpp +++ b/src/strategy/values/HasTotemValue.cpp @@ -9,7 +9,7 @@ char* strstri(char const* str1, char const* str2); bool HasTotemValue::Calculate() { - GuidVector units = *context->GetValue("nearest npcs"); + GuidVector units = *context->GetValue("nearest totems"); for (ObjectGuid const guid : units) { Unit* unit = botAI->GetUnit(guid); @@ -17,14 +17,12 @@ bool HasTotemValue::Calculate() continue; Creature* creature = dynamic_cast(unit); - if (!creature || !creature->IsTotem()) - continue; if (creature->GetOwner() != bot) { continue; } - if (strstri(creature->GetName().c_str(), qualifier.c_str()) && bot->GetDistance(creature) <= botAI->GetRange("spell")) + if (strstri(creature->GetName().c_str(), qualifier.c_str())) return true; } diff --git a/src/strategy/values/NearestNpcsValue.cpp b/src/strategy/values/NearestNpcsValue.cpp index 0bae59426..efc73bb0e 100644 --- a/src/strategy/values/NearestNpcsValue.cpp +++ b/src/strategy/values/NearestNpcsValue.cpp @@ -50,4 +50,16 @@ void NearestTriggersValue::FindUnits(std::list& targets) bool NearestTriggersValue::AcceptUnit(Unit* unit) { return !unit->IsPlayer(); +} + +void NearestTotemsValue::FindUnits(std::list& targets) +{ + Acore::AnyUnitInObjectRangeCheck u_check(bot, range); + Acore::UnitListSearcher searcher(bot, targets, u_check); + Cell::VisitAllObjects(bot, searcher, range); +} + +bool NearestTotemsValue::AcceptUnit(Unit* unit) +{ + return unit->IsTotem(); } \ No newline at end of file diff --git a/src/strategy/values/NearestNpcsValue.h b/src/strategy/values/NearestNpcsValue.h index 4ae4a3af6..e23fc8224 100644 --- a/src/strategy/values/NearestNpcsValue.h +++ b/src/strategy/values/NearestNpcsValue.h @@ -39,4 +39,15 @@ class NearestTriggersValue : public NearestUnitsValue void FindUnits(std::list& targets) override; bool AcceptUnit(Unit* unit) override; }; + +class NearestTotemsValue : public NearestUnitsValue +{ + public: + NearestTotemsValue(PlayerbotAI* botAI, float range = 30.0f) : NearestUnitsValue(botAI, "nearest npcs", range, true) { } + + protected: + void FindUnits(std::list& targets) override; + bool AcceptUnit(Unit* unit) override; +}; + #endif diff --git a/src/strategy/values/ValueContext.h b/src/strategy/values/ValueContext.h index 46d126ead..38f37840a 100644 --- a/src/strategy/values/ValueContext.h +++ b/src/strategy/values/ValueContext.h @@ -103,6 +103,7 @@ class ValueContext : public NamedObjectContext creators["nearest game objects no los"] = &ValueContext::nearest_game_objects_no_los; creators["closest game objects"] = &ValueContext::closest_game_objects; creators["nearest npcs"] = &ValueContext::nearest_npcs; + creators["nearest totems"] = &ValueContext::nearest_totems; creators["nearest vehicles"] = &ValueContext::nearest_vehicles; creators["nearest friendly players"] = &ValueContext::nearest_friendly_players; creators["closest friendly players"] = &ValueContext::closest_friendly_players; @@ -367,6 +368,7 @@ class ValueContext : public NamedObjectContext static UntypedValue* closest_game_objects(PlayerbotAI* botAI) { return new NearestGameObjects(botAI, INTERACTION_DISTANCE); } static UntypedValue* log_level(PlayerbotAI* botAI) { return new LogLevelValue(botAI); } static UntypedValue* nearest_npcs(PlayerbotAI* botAI) { return new NearestNpcsValue(botAI); } + static UntypedValue* nearest_totems(PlayerbotAI* botAI) { return new NearestTotemsValue(botAI); } static UntypedValue* nearest_vehicles(PlayerbotAI* botAI) { return new NearestVehiclesValue(botAI); } static UntypedValue* nearest_friendly_players(PlayerbotAI* botAI) { return new NearestFriendlyPlayersValue(botAI); } static UntypedValue* closest_friendly_players(PlayerbotAI* botAI) { return new NearestFriendlyPlayersValue(botAI, INTERACTION_DISTANCE); } From 3be922ce78dca4767cd29fb10b2ea94b26057f81 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 11 Apr 2024 14:52:28 +0800 Subject: [PATCH 3/6] Rewrite has totem check --- src/strategy/values/HasTotemValue.cpp | 61 +++++++++++++++++++++------ 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/src/strategy/values/HasTotemValue.cpp b/src/strategy/values/HasTotemValue.cpp index bba4b0693..7a5446b0e 100644 --- a/src/strategy/values/HasTotemValue.cpp +++ b/src/strategy/values/HasTotemValue.cpp @@ -9,22 +9,59 @@ char* strstri(char const* str1, char const* str2); bool HasTotemValue::Calculate() { - GuidVector units = *context->GetValue("nearest totems"); - for (ObjectGuid const guid : units) + for (uint8 i = 0; i < MAX_SUMMON_SLOT; ++i) { - Unit* unit = botAI->GetUnit(guid); - if (!unit) - continue; - - Creature* creature = dynamic_cast(unit); - - if (creature->GetOwner() != bot) { + if (!bot->m_SummonSlot[i]) + { continue; } - if (strstri(creature->GetName().c_str(), qualifier.c_str())) - return true; + if (Creature* OldTotem = bot->GetMap()->GetCreature(bot->m_SummonSlot[i])) + { + if (OldTotem->IsSummon() && OldTotem->GetDistance(bot) <= 30.0f) + { + if (strstri(OldTotem->GetName().c_str(), qualifier.c_str())) + return true; + } + } } - return false; } + +// bool HasTotemValue::Calculate() +// { +// for (uint8 i = 0; i < MAX_SUMMON_SLOT; ++i) +// { +// if (!bot->m_SummonSlot[i]) +// { +// continue; +// } + +// if (Creature* OldTotem = bot->GetMap()->GetCreature(bot->m_SummonSlot[i])) +// { +// if (OldTotem->IsSummon()) +// { +// if (strstri(creature->GetName().c_str(), qualifier.c_str())) +// return true; +// } +// } +// } + +// GuidVector units = *context->GetValue("nearest totems"); +// for (ObjectGuid const guid : units) +// { +// Unit* unit = botAI->GetUnit(guid); +// if (!unit) +// continue; +// Creature* creature = dynamic_cast(unit); + +// if (creature->GetOwner() != bot) { +// continue; +// } + +// if (strstri(creature->GetName().c_str(), qualifier.c_str())) +// return true; +// } + +// return false; +// } From f2884d94e6c9ea38cfc3083cf6fc07b1e8ca3b0b Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 11 Apr 2024 19:17:42 +0800 Subject: [PATCH 4/6] Movement overhead --- src/strategy/actions/MovementActions.cpp | 89 +++++++++++++++++++++--- src/strategy/actions/MovementActions.h | 1 + 2 files changed, 82 insertions(+), 8 deletions(-) diff --git a/src/strategy/actions/MovementActions.cpp b/src/strategy/actions/MovementActions.cpp index 926dcb3fd..92a7cf3c1 100644 --- a/src/strategy/actions/MovementActions.cpp +++ b/src/strategy/actions/MovementActions.cpp @@ -3,7 +3,9 @@ */ #include "MovementActions.h" +#include "Map.h" #include "MotionMaster.h" +#include "MoveSplineInitArgs.h" #include "MovementGenerator.h" #include "ObjectDefines.h" #include "ObjectGuid.h" @@ -151,13 +153,8 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle, // } bool generatePath = !bot->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED) && !bot->IsFlying() && !bot->HasUnitMovementFlag(MOVEMENTFLAG_SWIMMING) && !bot->IsInWater(); - float modifiedZ = SearchBestGroundZForPath(x, y, z, generatePath, 20.0f, normal_only, 8.0f); - if (modifiedZ == INVALID_HEIGHT) { - return false; - } - float distance = bot->GetExactDist(x, y, modifiedZ); - if (distance > sPlayerbotAIConfig->contactDistance) - { + if (!generatePath) { + float distance = bot->GetExactDist(x, y, z); WaitForReach(distance); if (bot->IsSitState()) @@ -171,9 +168,36 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle, MotionMaster &mm = *bot->GetMotionMaster(); mm.Clear(); - mm.MovePoint(mapId, x, y, modifiedZ, generatePath); + mm.MovePoint(mapId, x, y, z, generatePath); AI_VALUE(LastMovement&, "last movement").Set(mapId, x, y, z, bot->GetOrientation()); return true; + } else { + float modifiedZ; + Movement::PointsArray path = SearchForBestPath(x, y, z, modifiedZ); + if (modifiedZ == INVALID_HEIGHT) { + return false; + } + float distance = bot->GetExactDist(x, y, modifiedZ); + if (distance > sPlayerbotAIConfig->contactDistance) + { + WaitForReach(distance); + + if (bot->IsSitState()) + bot->SetStandState(UNIT_STAND_STATE_STAND); + + if (bot->IsNonMeleeSpellCast(true)) + { + bot->CastStop(); + botAI->InterruptSpell(); + } + MotionMaster &mm = *bot->GetMotionMaster(); + + mm.Clear(); + mm.MoveSplinePath(&path); + AI_VALUE(LastMovement&, "last movement").Set(mapId, x, y, z, bot->GetOrientation()); + return true; + } + } return false; @@ -1378,6 +1402,55 @@ float MovementAction::SearchBestGroundZForPath(float x, float y, float z, bool g return current_z; } +const Movement::PointsArray MovementAction::SearchForBestPath(float x, float y, float z, float &modified_z, int maxSearchCount, bool normal_only, float step) +{ + bool found = false; + modified_z = INVALID_HEIGHT; + float tempZ = bot->GetMapWaterOrGroundLevel(x, y, z); + PathGenerator gen(bot); + gen.CalculatePath(x, y, tempZ); + Movement::PointsArray result = gen.GetPath(); + float min_length = gen.getPathLength(); + if (gen.GetPathType() == PATHFIND_NORMAL && abs(tempZ - z) < 0.5f) { + modified_z = tempZ; + return result; + } + // Start searching + if (gen.GetPathType() == PATHFIND_NORMAL) { + found = true; + modified_z = tempZ; + } + int count = 1; + for (float delta = step; count < maxSearchCount / 2 + 1; count++, delta += step) { + tempZ = bot->GetMapWaterOrGroundLevel(x, y, z + delta); + PathGenerator gen(bot); + gen.CalculatePath(x, y, tempZ); + if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { + found = true; + min_length = gen.getPathLength(); + result = gen.GetPath(); + modified_z = tempZ; + } + } + for (float delta = -step; count < maxSearchCount; count++, delta -= step) { + tempZ = bot->GetMapWaterOrGroundLevel(x, y, z + delta); + PathGenerator gen(bot); + gen.CalculatePath(x, y, tempZ); + if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { + found = true; + min_length = gen.getPathLength(); + result = gen.GetPath(); + modified_z = tempZ; + } + } + if (!found && normal_only) { + return Movement::PointsArray{}; + } + if (!found && !normal_only) { + return result; + } + return result; +} bool FleeAction::Execute(Event event) { diff --git a/src/strategy/actions/MovementActions.h b/src/strategy/actions/MovementActions.h index bff7ff3a3..93fc242bc 100644 --- a/src/strategy/actions/MovementActions.h +++ b/src/strategy/actions/MovementActions.h @@ -43,6 +43,7 @@ class MovementAction : public Action void CreateWp(Player* wpOwner, float x, float y, float z, float o, uint32 entry, bool important = false); private: float SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range = 20.0f, bool normal_only = false, float step = 8.0f); + const Movement::PointsArray SearchForBestPath(float x, float y, float z, float &modified_z, int maxSearchCount = 5, bool normal_only = false, float step = 8.0f); }; class FleeAction : public MovementAction From ad4fa111759cd7d55352a2e16a63c9b204741fd0 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 11 Apr 2024 19:47:20 +0800 Subject: [PATCH 5/6] Movement search time config --- conf/playerbots.conf.dist | 4 + src/PlayerbotAIConfig.cpp | 1 + src/PlayerbotAIConfig.h | 3 +- src/strategy/actions/MovementActions.cpp | 108 +++++++++++------------ src/strategy/actions/MovementActions.h | 2 +- 5 files changed, 62 insertions(+), 56 deletions(-) diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index 18ff5b1b7..e883c56e5 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -256,6 +256,10 @@ AiPlayerbot.GlobalCooldown = 500 # Max wait time when moving AiPlayerbot.MaxWaitForMove = 5000 +# Max search time for movement (higher for better movement on slopes) +# default: 3 +AiPlayerbot.MaxMovementSearchTime = 3 + # Action expiration time AiPlayerbot.ExpireActionTime = 5000 diff --git a/src/PlayerbotAIConfig.cpp b/src/PlayerbotAIConfig.cpp index 28f43817f..bf168bf61 100644 --- a/src/PlayerbotAIConfig.cpp +++ b/src/PlayerbotAIConfig.cpp @@ -53,6 +53,7 @@ bool PlayerbotAIConfig::Initialize() globalCoolDown = sConfigMgr->GetOption("AiPlayerbot.GlobalCooldown", 1500); maxWaitForMove = sConfigMgr->GetOption("AiPlayerbot.MaxWaitForMove", 5000); + maxMovementSearch = sConfigMgr->GetOption("AiPlayerbot.MaxMovementSearchTime", 3); expireActionTime = sConfigMgr->GetOption("AiPlayerbot.ExpireActionTime", 5000); dispelAuraDuration = sConfigMgr->GetOption("AiPlayerbot.DispelAuraDuration", 7000); reactDelay = sConfigMgr->GetOption("AiPlayerbot.ReactDelay", 500); diff --git a/src/PlayerbotAIConfig.h b/src/PlayerbotAIConfig.h index b3e5fdd73..22930b86f 100644 --- a/src/PlayerbotAIConfig.h +++ b/src/PlayerbotAIConfig.h @@ -54,7 +54,8 @@ class PlayerbotAIConfig bool enabled; bool allowGuildBots, allowPlayerBots; - uint32 globalCoolDown, reactDelay, maxWaitForMove, expireActionTime, dispelAuraDuration, passiveDelay, repeatDelay, + uint32 globalCoolDown, reactDelay, maxWaitForMove, maxMovementSearchTime, expireActionTime, + dispelAuraDuration, passiveDelay, repeatDelay, errorDelay, rpgDelay, sitDelay, returnDelay, lootDelay; float sightDistance, spellDistance, reactDistance, grindDistance, lootDistance, shootDistance, fleeDistance, tooCloseDistance, meleeDistance, followDistance, whisperDistance, contactDistance, diff --git a/src/strategy/actions/MovementActions.cpp b/src/strategy/actions/MovementActions.cpp index 92a7cf3c1..faf6a3283 100644 --- a/src/strategy/actions/MovementActions.cpp +++ b/src/strategy/actions/MovementActions.cpp @@ -173,7 +173,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle, return true; } else { float modifiedZ; - Movement::PointsArray path = SearchForBestPath(x, y, z, modifiedZ); + Movement::PointsArray path = SearchForBestPath(x, y, z, modifiedZ, sPlayerbotAIConfig->maxMovementSearchTime); if (modifiedZ == INVALID_HEIGHT) { return false; } @@ -1348,59 +1348,59 @@ bool MovementAction::MoveInside(uint32 mapId, float x, float y, float z, float d return MoveNear(mapId, x, y, z, distance); } -float MovementAction::SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range, bool normal_only, float step) -{ - if (!generatePath) { - return z; - } - float min_length = 100000.0f; - float current_z = INVALID_HEIGHT; - float modified_z; - float delta; - for (delta = 0.0f; delta <= range / 2; delta += step) { - modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); - PathGenerator gen(bot); - gen.CalculatePath(x, y, modified_z); - if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { - min_length = gen.getPathLength(); - current_z = modified_z; - if (abs(current_z - z) < 0.5f) { - return current_z; - } - } - } - for (delta = -step; delta >= -range / 2; delta -= step) { - modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); - PathGenerator gen(bot); - gen.CalculatePath(x, y, modified_z); - if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { - min_length = gen.getPathLength(); - current_z = modified_z; - if (abs(current_z - z) < 0.5f) { - return current_z; - } - } - } - for (delta = range / 2 + step; delta <= range; delta += 2) { - modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); - PathGenerator gen(bot); - gen.CalculatePath(x, y, modified_z); - if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { - min_length = gen.getPathLength(); - current_z = modified_z; - if (abs(current_z - z) < 0.5f) { - return current_z; - } - } - } - if (current_z == INVALID_HEIGHT && normal_only) { - return INVALID_HEIGHT; - } - if (current_z == INVALID_HEIGHT && !normal_only) { - return z; - } - return current_z; -} +// float MovementAction::SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range, bool normal_only, float step) +// { +// if (!generatePath) { +// return z; +// } +// float min_length = 100000.0f; +// float current_z = INVALID_HEIGHT; +// float modified_z; +// float delta; +// for (delta = 0.0f; delta <= range / 2; delta += step) { +// modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); +// PathGenerator gen(bot); +// gen.CalculatePath(x, y, modified_z); +// if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { +// min_length = gen.getPathLength(); +// current_z = modified_z; +// if (abs(current_z - z) < 0.5f) { +// return current_z; +// } +// } +// } +// for (delta = -step; delta >= -range / 2; delta -= step) { +// modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); +// PathGenerator gen(bot); +// gen.CalculatePath(x, y, modified_z); +// if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { +// min_length = gen.getPathLength(); +// current_z = modified_z; +// if (abs(current_z - z) < 0.5f) { +// return current_z; +// } +// } +// } +// for (delta = range / 2 + step; delta <= range; delta += 2) { +// modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); +// PathGenerator gen(bot); +// gen.CalculatePath(x, y, modified_z); +// if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { +// min_length = gen.getPathLength(); +// current_z = modified_z; +// if (abs(current_z - z) < 0.5f) { +// return current_z; +// } +// } +// } +// if (current_z == INVALID_HEIGHT && normal_only) { +// return INVALID_HEIGHT; +// } +// if (current_z == INVALID_HEIGHT && !normal_only) { +// return z; +// } +// return current_z; +// } const Movement::PointsArray MovementAction::SearchForBestPath(float x, float y, float z, float &modified_z, int maxSearchCount, bool normal_only, float step) { diff --git a/src/strategy/actions/MovementActions.h b/src/strategy/actions/MovementActions.h index 93fc242bc..2a605cb18 100644 --- a/src/strategy/actions/MovementActions.h +++ b/src/strategy/actions/MovementActions.h @@ -42,7 +42,7 @@ class MovementAction : public Action bool MoveInside(uint32 mapId, float x, float y, float z, float distance = sPlayerbotAIConfig->followDistance); void CreateWp(Player* wpOwner, float x, float y, float z, float o, uint32 entry, bool important = false); private: - float SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range = 20.0f, bool normal_only = false, float step = 8.0f); + // float SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range = 20.0f, bool normal_only = false, float step = 8.0f); const Movement::PointsArray SearchForBestPath(float x, float y, float z, float &modified_z, int maxSearchCount = 5, bool normal_only = false, float step = 8.0f); }; From c8c33f01aa314690b9022536725f75ca72720cea Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 11 Apr 2024 19:48:20 +0800 Subject: [PATCH 6/6] Fix maxMovementSearchTime --- src/PlayerbotAIConfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PlayerbotAIConfig.cpp b/src/PlayerbotAIConfig.cpp index bf168bf61..8ddc3e0d9 100644 --- a/src/PlayerbotAIConfig.cpp +++ b/src/PlayerbotAIConfig.cpp @@ -53,7 +53,7 @@ bool PlayerbotAIConfig::Initialize() globalCoolDown = sConfigMgr->GetOption("AiPlayerbot.GlobalCooldown", 1500); maxWaitForMove = sConfigMgr->GetOption("AiPlayerbot.MaxWaitForMove", 5000); - maxMovementSearch = sConfigMgr->GetOption("AiPlayerbot.MaxMovementSearchTime", 3); + maxMovementSearchTime = sConfigMgr->GetOption("AiPlayerbot.MaxMovementSearchTime", 3); expireActionTime = sConfigMgr->GetOption("AiPlayerbot.ExpireActionTime", 5000); dispelAuraDuration = sConfigMgr->GetOption("AiPlayerbot.DispelAuraDuration", 7000); reactDelay = sConfigMgr->GetOption("AiPlayerbot.ReactDelay", 500);