#ifdef SVQC
-#include "../../server/autocvars.qh"
+#include <server/autocvars.qh>
// Generic aiming
-vector turret_aim_generic()
-{SELFPARAM();
+vector turret_aim_generic(entity this)
+{
vector pre_pos, prep;
float distance, impact_time = 0, i, mintime;
- turret_tag_fire_update();
+ turret_tag_fire_update(this);
- if(self.aim_flags & TFL_AIM_SIMPLE)
- return real_origin(self.enemy);
+ if(this.aim_flags & TFL_AIM_SIMPLE)
+ return real_origin(this.enemy);
- mintime = max(self.attack_finished_single - time,0) + sys_frametime;
+ mintime = max(this.attack_finished_single[0] - time,0) + sys_frametime;
// Baseline
- pre_pos = real_origin(self.enemy);
+ pre_pos = real_origin(this.enemy);
// Lead?
- if (self.aim_flags & TFL_AIM_LEAD)
+ if (this.aim_flags & TFL_AIM_LEAD)
{
- if (self.aim_flags & TFL_AIM_SHOTTIMECOMPENSATE) // Need to conpensate for shot traveltime
+ if (this.aim_flags & TFL_AIM_SHOTTIMECOMPENSATE) // Need to conpensate for shot traveltime
{
prep = pre_pos;
- distance = vlen(prep - self.tur_shotorg);
- impact_time = distance / self.shot_speed;
+ distance = vlen(prep - this.tur_shotorg);
+ impact_time = distance / this.shot_speed;
- prep = pre_pos + (self.enemy.velocity * (impact_time + mintime));
+ prep = pre_pos + (this.enemy.velocity * (impact_time + mintime));
- if(self.aim_flags & TFL_AIM_ZPREDICT)
- if(!(self.enemy.flags & FL_ONGROUND))
- if(self.enemy.movetype == MOVETYPE_WALK || self.enemy.movetype == MOVETYPE_TOSS || self.enemy.movetype == MOVETYPE_BOUNCE)
+ if(this.aim_flags & TFL_AIM_ZPREDICT)
+ if(!IS_ONGROUND(this.enemy))
+ if(this.enemy.movetype == MOVETYPE_WALK || this.enemy.movetype == MOVETYPE_TOSS || this.enemy.movetype == MOVETYPE_BOUNCE)
{
float vz;
prep_z = pre_pos_z;
- vz = self.enemy.velocity_z;
+ vz = this.enemy.velocity_z;
for(i = 0; i < impact_time; i += sys_frametime)
{
vz = vz - (autocvar_sv_gravity * sys_frametime);
pre_pos = prep;
}
else
- pre_pos = pre_pos + self.enemy.velocity * mintime;
+ pre_pos = pre_pos + this.enemy.velocity * mintime;
}
- if(self.aim_flags & TFL_AIM_SPLASH)
+ if(this.aim_flags & TFL_AIM_SPLASH)
{
- //tracebox(pre_pos + '0 0 32',self.enemy.mins,self.enemy.maxs,pre_pos -'0 0 64',MOVE_WORLDONLY,self.enemy);
- traceline(pre_pos + '0 0 32',pre_pos -'0 0 64',MOVE_WORLDONLY,self.enemy);
+ //tracebox(pre_pos + '0 0 32',this.enemy.mins,this.enemy.maxs,pre_pos -'0 0 64',MOVE_WORLDONLY,this.enemy);
+ traceline(pre_pos + '0 0 32',pre_pos -'0 0 64',MOVE_WORLDONLY,this.enemy);
if(trace_fraction != 1.0)
pre_pos = trace_endpos;
}
(m_score * _turret.target_select_missilebias) +
(p_score * _turret.target_select_playerbias);
- if(_turret.target_range < vlen(_turret.tur_shotorg - real_origin(_target)))
+ if(vdist((_turret.tur_shotorg - real_origin(_target)), >, _turret.target_range))
{
//dprint("Wtf?\n");
score *= 0.001;
}
// Generic damage handling
-void turret_hide()
-{SELFPARAM();
- self.effects |= EF_NODRAW;
- self.nextthink = time + self.respawntime - 0.2;
- self.think = turret_respawn;
+void turret_hide(entity this)
+{
+ this.effects |= EF_NODRAW;
+ this.nextthink = time + this.respawntime - 0.2;
+ setthink(this, turret_respawn);
}
-void turret_die()
-{SELFPARAM();
- self.deadflag = DEAD_DEAD;
- self.tur_head.deadflag = self.deadflag;
+void turret_die(entity this)
+{
+ this.deadflag = DEAD_DEAD;
+ this.tur_head.deadflag = this.deadflag;
// Unsolidify and hide real parts
- self.solid = SOLID_NOT;
- self.tur_head.solid = self.solid;
+ this.solid = SOLID_NOT;
+ this.tur_head.solid = this.solid;
- self.event_damage = func_null;
- self.takedamage = DAMAGE_NO;
+ this.event_damage = func_null;
+ this.takedamage = DAMAGE_NO;
- self.health = 0;
+ this.health = 0;
// Go boom
- //RadiusDamage (self,self, min(self.ammo,50),min(self.ammo,50) * 0.25,250,world,min(self.ammo,50)*5,DEATH_TURRET,world);
+ //RadiusDamage (this,this, min(this.ammo,50),min(this.ammo,50) * 0.25,250,world,min(this.ammo,50)*5,DEATH_TURRET,world);
- if(self.damage_flags & TFL_DMG_DEATH_NORESPAWN)
+ Turret tur = get_turretinfo(this.m_id);
+ if(this.damage_flags & TFL_DMG_DEATH_NORESPAWN)
{
- TUR_ACTION(self.turretid, TR_DEATH);
+ tur.tr_death(tur, this);
- remove(self.tur_head);
- remove(self);
+ remove(this.tur_head);
+ remove(this);
}
else
{
// Setup respawn
- self.SendFlags |= TNSF_STATUS;
- self.nextthink = time + 0.2;
- self.think = turret_hide;
+ this.SendFlags |= TNSF_STATUS;
+ this.nextthink = time + 0.2;
+ setthink(this, turret_hide);
- TUR_ACTION(self.turretid, TR_DEATH);
+ tur.tr_death(tur, this);
}
}
-void turret_damage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector vforce)
-{SELFPARAM();
+void turret_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector vforce)
+{
// Enough already!
- if(self.deadflag == DEAD_DEAD)
+ if(this.deadflag == DEAD_DEAD)
return;
// Inactive turrets take no damage. (hm..)
- if(!self.active)
+ if(!this.active)
return;
- if(SAME_TEAM(self, attacker))
+ if(SAME_TEAM(this, attacker))
{
if(autocvar_g_friendlyfire)
damage = damage * autocvar_g_friendlyfire;
return;
}
- self.health -= damage;
+ this.health -= damage;
// thorw head slightly off aim when hit?
- if (self.damage_flags & TFL_DMG_HEADSHAKE)
+ if (this.damage_flags & TFL_DMG_HEADSHAKE)
{
- self.tur_head.angles_x = self.tur_head.angles_x + (-0.5 + random()) * damage;
- self.tur_head.angles_y = self.tur_head.angles_y + (-0.5 + random()) * damage;
+ this.tur_head.angles_x = this.tur_head.angles_x + (-0.5 + random()) * damage;
+ this.tur_head.angles_y = this.tur_head.angles_y + (-0.5 + random()) * damage;
- self.SendFlags |= TNSF_ANG;
+ this.SendFlags |= TNSF_ANG;
}
- if (self.turret_flags & TUR_FLAG_MOVE)
- self.velocity = self.velocity + vforce;
+ if (this.turret_flags & TUR_FLAG_MOVE)
+ this.velocity = this.velocity + vforce;
- if (self.health <= 0)
+ if (this.health <= 0)
{
- self.event_damage = func_null;
- self.tur_head.event_damage = func_null;
- self.takedamage = DAMAGE_NO;
- self.nextthink = time;
- self.think = turret_die;
+ this.event_damage = func_null;
+ this.tur_head.event_damage = func_null;
+ this.takedamage = DAMAGE_NO;
+ this.nextthink = time;
+ setthink(this, turret_die);
}
- self.SendFlags |= TNSF_STATUS;
+ 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.effects &= ~EF_NODRAW;
- self.deadflag = DEAD_NO;
- self.effects = EF_LOWPRECISION;
- self.solid = SOLID_BBOX;
- self.takedamage = DAMAGE_AIM;
- self.event_damage = turret_damage;
- self.avelocity = '0 0 0';
- self.tur_head.avelocity = self.avelocity;
- self.tur_head.angles = self.idle_aim;
- self.health = self.max_health;
- self.enemy = world;
- self.volly_counter = self.shot_volly;
- self.ammo = self.ammo_max;
-
- self.nextthink = time + self.ticrate;
- self.think = turret_think;
-
- self.SendFlags = TNSF_FULL_UPDATE;
-
- TUR_ACTION(self.turretid, TR_SETUP);
+ this.tur_head.team = this.team;
+ this.effects &= ~EF_NODRAW;
+ this.deadflag = DEAD_NO;
+ this.effects = EF_LOWPRECISION;
+ this.solid = SOLID_BBOX;
+ this.takedamage = DAMAGE_AIM;
+ this.event_damage = turret_damage;
+ this.avelocity = '0 0 0';
+ this.tur_head.avelocity = this.avelocity;
+ this.tur_head.angles = this.idle_aim;
+ this.health = this.max_health;
+ this.enemy = world;
+ this.volly_counter = this.shot_volly;
+ this.ammo = this.ammo_max;
+
+ this.nextthink = time + this.ticrate;
+ setthink(this, turret_think);
+
+ this.SendFlags = TNSF_FULL_UPDATE;
+
+ Turret tur = get_turretinfo(this.m_id);
+ tur.tr_setup(tur, this);
}
// Main functions
#define cvar_base "g_turrets_unit_"
.float clientframe;
-void turrets_setframe(float _frame, float client_only)
-{SELFPARAM();
- if((client_only ? self.clientframe : self.frame ) != _frame)
+void turrets_setframe(entity this, float _frame, float client_only)
+{
+ if((client_only ? this.clientframe : this.frame ) != _frame)
{
- self.SendFlags |= TNSF_ANIM;
- self.anim_start_time = time;
+ this.SendFlags |= TNSF_ANIM;
+ this.anim_start_time = time;
}
if(client_only)
- self.clientframe = _frame;
+ this.clientframe = _frame;
else
- self.frame = _frame;
+ this.frame = _frame;
}
-float turret_send(entity to, float sf)
-{SELFPARAM();
+bool turret_send(entity this, entity to, float sf)
+{
- WriteByte(MSG_ENTITY, ENT_CLIENT_TURRET);
+ WriteHeader(MSG_ENTITY, ENT_CLIENT_TURRET);
WriteByte(MSG_ENTITY, sf);
if(sf & TNSF_SETUP)
{
- WriteByte(MSG_ENTITY, self.turretid);
+ WriteByte(MSG_ENTITY, this.m_id);
- WriteCoord(MSG_ENTITY, self.origin_x);
- WriteCoord(MSG_ENTITY, self.origin_y);
- WriteCoord(MSG_ENTITY, self.origin_z);
+ WriteCoord(MSG_ENTITY, this.origin_x);
+ WriteCoord(MSG_ENTITY, this.origin_y);
+ WriteCoord(MSG_ENTITY, this.origin_z);
- WriteAngle(MSG_ENTITY, self.angles_x);
- WriteAngle(MSG_ENTITY, self.angles_y);
+ WriteAngle(MSG_ENTITY, this.angles_x);
+ WriteAngle(MSG_ENTITY, this.angles_y);
}
if(sf & TNSF_ANG)
{
- WriteShort(MSG_ENTITY, rint(self.tur_head.angles_x));
- WriteShort(MSG_ENTITY, rint(self.tur_head.angles_y));
+ WriteShort(MSG_ENTITY, rint(this.tur_head.angles_x));
+ WriteShort(MSG_ENTITY, rint(this.tur_head.angles_y));
}
if(sf & TNSF_AVEL)
{
- WriteShort(MSG_ENTITY, rint(self.tur_head.avelocity_x));
- WriteShort(MSG_ENTITY, rint(self.tur_head.avelocity_y));
+ WriteShort(MSG_ENTITY, rint(this.tur_head.avelocity_x));
+ WriteShort(MSG_ENTITY, rint(this.tur_head.avelocity_y));
}
if(sf & TNSF_MOVE)
{
- WriteShort(MSG_ENTITY, rint(self.origin_x));
- WriteShort(MSG_ENTITY, rint(self.origin_y));
- WriteShort(MSG_ENTITY, rint(self.origin_z));
+ WriteShort(MSG_ENTITY, rint(this.origin_x));
+ WriteShort(MSG_ENTITY, rint(this.origin_y));
+ WriteShort(MSG_ENTITY, rint(this.origin_z));
- WriteShort(MSG_ENTITY, rint(self.velocity_x));
- WriteShort(MSG_ENTITY, rint(self.velocity_y));
- WriteShort(MSG_ENTITY, rint(self.velocity_z));
+ WriteShort(MSG_ENTITY, rint(this.velocity_x));
+ WriteShort(MSG_ENTITY, rint(this.velocity_y));
+ WriteShort(MSG_ENTITY, rint(this.velocity_z));
- WriteShort(MSG_ENTITY, rint(self.angles_y));
+ WriteShort(MSG_ENTITY, rint(this.angles_y));
}
if(sf & TNSF_ANIM)
{
- WriteCoord(MSG_ENTITY, self.anim_start_time);
- WriteByte(MSG_ENTITY, self.frame);
+ WriteCoord(MSG_ENTITY, this.anim_start_time);
+ WriteByte(MSG_ENTITY, this.frame);
}
if(sf & TNSF_STATUS)
{
- WriteByte(MSG_ENTITY, self.team);
+ WriteByte(MSG_ENTITY, this.team);
- if(self.health <= 0)
+ if(this.health <= 0)
WriteByte(MSG_ENTITY, 0);
else
- WriteByte(MSG_ENTITY, ceil((self.health / self.max_health) * 255));
+ WriteByte(MSG_ENTITY, ceil((this.health / this.max_health) * 255));
}
return true;
}
-void load_unit_settings(entity ent, string unitname, float is_reload)
-{SELFPARAM();
+void load_unit_settings(entity ent, bool is_reload)
+{
+ string unitname = ent.netname;
string sbase;
if (ent == world)
ent.track_accel_rotate = cvar(strcat(sbase,"_track_accel_rot"));
ent.track_blendrate = cvar(strcat(sbase,"_track_blendrate"));
- if(is_reload)
- TUR_ACTION(self.turretid, TR_SETUP);
+ if(is_reload) {
+ Turret tur = get_turretinfo(ent.m_id);
+ tur.tr_setup(tur, ent);
+ }
}
-void turret_projectile_explode()
-{SELFPARAM();
+void turret_projectile_explode(entity this)
+{
- self.takedamage = DAMAGE_NO;
- self.event_damage = func_null;
+ this.takedamage = DAMAGE_NO;
+ this.event_damage = func_null;
#ifdef TURRET_DEBUG
float d;
- d = RadiusDamage (self, self.owner, self.owner.shot_dmg, 0, self.owner.shot_radius, self, world, self.owner.shot_force, self.totalfrags, world);
- self.owner.tur_debug_dmg_t_h = self.owner.tur_debug_dmg_t_h + d;
- self.owner.tur_debug_dmg_t_f = self.owner.tur_debug_dmg_t_f + self.owner.shot_dmg;
+ d = RadiusDamage (this, this.owner, this.owner.shot_dmg, 0, this.owner.shot_radius, this, world, this.owner.shot_force, this.totalfrags, world);
+ this.owner.tur_debug_dmg_t_h = this.owner.tur_debug_dmg_t_h + d;
+ this.owner.tur_debug_dmg_t_f = this.owner.tur_debug_dmg_t_f + this.owner.shot_dmg;
#else
- RadiusDamage (self, self.realowner, self.owner.shot_dmg, 0, self.owner.shot_radius, self, world, self.owner.shot_force, self.totalfrags, world);
+ RadiusDamage (this, this.realowner, this.owner.shot_dmg, 0, this.owner.shot_radius, this, world, this.owner.shot_force, this.totalfrags, world);
#endif
- remove(self);
+ remove(this);
}
-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 inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector vforce)
-{SELFPARAM();
- self.velocity += vforce;
- self.health -= damage;
- //self.realowner = attacker; // Dont change realowner, it does not make much sense for turrets
- if(self.health <= 0)
- W_PrepareExplosionByDamage(self.owner, turret_projectile_explode);
+void turret_projectile_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector vforce)
+{
+ this.velocity += vforce;
+ this.health -= damage;
+ //this.realowner = attacker; // Dont change realowner, it does not make much sense for turrets
+ if(this.health <= 0)
+ 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)
-{SELFPARAM();
+entity turret_projectile(entity actor, Sound _snd, float _size, float _health, float _death, float _proj_type, float _cull, float _cli_anim)
+{
+ TC(Sound, _snd);
entity proj;
- _sound (self, CH_WEAPON_A, _snd, VOL_BASE, ATTEN_NORM);
+ sound (actor, CH_WEAPON_A, _snd, VOL_BASE, ATTEN_NORM);
proj = spawn ();
- setorigin(proj, self.tur_shotorg);
+ setorigin(proj, actor.tur_shotorg);
setsize(proj, '-0.5 -0.5 -0.5' * _size, '0.5 0.5 0.5' * _size);
- proj.owner = self;
- proj.realowner = self;
+ proj.owner = actor;
+ proj.realowner = actor;
proj.bot_dodge = true;
- proj.bot_dodgerating = self.shot_dmg;
- proj.think = turret_projectile_explode;
- proj.touch = turret_projectile_touch;
+ proj.bot_dodgerating = actor.shot_dmg;
+ 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;
+ proj.velocity = normalize(actor.tur_shotdir_updated + randomvec() * actor.shot_spread) * actor.shot_speed;
proj.flags = FL_PROJECTILE;
- proj.enemy = self.enemy;
+ proj.enemy = actor.enemy;
proj.totalfrags = _death;
PROJECTILE_MAKETRIGGER(proj);
if(_health)
** 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();
+ turret_tag_fire_update(t_turret);
- 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);
+ 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);
- 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;
-
- 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;
}
/**
** the units .track_type and .track_flags
**/
.float turret_framecounter;
-void turret_track()
-{SELFPARAM();
+void turret_track(entity this)
+{
vector target_angle; // This is where we want to aim
vector move_angle; // This is where we can aim
float f_tmp;
vector v1, v2;
- v1 = self.tur_head.angles;
- v2 = self.tur_head.avelocity;
+ v1 = this.tur_head.angles;
+ v2 = this.tur_head.avelocity;
- if (self.track_flags == TFL_TRACK_NO)
+ if (this.track_flags == TFL_TRACK_NO)
return;
- if(!self.active)
- target_angle = self.idle_aim - ('1 0 0' * self.aim_maxpitch);
- else if (self.enemy == world)
+ if(!this.active)
+ target_angle = this.idle_aim - ('1 0 0' * this.aim_maxpitch);
+ else if (this.enemy == world)
{
- if(time > self.lip)
- target_angle = self.idle_aim + self.angles;
+ if(time > this.lip)
+ target_angle = this.idle_aim + this.angles;
else
- target_angle = vectoangles(normalize(self.tur_aimpos - self.tur_shotorg));
+ target_angle = vectoangles(normalize(this.tur_aimpos - this.tur_shotorg));
}
else
{
- target_angle = vectoangles(normalize(self.tur_aimpos - self.tur_shotorg));
+ target_angle = vectoangles(normalize(this.tur_aimpos - this.tur_shotorg));
}
- self.tur_head.angles_x = anglemods(self.tur_head.angles_x);
- self.tur_head.angles_y = anglemods(self.tur_head.angles_y);
+ this.tur_head.angles_x = anglemods(this.tur_head.angles_x);
+ this.tur_head.angles_y = anglemods(this.tur_head.angles_y);
// Find the diffrence between where we currently aim and where we want to aim
- //move_angle = target_angle - (self.angles + self.tur_head.angles);
- //move_angle = shortangle_vxy(move_angle,(self.angles + self.tur_head.angles));
+ //move_angle = target_angle - (this.angles + this.tur_head.angles);
+ //move_angle = shortangle_vxy(move_angle,(this.angles + this.tur_head.angles));
- move_angle = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(self.angles), AnglesTransform_FromAngles(target_angle))) - self.tur_head.angles;
- move_angle = shortangle_vxy(move_angle, self.tur_head.angles);
+ move_angle = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(this.angles), AnglesTransform_FromAngles(target_angle))) - this.tur_head.angles;
+ move_angle = shortangle_vxy(move_angle, this.tur_head.angles);
- switch(self.track_type)
+ switch(this.track_type)
{
case TFL_TRACKTYPE_STEPMOTOR:
- f_tmp = self.aim_speed * self.ticrate; // dgr/sec -> dgr/tic
- if (self.track_flags & TFL_TRACK_PITCH)
+ f_tmp = this.aim_speed * this.ticrate; // dgr/sec -> dgr/tic
+ if (this.track_flags & TFL_TRACK_PITCH)
{
- self.tur_head.angles_x += bound(-f_tmp,move_angle_x, f_tmp);
- if(self.tur_head.angles_x > self.aim_maxpitch)
- self.tur_head.angles_x = self.aim_maxpitch;
+ this.tur_head.angles_x += bound(-f_tmp,move_angle_x, f_tmp);
+ if(this.tur_head.angles_x > this.aim_maxpitch)
+ this.tur_head.angles_x = this.aim_maxpitch;
- if(self.tur_head.angles_x < -self.aim_maxpitch)
- self.tur_head.angles_x = self.aim_maxpitch;
+ if(this.tur_head.angles_x < -this.aim_maxpitch)
+ this.tur_head.angles_x = this.aim_maxpitch;
}
- if (self.track_flags & TFL_TRACK_ROTATE)
+ if (this.track_flags & TFL_TRACK_ROTATE)
{
- self.tur_head.angles_y += bound(-f_tmp, move_angle_y, f_tmp);
- if(self.tur_head.angles_y > self.aim_maxrotate)
- self.tur_head.angles_y = self.aim_maxrotate;
+ this.tur_head.angles_y += bound(-f_tmp, move_angle_y, f_tmp);
+ if(this.tur_head.angles_y > this.aim_maxrotate)
+ this.tur_head.angles_y = this.aim_maxrotate;
- if(self.tur_head.angles_y < -self.aim_maxrotate)
- self.tur_head.angles_y = self.aim_maxrotate;
+ if(this.tur_head.angles_y < -this.aim_maxrotate)
+ this.tur_head.angles_y = this.aim_maxrotate;
}
// CSQC
- self.SendFlags |= TNSF_ANG;
+ this.SendFlags |= TNSF_ANG;
return;
case TFL_TRACKTYPE_FLUIDINERTIA:
- f_tmp = self.aim_speed * self.ticrate; // dgr/sec -> dgr/tic
- move_angle_x = bound(-self.aim_speed, move_angle_x * self.track_accel_pitch * f_tmp, self.aim_speed);
- move_angle_y = bound(-self.aim_speed, move_angle_y * self.track_accel_rotate * f_tmp, self.aim_speed);
- move_angle = (self.tur_head.avelocity * self.track_blendrate) + (move_angle * (1 - self.track_blendrate));
+ f_tmp = this.aim_speed * this.ticrate; // dgr/sec -> dgr/tic
+ move_angle_x = bound(-this.aim_speed, move_angle_x * this.track_accel_pitch * f_tmp, this.aim_speed);
+ move_angle_y = bound(-this.aim_speed, move_angle_y * this.track_accel_rotate * f_tmp, this.aim_speed);
+ move_angle = (this.tur_head.avelocity * this.track_blendrate) + (move_angle * (1 - this.track_blendrate));
break;
case TFL_TRACKTYPE_FLUIDPRECISE:
- move_angle_y = bound(-self.aim_speed, move_angle_y, self.aim_speed);
- move_angle_x = bound(-self.aim_speed, move_angle_x, self.aim_speed);
+ move_angle_y = bound(-this.aim_speed, move_angle_y, this.aim_speed);
+ move_angle_x = bound(-this.aim_speed, move_angle_x, this.aim_speed);
break;
}
// pitch
- if (self.track_flags & TFL_TRACK_PITCH)
+ if (this.track_flags & TFL_TRACK_PITCH)
{
- self.tur_head.avelocity_x = move_angle_x;
- if((self.tur_head.angles_x + self.tur_head.avelocity_x * self.ticrate) > self.aim_maxpitch)
+ this.tur_head.avelocity_x = move_angle_x;
+ if((this.tur_head.angles_x + this.tur_head.avelocity_x * this.ticrate) > this.aim_maxpitch)
{
- self.tur_head.avelocity_x = 0;
- self.tur_head.angles_x = self.aim_maxpitch;
+ this.tur_head.avelocity_x = 0;
+ this.tur_head.angles_x = this.aim_maxpitch;
- self.SendFlags |= TNSF_ANG;
+ this.SendFlags |= TNSF_ANG;
}
- if((self.tur_head.angles_x + self.tur_head.avelocity_x * self.ticrate) < -self.aim_maxpitch)
+ if((this.tur_head.angles_x + this.tur_head.avelocity_x * this.ticrate) < -this.aim_maxpitch)
{
- self.tur_head.avelocity_x = 0;
- self.tur_head.angles_x = -self.aim_maxpitch;
+ this.tur_head.avelocity_x = 0;
+ this.tur_head.angles_x = -this.aim_maxpitch;
- self.SendFlags |= TNSF_ANG;
+ this.SendFlags |= TNSF_ANG;
}
}
// rot
- if (self.track_flags & TFL_TRACK_ROTATE)
+ if (this.track_flags & TFL_TRACK_ROTATE)
{
- self.tur_head.avelocity_y = move_angle_y;
+ this.tur_head.avelocity_y = move_angle_y;
- if((self.tur_head.angles_y + self.tur_head.avelocity_y * self.ticrate) > self.aim_maxrotate)
+ if((this.tur_head.angles_y + this.tur_head.avelocity_y * this.ticrate) > this.aim_maxrotate)
{
- self.tur_head.avelocity_y = 0;
- self.tur_head.angles_y = self.aim_maxrotate;
+ this.tur_head.avelocity_y = 0;
+ this.tur_head.angles_y = this.aim_maxrotate;
- self.SendFlags |= TNSF_ANG;
+ this.SendFlags |= TNSF_ANG;
}
- if((self.tur_head.angles_y + self.tur_head.avelocity_y * self.ticrate) < -self.aim_maxrotate)
+ if((this.tur_head.angles_y + this.tur_head.avelocity_y * this.ticrate) < -this.aim_maxrotate)
{
- self.tur_head.avelocity_y = 0;
- self.tur_head.angles_y = -self.aim_maxrotate;
+ this.tur_head.avelocity_y = 0;
+ this.tur_head.angles_y = -this.aim_maxrotate;
- self.SendFlags |= TNSF_ANG;
+ this.SendFlags |= TNSF_ANG;
}
}
- self.SendFlags |= TNSF_AVEL;
+ this.SendFlags |= TNSF_AVEL;
// Force a angle update every 10'th frame
- self.turret_framecounter += 1;
- if(self.turret_framecounter >= 10)
+ this.turret_framecounter += 1;
+ if(this.turret_framecounter >= 10)
{
- self.SendFlags |= TNSF_ANG;
- self.turret_framecounter = 0;
+ this.SendFlags |= TNSF_ANG;
+ this.turret_framecounter = 0;
}
}
if(e_target.alpha <= 0.3)
return -1;
- if(g_onslaught)
- if (substring(e_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job!
- return - 3;
+ if(MUTATOR_CALLHOOK(TurretValidateTarget, e_turret, e_target, validate_flags))
+ return M_ARGV(3, float);
if (validate_flags & TFL_TARGETSELECT_NO)
return -4;
}
else if (e_target.health <= 0)
return -6;
- else if(e_target.frozen > 0)
+ else if(STAT(FROZEN, e_target) > 0)
return -6;
// player
if(!(validate_flags & TFL_TARGETSELECT_PLAYERS))
return -7;
- if (e_target.deadflag != DEAD_NO)
+ if (IS_DEAD(e_target))
return -8;
}
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;
}
-entity turret_select_target()
-{SELFPARAM();
+entity turret_select_target(entity this)
+{
entity e; // target looper entity
float score; // target looper entity score
entity e_enemy; // currently best scoreing target
float m_score; // currently best scoreing target's score
m_score = 0;
- if(self.enemy && self.enemy.takedamage && turret_validate_target(self,self.enemy,self.target_validate_flags) > 0)
+ if(this.enemy && this.enemy.takedamage && turret_validate_target(this,this.enemy,this.target_validate_flags) > 0)
{
- e_enemy = self.enemy;
- m_score = self.turret_score_target(self,e_enemy) * self.target_select_samebias;
+ e_enemy = this.enemy;
+ m_score = this.turret_score_target(this,e_enemy) * this.target_select_samebias;
}
else
- e_enemy = self.enemy = world;
+ e_enemy = this.enemy = world;
- e = findradius(self.origin, self.target_range);
+ e = findradius(this.origin, this.target_range);
// Nothing to aim at?
if (!e)
{
if(e.takedamage)
{
- float f = turret_validate_target(self, e, self.target_select_flags);
+ float f = turret_validate_target(this, e, this.target_select_flags);
//dprint("F is: ", ftos(f), "\n");
if ( f > 0)
{
- score = self.turret_score_target(self,e);
+ score = this.turret_score_target(this,e);
if ((score > m_score) && (score > 0))
{
e_enemy = e;
/**
** Preforms pre-fire checks based on the uints firecheck_flags
**/
-float turret_firecheck()
-{SELFPARAM();
+bool turret_firecheck(entity this)
+{
// This one just dont care =)
- if (self.firecheck_flags & TFL_FIRECHECK_NO)
- return 1;
+ if (this.firecheck_flags & TFL_FIRECHECK_NO)
+ return true;
- if (self.enemy == world)
- return 0;
+ if (this.enemy == world)
+ return false;
// Ready?
- if (self.firecheck_flags & TFL_FIRECHECK_REFIRE)
- if (self.attack_finished_single > time) return 0;
+ if (this.firecheck_flags & TFL_FIRECHECK_REFIRE)
+ if (this.attack_finished_single[0] > time) return false;
// Special case: volly fire turret that has to fire a full volly if a shot was fired.
- if (self.shoot_flags & TFL_SHOOT_VOLLYALWAYS)
- if (self.volly_counter != self.shot_volly)
- if(self.ammo >= self.shot_dmg)
- return 1;
+ if (this.shoot_flags & TFL_SHOOT_VOLLYALWAYS)
+ if (this.volly_counter != this.shot_volly)
+ if(this.ammo >= this.shot_dmg)
+ return true;
// Lack of zombies makes shooting dead things unnecessary :P
- if (self.firecheck_flags & TFL_FIRECHECK_DEAD)
- if (self.enemy.deadflag != DEAD_NO)
- return 0;
+ if (this.firecheck_flags & TFL_FIRECHECK_DEAD)
+ if (IS_DEAD(this.enemy))
+ return false;
// Own ammo?
- if (self.firecheck_flags & TFL_FIRECHECK_AMMO_OWN)
- if (self.ammo < self.shot_dmg)
- return 0;
+ if (this.firecheck_flags & TFL_FIRECHECK_AMMO_OWN)
+ if (this.ammo < this.shot_dmg)
+ return false;
// Other's ammo? (support-supply units)
- if (self.firecheck_flags & TFL_FIRECHECK_AMMO_OTHER)
- if (self.enemy.ammo >= self.enemy.ammo_max)
- return 0;
+ if (this.firecheck_flags & TFL_FIRECHECK_AMMO_OTHER)
+ if (this.enemy.ammo >= this.enemy.ammo_max)
+ return false;
// Target of opertunity?
- if(turret_validate_target(self, self.tur_impactent, self.target_validate_flags) > 0)
+ if(turret_validate_target(this, this.tur_impactent, this.target_validate_flags) > 0)
{
- self.enemy = self.tur_impactent;
- return 1;
+ this.enemy = this.tur_impactent;
+ return true;
}
- if (self.firecheck_flags & TFL_FIRECHECK_DISTANCES)
+ if (this.firecheck_flags & TFL_FIRECHECK_DISTANCES)
{
// To close?
- if (self.tur_dist_aimpos < self.target_range_min)
- if(turret_validate_target(self, self.tur_impactent, self.target_validate_flags) > 0)
- return 1; // Target of opertunity?
+ if (this.tur_dist_aimpos < this.target_range_min)
+ if(turret_validate_target(this, this.tur_impactent, this.target_validate_flags) > 0)
+ return true; // Target of opertunity?
else
- return 0;
+ return false;
}
// Try to avoid FF?
- if (self.firecheck_flags & TFL_FIRECHECK_AFF)
- if (self.tur_impactent.team == self.team)
- return 0;
+ if (this.firecheck_flags & TFL_FIRECHECK_AFF)
+ if (this.tur_impactent.team == this.team)
+ return false;
// aim<->predicted impact
- if (self.firecheck_flags & TFL_FIRECHECK_AIMDIST)
- if (self.tur_dist_impact_to_aimpos > self.aim_firetolerance_dist)
- return 0;
+ if (this.firecheck_flags & TFL_FIRECHECK_AIMDIST)
+ if (this.tur_dist_impact_to_aimpos > this.aim_firetolerance_dist)
+ return false;
// Volly status
- if (self.shot_volly > 1)
- if (self.volly_counter == self.shot_volly)
- if (self.ammo < (self.shot_dmg * self.shot_volly))
- return 0;
+ if (this.shot_volly > 1)
+ if (this.volly_counter == this.shot_volly)
+ if (this.ammo < (this.shot_dmg * this.shot_volly))
+ return false;
- /*if(self.firecheck_flags & TFL_FIRECHECK_VERIFIED)
- if(self.tur_impactent != self.enemy)
- return 0;*/
+ /*if(this.firecheck_flags & TFL_FIRECHECK_VERIFIED)
+ if(this.tur_impactent != this.enemy)
+ return false;*/
- return 1;
+ return true;
}
-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();
+ return this.turret_firecheckfunc(this);
}
-void turret_fire()
-{SELFPARAM();
+void turret_fire(entity this)
+{
if (autocvar_g_turrets_nofire != 0)
return;
- if(MUTATOR_CALLHOOK(TurretFire, self))
+ if(MUTATOR_CALLHOOK(TurretFire, this))
return;
- TUR_ACTION(self.turretid, TR_ATTACK);
+ Turret info = get_turretinfo(this.m_id);
+ info.tr_attack(info, this);
- self.attack_finished_single = time + self.shot_refire;
- self.ammo -= self.shot_dmg;
- self.volly_counter = self.volly_counter - 1;
+ this.attack_finished_single[0] = time + this.shot_refire;
+ this.ammo -= this.shot_dmg;
+ this.volly_counter = this.volly_counter - 1;
- if (self.volly_counter <= 0)
+ if (this.volly_counter <= 0)
{
- self.volly_counter = self.shot_volly;
+ this.volly_counter = this.shot_volly;
- if (self.shoot_flags & TFL_SHOOT_CLEARTARGET)
- self.enemy = world;
+ if (this.shoot_flags & TFL_SHOOT_CLEARTARGET)
+ this.enemy = world;
- if (self.shot_volly > 1)
- self.attack_finished_single = time + self.shot_volly_refire;
+ if (this.shot_volly > 1)
+ this.attack_finished_single[0] = time + this.shot_volly_refire;
}
#ifdef TURRET_DEBUG
- if (self.enemy) paint_target3(self.tur_aimpos, 64, self.tur_debug_rvec, self.tur_impacttime + 0.25);
+ if (this.enemy) paint_target3(this.tur_aimpos, 64, this.tur_debug_rvec, this.tur_impacttime + 0.25);
#endif
}
-void turret_think()
-{SELFPARAM();
- entity e;
-
- self.nextthink = time + self.ticrate;
-
- // ONS uses somewhat backwards linking.
- if (teamplay)
- {
- if (g_onslaught)
- if (self.target)
- {
- e = find(world, targetname,self.target);
- if (e != world)
- self.team = e.team;
- }
+void turret_think(entity this)
+{
+ this.nextthink = time + this.ticrate;
- if (self.team != self.tur_head.team)
- turret_respawn();
- }
+ MUTATOR_CALLHOOK(TurretThink, this);
#ifdef TURRET_DEBUG
- if (self.tur_debug_tmr1 < time)
+ if (this.tur_debug_tmr1 < time)
{
- if (self.enemy) paint_target (self.enemy,128,self.tur_debug_rvec,0.9);
- paint_target(self,256,self.tur_debug_rvec,0.9);
- self.tur_debug_tmr1 = time + 1;
+ if (this.enemy) paint_target (this.enemy,128,this.tur_debug_rvec,0.9);
+ paint_target(this,256,this.tur_debug_rvec,0.9);
+ this.tur_debug_tmr1 = time + 1;
}
#endif
// Handle ammo
- if (!(self.spawnflags & TSF_NO_AMMO_REGEN))
- if (self.ammo < self.ammo_max)
- self.ammo = min(self.ammo + self.ammo_recharge, self.ammo_max);
+ if (!(this.spawnflags & TSF_NO_AMMO_REGEN))
+ if (this.ammo < this.ammo_max)
+ this.ammo = min(this.ammo + this.ammo_recharge, this.ammo_max);
// Inactive turrets needs to run the think loop,
// So they can handle animation and wake up if need be.
- if(!self.active)
+ if(!this.active)
{
- turret_track();
+ turret_track(this);
return;
}
// This is typicaly used for zaping every target in range
// turret_fusionreactor uses this to recharge friendlys.
- if (self.shoot_flags & TFL_SHOOT_HITALLVALID)
+ if (this.shoot_flags & TFL_SHOOT_HITALLVALID)
{
- // Do a self.turret_fire for every valid target.
- e = findradius(self.origin,self.target_range);
+ // Do a this.turret_fire for every valid target.
+ entity e = findradius(this.origin,this.target_range);
while (e)
{
if(e.takedamage)
{
- if (turret_validate_target(self,e,self.target_validate_flags))
+ if (turret_validate_target(this,e,this.target_validate_flags))
{
- self.enemy = e;
+ this.enemy = e;
- turret_do_updates(self);
+ turret_do_updates(this);
- if (turret_checkfire())
- turret_fire();
+ if (turret_checkfire(this))
+ turret_fire(this);
}
}
e = e.chain;
}
- self.enemy = world;
+ this.enemy = world;
}
- else if(self.shoot_flags & TFL_SHOOT_CUSTOM)
+ else if(this.shoot_flags & TFL_SHOOT_CUSTOM)
{
// This one is doing something.. oddball. assume its handles what needs to be handled.
// Predict?
- if(!(self.aim_flags & TFL_AIM_NO))
- self.tur_aimpos = turret_aim_generic();
+ if(!(this.aim_flags & TFL_AIM_NO))
+ this.tur_aimpos = turret_aim_generic(this);
// Turn & pitch?
- if(!(self.track_flags & TFL_TRACK_NO))
- turret_track();
+ if(!(this.track_flags & TFL_TRACK_NO))
+ turret_track(this);
- turret_do_updates(self);
+ turret_do_updates(this);
// Fire?
- if (turret_checkfire())
- turret_fire();
+ if (turret_checkfire(this))
+ turret_fire(this);
}
else
{
// Special case for volly always. if it fired once it must compleate the volly.
- if(self.shoot_flags & TFL_SHOOT_VOLLYALWAYS)
- if(self.volly_counter != self.shot_volly)
+ if(this.shoot_flags & TFL_SHOOT_VOLLYALWAYS)
+ if(this.volly_counter != this.shot_volly)
{
// Predict or whatnot
- if(!(self.aim_flags & TFL_AIM_NO))
- self.tur_aimpos = turret_aim_generic();
+ if(!(this.aim_flags & TFL_AIM_NO))
+ this.tur_aimpos = turret_aim_generic(this);
// Turn & pitch
- if(!(self.track_flags & TFL_TRACK_NO))
- turret_track();
+ if(!(this.track_flags & TFL_TRACK_NO))
+ turret_track(this);
- turret_do_updates(self);
+ turret_do_updates(this);
// Fire!
- if (turret_checkfire())
- turret_fire();
+ if (turret_checkfire(this))
+ turret_fire(this);
- TUR_ACTION(self.turretid, TR_THINK);
+ Turret tur = get_turretinfo(this.m_id);
+ tur.tr_think(tur, this);
return;
}
// g_turrets_targetscan_maxdelay forces a target re-scan at least this often
float do_target_scan = 0;
- if((self.target_select_time + autocvar_g_turrets_targetscan_maxdelay) < time)
+ if((this.target_select_time + autocvar_g_turrets_targetscan_maxdelay) < time)
do_target_scan = 1;
// Old target (if any) invalid?
- if(self.target_validate_time < time)
- if (turret_validate_target(self, self.enemy, self.target_validate_flags) <= 0)
+ if(this.target_validate_time < time)
+ if (turret_validate_target(this, this.enemy, this.target_validate_flags) <= 0)
{
- self.enemy = world;
- self.target_validate_time = time + 0.5;
+ this.enemy = world;
+ this.target_validate_time = time + 0.5;
do_target_scan = 1;
}
// But never more often then g_turrets_targetscan_mindelay!
- if (self.target_select_time + autocvar_g_turrets_targetscan_mindelay > time)
+ if (this.target_select_time + autocvar_g_turrets_targetscan_mindelay > time)
do_target_scan = 0;
if(do_target_scan)
{
- self.enemy = turret_select_target();
- self.target_select_time = time;
+ this.enemy = turret_select_target(this);
+ this.target_select_time = time;
}
// No target, just go to idle, do any custom stuff and bail.
- if (self.enemy == world)
+ if (this.enemy == world)
{
// Turn & pitch
- if(!(self.track_flags & TFL_TRACK_NO))
- turret_track();
+ if(!(this.track_flags & TFL_TRACK_NO))
+ turret_track(this);
- TUR_ACTION(self.turretid, TR_THINK);
+ Turret tur = get_turretinfo(this.m_id);
+ tur.tr_think(tur, this);
// And bail.
return;
}
else
- self.lip = time + autocvar_g_turrets_aimidle_delay; // Keep track of the last time we had a target.
+ this.lip = time + autocvar_g_turrets_aimidle_delay; // Keep track of the last time we had a target.
// Predict?
- if(!(self.aim_flags & TFL_AIM_NO))
- self.tur_aimpos = turret_aim_generic();
+ if(!(this.aim_flags & TFL_AIM_NO))
+ this.tur_aimpos = turret_aim_generic(this);
// Turn & pitch?
- if(!(self.track_flags & TFL_TRACK_NO))
- turret_track();
+ if(!(this.track_flags & TFL_TRACK_NO))
+ turret_track(this);
- turret_do_updates(self);
+ turret_do_updates(this);
// Fire?
- if (turret_checkfire())
- turret_fire();
+ if (turret_checkfire(this))
+ turret_fire(this);
}
- TUR_ACTION(self.turretid, TR_THINK);
+ Turret tur = get_turretinfo(this.m_id);
+ tur.tr_think(tur, this);
}
/*
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;
- self.nextthink = time;
- self.tur_head.effects = EF_NODRAW;
+void turret_link(entity this)
+{
+ Net_LinkEntity(this, true, 0, turret_send);
+ setthink(this, turret_think);
+ this.nextthink = time;
+ this.tur_head.effects = EF_NODRAW;
}
-void turrets_manager_think()
-{SELFPARAM();
- self.nextthink = time + 1;
+void turrets_manager_think(entity this)
+{
+ this.nextthink = time + 1;
- entity e;
if (autocvar_g_turrets_reloadcvars == 1)
{
- e = nextent(world);
- while (e)
- {
- if (IS_TURRET(e))
- {
- load_unit_settings(e,e.cvar_basename,1);
- TUR_ACTION(self.turretid, TR_THINK);
- }
-
- e = nextent(e);
- }
- cvar_set("g_turrets_reloadcvars","0");
+ 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");
}
}
-float turret_initialize(float tur_id)
-{SELFPARAM();
+void turret_initparams(entity tur)
+{
+ #define TRY(x) (x) ? (x)
+ tur.respawntime = max (-1, (TRY(tur.respawntime) : 60 ));
+ tur.shot_refire = bound(0.01, (TRY(tur.shot_refire) : 1 ), 9999);
+ tur.shot_dmg = max (1, (TRY(tur.shot_dmg) : tur.shot_refire * 50 ));
+ tur.shot_radius = max (1, (TRY(tur.shot_radius) : tur.shot_dmg * 0.5 ));
+ tur.shot_speed = max (1, (TRY(tur.shot_speed) : 2500 ));
+ tur.shot_spread = bound(0.0001, (TRY(tur.shot_spread) : 0.0125 ), 500);
+ tur.shot_force = bound(0.001, (TRY(tur.shot_force) : tur.shot_dmg * 0.5 + tur.shot_radius * 0.5 ), 5000);
+ tur.shot_volly = bound(1, (TRY(tur.shot_volly) : 1 ), floor(tur.ammo_max / tur.shot_dmg));
+ tur.shot_volly_refire = bound(tur.shot_refire, (TRY(tur.shot_volly_refire) : tur.shot_refire * tur.shot_volly ), 60);
+ tur.target_range = bound(0, (TRY(tur.target_range) : tur.shot_speed * 0.5 ), MAX_SHOT_DISTANCE);
+ tur.target_range_min = bound(0, (TRY(tur.target_range_min) : tur.shot_radius * 2 ), MAX_SHOT_DISTANCE);
+ tur.target_range_optimal = bound(0, (TRY(tur.target_range_optimal) : tur.target_range * 0.5 ), MAX_SHOT_DISTANCE);
+ tur.aim_maxrotate = bound(0, (TRY(tur.aim_maxrotate) : 90 ), 360);
+ tur.aim_maxpitch = bound(0, (TRY(tur.aim_maxpitch) : 20 ), 90);
+ tur.aim_speed = bound(0.1, (TRY(tur.aim_speed) : 36 ), 1000);
+ tur.aim_firetolerance_dist = bound(0.1, (TRY(tur.aim_firetolerance_dist) : 5 + (tur.shot_radius * 2) ), MAX_SHOT_DISTANCE);
+ tur.target_select_rangebias = bound(-10, (TRY(tur.target_select_rangebias) : 1 ), 10);
+ tur.target_select_samebias = bound(-10, (TRY(tur.target_select_samebias) : 1 ), 10);
+ tur.target_select_anglebias = bound(-10, (TRY(tur.target_select_anglebias) : 1 ), 10);
+ tur.target_select_missilebias = bound(-10, (TRY(tur.target_select_missilebias) : 1 ), 10);
+ tur.target_select_playerbias = bound(-10, (TRY(tur.target_select_playerbias) : 1 ), 10);
+ tur.ammo_max = max (tur.shot_dmg, (TRY(tur.ammo_max) : tur.shot_dmg * 10 ));
+ tur.ammo_recharge = max (0, (TRY(tur.ammo_recharge) : tur.shot_dmg * 0.5 ));
+ #undef TRY
+}
+
+bool turret_initialize(entity this, Turret tur)
+{
if(!autocvar_g_turrets)
return false;
- entity e;
- entity tur = get_turretinfo(tur_id);
- if(tur.turretid == 0)
+ if(tur.m_id == 0)
return false; // invalid turret
- if(!self.tur_head) { TUR_ACTION(tur_id, TR_PRECACHE); } // if tur_head exists, we can assume this turret re-spawned
+ // if tur_head exists, we can assume this turret re-spawned
+ if(!this.tur_head) {
+ tur.tr_precache(tur);
+ }
- e = find(world, classname, "turret_manager");
+ entity e = find(world, classname, "turret_manager");
if(!e)
{
- e = spawn();
- e.classname = "turret_manager";
- e.think = turrets_manager_think;
+ e = new(turret_manager);
+ setthink(e, turrets_manager_think);
e.nextthink = time + 2;
}
- if(!(self.spawnflags & TSF_SUSPENDED))
- builtin_droptofloor();
-
- self.cvar_basename = tur.cvar_basename;
- load_unit_settings(self, self.cvar_basename, 0);
-
- if(!self.team || !teamplay) { self.team = MAX_SHOT_DISTANCE; }
- if(!self.ticrate) { self.ticrate = ((self.turret_flags & TUR_FLAG_SUPPORT) ? 0.2 : 0.1); }
- if(!self.health) { self.health = 1000; }
- if(!self.shot_refire) { self.shot_refire = 1; }
- if(!self.tur_shotorg) { self.tur_shotorg = '50 0 50'; }
- if(!self.turret_flags) { self.turret_flags = TUR_FLAG_SPLASH | TUR_FLAG_MEDPROJ | TUR_FLAG_PLAYER; }
- if(!self.damage_flags) { self.damage_flags = TFL_DMG_YES | TFL_DMG_RETALIATE | TFL_DMG_AIMSHAKE; }
- if(!self.aim_flags) { self.aim_flags = TFL_AIM_LEAD | TFL_AIM_SHOTTIMECOMPENSATE; }
- if(!self.track_type) { self.track_type = TFL_TRACKTYPE_STEPMOTOR; }
- if(!self.track_flags) { self.track_flags = TFL_TRACK_PITCH | TFL_TRACK_ROTATE; }
- if(!self.ammo_flags) { self.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE; }
- if(!self.target_select_flags) { self.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_ANGLELIMITS; }
- if(!self.firecheck_flags) { self.firecheck_flags = TFL_FIRECHECK_DEAD | TFL_FIRECHECK_DISTANCES | TFL_FIRECHECK_LOS
+ if(!(this.spawnflags & TSF_SUSPENDED))
+ WITHSELF(this, builtin_droptofloor());
+
+ this.netname = tur.netname;
+ load_unit_settings(this, 0);
+
+ if(!this.team || !teamplay) { this.team = MAX_SHOT_DISTANCE; }
+ if(!this.ticrate) { this.ticrate = ((this.turret_flags & TUR_FLAG_SUPPORT) ? 0.2 : 0.1); }
+ if(!this.health) { this.health = 1000; }
+ if(!this.shot_refire) { this.shot_refire = 1; }
+ if(!this.tur_shotorg) { this.tur_shotorg = '50 0 50'; }
+ if(!this.turret_flags) { this.turret_flags = TUR_FLAG_SPLASH | TUR_FLAG_MEDPROJ | TUR_FLAG_PLAYER; }
+ if(!this.damage_flags) { this.damage_flags = TFL_DMG_YES | TFL_DMG_RETALIATE | TFL_DMG_AIMSHAKE; }
+ if(!this.aim_flags) { this.aim_flags = TFL_AIM_LEAD | TFL_AIM_SHOTTIMECOMPENSATE; }
+ if(!this.track_type) { this.track_type = TFL_TRACKTYPE_STEPMOTOR; }
+ if(!this.track_flags) { this.track_flags = TFL_TRACK_PITCH | TFL_TRACK_ROTATE; }
+ if(!this.ammo_flags) { this.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE; }
+ if(!this.target_select_flags) { this.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_ANGLELIMITS; }
+ if(!this.firecheck_flags) { this.firecheck_flags = TFL_FIRECHECK_DEAD | TFL_FIRECHECK_DISTANCES | TFL_FIRECHECK_LOS
| TFL_FIRECHECK_AIMDIST | TFL_FIRECHECK_TEAMCHECK | TFL_FIRECHECK_AMMO_OWN | TFL_FIRECHECK_REFIRE; }
- if(self.track_type != TFL_TRACKTYPE_STEPMOTOR)
+ if(this.track_type != TFL_TRACKTYPE_STEPMOTOR)
{
// Fluid / Ineria mode. Looks mutch nicer.
// Can reduce aim preformance alot, needs a bit diffrent aimspeed
- self.aim_speed = bound(0.1, ((!self.aim_speed) ? 180 : self.aim_speed), 1000);
+ this.aim_speed = bound(0.1, ((!this.aim_speed) ? 180 : this.aim_speed), 1000);
- if(!self.track_accel_pitch) { self.track_accel_pitch = 0.5; }
- if(!self.track_accel_rotate) { self.track_accel_rotate = 0.5; }
- if(!self.track_blendrate) { self.track_blendrate = 0.35; }
+ if(!this.track_accel_pitch) { this.track_accel_pitch = 0.5; }
+ if(!this.track_accel_rotate) { this.track_accel_rotate = 0.5; }
+ if(!this.track_blendrate) { this.track_blendrate = 0.35; }
}
- self.respawntime = max(-1, ((!self.respawntime) ? 60 : self.respawntime));
- self.shot_refire = bound(0.01, ((!self.shot_refire) ? 1 : self.shot_refire), 9999);
- self.shot_dmg = max(1, ((!self.shot_dmg) ? self.shot_refire * 50 : self.shot_dmg));
- self.shot_radius = max(1, ((!self.shot_radius) ? self.shot_dmg * 0.5 : self.shot_radius));
- self.shot_speed = max(1, ((!self.shot_speed) ? 2500 : self.shot_speed));
- self.shot_spread = bound(0.0001, ((!self.shot_spread) ? 0.0125 : self.shot_spread), 500);
- self.shot_force = bound(0.001, ((!self.shot_force) ? self.shot_dmg * 0.5 + self.shot_radius * 0.5 : self.shot_force), 5000);
- self.shot_volly = bound(1, ((!self.shot_volly) ? 1 : self.shot_volly), floor(self.ammo_max / self.shot_dmg));
- self.shot_volly_refire = bound(self.shot_refire, ((!self.shot_volly_refire) ? self.shot_refire * self.shot_volly : self.shot_volly_refire), 60);
- self.target_range = bound(0, ((!self.target_range) ? self.shot_speed * 0.5 : self.target_range), MAX_SHOT_DISTANCE);
- self.target_range_min = bound(0, ((!self.target_range_min) ? self.shot_radius * 2 : self.target_range_min), MAX_SHOT_DISTANCE);
- self.target_range_optimal = bound(0, ((!self.target_range_optimal) ? self.target_range * 0.5 : self.target_range_optimal), MAX_SHOT_DISTANCE);
- self.aim_maxrotate = bound(0, ((!self.aim_maxrotate) ? 90 : self.aim_maxrotate), 360);
- self.aim_maxpitch = bound(0, ((!self.aim_maxpitch) ? 20 : self.aim_maxpitch), 90);
- self.aim_speed = bound(0.1, ((!self.aim_speed) ? 36 : self.aim_speed), 1000);
- self.aim_firetolerance_dist = bound(0.1, ((!self.aim_firetolerance_dist) ? 5 + (self.shot_radius * 2) : self.aim_firetolerance_dist), MAX_SHOT_DISTANCE);
- self.target_select_rangebias = bound(-10, ((!self.target_select_rangebias) ? 1 : self.target_select_rangebias), 10);
- self.target_select_samebias = bound(-10, ((!self.target_select_samebias) ? 1 : self.target_select_samebias), 10);
- self.target_select_anglebias = bound(-10, ((!self.target_select_anglebias) ? 1 : self.target_select_anglebias), 10);
- self.target_select_missilebias = bound(-10, ((!self.target_select_missilebias) ? 1 : self.target_select_missilebias), 10);
- self.target_select_playerbias = bound(-10, ((!self.target_select_playerbias) ? 1 : self.target_select_playerbias), 10);
- self.ammo_max = max(self.shot_dmg, ((!self.ammo_max) ? self.shot_dmg * 10 : self.ammo_max));
- self.ammo_recharge = max(0, ((!self.ammo_recharge) ? self.shot_dmg * 0.5 : self.ammo_recharge));
-
- self.turret_flags = TUR_FLAG_ISTURRET | (tur.spawnflags);
-
- if(self.turret_flags & TUR_FLAG_SPLASH)
- self.aim_flags |= TFL_AIM_SPLASH;
-
- if(self.turret_flags & TUR_FLAG_MISSILE)
- self.target_select_flags |= TFL_TARGETSELECT_MISSILES;
-
- if(self.turret_flags & TUR_FLAG_PLAYER)
- self.target_select_flags |= TFL_TARGETSELECT_PLAYERS;
-
- if(self.spawnflags & TSL_NO_RESPAWN)
- self.damage_flags |= TFL_DMG_DEATH_NORESPAWN;
-
- if (self.turret_flags & TUR_FLAG_SUPPORT)
- self.turret_score_target = turret_targetscore_support;
+ turret_initparams(this);
+
+ this.turret_flags = TUR_FLAG_ISTURRET | (tur.spawnflags);
+
+ if(this.turret_flags & TUR_FLAG_SPLASH)
+ this.aim_flags |= TFL_AIM_SPLASH;
+
+ if(this.turret_flags & TUR_FLAG_MISSILE)
+ this.target_select_flags |= TFL_TARGETSELECT_MISSILES;
+
+ if(this.turret_flags & TUR_FLAG_PLAYER)
+ this.target_select_flags |= TFL_TARGETSELECT_PLAYERS;
+
+ if(this.spawnflags & TSL_NO_RESPAWN)
+ this.damage_flags |= TFL_DMG_DEATH_NORESPAWN;
+
+ if (this.turret_flags & TUR_FLAG_SUPPORT)
+ this.turret_score_target = turret_targetscore_support;
else
- self.turret_score_target = turret_targetscore_generic;
+ this.turret_score_target = turret_targetscore_generic;
++turret_count;
- _setmodel(self, tur.model);
- setsize(self, tur.mins, tur.maxs);
-
- self.turretid = tur_id;
- self.classname = "turret_main";
- self.active = ACTIVE_ACTIVE;
- self.effects = EF_NODRAW;
- self.netname = TUR_NAME(tur_id);
- self.ticrate = bound(sys_frametime, self.ticrate, 60);
- self.max_health = self.health;
- self.target_validate_flags = self.target_select_flags;
- self.ammo = self.ammo_max;
- self.ammo_recharge *= self.ticrate;
- self.solid = SOLID_BBOX;
- self.takedamage = DAMAGE_AIM;
- self.movetype = MOVETYPE_NOCLIP;
- self.view_ofs = '0 0 0';
- self.turret_firecheckfunc = turret_firecheck;
- self.event_damage = turret_damage;
- self.use = turret_use;
- self.bot_attack = true;
- self.nextthink = time + 1;
- self.nextthink += turret_count * sys_frametime;
-
- self.tur_head = spawn();
- _setmodel(self.tur_head, tur.head_model);
- setsize(self.tur_head, '0 0 0', '0 0 0');
- setorigin(self.tur_head, '0 0 0');
- setattachment(self.tur_head, self, "tag_head");
-
- self.tur_head.netname = self.tur_head.classname = "turret_head";
- self.tur_head.team = self.team;
- self.tur_head.owner = self;
- self.tur_head.takedamage = DAMAGE_NO;
- self.tur_head.solid = SOLID_NOT;
- self.tur_head.movetype = self.movetype;
-
- if(!self.tur_defend)
- if(self.target != "")
+ _setmodel(this, tur.model);
+ setsize(this, tur.mins, tur.maxs);
+
+ this.m_id = tur.m_id;
+ this.classname = "turret_main";
+ this.active = ACTIVE_ACTIVE;
+ this.effects = EF_NODRAW;
+ this.netname = tur.turret_name;
+ this.ticrate = bound(sys_frametime, this.ticrate, 60);
+ this.max_health = this.health;
+ this.target_validate_flags = this.target_select_flags;
+ this.ammo = this.ammo_max;
+ this.ammo_recharge *= this.ticrate;
+ this.solid = SOLID_BBOX;
+ this.takedamage = DAMAGE_AIM;
+ this.movetype = MOVETYPE_NOCLIP;
+ this.view_ofs = '0 0 0';
+ this.turret_firecheckfunc = turret_firecheck;
+ this.event_damage = turret_damage;
+ this.use = turret_use;
+ this.bot_attack = true;
+ this.nextthink = time + 1;
+ this.nextthink += turret_count * sys_frametime;
+
+ this.tur_head = new(turret_head);
+ _setmodel(this.tur_head, tur.head_model);
+ setsize(this.tur_head, '0 0 0', '0 0 0');
+ setorigin(this.tur_head, '0 0 0');
+ setattachment(this.tur_head, this, "tag_head");
+
+ this.tur_head.netname = this.tur_head.classname;
+ this.tur_head.team = this.team;
+ this.tur_head.owner = this;
+ this.tur_head.takedamage = DAMAGE_NO;
+ this.tur_head.solid = SOLID_NOT;
+ this.tur_head.movetype = this.movetype;
+
+ if(!this.tur_defend)
+ if(this.target != "")
{
- self.tur_defend = find(world, targetname, self.target);
- if (self.tur_defend == world)
+ this.tur_defend = find(world, targetname, this.target);
+ if (this.tur_defend == world)
{
- self.target = "";
+ this.target = "";
LOG_TRACE("Turret has invalid defendpoint!\n");
}
}
- if (self.tur_defend)
- self.idle_aim = self.tur_head.angles + angleofs(self.tur_head, self.tur_defend);
+ if (this.tur_defend)
+ this.idle_aim = this.tur_head.angles + angleofs(this.tur_head, this.tur_defend);
else
- self.idle_aim = '0 0 0';
+ this.idle_aim = '0 0 0';
#ifdef TURRET_DEBUG
- self.tur_debug_start = self.nextthink;
- while (vlen(self.tur_debug_rvec) < 2)
- self.tur_debug_rvec = randomvec() * 4;
+ this.tur_debug_start = this.nextthink;
+ while(vdist(this.tur_debug_rvec, <, 2))
+ this.tur_debug_rvec = randomvec() * 4;
- self.tur_debug_rvec_x = fabs(self.tur_debug_rvec_x);
- self.tur_debug_rvec_y = fabs(self.tur_debug_rvec_y);
- self.tur_debug_rvec_z = fabs(self.tur_debug_rvec_z);
+ this.tur_debug_rvec_x = fabs(this.tur_debug_rvec_x);
+ this.tur_debug_rvec_y = fabs(this.tur_debug_rvec_y);
+ this.tur_debug_rvec_z = fabs(this.tur_debug_rvec_z);
#endif
- turret_link();
- turret_respawn();
- turret_tag_fire_update();
+ turret_link(this);
+ turret_respawn(this);
+ turret_tag_fire_update(this);
- TUR_ACTION(tur_id, TR_SETUP);
+ tur.tr_setup(tur, this);
- if(MUTATOR_CALLHOOK(TurretSpawn, self))
+ if(MUTATOR_CALLHOOK(TurretSpawn, this))
return false;
return true;