]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/aim.qc
Merge branch 'master' into terencehill/ft_autorevive_progress
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / aim.qc
index 7af3fab05eef57c376298e302347b6d2bf4ef9bf..21506d07523e406f0a5591d84f4c302668321f15 100644 (file)
@@ -170,14 +170,15 @@ void bot_lagfunc(entity this, float t, float f1, float f2, entity e1, vector v1,
                this.bot_canfire = 1;
 }
 
+// this function should be called after bot_aim so the aim is reset the next frame
 void bot_aim_reset(entity this)
 {
+       this.bot_mouseaim = this.v_angle;
+       this.bot_olddesiredang = this.v_angle;
        this.bot_aimdir_executed = true;
        this.bot_badaimtime = 0;
        this.bot_aimthinktime = time;
        this.bot_prevaimtime = time;
-       this.bot_mouseaim = this.v_angle;
-       this.bot_olddesiredang = this.v_angle;
        this.bot_1st_order_aimfilter = '0 0 0';
        this.bot_2nd_order_aimfilter = '0 0 0';
        this.bot_3th_order_aimfilter = '0 0 0';
@@ -198,9 +199,18 @@ void bot_aimdir(entity this, vector v, float maxfiredeviation)
        this.v_angle_y = this.v_angle.y - floor(this.v_angle.y / 360) * 360;
        this.v_angle_z = 0;
 
+       // make work bot_aim_reset even if called before this function
+       if (this.bot_prevaimtime == time)
+               return;
+
        // invalid aim dir (can happen when bot overlaps target)
        if(!v) return;
 
+       float skill_save = skill;
+       // allow turning in a more natural way when bot is walking
+       if (!this.bot_aimtarg)
+               skill = max(4, skill);
+
        // get the desired angles to aim at
        //dprint(" at:", vtos(v));
        v = normalize(v);
@@ -301,10 +311,9 @@ void bot_aimdir(entity this, vector v, float maxfiredeviation)
        blendrate = autocvar_bot_ai_aimskill_blendrate;
        r = max(fixedrate, blendrate);
        //this.v_angle = this.v_angle + diffang * bound(frametime, r * frametime * (2+skill*skill*0.05-random()*0.05*(10-skill)), 1);
-       this.v_angle = this.v_angle + diffang * bound(delta_t, r * delta_t * (2 + ((skill + this.bot_mouseskill) ** 3) * 0.005 - random()), 1);
-       this.v_angle = this.v_angle * bound(0,autocvar_bot_ai_aimskill_mouse,1) + desiredang * bound(0,(1-autocvar_bot_ai_aimskill_mouse),1);
-       //this.v_angle = this.v_angle + diffang * bound(0, r * frametime * (skill * 0.5 + 2), 1);
-       //this.v_angle = this.v_angle + diffang * (1/ blendrate);
+       r = bound(delta_t, r * delta_t * (2 + ((skill + this.bot_mouseskill) ** 3) * 0.005 - random()), 1);
+       this.v_angle += diffang * (r + (1 - r) * bound(0, 1 - autocvar_bot_ai_aimskill_mouse, 1));
+
        this.v_angle_z = 0;
        this.v_angle_y = this.v_angle.y - floor(this.v_angle.y / 360) * 360;
        //dprint(" turn:", vtos(this.v_angle));
@@ -322,10 +331,21 @@ void bot_aimdir(entity this, vector v, float maxfiredeviation)
        //if (diffang_y >= 180)
        //      diffang_y = diffang_y - 360;
 
+       skill = skill_save;
+
        //dprint("e ", vtos(diffang), " < ", ftos(maxfiredeviation), "\n");
 
+       if (maxfiredeviation <= 0)
+               return;
+
+       if (!autocvar_bot_ai_aimskill_firetolerance)
+       {
+               this.bot_firetimer = time + 0.2;
+               return;
+       }
+
        // decide whether to fire this time
-       if (maxfiredeviation != 0 && v * shotdir > cos(maxfiredeviation * DEG2RAD))
+       if (v * shotdir > cos(maxfiredeviation * DEG2RAD))
        {
                traceline(shotorg, shotorg + shotdir * 1000, false, NULL);
                if (vdist(trace_endpos - shotorg, <, 500 + 500 * bound(0, skill + this.bot_aggresskill, 10))
@@ -336,8 +356,6 @@ void bot_aimdir(entity this, vector v, float maxfiredeviation)
        }
        //dprint(ftos(maxfiredeviation),"\n");
        //dprint(" diff:", vtos(diffang), "\n");
-
-       //return this.bot_canfire && (time < this.bot_firetimer);
 }
 
 vector bot_shotlead(vector targorigin, vector targvelocity, float shotspeed, float shotdelay)