]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/aim.qc
Bot AI: reset aim when bots respawn
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / aim.qc
index e7a2e6a7bef1d1ee2c3b4ea80be3fb13516bcb1e..ae133b4ed0382f2c77ff0be9b0e3a27b60fa09d1 100644 (file)
@@ -170,6 +170,23 @@ void bot_lagfunc(entity this, float t, float f1, float f2, entity e1, vector v1,
                this.bot_canfire = 1;
 }
 
                this.bot_canfire = 1;
 }
 
+void bot_aim_reset(entity this)
+{
+       this.bot_aimdir_executed = true;
+       makevectors(this.v_angle);
+       this.bot_badaimtime = 0;
+       this.bot_aimthinktime = time;
+       this.bot_prevaimtime = time;
+       this.bot_mouseaim = v_forward;
+       this.bot_olddesiredang = v_forward;
+       this.bot_1st_order_aimfilter = '0 0 0';
+       this.bot_2nd_order_aimfilter = '0 0 0';
+       this.bot_3th_order_aimfilter = '0 0 0';
+       this.bot_4th_order_aimfilter = '0 0 0';
+       this.bot_5th_order_aimfilter = '0 0 0';
+       this.bot_firetimer = 0;
+}
+
 void bot_aimdir(entity this, vector v, float maxfiredeviation)
 {
        float dist, delta_t, blend;
 void bot_aimdir(entity this, vector v, float maxfiredeviation)
 {
        float dist, delta_t, blend;
@@ -309,10 +326,15 @@ void bot_aimdir(entity this, vector v, float maxfiredeviation)
        //dprint("e ", vtos(diffang), " < ", ftos(maxfiredeviation), "\n");
 
        // decide whether to fire this time
        //dprint("e ", vtos(diffang), " < ", ftos(maxfiredeviation), "\n");
 
        // decide whether to fire this time
-       if (v * shotdir >= cos(maxfiredeviation * DEG2RAD))
-       if(vdist(trace_endpos-shotorg, <, 500 + 500 * bound(0, skill + this.bot_aggresskill, 10)) || random()*random()>bound(0,(skill+this.bot_aggresskill)*0.05,1))
-               this.bot_firetimer = time + bound(0.1, 0.5-(skill+this.bot_aggresskill)*0.05, 0.5);
-       //traceline(shotorg,shotorg+shotdir*1000,false,NULL);
+       if (maxfiredeviation != 0 && 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))
+                       || random() * random() > bound(0, (skill + this.bot_aggresskill) * 0.05, 1))
+               {
+                       this.bot_firetimer = time + bound(0.1, 0.5 - (skill + this.bot_aggresskill) * 0.05, 0.5);
+               }
+       }
        //dprint(ftos(maxfiredeviation),"\n");
        //dprint(" diff:", vtos(diffang), "\n");
 
        //dprint(ftos(maxfiredeviation),"\n");
        //dprint(" diff:", vtos(diffang), "\n");
 
@@ -390,6 +412,12 @@ bool bot_aim(entity this, .entity weaponentity, float shotspeed, float shotspeed
                }
        }
 
                }
        }
 
+       if (time > this.bot_firetimer)
+       {
+               this.dphitcontentsmask = hf;
+               return false;
+       }
+
        //if (r > maxshottime * shotspeed)
        //      return false;
        this.dphitcontentsmask = hf;
        //if (r > maxshottime * shotspeed)
        //      return false;
        this.dphitcontentsmask = hf;