Bobot_movement.c

#include "../game/g_local.h"
#include "bobot.h"
extern int        myteam, otherteam;
//joc skill des bobots        0        1        2        3        4        5        6
float LookFTBO[]    =        {0.10    ,0.15    ,0.20    ,0.25    ,0.30    ,0.35    ,0.40};
float LookFrein[]    =        {0.90    ,0.85    ,0.80    ,0.75    ,0.70    ,0.65    ,0.10};
//int LookPrecision[]    =    {20        ,17        ,15        ,10        ,5        ,1};
//===========================================================================
// Routine      : FUSION_MOVEMENT_CanMove
// Description  : Checks if bot can move (really just checking ground)
//              : Not an accurate check, but does a decent enough job
//              : and looks for lava/slime.

qboolean FUSION_MOVEMENT_CanMove(gentity_t *bobot, int direction)
{   vec3_t forward, right;
    vec3_t offset,start,end;
    vec3_t angles;
    trace_t tr;

    /*    Now check to see if move will move us off an edge */
      VectorCopy(bobot->s.angles,angles);
    if(direction == BOT_MOVE_LEFT)
    { angles[1] += 90; }
    else if(direction == BOT_MOVE_RIGHT)
    { angles[1] -= 90; }
    else if(direction == BOT_MOVE_BACK)
    { angles[1] -=180; }
 
    /*    Set up the vectors */
    AngleVectors (angles, forward, right, NULL);
    VectorSet(offset, 36, 0, 24);
    G_ProjectSource (bobot->s.origin, offset, forward, right, start);
    VectorSet(offset, 36, 0, -100);
    G_ProjectSource (bobot->s.origin, offset, forward, right, end);
    trap_Trace(&tr,start, NULL, NULL, end, bobot->s.number, MASK_SOLID|MASK_OPAQUE);
    if(tr.fraction == 1.0 || tr.contents & (CONTENTS_LAVA|CONTENTS_SLIME))
    { return qfalse; }
    return qtrue;
}

/*--------------------------------------------------------------------------
Routine      : FUSION_MOVEMENT_Attack
Description  : Attack movement
             : Just basic move and avoidance
---------------------------------------------------------------------------*/
void FUSION_MOVEMENT_Attack (gentity_t *bobot, usercmd_t *ucmd)
{      float        c;
       vec3_t      target;
       vec3_t      angles;
       vec3_t      attackvector;
       float       dist;
       vec3_t        ang, dir;
       Sbobot        *bobotAI = &bobots[bobot->s.clientNum]; // 3emeType
       gentity_t    *enemy = bobotAI->armsAction.ent;

    if (enemy == NULL)
    {    ucmd->buttons = 0;
        return;
    }
    VectorSubtract( enemy->r.currentOrigin, bobot->client->ps.origin, dir );
    VectorNormalize( dir );
    vectoangles( dir, ang );
   
    /*    si l'ennemi peut être visible et qu'il est dans le champ de vision du bot, alors à l'attaque ! */
    VectorSubtract( bobot->s.origin, enemy->s.origin, attackvector);
    dist = VectorLength( attackvector);
    // Use long aim ! DUCK ! IF you don't have the flag ! That is
    if (dist > 550 && !bobot->client->ps.powerups[PW_REDFLAG] && !bobot->client->ps.powerups[PW_BLUEFLAG] )
        {    ucmd->upmove = -48;
            bobot->client->ps.pm_flags |= PMF_DUCKED;
        }
        else
        {    // Duck, but also move !
            if (dist > 350)
            {    ucmd->upmove = -48;
                bobot->client->ps.pm_flags |= PMF_DUCKED;
            }   
            // Randomly choose a movement direction
            //-------------------------------------------------------
            c = random();
            if(c < 0.2 && FUSION_MOVEMENT_CanMove(bobot,BOT_MOVE_LEFT))
            { ucmd->rightmove -= 400;  }
            else if(c < 0.4 && FUSION_MOVEMENT_CanMove(bobot,BOT_MOVE_RIGHT))
            { ucmd->rightmove += 400; }
            else if(c < 0.6 && FUSION_MOVEMENT_CanMove(bobot,BOT_MOVE_FORWARD))
            { ucmd->forwardmove += 400; }
            else if(c < 0.8 && FUSION_MOVEMENT_CanMove(bobot,BOT_MOVE_FORWARD))
            { ucmd->forwardmove -= 400; }
            //-------------------------------------------------------
        }
        if (dist < 200)
        {    // Randomly choose a vertical movement direction
            //-------------------------------------------------------
            c = (random()-0.5)*5;
            if(bobot->client->ps.groundEntityNum)
            {    if(c < 3.0)                //FIXME: 2.0
                {ucmd->upmove = 10;    }    // Was 200
                else
                { ucmd->upmove -= 200; }
            }
            //-------------------------------------------------------
        }
        if(dist < 75)
        { ucmd->forwardmove -= 200;    } // Move away !
        //-------------------------------------------------------
        VectorCopy(enemy->client->ps.origin,target);
        //-------------------------------------------------------
        // AVD if we're hunting dude with the docs, DONT do a rightmove !
        if (enemy->client->ps.powerups[PW_REDFLAG] ||enemy->client->ps.powerups[PW_BLUEFLAG])
        {    ucmd->rightmove = 0;
            ucmd->upmove = 0;
        }
        //+joc
        VectorSubtract (target, bobot->client->ps.origin, bobotAI->move_vector);
        vectoangles (bobotAI->move_vector, angles);
        AnglesSubtract (angles , bobot->s.angles , angles);
        //on ne tire que si on a des chances de toucher !
        if (VectorLength(angles) < BOBOT_VIEW_PRECISION_TIR)
        { ucmd->buttons = BUTTON_ATTACK; }
        BOBOT_MOVEMENT_ChangeBotAngle(angles,bobot);
        //-joc
        bobotAI->teamPauseTime = level.time;
//    }
}

