]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_hagar.qc
Also update the reload delay when firing, to add a forced pause that was missing
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_hagar.qc
index 760e6cf353895eda9388e9080e09895ca8001c6e..d4b47a29e55ff64231e9b8bd8b7f5496db0a138a 100644 (file)
@@ -115,89 +115,119 @@ void W_Hagar_Attack2 (void)
        other = missile; MUTATOR_CALLHOOK(EditProjectile);
 }
 
-.float temp_limit;
-
+.float hagarload_refire;
 void W_Hagar_Attack2_Load (void)
 {
-       if not(self.BUTTON_ATCK2 && autocvar_g_balance_hagar_secondary)
-               return;
-       if(self.temp_limit > time)
+       if not(weapon_action(self.weapon, WR_CHECKAMMO2))
+       {
+               W_SwitchToOtherWeapon(self);
                return;
-       self.temp_limit = time + 0.5;
+       }
 
        local entity missile, prevmissile, firstmissile;
-       local float counter, shots;
+       local float counter, shots, loaded;
+       local float used_ammo, enough_ammo;
        local vector s;
        vector forward, right, up;
 
-       W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", CHAN_WEAPON, autocvar_g_balance_hagar_secondary_damage);
-       pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
+       loaded = self.hagar_load >= autocvar_g_balance_hagar_secondary_load_max;
 
-       forward = v_forward;
-       right = v_right;
-       up = v_up;
+       // check if we have enough ammo for another rocket
+       used_ammo = autocvar_g_balance_hagar_secondary_ammo;
+       if(autocvar_g_balance_hagar_reload_ammo)
+               enough_ammo = self.weapon_load[WEP_HAGAR] >= used_ammo + (used_ammo * self.hagar_load);
+       else
+               enough_ammo = self.ammo_rockets >= used_ammo + (used_ammo * self.hagar_load);
 
-       shots = autocvar_g_balance_crylink_primary_shots;
-       missile = world;
-       while (counter < shots)
+       if(self.BUTTON_ATCK2 && !loaded && enough_ammo)
        {
+               // we can attempt to load another rocket
+               if(self.hagarload_refire < time)
+               {
+                       self.hagar_load += 1;
+                       sound(self, CHAN_WEAPON2, "weapons/hagar_load.wav", VOL_BASE, ATTN_NORM);
 
-               missile = spawn ();
-               missile.owner = missile.realowner = self;
-               missile.classname = "missile";
-               missile.bot_dodge = TRUE;
-               missile.bot_dodgerating = autocvar_g_balance_hagar_secondary_damage;
-               if(shots == 1) {
-                       missile.queuenext = missile;
-                       missile.queueprev = missile;
-               }
-               else if(counter == 0) { // first projectile, store in firstmissile for now
-                       firstmissile = missile;
-               }
-               else if(counter == shots - 1) { // last projectile, link up with first projectile
-                       prevmissile.queuenext = missile;
-                       firstmissile.queueprev = missile;
-                       missile.queuenext = firstmissile;
-                       missile.queueprev = prevmissile;
-               }
-               else { // else link up with previous projectile
-                       prevmissile.queuenext = missile;
-                       missile.queueprev = prevmissile;
+                       self.hagarload_refire = time + autocvar_g_balance_hagar_secondary_refire;
                }
+       }
+       else if(self.hagar_load && (!self.BUTTON_ATCK2 || ((loaded || !enough_ammo) && !autocvar_g_balance_hagar_secondary_load_hold)))
+       if(weapon_prepareattack(0, autocvar_g_balance_hagar_secondary_refire))
+       {
+               // time to release the rockets we've loaded
 
-               prevmissile = missile;
+               W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_hagar_secondary_ammo * self.hagar_load, autocvar_g_balance_hagar_reload_ammo);
 
-               missile.touch = W_Hagar_Touch;
-               missile.use = W_Hagar_Explode;
-               missile.think = adaptor_think2use_hittype_splash;
-               missile.nextthink = time + autocvar_g_balance_hagar_secondary_lifetime_min + random() * autocvar_g_balance_hagar_secondary_lifetime_rand;
-               PROJECTILE_MAKETRIGGER(missile);
-               missile.projectiledeathtype = WEP_HAGAR;
-               setorigin (missile, w_shotorg);
-               setsize(missile, '0 0 0', '0 0 0');
+               W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", CHAN_WEAPON, autocvar_g_balance_hagar_secondary_damage);
+               pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
 
-               missile.movetype = MOVETYPE_FLY;
+               forward = v_forward;
+               right = v_right;
+               up = v_up;
 
-               s = '0 0 0';
-               if (counter == 0)
-                       s = '0 0 0';
-               else
+               shots = self.hagar_load;
+               missile = world;
+               while (counter < shots)
                {
-                       makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
-                       s_y = v_forward_x;
-                       s_z = v_forward_y;
-               }
-               s = s * autocvar_g_balance_hagar_secondary_load_spread * g_weaponspreadfactor;
-               W_SetupProjectileVelocityEx(missile, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_hagar_secondary_speed"), 0, 0, 0, FALSE);
+                       missile = spawn ();
+                       missile.owner = missile.realowner = self;
+                       missile.classname = "missile";
+                       missile.bot_dodge = TRUE;
+                       missile.bot_dodgerating = autocvar_g_balance_hagar_secondary_damage;
+
+                       if(shots == 1) {
+                               missile.queuenext = missile;
+                               missile.queueprev = missile;
+                       }
+                       else if(counter == 0) { // first projectile, store in firstmissile for now
+                               firstmissile = missile;
+                       }
+                       else if(counter == shots - 1) { // last projectile, link up with first projectile
+                               prevmissile.queuenext = missile;
+                               firstmissile.queueprev = missile;
+                               missile.queuenext = firstmissile;
+                               missile.queueprev = prevmissile;
+                       }
+                       else { // else link up with previous projectile
+                               prevmissile.queuenext = missile;
+                               missile.queueprev = prevmissile;
+                       }
+                       prevmissile = missile;
+
+                       missile.touch = W_Hagar_Touch; // not bouncy
+                       missile.use = W_Hagar_Explode2;
+                       missile.think = adaptor_think2use_hittype_splash;
+                       missile.nextthink = time + autocvar_g_balance_hagar_secondary_lifetime_min + random() * autocvar_g_balance_hagar_secondary_lifetime_rand;
+                       PROJECTILE_MAKETRIGGER(missile);
+                       missile.projectiledeathtype = WEP_HAGAR;
+                       setorigin (missile, w_shotorg);
+                       setsize(missile, '0 0 0', '0 0 0');
+                       missile.movetype = MOVETYPE_FLY;
 
-               missile.angles = vectoangles (missile.velocity);
-               missile.flags = FL_PROJECTILE;
+                       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 = s * cvar("g_balance_hagar_secondary_spread") * g_weaponspreadfactor;
+                       W_SetupProjectileVelocityEx(missile, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_hagar_secondary_speed"), 0, 0, 0, FALSE);
+
+                       missile.angles = vectoangles (missile.velocity);
+                       missile.flags = FL_PROJECTILE;
 
-               CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR, TRUE);
+                       CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR, TRUE);
 
-               other = missile; MUTATOR_CALLHOOK(EditProjectile);
+                       other = missile; MUTATOR_CALLHOOK(EditProjectile);
 
-               counter = counter + 1;
+                       counter = counter + 1;
+               }
+
+               weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_hagar_secondary_refire, w_ready);
+               self.hagarload_refire = time + autocvar_g_balance_hagar_secondary_refire;
+               self.hagar_load = 0;
        }
 }
 
