]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_hagar.qc
Move load persistence floats back to their weapon files. That should be the last...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_hagar.qc
index d3723573687c76230d790fc810ed4bfc282877ea..e982c3a213718828b3986f302074a12ff4c2d0b8 100644 (file)
@@ -1,12 +1,68 @@
 #ifdef REGISTER_WEAPON
-REGISTER_WEAPON(HAGAR, w_hagar, IT_ROCKETS, 8, WEP_FLAG_NORMAL | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "hagar", "hagar", "Hagar");
+REGISTER_WEAPON(HAGAR, w_hagar, IT_ROCKETS, 8, WEP_FLAG_NORMAL | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "hagar", "hagar", _("Hagar"))
 #else
 #ifdef SVQC
 // NO bounce protection, as bounces are limited!
+
+// weapon load persistence, for weapons that support reloading
+.float hagar_load;
+
+void W_Hagar_SetAmmoCounter()
+{
+       // set clip_load to the weapon we have switched to, if the gun uses reloading
+       if(!autocvar_g_balance_hagar_reload_ammo)
+               self.clip_load = 0; // also keeps crosshair ammo from displaying
+       else
+       {
+               self.clip_load = self.hagar_load;
+               self.clip_size = autocvar_g_balance_hagar_reload_ammo; // for the crosshair ammo display
+       }
+}
+
+void W_Hagar_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_hagar_reload_ammo && self.ammo_rockets) // make sure we don't add more ammo than we have
+       {
+               self.clip_load += 1;
+               self.ammo_rockets -= 1;
+       }
+       self.hagar_load = self.clip_load;
+
+       t = ATTACK_FINISHED(self) - autocvar_g_balance_hagar_reload_time - 1;
+       ATTACK_FINISHED(self) = t;
+       w_ready();
+}
+
+void W_Hagar_Reload()
+{
+       // return if reloading is disabled for this weapon
+       if(!autocvar_g_balance_hagar_reload_ammo)
+               return;
+
+       if(!W_ReloadCheck(self.ammo_rockets, min(autocvar_g_balance_hagar_primary_ammo, autocvar_g_balance_hagar_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_hagar_reload_time + 1;
+       ATTACK_FINISHED(self) = t;
+
+       weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_hagar_reload_time, W_Hagar_ReloadedAndReady);
+
+       self.old_clip_load = self.clip_load;
+       self.clip_load = -1;
+}
+
 void W_Hagar_Explode (void)
 {
        self.event_damage = SUB_Null;
-       RadiusDamage (self, self.realowner, cvar("g_balance_hagar_primary_damage"), cvar("g_balance_hagar_primary_edgedamage"), cvar("g_balance_hagar_primary_radius"), world, cvar("g_balance_hagar_primary_force"), self.projectiledeathtype, other);
+       RadiusDamage (self, self.realowner, autocvar_g_balance_hagar_primary_damage, autocvar_g_balance_hagar_primary_edgedamage, autocvar_g_balance_hagar_primary_radius, world, autocvar_g_balance_hagar_primary_force, self.projectiledeathtype, other);
 
        remove (self);
 }
@@ -14,7 +70,7 @@ void W_Hagar_Explode (void)
 void W_Hagar_Explode2 (void)
 {
        self.event_damage = SUB_Null;
-       RadiusDamage (self, self.realowner, cvar("g_balance_hagar_secondary_damage"), cvar("g_balance_hagar_secondary_edgedamage"), cvar("g_balance_hagar_secondary_radius"), world, cvar("g_balance_hagar_secondary_force"), self.projectiledeathtype, other);
+       RadiusDamage (self, self.realowner, autocvar_g_balance_hagar_secondary_damage, autocvar_g_balance_hagar_secondary_edgedamage, autocvar_g_balance_hagar_secondary_radius, world, autocvar_g_balance_hagar_secondary_force, self.projectiledeathtype, other);
 
        remove (self);
 }
@@ -44,9 +100,19 @@ void W_Hagar_Attack (void)
 {
        local entity missile;
 
+       // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
        if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
-               self.ammo_rockets = self.ammo_rockets - cvar("g_balance_hagar_primary_ammo");
-       W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", cvar("g_balance_hagar_primary_damage"));
+       {
+               if(autocvar_g_balance_hagar_reload_ammo)
+               {
+                       self.clip_load -= autocvar_g_balance_hagar_primary_ammo;
+                       self.hagar_load = self.clip_load;
+               }
+               else
+                       self.ammo_rockets -= autocvar_g_balance_hagar_primary_ammo;
+       }
+
+       W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", CHAN_WEAPON, autocvar_g_balance_hagar_primary_damage);
 
        pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
 
@@ -54,11 +120,11 @@ void W_Hagar_Attack (void)
        missile.owner = missile.realowner = self;
        missile.classname = "missile";
        missile.bot_dodge = TRUE;
-       missile.bot_dodgerating = cvar("g_balance_hagar_primary_damage");
+       missile.bot_dodgerating = autocvar_g_balance_hagar_primary_damage;
        missile.touch = W_Hagar_Touch;
        missile.use = W_Hagar_Explode;
        missile.think = adaptor_think2use_hittype_splash;
-       missile.nextthink = time + cvar("g_balance_hagar_primary_lifetime");
+       missile.nextthink = time + autocvar_g_balance_hagar_primary_lifetime;
        PROJECTILE_MAKETRIGGER(missile);
        missile.projectiledeathtype = WEP_HAGAR;
        setorigin (missile, w_shotorg);
@@ -71,16 +137,27 @@ void W_Hagar_Attack (void)
        missile.flags = FL_PROJECTILE;
 
        CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR, TRUE);
+
+       other = missile; MUTATOR_CALLHOOK(EditProjectile);
 }
 
 void W_Hagar_Attack2 (void)
 {
        local entity missile;
 
+       // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
        if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
-               self.ammo_rockets = self.ammo_rockets - cvar("g_balance_hagar_secondary_ammo");
-       W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav", cvar("g_balance_hagar_secondary_damage"));
-       //W_SetupShot (self, FALSE, 2, "weapons/hagar_fire.wav"); // TODO: move model a little to the right
+       {
+               if(autocvar_g_balance_hagar_reload_ammo)
+               {
+                       self.clip_load -= autocvar_g_balance_hagar_secondary_ammo;
+                       self.hagar_load = self.clip_load;
+               }
+               else
+                       self.ammo_rockets -= autocvar_g_balance_hagar_secondary_ammo;
+       }
+
+       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);
 
@@ -88,12 +165,12 @@ void W_Hagar_Attack2 (void)
        missile.owner = missile.realowner = self;
        missile.classname = "missile";
        missile.bot_dodge = TRUE;
-       missile.bot_dodgerating = cvar("g_balance_hagar_secondary_damage");
+       missile.bot_dodgerating = autocvar_g_balance_hagar_secondary_damage;
        missile.touch = W_Hagar_Touch2;
        missile.cnt = 0;
        missile.use = W_Hagar_Explode2;
        missile.think = adaptor_think2use_hittype_splash;
-       missile.nextthink = time + cvar("g_balance_hagar_secondary_lifetime_min") + random() * cvar("g_balance_hagar_secondary_lifetime_rand");
+       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 | HITTYPE_SECONDARY;
        setorigin (missile, w_shotorg);
@@ -106,6 +183,8 @@ void W_Hagar_Attack2 (void)
        missile.flags = FL_PROJECTILE;
 
        CSQCProjectile(missile, TRUE, PROJECTILE_HAGAR_BOUNCING, TRUE);
+
+       other = missile; MUTATOR_CALLHOOK(EditProjectile);
 }
 
 void spawnfunc_weapon_hagar (void)
