analyze: allow to disable goal marking analyze: add cvars descriptions and bounds nav: added optional post path smoothing for astar algorithm nav: now bots will use Dijkstra algo instead of floyd-warshall if memory usage too high (controlled via yb_path_floyd_memory_limit cvar) (fixes #434) nav: vistable are now calculated every frame to prevent game-freeze during loading the game (fixes #434) graph: pracrice reworked to hash table so memory footprint is as low as possible (at cost 5-10% performance loss on practice) (fixes #434) control: bots commands now is case-insensitive bot: major refactoring of bot's code nav: issue warnings about path fail only with debug practice: check for visibility when updating danger index analyzer: suspend any analyzing on change level control: add kickall_ct/kickall_t nav: increase blocked distance in stuck check
121 lines
3 KiB
C++
121 lines
3 KiB
C++
//
|
|
// YaPB - Counter-Strike Bot based on PODBot by Markus Klinge.
|
|
// Copyright © 2004-2023 YaPB Project <yapb@jeefo.net>.
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
//
|
|
|
|
#pragma once
|
|
|
|
// limits for storing practice data
|
|
CR_DECLARE_SCOPED_ENUM_TYPE (PracticeLimit, int32_t,
|
|
Goal = 2040,
|
|
Damage = 2040
|
|
);
|
|
|
|
// storage for from, to, team
|
|
class DangerStorage final {
|
|
protected:
|
|
uint16_t data[3] {};
|
|
|
|
public:
|
|
constexpr DangerStorage () = default;
|
|
|
|
public:
|
|
constexpr DangerStorage (const int32_t &a, const int32_t &b, const int32_t &c) :
|
|
data { static_cast <uint16_t> (a), static_cast <uint16_t> (b), static_cast <uint16_t> (c) } {}
|
|
|
|
public:
|
|
constexpr bool operator == (const DangerStorage &rhs) const {
|
|
return rhs.data[2] == data[2] && rhs.data[1] == data[1] && rhs.data[0] == data[0];
|
|
}
|
|
|
|
constexpr bool operator != (const DangerStorage &rhs) const {
|
|
return !operator == (rhs);
|
|
}
|
|
|
|
public:
|
|
// fnv1a for 3d vector hash
|
|
constexpr uint32_t hash () const {
|
|
constexpr uint32_t prime = 16777619u;
|
|
constexpr uint32_t seed = 2166136261u;
|
|
|
|
uint32_t hash = seed;
|
|
|
|
for (const auto &key : data) {
|
|
hash = (hash * prime) ^ key;
|
|
}
|
|
return hash;
|
|
}
|
|
};
|
|
|
|
// define hash function for hash map
|
|
CR_NAMESPACE_BEGIN
|
|
|
|
template <> struct Hash <DangerStorage> {
|
|
uint32_t operator () (const DangerStorage &key) const noexcept {
|
|
return key.hash ();
|
|
}
|
|
};
|
|
|
|
CR_NAMESPACE_END
|
|
|
|
class BotPractice final : public Singleton <BotPractice> {
|
|
public:
|
|
// collected data
|
|
struct PracticeData {
|
|
int16_t damage {}, value {};
|
|
int16_t index { kInvalidNodeIndex };
|
|
};
|
|
|
|
// used to save-restore practice data
|
|
struct DangerSaveRestore {
|
|
DangerStorage danger {};
|
|
PracticeData data {};
|
|
|
|
public:
|
|
DangerSaveRestore () = default;
|
|
|
|
public:
|
|
DangerSaveRestore (const DangerStorage &ds, const PracticeData &pd) : danger (ds), data (pd) {}
|
|
};
|
|
|
|
HashMap <DangerStorage, PracticeData> m_data {};
|
|
int32_t m_teamHighestDamage[kGameTeamNum] {};
|
|
|
|
public:
|
|
BotPractice () = default;
|
|
~BotPractice () = default;
|
|
|
|
private:
|
|
inline bool exists (int32_t team, int32_t start, int32_t goal) const {
|
|
return m_data.exists ({ start, goal, team });
|
|
}
|
|
|
|
public:
|
|
int32_t getIndex (int32_t team, int32_t start, int32_t goal);
|
|
void setIndex (int32_t team, int32_t start, int32_t goal, int32_t value);
|
|
|
|
int32_t getValue (int32_t team, int32_t start, int32_t goal);
|
|
void setValue (int32_t team, int32_t start, int32_t goal, int32_t value);
|
|
|
|
int32_t getDamage (int32_t team, int32_t start, int32_t goal);
|
|
void setDamage (int32_t team, int32_t start, int32_t goal, int32_t value);
|
|
|
|
public:
|
|
void update ();
|
|
void load ();
|
|
void save ();
|
|
|
|
public:
|
|
int32_t getHighestDamageForTeam (int32_t team) const {
|
|
return cr::max (1, m_teamHighestDamage[team]);
|
|
}
|
|
|
|
void setHighestDamageForTeam (int32_t team, int32_t value) {
|
|
m_teamHighestDamage[team] = value;
|
|
}
|
|
};
|
|
|
|
// explose global
|
|
CR_EXPOSE_GLOBAL_SINGLETON (BotPractice, practice);
|