From: terencehill Date: Fri, 19 Aug 2022 17:09:10 +0000 (+0200) Subject: Bot AI: fix bots sometimes firing in the opposite direction if bot_ai_aimskill_fireto... X-Git-Tag: xonotic-v0.8.6~322^2~13 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4541e69d50c9d121b5dc6ec7790bfc57552b06bb;p=xonotic%2Fxonotic-data.pk3dir.git Bot AI: fix bots sometimes firing in the opposite direction if bot_ai_aimskill_firetolerance is on. Also avoid an useless makevector call if bot_ai_aimskill_firetolerance is off --- diff --git a/qcsrc/server/bot/default/aim.qc b/qcsrc/server/bot/default/aim.qc index 6b1488bac..a58ec6134 100644 --- a/qcsrc/server/bot/default/aim.qc +++ b/qcsrc/server/bot/default/aim.qc @@ -309,28 +309,12 @@ void bot_aimdir(entity this, vector v, float maxfiredeviation) //this.v_angle = this.v_angle + diffang * bound(frametime, r * frametime * (2+skill*skill*0.05-random()*0.05*(10-skill)), 1); 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)); - makevectors(this.v_angle); - shotorg = this.origin + this.view_ofs; - shotdir = v_forward; - - //dprint(" dir:", vtos(v_forward)); - //te_lightning2(NULL, shotorg, shotorg + shotdir * 100); - - // calculate turn angles again - //diffang = desiredang - this.v_angle; - //diffang_y = diffang_y - floor(diffang_y / 360) * 360; - //if (diffang_y >= 180) - // diffang_y = diffang_y - 360; - skill = skill_save; - //dprint("e ", vtos(diffang), " < ", ftos(maxfiredeviation), "\n"); - if (maxfiredeviation <= 0) return; @@ -340,8 +324,18 @@ void bot_aimdir(entity this, vector v, float maxfiredeviation) return; } + makevectors(this.v_angle); + shotorg = this.origin + this.view_ofs; + shotdir = v_forward; + // decide whether to fire this time - if (v * shotdir > cos(maxfiredeviation * DEG2RAD)) + // v is the calculated trajectory, shotdir is bot view direction + // NOTE: checking if (v * shotdir > cos(maxfiredeviation * DEG2RAD)) would be cheaper + // but it gets evaluated to true even if v and shotdir have nearly opposite direction + vector deviation = vectoangles(v) - vectoangles(shotdir); + while (deviation.x < -180) deviation.x += 360; while (deviation.x > 180) deviation.x -= 360; + while (deviation.y < -180) deviation.y += 360; while (deviation.y > 180) deviation.y -= 360; + if (fabs(deviation.x) < maxfiredeviation && fabs(deviation.y) < maxfiredeviation) { traceline(shotorg, shotorg + shotdir * 1000, false, NULL); if (vdist(trace_endpos - shotorg, <, 500 + 500 * bound(0, skill + this.bot_aggresskill, 10)) @@ -350,8 +344,6 @@ void bot_aimdir(entity this, vector v, float maxfiredeviation) 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"); } vector bot_shotlead(vector targorigin, vector targvelocity, float shotspeed, float shotdelay)