]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
implement W_CalculateSpreadPattern, migrate hagar crylink shotgun
authordrjaska <drjaska83@gmail.com>
Tue, 16 May 2023 23:08:48 +0000 (02:08 +0300)
committerdrjaska <drjaska83@gmail.com>
Tue, 16 May 2023 23:08:48 +0000 (02:08 +0300)
qcsrc/common/weapons/calculations.qc
qcsrc/common/weapons/weapon/crylink.qc
qcsrc/common/weapons/weapon/hagar.qc
qcsrc/common/weapons/weapon/shotgun.qc
qcsrc/common/weapons/weapon/shotgun.qh

index cd2d925bc56004223c86899c0c1b66e07db0c8f5..c3faf1c3cfbe69c8562a5e54ec1c661dd0013367 100644 (file)
@@ -184,6 +184,36 @@ int W_GetGunAlignment(entity player)
 }
 #endif
 
+vector W_CalculateSpreadPattern(int counter, int total, bool returnTransformVector)
+{
+       // first is always centered
+       if (counter == 0)
+               return '0 0 0';
+
+       vector s = '0 0 0';
+
+       // points form a round circle with even distribution
+       // this could be simplified to '0 360 0' * (counter / total)
+       // but it would lose ALL the specific placements
+       // for example with this 2 pellets is center + directly up
+       // while 3 pellets is a horizontal sweep and and 4 is an upside
+       // down Y shape, 5 is a star instead of a pentagram,
+       // 9 is a 3x3 grid and 13 is a circle with center + 3 per quadrant
+       makevectors('0 360 0' * ((0.25 * ((total + 1) % 2)) + (counter / (total - 1))));
+
+       if (returnTransformVector) // return transform vector
+       {
+               s.y = v_forward.x;
+               s.z = v_forward.y;
+       }
+       else // return original result normal vector
+       {
+               s = v_forward;
+       }
+
+       return s;
+}
+
 vector W_CalculateSpread(vector forward, float spread, float spreadfactor, float spreadstyle)
 {
        float sigma;
index ae1eae28459adfb50c468fc37571feb1000e9a69..8660de078815e9d17f478571e06fa7fd6a12c4fb 100644 (file)
@@ -347,16 +347,7 @@ void W_Crylink_Attack(Weapon thiswep, entity actor, .entity weaponentity)
                setorigin(proj, w_shotorg);
                setsize(proj, '0 0 0', '0 0 0');
 
-
-               s = '0 0 0';
-               if(counter == 0)
-                       s = '0 0 0';
-               else
-               {
-                       makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
-                       s.y = v_forward.x;
-                       s.z = v_forward.y;
-               }
+               s = W_CalculateSpreadPattern(counter, shots, true);
                s = s * WEP_CVAR_PRI(crylink, spread) * autocvar_g_weaponspreadfactor;
                W_SetupProjVelocity_Explicit(proj, w_shotdir + right * s.y + up * s.z, v_up, WEP_CVAR_PRI(crylink, speed), 0, 0, 0, false);
                settouch(proj, W_Crylink_Touch);
@@ -462,15 +453,7 @@ void W_Crylink_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
 
                if(WEP_CVAR_SEC(crylink, spreadtype) == 1)
                {
-                       s = '0 0 0';
-                       if(counter == 0)
-                               s = '0 0 0';
-                       else
-                       {
-                               makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
-                               s.y = v_forward.x;
-                               s.z = v_forward.y;
-                       }
+                       s = W_CalculateSpreadPattern(counter, shots, true);
                        s = s * WEP_CVAR_SEC(crylink, spread) * autocvar_g_weaponspreadfactor;
                        s = w_shotdir + right * s.y + up * s.z;
                }
index 725243ee44eead29b7c9f57106dc9c151b7523f2..3002e7cdf9969d5a8c69aaae96d81d4108d7760b 100644 (file)
@@ -223,16 +223,7 @@ void W_Hagar_Attack2_Load_Release(Weapon thiswep, entity actor, .entity weaponen
                spread_pershot = (1 - (spread_pershot * WEP_CVAR_SEC(hagar, load_spread_bias)));
                spread_pershot = (WEP_CVAR_SEC(hagar, spread) * spread_pershot * autocvar_g_weaponspreadfactor);
 
-               // pattern spread calculation
-               s = '0 0 0';
-               if(counter == 0)
-                       s = '0 0 0';
-               else
-               {
-                       makevectors('0 360 0' * ((0.25 * ((shots + 1) % 2)) + (counter / (shots - 1))));
-                       s.y = v_forward.x;
-                       s.z = v_forward.y;
-               }
+               s = W_CalculateSpreadPattern(counter, shots, true);
                s = s * WEP_CVAR_SEC(hagar, load_spread) * autocvar_g_weaponspreadfactor;
 
                W_SetupProjVelocity_Explicit(missile, w_shotdir + right * s.y + up * s.z, v_up, WEP_CVAR_SEC(hagar, speed), 0, 0, spread_pershot, false);
index 65cc0d9d926323840f682a60c5fc046ba1ec7dd7..0985a841c0bc06e6cabfbeb8576eab9531f46455 100644 (file)
@@ -16,8 +16,23 @@ void W_Shotgun_Attack(Weapon thiswep, entity actor, .entity weaponentity, float
        if(lag && bullets > 0)
                antilag_takeback_all(actor, lag);
 
-       for(int sc = 0;sc < bullets;sc = sc + 1)
-               fireBullet_antilag(actor, weaponentity, w_shotorg, w_shotdir, spread, solidpenetration, damage, 0, force, thiswep.m_id, bullet_trail_effect, false);
+       if (WEP_CVAR_PRI(shotgun, spread_fixed) > 0)
+       {
+               vector forward, right, up;
+               forward = v_forward;
+               right = v_right;
+               up = v_up;
+
+               for(int sc = 0; sc < bullets; ++sc)
+               {
+                       vector s = W_CalculateSpreadPattern(sc, bullets, true);
+                       s = s * (WEP_CVAR_PRI(shotgun, spread) / WEP_CVAR_PRI(shotgun, spread_fixed) * autocvar_g_weaponspreadfactor);
+                       fireBullet_antilag(actor, weaponentity, w_shotorg, w_shotdir + right * s.y + up * s.z, 0, solidpenetration, damage, 0, force, thiswep.m_id, bullet_trail_effect, false);
+               }
+       }
+       else
+               for(int sc = 0; sc < bullets; ++sc)
+                       fireBullet_antilag(actor, weaponentity, w_shotorg, w_shotdir, spread, solidpenetration, damage, 0, force, thiswep.m_id, bullet_trail_effect, false);
 
        if(lag && bullets > 0)
                antilag_restore_all(actor);
@@ -28,7 +43,7 @@ void W_Shotgun_Attack(Weapon thiswep, entity actor, .entity weaponentity, float
        if(autocvar_g_casings >= 1)
        {
                makevectors(actor.v_angle); // for some reason, this is lost
-               //for(int sc = 0;sc < WEP_CVAR_PRI(shotgun, ammo);sc = sc + 1)
+               //for(int sc = 0; sc < WEP_CVAR_PRI(shotgun, ammo); ++sc)
                        SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 30) * v_up), vectoangles(v_forward), 1, actor, weaponentity);
        }
 }
