From 197ce20c314c6457d03a8e395bf6fa62be0db859 Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Wed, 20 Jul 2022 16:27:24 -0700 Subject: [PATCH] BotLib: Start making use of some of NSNavAI --- src/botlib/bot.h | 1 - src/botlib/bot.qc | 18 +++----------- src/botlib/bot_combat.qc | 2 +- src/botlib/route.qc | 16 ------------ src/botlib/way.qc | 2 +- src/gs-entbase/server/scripted_sequence.qc | 4 +-- src/server/route.h | 1 - src/shared/NSClient.h | 2 +- src/shared/NSMonster.qc | 14 +++++------ src/shared/NSNavAI.h | 4 +-- src/shared/NSNavAI.qc | 29 ++++++++++++---------- 11 files changed, 32 insertions(+), 61 deletions(-) diff --git a/src/botlib/bot.h b/src/botlib/bot.h index 7d42e969..5a40873a 100644 --- a/src/botlib/bot.h +++ b/src/botlib/bot.h @@ -80,7 +80,6 @@ class bot:player virtual void(void) SeeThink; virtual void(int, int) BrainThink; virtual void(void) RunAI; - virtual void(vector) NewRoute; virtual void(void) CreateObjective; virtual void(void) CheckRoute; virtual void(void) PreFrame; diff --git a/src/botlib/bot.qc b/src/botlib/bot.qc index 35929c03..83ad8393 100644 --- a/src/botlib/bot.qc +++ b/src/botlib/bot.qc @@ -49,14 +49,8 @@ bot::GetRunSpeed(void) void bot::RouteClear(void) { - if (!m_iNodes) - return; - - m_iCurNode = BOTROUTE_END; - m_iNodes = 0; + super::RouteClear(); m_flNodeGiveup = 0.0f; - memfree(m_pRoute); - print(sprintf("%s cleared his route.\n", netname)); } void @@ -70,7 +64,7 @@ bot::BrainThink(int enemyvisible, int enemydistant) } } else if (m_eTarget && enemyvisible && enemydistant) { /* we can see the player, but are too far away, plot a route */ - route_calculate(this, m_eTarget.origin, 0, Bot_RouteCB); + RouteToPosition(m_eTarget.origin); } } @@ -287,16 +281,10 @@ bot::CheckRoute(void) } } -void -bot::NewRoute(vector pos) -{ - route_calculate(this, pos, 0, Bot_RouteCB); -} - void bot::CreateObjective(void) { - route_calculate(this, Route_SelectDestination(this), 0, Bot_RouteCB); + RouteToPosition(Route_SelectDestination(this)); } void diff --git a/src/botlib/bot_combat.qc b/src/botlib/bot_combat.qc index 63ee2aaf..a3ae740c 100644 --- a/src/botlib/bot_combat.qc +++ b/src/botlib/bot_combat.qc @@ -154,7 +154,7 @@ BotLib_Alert(vector pos, float radius, float t) /* we've heard a noise. investigate the location */ print(sprintf("bot alerted by noise at %v\n", pos)); f.RouteClear(); - f.NewRoute(pos); + f.RouteToPosition(pos); } g_botalert_timer = time + 0.5f; diff --git a/src/botlib/route.qc b/src/botlib/route.qc index 6d3ccaef..392c006d 100644 --- a/src/botlib/route.qc +++ b/src/botlib/route.qc @@ -163,22 +163,6 @@ Route_SelectRandomSpot(void) return (eLastSpot); } -void -Bot_RouteCB(entity ent, vector dest, int numnodes, nodeslist_t *nodelist) -{ - bot b = (bot)ent; - b.m_iNodes = numnodes; - b.m_iCurNode = numnodes - 1; - b.m_pRoute = nodelist; - b.m_vecLastNode = dest; - b.m_flNodeGiveup = 0.0f; - - print("Bot: Route calculated.\n"); - print(sprintf("Bot: # of nodes: %i\n", b.m_iNodes) ); - print(sprintf("Bot: # current node: %i\n", b.m_iCurNode) ); - print(sprintf("Bot: # endpos: %v\n", dest)); -} - vector Route_SelectDestination(bot target) { diff --git a/src/botlib/way.qc b/src/botlib/way.qc index f9ff72c4..8016aa33 100644 --- a/src/botlib/way.qc +++ b/src/botlib/way.qc @@ -482,7 +482,7 @@ Way_GoToPoint(entity pl) bot targ; targ = (bot)a; targ.RouteClear(); - route_calculate(targ, pl.origin, 0, Bot_RouteCB); + targ.RouteToPosition(pl.origin); print(sprintf("Told bot to go to %v\n", trace_endpos)); } } diff --git a/src/gs-entbase/server/scripted_sequence.qc b/src/gs-entbase/server/scripted_sequence.qc index 5dc65209..ea4cc5fe 100644 --- a/src/gs-entbase/server/scripted_sequence.qc +++ b/src/gs-entbase/server/scripted_sequence.qc @@ -208,12 +208,12 @@ scripted_sequence::RunOnEntity(entity targ) if (m_iMove == SS_NO) { NSLog("\tType: SS_NO (%i)", m_iMove); } else if (m_iMove == SS_WALK) { - f.NewRoute(origin); + f.RouteToPosition(origin); f.m_flSequenceSpeed = f.GetWalkSpeed(); NSLog("\tType: SS_WALK (%i)", m_iMove); return; } else if (m_iMove == SS_RUN) { - f.NewRoute(origin); + f.RouteToPosition(origin); f.m_flSequenceSpeed = f.GetRunSpeed(); NSLog("\tType: SS_RUN (%i)", m_iMove); return; diff --git a/src/server/route.h b/src/server/route.h index e9d57539..2923c767 100644 --- a/src/server/route.h +++ b/src/server/route.h @@ -15,7 +15,6 @@ */ int Route_RoundDistance( float flDist ); -void Bot_RouteCB( entity ent, vector dest, int numnodes, nodeslist_t *nodelist ); int Route_GetNodeFlags(nodeslist_t *node); vector Route_GetJumpVelocity(vector frompos, vector topos, float gravitymod); diff --git a/src/shared/NSClient.h b/src/shared/NSClient.h index 54b9197b..2549da4a 100644 --- a/src/shared/NSClient.h +++ b/src/shared/NSClient.h @@ -16,7 +16,7 @@ /* both NSClientPlayer and base_NSClientSpectator are based off this class */ class -NSClient:NSSurfacePropEntity +NSClient:NSNavAI { vector origin_net; vector velocity_net; diff --git a/src/shared/NSMonster.qc b/src/shared/NSMonster.qc index 6281fb2c..590d7346 100644 --- a/src/shared/NSMonster.qc +++ b/src/shared/NSMonster.qc @@ -213,7 +213,7 @@ NSMonster::SeeThink(void) /* enemy is not valid anymore, reset it, clear route and search for new enemy */ SetState(MONSTER_ALERT); m_eEnemy = __NULL__; - ClearRoute(); + RouteClear(); m_flSeeTime = 0; } @@ -227,7 +227,7 @@ NSMonster::SeeThink(void) m_eEnemy = NSMonster_FindClosestPlayer(this); if (m_eEnemy) - NewRoute(m_eEnemy.origin); + RouteToPosition(m_eEnemy.origin); return; } @@ -299,8 +299,8 @@ NSMonster::AttackThink(void) /* FIXME: This is unreliable, but unlikely that a player ever is here */ if (m_vecLKPos != [0,0,0]) { - ClearRoute(); - NewRoute(m_vecLKPos); + RouteClear(); + RouteToPosition(m_vecLKPos); m_flSequenceSpeed = 140; m_vecLKPos = [0,0,0]; } @@ -433,8 +433,6 @@ NSMonster::RouteEnded(void) void NSMonster::WalkRoute(void) { - vector endangles; - /* we're busy shooting at something, don't walk */ if (GetState() == MONSTER_AIMING && m_eEnemy) { input_angles = vectoangles(m_eEnemy.origin - origin); @@ -1037,8 +1035,8 @@ NSMonster_AlertEnemyAlliance(vector pos, float radius, int alliance) continue; /* we've heard a noise. investigate the location */ - f.ClearRoute(); - f.NewRoute(pos); + f.RouteClear(); + f.RouteToPosition(pos); f.m_flSequenceSpeed = 140; } diff --git a/src/shared/NSNavAI.h b/src/shared/NSNavAI.h index e1cab08c..3da357de 100644 --- a/src/shared/NSNavAI.h +++ b/src/shared/NSNavAI.h @@ -42,8 +42,8 @@ NSNavAI:NSSurfacePropEntity virtual vector(void) GetRouteDirection; virtual void(void) RouteEnded; - virtual void(void) ClearRoute; + virtual void(void) RouteClear; virtual void(void) CheckRoute; - virtual void(vector) NewRoute; + virtual void(vector) RouteToPosition; #endif }; \ No newline at end of file diff --git a/src/shared/NSNavAI.qc b/src/shared/NSNavAI.qc index dccd2bfd..cd6e43dc 100644 --- a/src/shared/NSNavAI.qc +++ b/src/shared/NSNavAI.qc @@ -104,7 +104,7 @@ NSNavAI::CheckRoute(void) /* reached the end of the line */ if (m_iCurNode < -1) { - ClearRoute(); + RouteClear(); RouteEnded(); NSLog("^2%s::^3CheckRoute^7: %s reached end", classname, targetname); } @@ -145,7 +145,7 @@ NSNavAI::CheckRoute(void) if (m_flNodeGiveup >= 1.0f) { print(sprintf("NSNavAI::CheckNode: %s gave up route\n", this.netname)); - ClearRoute(); + RouteClear(); }*/ } @@ -179,10 +179,10 @@ NSNavAI::GetRouteDirection(void) } void -NSNavAI::NewRoute(vector destination) +NSNavAI::RouteToPosition(vector destination) { /* engine calls this upon successfully creating a route */ - static void NewRoute_RouteCB(entity ent, vector dest, int numnodes, nodeslist_t *nodelist) + static void RouteToPosition_RouteCB(entity ent, vector dest, int numnodes, nodeslist_t *nodelist) { NSNavAI p = (NSNavAI)ent; p.m_iNodes = numnodes; @@ -194,11 +194,11 @@ NSNavAI::NewRoute(vector destination) /* can we walk directly to our target destination? */ if (trace_fraction == 1.0) { - NSLog("^2%s::^3NewRoute^7: " \ + NSLog("^2%s::^3RouteToPosition^7: " \ "Walking directly to last node", classname); p.m_iCurNode = -1; } else { - NSLog("^2%s::^3NewRoute^7: " \ + NSLog("^2%s::^3RouteToPosition^7: " \ "Path obstructed, calculating route", classname); /* run through all nodes, mark the closest direct path possible */ @@ -218,21 +218,24 @@ NSNavAI::NewRoute(vector destination) if (!g_nodes_present) return; - ClearRoute(); + RouteClear(); if (!m_iNodes) { - route_calculate(this, destination, 0, NewRoute_RouteCB); + route_calculate(this, destination, 0, RouteToPosition_RouteCB); m_vecLastNode = destination; } } void -NSNavAI::ClearRoute(void) +NSNavAI::RouteClear(void) { - if (m_iNodes) { - m_iNodes = 0; - memfree(m_pRoute); - } + if (!m_iNodes) + return; + + m_iCurNode = BOTROUTE_END; + m_iNodes = 0; + memfree(m_pRoute); + print(sprintf("%s cleared his route.\n", netname)); } #endif