//========================================== // AI_SetGoal // set the goal //jabot092 //========================================== void AI_SetGoal(edict_t *self, int goal_node) { int node; self->ai->goal_node = goal_node; node = AI_FindClosestReachableNode( self->s.origin, self, NODE_DENSITY*3, NODE_ALL ); if(node == -1) { AI_SetUpMoveWander(self); return; } //------- ASTAR ----------- //do this twice, 1 time randomly dropping some nodes out so bots take alternate routes. Second time, normal. dropnodes = true; if( !AStar_GetPath( node, goal_node, self->ai->pers.moveTypesMask, &self->ai->path ) ) { dropnodes = false; if( !AStar_GetPath( node, goal_node, self->ai->pers.moveTypesMask, &self->ai->path ) ) { AI_SetUpMoveWander(self); return; } } dropnodes = false; self->ai->current_node = self->ai->path.nodes[self->ai->path.numNodes]; //------------------------- // if(AIDevel.debugChased && bot_showlrgoal->value) // G_PrintMsg (AIDevel.chaseguy, PRINT_HIGH, "%s: GOAL: new START NODE selected %d\n", self->ai->pers.netname, node); self->ai->next_node = self->ai->current_node; // make sure we get to the nearest node first self->ai->node_timeout = 0; }
void AI_SetGoal( edict_t *self, int goal_node ) { int node; self->ai->goal_node = goal_node; node = AI_FindClosestReachableNode( self->s.origin, self, NODE_DENSITY * 3, NODE_ALL ); if( node == NODE_INVALID ) { AI_ClearGoal( self ); return; } // ASTAR if( !AStar_GetPath( node, goal_node, self->ai->status.moveTypesMask, &self->ai->path ) ) { AI_ClearGoal( self ); return; } self->ai->current_node = self->ai->path.nodes[self->ai->path.numNodes]; if( nav.debugMode && bot_showlrgoal->integer > 1 ) G_PrintChasersf( self, "%s: GOAL: new START NODE selected %d goal %d\n", self->ai->pers.netname, node, self->ai->goal_node ); self->ai->next_node = self->ai->current_node; // make sure we get to the nearest node first self->ai->node_timeout = 0; self->ai->longRangeGoalTimeout = 0; self->ai->tries = 0; // Reset the count of how many times we tried this goal }
//========================================== // AI_FindCost // Determine cost of moving from one node to another //========================================== int AI_FindCost(int from, int to, int movetypes) { astarpath_t path; if( !AStar_GetPath( from, to, movetypes, &path ) ) return -1; return path.numNodes; }
int AI_FindCost( int from, int to, int movetypes ) { astarpath_t path; if( !AStar_GetPath( from, to, movetypes, &path ) ) return -1; return path.totalDistance; }
//========================================== // AI_ClosestNodeToReachableSpot // Find the closest node to a given origin that is reachable by player //========================================== int AI_ClosestNodeToReachableSpot(edict_t *self, vec3_t origin) { int i; float closest = 999999999; float dist; int node=-1; vec3_t v; //int check[4]; int c; //gi.dprintf(DEVELOPER_MSG_GAME, "%s\n",vtos(origin)); //check[0]=-1; //check[1]=-1; //check[2]=-1; //check[3]=-1; c = 0; while (c < 4) { closest = 999999999; node=-1; for(i=0;i<nav.num_nodes;i++) { //gi.dprintf(DEVELOPER_MSG_GAME, "%s\n", vtos(nodes[i].origin)); VectorSubtract( nodes[i].origin, origin, v ); dist = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; //gi.dprintf(DEVELOPER_MSG_GAME, "%f\n", dist); if(dist < closest) { // if (i != check[0] && i != check[1] && // i != check[2] && i != check[3]) // { node = i; closest = dist; // } } } //gi.dprintf(DEVELOPER_MSG_GAME, "check: %i\n", node); if( AStar_GetPath( self->ai->current_node, node, self->ai->pers.moveTypesMask, &self->ai->path ) ) return node; //check [c] = node; //gi.dprintf(DEVELOPER_MSG_GAME, "%s\n", vtos(nodes[node].origin)); c++; } //gi.dprintf(DEVELOPER_MSG_GAME, "no node found\n"); return -1; }