]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_crylink.qc
Merge remote branch 'origin/master' into samual/keepaway
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_crylink.qc
index a4f4d6b35b14526e1e38e40ffae896a11ed62d53..07100c7784966e13e672a250b55dbb1dde0708d5 100644 (file)
@@ -44,69 +44,84 @@ void W_Crylink_LinkExplode (entity e, entity e2)
 // stored in w_crylink_linkjoin_time.
 // could possibly network this origin and time, and display a special particle
 // effect when projectiles meet there :P
+// jspeed: MINIMUM jing speed
+// jtime: MAXIMUM jing time (0: none)
 float w_crylink_linkjoin_time;
-vector W_Crylink_LinkJoin(entity e, float joinspeed)
+vector W_Crylink_LinkJoin(entity e, float jspeed, float jtime)
 {
        vector avg_origin, avg_velocity;
        vector targ_origin;
        float avg_dist, n;
        entity p;
 
+       w_crylink_linkjoin_time = 0;
+
        avg_origin = e.origin;
        avg_velocity = e.velocity;
        n = 1;
        for(p = e; (p = p.queuenext) != e; )
        {
-               avg_origin += p.origin;
-               avg_velocity += p.velocity;
+               avg_origin += WarpZone_RefSys_TransformOrigin(p, e, p.origin);
+               avg_velocity += WarpZone_RefSys_TransformVelocity(p, e, p.velocity);
                ++n;
        }
        avg_origin *= (1.0 / n);
        avg_velocity *= (1.0 / n);
 
+       if(n < 2)
+               return avg_origin; // nothing to do
+
        // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
        avg_dist = pow(vlen(e.origin - avg_origin), 2);
        for(p = e; (p = p.queuenext) != e; )
-               avg_dist += pow(vlen(e.origin - avg_origin), 2);
+               avg_dist += pow(vlen(WarpZone_RefSys_TransformOrigin(p, e, p.origin) - avg_origin), 2);
        avg_dist *= (1.0 / n);
+       avg_dist = sqrt(avg_dist);
 
-       w_crylink_linkjoin_time = 0;
        if(avg_dist == 0)
                return avg_origin; // no change needed
 
-       if(joinspeed == 0)
+       if(jspeed == 0 && jtime == 0)
        {
                e.velocity = avg_velocity;
                UpdateCSQCProjectile(e);
                for(p = e; (p = p.queuenext) != e; )
                {
-                       p.velocity = avg_velocity;
+                       p.velocity = WarpZone_RefSys_TransformVelocity(e, p, avg_velocity);
                        UpdateCSQCProjectile(p);
                }
        }
        else
        {
-               w_crylink_linkjoin_time = avg_dist / joinspeed;
+               if(jtime)
+               {
+                       if(jspeed)
+                               w_crylink_linkjoin_time = min(jtime, avg_dist / jspeed);
+                       else
+                               w_crylink_linkjoin_time = jtime;
+               }
+               else
+                       w_crylink_linkjoin_time = avg_dist / jspeed;
                targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
 
-               e.velocity = (targ_origin - e.origin) * (joinspeed / avg_dist);
+               e.velocity = (targ_origin - e.origin) * (1.0 / w_crylink_linkjoin_time);
                UpdateCSQCProjectile(e);
                for(p = e; (p = p.queuenext) != e; )
                {
-                       p.velocity = (targ_origin - p.origin) * (joinspeed / avg_dist);
+                       p.velocity = WarpZone_RefSys_TransformVelocity(e, p, (targ_origin - WarpZone_RefSys_TransformOrigin(p, e, p.origin)) * (1.0 / w_crylink_linkjoin_time));
                        UpdateCSQCProjectile(p);
                }
 
                // analysis:
-               //   joinspeed -> +infinity:
+               //   jspeed -> +infinity:
                //      w_crylink_linkjoin_time -> +0
                //      targ_origin -> avg_origin
                //      p->velocity -> HUEG towards center
-               //   joinspeed -> 0:
+               //   jspeed -> 0:
                //      w_crylink_linkjoin_time -> +/- infinity
                //      targ_origin -> avg_velocity * +/- infinity
                //      p->velocity -> avg_velocity
-               //   joinspeed -> -infinity:
+               //   jspeed -> -infinity:
                //      w_crylink_linkjoin_time -> -0
                //      targ_origin -> avg_origin
                //      p->velocity -> HUEG away from center
@@ -115,6 +130,56 @@ vector W_Crylink_LinkJoin(entity e, float joinspeed)
        return targ_origin;
 }
 
+void W_Crylink_LinkJoinEffect_Think()
+{
+       // is there at least 2 projectiles very close?
+       entity e, p;
+       float n;
+       e = self.owner.crylink_lastgroup;
+       n = 0;
+       if(e)
+       {
+               if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
+                       ++n;
+               for(p = e; (p = p.queuenext) != e; )
+               {
+                       if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
+                               ++n;
+               }
+               if(n >= 2)
+               {
+                       if(e.projectiledeathtype & HITTYPE_SECONDARY)
+                       {
+                               if(cvar("g_balance_crylink_secondary_joinexplode"))
+                               {
+                                       n = n / cvar("g_balance_crylink_secondary_shots");
+                                       RadiusDamage (e, e.realowner, cvar("g_balance_crylink_secondary_joinexplode_damage") * n, 
+                                                                       cvar("g_balance_crylink_secondary_joinexplode_edgedamage") * n, 
+                                                                       cvar("g_balance_crylink_secondary_joinexplode_radius") * n, e.realowner, 
+                                                                       cvar("g_balance_crylink_secondary_joinexplode_force") * n, e.projectiledeathtype, other);
+
+                                       pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
+                               }                               
+                       }
+                       else
+                       {
+                               if(cvar("g_balance_crylink_primary_joinexplode"))
+                               {
+                                       n = n / cvar("g_balance_crylink_primary_shots");
+                                       RadiusDamage (e, e.realowner, cvar("g_balance_crylink_primary_joinexplode_damage") * n, 
+                                                                       cvar("g_balance_crylink_primary_joinexplode_edgedamage") * n, 
+                                                                       cvar("g_balance_crylink_primary_joinexplode_radius") * n, e.realowner, 
+                                                                       cvar("g_balance_crylink_primary_joinexplode_force") * n, e.projectiledeathtype, other);
+
+                                       pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
+                               }                               
+                       }                       
+               }
+       }
+       remove(self);
+}
+
+
 // NO bounce protection, as bounces are limited!
 void W_Crylink_Touch (void)
 {
@@ -142,14 +207,21 @@ void W_Crylink_Touch (void)
                f = cvar("g_balance_crylink_primary_bouncedamagefactor");
        if(a)
                f *= a;
-       if (RadiusDamage (self, self.realowner, cvar("g_balance_crylink_primary_damage") * f, cvar("g_balance_crylink_primary_edgedamage") * f, cvar("g_balance_crylink_primary_radius"), world, cvar("g_balance_crylink_primary_force") * f, self.projectiledeathtype, other) || finalhit)
+       if (RadiusDamage (self, self.realowner, cvar("g_balance_crylink_primary_damage") * f, cvar("g_balance_crylink_primary_edgedamage") * f, cvar("g_balance_crylink_primary_radius"), world, cvar("g_balance_crylink_primary_force") * f, self.projectiledeathtype, other) && cvar("g_balance_crylink_primary_linkexplode"))
        {
                W_Crylink_LinkExplode(self.queuenext, self);
                remove (self);
                return;
        }
+       else if(finalhit)
+       {
+               // just unlink
+               W_Crylink_Dequeue(self);
+               remove(self);
+               return;
+       }
        self.cnt = self.cnt - 1;
-       // self.angles = vectoangles(self.velocity); // csqc
+       self.angles = vectoangles(self.velocity);
        self.owner = world;
        self.projectiledeathtype |= HITTYPE_BOUNCE;
        // commented out as it causes a little hitch...
@@ -183,7 +255,7 @@ void W_Crylink_Touch2 (void)
                f = cvar("g_balance_crylink_secondary_bouncedamagefactor");
        if(a)
                f *= a;
-       if (RadiusDamage (self, self.realowner, cvar("g_balance_crylink_secondary_damage") * f, cvar("g_balance_crylink_secondary_edgedamage") * f, cvar("g_balance_crylink_secondary_radius"), world, cvar("g_balance_crylink_secondary_force") * f, self.projectiledeathtype, other))
+       if (RadiusDamage (self, self.realowner, cvar("g_balance_crylink_secondary_damage") * f, cvar("g_balance_crylink_secondary_edgedamage") * f, cvar("g_balance_crylink_secondary_radius"), world, cvar("g_balance_crylink_secondary_force") * f, self.projectiledeathtype, other) && cvar("g_balance_crylink_secondary_linkexplode"))
        {
                W_Crylink_LinkExplode(self.queuenext, self);
                remove (self);
@@ -197,7 +269,7 @@ void W_Crylink_Touch2 (void)
                return;
        }
        self.cnt = self.cnt - 1;
-       // self.angles = vectoangles(self.velocity); // csqc
+       self.angles = vectoangles(self.velocity);
        self.owner = world;
        self.projectiledeathtype |= HITTYPE_BOUNCE;
        // commented out as it causes a little hitch...
@@ -213,9 +285,10 @@ void W_Crylink_Fadethink (void)
 
 void W_Crylink_Attack (void)
 {
-       float counter, shots;
-       entity proj, prevproj, firstproj;
-       vector forward, right, up, s
+       local float counter, shots;
+       local entity proj, prevproj, firstproj;
+       local vector s;
+       vector forward, right, up;
 
        if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
                self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
@@ -235,7 +308,11 @@ void W_Crylink_Attack (void)
                proj.classname = "spike";
                proj.bot_dodge = TRUE;
                proj.bot_dodgerating = cvar("g_balance_crylink_primary_damage");
-               if(counter == 0) { // first projectile, store in firstproj for now
+               if(shots == 1) {
+                       proj.queuenext = proj;
+                       proj.queueprev = proj;
+               }
+               else if(counter == 0) { // first projectile, store in firstproj for now
                        firstproj = proj;
                }
                else if(counter == shots - 1) { // last projectile, link up with first projectile
@@ -270,32 +347,27 @@ void W_Crylink_Attack (void)
                        s_z = v_forward_y;
                }
                s = s * cvar("g_balance_crylink_primary_spread") * g_weaponspreadfactor;
-               W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_crylink_primary_speed"), 0, 0, 0);
+               W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_crylink_primary_speed"), 0, 0, 0, FALSE);
                proj.touch = W_Crylink_Touch;
 
                proj.think = W_Crylink_Fadethink;
                if(counter == 0)
                {
                        proj.fade_time = time + cvar("g_balance_crylink_primary_middle_lifetime");
-                       self.fade_rate = 1 / cvar("g_balance_crylink_primary_middle_fadetime");
+                       proj.fade_rate = 1 / cvar("g_balance_crylink_primary_middle_fadetime");
                        proj.nextthink = time + cvar("g_balance_crylink_primary_middle_lifetime") + cvar("g_balance_crylink_primary_middle_fadetime");
                }
-               else if(counter <= 3)
-               {
-                       proj.fade_time = time + cvar("g_balance_crylink_primary_star_lifetime");
-                       self.fade_rate = 1 / cvar("g_balance_crylink_primary_star_fadetime");
-                       proj.nextthink = time + cvar("g_balance_crylink_primary_star_lifetime") + cvar("g_balance_crylink_primary_star_fadetime");
-               }
                else
                {
                        proj.fade_time = time + cvar("g_balance_crylink_primary_other_lifetime");
-                       self.fade_rate = 1 / cvar("g_balance_crylink_primary_other_fadetime");
+                       proj.fade_rate = 1 / cvar("g_balance_crylink_primary_other_fadetime");
                        proj.nextthink = time + cvar("g_balance_crylink_primary_other_lifetime") + cvar("g_balance_crylink_primary_other_fadetime");
                }
                proj.cnt = cvar("g_balance_crylink_primary_bounces");
-               
                //proj.scale = 1 + 1 * proj.cnt;
-               //proj.angles = vectoangles (proj.velocity); // csqc
+
+               proj.angles = vectoangles (proj.velocity);
+
                //proj.glow_size = 20;
 
                proj.flags = FL_PROJECTILE;
@@ -329,7 +401,11 @@ void W_Crylink_Attack2 (void)
                proj.classname = "spike";
                proj.bot_dodge = TRUE;
                proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
-               if(counter == 0) { // first projectile, store in firstproj for now
+               if(shots == 1) {
+                       proj.queuenext = proj;
+                       proj.queueprev = proj;
+               }
+               else if(counter == 0) { // first projectile, store in firstproj for now
                        firstproj = proj;
                }
                else if(counter == shots - 1) { // last projectile, link up with first projectile
@@ -353,25 +429,25 @@ void W_Crylink_Attack2 (void)
                setorigin (proj, w_shotorg);
                setsize(proj, '0 0 0', '0 0 0');
 
-               W_SetupProjectileVelocityEx(proj, (w_shotdir + (((counter + 0.5) / shots) * 2 - 1) * v_right * cvar("g_balance_crylink_secondary_spread") * g_weaponspreadfactor), v_up, cvar("g_balance_crylink_secondary_speed"), 0, 0, 0);
+               W_SetupProjectileVelocityEx(proj, (w_shotdir + (((counter + 0.5) / shots) * 2 - 1) * v_right * cvar("g_balance_crylink_secondary_spread") * g_weaponspreadfactor), v_up, cvar("g_balance_crylink_secondary_speed"), 0, 0, 0, FALSE);
                proj.touch = W_Crylink_Touch2;
                proj.think = W_Crylink_Fadethink;
                if(counter == (shots - 1) / 2)
                {
                        proj.fade_time = time + cvar("g_balance_crylink_secondary_middle_lifetime");
-                       self.fade_rate = 1 / cvar("g_balance_crylink_secondary_middle_fadetime");
+                       proj.fade_rate = 1 / cvar("g_balance_crylink_secondary_middle_fadetime");
                        proj.nextthink = time + cvar("g_balance_crylink_secondary_middle_lifetime") + cvar("g_balance_crylink_secondary_middle_fadetime");
                }
                else
                {
                        proj.fade_time = time + cvar("g_balance_crylink_secondary_line_lifetime");
-                       self.fade_rate = 1 / cvar("g_balance_crylink_secondary_line_fadetime");
+                       proj.fade_rate = 1 / cvar("g_balance_crylink_secondary_line_fadetime");
                        proj.nextthink = time + cvar("g_balance_crylink_secondary_line_lifetime") + cvar("g_balance_crylink_secondary_line_fadetime");
                }
                proj.cnt = cvar("g_balance_crylink_secondary_bounces");
                //proj.scale = 1 + 1 * proj.cnt;
 
-               // proj.angles = vectoangles (proj.velocity); // csqc
+               proj.angles = vectoangles (proj.velocity);
 
                //proj.glow_size = 20;
 
@@ -409,17 +485,18 @@ float w_crylink(float req)
                        {
                                W_Crylink_Attack();
                                weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
-                               if(cvar("g_balance_crylink_primary_joinspeed") != 0)
+                               if(cvar("g_balance_crylink_primary_joinspread") != 0 || cvar("g_balance_crylink_primary_jointime") != 0)
                                        self.crylink_waitrelease = 1;
-                       }               
+                       }
                }
                else if(self.BUTTON_ATCK2 && cvar("g_balance_crylink_secondary"))
                {
+                       if (!self.crylink_waitrelease)
                        if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
                        {
                                W_Crylink_Attack2();
                                weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
-                               if(cvar("g_balance_crylink_secondary_joinspeed") != 0)
+                               if(cvar("g_balance_crylink_secondary_joinspread") != 0 || cvar("g_balance_crylink_secondary_jointime") != 0)
                                        self.crylink_waitrelease = 2;
                        }
                }
@@ -430,23 +507,37 @@ float w_crylink(float req)
                                // fired and released now!
                                if(self.crylink_lastgroup)
                                {
+                                       vector pos;
+                                       entity linkjoineffect;
+                                       
+                                       
                                        if(self.crylink_waitrelease == 1)
                                        {
-                                               W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_primary_joinspeed"));                                                
-                                               
-                                               // 'splode @ join, if timing is just right, you get the target with the join-explode splash first, then the individual projectile's damage.
-                                               self.crylink_lastgroup.think = W_Crylink_Touch;
-                                               self.crylink_lastgroup.nextthink = w_crylink_linkjoin_time + time;                                                      
+                                               pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_primary_joinspread") * cvar("g_balance_crylink_primary_speed"), cvar("g_balance_crylink_primary_jointime"));
                                                
                                        }
                                        else
                                        {
-                                               W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_secondary_joinspeed"));
+                                               pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_secondary_joinspread") * cvar("g_balance_crylink_secondary_speed"), cvar("g_balance_crylink_secondary_jointime"));
                                        }
+                                       
+                                       linkjoineffect = spawn();
+                                       linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
+                                       linkjoineffect.classname = "linkjoineffect";                                    
+                                       linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
+                                       linkjoineffect.owner = self;
+                                       setorigin(linkjoineffect, pos);
+
+
+                               }
+                               self.crylink_waitrelease = 0;
+                               if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
+                               {
+                                       // ran out of ammo!
+                                       self.cnt = WEP_CRYLINK;
+                                       self.switchweapon = w_getbestweapon(self);
                                }
                        }
-
-                       self.crylink_waitrelease = 0;
                }
        }
        else if (req == WR_PRECACHE)
@@ -456,13 +547,24 @@ float w_crylink(float req)
                precache_model ("models/weapons/h_crylink.iqm");
                precache_sound ("weapons/crylink_fire.wav");
                precache_sound ("weapons/crylink_fire2.wav");
+               precache_sound ("weapons/crylink_linkjoin.wav");
        }
        else if (req == WR_SETUP)
                weapon_setup(WEP_CRYLINK);
        else if (req == WR_CHECKAMMO1)
+       {
+               // don't "run out of ammo" and switch weapons while waiting for release
+               if(self.crylink_lastgroup && self.crylink_waitrelease)
+                       return TRUE;
                return self.ammo_cells >= cvar("g_balance_crylink_primary_ammo");
+       }
        else if (req == WR_CHECKAMMO2)
+       {
+               // don't "run out of ammo" and switch weapons while waiting for release
+               if(self.crylink_lastgroup && self.crylink_waitrelease)
+                       return TRUE;
                return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
+       }
        return TRUE;
 };
 #endif