@@ -115,27 +194,34 @@ void spawnfunc_weapon_hagar (void)
 
 float w_hagar(float req)
 {
+       float ammo_amount;
        if (req == WR_AIM)
                if (random()>0.15)
-                       self.BUTTON_ATCK = bot_aim(cvar("g_balance_hagar_primary_speed"), 0, cvar("g_balance_hagar_primary_lifetime"), FALSE);
+                       self.BUTTON_ATCK = bot_aim(autocvar_g_balance_hagar_primary_speed, 0, autocvar_g_balance_hagar_primary_lifetime, FALSE);
                else
                {
                        // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
-                       self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_hagar_primary_speed"), 0, cvar("g_balance_hagar_primary_lifetime"), FALSE);
+                       self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_hagar_primary_speed, 0, autocvar_g_balance_hagar_primary_lifetime, FALSE);
                }
        else if (req == WR_THINK)
        {
-               if (self.BUTTON_ATCK)
-               if (weapon_prepareattack(0, cvar("g_balance_hagar_primary_refire")))
+               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
+                       W_Hagar_Reload();
+               else if (self.BUTTON_ATCK)
                {
-                       W_Hagar_Attack();
-                       weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_hagar_primary_refire"), w_ready);
+                       if (weapon_prepareattack(0, autocvar_g_balance_hagar_primary_refire))
+                       {
+                               W_Hagar_Attack();
+                               weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hagar_primary_refire, w_ready);
+                       }
                }
