]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_laser.qc
Share the final reload code that comes to mind. The reload code is for the most part...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_laser.qc
index 736c7a8dbd19a19539b02622319a422e2235065e..3f902ac948b3aa1a9a33cd38ba28d50c82bf5c78 100644 (file)
@@ -1,9 +1,20 @@
 #ifdef REGISTER_WEAPON
-REGISTER_WEAPON(LASER, w_laser, 0, 1, WEP_FLAG_NORMAL | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, 0, "laser", "laser", _("Laser"))
+REGISTER_WEAPON(LASER, w_laser, 0, 1, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, 0, "laser", "laser", _("Laser"))
 #else
 #ifdef SVQC
 void(float imp) W_SwitchWeapon;
 
+void W_Laser_Reload()
+{
+       self.(self.reload_ammo_player) = 1;
+       self.reload_ammo_min = 0;
+       self.reload_ammo_amount = autocvar_g_balance_laser_reload_ammo;
+       self.reload_time = autocvar_g_balance_laser_reload_time;
+       self.reload_sound = "weapons/reload.wav";
+
+       W_Reload();
+}
+
 void W_Laser_Touch (void)
 {
        PROJECTILE_TOUCH;
@@ -226,16 +237,40 @@ float w_laser(float req)
        }
        else if (req == WR_THINK)
        {
-               if (self.BUTTON_ATCK)
-               if (weapon_prepareattack(0, autocvar_g_balance_laser_primary_refire))
+               if(autocvar_g_balance_laser_reload_ammo && self.clip_load < 1) // forced reload
+                       W_Laser_Reload();
+               else if (self.BUTTON_ATCK)
                {
-                       W_Laser_Attack(0);
-                       weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_laser_primary_animtime, w_ready);
+                       if (weapon_prepareattack(0, autocvar_g_balance_laser_primary_refire))
+                       {
+                               // if this weapon is reloadable, decrease its load
+                               if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
+                               {
+                                       if(autocvar_g_balance_laser_reload_ammo)
+                                       {
+                                               self.clip_load -= 1;
+                                               self.weapon_load[WEP_LASER] = self.clip_load;
+                                       }
+                               }
+
+                               W_Laser_Attack(0);
+                               weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_laser_primary_animtime, w_ready);
+                       }
                }
-               if (self.BUTTON_ATCK2)
+               else if (self.BUTTON_ATCK2)
                {
                        if(autocvar_g_balance_laser_secondary)
                        {
+                               // if this weapon is reloadable, decrease its load
+                               if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
+                               {
+                                       if(autocvar_g_balance_laser_reload_ammo)
+                                       {
+                                               self.clip_load -= 1;
+                                               self.weapon_load[WEP_LASER] = self.clip_load;
+                                       }
+                               }
+
                                if (weapon_prepareattack(0, 0))
                                {
                                        W_Laser_Attack2();
@@ -256,13 +291,24 @@ float w_laser(float req)
                precache_model ("models/weapons/h_laser.iqm");
                precache_sound ("weapons/lasergun_fire.wav");
                precache_sound ("weapons/gauntlet_fire.wav");
+               precache_sound ("weapons/reload.wav");
        }
        else if (req == WR_SETUP)
+       {
                weapon_setup(WEP_LASER);
+       }
        else if (req == WR_CHECKAMMO1)
+       {
                return TRUE;
+       }
        else if (req == WR_CHECKAMMO2)
+       {
                return TRUE;
+       }
+       else if (req == WR_RELOAD)
+       {
+               W_Laser_Reload();
+       }
        return TRUE;
 };
 #endif
@@ -282,13 +328,13 @@ float w_laser(float req)
                precache_sound("weapons/laserimpact.wav");
        }
        else if (req == WR_SUICIDEMESSAGE)
-               w_deathtypestring = "%s lasered themself to hell";
+               w_deathtypestring = _("%s lasered themself to hell");
        else if (req == WR_KILLMESSAGE)
        {
                if(w_deathtype & HITTYPE_SECONDARY)
-                       w_deathtypestring = "%s was cut in half by %s's gauntlet"; // unchecked: SPLASH
+                       w_deathtypestring = _("%s was cut in half by %s's gauntlet"); // unchecked: SPLASH
                else
-                       w_deathtypestring = "%s was lasered to death by %s"; // unchecked: SPLASH
+                       w_deathtypestring = _("%s was lasered to death by %s"); // unchecked: SPLASH
        }
        return TRUE;
 }