X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fserver%2Fbot%2Fdefault%2Faim.qc;h=ae133b4ed0382f2c77ff0be9b0e3a27b60fa09d1;hp=0b813dae1fd5b3be51a7828a22f5c86efefef404;hb=0e4f674ee0300e74cc11de82564e2a03710822cd;hpb=30648cd6167b20ad5924c03cd39efff9ef5b62df diff --git a/qcsrc/server/bot/default/aim.qc b/qcsrc/server/bot/default/aim.qc index 0b813dae1f..ae133b4ed0 100644 --- a/qcsrc/server/bot/default/aim.qc +++ b/qcsrc/server/bot/default/aim.qc @@ -1,5 +1,7 @@ #include "aim.qh" +#include + #include "cvars.qh" #include "bot.qh" @@ -9,7 +11,7 @@ #include "../../weapons/weaponsystem.qh" -#include "../../mutators/_mod.qh" +#include // traces multiple trajectories to find one that will impact the target // 'end' vector is the place it aims for, @@ -93,11 +95,11 @@ float findtrajectorywithleading(vector org, vector m1, vector m2, entity targ, f void lag_update(entity this) { - if (this.lag1_time) if (time > this.lag1_time) {this.lag_func(this, this.lag1_time, this.lag1_float1, this.lag1_float2, this.lag1_entity1, this.lag1_vec1, this.lag1_vec2, this.lag1_vec3, this.lag1_vec4);this.lag1_time = 0;} - if (this.lag2_time) if (time > this.lag2_time) {this.lag_func(this, this.lag2_time, this.lag2_float1, this.lag2_float2, this.lag2_entity1, this.lag2_vec1, this.lag2_vec2, this.lag2_vec3, this.lag2_vec4);this.lag2_time = 0;} - if (this.lag3_time) if (time > this.lag3_time) {this.lag_func(this, this.lag3_time, this.lag3_float1, this.lag3_float2, this.lag3_entity1, this.lag3_vec1, this.lag3_vec2, this.lag3_vec3, this.lag3_vec4);this.lag3_time = 0;} - if (this.lag4_time) if (time > this.lag4_time) {this.lag_func(this, this.lag4_time, this.lag4_float1, this.lag4_float2, this.lag4_entity1, this.lag4_vec1, this.lag4_vec2, this.lag4_vec3, this.lag4_vec4);this.lag4_time = 0;} - if (this.lag5_time) if (time > this.lag5_time) {this.lag_func(this, this.lag5_time, this.lag5_float1, this.lag5_float2, this.lag5_entity1, this.lag5_vec1, this.lag5_vec2, this.lag5_vec3, this.lag5_vec4);this.lag5_time = 0;} + if (this.lag1_time && time > this.lag1_time) { this.lag_func(this, this.lag1_time, this.lag1_float1, this.lag1_float2, this.lag1_entity1, this.lag1_vec1, this.lag1_vec2, this.lag1_vec3, this.lag1_vec4); this.lag1_time = 0; } + if (this.lag2_time && time > this.lag2_time) { this.lag_func(this, this.lag2_time, this.lag2_float1, this.lag2_float2, this.lag2_entity1, this.lag2_vec1, this.lag2_vec2, this.lag2_vec3, this.lag2_vec4); this.lag2_time = 0; } + if (this.lag3_time && time > this.lag3_time) { this.lag_func(this, this.lag3_time, this.lag3_float1, this.lag3_float2, this.lag3_entity1, this.lag3_vec1, this.lag3_vec2, this.lag3_vec3, this.lag3_vec4); this.lag3_time = 0; } + if (this.lag4_time && time > this.lag4_time) { this.lag_func(this, this.lag4_time, this.lag4_float1, this.lag4_float2, this.lag4_entity1, this.lag4_vec1, this.lag4_vec2, this.lag4_vec3, this.lag4_vec4); this.lag4_time = 0; } + if (this.lag5_time && time > this.lag5_time) { this.lag_func(this, this.lag5_time, this.lag5_float1, this.lag5_float2, this.lag5_entity1, this.lag5_vec1, this.lag5_vec2, this.lag5_vec3, this.lag5_vec4); this.lag5_time = 0; } } float lag_additem(entity this, float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4) @@ -130,18 +132,19 @@ bool bot_shouldattack(entity this, entity targ) if(targ.team==0) return false; } - else if(bot_ignore_bots) - if(IS_BOT_CLIENT(targ)) - return false; + else if (autocvar_bot_ignore_bots && IS_BOT_CLIENT(targ)) + return false; if (!targ.takedamage) return false; if (IS_DEAD(targ)) return false; - if (PHYS_INPUT_BUTTON_CHAT(targ)) + if (PHYS_INPUT_BUTTON_CHAT(targ) && !autocvar_bot_typefrag) return false; if(targ.flags & FL_NOTARGET) return false; + if(targ.alpha <= 0.1 && targ.alpha != 0) + return false; // invisible via alpha if(MUTATOR_CALLHOOK(BotShouldAttack, this, targ)) return false; @@ -151,13 +154,8 @@ bool bot_shouldattack(entity this, entity targ) void bot_lagfunc(entity this, float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4) { - if(this.flags & FL_INWATER) - { - this.bot_aimtarg = NULL; - return; - } this.bot_aimtarg = e1; - this.bot_aimlatency = this.ping; // FIXME? Shouldn't this be in the lag item? + this.bot_aimlatency = CS(this).ping; // FIXME? Shouldn't this be in the lag item? //this.bot_aimorigin = v1; //this.bot_aimvelocity = v2; this.bot_aimtargorigin = v3; @@ -172,16 +170,38 @@ void bot_lagfunc(entity this, float t, float f1, float f2, entity e1, vector v1, this.bot_canfire = 1; } -float bot_aimdir(entity this, vector v, float maxfiredeviation) +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; vector desiredang, diffang; + this.bot_aimdir_executed = true; + //dprint("aim ", this.netname, ": old:", vtos(this.v_angle)); // make sure v_angle is sane first this.v_angle_y = this.v_angle.y - floor(this.v_angle.y / 360) * 360; this.v_angle_z = 0; + // invalid aim dir (can happen when bot overlaps target) + if(!v) return; + // get the desired angles to aim at //dprint(" at:", vtos(v)); v = normalize(v); @@ -239,6 +259,7 @@ float bot_aimdir(entity this, vector v, float maxfiredeviation) + this.bot_4th_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_4th + this.bot_5th_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_5th ); + desiredang.x = bound(-90, desiredang.x, 90); // calculate turn angles diffang = desiredang - this.bot_mouseaim; @@ -305,14 +326,19 @@ float bot_aimdir(entity this, vector v, float maxfiredeviation) //dprint("e ", vtos(diffang), " < ", ftos(maxfiredeviation), "\n"); // decide whether to fire this time - if ((normalize(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"); - return this.bot_canfire && (time < this.bot_firetimer); + //return this.bot_canfire && (time < this.bot_firetimer); } vector bot_shotlead(vector targorigin, vector targvelocity, float shotspeed, float shotdelay) @@ -323,7 +349,7 @@ vector bot_shotlead(vector targorigin, vector targvelocity, float shotspeed, flo bool bot_aim(entity this, .entity weaponentity, float shotspeed, float shotspeedupward, float maxshottime, bool applygravity) { - float f, r, hf, distanceratio; + float r, hf, distanceratio; vector v; /* eprint(this); @@ -365,11 +391,11 @@ bool bot_aim(entity this, .entity weaponentity, float shotspeed, float shotspeed return false; } - f = bot_aimdir(this, findtrajectory_velocity - shotspeedupward * '0 0 1', r); + bot_aimdir(this, findtrajectory_velocity - shotspeedupward * '0 0 1', r); } else { - f = bot_aimdir(this, v - shotorg, r); + bot_aimdir(this, v - shotorg, r); //dprint("AIM: ");dprint(vtos(this.bot_aimtargorigin));dprint(" + ");dprint(vtos(this.bot_aimtargvelocity));dprint(" * ");dprint(ftos(this.bot_aimlatency + vlen(this.bot_aimtargorigin - shotorg) / shotspeed));dprint(" = ");dprint(vtos(v));dprint(" : aimdir = ");dprint(vtos(normalize(v - shotorg)));dprint(" : ");dprint(vtos(shotdir));dprint("\n"); //traceline(shotorg, shotorg + shotdir * 10000, false, this); //if (trace_ent.takedamage) @@ -386,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;