Bot AI: fix bots starting to fire when they aren't aiming at the enemy yet
authorterencehill <piuntn@gmail.com>
Wed, 21 Nov 2018 22:55:34 +0000 (23:55 +0100)
committerterencehill <piuntn@gmail.com>
Thu, 22 Nov 2018 14:56:04 +0000 (15:56 +0100)
qcsrc/server/bot/default/aim.qc
qcsrc/server/bot/default/havocbot/havocbot.qc

index e7a2e6a7bef1d1ee2c3b4ea80be3fb13516bcb1e..f30c5e58ea4dacaa878f2911d2debdd68ec8cc3b 100644 (file)
@@ -309,10 +309,15 @@ void bot_aimdir(entity this, vector v, float maxfiredeviation)
        //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");
 
@@ -390,6 +395,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;
index 35b2cc4e28bcda0098b861056f22f0c50055031d..bed2919051e70ba6b63a8d2b4c105d5434a62390 100644 (file)
@@ -137,7 +137,7 @@ void havocbot_ai(entity this)
                else
                {
                        if(IS_PLAYER(this.bot_aimtarg))
-                               bot_aimdir(this, this.bot_aimtarg.origin + this.bot_aimtarg.view_ofs - this.origin - this.view_ofs , -1);
+                               bot_aimdir(this, this.bot_aimtarg.origin + this.bot_aimtarg.view_ofs - this.origin - this.view_ofs, 0);
                }
        }
        else if (this.goalcurrent)
@@ -153,7 +153,7 @@ void havocbot_ai(entity this)
                vector dir = get_closer_dest(this.goalcurrent, this.origin);
                dir -= this.origin + this.view_ofs;
                dir.z = 0;
-               bot_aimdir(this, dir, -1);
+               bot_aimdir(this, dir, 0);
        }
 
        // if the bot is not attacking, consider reloading weapons
@@ -1203,9 +1203,9 @@ void havocbot_movetogoal(entity this)
        if (!this.bot_aimdir_executed)
        {
                if (time < this.bot_stop_moving_timeout)
-                       bot_aimdir(this, normalize(this.goalcurrent.origin - this.origin), -1);
+                       bot_aimdir(this, normalize(this.goalcurrent.origin - this.origin), 0);
                else
-                       bot_aimdir(this, dir, -1);
+                       bot_aimdir(this, dir, 0);
        }
 
        if (!ladder_zdir)
@@ -1578,7 +1578,7 @@ float havocbot_moveto(entity this, vector pos)
                        vector dir = get_closer_dest(this.goalcurrent, this.origin);
                        dir -= this.origin + this.view_ofs;
                        dir.z = 0;
-                       bot_aimdir(this, dir, -1);
+                       bot_aimdir(this, dir, 0);
                }
 
                if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_REACHED)