Skip to content

Commit bd2f49d

Browse files
committed
Nav Blockers Fix
Fixed door nav blockers not ignoring disabled triggers, causing some issues in some TF2 maps. Added a command to print nav blockers information.
1 parent 342cba8 commit bd2f49d

6 files changed

Lines changed: 43 additions & 0 deletions

File tree

extension/mods/tf2/teamfortress2mod.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ void CTeamFortress2Mod::FireGameEvent(IGameEvent* event)
270270
}
271271
else if (strncasecmp(name, "teamplay_point_captured", 23) == 0)
272272
{
273+
TheNavMesh->ScheduleRecomputationOfInternalData(CNavMesh::RecomputeInternalDataReason::RECOMPUTEREASON_OBJECTIVE_UPDATED);
273274
int pointID = event->GetInt("cp");
274275
int teamWhoCapped = event->GetInt("team");
275276
CBaseEntity* entity = GetControlPointByIndex(pointID);
@@ -1524,6 +1525,7 @@ void CTeamFortress2Mod::OnRoundStart()
15241525
};
15251526

15261527
extmanager->ForEachBot(func);
1528+
TheNavMesh->ScheduleRecomputationOfInternalData(CNavMesh::RecomputeInternalDataReason::RECOMPUTEREASON_RESET);
15271529
}
15281530

15291531
const TeamFortress2::TFObjectiveResource* CTeamFortress2Mod::GetTFObjectiveResource() const

extension/navmesh/nav_blocker.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class INavBlocker
5151
virtual void OnRecomputeInternalData() = 0;
5252
// Return true if this blocker should be deleted when the nav mesh internal data is recomputed
5353
virtual bool RemoveOnRecompute() = 0;
54+
// The name of this blocker, for debugging purposes
55+
virtual const char* GetName() = 0;
56+
// Prints debug information to the console.
57+
virtual void PrintDebugInfo() = 0;
5458
};
5559

5660
/**
@@ -84,6 +88,8 @@ class CNavBlocker : public INavBlocker
8488
bool IsBlocked(int teamID) { return true; }
8589
void OnRecomputeInternalData() override {}
8690
bool RemoveOnRecompute() override { return false; }
91+
const char* GetName() override { return "CNavBlocker"; }
92+
void PrintDebugInfo() override {}
8793

8894
protected:
8995
std::vector<AreaType*> m_areas;

extension/navmesh/nav_blocker_door.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ bool CDoorNavBlocker::IsBlocked(int teamID)
7777
return m_blocked;
7878
}
7979

80+
void CDoorNavBlocker::PrintDebugInfo()
81+
{
82+
META_CONPRINTF("Door: %s\n", UtilHelpers::textformat::FormatEntity(m_door.Get()));
83+
META_CONPRINTF("Trigger: %s\n", UtilHelpers::textformat::FormatEntity(m_trigger.Get()));
84+
META_CONPRINTF("Filter: %s\n", UtilHelpers::textformat::FormatEntity(m_filter.Get()));
85+
META_CONPRINTF("Team Only: %s Team: %i\n", UtilHelpers::textformat::FormatBool(m_teamOnly), m_teamNum);
86+
}
87+
8088
void CDoorNavBlocker::UpdateDoor()
8189
{
8290
CBaseEntity* door = m_door.Get();
@@ -108,6 +116,15 @@ void CDoorNavBlocker::UpdateDoor()
108116
auto func = [&targetname, &trigger](int index, edict_t* edict, CBaseEntity* entity) {
109117
if (entity)
110118
{
119+
bool disabled = false;
120+
entprops->GetEntPropBool(entity, Prop_Data, "m_bDisabled", disabled);
121+
122+
// some doors (IE: pl_goldrush) have one trigger per team
123+
if (disabled)
124+
{
125+
return true; // skip, continue loop
126+
}
127+
111128
if (UtilHelpers::io::IsConnectedTo(entity, targetname))
112129
{
113130
trigger = entity;

extension/navmesh/nav_blocker_door.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class CDoorNavBlocker : public CNavBlocker<CNavArea>
3131
void Update() override;
3232
bool IsBlocked(int teamID) override;
3333
bool RemoveOnRecompute() override { return true; }
34+
const char* GetName() override { return "CDoorNavBlocker"; }
35+
void PrintDebugInfo() override;
3436

3537
protected:
3638
DoorType m_doortype;

extension/navmesh/nav_mesh.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4686,6 +4686,16 @@ void NavNotifyClientsOfReload::operator()(CBaseExtPlayer* player)
46864686
}
46874687
}
46884688

4689+
void CNavMesh::CommandNavDebugAutoBlockers()
4690+
{
4691+
std::for_each(m_navblockers.begin(), m_navblockers.end(), [](std::unique_ptr<INavBlocker>& blocker) {
4692+
META_CONPRINTF("Nav Blocker: \"%s\". Valid: %s. Status (ANY TEAM): %s \n",
4693+
blocker->GetName(),
4694+
UtilHelpers::textformat::FormatBool(blocker->IsValid()),
4695+
blocker->IsBlocked(NAV_TEAM_ANY) ? "BLOCKED" : "UNBLOCKED");
4696+
blocker->PrintDebugInfo();
4697+
});
4698+
}
46894699

46904700
CON_COMMAND_F(sm_nav_import, "Imports an existing official navigation mesh.", FCVAR_GAMEDLL | FCVAR_CHEAT)
46914701
{
@@ -4696,3 +4706,8 @@ CON_COMMAND_F(sm_nav_rcbot2_import, "Imports waypoints from RCBot2", FCVAR_GAMED
46964706
{
46974707
TheNavMesh->ImportWaypointsFromRCBot2();
46984708
}
4709+
4710+
CON_COMMAND_F(sm_nav_debug_blockers, "Shows debug information of nav blockers.", FCVAR_GAMEDLL | FCVAR_CHEAT)
4711+
{
4712+
TheNavMesh->CommandNavDebugAutoBlockers();
4713+
}

extension/navmesh/nav_mesh.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ class CNavMesh : public CEventListenerHelper
655655
void CommandNavReloadMesh(); // Saves the navigation mesh and reloads it
656656
void CommandNavMeasureDistance(); // Measures the distance between two nav areas
657657
void CommandNavDumpToKeyValues(); // Dumps nav mesh data to a KV file
658+
void CommandNavDebugAutoBlockers(); // Debug automatic nav blockers
658659

659660
void AddToDragSelectionSet( CNavArea *pArea );
660661
void RemoveFromDragSelectionSet( CNavArea *pArea );

0 commit comments

Comments
 (0)