Skip to content

Commit

Permalink
TF Nav
Browse files Browse the repository at this point in the history
  • Loading branch information
caxanga334 committed May 13, 2024
1 parent 6ee218a commit 62543ac
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 46 deletions.
8 changes: 7 additions & 1 deletion AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class ExtensionConfig(object):
cxx.defines += ['WIN32', '_WINDOWS']

def configure_shared(self, cxx):
cxx.defines += ['EXT_DEBUG_DRAW_TIME=0.0f', 'RAD_TELEMETRY_DISABLED']
cxx.defines += ['RAD_TELEMETRY_DISABLED']

if builder.options.debugmode == '1':
cxx.defines += ['EXT_DEBUG']
Expand Down Expand Up @@ -464,6 +464,7 @@ class ExtensionConfig(object):
]
return compiler


def ExtLibrary(self, context, compiler, name):
binary = self.Library(context, compiler, name)
SetArchFlags(compiler)
Expand Down Expand Up @@ -514,6 +515,11 @@ class ExtensionConfig(object):

return binary

def CPPLibrary(self, project, context, compiler, name):
binary = project.Configure(compiler, name, '{0}'.format(compiler.target.arch))
self.AddCxxCompat(binary)
return binary

def HL2Library(self, context, compiler, name, sdk):
binary = self.Library(context, compiler, name)
self.ConfigureForExtension(context, binary.compiler)
Expand Down
160 changes: 160 additions & 0 deletions extension/mods/tf2/nav/tfnav_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,54 @@ inline static CTFNavArea::TFNavPathAttributes NameToTFNavPathAttribute(const cha
}
}

inline static CTFNavArea::TFNavAttributes NameToTFNavAttributes(const char* name)
{
if (strncasecmp(name, "limit_red", 9) == 0)
{
return CTFNavArea::TFNAV_LIMIT_TO_REDTEAM;
}
else if (strncasecmp(name, "limit_blu", 9) == 0)
{
return CTFNavArea::TFNAV_LIMIT_TO_BLUTEAM;
}
else if (strncasecmp(name, "sentry_gun_hint", 15) == 0)
{
return CTFNavArea::TFNAV_SENTRYGUN_HINT;
}
else if (strncasecmp(name, "dispenser_hint", 14) == 0)
{
return CTFNavArea::TFNAV_DISPENSER_HINT;
}
else if (strncasecmp(name, "tele_entrance_hint", 18) == 0)
{
return CTFNavArea::TFNAV_TELE_ENTRANCE_HINT;
}
else if (strncasecmp(name, "tele_exit_hint", 14) == 0)
{
return CTFNavArea::TFNAV_TELE_EXIT_HINT;
}
else if (strncasecmp(name, "sniper_spot_hint", 16) == 0)
{
return CTFNavArea::TFNAV_SNIPER_HINT;
}
else
{
return CTFNavArea::TFNAV_INVALID;
}
}

inline static CTFNavArea::MvMNavAttributes NameToMvMAttributes(const char* name)
{
if (strncasecmp(name, "frontlines", 10) == 0)
{
return CTFNavArea::MVMNAV_FRONTLINES;
}
else
{
return CTFNavArea::MVMNAV_INVALID;
}
}

class CTFNavEditTogglePathAttribute
{
public:
Expand Down Expand Up @@ -58,6 +106,62 @@ class CTFNavEditTogglePathAttribute
CTFNavArea::TFNavPathAttributes m_attribute;
};

class CTFNavEditToggleAttribute
{
public:
CTFNavEditToggleAttribute(CTFNavArea::TFNavAttributes attribute)
{
m_attribute = attribute;
}

bool operator() (CNavArea* baseArea)
{
CTFNavArea* area = static_cast<CTFNavArea*>(baseArea);

if (TheNavMesh->IsSelectedSetEmpty() && area->HasTFAttributes(m_attribute))
{
area->ClearTFAttributes(m_attribute);
}
else
{
area->SetTFAttributes(m_attribute);
}

return true;
}

private:
CTFNavArea::TFNavAttributes m_attribute;
};

