}
// 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);
#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)
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);
++turret_count;
_setmodel(this, tur.model);
- setsize(this, tur.mins, tur.maxs);
+ setsize(this, tur.m_mins, tur.m_maxs);
this.m_id = tur.m_id;
this.classname = "turret_main";
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;
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;