示例#1
0
//==========================================
// AI_Think
// think funtion for AIs
//==========================================
void AI_Think( edict_t *self )
{
	if( !self->ai || self->ai->type == AI_INACTIVE )
		return;

	if( level.spawnedTimeStamp + 5000 > game.realtime || !level.canSpawnEntities )
	{
		self->nextThink = level.time + game.snapFrameTime;
		return;
	}

	// check for being blocked
	if( !G_ISGHOSTING( self ) )
	{
		AI_CategorizePosition( self );

		if( VectorLengthFast( self->velocity ) > 37 )
			self->ai->blocked_timeout = level.time + 10000;

		// if completely stuck somewhere
		if( self->ai->blocked_timeout < level.time )
		{
			self->ai->pers.blockedTimeout( self );
			return;
		}
	}

	//update status information to feed up ai
	if( self->ai->statusUpdateTimeout <= level.time )
		AI_UpdateStatus( self );

	if( AI_NodeHasTimedOut( self ) )
		AI_ClearGoal( self );

	if( self->ai->goal_node == NODE_INVALID )
		AI_PickLongRangeGoal( self );

	//if( self == level.think_client_entity )
	AI_PickShortRangeGoal( self );

	self->ai->pers.RunFrame( self );

	// Show the path
	if( nav.debugMode && bot_showpath->integer && self->ai->goal_node != NODE_INVALID )
	{
		// only draw the path of those bots which are being chased
		edict_t *chaser;
		bool chaserFound = false;

		for( chaser = game.edicts + 1; ENTNUM( chaser ) < gs.maxclients; chaser++ )
		{
			if( chaser->r.client->resp.chase.active && chaser->r.client->resp.chase.target == ENTNUM( self ) )
			{
				AITools_DrawPath( self, self->ai->goal_node );
				chaserFound = true;
			}
		}

		if( !chaserFound && game.numBots == 1 )
			AITools_DrawPath( self, self->ai->goal_node );
	}
}
示例#2
0
//==========================================
// AI_FollowPath
// Move closer to goal by pointing the bot to the next node
// that is closer to the goal //jabot092 (path-> to path.)
//==========================================
qboolean AI_FollowPath( edict_t *self )
{
	vec3_t			v;
	float			dist;


	if( self->ai->goal_node == INVALID )
		return false;

	// Try again?
	if(self->ai->node_timeout++ > 30)
	{
		if(self->ai->tries++ > 3)
			return false;
		else
			AI_SetGoal( self, self->ai->goal_node );
	}

	// Are we there yet?
	VectorSubtract( self->s.origin, nodes[self->ai->next_node].origin, v );
	dist = VectorLength(v);

	//special lower plat reached check
	if( dist < 64
		&& nodes[self->ai->current_node].flags & NODEFLAGS_PLATFORM
		&& nodes[self->ai->next_node].flags & NODEFLAGS_PLATFORM
		&& self->groundentity && self->groundentity->use == Use_Plat)
		dist = 16;

	if( (dist < 32 && nodes[self->ai->next_node].flags != NODEFLAGS_JUMPPAD && nodes[self->ai->next_node].flags != NODEFLAGS_TELEPORTER_IN)
		|| (self->ai->status.jumpadReached && nodes[self->ai->next_node].flags & NODEFLAGS_JUMPPAD)
		|| (self->ai->status.TeleportReached && nodes[self->ai->next_node].flags & NODEFLAGS_TELEPORTER_IN) )
	{
		// reset timeout
		self->ai->node_timeout = 0;

		if( self->ai->next_node == self->ai->goal_node )
		{
			//if(AIDevel.debugChased && bot_showlrgoal->value)
			//	G_PrintMsg (AIDevel.chaseguy, PRINT_HIGH, "%s: GOAL REACHED!\n", self->ai->pers.netname);
			
			//if botroam, setup a timeout for it
			if( nodes[self->ai->goal_node].flags & NODEFLAGS_BOTROAM )
			{
				int		i;
				for( i=0; i<nav.num_broams; i++) {	//find the broam
					if( nav.broams[i].node != self->ai->goal_node )
						continue;

					//if(AIDevel.debugChased && bot_showlrgoal->integer)
					//	G_PrintMsg (AIDevel.chaseguy, PRINT_HIGH, "%s: BotRoam Time Out set up for node %i\n", self->ai->pers.netname, nav.broams[i].node);
					//Com_Printf( "%s: BotRoam Time Out set up for node %i\n", self->ai->pers.netname, nav.broams[i].node);
					self->ai->status.broam_timeouts[i] = level.time + 15.0;
					break;
				}
			}
		
			// Pick a new goal
			if (self->ai->state != BOT_STATE_CAMP)
				AI_PickLongRangeGoal(self);

		//	if (self->ai->next_node == self->ai->current_node)
		//	{	//gi.dprintf(DEVELOPER_MSG_GAME, "next_node\n");
				//AI_PickLongRangeGoal(self);
		//	}
				
		}
		else
		{
			self->ai->current_node = self->ai->next_node;
			if( self->ai->path.numNodes )
				self->ai->path.numNodes--;
			self->ai->next_node = self->ai->path.nodes[self->ai->path.numNodes];
		}
	}

	if(self->ai->current_node == -1 || self->ai->next_node == -1)
		return false;

	// Set bot's movement vector
	VectorSubtract( nodes[self->ai->next_node].origin, self->s.origin , self->ai->move_vector );
	return true;
}