]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/nades/nades.qc
Nades code: don't use booleans as array indexes for m_projectile, optimize spawn_held...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / nades / nades.qc
index 9bd55333746a18a7a62368b85aa6562cf10ddb9f..d44e649f2ebb6c76dd2d8739dfda777c200d7144 100644 (file)
@@ -24,7 +24,7 @@ entity Nade_TrailEffect(int proj, int nade_team)
     }
 
     FOREACH(Nades, true, {
-        for (int j = 0; j < 2; j++)
+        for (int j = 0; j < 2; ++j)
         {
             if (it.m_projectile[j] == proj)
             {
@@ -37,6 +37,7 @@ entity Nade_TrailEffect(int proj, int nade_team)
 
     return EFFECT_Null;
 }
+
 #endif
 
 #ifdef CSQC
@@ -92,6 +93,8 @@ MUTATOR_HOOKFUNCTION(cl_nades, Ent_Projectile)
 }
 MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile)
 {
+       if (!mut_is_active(MUT_NADES)) return;
+
        entity proj = M_ARGV(0, entity);
 
        if (proj.cnt == PROJECTILE_NAPALM_FOUNTAIN)
@@ -103,6 +106,7 @@ MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile)
 
        entity nade_type = Nade_FromProjectile(proj.cnt);
        if (nade_type == NADE_TYPE_Null) return;
+
        if(STAT(NADES_SMALL))
        {
                proj.mins = '-8 -8 -8';
@@ -200,7 +204,7 @@ void nade_timer_think(entity this)
 
 void nade_burn_spawn(entity _nade)
 {
-       CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[true], true);
+       CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[1], true);
 }
 
 void nade_spawn(entity _nade)
@@ -218,7 +222,7 @@ void nade_spawn(entity _nade)
 
        _nade.effects |= EF_LOWPRECISION;
 
-       CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[false], true);
+       CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[0], true);
 }
 
 void normal_nade_boom(entity this)
@@ -382,7 +386,7 @@ void napalm_fountain_think(entity this)
 
 void nade_napalm_boom(entity this)
 {
-       for (int c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
+       for (int c = 0; c < autocvar_g_nades_napalm_ball_count; ++c)
                nade_napalm_ball(this);
 
        entity fountain = new(nade_napalm_fountain);
@@ -1257,7 +1261,7 @@ bool nade_customize(entity this, entity client)
                if(!this.traileffectnum)
                {
                        entity nade = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this));
-                       this.traileffectnum = _particleeffectnum(Nade_TrailEffect(nade.m_projectile[false], this.team).eent_eff_name);
+                       this.traileffectnum = _particleeffectnum(Nade_TrailEffect(nade.m_projectile[0], this.team).eent_eff_name);
                }
                this.alpha = 1;
        }
@@ -1269,11 +1273,13 @@ void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, strin
 {
        entity n = new(nade), fn = new(fake_nade);
 
-       STAT(NADE_BONUS_TYPE, n) = max(1, ntype);
        n.pokenade_type = pntype;
 
-       if(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)) == NADE_TYPE_Null)
-               STAT(NADE_BONUS_TYPE, n) = NADE_TYPE_NORMAL.m_id;
+       Nade def = REGISTRY_GET(Nades, max(1, ntype));
+       if(def == NADE_TYPE_Null)
+               def = NADE_TYPE_NORMAL;
+
+       STAT(NADE_BONUS_TYPE, n) = def.m_id;
 
        .entity weaponentity = weaponentities[0]; // TODO: unhardcode
 
@@ -1281,8 +1287,8 @@ void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, strin
        //setattachment(n, player, "bip01 l hand");
        n.exteriormodeltoclient = player;
        setcefc(n, nade_customize);
-       n.traileffectnum = _particleeffectnum(Nade_TrailEffect(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_projectile[false], player.team).eent_eff_name);
-       n.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
+       n.traileffectnum = _particleeffectnum(Nade_TrailEffect(def.m_projectile[0], player.team).eent_eff_name);
+       n.colormod = def.m_color;
        n.realowner = nowner;
        n.colormap = player.colormap;
        n.glowmod = player.glowmod;
@@ -1293,19 +1299,19 @@ void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, strin
        n.projectiledeathtype = DEATH_NADE.m_id;
        n.weaponentity_fld = weaponentity;
        n.nade_lifetime = ntime;
-       n.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
+       n.alpha = def.m_alpha;
 
        setmodel(fn, MDL_NADE_VIEW);
        //setattachment(fn, player.(weaponentity), "");
        fn.viewmodelforclient = player;
        fn.realowner = fn.owner = player;
-       fn.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color;
+       fn.colormod = def.m_color;
        fn.colormap = player.colormap;
        fn.glowmod = player.glowmod;
        setthink(fn, SUB_Remove);
        fn.nextthink = n.wait;
        fn.weaponentity_fld = weaponentity;
-       fn.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha;
+       fn.alpha = def.m_alpha;
 
        player.nade = n;
        player.fake_nade = fn;
@@ -1641,9 +1647,13 @@ MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
 {
        entity player = M_ARGV(0, entity);
 
-       player.nade_refire = (autocvar_g_nades_onspawn) 
-               ? time + autocvar_g_nades_nade_refire 
-               : time + autocvar_g_spawnshieldtime;
+       if (StatusEffects_active(STATUSEFFECT_SpawnShield, player))
+               player.nade_refire = StatusEffects_gettime(STATUSEFFECT_SpawnShield, player);
+       else
+               player.nade_refire = time;
+
+       if (!autocvar_g_nades_onspawn)
+               player.nade_refire += autocvar_g_nades_nade_refire;
 
        if(autocvar_g_nades_bonus_client_select)
                STAT(NADE_BONUS_TYPE, player) = CS_CVAR(player).cvar_cl_nade_type;