]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_crylink.qc
Merge branch 'master' into mirceakitsune/universal_reload_system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_crylink.qc
index d1f4e5d5ecc9b04852885fb5c26f1809bc820374..d45edbbed7bc58bc2962eb0cb9af48b186569936 100644 (file)
@@ -1,5 +1,5 @@
 #ifdef REGISTER_WEAPON
-REGISTER_WEAPON(CRYLINK, w_crylink, IT_CELLS, 6, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "crylink", "crylink", "Crylink");
+REGISTER_WEAPON(CRYLINK, w_crylink, IT_CELLS, 6, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "crylink", "crylink", _("Crylink"));
 #else
 #ifdef SVQC
 .float gravity;
@@ -9,6 +9,61 @@ REGISTER_WEAPON(CRYLINK, w_crylink, IT_CELLS, 6, WEP_FLAG_NORMAL | WEP_TYPE_SPLA
 .entity queuenext;
 .entity queueprev;
 
+// weapon load persistence, for weapons that support reloading
+.float crylink_load;
+
+void W_Crylink_SetAmmoCounter()
+{
+       // set clip_load to the weapon we have switched to, if the gun uses reloading
+       if(!autocvar_g_balance_crylink_reload_ammo)
+               self.clip_load = 0; // also keeps crosshair ammo from displaying
+       else
+       {
+               self.clip_load = self.crylink_load;
+               self.clip_size = autocvar_g_balance_crylink_reload_ammo; // for the crosshair ammo display
+       }
+}
+
+void W_Crylink_ReloadedAndReady()
+{
+       float t;
+
+       // now do the ammo transfer
+       self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
+       while(self.clip_load < autocvar_g_balance_crylink_reload_ammo && self.ammo_cells) // make sure we don't add more ammo than we have
+       {
+               self.clip_load += 1;
+               self.ammo_cells -= 1;
+       }
+       self.crylink_load = self.clip_load;
+
+       t = ATTACK_FINISHED(self) - autocvar_g_balance_crylink_reload_time - 1;
+       ATTACK_FINISHED(self) = t;
+       w_ready();
+}
+
+void W_Crylink_Reload()
+{
+       // return if reloading is disabled for this weapon
+       if(!autocvar_g_balance_crylink_reload_ammo)
+               return;
+
+       if(!W_ReloadCheck(self.ammo_cells, min(autocvar_g_balance_crylink_primary_ammo, autocvar_g_balance_crylink_secondary_ammo)))
+               return;
+
+       float t;
+
+       sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
+
+       t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_crylink_reload_time + 1;
+       ATTACK_FINISHED(self) = t;
+
+       weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_crylink_reload_time, W_Crylink_ReloadedAndReady);
+
+       self.old_clip_load = self.clip_load;
+       self.clip_load = -1;
+}
+
 void W_Crylink_CheckLinks(entity e)
 {
        float i;
@@ -177,27 +232,27 @@ void W_Crylink_LinkJoinEffect_Think()
                                if(autocvar_g_balance_crylink_secondary_joinexplode)
                                {
                                        n = n / autocvar_g_balance_crylink_secondary_shots;
-                                       RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_secondary_joinexplode_damage * n, 
-                                                                       autocvar_g_balance_crylink_secondary_joinexplode_edgedamage * n, 
-                                                                       autocvar_g_balance_crylink_secondary_joinexplode_radius * n, e.realowner, 
+                                       RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_secondary_joinexplode_damage * n,
+                                                                       autocvar_g_balance_crylink_secondary_joinexplode_edgedamage * n,
+                                                                       autocvar_g_balance_crylink_secondary_joinexplode_radius * n, e.realowner,
                                                                        autocvar_g_balance_crylink_secondary_joinexplode_force * n, e.projectiledeathtype, other);
 
                                        pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
-                               }                               
+                               }
                        }
                        else
                        {
                                if(autocvar_g_balance_crylink_primary_joinexplode)
                                {
                                        n = n / autocvar_g_balance_crylink_primary_shots;
-                                       RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_primary_joinexplode_damage * n, 
-                                                                       autocvar_g_balance_crylink_primary_joinexplode_edgedamage * n, 
-                                                                       autocvar_g_balance_crylink_primary_joinexplode_radius * n, e.realowner, 
+                                       RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_primary_joinexplode_damage * n,
+                                                                       autocvar_g_balance_crylink_primary_joinexplode_edgedamage * n,
+                                                                       autocvar_g_balance_crylink_primary_joinexplode_radius * n, e.realowner,
                                                                        autocvar_g_balance_crylink_primary_joinexplode_force * n, e.projectiledeathtype, other);
 
                                        pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
-                               }                               
-                       }                       
+                               }
+                       }
                }
        }
        remove(self);
@@ -319,8 +374,17 @@ void W_Crylink_Attack (void)
        vector forward, right, up;
        float maxdmg;
 
+       // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
        if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
-               self.ammo_cells = self.ammo_cells - autocvar_g_balance_crylink_primary_ammo;
+       {
+               if(autocvar_g_balance_crylink_reload_ammo)
+               {
+                       self.clip_load -= autocvar_g_balance_crylink_primary_ammo;
+                       self.crylink_load = self.clip_load;
+               }
+               else
+                       self.ammo_cells -= autocvar_g_balance_crylink_primary_ammo;
+       }
 
        maxdmg = autocvar_g_balance_crylink_primary_damage*autocvar_g_balance_crylink_primary_shots;
        maxdmg *= 1 + autocvar_g_balance_crylink_primary_bouncedamagefactor * autocvar_g_balance_crylink_primary_bounces;
@@ -397,6 +461,7 @@ void W_Crylink_Attack (void)
                        proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_other_fadetime;
                        proj.nextthink = time + autocvar_g_balance_crylink_primary_other_lifetime + autocvar_g_balance_crylink_primary_other_fadetime;
                }
+               proj.teleport_time = time + autocvar_g_balance_crylink_primary_joindelay;
                proj.cnt = autocvar_g_balance_crylink_primary_bounces;
                //proj.scale = 1 + 1 * proj.cnt;
 
@@ -421,8 +486,17 @@ void W_Crylink_Attack2 (void)
        local entity proj, prevproj, firstproj;
        float maxdmg;
 
+       // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
        if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
-               self.ammo_cells = self.ammo_cells - autocvar_g_balance_crylink_secondary_ammo;
+       {
+               if(autocvar_g_balance_crylink_reload_ammo)
+               {
+                       self.clip_load -= autocvar_g_balance_crylink_secondary_ammo;
+                       self.crylink_load = self.clip_load;
+               }
+               else
+                       self.ammo_cells -= autocvar_g_balance_crylink_secondary_ammo;
+       }
 
        maxdmg = autocvar_g_balance_crylink_secondary_damage*autocvar_g_balance_crylink_secondary_shots;
        maxdmg *= 1 + autocvar_g_balance_crylink_secondary_bouncedamagefactor * autocvar_g_balance_crylink_secondary_bounces;
@@ -484,6 +558,7 @@ void W_Crylink_Attack2 (void)
                        proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_line_fadetime;
                        proj.nextthink = time + autocvar_g_balance_crylink_secondary_line_lifetime + autocvar_g_balance_crylink_secondary_line_fadetime;
                }
+               proj.teleport_time = time + autocvar_g_balance_crylink_secondary_joindelay;
                proj.cnt = autocvar_g_balance_crylink_secondary_bounces;
                //proj.scale = 1 + 1 * proj.cnt;
 
@@ -509,16 +584,19 @@ void spawnfunc_weapon_crylink (void)
 
 float w_crylink(float req)
 {
+       float ammo_amount;
        if (req == WR_AIM)
        {
-               if (random() > 0.15)
+               if (random() < 0.10)
                        self.BUTTON_ATCK = bot_aim(autocvar_g_balance_crylink_primary_speed, 0, autocvar_g_balance_crylink_primary_middle_lifetime, FALSE);
                else
                        self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_crylink_secondary_speed, 0, autocvar_g_balance_crylink_secondary_middle_lifetime, FALSE);
        }
        else if (req == WR_THINK)
        {
-               if (self.BUTTON_ATCK)
+               if(autocvar_g_balance_crylink_reload_ammo && self.clip_load < min(autocvar_g_balance_crylink_primary_ammo, autocvar_g_balance_crylink_secondary_ammo)) // forced reload
+                       W_Crylink_Reload();
+               else if (self.BUTTON_ATCK)
                {
                        if (!self.crylink_waitrelease)
                        if (weapon_prepareattack(0, autocvar_g_balance_crylink_primary_refire))
@@ -542,33 +620,30 @@ float w_crylink(float req)
                }
                else
                {
-                       if (self.crylink_waitrelease)
+                       if (self.crylink_waitrelease && (!self.crylink_lastgroup || time > self.crylink_lastgroup.teleport_time))
                        {
                                // fired and released now!
                                if(self.crylink_lastgroup)
                                {
                                        vector pos;
                                        entity linkjoineffect;
-                                       
-                                       
+
                                        if(self.crylink_waitrelease == 1)
                                        {
                                                pos = W_Crylink_LinkJoin(self.crylink_lastgroup, autocvar_g_balance_crylink_primary_joinspread * autocvar_g_balance_crylink_primary_speed, autocvar_g_balance_crylink_primary_jointime);
-                                               
+
                                        }
                                        else
                                        {
                                                pos = W_Crylink_LinkJoin(self.crylink_lastgroup, autocvar_g_balance_crylink_secondary_joinspread * autocvar_g_balance_crylink_secondary_speed, autocvar_g_balance_crylink_secondary_jointime);
                                        }
-                                       
+
                                        linkjoineffect = spawn();
                                        linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
-                                       linkjoineffect.classname = "linkjoineffect";                                    
+                                       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))
@@ -588,22 +663,41 @@ float w_crylink(float req)
                precache_sound ("weapons/crylink_fire.wav");
                precache_sound ("weapons/crylink_fire2.wav");
                precache_sound ("weapons/crylink_linkjoin.wav");
+               precache_sound ("weapons/reload.wav");
        }
        else if (req == WR_SETUP)
+       {
                weapon_setup(WEP_CRYLINK);
+               W_Crylink_SetAmmoCounter();
+       }
        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 >= autocvar_g_balance_crylink_primary_ammo;
+
+               ammo_amount = self.ammo_cells >= autocvar_g_balance_crylink_primary_ammo;
+               ammo_amount += (autocvar_g_balance_crylink_reload_ammo && self.crylink_load >= autocvar_g_balance_crylink_primary_ammo);
+               return ammo_amount;
        }
        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 >= autocvar_g_balance_crylink_secondary_ammo;
+
+               ammo_amount = self.ammo_cells >= autocvar_g_balance_crylink_secondary_ammo;
+               ammo_amount += (autocvar_g_balance_crylink_reload_ammo && self.crylink_load >= autocvar_g_balance_crylink_secondary_ammo);
+               return ammo_amount;
+       }
+       else if (req == WR_RESETPLAYER)
+       {
+               // all weapons must be fully loaded when we spawn
+               self.crylink_load = autocvar_g_balance_crylink_reload_ammo;
+       }
+       else if (req == WR_RELOAD)
+       {
+               W_Crylink_Reload();
        }
        return TRUE;
 };
@@ -635,16 +729,16 @@ float w_crylink(float req)
        }
        else if (req == WR_SUICIDEMESSAGE)
        {
-               w_deathtypestring = "%s succeeded at self-destructing themself with the Crylink";
+               w_deathtypestring = _("%s succeeded at self-destructing themself with the Crylink");
        }
        else if (req == WR_KILLMESSAGE)
        {
                if(w_deathtype & HITTYPE_BOUNCE)
-                       w_deathtypestring = "%s could not hide from %s's Crylink"; // unchecked: SPLASH (SECONDARY can't be)
+                       w_deathtypestring = _("%s could not hide from %s's Crylink"); // unchecked: SPLASH (SECONDARY can't be)
                else if(w_deathtype & HITTYPE_SPLASH)
-                       w_deathtypestring = "%s was too close to %s's Crylink"; // unchecked: SECONDARY
+                       w_deathtypestring = _("%s was too close to %s's Crylink"); // unchecked: SECONDARY
                else
-                       w_deathtypestring = "%s took a close look at %s's Crylink"; // unchecked: SECONDARY
+                       w_deathtypestring = _("%s took a close look at %s's Crylink"); // unchecked: SECONDARY
        }
        return TRUE;
 }