}
// Generic damage handling
-void turret_hide()
-{SELFPARAM();
+void turret_hide(entity this)
+{
self.effects |= EF_NODRAW;
self.nextthink = time + self.respawntime - 0.2;
- self.think = turret_respawn;
+ setthink(self, turret_respawn);
}
-void turret_die()
-{SELFPARAM();
+void turret_die(entity this)
+{
self.deadflag = DEAD_DEAD;
self.tur_head.deadflag = self.deadflag;
// Setup respawn
self.SendFlags |= TNSF_STATUS;
self.nextthink = time + 0.2;
- self.think = turret_hide;
+ setthink(self, turret_hide);
tur.tr_death(tur, self);
}
this.tur_head.event_damage = func_null;
this.takedamage = DAMAGE_NO;
this.nextthink = time;
- this.think = turret_die;
+ setthink(this, turret_die);
}
this.SendFlags |= TNSF_STATUS;
}
-void() turret_think;
-void turret_respawn()
-{SELFPARAM();
+void turret_think(entity this);
+void turret_respawn(entity this)
+{
// Make sure all parts belong to the same team since
// this function doubles as "teamchange" function.
self.tur_head.team = self.team;
self.ammo = self.ammo_max;
self.nextthink = time + self.ticrate;
- self.think = turret_think;
+ setthink(self, turret_think);
self.SendFlags = TNSF_FULL_UPDATE;
}
}
-void turret_projectile_explode()
-{SELFPARAM();
+void turret_projectile_explode(entity this)
+{
self.takedamage = DAMAGE_NO;
self.event_damage = func_null;
remove(self);
}
-void turret_projectile_touch()
+void turret_projectile_touch(entity this)
{
- PROJECTILE_TOUCH;
- turret_projectile_explode();
+ PROJECTILE_TOUCH(this);
+ turret_projectile_explode(this);
}
void turret_projectile_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector vforce)
this.health -= damage;
//this.realowner = attacker; // Dont change realowner, it does not make much sense for turrets
if(this.health <= 0)
- WITH(entity, self, this, W_PrepareExplosionByDamage(this.owner, turret_projectile_explode));
+ W_PrepareExplosionByDamage(this, this.owner, turret_projectile_explode);
}
-entity turret_projectile(string _snd, float _size, float _health, float _death, float _proj_type, float _cull, float _cli_anim)
+entity turret_projectile(Sound _snd, float _size, float _health, float _death, float _proj_type, float _cull, float _cli_anim)
{SELFPARAM();
+ TC(Sound, _snd);
entity proj;
- _sound (self, CH_WEAPON_A, _snd, VOL_BASE, ATTEN_NORM);
+ sound (self, CH_WEAPON_A, _snd, VOL_BASE, ATTEN_NORM);
proj = spawn ();
setorigin(proj, self.tur_shotorg);
setsize(proj, '-0.5 -0.5 -0.5' * _size, '0.5 0.5 0.5' * _size);
proj.realowner = self;
proj.bot_dodge = true;
proj.bot_dodgerating = self.shot_dmg;
- proj.think = turret_projectile_explode;
- proj.touch = turret_projectile_touch;
+ setthink(proj, turret_projectile_explode);
+ settouch(proj, turret_projectile_touch);
proj.nextthink = time + 9;
proj.movetype = MOVETYPE_FLYMISSILE;
proj.velocity = normalize(self.tur_shotdir_updated + randomvec() * self.shot_spread) * self.shot_speed;
** and updated aim<->predict impact distance.
**/
void turret_do_updates(entity t_turret)
-{SELFPARAM();
- vector enemy_pos;
-
- setself(t_turret);
-
- enemy_pos = real_origin(self.enemy);
+{
+ vector enemy_pos = real_origin(t_turret.enemy);
- turret_tag_fire_update();
+ WITHSELF(t_turret, turret_tag_fire_update());
- self.tur_shotdir_updated = v_forward;
- self.tur_dist_enemy = vlen(self.tur_shotorg - enemy_pos);
- self.tur_dist_aimpos = vlen(self.tur_shotorg - self.tur_aimpos);
+ t_turret.tur_shotdir_updated = v_forward;
+ t_turret.tur_dist_enemy = vlen(t_turret.tur_shotorg - enemy_pos);
+ t_turret.tur_dist_aimpos = vlen(t_turret.tur_shotorg - t_turret.tur_aimpos);
- /*if((self.firecheck_flags & TFL_FIRECHECK_VERIFIED) && (self.enemy))
+ /*if((t_turret.firecheck_flags & TFL_FIRECHECK_VERIFIED) && (t_turret.enemy))
{
- oldpos = self.enemy.origin;
- setorigin(self.enemy, self.tur_aimpos);
- tracebox(self.tur_shotorg, '-1 -1 -1', '1 1 1', self.tur_shotorg + (self.tur_shotdir_updated * self.tur_dist_aimpos), MOVE_NORMAL,self);
- setorigin(self.enemy, oldpos);
+ oldpos = t_turret.enemy.origin;
+ setorigin(t_turret.enemy, t_turret.tur_aimpos);
+ tracebox(t_turret.tur_shotorg, '-1 -1 -1', '1 1 1', t_turret.tur_shotorg + (t_turret.tur_shotdir_updated * t_turret.tur_dist_aimpos), MOVE_NORMAL,t_turret);
+ setorigin(t_turret.enemy, oldpos);
- if(trace_ent == self.enemy)
- self.tur_dist_impact_to_aimpos = 0;
+ if(trace_ent == t_turret.enemy)
+ t_turret.tur_dist_impact_to_aimpos = 0;
else
- self.tur_dist_impact_to_aimpos = vlen(trace_endpos - self.tur_aimpos);
+ t_turret.tur_dist_impact_to_aimpos = vlen(trace_endpos - t_turret.tur_aimpos);
}
else*/
- tracebox(self.tur_shotorg, '-1 -1 -1','1 1 1', self.tur_shotorg + (self.tur_shotdir_updated * self.tur_dist_aimpos), MOVE_NORMAL,self);
-
- self.tur_dist_impact_to_aimpos = vlen(trace_endpos - self.tur_aimpos) - (vlen(self.enemy.maxs - self.enemy.mins) * 0.5);
- self.tur_impactent = trace_ent;
- self.tur_impacttime = vlen(self.tur_shotorg - trace_endpos) / self.shot_speed;
+ tracebox(t_turret.tur_shotorg, '-1 -1 -1','1 1 1', t_turret.tur_shotorg + (t_turret.tur_shotdir_updated * t_turret.tur_dist_aimpos), MOVE_NORMAL,t_turret);
- setself(this);
+ t_turret.tur_dist_impact_to_aimpos = vlen(trace_endpos - t_turret.tur_aimpos) - (vlen(t_turret.enemy.maxs - t_turret.enemy.mins) * 0.5);
+ t_turret.tur_impactent = trace_ent;
+ t_turret.tur_impacttime = vlen(t_turret.tur_shotorg - trace_endpos) / t_turret.shot_speed;
}
/**
return -1;
if(MUTATOR_CALLHOOK(TurretValidateTarget, e_turret, e_target, validate_flags))
- return ret_float;
+ return M_ARGV(3, float);
if (validate_flags & TFL_TARGETSELECT_NO)
return -4;
traceline(e_turret.origin + '0 0 16', v_tmp, 0, e_turret);
- if (e_turret.aim_firetolerance_dist < vlen(v_tmp - trace_endpos))
+ if(vdist(v_tmp - trace_endpos, >, e_turret.aim_firetolerance_dist))
return -19;
}
return 1;
}
-bool turret_checkfire()
-{SELFPARAM();
- bool ret = false; // dummy
- if(MUTATOR_CALLHOOK(Turret_CheckFire, ret))
- return ret_bool;
+bool turret_checkfire(entity this)
+{
+ if(MUTATOR_CALLHOOK(Turret_CheckFire, this))
+ return M_ARGV(1, bool);
- return self.turret_firecheckfunc();
+ bool ret = false;
+ WITHSELF(this, ret = this.turret_firecheckfunc());
+
+ return ret;
}
void turret_fire()
#endif
}
-void turret_think()
-{SELFPARAM();
+void turret_think(entity this)
+{
self.nextthink = time + self.ticrate;
MUTATOR_CALLHOOK(TurretThink, self);
turret_do_updates(self);
- if (turret_checkfire())
+ if (turret_checkfire(self))
turret_fire();
}
}
turret_do_updates(self);
// Fire?
- if (turret_checkfire())
+ if (turret_checkfire(self))
turret_fire();
}
else
turret_do_updates(self);
// Fire!
- if (turret_checkfire())
+ if (turret_checkfire(self))
turret_fire();
Turret tur = get_turretinfo(self.m_id);
turret_do_updates(self);
// Fire?
- if (turret_checkfire())
+ if (turret_checkfire(self))
turret_fire();
}
When .used a turret switch team to activator.team.
If activator is world, the turret go inactive.
*/
-void turret_use()
-{SELFPARAM();
- LOG_TRACE("Turret ",self.netname, " used by ", activator.classname, "\n");
+void turret_use(entity this, entity actor, entity trigger)
+{
+ LOG_TRACE("Turret ",this.netname, " used by ", actor.classname, "\n");
- self.team = activator.team;
+ this.team = actor.team;
- if(self.team == 0)
- self.active = ACTIVE_NOT;
+ if(this.team == 0)
+ this.active = ACTIVE_NOT;
else
- self.active = ACTIVE_ACTIVE;
+ this.active = ACTIVE_ACTIVE;
}
void turret_link()
{SELFPARAM();
Net_LinkEntity(self, true, 0, turret_send);
- self.think = turret_think;
+ setthink(self, turret_think);
self.nextthink = time;
self.tur_head.effects = EF_NODRAW;
}
-void turrets_manager_think()
+void turrets_manager_think(entity this)
{
- SELFPARAM();
this.nextthink = time + 1;
if (autocvar_g_turrets_reloadcvars == 1)
{
- FOREACH_ENTITY(IS_TURRET(it), LAMBDA(
+ FOREACH_ENTITY(IS_TURRET(it), {
load_unit_settings(it, true);
Turret tur = get_turretinfo(it.m_id);
tur.tr_think(tur, it);
- ));
+ });
cvar_set("g_turrets_reloadcvars", "0");
}
}
if(!e)
{
e = new(turret_manager);
- e.think = turrets_manager_think;
+ setthink(e, turrets_manager_think);
e.nextthink = time + 2;
}
#ifdef TURRET_DEBUG
self.tur_debug_start = self.nextthink;
- while (vlen(self.tur_debug_rvec) < 2)
+ while(vdist(self.tur_debug_rvec, <, 2))
self.tur_debug_rvec = randomvec() * 4;
self.tur_debug_rvec_x = fabs(self.tur_debug_rvec_x);
#endif
turret_link();
- turret_respawn();
+ turret_respawn(self);
turret_tag_fire_update();
tur.tr_setup(tur, self);