class CTFNavEditToggleMvMAttribute
{
public:
CTFNavEditToggleMvMAttribute(CTFNavArea::MvMNavAttributes attribute)
{
m_attribute = attribute;
}

bool operator() (CNavArea* baseArea)
{
CTFNavArea* area = static_cast<CTFNavArea*>(baseArea);

if (TheNavMesh->IsSelectedSetEmpty() && area->HasMVMAttributes(m_attribute))
{
area->ClearMVMAttributes(m_attribute);
}
else
{
area->SetMVMAttributes(m_attribute);
}

return true;
}

private:
CTFNavArea::MvMNavAttributes m_attribute;
};

CON_COMMAND_F(sm_tf_nav_toggle_path_attrib, "Toggles NavBot TF Path Attributes on the selected set", FCVAR_CHEAT)
{
if (args.ArgC() < 2)
Expand All @@ -83,5 +187,61 @@ CON_COMMAND_F(sm_tf_nav_toggle_path_attrib, "Toggles NavBot TF Path Attributes o
}
}

TheNavMesh->ClearSelectedSet();
}

CON_COMMAND_F(sm_tf_nav_toggle_attrib, "Toggles NavBot TF Attributes on the selected set", FCVAR_CHEAT)
{
if (args.ArgC() < 2)
{
Msg("Usage: sm_tf_nav_toggle_attrib <attribute 1> ... <attribute N> \n");
Msg("Valid Attributes: limit_red limit_blu sentry_gun_hint dispenser_hint tele_entrance_hint tele_exit_hint sniper_spot_hint \n");
return;
}

for (int i = 1; i < args.ArgC(); i++)
{
auto attrib = NameToTFNavAttributes(args[i]);

if (attrib != CTFNavArea::TFNAV_INVALID)
{
CTFNavEditToggleAttribute toggle(attrib);
TheNavMesh->ForAllSelectedAreas(toggle);
Msg("Toggling TF Attribute \"%s\". \n", args[i]);
}
else
{
Warning("Unknown TF Attribute \"%s\"! \n", args[i]);
}
}

TheNavMesh->ClearSelectedSet();
}

CON_COMMAND_F(sm_tf_nav_toggle_mvm_attrib, "Toggles NavBot TF MvM Attributes on the selected set", FCVAR_CHEAT)
{
if (args.ArgC() < 2)
{
Msg("Usage: sm_tf_nav_toggle_mvm_attrib <attribute 1> ... <attribute N> \n");
Msg("Valid Attributes: frontlines \n");
return;
}

for (int i = 1; i < args.ArgC(); i++)
{
auto attrib = NameToMvMAttributes(args[i]);

if (attrib != CTFNavArea::MVMNAV_INVALID)
{
CTFNavEditToggleMvMAttribute toggle(attrib);
TheNavMesh->ForAllSelectedAreas(toggle);
Msg("Toggling TF MvM Attribute \"%s\". \n", args[i]);
}
else
{
Warning("Unknown TF MvM Attribute \"%s\"! \n", args[i]);
}
}

TheNavMesh->ClearSelectedSet();
}
71 changes: 65 additions & 6 deletions extension/mods/tf2/nav/tfnavarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,19 @@ void CTFNavArea::Debug_ShowTFPathAttributes() const
if (HasTFPathAttributes(TFNAV_PATH_NO_RED_TEAM))
{
ke::SafeStrcat(message, TEXT_SIZE, " NO_RED_TEAM");
DrawFilled(153, 204, 255, 255, EXT_DEBUG_DRAW_TIME, true);
DrawFilled(153, 204, 255, 255, NDEBUG_PERSIST_FOR_ONE_TICK, true);
}

if (HasTFPathAttributes(TFNAV_PATH_NO_BLU_TEAM))
{
ke::SafeStrcat(message, TEXT_SIZE, " NO_BLU_TEAM");
DrawFilled(255, 64, 64, 255, EXT_DEBUG_DRAW_TIME, true);
DrawFilled(255, 64, 64, 255, NDEBUG_PERSIST_FOR_ONE_TICK, true);
}

