BotLib: Start making use of some of NSNavAI

This commit is contained in:
Marco Cawthorne 2022-07-20 16:27:24 -07:00
parent 8fccdcbad1
commit 197ce20c31
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
11 changed files with 32 additions and 61 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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)
{

View File

@ -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));
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;
}

View File

@ -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
};

View File

@ -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