Tweak mob roaming logic and a few other values

This fixes the crash with mobs with a very small m_iIdleRange and avoids
unnecessary looping.

Co-authored-by: JadeShrineMaiden <69916714+JadeShrineMaiden@users.noreply.github.com>
This commit is contained in:
dongresource 2020-12-17 01:59:55 +01:00
parent 618a8d0a9f
commit f7a6615379
5 changed files with 20 additions and 14 deletions

View File

@ -661,19 +661,24 @@ void MobManager::roamingStep(Mob *mob, time_t currTime) {
if (mob->idleRange == 0 || speed == 0)
return;
int farX, farY;
int distance; // for short walk detection
int farX, farY, distance;
int minDistance = mob->idleRange / 2;
/*
* We don't want the mob to just take one step and stop, so we make sure
* it has walked a half-decent distance.
*/
do {
// pick a random destination
farX = xStart + rand() % mob->idleRange;
farY = yStart + rand() % mob->idleRange;
distance = std::hypot(mob->appearanceData.iX - farX, mob->appearanceData.iY - farY);
} while (distance < 500);
distance = std::abs(std::max(farX - mob->appearanceData.iX, farY - mob->appearanceData.iY));
if (distance == 0)
distance += 1; // hack to avoid FPE
// if it's too short a walk, go further in that direction
farX = mob->appearanceData.iX + (farX - mob->appearanceData.iX) * minDistance / distance;
farY = mob->appearanceData.iY + (farY - mob->appearanceData.iY) * minDistance / distance;
// but don't got out of bounds
farX = std::clamp(farX, xStart, xStart + mob->idleRange);
farY = std::clamp(farY, yStart, yStart + mob->idleRange);
// halve movement speed if snared
if (mob->appearanceData.iConditionBitFlag & CSB_BIT_DN_MOVE_SPEED)

View File

@ -70,7 +70,7 @@ struct Mob : public BaseNPC {
data = d;
regenTime = data["m_iRegenTime"];
idleRange = (int)data["m_iIdleRange"] * 2; // TODO: tuning?
idleRange = (int)data["m_iIdleRange"];
dropType = data["m_iDropType"];
level = data["m_iNpcLevel"];

View File

@ -908,7 +908,7 @@ std::string PlayerManager::getPlayerName(Player *plr, bool id) {
return "NOT IN GAME";
std::string ret = "";
if (id && plr->accountLevel <= 10)
if (id && plr->accountLevel <= 30)
ret += "(GM) ";
ret += U16toU8(plr->PCStyle.szFirstName) + " " + U16toU8(plr->PCStyle.szLastName);

View File

@ -1,4 +1,5 @@
leak:TableData::init
leak:ChunkManager::newChunk
leak:NPCManager::updateNPCPosition
leak:NPCManager::summonNPC
leak:NanoManager::doBuff

2
tdata

@ -1 +1 @@
Subproject commit daba8a8a622ab9f2f63a72a66c243a49ea926088
Subproject commit a36aca30c9ff69b39a1b128227a6e69c77e3c00e