]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Give nades random spread, also fix "amazing" announcement for shooting them
authorMario <mario@smbclan.net>
Mon, 18 Apr 2016 05:41:03 +0000 (15:41 +1000)
committerMario <mario@smbclan.net>
Mon, 18 Apr 2016 05:41:03 +0000 (15:41 +1000)
mutators.cfg
qcsrc/common/mutators/mutator/instagib/instagib.qc
qcsrc/common/mutators/mutator/nades/nades.qc
qcsrc/common/weapons/calculations.qc

index 26132baefad9cfa06456b3abd6e518b32ad9e576..0f49665424d3d5a0f8af9bdaa483bb088baa1525 100644 (file)
@@ -181,6 +181,7 @@ set g_random_gravity_negative 1000 "negative gravity multiplier"
 //  Nades
 // =======
 set g_nades 0 "enable off-hand grenades"
+set g_nades_spread 0.04 "random spread offset of throw direction"
 set g_nades_throw_offset "0 0 0" "nade throwing offset"
 set g_nades_spawn 1 "give nades right away when player spawns rather than delaying entire refire"
 set g_nades_client_select 0 "allow client side selection of nade type"
index 7b0aed460f9a885aafe5ad1b16cff690a01448f7..ec11970fed3519536b2076f8d9cee51e3a286df7 100644 (file)
@@ -337,6 +337,7 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_Calculate)
        }
 
        if(frag_target.alpha && frag_target.alpha < 1)
+       if(IS_PLAYER(frag_target))
                yoda = 1;
 
        return false;
index 8d17edb0b6c164b7114bf24b551b16c396bb7065..44847f27de94043bdde6e02921a4f3c6c288c81a 100644 (file)
@@ -4,6 +4,7 @@
 
 #ifdef SVQC
 bool autocvar_g_nades_nade_small;
+float autocvar_g_nades_spread = 0.04;
 #endif
 
 REGISTER_STAT(NADES_SMALL, int, autocvar_g_nades_nade_small)
@@ -1068,7 +1069,9 @@ void nades_CheckThrow()
                        float _force = time - held_nade.nade_time_primed;
                        _force /= autocvar_g_nades_nade_lifetime;
                        _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
-                       toss_nade(self, true, (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05) * _force, 0);
+                       vector dir = (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05);
+                       dir = W_CalculateSpread(dir, autocvar_g_nades_spread, g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
+                       toss_nade(self, true, dir * _force, 0);
                }
        }
 }
@@ -1122,7 +1125,9 @@ CLASS(NadeOffhand, OffhandWeapon)
                                float _force = time - held_nade.nade_time_primed;
                                _force /= autocvar_g_nades_nade_lifetime;
                                _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
-                               toss_nade(player, false, (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1) * _force, 0);
+                               vector dir = (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1);
+                               dir = W_CalculateSpread(dir, autocvar_g_nades_spread, g_weaponspreadfactor, autocvar_g_projectiles_spread_style);
+                               toss_nade(player, false, dir * _force, 0);
                        }
                }
     }
