From 9d8318e5846fc35b9c99921b8de2005f8d3e717d Mon Sep 17 00:00:00 2001 From: jeefo Date: Wed, 1 Feb 2023 21:19:17 +0300 Subject: [PATCH] fix: probably fix for duplicate bot names when save names active (ref #403) --- inc/config.h | 3 +++ src/config.cpp | 9 +++++++++ src/manager.cpp | 3 +++ 3 files changed, 15 insertions(+) diff --git a/inc/config.h b/inc/config.h index beef26f..2014eb8 100644 --- a/inc/config.h +++ b/inc/config.h @@ -111,6 +111,9 @@ public: // remove bot name from used list void clearUsedName (Bot *bot); + // set the bot names as used + void setBotNameUsed(const int index, StringRef name); + // initialize weapon info void initWeapons (); diff --git a/src/config.cpp b/src/config.cpp index 7b75d27..3d10bfa 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -711,6 +711,15 @@ void BotConfig::clearUsedName (Bot *bot) { } } +void BotConfig::setBotNameUsed(const int index, StringRef name) { + for (auto &bn : m_botNames) { + if (bn.name == name) { + bn.usedBy = index; + break; + } + } +} + void BotConfig::initWeapons () { m_weapons.clear (); diff --git a/src/manager.cpp b/src/manager.cpp index a9fed2d..50cfc74 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -236,6 +236,9 @@ BotCreateResult BotManager::create (StringRef name, int difficulty, int personal if (botName != nullptr) { botName->usedBy = index; // save by who name is used } + else { + conf.setBotNameUsed(index, resultName); + } m_bots.push (cr::move (object)); ctrl.msg ("Connecting Bot...");