From 8c14d0516838bdc4011fd5989cb600d3140055c8 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Sun, 7 Apr 2024 18:49:08 +0700 Subject: [PATCH] Add fallback place names if BotChatter.db is missing --- regamedll/dlls/bot/cs_bot_chatter.cpp | 5 + regamedll/dlls/bot/cs_bot_chatter.h | 2 + regamedll/dlls/player.cpp | 13 ++- regamedll/game_shared/bot/nav_area.cpp | 133 +++++++++++++++++++++++++ regamedll/game_shared/bot/nav_area.h | 2 + regamedll/game_shared/bot/nav_file.cpp | 18 +++- 6 files changed, 169 insertions(+), 4 deletions(-) diff --git a/regamedll/dlls/bot/cs_bot_chatter.cpp b/regamedll/dlls/bot/cs_bot_chatter.cpp index 31bd03bbd..2c6b3336e 100644 --- a/regamedll/dlls/bot/cs_bot_chatter.cpp +++ b/regamedll/dlls/bot/cs_bot_chatter.cpp @@ -540,8 +540,13 @@ bool BotPhraseManager::Initialize(const char *filename, int bankIndex) else if (!Q_stricmp("UNDEFINED", token)) placeCriteria = UNDEFINED_PLACE; else + { placeCriteria = TheBotPhrases->NameToID(token); + if (!TheBotPhrases->IsValid() && placeCriteria == UNDEFINED_PLACE) + placeCriteria = TheNavAreaGrid.NameToID(token); + } + continue; } diff --git a/regamedll/dlls/bot/cs_bot_chatter.h b/regamedll/dlls/bot/cs_bot_chatter.h index f8d7f45b2..4a4591cf6 100644 --- a/regamedll/dlls/bot/cs_bot_chatter.h +++ b/regamedll/dlls/bot/cs_bot_chatter.h @@ -255,6 +255,8 @@ class BotPhraseManager Place NameToID(const char *name) const; const char *IDToName(Place id) const; + bool IsValid() const { return !m_placeList.empty(); } + // given a name, return the associated phrase collection const BotPhrase *GetPhrase(const char *name) const; diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index b5134ea82..b5e21eb03 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -415,7 +415,11 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Radio)(const char *msg_id, const char *msg { // search the place name where is located the player const char *placeName = nullptr; - if (AreRunningCZero() && TheBotPhrases) + if (( +#ifdef REGAMEDLL_ADD + location_area_info.value || +#endif + AreRunningCZero()) && TheBotPhrases) { Place playerPlace = TheNavAreaGrid.GetPlace(&pev->origin); const BotPhraseList *placeList = TheBotPhrases->GetPlaceList(); @@ -427,7 +431,11 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Radio)(const char *msg_id, const char *msg break; } } + + if (!placeName[0]) + placeName = TheNavAreaGrid.IDToName(playerPlace); } + if (placeName) ClientPrint(pEntity->pev, HUD_PRINTRADIO, NumAsString(entindex()), "#Game_radio_location", STRING(pev->netname), placeName, msg_verbose); else @@ -10100,6 +10108,9 @@ void CBasePlayer::UpdateLocation(bool forceUpdate) break; } } + + if (!placeName[0]) + placeName = TheNavAreaGrid.IDToName(playerPlace); } if (!placeName[0] || (m_lastLocation[0] && !Q_strcmp(placeName, &m_lastLocation[1]))) diff --git a/regamedll/game_shared/bot/nav_area.cpp b/regamedll/game_shared/bot/nav_area.cpp index 1ff3ef8c5..1cac88ce9 100644 --- a/regamedll/game_shared/bot/nav_area.cpp +++ b/regamedll/game_shared/bot/nav_area.cpp @@ -3815,6 +3815,9 @@ void EditNavAreas(NavEditCmdType cmd) if (area->GetPlace()) { const char *name = TheBotPhrases->IDToName(area->GetPlace()); + if (!TheBotPhrases->IsValid() && !name) + name = TheNavAreaGrid.IDToName(area->GetPlace()); + if (name) Q_strcpy(locName, name); else @@ -4810,3 +4813,133 @@ Place CNavAreaGrid::GetPlace(const Vector *pos) const return UNDEFINED_PLACE; } + +static const char *g_pszDefaultPlaceNames[] = +{ + "BombsiteA", + "BombsiteB", + "BombsiteC", + "Hostages", + "HostageRescueZone", + "VipRescueZone", + "CTSpawn", + "TSpawn", + "Bridge", + "Middle", + "House", + "Apartment", + "Apartments", + "Market", + "Sewers", + "Tunnel", + "Ducts", + "Village", + "Roof", + "Upstairs", + "Downstairs", + "Basement", + "Crawlspace", + "Kitchen", + "Inside", + "Outside", + "Tower", + "WineCellar", + "Garage", + "Courtyard", + "Water", + "FrontDoor", + "BackDoor", + "SideDoor", + "BackWay", + "FrontYard", + "BackYard", + "SideYard", + "Lobby", + "Vault", + "Elevator", + "DoubleDoors", + "SecurityDoors", + "LongHall", + "SideHall", + "FrontHall", + "BackHall", + "MainHall", + "FarSide", + "Windows", + "Window", + "Attic", + "StorageRoom", + "ProjectorRoom", + "MeetingRoom", + "ConferenceRoom", + "ComputerRoom", + "BigOffice", + "LittleOffice", + "Dumpster", + "Airplane", + "Underground", + "Bunker", + "Mines", + "Front", + "Back", + "Rear", + "Side", + "Ramp", + "Underpass", + "Overpass", + "Stairs", + "Ladder", + "Gate", + "GateHouse", + "LoadingDock", + "GuardHouse", + "Entrance", + "VendingMachines", + "Loft", + "Balcony", + "Alley", + "BackAlley", + "SideAlley", + "FrontRoom", + "BackRoom", + "SideRoom", + "Crates", + "Truck", + "Bedroom", + "FamilyRoom", + "Bathroom", + "LivingRoom", + "Den", + "Office", + "Atrium", + "Entryway", + "Foyer", + "Stairwell", + "Fence", + "Deck", + "Porch", + "Patio", + "Wall" +}; + +// Return fallback place name for given place id +const char *CNavAreaGrid::IDToName(Place place) const +{ + if (place <= 0 || place > ARRAYSIZE(g_pszDefaultPlaceNames)) + return nullptr; + + return g_pszDefaultPlaceNames[place - 1]; +} + +// Return place id for given place name +Place CNavAreaGrid::NameToID(const char *name) const +{ + for (unsigned int place = 0; place < ARRAYSIZE(g_pszDefaultPlaceNames); place++) + { + const char *placeName = g_pszDefaultPlaceNames[place]; + if (!Q_stricmp(placeName, name)) + return place + 1; + } + + return UNDEFINED_PLACE; +} diff --git a/regamedll/game_shared/bot/nav_area.h b/regamedll/game_shared/bot/nav_area.h index d1ed024ec..c4cf8a1ff 100644 --- a/regamedll/game_shared/bot/nav_area.h +++ b/regamedll/game_shared/bot/nav_area.h @@ -505,6 +505,8 @@ class CNavAreaGrid bool IsValid() const; Place GetPlace(const Vector *pos) const; // return radio chatter place for given coordinate + Place NameToID(const char *name) const; + const char *IDToName(Place id) const; private: const float m_cellSize; diff --git a/regamedll/game_shared/bot/nav_file.cpp b/regamedll/game_shared/bot/nav_file.cpp index ad04f52c9..c9f206fd9 100644 --- a/regamedll/game_shared/bot/nav_file.cpp +++ b/regamedll/game_shared/bot/nav_file.cpp @@ -85,7 +85,10 @@ void PlaceDirectory::Save(int fd) // store entries for (auto &id : m_directory) { - auto placeName = TheBotPhrases->IDToName(id); + const char *placeName = TheBotPhrases->IDToName(id); + + if (!TheBotPhrases->IsValid() && !placeName) + placeName = TheNavAreaGrid.IDToName(id); // store string length followed by string itself unsigned short len = (unsigned short)Q_strlen(placeName) + 1; @@ -110,7 +113,11 @@ void PlaceDirectory::Load(SteamFile *file) file->Read(&len, sizeof(unsigned short)); file->Read(placeName, len); - AddPlace(TheBotPhrases->NameToID(placeName)); + Place place = TheBotPhrases->NameToID(placeName); + if (!TheBotPhrases->IsValid() && place == UNDEFINED_PLACE) + place = TheNavAreaGrid.NameToID(placeName); + + AddPlace(place); } } @@ -652,7 +659,12 @@ void LoadLocationFile(const char *filename) for (int i = 0; i < dirSize; i++) { locData = SharedParse(locData); - directory.push_back(TheBotPhrases->NameToID(SharedGetToken())); + + Place place = TheBotPhrases->NameToID(SharedGetToken()); + if (!TheBotPhrases->IsValid() && place == UNDEFINED_PLACE) + place = TheNavAreaGrid.NameToID(SharedGetToken()); + + directory.push_back(place); } // read places for each nav area