+#include "sv_turrets.qh"
#ifdef SVQC
#include <server/autocvars.qh>
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)
+ if(this.enemy.move_movetype == MOVETYPE_WALK || this.enemy.move_movetype == MOVETYPE_TOSS || this.enemy.move_movetype == MOVETYPE_BOUNCE)
{
float vz;
prep_z = pre_pos_z;
// Generic damage handling
void turret_hide(entity this)
{
- self.effects |= EF_NODRAW;
- self.nextthink = time + self.respawntime - 0.2;
- setthink(self, turret_respawn);
+ this.effects |= EF_NODRAW;
+ this.nextthink = time + this.respawntime - 0.2;
+ setthink(this, turret_respawn);
}
void turret_die(entity this)
{
- self.deadflag = DEAD_DEAD;
- self.tur_head.deadflag = self.deadflag;
+ 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,NULL,min(this.ammo,50)*5,DEATH_TURRET,NULL);
- Turret tur = get_turretinfo(self.m_id);
- if(self.damage_flags & TFL_DMG_DEATH_NORESPAWN)
+ Turret tur = get_turretinfo(this.m_id);
+ if(this.damage_flags & TFL_DMG_DEATH_NORESPAWN)
{
- tur.tr_death(tur, self);
+ tur.tr_death(tur, this);
- remove(self.tur_head);
- remove(self);
+ delete(this.tur_head);
+ delete(this);
}
else
{
// Setup respawn
- self.SendFlags |= TNSF_STATUS;
- self.nextthink = time + 0.2;
- setthink(self, turret_hide);
+ this.SendFlags |= TNSF_STATUS;
+ this.nextthink = time + 0.2;
+ setthink(this, turret_hide);
- tur.tr_death(tur, self);
+ tur.tr_death(tur, 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;
- setthink(self, turret_think);
-
- self.SendFlags = TNSF_FULL_UPDATE;
-
- Turret tur = get_turretinfo(self.m_id);
- tur.tr_setup(tur, self);
+ 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 = NULL;
+ 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);
}
WriteByte(MSG_ENTITY, sf);
if(sf & TNSF_SETUP)
{
- WriteByte(MSG_ENTITY, self.m_id);
+ 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;
string unitname = ent.netname;
string sbase;
- if (ent == world)
+ if (ent == NULL)
return;
if(!ent.turret_scale_damage) ent.turret_scale_damage = 1;
sbase = strcat(cvar_base,unitname);
if (is_reload)
{
- ent.enemy = world;
+ ent.enemy = NULL;
ent.tur_head.avelocity = '0 0 0';
ent.tur_head.angles = '0 0 0';
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, NULL, this.owner.shot_force, this.totalfrags, NULL);
+ 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, NULL, this.owner.shot_force, this.totalfrags, NULL);
#endif
- remove(self);
+ delete(this);
}
-void turret_projectile_touch(entity this)
+void turret_projectile_touch(entity this, entity toucher)
{
- PROJECTILE_TOUCH(this);
+ PROJECTILE_TOUCH(this, toucher);
turret_projectile_explode(this);
}
setthink(proj, turret_projectile_explode);
settouch(proj, turret_projectile_touch);
proj.nextthink = time + 9;
- proj.movetype = MOVETYPE_FLYMISSILE;
+ set_movetype(proj, MOVETYPE_FLYMISSILE);
proj.velocity = normalize(actor.tur_shotdir_updated + randomvec() * actor.shot_spread) * actor.shot_speed;
- proj.flags = FL_PROJECTILE;
+ proj.flags = FL_PROJECTILE;
+ IL_PUSH(g_projectiles, proj);
+ IL_PUSH(g_bot_dodge, proj);
proj.enemy = actor.enemy;
proj.totalfrags = _death;
PROJECTILE_MAKETRIGGER(proj);
if(!this.active)
target_angle = this.idle_aim - ('1 0 0' * this.aim_maxpitch);
- else if (this.enemy == world)
+ else if (this.enemy == NULL)
{
if(time > this.lip)
target_angle = this.idle_aim + this.angles;
*/
#ifdef TURRET_DEBUG_TARGETSELECT
- LOG_TRACE("Target:",e_target.netname," is a valid target for ",e_turret.netname,"\n");
+ LOG_TRACE("Target:",e_target.netname," is a valid target for ",e_turret.netname);
#endif
return 1;
m_score = this.turret_score_target(this,e_enemy) * this.target_select_samebias;
}
else
- e_enemy = this.enemy = world;
+ e_enemy = this.enemy = NULL;
e = findradius(this.origin, this.target_range);
// Nothing to aim at?
if (!e)
- return world;
+ return NULL;
while (e)
{
if (this.firecheck_flags & TFL_FIRECHECK_NO)
return true;
- if (this.enemy == world)
+ if (this.enemy == NULL)
return false;
// Ready?
this.volly_counter = this.shot_volly;
if (this.shoot_flags & TFL_SHOOT_CLEARTARGET)
- this.enemy = world;
+ this.enemy = NULL;
if (this.shot_volly > 1)
this.attack_finished_single[0] = time + this.shot_volly_refire;
e = e.chain;
}
- this.enemy = world;
+ this.enemy = NULL;
}
else if(this.shoot_flags & TFL_SHOOT_CUSTOM)
{
if(this.target_validate_time < time)
if (turret_validate_target(this, this.enemy, this.target_validate_flags) <= 0)
{
- this.enemy = world;
+ this.enemy = NULL;
this.target_validate_time = time + 0.5;
do_target_scan = 1;
}
}
// No target, just go to idle, do any custom stuff and bail.
- if (this.enemy == world)
+ if (this.enemy == NULL)
{
// Turn & pitch
if(!(this.track_flags & TFL_TRACK_NO))
/*
When .used a turret switch team to activator.team.
- If activator is world, the turret go inactive.
+ If activator is NULL, the turret go inactive.
*/
void turret_use(entity this, entity actor, entity trigger)
{
- LOG_TRACE("Turret ",this.netname, " used by ", actor.classname, "\n");
+ LOG_TRACE("Turret ",this.netname, " used by ", actor.classname);
this.team = actor.team;
if (autocvar_g_turrets_reloadcvars == 1)
{
- FOREACH_ENTITY(IS_TURRET(it), {
+ IL_EACH(g_turrets, true,
+ {
load_unit_settings(it, true);
Turret tur = get_turretinfo(it.m_id);
tur.tr_think(tur, it);
// if tur_head exists, we can assume this turret re-spawned
if(!this.tur_head) {
tur.tr_precache(tur);
+ IL_PUSH(g_turrets, this);
+ IL_PUSH(g_bot_targets, this);
}
- entity e = find(world, classname, "turret_manager");
+ entity e = find(NULL, classname, "turret_manager");
if(!e)
{
e = new(turret_manager);
}
if(!(this.spawnflags & TSF_SUSPENDED))
- WITHSELF(this, builtin_droptofloor());
+ droptofloor(this);
this.netname = tur.netname;
load_unit_settings(this, 0);
this.ammo_recharge *= this.ticrate;
this.solid = SOLID_BBOX;
this.takedamage = DAMAGE_AIM;
- this.movetype = MOVETYPE_NOCLIP;
+ set_movetype(this, MOVETYPE_NOCLIP);
this.view_ofs = '0 0 0';
this.turret_firecheckfunc = turret_firecheck;
this.event_damage = turret_damage;
this.tur_head.owner = this;
this.tur_head.takedamage = DAMAGE_NO;
this.tur_head.solid = SOLID_NOT;
- this.tur_head.movetype = this.movetype;
+ set_movetype(this.tur_head, this.move_movetype);
if(!this.tur_defend)
if(this.target != "")
{
- this.tur_defend = find(world, targetname, this.target);
- if (this.tur_defend == world)
+ this.tur_defend = find(NULL, targetname, this.target);
+ if (this.tur_defend == NULL)
{
this.target = "";
- LOG_TRACE("Turret has invalid defendpoint!\n");
+ LOG_TRACE("Turret has invalid defendpoint!");
}
}