diff --git a/.gitignore b/.gitignore index 2ac93e819a..e6a5c642cd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ # Qt Creator /build-src-* +# Rider +**/.idea + # CMake build dir /src/build out diff --git a/game/neo/resource/NeoModEvents.res b/game/neo/resource/NeoModEvents.res index 9d62eb6227..7bf23c6185 100644 --- a/game/neo/resource/NeoModEvents.res +++ b/game/neo/resource/NeoModEvents.res @@ -89,6 +89,9 @@ "pingy" "short" // ping y position "pingz" "short" // ping z position "ghosterping" "bool" // the player is carrying the ghost + "server" "bool" // whether this was fired server side (else it's predicted) + "place_exact" "bool" // whether the place ping is pinpoint precise on the place name (else we consider the ping to be "near" it) + "place_name" "string" // nav place name of the pinged location (may be empty "" string) } "ghost_enemy_callout" diff --git a/src/game/client/neo/ui/neo_hud_player_ping.cpp b/src/game/client/neo/ui/neo_hud_player_ping.cpp index 7ca9e7f6dc..557704f061 100644 --- a/src/game/client/neo/ui/neo_hud_player_ping.cpp +++ b/src/game/client/neo/ui/neo_hud_player_ping.cpp @@ -32,6 +32,16 @@ ConVar cl_neo_player_pings("cl_neo_player_pings", "1", FCVAR_ARCHIVE | FCVAR_USE } }); +enum NeoPlayerPingsInSpectate +{ + NEO_SPECTATE_PINGS_DISABLED = 0, + NEO_SPECTATE_PINGS_TARGET, + NEO_SPECTATE_PINGS_ALL, + + NEO_SPECTATE_PINGS_LAST_VALUE = NEO_SPECTATE_PINGS_ALL +}; +ConVar cl_neo_player_pings_in_spectate("cl_neo_player_pings_in_spectate", "1", FCVAR_ARCHIVE, "See pings of players playing the game. 0 = disabled, 1 = spectate target team, 2 = all", true, NEO_SPECTATE_PINGS_DISABLED, true, NEO_SPECTATE_PINGS_LAST_VALUE); + CNEOHud_PlayerPing::CNEOHud_PlayerPing(const char* pElementName, vgui::Panel* parent) : CHudElement(pElementName), Panel(parent, pElementName) { @@ -109,45 +119,105 @@ void CNEOHud_PlayerPing::Init(void) //----------------------------------------------------------------------------- void CNEOHud_PlayerPing::FireGameEvent(IGameEvent* event) { - auto eventName = event->GetName(); + const auto eventName = event->GetName(); if (!Q_stricmp(eventName, "player_ping")) { - if (!cl_neo_player_pings.GetBool()) + OnPlayerPing(event); + } + else if (!Q_stricmp(eventName, "round_start")) + { + HideAllPings(); + } + else if (!Q_stricmp(eventName, "player_team")) + { + auto player = UTIL_PlayerByUserId(event->GetInt("userid")); + if (player && player->IsLocalPlayer()) { - return; + HideAllPings(); } + } +} - const int userID = event->GetInt("userid"); - const int playerIndex = engine->GetPlayerForUserID(userID); - if (GetClientVoiceMgr()->IsPlayerBlocked(playerIndex) || (!NEORules()->IsTeamplay() && playerIndex != GetLocalPlayerIndex())) +void CNEOHud_PlayerPing::OnPlayerPing(const IGameEvent* event) +{ + // This is already checked by the emitter side, but we check again because it could arrive late (dynamic custom rule change etc.) + if (!NEORules() || !NEORules()->ArePingsAllowed()) + { + return; + } + + if (!cl_neo_player_pings.GetBool()) + { + return; + } + + const auto localPlayer = C_NEO_Player::GetLocalNEOPlayer(); + Assert(localPlayer); + const auto localTeamNumber = localPlayer->GetTeamNumber(); + + const int pingerIndex = engine->GetPlayerForUserID(event->GetInt("userid")); + Assert(pingerIndex >= 0); + + const bool isOwnPing = (pingerIndex == localPlayer->entindex()); + if (!isOwnPing) + { + if (pingerIndex == 0 || GetClientVoiceMgr()->IsPlayerBlocked(pingerIndex)) { return; } + } - const int localTeam = GetLocalPlayerTeam(); - const int playerTeam = event->GetInt("playerteam"); - if (localTeam != TEAM_SPECTATOR && playerTeam != localTeam) + const int pingRecipientTeam = event->GetInt("playerteam"); + + if (localTeamNumber == TEAM_SPECTATOR) + { + const C_BaseEntity* obsTarget; + switch (cl_neo_player_pings_in_spectate.GetInt()) { + case NEO_SPECTATE_PINGS_DISABLED: + return; + case NEO_SPECTATE_PINGS_TARGET: + obsTarget = localPlayer->GetObserverTarget(); + if (!obsTarget || obsTarget->GetTeamNumber() != pingRecipientTeam) + return; + break; + case NEO_SPECTATE_PINGS_ALL: + break; + default: + Warning("%s: unhandled enum case %d\n", __FUNCTION__, cl_neo_player_pings_in_spectate.GetInt()); return; } - - const Vector worldpos = Vector(event->GetInt("pingx"), event->GetInt("pingy"), event->GetInt("pingz")); - bool ghosterPing = event->GetBool("ghosterping"); - SetPos(playerIndex - 1, playerTeam, worldpos, ghosterPing); } - else if (!Q_stricmp(eventName, "round_start")) + else if (localTeamNumber != pingRecipientTeam) { - HideAllPings(); + return; } - else if (!Q_stricmp(eventName, "player_team")) + + const int pingerSlot = pingerIndex - 1; + Assert(pingerSlot >= 0); + + const Vector worldpos(event->GetInt("pingx"), event->GetInt("pingy"), event->GetInt("pingz")); + const bool ghosterPing = event->GetBool("ghosterping"); + SetPos(pingerSlot, pingRecipientTeam, worldpos, ghosterPing); + + const bool thisIsPredictedPing = !event->GetBool("server", false); + if (thisIsPredictedPing) { - auto player = UTIL_PlayerByUserId(event->GetInt("userid")); - if (player && player->IsLocalPlayer()) - { - HideAllPings(); - } + // don't print predicted (bogus) placenames; we only wanna predict the in-world visuals but not the place text + return; + } + + if (isOwnPing) + { + static ConVarRef cl_neo_player_pings_print_own("cl_neo_player_pings_print_own"); + Assert(cl_neo_player_pings_print_own.IsValid()); + if (!cl_neo_player_pings_print_own.GetBool()) + return; } + const bool placeIsExact = event->GetBool("place_exact"); + const char* placeName = event->GetString("place_name"); + NotifyPing(pingerSlot, placeName, placeIsExact); } void CNEOHud_PlayerPing::LevelShutdown(void) @@ -156,15 +226,6 @@ void CNEOHud_PlayerPing::LevelShutdown(void) m_flNextPingSoundTime = 0.f; } -enum NeoPlayerPingsInSpectate -{ - NEO_SPECTATE_PINGS_DISABLED = 0, - NEO_SPECTATE_PINGS_TARGET, - NEO_SPECTATE_PINGS_ALL, - - NEO_SPECTATE_PINGS_LAST_VALUE = NEO_SPECTATE_PINGS_ALL -}; -ConVar cl_neo_player_pings_in_spectate("cl_neo_player_pings_in_spectate", "1", FCVAR_ARCHIVE, "See pings of players playing the game. 0 = disabled, 1 = spectate target team, 2 = all", true, NEO_SPECTATE_PINGS_DISABLED, true, NEO_SPECTATE_PINGS_LAST_VALUE); void CNEOHud_PlayerPing::DrawNeoHudElement() { if (!ShouldDraw()) @@ -315,7 +376,8 @@ void CNEOHud_PlayerPing::UpdateDistanceToPlayer(C_BasePlayer* player, const int m_iPlayerPings[playerSlot].noLineOfSight = tr.fraction < 0.999; } -void CNEOHud_PlayerPing::SetPos(const int playerSlot, const int playerTeam, const Vector& pos, bool ghosterPing) { +void CNEOHud_PlayerPing::SetPos(const int playerSlot, const int playerTeam, const Vector& pos, bool ghosterPing) +{ constexpr float PLAYER_PING_LIFETIME = 8; auto localPlayer = C_NEO_Player::GetLocalNEOPlayer(); if (!localPlayer) { return; } @@ -326,51 +388,38 @@ void CNEOHud_PlayerPing::SetPos(const int playerSlot, const int playerTeam, cons m_iPlayerPings[playerSlot].ghosterPing = ghosterPing; UpdateDistanceToPlayer(localPlayer, playerSlot); - const int playerPingsInSpectate = cl_neo_player_pings_in_spectate.GetInt(); - if (GetLocalPlayerTeam() == TEAM_SPECTATOR && playerPingsInSpectate != NEO_SPECTATE_PINGS_ALL) - { - if (playerPingsInSpectate == NEO_SPECTATE_PINGS_DISABLED) - { - return; - } - - int spectateTargetTeam = TEAM_UNASSIGNED; - if (auto observerTarget = localPlayer->GetObserverTarget()) - { - spectateTargetTeam = observerTarget->GetTeamNumber(); - if (playerTeam != spectateTargetTeam) - { - return; - } - } - else - { - return; - } - } - NotifyPing(playerSlot); } ConVar snd_ping_volume("snd_ping_volume", "0.33", FCVAR_ARCHIVE, "Player ping volume", true, 0.f, true, 1.f); ConVar cl_neo_player_pings_chat_message("cl_neo_player_pings_chat_message", "1", FCVAR_ARCHIVE, "Show message in chat for player pings.", true, 0, true, 1); // NEO TODO (Adam) custom chat filter instead? ConVar cl_neo_player_pings_time_between_sounds("cl_neo_player_pings_time_between_sounds", "0", FCVAR_ARCHIVE, "Minimum time between two ping sounds", true, 0, false, 0); -void CNEOHud_PlayerPing::NotifyPing(const int playerSlot) +#ifdef _DEBUG +ConVar cl_neo_player_pings_skip_text_for_bots("cl_neo_player_pings_skip_text_for_bots", "1", FCVAR_DONTRECORD); +#endif +void CNEOHud_PlayerPing::NotifyPing(const int playerSlot, const char* placeName, bool placeIsExact) { C_NEO_Player* pPlayer = static_cast(UTIL_PlayerByIndex(playerSlot + 1)); - if (!pPlayer || pPlayer->IsLocalPlayer()) + if (!pPlayer) { return; } if (cl_neo_player_pings_chat_message.GetBool()) { - // Skip text notification for bots - if (g_PR && !g_PR->IsFakePlayer(playerSlot + 1)) + if ( + ( g_PR && !g_PR->IsFakePlayer(playerSlot + 1) ) +#ifdef _DEBUG + || !cl_neo_player_pings_skip_text_for_bots.GetBool() +#endif + ) { CBaseHudChat* hudChat = (CBaseHudChat*)GET_HUDELEMENT(CHudChat); if (hudChat) { - hudChat->ChatPrintf(0, CHAT_FILTER_NONE, "%s pinged a location\n", pPlayer->GetNeoPlayerName()); + hudChat->ChatPrintf(0, CHAT_FILTER_NONE, "%s pinged %s%s\n", + pPlayer->GetNeoPlayerName(), + (placeIsExact || !placeName || !*placeName) ? "" : "near ", // only specify "near" for concrete callouts + (placeName && *placeName) ? placeName : "a location"); } } } diff --git a/src/game/client/neo/ui/neo_hud_player_ping.h b/src/game/client/neo/ui/neo_hud_player_ping.h index a8a844e237..81e2fd74df 100644 --- a/src/game/client/neo/ui/neo_hud_player_ping.h +++ b/src/game/client/neo/ui/neo_hud_player_ping.h @@ -34,10 +34,11 @@ class CNEOHud_PlayerPing : public CNEOHud_ChildElement, public CHudElement, publ virtual void FireGameEvent(IGameEvent* event) override; private: + void OnPlayerPing(const IGameEvent* event); int GetStringPixelWidth(wchar_t* pString, vgui::HFont hFont); void UpdateDistanceToPlayer(C_BasePlayer* player, const int pingIndex); void SetPos(const int index, const int playerTeam, const Vector& pos, bool ghosterPing); - void NotifyPing(const int playerSlot); + void NotifyPing(const int playerSlot, const char* placeName, bool placeIsExact); private: playerPing m_iPlayerPings[MAX_PLAYERS] = {}; diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index dc7d226781..cfc7321e7d 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -853,7 +853,12 @@ CNavArea *CNavMesh::GetNavArea( CBaseEntity *pEntity, int nFlags, float flBeneat * Used to find initial area if we start off of the mesh. * @todo Make sure area is not on the other side of the wall from goal. */ +#ifdef NEO +CNavArea *CNavMesh::GetNearestNavArea( const Vector &pos, bool anyZ, float maxDist, bool checkLOS, bool checkGround, int team, + bool(*ignorePredicate)(const CNavArea*) ) const +#else CNavArea *CNavMesh::GetNearestNavArea( const Vector &pos, bool anyZ, float maxDist, bool checkLOS, bool checkGround, int team ) const +#endif { VPROF_BUDGET( "CNavMesh::GetNearestNavArea", "NextBot" ); @@ -869,6 +874,9 @@ CNavArea *CNavMesh::GetNearestNavArea( const Vector &pos, bool anyZ, float maxDi close = GetNavArea( pos ); if ( close ) { +#ifdef NEO + if (!ignorePredicate || !ignorePredicate(close)) +#endif return close; } } @@ -954,6 +962,11 @@ CNavArea *CNavMesh::GetNearestNavArea( const Vector &pos, bool anyZ, float maxDi // mark as visited area->m_nearNavSearchMarker = searchMarker; +#ifdef NEO + if (ignorePredicate && ignorePredicate(area)) + continue; +#endif + Vector areaPos; area->GetClosestPointOnArea( source, &areaPos ); @@ -1030,7 +1043,6 @@ CNavArea *CNavMesh::GetNearestNavArea( const Vector &pos, bool anyZ, float maxDi } } } - return close; } diff --git a/src/game/server/nav_mesh.h b/src/game/server/nav_mesh.h index 48ae68577d..b85012b657 100644 --- a/src/game/server/nav_mesh.h +++ b/src/game/server/nav_mesh.h @@ -334,7 +334,12 @@ class CNavMesh : public CGameEventListener CNavArea *GetNavArea( const Vector &pos, float beneathLimt = 120.0f ) const; // given a position, return the nav area that IsOverlapping and is *immediately* beneath it CNavArea *GetNavArea( CBaseEntity *pEntity, int nGetNavAreaFlags, float flBeneathLimit = 120.0f ) const; CNavArea *GetNavAreaByID( unsigned int id ) const; +#ifdef NEO + CNavArea *GetNearestNavArea( const Vector &pos, bool anyZ = false, float maxDist = 10000.0f, bool checkLOS = false, bool checkGround = true, int team = TEAM_ANY, + bool(*ignorePredicate)(const CNavArea*) = nullptr) const; +#else CNavArea *GetNearestNavArea( const Vector &pos, bool anyZ = false, float maxDist = 10000.0f, bool checkLOS = false, bool checkGround = true, int team = TEAM_ANY ) const; +#endif CNavArea *GetNearestNavArea( CBaseEntity *pEntity, int nGetNavAreaFlags = GETNAVAREA_CHECK_GROUND, float maxDist = 10000.0f ) const; Place GetPlace( const Vector &pos ) const; // return Place at given coordinate @@ -870,7 +875,11 @@ class CNavMesh : public CGameEventListener float yMax = yMin + area->GetSizeY(); // clip ray to area +#ifdef NEO + Vector exit = vec3_invalid; +#else Vector exit; +#endif NavDirType edge = NUM_DIRECTIONS; if ( to.x < 0.0f ) diff --git a/src/game/server/neo/bot/behavior/neo_bot_behavior.cpp b/src/game/server/neo/bot/behavior/neo_bot_behavior.cpp index c85df07851..268c0c176e 100644 --- a/src/game/server/neo/bot/behavior/neo_bot_behavior.cpp +++ b/src/game/server/neo/bot/behavior/neo_bot_behavior.cpp @@ -1063,7 +1063,7 @@ void CNEOBotMainAction::FireWeaponAtEnemy( CNEOBot *me ) if (bOnTarget) { - if (NEORules()->IsTeamplay()) + if (NEORules()->ArePingsAllowed()) { me->PressSpecialFireButton(); // place a player ping to alert friends } diff --git a/src/game/shared/neo/neo_gamerules.h b/src/game/shared/neo/neo_gamerules.h index 1bdee613ae..4e5dae0235 100644 --- a/src/game/shared/neo/neo_gamerules.h +++ b/src/game/shared/neo/neo_gamerules.h @@ -450,6 +450,17 @@ class CNEORules : public CHL2MPRules, public CGameEventListener bool IsClassFull(int team, int classId) const; int GetFallbackClass(int team, int preferredClass) const; + inline bool ArePingsAllowed() + { + constexpr auto modesWhereWeUseSaneLogic = NEO_GAME_TYPE_CTG; + if (GetGameType() != modesWhereWeUseSaneLogic) + { + return true; + } + // Only allow pings for game modes with friendlies, because it makes no sense to send pings to your enemies. + return IsTeamplay(); + } + public: #ifdef GAME_DLL // Workaround for bot spawning. See Bot_f() for details. diff --git a/src/game/shared/neo/neo_player_shared.cpp b/src/game/shared/neo/neo_player_shared.cpp index d5f523c88c..e231a1ddec 100644 --- a/src/game/shared/neo/neo_player_shared.cpp +++ b/src/game/shared/neo/neo_player_shared.cpp @@ -25,6 +25,7 @@ #ifdef GAME_DLL #include "basetypes.h" +#include "nav_mesh.h" #endif #include "convar.h" @@ -136,10 +137,25 @@ CBaseCombatWeapon* GetNeoWepWithBits(const CNEO_Player* player, const NEO_WEP_BI #ifdef CLIENT_DLL extern ConVar cl_neo_player_pings; +static ConVar cl_neo_player_pings_print_own("cl_neo_player_pings_print_own", "0", FCVAR_ARCHIVE, + "Whether to print the place names of your own pings to chat.", true, false, true, true); +#else +static ConVar sv_neo_player_pings_calc_placename("sv_neo_player_pings_calc_placename", "1", 0, + "Whether the server should calculate place names for player pings from the nav mesh (possibly expensive)", true, false, true, true); #endif // CLIENT_DLL void CheckPingButton(CNEO_Player* player) { - if (!player->IsAlive() || !(player->m_afButtonPressed & IN_ATTACK3) || player->m_flNextPingTime > gpGlobals->curtime) + if (!(player->m_afButtonPressed & IN_ATTACK3) || player->m_flNextPingTime > gpGlobals->curtime) + { + return; + } + + if (!NEORules() || !NEORules()->ArePingsAllowed()) + { + return; + } + + if (!player->IsAlive()) { return; } @@ -158,6 +174,7 @@ void CheckPingButton(CNEO_Player* player) } IGameEvent* event = gameeventmanager->CreateEvent("player_ping"); + Assert(event); if (event) { trace_t tr; @@ -177,7 +194,39 @@ void CheckPingButton(CNEO_Player* player) event->SetInt("pingy", tr.endpos.y); event->SetInt("pingz", tr.endpos.z); event->SetBool("ghosterping", player->IsCarryingGhost() || player->m_iNeoClass == NEO_CLASS_VIP); + event->SetBool("server", player->IsServer()); #ifdef GAME_DLL + if (sv_neo_player_pings_calc_placename.GetBool() && TheNavMesh) + { + constexpr auto fnGetNearbyNavArea = + [](const Vector& pingPos, const float maxDist, const bool requireAreaBeNamed)->CNavArea* { + Assert(TheNavMesh); + constexpr auto ignoreNamelessPlaces = [](const CNavArea* area)->bool { + return !area || !TheNavMesh->PlaceToName(area->GetPlace()); + }; + return TheNavMesh->GetNearestNavArea(pingPos, true, maxDist, false, false, TEAM_ANY, + requireAreaBeNamed + ? static_cast(ignoreNamelessPlaces) + : nullptr); + }; + + constexpr float maxPingAreaDist = 1024; + constexpr float maxMissedPingAreaDist = maxPingAreaDist * 4; + static_assert(maxPingAreaDist < maxMissedPingAreaDist); + static_assert(IN_BETWEEN_EQ(0, maxPingAreaDist, COORD_EXTENT)); + static_assert(IN_BETWEEN_EQ(0, maxMissedPingAreaDist, COORD_EXTENT)); + const auto actualNavAreaOfPing = fnGetNearbyNavArea(tr.endpos, maxPingAreaDist, false); + const auto nearestNamedNavAreaOfPing = !actualNavAreaOfPing ? nullptr : fnGetNearbyNavArea(tr.endpos, maxMissedPingAreaDist, true); + + if (actualNavAreaOfPing && nearestNamedNavAreaOfPing) + { + const bool pingPlaceNameIsExact = (actualNavAreaOfPing == nearestNamedNavAreaOfPing); + event->SetBool("place_exact", pingPlaceNameIsExact); + + const char* placeName = TheNavMesh->PlaceToName(nearestNamedNavAreaOfPing->GetPlace()); + event->SetString("place_name", placeName); + } + } gameeventmanager->FireEvent(event); #else gameeventmanager->FireEventClientSide(event);