From d2dd37d39972db2038dc8adb7c0573dbb92898a9 Mon Sep 17 00:00:00 2001 From: mostlikely4r Date: Sat, 11 Jan 2025 08:45:36 +0100 Subject: [PATCH 1/2] AI chat: Fix gossiptext replacement in rpg chat. --- playerbot/PlayerbotLLMInterface.cpp | 2 +- playerbot/PlayerbotTextMgr.cpp | 10 +++++----- playerbot/PlayerbotTextMgr.h | 6 +++--- playerbot/strategy/actions/RtscAction.cpp | 4 ++-- playerbot/strategy/actions/SayAction.cpp | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/playerbot/PlayerbotLLMInterface.cpp b/playerbot/PlayerbotLLMInterface.cpp index d214522e..fef30bfa 100644 --- a/playerbot/PlayerbotLLMInterface.cpp +++ b/playerbot/PlayerbotLLMInterface.cpp @@ -393,7 +393,7 @@ std::vector PlayerbotLLMInterface::ParseResponse(const std::string& actualResponse = extractAfterPattern(actualResponse, startPattern); - PlayerbotTextMgr::replaceAll(actualResponse, R"(\")", "'"); + PlayerbotTextMgr::ReplaceAll(actualResponse, R"(\")", "'"); if (debug) { diff --git a/playerbot/PlayerbotTextMgr.cpp b/playerbot/PlayerbotTextMgr.cpp index c23778c5..1283e4d6 100644 --- a/playerbot/PlayerbotTextMgr.cpp +++ b/playerbot/PlayerbotTextMgr.cpp @@ -18,7 +18,7 @@ PlayerbotTextMgr::~PlayerbotTextMgr() { } -void PlayerbotTextMgr::replaceAll(std::string & str, const std::string & from, const std::string & to) { +void PlayerbotTextMgr::ReplaceAll(std::string & str, const std::string & from, const std::string & to) { if (from.empty()) return; size_t start_pos = 0; @@ -28,10 +28,10 @@ void PlayerbotTextMgr::replaceAll(std::string & str, const std::string & from, c } } -void PlayerbotTextMgr::replacePlaceholders(std::string& text, const std::map& placeholders) +void PlayerbotTextMgr::ReplacePlaceholders(std::string& text, const std::map& placeholders) { for (auto& placeholder : placeholders) - replaceAll(text, placeholder.first, placeholder.second); + ReplaceAll(text, placeholder.first, placeholder.second); } void PlayerbotTextMgr::LoadBotTexts() @@ -115,7 +115,7 @@ std::string PlayerbotTextMgr::GetBotText(std::string name, std::map& placeholders); - static std::string GetReplacePlaceholders(const std::string& text, const std::map& placeholders) { std::string retText = text; replacePlaceholders (retText, placeholders); return retText; } + static void ReplaceAll(std::string& str, const std::string& from, const std::string& to); + static void ReplacePlaceholders(std::string& text, const std::map& placeholders); + static std::string GetReplacePlaceholders(const std::string& text, const std::map& placeholders) { std::string retText = text; ReplacePlaceholders (retText, placeholders); return retText; } std::string GetBotText(std::string name, std::map placeholders); std::string GetBotText(std::string name); diff --git a/playerbot/strategy/actions/RtscAction.cpp b/playerbot/strategy/actions/RtscAction.cpp index 9ed4263d..fc800f50 100644 --- a/playerbot/strategy/actions/RtscAction.cpp +++ b/playerbot/strategy/actions/RtscAction.cpp @@ -149,7 +149,7 @@ bool RTSCAction::Execute(Event& event) if (filePerBot) { - PlayerbotTextMgr::replaceAll(fileName, "BOTNAME", playerName); + PlayerbotTextMgr::ReplaceAll(fileName, "BOTNAME", playerName); sPlayerbotAIConfig.openLog(fileName, "w", true); } @@ -217,7 +217,7 @@ bool RTSCAction::Execute(Event& event) if (filePerBot) { - PlayerbotTextMgr::replaceAll(fileName, "BOTNAME", playerName); + PlayerbotTextMgr::ReplaceAll(fileName, "BOTNAME", playerName); } std::string m_logsDir = sConfig.GetStringDefault("LogsDir"); diff --git a/playerbot/strategy/actions/SayAction.cpp b/playerbot/strategy/actions/SayAction.cpp index b167afdf..93779106 100644 --- a/playerbot/strategy/actions/SayAction.cpp +++ b/playerbot/strategy/actions/SayAction.cpp @@ -270,7 +270,7 @@ void ChatReplyAction::GetAIChatPlaceholders(std::map& replace["GOSSIP_OPTION_TRAINER"] = unit->GetName() + std::string(" can train pets."); replace["GOSSIP_OPTION_UNLEARNPETSKILLS"] = unit->GetName() + std::string(" can help pets unlearn their skills."); - PlayerbotTextMgr::GetReplacePlaceholders(gossipText, replace); + PlayerbotTextMgr::ReplacePlaceholders(gossipText, replace); placeholders["<" + preFix + " gossip>"] = gossipText; } From 1d254a68d03263f38e663e0141991d09f39d9310 Mon Sep 17 00:00:00 2001 From: mostlikely4r Date: Sat, 11 Jan 2025 19:55:57 +0100 Subject: [PATCH 2/2] Nodegen: Fixed some crashes during generation --- playerbot/TravelNode.cpp | 39 ++++++++++++++++--------------------- playerbot/WorldPosition.cpp | 16 +++++++-------- 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/playerbot/TravelNode.cpp b/playerbot/TravelNode.cpp index e1e9c22e..ac8912ff 100644 --- a/playerbot/TravelNode.cpp +++ b/playerbot/TravelNode.cpp @@ -81,7 +81,7 @@ void TravelNodePath::calculateCost(bool distanceOnly) if (lastPoint && point.getMapId() == lastPoint.getMapId()) { - if (!distanceOnly && (point.isInWater() || lastPoint.isInWater())) + if (!distanceOnly && (point.isVmapLoaded() && point.isInWater()) || (lastPoint.isVmapLoaded() && lastPoint.isInWater())) swimDistance += point.distance(lastPoint); distance += point.distance(lastPoint); @@ -1843,8 +1843,23 @@ void TravelNodeMap::manageNodes(Unit* bot, bool mapFull) void TravelNodeMap::LoadMaps() { -#ifdef MANGOSBOT_ZERO sLog.outError("Trying to load all maps and tiles for node generation. Please ignore any maps that could not be loaded."); + for (uint32 i = 0; i < sMapStore.GetNumRows(); ++i) + { + if (!sMapStore.LookupEntry(i)) + continue; + + uint32 mapId = sMapStore.LookupEntry(i)->MapID; + if (mapId == 0 || mapId == 1 || mapId == 530 || mapId == 571) + { + MMAP::MMapFactory::createOrGetMMapManager()->loadAllMapTiles(sWorld.GetDataPath(), mapId); + } + else + { + MMAP::MMapFactory::createOrGetMMapManager()->loadMapInstance(sWorld.GetDataPath(), mapId, 0); + } + } + for (uint32 i = 0; i < sMapStore.GetNumRows(); ++i) { if (!sMapStore.LookupEntry(i)) @@ -1871,26 +1886,6 @@ void TravelNodeMap::LoadMaps() } } } -#endif -#ifdef MANGOSBOT_ONE - sLog.outError("Trying to load all maps and tiles for node generation. Please ignore any maps that could not be loaded."); - for (uint32 i = 0; i < sMapStore.GetNumRows(); ++i) - { - if (!sMapStore.LookupEntry(i)) - continue; - - uint32 mapId = sMapStore.LookupEntry(i)->MapID; - if (mapId == 0 || mapId == 1 || mapId == 530 || mapId == 571) - { - MMAP::MMapFactory::createOrGetMMapManager()->loadAllMapTiles(sWorld.GetDataPath(), mapId); - } - else - { - MMAP::MMapFactory::createOrGetMMapManager()->loadMapInstance(sWorld.GetDataPath(), mapId, 0); - } - } -#endif - } void TravelNodeMap::generateNpcNodes() diff --git a/playerbot/WorldPosition.cpp b/playerbot/WorldPosition.cpp index ad59cc1a..43da6e5f 100644 --- a/playerbot/WorldPosition.cpp +++ b/playerbot/WorldPosition.cpp @@ -686,10 +686,10 @@ bool WorldPosition::loadMapAndVMap(uint32 mapId, uint32 instanceId, int x, int y { std::string logName = "load_map_grid.csv"; - bool hasVmap = isVmapLoaded(mapId, x, y); + //bool hasVmap = isVmapLoaded(mapId, x, y); bool hasMmap = isMmapLoaded(mapId, instanceId, x, y); - if (hasVmap && hasMmap) + if (hasMmap) return true; if (sTravelMgr.IsBadMmap(mapId, x, y)) @@ -718,14 +718,14 @@ bool WorldPosition::loadMapAndVMap(uint32 mapId, uint32 instanceId, int x, int y #endif - if (!isLoaded) - sTravelMgr.AddBadMmap(mapId, x, y); + //if (!isLoaded) + // sTravelMgr.AddBadMmap(mapId, x, y); } - if (!hasVmap) - { - loadVMap(mapId, x, y); - } + //if (!hasVmap) + //{ + // loadVMap(mapId, x, y); + //} if (sPlayerbotAIConfig.hasLog(logName)) {