index 1a4888434cccc287d0dd4c690d062024166b64cf..e8307f39d20068151236b4e26d9155c820d61d2f 100644 (file)
@@ -157,104 +157,106 @@ vector W_CalculateSpread(vector forward, float spread, float spreadfactor, float
        float sigma;
        vector v1 = '0 0 0', v2;
        float dx, dy, r;
-       float sstyle;
        spread *= spreadfactor; //g_weaponspreadfactor;
        if(spread <= 0)
                return forward;
-       sstyle = spreadstyle; //autocvar_g_projectiles_spread_style;
 
-       if(sstyle == 0)
+       switch(spreadstyle)
        {
-               // this is the baseline for the spread value!
-               // standard deviation: sqrt(2/5)
-               // density function: sqrt(1-r^2)
-               return forward + randomvec() * spread;
+               case 0:
+               {
+                       // this is the baseline for the spread value!
+                       // standard deviation: sqrt(2/5)
+                       // density function: sqrt(1-r^2)
+                       return forward + randomvec() * spread;
+               }
+               case 1:
+               {
+                       // same thing, basically
+                       return normalize(forward + cliptoplane(randomvec() * spread, forward));
+               }
+               case 2:
+               {
+                       // circle spread... has at sigma=1 a standard deviation of sqrt(1/2)
+                       sigma = spread * 0.89442719099991587855; // match baseline stddev
+                       v1 = findperpendicular(forward);
+                       v2 = cross(forward, v1);
+                       // random point on unit circle
+                       dx = random() * 2 * M_PI;
+                       dy = sin(dx);
+                       dx = cos(dx);
+                       // radius in our dist function
+                       r = random();
+                       r = sqrt(r);
+                       return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
+               }
+               case 3: // gauss 3d
+               {
+                       sigma = spread * 0.44721359549996; // match baseline stddev
+                       // note: 2D gaussian has sqrt(2) times the stddev of 1D, so this factor is right
+                       v1 = forward;
+                       v1_x += gsl_ran_gaussian(sigma);
+                       v1_y += gsl_ran_gaussian(sigma);
+                       v1_z += gsl_ran_gaussian(sigma);
+                       return v1;
+               }
+               case 4: // gauss 2d
+               {
+                       sigma = spread * 0.44721359549996; // match baseline stddev
+                       // note: 2D gaussian has sqrt(2) times the stddev of 1D, so this factor is right
+                       v1_x = gsl_ran_gaussian(sigma);
+                       v1_y = gsl_ran_gaussian(sigma);
+                       v1_z = gsl_ran_gaussian(sigma);
+                       return normalize(forward + cliptoplane(v1, forward));
+               }
+               case 5: // 1-r
+               {
+                       sigma = spread * 1.154700538379252; // match baseline stddev
+                       v1 = findperpendicular(forward);
+                       v2 = cross(forward, v1);
+                       // random point on unit circle
+                       dx = random() * 2 * M_PI;
+                       dy = sin(dx);
+                       dx = cos(dx);
+                       // radius in our dist function
+                       r = random();
+                       r = solve_cubic_abcd(-2, 3, 0, -r) * '0 1 0';
+                       return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
+               }
+               case 6: // 1-r^2
+               {
+                       sigma = spread * 1.095445115010332; // match baseline stddev
+                       v1 = findperpendicular(forward);
+                       v2 = cross(forward, v1);
+                       // random point on unit circle
+                       dx = random() * 2 * M_PI;
+                       dy = sin(dx);
+                       dx = cos(dx);
+                       // radius in our dist function
+                       r = random();
+                       r = sqrt(1 - r);
+                       r = sqrt(1 - r);
+                       return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
+               }
+               case 7: // (1-r) (2-r)
+               {
+                       sigma = spread * 1.224744871391589; // match baseline stddev
+                       v1 = findperpendicular(forward);
+                       v2 = cross(forward, v1);
+                       // random point on unit circle
+                       dx = random() * 2 * M_PI;
+                       dy = sin(dx);
+                       dx = cos(dx);
+                       // radius in our dist function
+                       r = random();
+                       r = 1 - sqrt(r);
+                       r = 1 - sqrt(r);
+                       return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
+               }
+               default:
+                       error("g_projectiles_spread_style must be 0 (sphere), 1 (flattened sphere), 2 (circle), 3 (gauss 3D), 4 (gauss plane), 5 (linear falloff), 6 (quadratic falloff), 7 (stronger falloff)!");
        }
-       else if(sstyle == 1)
-       {
-               // same thing, basically
-               return normalize(forward + cliptoplane(randomvec() * spread, forward));
-       }
-       else if(sstyle == 2)
-       {
-               // circle spread... has at sigma=1 a standard deviation of sqrt(1/2)
-               sigma = spread * 0.89442719099991587855; // match baseline stddev
-               v1 = findperpendicular(forward);
-               v2 = cross(forward, v1);
-               // random point on unit circle
-               dx = random() * 2 * M_PI;
-               dy = sin(dx);
-               dx = cos(dx);
-               // radius in our dist function
-               r = random();
-               r = sqrt(r);
-               return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
-       }
-       else if(sstyle == 3) // gauss 3d
-       {
-               sigma = spread * 0.44721359549996; // match baseline stddev
-               // note: 2D gaussian has sqrt(2) times the stddev of 1D, so this factor is right
-               v1 = forward;
-               v1_x += gsl_ran_gaussian(sigma);
-               v1_y += gsl_ran_gaussian(sigma);
-               v1_z += gsl_ran_gaussian(sigma);
-               return v1;
-       }
-       else if(sstyle == 4) // gauss 2d
-       {
-               sigma = spread * 0.44721359549996; // match baseline stddev
-               // note: 2D gaussian has sqrt(2) times the stddev of 1D, so this factor is right
-               v1_x = gsl_ran_gaussian(sigma);
-               v1_y = gsl_ran_gaussian(sigma);
-               v1_z = gsl_ran_gaussian(sigma);
-               return normalize(forward + cliptoplane(v1, forward));
-       }
-       else if(sstyle == 5) // 1-r
-       {
-               sigma = spread * 1.154700538379252; // match baseline stddev
-               v1 = findperpendicular(forward);
-               v2 = cross(forward, v1);
-               // random point on unit circle
-               dx = random() * 2 * M_PI;
-               dy = sin(dx);
-               dx = cos(dx);
-               // radius in our dist function
-               r = random();
-               r = solve_cubic_abcd(-2, 3, 0, -r) * '0 1 0';
-               return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
-       }
-       else if(sstyle == 6) // 1-r^2
-       {
-               sigma = spread * 1.095445115010332; // match baseline stddev
-               v1 = findperpendicular(forward);
-               v2 = cross(forward, v1);
-               // random point on unit circle
-               dx = random() * 2 * M_PI;
-               dy = sin(dx);
-               dx = cos(dx);
-               // radius in our dist function
-               r = random();
-               r = sqrt(1 - r);
-               r = sqrt(1 - r);
-               return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
-       }
-       else if(sstyle == 7) // (1-r) (2-r)
-       {
-               sigma = spread * 1.224744871391589; // match baseline stddev
-               v1 = findperpendicular(forward);
-               v2 = cross(forward, v1);
-               // random point on unit circle
-               dx = random() * 2 * M_PI;
-               dy = sin(dx);
-               dx = cos(dx);
-               // radius in our dist function
-               r = random();
-               r = 1 - sqrt(r);
-               r = 1 - sqrt(r);
-               return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
-       }
-       else
-               error("g_projectiles_spread_style must be 0 (sphere), 1 (flattened sphere), 2 (circle), 3 (gauss 3D), 4 (gauss plane), 5 (linear falloff), 6 (quadratic falloff), 7 (stronger falloff)!");
+               
        return '0 0 0';
        /*
         * how to derive falloff functions: