2019-08-12 14:16:28 +03:00
|
|
|
//
|
2023-05-24 23:41:23 +03:00
|
|
|
// YaPB, based on PODBot by Markus Klinge ("CountFloyd").
|
|
|
|
|
// Copyright © YaPB Project Developers <yapb@jeefo.net>.
|
2019-08-12 14:16:28 +03:00
|
|
|
//
|
2020-11-03 08:57:12 +03:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-08-12 14:16:28 +03:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2020-06-12 18:52:38 +03:00
|
|
|
class BotSupport final : public Singleton <BotSupport> {
|
2025-02-15 13:51:45 +03:00
|
|
|
using AliasInfo = Twin <StringRef, StringRef>;
|
|
|
|
|
using AliasMap = HashMap <int32_t, AliasInfo, EmptyHash <int32_t> >;
|
|
|
|
|
|
2019-08-12 14:16:28 +03:00
|
|
|
private:
|
2023-04-02 12:17:12 +03:00
|
|
|
bool m_needToSendWelcome {};
|
|
|
|
|
float m_welcomeReceiveTime {};
|
2019-08-12 14:16:28 +03:00
|
|
|
|
2023-04-02 12:17:12 +03:00
|
|
|
StringArray m_sentences {};
|
|
|
|
|
SmallArray <Client> m_clients {};
|
2019-08-12 14:16:28 +03:00
|
|
|
|
2025-02-15 13:51:45 +03:00
|
|
|
AliasMap m_weaponAliases {};
|
2019-08-12 14:16:28 +03:00
|
|
|
|
|
|
|
|
public:
|
2020-06-12 18:52:38 +03:00
|
|
|
BotSupport ();
|
|
|
|
|
~BotSupport () = default;
|
2019-08-12 14:16:28 +03:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// need to send welcome message ?
|
|
|
|
|
void checkWelcome ();
|
|
|
|
|
|
2019-09-14 23:13:55 +03:00
|
|
|
// converts weapon id to alias name
|
aim: verify camp angles from nav data before using them
aim: tweaked a bit grenade handling, so bots should use them more
aim: reduce time between selecting grenade and throwing it away
aim: removed hacks in look angles code, due to removing yb_whoose_your_daddy cvar
aim: use direct enemy origin from visibility check, and not re-calculate it
aim: update enemy prediction, so it now depends on frame interval for a bot
aim: additional height offset are tweaked, and now used only for difficulty 4
nav: tweaked a bit player avoidance code, and it's not preventing bot from checking terrain
nav: do not check banned nodes, when bucket sizes re too low
nav: cover nodes are now selected depending on total bots on server
nav: let bot enter pause task after long jump
nav: extend velocity by a little for a jump, like it was in first versions of bot
nav: stuck checking is now taken in account lower minimal speed if bot is ducking
fix: navigation reachability timers, so bots will have correct current node index while camping
fix: bots are unable to finish pickup or destroy breakable task, if target is not reachable
fix: cover nodes are now calculated as they should
fix: manual calling bots add_[t/ct] now ignores yb_join_team cvar
bot: tweaked a little difficulty levels, so level 4 is now nightmare level, and 3 is very heard
bot: minor refactoring and moving functions to correct source file
bot: add yb_economics_disrespect_percent, so bots can ignore economics and buy more different guns
bot: add yb_check_darkness that allows to disable darkness checks for bot, thus disallowing usage of flashlight
bot: camp buttons are now lightly depends on bot health
chat: welcome chat message from bots is now sent during first freeze time period
crlib: switch over to stdint.h and remove crlib-own types
crlib: fixed alignment in sse code
2023-04-07 14:46:49 +03:00
|
|
|
StringRef weaponIdToAlias (int32_t id);
|
2019-08-12 14:16:28 +03:00
|
|
|
|
|
|
|
|
// nearest player search helper
|
|
|
|
|
bool findNearestPlayer (void **holder, edict_t *to, float searchDistance = 4096.0, bool sameTeam = false, bool needBot = false, bool needAlive = false, bool needDrawn = false, bool needBotWithC4 = false);
|
|
|
|
|
|
|
|
|
|
// tracing decals for bots spraying logos
|
2025-02-05 21:28:29 +03:00
|
|
|
void decalTrace (TraceResult *trace, int decalIndex);
|
2019-08-12 14:16:28 +03:00
|
|
|
|
|
|
|
|
// update stats on clients
|
|
|
|
|
void updateClients ();
|
|
|
|
|
|
2025-10-08 20:12:46 +03:00
|
|
|
// check if origin is visible from the entity side
|
|
|
|
|
bool isVisible (const Vector &origin, edict_t *ent);
|
2020-12-15 15:28:58 +03:00
|
|
|
|
2022-01-16 01:14:11 +03:00
|
|
|
// get the current date and time as string
|
|
|
|
|
String getCurrentDateTime ();
|
|
|
|
|
|
2024-01-19 18:29:20 +03:00
|
|
|
// generates fake steam id from bot name
|
|
|
|
|
StringRef getFakeSteamId (edict_t *ent);
|
|
|
|
|
|
2023-08-22 09:45:29 +03:00
|
|
|
// get's the wave length
|
2025-03-16 18:25:15 +03:00
|
|
|
float getWaveFileDuration (StringRef filename);
|
2023-08-22 09:45:29 +03:00
|
|
|
|
2025-02-15 13:51:45 +03:00
|
|
|
// set custom cvar descriptions
|
|
|
|
|
void setCustomCvarDescriptions ();
|
|
|
|
|
|
2025-10-08 20:12:46 +03:00
|
|
|
// check if line of sight blocked by a smoke
|
|
|
|
|
bool isLineBlockedBySmoke (const Vector &from, const Vector &to);
|
|
|
|
|
|
2019-08-12 14:16:28 +03:00
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
// re-show welcome after changelevel ?
|
|
|
|
|
void setNeedForWelcome (bool need) {
|
|
|
|
|
m_needToSendWelcome = need;
|
2024-01-19 00:03:45 +03:00
|
|
|
m_welcomeReceiveTime = -1.0f;
|
2019-08-12 14:16:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get array of clients
|
|
|
|
|
SmallArray <Client> &getClients () {
|
|
|
|
|
return m_clients;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get clients as const-reference
|
|
|
|
|
const SmallArray <Client> &getClients () const {
|
|
|
|
|
return m_clients;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get single client as ref
|
|
|
|
|
Client &getClient (const int index) {
|
|
|
|
|
return m_clients[index];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 23:31:54 +03:00
|
|
|
// gets the shooting cone deviation
|
2024-03-09 01:06:11 +03:00
|
|
|
float getConeDeviation (edict_t *ent, const Vector &pos) const {
|
2023-08-08 11:48:37 +03:00
|
|
|
return ent->v.v_angle.forward () | (pos - (ent->v.origin + ent->v.view_ofs)).normalize (); // he's facing it, he meant it
|
2019-08-29 23:31:54 +03:00
|
|
|
}
|
|
|
|
|
|
2023-08-08 11:48:37 +03:00
|
|
|
// check if position is inside view cone of entity
|
2024-03-09 01:06:11 +03:00
|
|
|
bool isInViewCone (const Vector &pos, edict_t *ent) const {
|
|
|
|
|
return getConeDeviation (ent, pos) >= cr::cosf (cr::deg2rad ((ent->v.fov > 0 ? ent->v.fov : 90.0f) * 0.5f));
|
2019-08-29 23:31:54 +03:00
|
|
|
}
|
2019-08-12 14:16:28 +03:00
|
|
|
};
|
|
|
|
|
|
2023-05-12 22:12:22 +03:00
|
|
|
// expose global
|
2020-06-12 18:52:38 +03:00
|
|
|
CR_EXPOSE_GLOBAL_SINGLETON (BotSupport, util);
|