mod-playerbots/src/Ai/Base/Value/PositionValue.h
bashermens 13fff46fa0
Improper singletons migration to clean Meyer's singletons (cherry-pick) (#2082)
# Pull Request

- Applies the clean and corrected singletons, Meyer pattern. (cherry
picked from @SmashingQuasar )

Testing by just playing the game in various ways. Been tested by myself
@Celandriel and @SmashingQuasar
---

## 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**)

---

## AI Assistance

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

## 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.

---------

Co-authored-by: Nicolas Lebacq <nicolas.cordier@outlook.com>
Co-authored-by: Keleborn <22352763+Celandriel@users.noreply.github.com>
2026-01-30 21:49:37 +01:00

90 lines
2.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.
*/
#ifndef _PLAYERBOT_POSITIONVALUE_H
#define _PLAYERBOT_POSITIONVALUE_H
#include "NamedObjectContext.h"
#include "TravelMgr.h"
#include "Value.h"
class PlayerbotAI;
class PositionInfo
{
public:
PositionInfo() : x(0), y(0), z(0), mapId(0), valueSet(false) {}
PositionInfo(float x, float y, float z, uint32 mapId, bool valueSet = true)
: x(x), y(y), z(z), mapId(mapId), valueSet(valueSet)
{
}
PositionInfo(PositionInfo const& other)
: x(other.x), y(other.y), z(other.z), mapId(other.mapId), valueSet(other.valueSet)
{
}
void Set(float newX, float newY, float newZ, uint32 newMapId)
{
x = newX;
y = newY;
z = newZ;
mapId = newMapId;
valueSet = true;
}
void Reset() { valueSet = false; }
bool isSet() { return valueSet; }
float x;
float y;
float z;
uint32 mapId;
bool valueSet;
};
typedef std::map<std::string, PositionInfo> PositionMap;
class PositionValue : public ManualSetValue<PositionMap&>
{
public:
PositionValue(PlayerbotAI* botAI, std::string const name = "position");
std::string const Save() override;
bool Load(std::string const value) override;
private:
PositionMap positions;
};
class CurrentPositionValue : public LogCalculatedValue<WorldPosition>
{
public:
CurrentPositionValue(PlayerbotAI* botAI, std::string const name = "current position", uint32 checkInterval = 1)
: LogCalculatedValue<WorldPosition>(botAI, name, checkInterval)
{
minChangeInterval = 60;
logLength = 30;
};
bool EqualToLast(WorldPosition value) override
{
return value.fDist(lastValue) < sPlayerbotAIConfig.tooCloseDistance;
}
WorldPosition Calculate() override;
};
class SinglePositionValue : public CalculatedValue<PositionInfo>, public Qualified
{
public:
SinglePositionValue(PlayerbotAI* ai, std::string name = "pos") : CalculatedValue(ai, name), Qualified() {};
virtual PositionInfo Calculate() override;
virtual void Set(PositionInfo value) override;
virtual void Reset() override;
};
#endif