yapb-noob-edition/inc/config.h

255 lines
6.6 KiB
C
Raw Permalink Normal View History

//
// YaPB, based on PODBot by Markus Klinge ("CountFloyd").
// Copyright © YaPB Project Developers <yapb@jeefo.net>.
//
// SPDX-License-Identifier: MIT
//
#pragma once
// botname structure definition
struct BotName {
String name {};
int usedBy = -1;
public:
BotName () = default;
2023-03-13 15:39:15 +03:00
BotName (StringRef name, int usedBy) : name (name), usedBy (usedBy) {}
};
// voice config structure definition
struct ChatterItem {
String name {};
float repeat {};
float duration {};
public:
2023-03-13 15:39:15 +03:00
ChatterItem (StringRef name, float repeat, float duration) : name (name), repeat (repeat), duration (duration) {}
};
// mostly config stuff, and some stuff dealing with menus
class BotConfig final : public Singleton <BotConfig> {
private:
Array <StringArray> m_chat {};
Array <Array <ChatterItem>> m_chatter {};
Array <BotName> m_botNames {};
Array <ChatKeywords> m_replies {};
SmallArray <WeaponInfo> m_weapons {};
SmallArray <WeaponProp> m_weaponProps {};
IntArray m_logosIndices {};
StringArray m_avatars {};
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
HashMap <uint32_t, String, Hash <int32_t>> m_language {};
HashMap <int32_t, BotDifficultyData> m_difficulty {};
HashMap <String, String> m_custom {};
2020-06-12 18:52:38 +03:00
// default tables for personality weapon preferences, overridden by weapon.cfg
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
SmallArray <int32_t> m_normalWeaponPrefs = { 0, 2, 1, 4, 5, 6, 3, 12, 10, 24, 25, 13, 11, 8, 7, 22, 23, 18, 21, 17, 19, 15, 17, 9, 14, 16 };
SmallArray <int32_t> m_rusherWeaponPrefs = { 0, 2, 1, 4, 5, 6, 3, 24, 19, 22, 23, 20, 21, 10, 12, 13, 7, 8, 11, 9, 18, 17, 19, 25, 15, 16 };
SmallArray <int32_t> m_carefulWeaponPrefs = { 0, 2, 1, 4, 25, 6, 3, 7, 8, 12, 10, 13, 11, 9, 24, 18, 14, 17, 16, 15, 19, 20, 21, 22, 23, 5 };
SmallArray <int32_t> m_botBuyEconomyTable = { 1900, 2100, 2100, 4000, 6000, 7000, 16000, 1200, 800, 1000, 3000 };
SmallArray <int32_t> m_grenadeBuyPrecent = { 95, 85, 60 };
public:
BotConfig ();
~BotConfig () = default;
public:
// load the configuration files
void loadConfigs ();
// loads main config file
void loadMainConfig (bool isFirstLoad = false);
// loads bot names
void loadNamesConfig ();
// loads weapons config
void loadWeaponsConfig ();
// loads chatter config
void loadChatterConfig ();
// loads chat config
void loadChatConfig ();
// loads language config
void loadLanguageConfig ();
// load bots logos config
void loadLogosConfig ();
// load bots avatars config
void loadAvatarsConfig ();
2020-06-12 18:52:38 +03:00
// load bots difficulty config
void loadDifficultyConfig ();
// loads bots map-specific config
void loadMapSpecificConfig ();
// loads custom config
void loadCustomConfig ();
// sets memfile to use engine functions
void setupMemoryFiles ();
// picks random bot name
BotName *pickBotName ();
// remove bot name from used list
void clearUsedName (Bot *bot);
// set the bot names as used
2023-03-13 15:39:15 +03:00
void setBotNameUsed (const int index, StringRef name);
// initialize weapon info
void initWeapons ();
// fix weapon prices (ie for elite)
void adjustWeaponPrices ();
// find weapon info by weapon id
WeaponInfo &findWeaponById (int id);
// translates bot message into needed language
2020-06-12 18:52:38 +03:00
const char *translate (StringRef input);
// display current custom values
void showCustomValues ();
// opens config helper
bool openConfig (StringRef fileName, StringRef errorIfNotExists, MemFile *outFile, bool languageDependant = false);
private:
2020-06-12 18:52:38 +03:00
bool isCommentLine (StringRef line) const {
if (line.empty ()) {
return true;
}
return line.substr (0, 1).findFirstOf ("#/;") != String::InvalidIndex;
};
// hash the language string, only the letters
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
uint32_t hashLangString (StringRef str);
public:
// checks whether chat banks contains messages
bool hasChatBank (int chatType) const {
return !m_chat[chatType].empty ();
}
// checks whether chatter banks contains messages
bool hasChatterBank (int chatterType) const {
return !m_chatter[chatterType].empty ();
}
// pick random phrase from chat bank
2020-06-12 18:52:38 +03:00
StringRef pickRandomFromChatBank (int chatType) {
return m_chat[chatType].random ();
}
// pick random phrase from chatter bank
const ChatterItem &pickRandomFromChatterBank (int chatterType) {
return m_chatter[chatterType].random ();
}
// gets chatter repeat-interval
float getChatterMessageRepeatInterval (int chatterType) const {
return m_chatter[chatterType][0].repeat;
}
// get's the replies array
Array <ChatKeywords> &getReplies () {
return m_replies;
}
// get's the weapon info data
SmallArray <WeaponInfo> &getWeapons () {
return m_weapons;
}
// get's raw weapon info
WeaponInfo *getRawWeapons () {
return m_weapons.begin ();
}
// get's the weapons prop
2019-08-12 22:51:26 +03:00
WeaponProp &getWeaponProp (int id) {
return m_weaponProps[id];
}
// get's weapons type by id
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
int32_t getWeaponType (int id) const {
for (const auto &weapon : m_weapons) {
if (weapon.id == id) {
return weapon.type;
}
}
return WeaponType::None;
}
// get's weapon preferences for personality
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
int32_t *getWeaponPrefs (int personality) const {
switch (personality) {
case Personality::Normal:
default:
return m_normalWeaponPrefs.data ();
case Personality::Rusher:
return m_rusherWeaponPrefs.data ();
case Personality::Careful:
return m_carefulWeaponPrefs.data ();
}
}
2020-06-12 18:52:38 +03:00
// get's the difficulty level tweaks
BotDifficultyData *getDifficultyTweaks (int32_t level) {
2020-06-12 18:52:38 +03:00
return &m_difficulty[level];
}
// get economics value
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
int32_t *getEconLimit () {
return m_botBuyEconomyTable.data ();
}
// get's grenade buy percents
bool chanceToBuyGrenade (int grenadeType) const {
return rg.chance (m_grenadeBuyPrecent[grenadeType]);
}
// get's random avatar for player (if any)
2020-06-12 18:52:38 +03:00
StringRef getRandomAvatar () const {
if (!m_avatars.empty ()) {
return m_avatars.random ();
}
return "";
}
// get's random logo index
int32_t getRandomLogoDecalIndex () const {
return static_cast <int32_t> (m_logosIndices.random ());
}
// get custom value
StringRef fetchCustom (StringRef name) {
2023-04-15 04:10:09 +03:00
if (m_custom.exists (name)) {
return m_custom[name];
}
logger.error ("Trying to fetch unknown custom variable: %s", name);
return "";
}
// simple accessors to c4 model name
StringRef getBombModelName () {
return fetchCustom ("C4ModelName");
}
};
2022-04-26 21:57:36 +06:00
// expose global
CR_EXPOSE_GLOBAL_SINGLETON (BotConfig, conf);