//===========================================================================
// Routine      : FUSION_MOVEMENT_SpecialMove
// Description  : Handles special cases of crouch/jump
//              : If resolved here, function returns true
qboolean FUSION_MOVEMENT_SpecialMove(gentity_t *bobot, usercmd_t *ucmd)
{   vec3_t dir,forward,right,start,end,offset;
    vec3_t top;
    trace_t tr;
 
    // Get current direction
    VectorCopy(bobot->client->ps.viewangles,dir);
    dir[YAW] = bobot->s.angles[YAW];
    AngleVectors (dir, forward, right, NULL);
    VectorSet(offset, 0, 0, 0);
    G_ProjectSource (bobot->client->ps.origin, offset, forward, right, start);
    offset[0] += 18;
    G_ProjectSource (bobot->client->ps.origin, offset, forward, right, end);
    // trace it
    // So bots don't jump all the time
    start[2] += 18;
    end[2] += 18;
    trap_Trace(&tr, start, bobot->r.mins, bobot->r.maxs,end, bobot->s.number, MASK_SOLID);
    //tr = gi.trace (start, bobot->mins, bobot->maxs, end, bobot, MASK_MONSTERSOLID);
    if( tr.fraction < 1.0 )
    {   // Check for crouching
        start[2] -= 14;
        end[2] -= 14;
        // Set up for crouching check
        VectorCopy(bobot->r.maxs,top);
         // crouching height
        top[2] = 0.0;
        trap_Trace(&tr, start, bobot->r.mins, bobot->r.maxs,end, bobot->s.number, MASK_SOLID);
        //tr = gi.trace (start, bobot->mins, top, end, bobot, MASK_MONSTERSOLID);
        // Crouch
        if( tr.fraction == 1.0)
        {    ucmd->forwardmove = 400;
            ucmd->upmove = -400;
            return qtrue;
        }
        //-------------------------------------------------------
        // Check for jump
        //-------------------------------------------------------
        start[2] += 32;
        end[2] += 32;
        trap_Trace(&tr, start, bobot->r.mins, bobot->r.maxs,end, bobot->s.number, MASK_SOLID);
        //tr = gi.trace (start, bobot->mins, bobot->maxs, end, bobot, MASK_MONSTERSOLID);
        if(tr.fraction == 1.0)
        {   ucmd->forwardmove = 400;
            if(bobot->client->ps.groundEntityNum)
            { ucmd->upmove = 400; }
            return qtrue;
        }
        //-------------------------------------------------------
    }
    return qfalse; // We did not resolve a move here
}
/*********************************************************************************************
Joc changer la vue du bobot pour eviter l'effet "parkinson" ou les headshot à tous les coups
on entre dans delta angle la différence entre l'angle voulu pour la visée et l'angle du bobot
*********************************************************************************************/
void BOBOT_MOVEMENT_ChangeBotAngle(vec3_t deltaAngle, gentity_t *bobot)
{
    Sbobot        *bobotAI = &bobots[bobot->s.clientNum];
    //joc asservissement en vitesse
    if (deltaAngle[PITCH] > BOBOT_VIEW_MAX_ACCEL)
    { deltaAngle[PITCH] = BOBOT_VIEW_MAX_ACCEL; }
    else if (deltaAngle[PITCH] < -BOBOT_VIEW_MAX_ACCEL)
    { deltaAngle[PITCH] =-BOBOT_VIEW_MAX_ACCEL; }
    if (deltaAngle[YAW] > BOBOT_VIEW_MAX_ACCEL)
    { deltaAngle[YAW] = BOBOT_VIEW_MAX_ACCEL; }
    else if (deltaAngle[YAW] < -BOBOT_VIEW_MAX_ACCEL)
    { deltaAngle[YAW] =-BOBOT_VIEW_MAX_ACCEL; }
    //on multiplie par une constante (FTBO)
    deltaAngle[PITCH] *= LookFTBO[bobotAI->skill];
    deltaAngle[YAW] *= LookFTBO[bobotAI->skill];
    deltaAngle[ROLL] *= LookFTBO[bobotAI->skill];
    VectorAdd(bobotAI->vitesse_angle, deltaAngle,bobotAI->vitesse_angle) ;
    if(bobotAI->vitesse_angle[PITCH]> BOBOT_VIEW_MAX_SPEED)
    { bobotAI->vitesse_angle[PITCH]= BOBOT_VIEW_MAX_SPEED; }
    else if (bobotAI->vitesse_angle[PITCH]< -BOBOT_VIEW_MAX_SPEED)
    { bobotAI->vitesse_angle[PITCH]= -BOBOT_VIEW_MAX_SPEED; }
    if(bobotAI->vitesse_angle[YAW]> BOBOT_VIEW_MAX_SPEED)
    { bobotAI->vitesse_angle[YAW]= BOBOT_VIEW_MAX_SPEED; }
    else if (bobotAI->vitesse_angle[YAW]< -BOBOT_VIEW_MAX_SPEED)
    { bobotAI->vitesse_angle[YAW]= -BOBOT_VIEW_MAX_SPEED; }
}
/**********************************************************************************************
BOBOT_MOVEMENT_View_Think() : doit etre appelé à chaque frame pour actualiser la vue du bobot
c'est tres simple pour le moment !
***********************************************************************************************/
void BOBOT_MOVEMENT_View_Think(gentity_t *bobot)
{    Sbobot    *bobotAI = &bobots[bobot->s.clientNum];
    float    lookFrein = LookFrein[bobotAI->skill];

    VectorAdd(bobotAI->vitesse_angle,bobot->s.angles,bobot->s.angles);
    bobot->s.angles[PITCH] = AngleMod(bobot->s.angles[PITCH]);
    bobot->s.angles[YAW] = AngleMod(bobot->s.angles[YAW]);
   
    /*    frein pour eviter que la visée oscille toujours autour de la cible */
    bobotAI->vitesse_angle[PITCH]    *= lookFrein;
    bobotAI->vitesse_angle[YAW]        *= lookFrein;
    bobotAI->vitesse_angle[ROLL]    *= lookFrein;
}

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