if (HasTFPathAttributes(TFNAV_PATH_NO_CARRIERS))
{
ke::SafeStrcat(message, TEXT_SIZE, " NO_FLAG_CARRIERS");
DrawFilled(255, 69, 0, 255, EXT_DEBUG_DRAW_TIME, true);
DrawFilled(255, 69, 0, 255, NDEBUG_PERSIST_FOR_ONE_TICK, true);
}

if (HasTFPathAttributes(TFNAV_PATH_CARRIERS_AVOID))
Expand All @@ -146,13 +146,72 @@ void CTFNavArea::Debug_ShowTFPathAttributes() const

if (m_spawnroomteam == static_cast<int>(TeamFortress2::TFTeam::TFTeam_Blue))
{
DrawFilled(153, 204, 255, 255, EXT_DEBUG_DRAW_TIME, true);
DrawFilled(153, 204, 255, 255, NDEBUG_PERSIST_FOR_ONE_TICK, true);
}
else if (m_spawnroomteam == static_cast<int>(TeamFortress2::TFTeam::TFTeam_Red))
{
DrawFilled(255, 64, 64, 255, EXT_DEBUG_DRAW_TIME, true);
DrawFilled(255, 64, 64, 255, NDEBUG_PERSIST_FOR_ONE_TICK, true);
}
}

NDebugOverlay::Text(GetCenter() + Vector(0.0f, 0.0f, 12.0f), message, true, EXT_DEBUG_DRAW_TIME);
NDebugOverlay::Text(GetCenter() + Vector(0.0f, 0.0f, 12.0f), message, true, NDEBUG_PERSIST_FOR_ONE_TICK);
}

void CTFNavArea::Debug_ShowTFAttributes() const
{
constexpr auto TEXT_SIZE = 256;
char message[TEXT_SIZE]{};

if (HasTFAttributes(TFNAV_LIMIT_TO_REDTEAM))
{
ke::SafeStrcat(message, TEXT_SIZE, " LIMIT_TO_RED_TEAM");
DrawFilled(153, 204, 255, 255, NDEBUG_PERSIST_FOR_ONE_TICK, true);
}

if (HasTFAttributes(TFNAV_LIMIT_TO_BLUTEAM))
{
ke::SafeStrcat(message, TEXT_SIZE, " LIMIT_TO_BLU_TEAM");
DrawFilled(255, 64, 64, 255, NDEBUG_PERSIST_FOR_ONE_TICK, true);
}

if (HasTFAttributes(TFNAV_SENTRYGUN_HINT))
{
ke::SafeStrcat(message, TEXT_SIZE, " SENTRYGUN_HINT");
}

if (HasTFAttributes(TFNAV_DISPENSER_HINT))
{
ke::SafeStrcat(message, TEXT_SIZE, " DISPENSER_HINT");
}

if (HasTFAttributes(TFNAV_TELE_ENTRANCE_HINT))
{
ke::SafeStrcat(message, TEXT_SIZE, " TELE_ENTRANCE_HINT");
}

if (HasTFAttributes(TFNAV_TELE_EXIT_HINT))
{
ke::SafeStrcat(message, TEXT_SIZE, " TELE_EXIT_HINT");
}

if (HasTFAttributes(TFNAV_SNIPER_HINT))
{
ke::SafeStrcat(message, TEXT_SIZE, " SNIPER_HINT");
}

NDebugOverlay::Text(GetCenter() + Vector(0.0f, 0.0f, 12.0f), message, true, NDEBUG_PERSIST_FOR_ONE_TICK);
}

