Bobot_navigation.c

#include "../game/g_local.h"
#include "bobot.h"
/*-------------------------------------------------------------------
  _______              .__              __  .__              
  \      \ _____ ___  _|__| _________ _/  |_|__| ____   ____ 
  /   |   \\__  \\  \/ /  |/ ___\__  \\   __\  |/  _ \ /    \
 /    |    \/ __ \\   /|  / /_/  > __ \|  | |  (  <_> )   |  \
 \____|__  (____  /\_/ |__\___  (____  /__| |__|\____/|___|  /
         \/     \/       /_____/     \/                    \/
    bobot_navigation.c
    Fusion Navigation
-------------------------------------------------------------------*/

/*-------------------------------------------------------------------
Routine      : BOBOT_NAVIGATION_FindClosestNode
Description  : Find the closest node to the player within a certain range
-------------------------------------------------------------------*/
int BOBOT_NAVIGATION_FindClosestNode(gentity_t *bobot, int r, int type)
{   int         i;
    float       closest;
    float       dist;
    int         node=-1;
    vec3_t      v;
    float       rng;
 
    /*    Square Range for distance comparison (eliminated sqrt) */
    rng = (float)(r * r);
    closest = rng + 1;            //if we found none in the range, we just found none .
    for( i = 0; i < number_of_nodes; i++)
    {    VectorSubtract( nodes[i].origin, bobot->r.currentOrigin, v );
        dist = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
        if (dist < closest && dist < rng )
        {    node = i;
            closest = dist;
        }
    }
    return node;
}
/*-------------------------------------------------------------------
Routine      : FUSION_NAVIGATION_FindClosestReachableNode
Description  : Find the closest node to the player within a certain range
-------------------------------------------------------------------*/
int FUSION_NAVIGATION_FindClosestReachableNode(gentity_t *bobot, int r, int type)
{   int         i;
    float       closest;
    float       dist;
    int         node=-1;
    vec3_t      v;
    float       rng;
    Sbobot        *bobotAI;

    bobotAI = &bobots[bobot->s.clientNum];
   
    /*    Square Range for distance comparison (eliminated sqrt) */
    rng = (float)(r * r);
    closest = rng + 1;            // if we found none in the range, we just found none .
    for( i = 0; i < number_of_nodes; i++)
    {    VectorSubtract( nodes[i].origin, bobot->r.currentOrigin, v );
        dist = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
        if (dist < closest && dist < rng )
        {    node = i;
             closest = dist;
            bobotAI->minDistanceFromNextNode = VectorLength(v);
            bobotAI->maxDistanceFromNextNode = bobotAI->minDistanceFromNextNode;
            bobotAI->lastDistanceFromNextNode = bobotAI->minDistanceFromNextNode;
            VectorCopy(v,bobotAI->move_vector);
        }
    }
    return node;
}

Créer un site gratuit avec e-monsite - Signaler un contenu illicite sur ce site