@@ -221,7 +251,7 @@ float w_hagar(float req)
        {
                if(autocvar_g_balance_hagar_reload_ammo && self.clip_load < min(autocvar_g_balance_hagar_primary_ammo, autocvar_g_balance_hagar_secondary_ammo)) // forced reload
                        weapon_action(self.weapon, WR_RELOAD);
-               else if (self.BUTTON_ATCK)
+               else if (self.BUTTON_ATCK && !self.hagar_load) // not while loading the secondary fire
                {
                        if (weapon_prepareattack(0, autocvar_g_balance_hagar_primary_refire))
                        {
@@ -229,8 +259,8 @@ float w_hagar(float req)
                                weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hagar_primary_refire, w_ready);
                        }
                }
-               else if(autocvar_g_balance_hagar_secondary_load)
-                       W_Hagar_Attack2_Load();
+               else if(autocvar_g_balance_hagar_secondary_load && autocvar_g_balance_hagar_secondary)
+                       W_Hagar_Attack2_Load(); // must run each frame
                else if (self.BUTTON_ATCK2 && autocvar_g_balance_hagar_secondary)
                {
                        if (weapon_prepareattack(1, autocvar_g_balance_hagar_secondary_refire))
@@ -246,12 +276,15 @@ float w_hagar(float req)
                precache_model ("models/weapons/v_hagar.md3");
                precache_model ("models/weapons/h_hagar.iqm");
                precache_sound ("weapons/hagar_fire.wav");
+               precache_sound ("weapons/hagar_load.wav");
                //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
        }
        else if (req == WR_SETUP)
        {
                weapon_setup(WEP_HAGAR);
                self.current_ammo = ammo_rockets;
+
+               self.hagar_load = 0;
        }
        else if (req == WR_CHECKAMMO1)
        {