index 5b200ed588e0df64bcfb951ab16e6e2ffcfb49e3..979e782303ee6dd7269ebca08a7aa2c36fb68e12 100644 (file)
@@ -39,18 +39,19 @@ CLASS(Shotgun, Weapon)
                P(class, prefix, melee_traces, float, SEC) \
                P(class, prefix, refire, float, BOTH) \
                P(class, prefix, reload_ammo, float, NONE) \
-        P(class, prefix, reload_time, float, NONE) \
+               P(class, prefix, reload_time, float, NONE) \
                P(class, prefix, secondary, float, NONE) \
                P(class, prefix, solidpenetration, float, PRI) \
                P(class, prefix, spread, float, PRI) \
-        P(class, prefix, switchdelay_drop, float, NONE) \
-        P(class, prefix, switchdelay_raise, float, NONE) \
-        P(class, prefix, weaponreplace, string,NONE) \
-        P(class, prefix, weaponstartoverride, float, NONE) \
-        P(class, prefix, weaponstart, float, NONE) \
-        P(class, prefix, weaponthrowable, float, NONE) \
+               P(class, prefix, spread_fixed, float, PRI) \
+               P(class, prefix, switchdelay_drop, float, NONE) \
+               P(class, prefix, switchdelay_raise, float, NONE) \
+               P(class, prefix, weaponreplace, string,NONE) \
+               P(class, prefix, weaponstartoverride, float, NONE) \
+               P(class, prefix, weaponstart, float, NONE) \
+               P(class, prefix, weaponthrowable, float, NONE) \
        END()
-    W_PROPS(X, Shotgun, shotgun)
+       W_PROPS(X, Shotgun, shotgun)
 #undef X
 
 ENDCLASS(Shotgun)