X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fturrets%2Fsv_turrets.qc;h=cb69bf0ff12ba7f2ec9c312e0af33002af6b9393;hb=573a45ee4af6014b2465242cbf884453d371b5da;hp=4d598db543a1ba0f006702b26f1f31119590eb80;hpb=63ab06764e6e0a20481ab406863eb7bca32cb669;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/turrets/sv_turrets.qc b/qcsrc/common/turrets/sv_turrets.qc index 4d598db54..cb69bf0ff 100644 --- a/qcsrc/common/turrets/sv_turrets.qc +++ b/qcsrc/common/turrets/sv_turrets.qc @@ -789,7 +789,7 @@ float turret_validate_target(entity e_turret, entity e_target, float validate_fl } // Can we even aim this thing? - tvt_thadv = angleofs3(e_turret.tur_head.origin, e_turret.angles + e_turret.tur_head.angles, e_target); + tvt_thadv = angleofs3(e_turret.tur_head.origin, e_turret.angles + e_turret.tur_head.angles, e_target.origin); tvt_tadv = shortangle_vxy(angleofs(e_turret, e_target), e_turret.angles); tvt_thadf = vlen(tvt_thadv); tvt_tadf = vlen(tvt_tadv); @@ -1245,6 +1245,30 @@ void turret_initparams(entity tur) #undef TRY } +void turret_findtarget(entity this) +{ + entity e = find(NULL, classname, "turret_manager"); + if(!e) + { + e = new(turret_manager); + setthink(e, turrets_manager_think); + e.nextthink = time + 2; + } + + entity targ = find(NULL, targetname, this.target); + if(targ.classname == "turret_checkpoint") + return; // turrets don't defend checkpoints? + + if (!targ) + { + this.target = ""; + LOG_TRACE("Turret has invalid defendpoint!"); + } + + this.tur_defend = targ; + this.idle_aim = this.tur_head.angles + angleofs(this.tur_head, targ); +} + bool turret_initialize(entity this, Turret tur) { if(!autocvar_g_turrets) @@ -1260,14 +1284,6 @@ bool turret_initialize(entity this, Turret tur) IL_PUSH(g_bot_targets, this); } - entity e = find(NULL, classname, "turret_manager"); - if(!e) - { - e = new(turret_manager); - setthink(e, turrets_manager_think); - e.nextthink = time + 2; - } - if(!(this.spawnflags & TSF_SUSPENDED)) droptofloor(this); @@ -1341,6 +1357,7 @@ bool turret_initialize(entity this, Turret tur) this.takedamage = DAMAGE_AIM; set_movetype(this, MOVETYPE_NOCLIP); this.view_ofs = '0 0 0'; + this.idle_aim = '0 0 0'; this.turret_firecheckfunc = turret_firecheck; this.event_damage = turret_damage; this.use = turret_use; @@ -1363,21 +1380,8 @@ bool turret_initialize(entity this, Turret tur) this.weaponentities[0] = this; // lol - if(!this.tur_defend) - if(this.target != "") - { - this.tur_defend = find(NULL, targetname, this.target); - if (this.tur_defend == NULL) - { - this.target = ""; - LOG_TRACE("Turret has invalid defendpoint!"); - } - } - - if (this.tur_defend) - this.idle_aim = this.tur_head.angles + angleofs(this.tur_head, this.tur_defend); - else - this.idle_aim = '0 0 0'; + if(!this.tur_defend && this.target != "") + InitializeEntity(this, turret_findtarget, INITPRIO_FINDTARGET); #ifdef TURRET_DEBUG this.tur_debug_start = this.nextthink;