]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/turrets/sv_turrets.qc
Merge branch 'Mario/intrusive' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / sv_turrets.qc
index 1c87cbb45206968fd199ec29af39b2e961b0e8c1..c90eaff1fe98fdb22bc7918fefedd1f28c703738 100644 (file)
@@ -1,3 +1,4 @@
+#include "sv_turrets.qh"
 #ifdef SVQC
 #include <server/autocvars.qh>
 
@@ -32,7 +33,7 @@ vector turret_aim_generic(entity this)
 
                        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;
@@ -186,15 +187,15 @@ void turret_die(entity this)
        this.health                      = 0;
 
 // Go boom
-       //RadiusDamage (this,this, min(this.ammo,50),min(this.ammo,50) * 0.25,250,world,min(this.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(this.m_id);
        if(this.damage_flags & TFL_DMG_DEATH_NORESPAWN)
        {
                tur.tr_death(tur, this);
 
-               remove(this.tur_head);
-               remove(this);
+               delete(this.tur_head);
+               delete(this);
        }
        else
        {
@@ -267,7 +268,7 @@ void turret_respawn(entity this)
        this.tur_head.avelocity         = this.avelocity;
        this.tur_head.angles            = this.idle_aim;
        this.health                                     = this.max_health;
-       this.enemy                                      = world;
+       this.enemy                                      = NULL;
        this.volly_counter                      = this.shot_volly;
        this.ammo                                       = this.ammo_max;
 
@@ -365,7 +366,7 @@ void load_unit_settings(entity ent, bool is_reload)
        string unitname = ent.netname;
        string sbase;
 
-       if (ent == world)
+       if (ent == NULL)
                return;
 
        if(!ent.turret_scale_damage)    ent.turret_scale_damage = 1;
@@ -379,7 +380,7 @@ void load_unit_settings(entity ent, bool is_reload)
        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';
@@ -434,18 +435,18 @@ void turret_projectile_explode(entity this)
        this.event_damage = func_null;
 #ifdef TURRET_DEBUG
        float d;
-       d = RadiusDamage (this, this.owner, this.owner.shot_dmg, 0, this.owner.shot_radius, this, world, this.owner.shot_force, this.totalfrags, world);
+       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 (this, this.realowner, this.owner.shot_dmg, 0, this.owner.shot_radius, this, world, this.owner.shot_force, this.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(this);
+       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);
 }
 
@@ -474,9 +475,11 @@ entity turret_projectile(entity actor, Sound _snd, float _size, float _health, f
        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);
@@ -547,7 +550,7 @@ void turret_track(entity this)
 
        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;
@@ -824,7 +827,7 @@ float turret_validate_target(entity e_turret, entity e_target, float validate_fl
        */
 
 #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;
@@ -844,13 +847,13 @@ entity turret_select_target(entity this)
                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)
        {
@@ -903,7 +906,7 @@ bool turret_firecheck(entity this)
        if (this.firecheck_flags & TFL_FIRECHECK_NO)
                return true;
 
-       if (this.enemy == world)
+       if (this.enemy == NULL)
                return false;
 
        // Ready?
@@ -999,7 +1002,7 @@ void turret_fire(entity this)
                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;
@@ -1061,7 +1064,7 @@ void turret_think(entity this)
 
                        e = e.chain;
                }
-               this.enemy = world;
+               this.enemy = NULL;
        }
        else if(this.shoot_flags & TFL_SHOOT_CUSTOM)
        {
@@ -1118,7 +1121,7 @@ void turret_think(entity this)
                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;
                }
@@ -1134,7 +1137,7 @@ void turret_think(entity this)
                }
 
                // 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))
@@ -1170,11 +1173,11 @@ void turret_think(entity this)
 
 /*
        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;
 
@@ -1199,7 +1202,8 @@ void turrets_manager_think(entity this)
 
        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);
@@ -1248,9 +1252,11 @@ bool turret_initialize(entity this, Turret tur)
        // 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);
@@ -1259,7 +1265,7 @@ bool turret_initialize(entity this, Turret tur)
        }
 
        if(!(this.spawnflags & TSF_SUSPENDED))
-               WITHSELF(this, builtin_droptofloor());
+               droptofloor(this);
 
        this.netname = tur.netname;
        load_unit_settings(this, 0);
@@ -1329,7 +1335,7 @@ bool turret_initialize(entity this, Turret tur)
        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;
@@ -1349,16 +1355,16 @@ bool turret_initialize(entity this, Turret tur)
        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!");
                }
        }