From: Mario Date: Tue, 12 Jun 2018 05:24:03 +0000 (+1000) Subject: Add a function for turrets to tell how close they are to their target X-Git-Tag: xonotic-v0.8.5~2064 X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=6477b06739f4fa5df9343f635dc3a90b4aa08f67 Add a function for turrets to tell how close they are to their target --- diff --git a/qcsrc/common/turrets/sv_turrets.qc b/qcsrc/common/turrets/sv_turrets.qc index 2a7c41c98c..06f8bab9c9 100644 --- a/qcsrc/common/turrets/sv_turrets.qc +++ b/qcsrc/common/turrets/sv_turrets.qc @@ -1239,6 +1239,12 @@ void turret_initparams(entity tur) #undef TRY } +bool turret_closetotarget(entity this, vector targ) +{ + vector path_extra_size = '64 64 64'; + return boxesoverlap(targ - path_extra_size, targ + path_extra_size, this.absmin - path_extra_size, this.absmax + path_extra_size); +} + void turret_findtarget(entity this) { entity e = find(NULL, classname, "turret_manager"); diff --git a/qcsrc/common/turrets/sv_turrets.qh b/qcsrc/common/turrets/sv_turrets.qh index 41a7bd962d..deee313ab1 100644 --- a/qcsrc/common/turrets/sv_turrets.qh +++ b/qcsrc/common/turrets/sv_turrets.qh @@ -89,6 +89,9 @@ void turrets_setframe(entity this, float _frame, float client_only); bool turret_initialize(entity this, Turret tur); +// returns true when box overlaps with a given location +bool turret_closetotarget(entity this, vector targ); + /// Function to use for target evaluation. usualy turret_targetscore_generic .float(entity _turret, entity _target) turret_score_target; diff --git a/qcsrc/common/turrets/turret/ewheel.qc b/qcsrc/common/turrets/turret/ewheel.qc index 5625d23fc9..9a9001c42d 100644 --- a/qcsrc/common/turrets/turret/ewheel.qc +++ b/qcsrc/common/turrets/turret/ewheel.qc @@ -17,7 +17,7 @@ const int ewheel_anim_bck_fast = 4; void ewheel_move_path(entity this) { // Are we close enough to a path node to switch to the next? - if(vdist(this.origin - this.pathcurrent.origin, <, 64)) + if(turret_closetotarget(this, this.pathcurrent.origin)) { #ifdef EWHEEL_FANCYPATH if (this.pathcurrent.path_next == NULL) @@ -49,7 +49,6 @@ void ewheel_move_path(entity this) if (this.pathcurrent) { - this.moveto = this.pathcurrent.origin; this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95); diff --git a/qcsrc/common/turrets/turret/walker.qc b/qcsrc/common/turrets/turret/walker.qc index 8cf795a938..499e64d0cc 100644 --- a/qcsrc/common/turrets/turret/walker.qc +++ b/qcsrc/common/turrets/turret/walker.qc @@ -281,7 +281,8 @@ void walker_move_path(entity this) { #ifdef WALKER_FANCYPATHING // Are we close enougth to a path node to switch to the next? - if(vdist(this.origin - this.pathcurrent.origin, <, 64)) + if(turret_closetotarget(this, this.pathcurrent.origin)) + { if (this.pathcurrent.path_next == NULL) { // Path endpoint reached @@ -304,13 +305,14 @@ void walker_move_path(entity this) } else this.pathcurrent = this.pathcurrent.path_next; + } this.moveto = this.pathcurrent.origin; this.steerto = steerlib_attract2(this, this.moveto,0.5,500,0.95); walker_move_to(this, this.moveto, 0); #else - if(vdist(this.origin - this.pathcurrent.origin, <, 64)) + if(turret_closetotarget(this, this.pathcurrent.origin)) this.pathcurrent = this.pathcurrent.enemy; if(!this.pathcurrent)