diff --git a/src/modules/PlayerbotV2/Api/PlayerbotAPI.cpp b/src/modules/PlayerbotV2/Api/PlayerbotAPI.cpp index e5ed5049a7..18d943cc13 100644 --- a/src/modules/PlayerbotV2/Api/PlayerbotAPI.cpp +++ b/src/modules/PlayerbotV2/Api/PlayerbotAPI.cpp @@ -2307,6 +2307,36 @@ Result API::move_to(float x, float y, float z, bool run, bool direct, bool drop, } } + // A goal moved far UP onto a model: the bot asked for a spot at its own level (a wander step, a chunk of a long walk), and a height + // probe from high above or the polygon nearest the goal lies 8+ y higher on something that is not the terrain: a tree's roots or + // branches, a roof. Shadowglen 0.1.34: wander goals at the bot's level under Aldrassil were moved onto the tree (far_end_snap 1358.1 + // -> 1397.3, the NoPath retry from 50 y above landing 18 to 29 y up on the trunks), and the bots ran at the trees, stopped and picked + // again, round and round. A hill is terrain, so the terrain height there is close to the surface found and the goal still moves up. + // Open world only: in a dungeon, a battleground or a capital the floors are models and have their own guards. + bool const open_world_level_ask = std::fabs(z_ask - p_->GetPositionZ()) < ::Playerbot::V2::Fleet::kSameLevelYards + && p_->GetMap() && !p_->GetMap()->IsDungeon() && !p_->GetMap()->IsBattlegroundOrArena() + && !::Playerbot::V2::World::IsVanillaCapitalZone(p_->GetZoneId()) && !p_->GetTransport() && !p_->IsInWater(); + auto rise_onto_model = [&](float sx, float sy, float sz) -> bool + { + constexpr float kModelRise = 8.0f; + if (!open_world_level_ask || sz <= std::max(z_ask, p_->GetPositionZ()) + kModelRise) + return false; + float const terrain = p_->GetMap()->GetGridHeight(p_->GetPhaseShift(), sx, sy); + bool const on_model = terrain <= INVALID_HEIGHT || sz - terrain > 4.0f; + if (on_model) + { + static std::unordered_map s_modelAt; + uint32 const mnow = GameTime::GetGameTimeMS(); + uint32& mat = s_modelAt[p_->GetGUID().GetCounter()]; + if (mat == 0 || mnow - mat >= 10000u) + { + mat = mnow ? mnow : 1u; + TC_LOG_INFO("playerbot.v2", "[goal_on_model] {} asked ({:.1f},{:.1f},{:.1f}) at its own level, not moved up to {:.1f} at ({:.1f},{:.1f}): terrain {:.1f}", + p_->GetName(), x, y, z_ask, sz, sx, sy, terrain); + } + } + return on_model; + }; if (!path_ok || (pt & PATHFIND_NOPATH)) { // Dest-Z mesh-snap RETRY. Stepped/projected waypoints carry the @@ -2337,7 +2367,7 @@ Result API::move_to(float x, float y, float z, bool run, bool direct, bool drop, break; gz = below; } - if (gz > INVALID_HEIGHT && std::fabs(gz - z) > 8.0f) + if (gz > INVALID_HEIGHT && std::fabs(gz - z) > 8.0f && !rise_onto_model(x, y, gz)) { // Re-run on the SAME PathGenerator (repeated CalculatePath // calls overwrite internal state by design). @@ -2367,7 +2397,7 @@ Result API::move_to(float x, float y, float z, bool run, bool direct, bool drop, true, 160.0f); if (mz <= INVALID_HEIGHT) mz = (p_->GetPositionZ() + z) * 0.5f; - if (SehSafeCalculatePath(path, mx, my, mz) && + if (!rise_onto_model(mx, my, mz) && SehSafeCalculatePath(path, mx, my, mz) && !(path.GetPathType() & PATHFIND_NOPATH)) { pt = path.GetPathType(); @@ -2524,7 +2554,8 @@ Result API::move_to(float x, float y, float z, bool run, bool direct, bool drop, // one, so the goal was picked again and again (Burning Steppes, Simer: 53 path_fail Magma for one quest goal in 3 minutes). // Left unsnapped, the goal ends as FarFromPolyEnd, which suppresses it for long and lets goal selection move on. bool const end_in_hazard = BotMovement::ClassifyDestinationLiquid(p_, ae.x, ae.y, ae.z) == BotMovement::LiquidVerdict::Hazard; - if (off_end <= 12.0f && std::fabs(dz_end) < max_dz && !snaps_under && !end_in_hazard && !::Playerbot::V2::Fleet::PathHasCliff(path.GetPath())) + if (off_end <= 12.0f && std::fabs(dz_end) < max_dz && !snaps_under && !end_in_hazard && !::Playerbot::V2::Fleet::PathHasCliff(path.GetPath()) + && !rise_onto_model(ae.x, ae.y, ae.z)) { if (SehSafeCalculatePath(path, ae.x, ae.y, ae.z) && !(path.GetPathType() & (PATHFIND_NOPATH | PATHFIND_FARFROMPOLY_END))) { diff --git a/src/modules/PlayerbotV2/Bot/BotAI.h b/src/modules/PlayerbotV2/Bot/BotAI.h index 4ec9dc5275..a3013d7d05 100644 --- a/src/modules/PlayerbotV2/Bot/BotAI.h +++ b/src/modules/PlayerbotV2/Bot/BotAI.h @@ -2074,14 +2074,15 @@ public: std::lock_guard lk(quest_mem_mtx_); quest_blacklist_until_ms_[quest_id] = now_ms + kQuestBlacklistMs; } - bool quest_blacklisted(uint32 quest_id, uint32 now_ms) const + // fleet_memory=false: only this bot's own drops count, not the other bots' (a starting-zone quest, see the offer scan). + bool quest_blacklisted(uint32 quest_id, uint32 now_ms, bool fleet_memory = true) const { if (quest_id == 0) return false; std::lock_guard lk(quest_mem_mtx_); auto const it = quest_blacklist_until_ms_.find(quest_id); if (it == quest_blacklist_until_ms_.end()) // Not this bot's own drop: other bots may have given up on the walk to its goal (Travel/ReachMemory.h). - return ::Playerbot::V2::Travel::QuestGoalMemory::Instance().KnownUnreachable(quest_id, now_ms); + return fleet_memory && ::Playerbot::V2::Travel::QuestGoalMemory::Instance().KnownUnreachable(quest_id, now_ms); return now_ms < it->second; } // Drop expired entries. Called periodically from State_Idle (every ~5min) diff --git a/src/modules/PlayerbotV2/Bot/BotSnapshotBuilder.cpp b/src/modules/PlayerbotV2/Bot/BotSnapshotBuilder.cpp index cf481ec026..253344e336 100644 --- a/src/modules/PlayerbotV2/Bot/BotSnapshotBuilder.cpp +++ b/src/modules/PlayerbotV2/Bot/BotSnapshotBuilder.cpp @@ -5545,7 +5545,9 @@ std::shared_ptr BotSnapshotBuilder::Build(Player* p, BotAI* b // "dropped" the goal and was handed it right back). Honor it here // so dropping a goal actually rotates the picker to other work // for the blacklist window. - if (bot_ai && bot_ai->quest_blacklisted(q.quest_id, now_ms)) + // Only the bot's OWN drop counts here: the other bots' drops (QuestGoalMemory) are about starting a quest, and with them + // a bot halfway through a quest stopped working on it as soon as two others somewhere had given up on theirs. + if (bot_ai && bot_ai->quest_blacklisted(q.quest_id, now_ms, /*fleet_memory*/ false)) continue; // Level gate: skip a quest the bot is too LOW-level to actually do. // A bot force-granted a quest far above its level (verified live: L4 @@ -6092,7 +6094,7 @@ std::shared_ptr BotSnapshotBuilder::Build(Player* p, BotAI* b Quest const* dqt = sObjectMgr->GetQuestTemplate(dq.quest_id); if (dqt && dqt->GetRequiredSkill() && const_cast(p)->GetSkillValue(dqt->GetRequiredSkill()) == 0) skip = "skill"; - else if (bot_ai && bot_ai->quest_blacklisted(dq.quest_id, now_ms)) + else if (bot_ai && bot_ai->quest_blacklisted(dq.quest_id, now_ms, /*fleet_memory*/ false)) skip = "quest_blacklist"; else if (dqt && !const_cast(p)->SatisfyQuestMinLevel(dqt, false)) skip = "min_level"; @@ -7442,7 +7444,17 @@ std::shared_ptr BotSnapshotBuilder::Build(Player* p, BotAI* b // Cheapest first: skip quests already in the log and the // per-bot blacklists. if (p->GetQuestStatus(qid) != QUEST_STATUS_NONE) continue; - if (offer_bot_ai && offer_bot_ai->quest_blacklisted(qid, offer_now_ms)) + // A starting-zone quest (bot and quest at level 10 or below) is taken even when other bots gave up on its goal: the + // first quests of a zone open everything after them, so skipping one strands every new bot there (Shadowglen 0.1.34: + // two drops of The Balance of Nature left 40 bots with empty quest logs). Only the bot's own drop skips it. + bool const starter_quest = [&] + { + if (p->GetLevel() > 10) + return false; + Quest const* sq = sObjectMgr->GetQuestTemplate(qid); + return sq && p->GetQuestLevel(sq) <= 10; + }(); + if (offer_bot_ai && offer_bot_ai->quest_blacklisted(qid, offer_now_ms, /*fleet_memory*/ !starter_quest)) continue; // Permanent class/race-impossible skip — these gates never flip // for this bot, so don't re-run the expensive CanTakeQuest or diff --git a/src/modules/PlayerbotV2/Bot/Quest/CompanionQuest.cpp b/src/modules/PlayerbotV2/Bot/Quest/CompanionQuest.cpp index 4e0fd85615..a7a424c9ea 100644 --- a/src/modules/PlayerbotV2/Bot/Quest/CompanionQuest.cpp +++ b/src/modules/PlayerbotV2/Bot/Quest/CompanionQuest.cpp @@ -174,7 +174,8 @@ void BuildState(Player* bot, BotAI* ai, BotSnapshot& snap) QuestStatus const os = owner->GetQuestStatus(qid); bool const owner_holds = os == QUEST_STATUS_INCOMPLETE; if (!owner_holds && !accept_all) continue; - if (ai && ai->quest_blacklisted(qid, now_ms)) continue; + // The player holds the quest: the companion takes it too, whatever other bots elsewhere gave up on. + if (ai && ai->quest_blacklisted(qid, now_ms, /*fleet_memory*/ !owner_holds)) continue; if (!BotCanTake(bot, qid)) continue; CompanionQuestAction a; a.giver = giver; diff --git a/src/modules/PlayerbotV2/Bot/States/State_Idle.cpp b/src/modules/PlayerbotV2/Bot/States/State_Idle.cpp index 2a2db6f0ed..7e8e8b5b1b 100644 --- a/src/modules/PlayerbotV2/Bot/States/State_Idle.cpp +++ b/src/modules/PlayerbotV2/Bot/States/State_Idle.cpp @@ -19997,7 +19997,7 @@ bool AutoactDispatch(BotSnapshotView const& s, BotAI& ai, if (t.goal_is_quest && s.current_quest_id() != 0) { ai.blacklist_quest(s.current_quest_id(), now_ms); - ::Playerbot::V2::Travel::QuestGoalMemory::Instance().NoteDropped(s.current_quest_id(), now_ms); + ::Playerbot::V2::Travel::QuestGoalMemory::Instance().NoteDropped(s.current_quest_id(), uint64(s.bot_id()), now_ms); tw.last_recovery_ms = now_ms; tw.recovery_tier = 3; ai.set_last_rule_fired("idle:unstick:drop_goal"); diff --git a/src/modules/PlayerbotV2/Travel/ReachMemory.h b/src/modules/PlayerbotV2/Travel/ReachMemory.h index a3b6cade2e..02076c8f07 100644 --- a/src/modules/PlayerbotV2/Travel/ReachMemory.h +++ b/src/modules/PlayerbotV2/Travel/ReachMemory.h @@ -119,21 +119,27 @@ private: // QuestGoalMemory - the same idea for a quest objective: when bots keep giving up on the walk to one quest's goal (the tracker drops the goal // after it made no progress), the other bots stop starting that quest for a while instead of each paying the same 90 s wedge //. Per quest, not per place: the objective is one point. +// Several DIFFERENT bots must have given up, not one bot twice, and the memory lasts 10 minutes. With two drops (any bots) and 30 +// minutes, renewed by every new drop, Shadowglen's first quest The Balance of Nature (456) was skipped by every bot of the zone in +// 0.1.34: the bots there wedge on Aldrassil's roots now and then, two drops locked the quest for the whole fleet, and as every +// other Shadowglen quest follows it, 40 bots of level 1 to 5 stood with empty quest logs and wandered (9,599 quest_offer_refused, +// 2,556 quest_truly_stuck). The offer scan also leaves this memory out for starting-zone quests (BotSnapshotBuilder). class QuestGoalMemory { public: - static constexpr std::uint32_t kTtlMs = 30u * 60u * 1000u; - static constexpr std::uint32_t kMinDrops = 2; // one bot can be stuck for its own reasons (a pack on the path, its own gear) + static constexpr std::uint32_t kTtlMs = 10u * 60u * 1000u; + static constexpr std::uint32_t kMinBots = 3; // one bot can be stuck for its own reasons (a pack on the path, its own gear) - void NoteDropped(std::uint32_t quest_id, std::uint32_t now_ms) + void NoteDropped(std::uint32_t quest_id, std::uint64_t bot_id, std::uint32_t now_ms) { if (quest_id == 0) return; std::lock_guard lk(mx_); Entry& e = quests_[quest_id]; - if (e.drops == 0 || std::uint32_t(now_ms - e.last_ms) >= kTtlMs) - e.drops = 0; - ++e.drops; + if (e.bots.empty() || std::uint32_t(now_ms - e.last_ms) >= kTtlMs) + e.bots.clear(); + if (std::find(e.bots.begin(), e.bots.end(), bot_id) == e.bots.end() && e.bots.size() < 8) + e.bots.push_back(bot_id); e.last_ms = now_ms; } @@ -143,7 +149,7 @@ public: return false; std::lock_guard lk(mx_); auto const it = quests_.find(quest_id); - return it != quests_.end() && it->second.drops >= kMinDrops && std::uint32_t(now_ms - it->second.last_ms) < kTtlMs; + return it != quests_.end() && it->second.bots.size() >= kMinBots && std::uint32_t(now_ms - it->second.last_ms) < kTtlMs; } static QuestGoalMemory& Instance() @@ -153,7 +159,7 @@ public: } private: - struct Entry { std::uint32_t last_ms = 0; std::uint32_t drops = 0; }; + struct Entry { std::uint32_t last_ms = 0; std::vector bots; }; mutable std::mutex mx_; std::unordered_map quests_; }; diff --git a/tests/game/ClassicReachMemory.cpp b/tests/game/ClassicReachMemory.cpp index cf704d793f..582eb13e30 100644 --- a/tests/game/ClassicReachMemory.cpp +++ b/tests/game/ClassicReachMemory.cpp @@ -80,17 +80,21 @@ TEST_CASE("ReachMemory: the table never grows past its cap and keeps the newest" CHECK(m.KnownUnreachable(0, 0, 0, last, 0, t)); } -TEST_CASE("QuestGoalMemory: two bots giving up on a quest make it known unreachable until the time is up", "[reachmemory]") +TEST_CASE("QuestGoalMemory: three different bots giving up on a quest make it known unreachable until the time is up", "[reachmemory]") { QuestGoalMemory m; CHECK_FALSE(m.KnownUnreachable(4286, 1000)); - m.NoteDropped(4286, 1000); - CHECK_FALSE(m.KnownUnreachable(4286, 1100)); // one bot may be stuck for its own reasons - m.NoteDropped(4286, 2000); + m.NoteDropped(4286, 11, 1000); + m.NoteDropped(4286, 11, 1050); + m.NoteDropped(4286, 11, 1080); + CHECK_FALSE(m.KnownUnreachable(4286, 1100)); // one bot stuck again and again is that bot's own trouble + m.NoteDropped(4286, 12, 1500); + CHECK_FALSE(m.KnownUnreachable(4286, 1600)); // two bots are not enough (Shadowglen 0.1.34) + m.NoteDropped(4286, 13, 2000); CHECK(m.KnownUnreachable(4286, 3000)); CHECK_FALSE(m.KnownUnreachable(4287, 3000)); // another quest is not affected CHECK_FALSE(m.KnownUnreachable(4286, 2000 + QuestGoalMemory::kTtlMs)); - m.NoteDropped(4286, 2000 + QuestGoalMemory::kTtlMs + 5); // an old count does not carry over the expiry + m.NoteDropped(4286, 14, 2000 + QuestGoalMemory::kTtlMs + 5); // an old count does not carry over the expiry CHECK_FALSE(m.KnownUnreachable(4286, 2000 + QuestGoalMemory::kTtlMs + 10)); CHECK_FALSE(m.KnownUnreachable(0, 3000)); }