bot: refactor and clean up old code

fix: crash when saving old format pwf on hlds
bot: moved sdk headers to separate submodule
nav: improved unstuck and avoidance (thanks @commandcobra7) code
bot: use correct path slashes depending on platform for all data
cfg: removed simplified chines' translation, as it's too outdated
This commit is contained in:
jeefo 2023-05-12 20:00:06 +03:00
commit 7b58d51973
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED
42 changed files with 365 additions and 3805 deletions

View file

@ -48,8 +48,8 @@ void BotConfig::loadMainConfig (bool isFirstLoad) {
String line;
MemFile file;
// this is does the same as exec of engine, but not overwriting values of cvars spcified in cv_ignore_cvars_on_changelevel
if (util.openConfig (strings.format ("%s.cfg", product.folder), "Bot main config file is not found.", &file, false)) {
// this is does the same as exec of engine, but not overwriting values of cvars specified in cv_ignore_cvars_on_changelevel
if (util.openConfig (product.nameLower, "Bot main config file is not found.", &file, false)) {
while (file.getLine (line)) {
line.trim ();
@ -117,7 +117,7 @@ void BotConfig::loadNamesConfig () {
MemFile file;
// naming initialization
if (util.openConfig ("names.cfg", "Name configuration file not found.", &file, true)) {
if (util.openConfig ("names", "Name configuration file not found.", &file, true)) {
m_botNames.clear ();
while (file.getLine (line)) {
@ -172,7 +172,7 @@ void BotConfig::loadWeaponsConfig () {
MemFile file;
// weapon data initialization
if (util.openConfig ("weapon.cfg", "Weapon configuration file not found. Loading defaults.", &file)) {
if (util.openConfig ("weapon", "Weapon configuration file not found. Loading defaults.", &file)) {
while (file.getLine (line)) {
line.trim ();
@ -224,7 +224,7 @@ void BotConfig::loadChatterConfig () {
MemFile file;
// chatter initialization
if (game.is (GameFlags::HasBotVoice) && cv_radio_mode.int_ () == 2 && util.openConfig ("chatter.cfg", "Couldn't open chatter system configuration", &file)) {
if (game.is (GameFlags::HasBotVoice) && cv_radio_mode.int_ () == 2 && util.openConfig ("chatter", "Couldn't open chatter system configuration", &file)) {
m_chatter.clear ();
struct EventMap {
@ -332,7 +332,7 @@ void BotConfig::loadChatterConfig () {
items[1].trim ("(;)");
for (const auto &event : chatterEventMap) {
if (event.str == items[0]) {
if (event.str == items.first ()) {
// this does common work of parsing comma-separated chatter line
auto sentences = items[1].split (",");
@ -364,7 +364,7 @@ void BotConfig::loadChatConfig () {
MemFile file;
// chat config initialization
if (util.openConfig ("chat.cfg", "Chat file not found.", &file, true)) {
if (util.openConfig ("chat", "Chat file not found.", &file, true)) {
StringArray *chat = nullptr;
StringArray keywords {};
@ -467,7 +467,7 @@ void BotConfig::loadLanguageConfig () {
MemFile file;
// localizer inititalization
if (util.openConfig ("lang.cfg", "Specified language not found.", &file, true)) {
if (util.openConfig ("lang", "Specified language not found.", &file, true)) {
String temp;
Twin <String, String> lang;
@ -513,7 +513,7 @@ void BotConfig::loadAvatarsConfig () {
MemFile file;
// avatars inititalization
if (util.openConfig ("avatars.cfg", "Avatars config file not found. Avatars will not be displayed.", &file)) {
if (util.openConfig ("avatars", "Avatars config file not found. Avatars will not be displayed.", &file)) {
m_avatars.clear ();
while (file.getLine (line)) {
@ -577,7 +577,7 @@ void BotConfig::loadDifficultyConfig () {
};
// avatars inititalization
if (util.openConfig ("difficulty.cfg", "Difficulty config file not found. Loading defaults.", &file)) {
if (util.openConfig ("difficulty", "Difficulty config file not found. Loading defaults.", &file)) {
while (file.getLine (line)) {
if (isCommentLine (line) || line.length () < 3) {
@ -612,10 +612,10 @@ void BotConfig::loadDifficultyConfig () {
}
void BotConfig::loadMapSpecificConfig () {
auto mapSpecificConfig = strings.format ("addons/%s/conf/maps/%s.cfg", product.folder, game.getMapName ());
auto mapSpecificConfig = strings.joinPath (folders.addons, folders.bot, folders.config, "maps", strings.format ("%s.%s", game.getMapName (), kConfigExtension));
// check existence of file
if (File::exists (strings.format ("%s/%s", game.getRunningModName (), mapSpecificConfig))) {
if (plat.fileExists (strings.joinPath (game.getRunningModName (), mapSpecificConfig).chars ())) {
game.serverCommand ("exec %s", mapSpecificConfig);
ctrl.msg ("Executed map-specific config: %s", mapSpecificConfig);
@ -630,7 +630,7 @@ void BotConfig::loadCustomConfig () {
m_custom["AMXParachuteCvar"] = "sv_parachute";
// custom inititalization
if (util.openConfig ("custom.cfg", "Custom config file not found. Loading defaults.", &file)) {
if (util.openConfig ("custom", "Custom config file not found. Loading defaults.", &file)) {
m_custom.clear ();
while (file.getLine (line)) {
@ -642,7 +642,7 @@ void BotConfig::loadCustomConfig () {
auto values = line.split ("=");
if (values.length () != 2) {
logger.error ("Bad configuration for custom.cfg");
logger.error ("Bad configuration for custom.%s", kConfigExtension);
return;
}
auto kv = Twin <String, String> (values[0].trim (), values[1].trim ());
@ -661,7 +661,7 @@ void BotConfig::loadLogosConfig () {
MemFile file;
// logos inititalization
if (util.openConfig ("logos.cfg", "Logos config file not found. Loading defaults.", &file)) {
if (util.openConfig ("logos", "Logos config file not found. Loading defaults.", &file)) {
m_logos.clear ();
while (file.getLine (line)) {
@ -688,7 +688,7 @@ void BotConfig::setupMemoryFiles () {
};
if (setMemoryPointers) {
MemFileStorage::instance ().initizalize (wrapLoadFile, wrapFreeFile);
MemFileStorage::instance ().initizalize (cr::move (wrapLoadFile), cr::move (wrapFreeFile));
setMemoryPointers = false;
}
}