void CTFNavArea::Debug_ShowMvMAttributes() const
{
constexpr auto TEXT_SIZE = 256;
char message[TEXT_SIZE]{};

if (HasMVMAttributes(MVMNAV_FRONTLINES))
{
ke::SafeStrcat(message, TEXT_SIZE, " FRONTLINES");
DrawFilled(0, 153, 0, 255, NDEBUG_PERSIST_FOR_ONE_TICK, true);
}

NDebugOverlay::Text(GetCenter() + Vector(0.0f, 0.0f, 12.0f), message, true, NDEBUG_PERSIST_FOR_ONE_TICK);
}
4 changes: 4 additions & 0 deletions extension/mods/tf2/nav/tfnavarea.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class CTFNavArea : public CNavArea

enum TFNavAttributes
{
TFNAV_INVALID = 0,
TFNAV_LIMIT_TO_REDTEAM = (1 << 0), // Hints are limited to RED team only, this does not block pathing!
TFNAV_LIMIT_TO_BLUTEAM = (1 << 1), // Hints are limited to BLU team only, this does not block pathing!
TFNAV_SENTRYGUN_HINT = (1 << 2), // This is a good spot to build a sentry gun
Expand All @@ -96,6 +97,7 @@ class CTFNavArea : public CNavArea

enum MvMNavAttributes
{
MVMNAV_INVALID = 0,
MVMNAV_FRONTLINES = (1 << 0), // Bots will move here while waiting for the wave to start
};

Expand All @@ -117,6 +119,8 @@ class CTFNavArea : public CNavArea
void UpdateDynamicSpawnRoom();

void Debug_ShowTFPathAttributes() const;
void Debug_ShowTFAttributes() const;
void Debug_ShowMvMAttributes() const;

private:
int m_tfpathattributes;
Expand Down
22 changes: 18 additions & 4 deletions extension/mods/tf2/nav/tfnavmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

extern NavAreaVector TheNavAreas;

ConVar sm_nav_tf_show_path_attributes("sm_nav_tf_show_path_attributes", "0", FCVAR_GAMEDLL, "Shows TF Path Attributes");
ConVar sm_tf_nav_show_path_attributes("sm_tf_nav_show_path_attributes", "0", FCVAR_GAMEDLL, "Shows TF Path Attributes");
ConVar sm_tf_nav_show_attributes("sm_tf_nav_show_attributes", "0", FCVAR_GAMEDLL, "Shows TF Attributes");
ConVar sm_tf_nav_show_mvm_attributes("sm_tf_nav_show_mvm_attributes", "0", FCVAR_GAMEDLL, "Shows TF MvM Attributes");

CTFNavMesh::CTFNavMesh() : CNavMesh()
{
Expand Down Expand Up @@ -53,7 +55,9 @@ void CTFNavMesh::Update()

bool CTFNavMesh::Save(void)
{
sm_nav_tf_show_path_attributes.SetValue(0); // disable rendering to avoid crashes during map change
sm_tf_nav_show_path_attributes.SetValue(0); // disable rendering to avoid crashes during map change
sm_tf_nav_show_attributes.SetValue(0);
sm_tf_nav_show_mvm_attributes.SetValue(0);

return CNavMesh::Save();
}
Expand Down Expand Up @@ -100,7 +104,7 @@ void CTFNavMesh::PostCustomAnalysis(void)
}
}

if (!hasfrontline)
if (!hasfrontline && mod->GetCurrentGameMode() == TeamFortress2::GameModeType::GM_MVM)
{
smutils->LogError(myself, "Mann vs Machine navmesh without \"Frontlines\" areas!");
}
Expand All @@ -112,10 +116,20 @@ void CTFNavMesh::UpdateDebugDraw()
{
CTFNavArea* area = static_cast<CTFNavArea*>(TheNavAreas[it]);

if (sm_nav_tf_show_path_attributes.GetBool())
if (sm_tf_nav_show_path_attributes.GetBool())
{
area->Debug_ShowTFPathAttributes();
}

if (sm_tf_nav_show_attributes.GetBool())
{
area->Debug_ShowTFAttributes();
}

if (sm_tf_nav_show_mvm_attributes.GetBool())
{
area->Debug_ShowMvMAttributes();
}
}
}

Loading

0 comments on commit 62543ac

Please sign in to comment.