]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/turrets/sv_turrets.qc
Fix up more mutator hooks
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / sv_turrets.qc
index bbd9c990a5c2a238cad410da4195319ce7f35882..be7dbb8aebaa3bd928ea4123d04dff0d8fc2ba4a 100644 (file)
@@ -164,15 +164,15 @@ float turret_targetscore_generic(entity _turret, entity _target)
 }
 
 // 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;
 
@@ -201,7 +201,7 @@ void turret_die()
                // Setup respawn
                self.SendFlags    |= TNSF_STATUS;
                self.nextthink   = time + 0.2;
-               self.think               = turret_hide;
+               setthink(self, turret_hide);
 
                tur.tr_death(tur, self);
        }
@@ -245,15 +245,15 @@ void turret_damage(entity this, entity inflictor, entity attacker, float damage,
                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;
@@ -272,7 +272,7 @@ void turret_respawn()
        self.ammo                                       = self.ammo_max;
 
        self.nextthink = time + self.ticrate;
-       self.think       = turret_think;
+       setthink(self, turret_think);
 
        self.SendFlags = TNSF_FULL_UPDATE;
 
@@ -427,8 +427,8 @@ void load_unit_settings(entity ent, bool is_reload)
        }
 }
 
-void turret_projectile_explode()
-{SELFPARAM();
+void turret_projectile_explode(entity this)
+{
 
        self.takedamage = DAMAGE_NO;
        self.event_damage = func_null;
@@ -443,10 +443,10 @@ void turret_projectile_explode()
        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)
@@ -455,14 +455,15 @@ void turret_projectile_damage(entity this, entity inflictor, entity attacker, fl
        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);
@@ -470,8 +471,8 @@ entity turret_projectile(string _snd, float _size, float _health, float _death,
        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;
@@ -498,39 +499,33 @@ entity turret_projectile(string _snd, float _size, float _health, float _death,
 ** 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;
 }
 
 /**
@@ -709,7 +704,7 @@ float turret_validate_target(entity e_turret, entity e_target, float validate_fl
                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;
@@ -816,7 +811,7 @@ float turret_validate_target(entity e_turret, entity e_target, float validate_fl
 
                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;
        }
 
@@ -976,13 +971,15 @@ float turret_firecheck()
        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()
@@ -1016,8 +1013,8 @@ void turret_fire()
 #endif
 }
 
-void turret_think()
-{SELFPARAM();
+void turret_think(entity this)
+{
        self.nextthink = time + self.ticrate;
 
        MUTATOR_CALLHOOK(TurretThink, self);
@@ -1060,7 +1057,7 @@ void turret_think()
 
                                        turret_do_updates(self);
 
-                                       if (turret_checkfire())
+                                       if (turret_checkfire(self))
                                                turret_fire();
                                }
                        }
@@ -1084,7 +1081,7 @@ void turret_think()
                turret_do_updates(self);
 
                // Fire?
-               if (turret_checkfire())
+               if (turret_checkfire(self))
                        turret_fire();
        }
        else
@@ -1104,7 +1101,7 @@ void turret_think()
                                turret_do_updates(self);
 
                                // Fire!
-                               if (turret_checkfire())
+                               if (turret_checkfire(self))
                                        turret_fire();
 
                                Turret tur = get_turretinfo(self.m_id);
@@ -1166,7 +1163,7 @@ void turret_think()
                turret_do_updates(self);
 
                // Fire?
-               if (turret_checkfire())
+               if (turret_checkfire(self))
                        turret_fire();
        }
 
@@ -1178,39 +1175,38 @@ void turret_think()
        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");
        }
 }
@@ -1261,7 +1257,7 @@ float turret_initialize(Turret tur)
        if(!e)
        {
                e = new(turret_manager);
-               e.think = turrets_manager_think;
+               setthink(e, turrets_manager_think);
                e.nextthink = time + 2;
        }
 
@@ -1376,7 +1372,7 @@ float turret_initialize(Turret tur)
 
 #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);
@@ -1385,7 +1381,7 @@ float turret_initialize(Turret tur)
 #endif
 
        turret_link();
-       turret_respawn();
+       turret_respawn(self);
        turret_tag_fire_update();
 
        tur.tr_setup(tur, self);