-               if (self.BUTTON_ATCK2 && cvar("g_balance_hagar_secondary"))
-               if (weapon_prepareattack(1, cvar("g_balance_hagar_secondary_refire")))
+               else if (self.BUTTON_ATCK2 && autocvar_g_balance_hagar_secondary)
                {
-                       W_Hagar_Attack2();
-                       weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_hagar_secondary_refire"), w_ready);
+                       if (weapon_prepareattack(1, autocvar_g_balance_hagar_secondary_refire))
+                       {
+                               W_Hagar_Attack2();
+                               weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hagar_secondary_refire, w_ready);
+                       }
                }
        }
        else if (req == WR_PRECACHE)
@@ -144,13 +230,34 @@ 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/reload.wav");
        }
        else if (req == WR_SETUP)
+       {
                weapon_setup(WEP_HAGAR);
+               W_Hagar_SetAmmoCounter();
+       }
        else if (req == WR_CHECKAMMO1)
-               return self.ammo_rockets >= cvar("g_balance_hagar_primary_ammo");
+       {
+               ammo_amount = self.ammo_rockets >= autocvar_g_balance_hagar_primary_ammo;
+               ammo_amount += (autocvar_g_balance_hagar_reload_ammo && self.hagar_load >= autocvar_g_balance_hagar_primary_ammo);
+               return ammo_amount;
+       }
        else if (req == WR_CHECKAMMO2)
-               return self.ammo_rockets >= cvar("g_balance_hagar_secondary_ammo");
+       {
+               ammo_amount = self.ammo_rockets >= autocvar_g_balance_hagar_secondary_ammo;
+               ammo_amount += (autocvar_g_balance_hagar_reload_ammo && self.hagar_load >= autocvar_g_balance_hagar_secondary_ammo);
+               return ammo_amount;
+       }
+       else if (req == WR_RESETPLAYER)
+       {
+               // all weapons must be fully loaded when we spawn
+               self.hagar_load = autocvar_g_balance_hagar_reload_ammo;
+       }
+       else if (req == WR_RELOAD)
+       {
+               W_Hagar_Reload();
+       }
        return TRUE;
 };
 #endif
@@ -179,13 +286,13 @@ float w_hagar(float req)
                precache_sound("weapons/hagexp3.wav");
        }
        else if (req == WR_SUICIDEMESSAGE)
-               w_deathtypestring = "played with tiny rockets";
+               w_deathtypestring = "%s played with tiny rockets";
        else if (req == WR_KILLMESSAGE)
        {
                if(w_deathtype & HITTYPE_BOUNCE) // must be secondary; unchecked: SPLASH
-                       w_deathtypestring = "hoped #'s missiles wouldn't bounce";
+                       w_deathtypestring = "%s hoped %s's missiles wouldn't bounce";
                else // unchecked: SPLASH, SECONDARY
-                       w_deathtypestring = "was pummeled by";
+                       w_deathtypestring = "%s was pummeled by %s";
        }
        return TRUE;
 }