예제 #1
0
//==========================================
// AI_SpecialMove
// Handle special cases of crouch/jump
// If the move is resolved here, this function returns true.
//==========================================
qboolean AI_SpecialMove(edict_t *self, usercmd_t *ucmd)
{
	vec3_t forward;
	trace_t tr;
	vec3_t	boxmins, boxmaxs, boxorigin;

	// Get current direction
	AngleVectors( tv(0, self->s.angles[YAW], 0), forward, NULL, NULL );

	//make sure we are bloqued
	VectorCopy( self->s.origin, boxorigin );
	VectorMA( boxorigin, 8, forward, boxorigin ); //move box by 8 to front
	tr = gi.trace( self->s.origin, self->mins, self->maxs, boxorigin, self, MASK_AISOLID);
	if( !tr.startsolid && tr.fraction == 1.0 ) // not bloqued
		return false;

	if( self->ai.pers.moveTypesMask & LINK_CROUCH || self->ai.is_swim )
	{
		//crouch box
		VectorCopy( self->s.origin, boxorigin );
		VectorCopy( self->mins, boxmins );
		VectorCopy( self->maxs, boxmaxs );
		boxmaxs[2] = 14;	//crouched size
		VectorMA( boxorigin, 8, forward, boxorigin ); //move box by 8 to front
		//see if bloqued
		tr = gi.trace( boxorigin, boxmins, boxmaxs, boxorigin, self, MASK_AISOLID);
		if( !tr.startsolid ) // can move by crouching
		{
			ucmd->forwardmove = 400;
			ucmd->upmove = -400;
			return true;
		}
	}

	if( self->ai.pers.moveTypesMask & LINK_JUMP && self->groundentity )
	{
		//jump box
		VectorCopy( self->s.origin, boxorigin );
		VectorCopy( self->mins, boxmins );
		VectorCopy( self->maxs, boxmaxs );
		VectorMA( boxorigin, 8, forward, boxorigin );	//move box by 8 to front
		//
		boxorigin[2] += ( boxmins[2] + AI_JUMPABLE_HEIGHT );	//put at bottom + jumpable height
		boxmaxs[2] = boxmaxs[2] - boxmins[2];	//total player box height in boxmaxs
		boxmins[2] = 0;
		if( boxmaxs[2] > AI_JUMPABLE_HEIGHT ) //the player is smaller than AI_JUMPABLE_HEIGHT
		{
			boxmaxs[2] -= AI_JUMPABLE_HEIGHT;
			tr = gi.trace( boxorigin, boxmins, boxmaxs, boxorigin, self, MASK_AISOLID);
			if( !tr.startsolid )	//can move by jumping
			{
				ucmd->forwardmove = 400;
				ucmd->upmove = 400;
				
				return true;
			}
		}
	}

	//nothing worked, check for turning
	return AI_CheckEyes(self, ucmd);
}
예제 #2
0
//==========================================
// AI_SpecialMove
// Handle special cases of crouch/jump
// If the move is resolved here, this function returns qtrue.
//==========================================
qboolean AI_SpecialMove( edict_t *self, usercmd_t *ucmd )
{
	vec3_t forward;
	trace_t tr;
	vec3_t boxmins, boxmaxs, boxorigin;

	// Get current direction
	AngleVectors( tv( 0, self->s.angles[YAW], 0 ), forward, NULL, NULL );

	// make sure we are blocked
	VectorCopy( self->s.origin, boxorigin );
	VectorMA( boxorigin, 8, forward, boxorigin ); //move box by 8 to front
	G_Trace( &tr, self->s.origin, self->r.mins, self->r.maxs, boxorigin, self, MASK_AISOLID );
	if( !tr.startsolid && tr.fraction == 1.0 )  // not blocked
		return qfalse;

	//ramps
	if( ISWALKABLEPLANE( &tr.plane ) )
		return qfalse;

	if( self->ai.status.moveTypesMask & LINK_CROUCH || self->is_swim )
	{
		// crouch box
		VectorCopy( self->s.origin, boxorigin );
		VectorCopy( self->r.mins, boxmins );
		VectorCopy( self->r.maxs, boxmaxs );
		boxmaxs[2] = 14; // crouched size
		VectorMA( boxorigin, 8, forward, boxorigin ); // move box by 8 to front
		// see if blocked
		G_Trace( &tr, boxorigin, boxmins, boxmaxs, boxorigin, self, MASK_AISOLID );
		if( !tr.startsolid ) // can move by crouching
		{
			ucmd->forwardmove = 1;
			ucmd->upmove = -1;
			return qtrue;
		}
	}

	if( self->ai.status.moveTypesMask & LINK_JUMP && self->groundentity )
	{
		// jump box
		VectorCopy( self->s.origin, boxorigin );
		VectorCopy( self->r.mins, boxmins );
		VectorCopy( self->r.maxs, boxmaxs );
		VectorMA( boxorigin, 8, forward, boxorigin ); // move box by 8 to front
		//
		boxorigin[2] += ( boxmins[2] + AI_JUMPABLE_HEIGHT ); // put at bottom + jumpable height
		boxmaxs[2] = boxmaxs[2] - boxmins[2]; // total player box height in boxmaxs
		boxmins[2] = 0;

		G_Trace( &tr, boxorigin, boxmins, boxmaxs, boxorigin, self, MASK_AISOLID );
		if( !tr.startsolid ) // can move by jumping
		{
			ucmd->forwardmove = 1;
			ucmd->upmove = 1;

			return qtrue;
		}
	}

	// nothing worked, check for turning
	return AI_CheckEyes( self, ucmd );
}