From: Mario Date: Mon, 26 Dec 2016 13:25:41 +0000 (+1000) Subject: Hunter-Killer: Only loop through entities that can be damaged by contents (not perfec... X-Git-Tag: xonotic-v0.8.2~351 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=04d1db2c54a2a0ce8691879076be77a79567e25b;hp=238697513c0d8799ad5c619c94dc79a34b063d24 Hunter-Killer: Only loop through entities that can be damaged by contents (not perfect coverage, but avoids checking EVERY entity within a 5000 qu radius) --- diff --git a/qcsrc/common/turrets/turret/hk_weapon.qc b/qcsrc/common/turrets/turret/hk_weapon.qc index ddad35d025..5a2f05a483 100644 --- a/qcsrc/common/turrets/turret/hk_weapon.qc +++ b/qcsrc/common/turrets/turret/hk_weapon.qc @@ -44,7 +44,7 @@ METHOD(HunterKillerAttack, wr_think, void(entity thiswep, entity actor, .entity } } -bool hk_is_valid_target(entity this, entity e_target); +bool hk_is_valid_target(entity this, entity proj, entity targ); void turret_hk_missile_think(entity this) { vector vu, vd, vf, vl, vr, ve; // Vector (direction) @@ -53,10 +53,7 @@ void turret_hk_missile_think(entity this) float lt_for; // Length of Trace FORwrad float lt_seek; // Length of Trace SEEK (left, right, up down) float pt_seek; // Pitch of Trace SEEK (How mutch to angele left, right up, down trace towards v_forward) - vector pre_pos; float myspeed; - entity e; - float ad,edist; this.nextthink = time + this.ticrate; @@ -69,19 +66,17 @@ void turret_hk_missile_think(entity this) // Pick the closest valid target. if (!this.enemy) { - e = findradius(this.origin, 5000); - while (e) + // in this case, the lighter check is to validate it first, and check distance if it is valid + IL_EACH(g_damagedbycontents, hk_is_valid_target(this.owner, this, it), { - if (hk_is_valid_target(this, e)) - { - if (!this.enemy) - this.enemy = e; - else - if (vlen2(this.origin - e.origin) < vlen2(this.origin - this.enemy.origin)) - this.enemy = e; - } - e = e.chain; - } + if(vdist(it.origin, >, 5000)) + continue; + + if(!this.enemy) + this.enemy = it; + else if(vlen2(this.origin - it.origin) < vlen2(this.origin - this.enemy.origin)) + this.enemy = it; + }); } this.angles = vectoangles(this.velocity); @@ -91,16 +86,15 @@ void turret_hk_missile_think(entity this) if (this.enemy) { - edist = vlen(this.origin - this.enemy.origin); // Close enougth to do decent damage? - if ( edist <= (this.owner.shot_radius * 0.25) ) + if(vdist(this.origin - this.enemy.origin, <=, (this.owner.shot_radius * 0.25))) { turret_projectile_explode(this); return; } // Get data on enemy position - pre_pos = this.enemy.origin + + vector pre_pos = this.enemy.origin + this.enemy.velocity * min((vlen(this.enemy.origin - this.origin) / vlen(this.velocity)),0.5); @@ -111,12 +105,11 @@ void turret_hk_missile_think(entity this) } else { - edist = 0; - ve = '0 0 0'; + ve = '0 0 0'; fe = 0; } - if ((fe != 1) || (this.enemy == NULL) || (edist > 1000)) + if ((fe != 1) || (this.enemy == NULL) || vdist(this.origin - this.enemy.origin, >, 1000)) { myspeed = vlen(this.velocity); @@ -129,7 +122,7 @@ void turret_hk_missile_think(entity this) ff = trace_fraction; // Find angular offset - ad = vlen(vectoangles(normalize(this.enemy.origin - this.origin)) - this.angles); + float ad = vlen(vectoangles(normalize(this.enemy.origin - this.origin)) - this.angles); // To close to something, Slow down! if ( ((ff < 0.7) || (ad > 4)) && (myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) ) @@ -224,7 +217,7 @@ void turret_hk_missile_think(entity this) #ifdef TURRET_DEBUG_HK //if(this.atime < time) { - if ((fe <= 0.99)||(edist > 1000)) + if ((fe <= 0.99)||vdist(this.origin - this.enemy.origin, >, 1000)) { te_lightning2(NULL,this.origin, this.origin + vr * lt_seek); te_lightning2(NULL,this.origin, this.origin + vl * lt_seek); @@ -246,35 +239,39 @@ void turret_hk_missile_think(entity this) UpdateCSQCProjectile(this); } -bool hk_is_valid_target(entity this, entity e_target) +bool hk_is_valid_target(entity this, entity proj, entity targ) { - if (e_target == NULL) + if (!targ) + return false; + + // we know for sure pure entities are bad targets + if(is_pure(targ)) return false; // If only this was used more.. - if (e_target.flags & FL_NOTARGET) + if (targ.flags & FL_NOTARGET) return false; // Cant touch this - if ((e_target.takedamage == DAMAGE_NO) || (e_target.health < 0)) + if ((targ.takedamage == DAMAGE_NO) || (targ.health < 0)) return false; // player - if (IS_CLIENT(e_target)) + if (IS_PLAYER(targ)) { - if (this.owner.target_select_playerbias < 0) + if (this.target_select_playerbias < 0) return false; - if (IS_DEAD(e_target)) + if (IS_DEAD(targ)) return false; } // Missile - if ((e_target.flags & FL_PROJECTILE) && (this.owner.target_select_missilebias < 0)) + if ((targ.flags & FL_PROJECTILE) && (this.target_select_missilebias < 0)) return false; // Team check - if ((e_target.team == this.owner.team) || (this.owner.team == e_target.owner.team)) + if ((targ.team == this.team) || (this.team == targ.owner.team)) return false; return true;