Skip to content

Commit

Permalink
Add fallback place names if BotChatter.db is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq committed Apr 7, 2024
1 parent 1ae0091 commit 8c14d05
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 4 deletions.
5 changes: 5 additions & 0 deletions regamedll/dlls/bot/cs_bot_chatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions regamedll/dlls/bot/cs_bot_chatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 12 additions & 1 deletion regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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])))
Expand Down
133 changes: 133 additions & 0 deletions regamedll/game_shared/bot/nav_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions regamedll/game_shared/bot/nav_area.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 15 additions & 3 deletions regamedll/game_shared/bot/nav_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8c14d05

Please sign in to comment.