Files
mod-playerbots/src/Ai/Base/Actions/TaxiAction.cpp
NoxMax b7b67e0fd9 Feat/Fix: Expand follower bot flightmaster distance search and use correct config patterns (#2140)
# Pull Request

Feat:
A common problem I have with follower bots is that if I quickly run up
to a flightmaster and select a destination, as I go on my way, the bots
can't get on a damn bird and say "Cannot find any flightmaster to talk".
Guy was 8 yards away and they're completely blind to him.

This is because when you select a destination, at that moment the bot
would check `GetNPCIfCanInteractWith` from core, which uses
`INTERACTION_DISTANCE`, which is defined as 5.5 yards. So the bot has to
have caught up with you to be within 5.5 yards of the flightmaster.

This PR expands that distance to use our own
`sPlayerbotAIConfig.farDistance`, which is by default set to 20 yards.
So just as long as bots have caught up to be within 20 yards from the
flightmaster, they will follow you.

Fix:
While I was doing this, I noticed that the timings for bot flight
staggering (introduced in #1281) are defined in TaxiAction and
PlayerbotAIConfig. So I removed their definitions from TaxiAction, made
proper calls to the configs, and renamed them to similar format that
other configs use.

---

## Design Philosophy

We prioritize **stability, performance, and predictability** over
behavioral realism.
Complex player-mimicking logic is intentionally limited due to its
negative impact on scalability, maintainability, and
long-term robustness.

Excessive processing overhead can lead to server hiccups, increased CPU
usage, and degraded performance for all
participants. Because every action and
decision tree is executed **per bot and per trigger**, even small
increases in logic complexity can scale poorly and
negatively affect both players and
world (random) bots. Bots are not expected to behave perfectly, and
perfect simulation of human decision-making is not a
project goal. Increased behavioral
realism often introduces disproportionate cost, reduced predictability,
and significantly higher maintenance overhead.

Every additional branch of logic increases long-term responsibility. All
decision paths must be tested, validated, and
maintained continuously as the system evolves.
If advanced or AI-intensive behavior is introduced, the **default
configuration must remain the lightweight decision
model**. More complex behavior should only be
available as an **explicit opt-in option**, clearly documented as having
a measurable performance cost.

Principles:

- **Stability before intelligence**  
  A stable system is always preferred over a smarter one.

- **Performance is a shared resource**  
  Any increase in bot cost affects all players and all bots.

- **Simple logic scales better than smart logic**  
Predictable behavior under load is more valuable than perfect decisions.

- **Complexity must justify itself**  
  If a feature cannot clearly explain its cost, it should not exist.

- **Defaults must be cheap**  
  Expensive behavior must always be optional and clearly communicated.

- **Bots should look reasonable, not perfect**  
  The goal is believable behavior, not human simulation.

Before submitting, confirm that this change aligns with those
principles.

---

## Feature Evaluation

Please answer the following:

- Describe the **minimum logic** required to achieve the intended
behavior?
- Describe the **cheapest implementation** that produces an acceptable
result?
- Describe the **runtime cost** when this logic executes across many
bots?

Changes here use a minimal amount of code to accomplish the objective,
including using pre-defined distance values rather than creating new
ones. Changes have no effect on processing.

---

## How to Test the Changes

For expanding flightmaster search distance: You will be using the `stay`
command. A bot commanded to `stay` will still take a flight with you, if
it is near a flightmaster. So you can use the command to position the
bot exactly where you want it to be
1. Place your follower bot immediately next to the flightmaster
2. Take a flight and the bot should follow. Nothing new here
3. Place the bot about 12 yards away from flightmaster.
4. Take a flight and the bot should follow. Same as before.
5. Repeat again, but this time place the bot 22 yards away. It should
not follow you and instead say "Cannot find any flightmaster to talk"
6. The change should work correctly with `InstantFlightPaths = 0` in
worldserver.conf, or if it's set to 1/2 and bots can instantly fly.

For the config of staggering:
1. Make sure `InstantFlightPaths = 0` in worldserver.conf.
2. Change the timings in playerbots.conf under the `# FLIGHTPATH`
section.
3. Changes should be correctly reflected in world.


## Complexity & Impact

Does this change add new decision branches?
- - [x] No
- - [ ] Yes (**explain below**)

Does this change increase per-bot or per-tick processing?
- - [x] No
- - [ ] Yes (**describe and justify impact**)

Could this logic scale poorly under load?
- - [x] No
- - [ ] Yes (**explain why**)
---

## Defaults & Configuration

Does this change modify default bot behavior?
- - [x] No
- - [ ] Yes (**explain why**)

Follower bots search a slightly bigger distance for nearby
flightmasters.

If this introduces more advanced or AI-heavy logic:
- - [x] Lightweight mode remains the default
- - [x] More complex behavior is optional and thereby configurable
---

## AI Assistance

Was AI assistance (e.g. ChatGPT or similar tools) used while working on
this change?
- - [x] No
- - [ ] Yes (**explain below**)

If yes, please specify:

- AI tool or model used (e.g. ChatGPT, GPT-4, Claude, etc.)
- Purpose of usage (e.g. brainstorming, refactoring, documentation, code
generation)
- Which parts of the change were influenced or generated
- Whether the result was manually reviewed and adapted

AI assistance is allowed, but all submitted code must be fully
understood, reviewed, and owned by the contributor.
Any AI-influenced changes must be verified against existing CORE and PB
logic. We expect contributors to be honest
about what they do and do not understand.

---

## Final Checklist

- - [x] Stability is not compromised
- - [x] Performance impact is understood, tested, and acceptable
- - [x] Added logic complexity is justified and explained
- - [x] Documentation updated if needed

---

## Notes for Reviewers

Anything that significantly improves realism at the cost of stability or
performance should be carefully discussed
before merging.
2026-02-27 16:07:42 -08:00

133 lines
4.3 KiB
C++

/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#include "TaxiAction.h"
#include "Event.h"
#include "LastMovementValue.h"
#include "Playerbots.h"
#include "PlayerbotAIConfig.h"
#include "Config.h"
bool TaxiAction::Execute(Event event)
{
botAI->RemoveShapeshift();
LastMovement& movement = context->GetValue<LastMovement&>("last taxi")->Get();
WorldPacket& p = event.getPacket();
std::string const param = event.getParam();
if ((!p.empty() && (p.GetOpcode() == CMSG_TAXICLEARALLNODES || p.GetOpcode() == CMSG_TAXICLEARNODE)) ||
param == "clear")
{
movement.taxiNodes.clear();
movement.Set(nullptr);
botAI->TellMaster("I am ready for the next flight");
return true;
}
GuidVector units = *context->GetValue<GuidVector>("nearest npcs");
for (ObjectGuid const guid : units)
{
Creature* npc = ObjectAccessor::GetCreature(*bot, guid);
if (!npc || !npc->IsAlive())
continue;
if (!(npc->GetNpcFlags() & UNIT_NPC_FLAG_FLIGHTMASTER))
continue;
if (bot->GetDistance(npc) > sPlayerbotAIConfig.farDistance)
continue;
uint32 curloc = sObjectMgr->GetNearestTaxiNode(npc->GetPositionX(), npc->GetPositionY(), npc->GetPositionZ(),
npc->GetMapId(), bot->GetTeamId());
std::vector<uint32> nodes;
for (uint32 i = 0; i < sTaxiPathStore.GetNumRows(); ++i)
{
if (TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(i))
if (entry->from == curloc)
{
uint8 field = uint8((i - 1) / 32);
if (field < TaxiMaskSize)
nodes.push_back(i);
}
}
// Only for follower bots
if (botAI->HasRealPlayerMaster())
{
uint32 index = botAI->GetGroupSlotIndex(bot);
uint32 delay = sPlayerbotAIConfig.botTaxiDelayMin +
index * sPlayerbotAIConfig.botTaxiGapMs +
urand(0, sPlayerbotAIConfig.botTaxiGapJitterMs);
delay = std::min(delay, sPlayerbotAIConfig.botTaxiDelayMax);
// Store the NPC's GUID so we can re-acquire the pointer later
ObjectGuid npcGuid = npc->GetGUID();
// schedule the take-off
botAI->AddTimedEvent(
[bot = bot, &movement, npcGuid]() -> void
{
if (Creature* npcPtr = ObjectAccessor::GetCreature(*bot, npcGuid))
if (!movement.taxiNodes.empty())
bot->ActivateTaxiPathTo(movement.taxiNodes, npcPtr, 0);
},
delay);
botAI->SetNextCheckDelay(delay + 50);
return true;
}
if (param == "?")
{
botAI->TellMasterNoFacing("=== Taxi ===");
uint32 index = 1;
for (uint32 node : nodes)
{
TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(node);
if (!entry)
continue;
TaxiNodesEntry const* dest = sTaxiNodesStore.LookupEntry(entry->to);
if (!dest)
continue;
std::ostringstream out;
out << index++ << ": " << dest->name[0];
botAI->TellMasterNoFacing(out.str());
}
return true;
}
uint32 selected = atoi(param.c_str());
if (selected)
{
uint32 path = nodes[selected - 1];
TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(path);
if (!entry)
return false;
return bot->ActivateTaxiPathTo({entry->from, entry->to}, npc, 0);
}
if (!movement.taxiNodes.empty() && !bot->ActivateTaxiPathTo(movement.taxiNodes, npc, 0))
{
movement.taxiNodes.clear();
movement.Set(nullptr);
botAI->TellError("I can't fly with you");
return false;
}
return true;
}
botAI->TellError("Cannot find any flightmaster to talk");
return false;
}