]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_minelayer.qc
Merge remote-tracking branch 'origin/fruitiex/disable-shootanim'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_minelayer.qc
index 7c07fa4bcf4588a84578f75bb099cd98afc183cb..14c6506faa0d13111f35402e3a8f109ac8384f63 100644 (file)
@@ -1,5 +1,5 @@
 #ifdef REGISTER_WEAPON
-REGISTER_WEAPON(MINE_LAYER, w_minelayer, IT_ROCKETS, 4, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_HIGH, "minelayer", "minelayer", _("Mine Layer"))
+REGISTER_WEAPON(MINE_LAYER, w_minelayer, IT_ROCKETS, 4, WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_HIGH, "minelayer", "minelayer", _("Mine Layer"))
 #else
 #ifdef SVQC
 void W_Mine_Think (void);
@@ -66,12 +66,16 @@ void W_Mine_Explode ()
 
        if (self.owner.weapon == WEP_MINE_LAYER)
        {
-               if(self.owner.ammo_rockets < autocvar_g_balance_minelayer_ammo)
+               entity oldself;
+               oldself = self;
+               self = self.owner;
+               if (!weapon_action(WEP_MINE_LAYER, WR_CHECKAMMO1))
                {
-                       self.owner.cnt = WEP_MINE_LAYER;
-                       ATTACK_FINISHED(self.owner) = time;
-                       self.owner.switchweapon = w_getbestweapon(self.owner);
+                       self.cnt = WEP_MINE_LAYER;
+                       ATTACK_FINISHED(self) = time;
+                       self.switchweapon = w_getbestweapon(self);
                }
+               self = oldself;
        }
        self.owner.minelayer_mines -= 1;
        remove (self);
@@ -86,12 +90,16 @@ void W_Mine_DoRemoteExplode ()
 
        if (self.owner.weapon == WEP_MINE_LAYER)
        {
-               if(self.owner.ammo_rockets < autocvar_g_balance_minelayer_ammo)
+               entity oldself;
+               oldself = self;
+               self = self.owner;
+               if (!weapon_action(WEP_MINE_LAYER, WR_CHECKAMMO1))
                {
-                       self.owner.cnt = WEP_MINE_LAYER;
-                       ATTACK_FINISHED(self.owner) = time;
-                       self.owner.switchweapon = w_getbestweapon(self.owner);
+                       self.cnt = WEP_MINE_LAYER;
+                       ATTACK_FINISHED(self) = time;
+                       self.switchweapon = w_getbestweapon(self);
                }
+               self = oldself;
        }
        self.owner.minelayer_mines -= 1;
        remove (self);
@@ -282,10 +290,30 @@ void W_Mine_Attack (void)
 
 void spawnfunc_weapon_minelayer (void); // defined in t_items.qc
 
-float w_minelayer(float req)
+float W_PlacedMines(float detonate)
 {
        entity mine;
        float minfound;
+
+       for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
+       {
+               if(detonate)
+               {
+                       if(!mine.minelayer_detonate)
+                       {
+                               mine.minelayer_detonate = TRUE;
+                               minfound = 1;
+                       }
+               }
+               else
+                       minfound = 1;
+       }
+       return minfound;
+}
+
+float w_minelayer(float req)
+{
+       entity mine;
        float ammo_amount;
 
        if (req == WR_AIM)
@@ -386,7 +414,11 @@ float w_minelayer(float req)
        else if (req == WR_THINK)
        {
                if(autocvar_g_balance_minelayer_reload_ammo && self.clip_load < autocvar_g_balance_minelayer_ammo) // forced reload
-                       weapon_action(self.weapon, WR_RELOAD);
+               {
+                       // not if we're holding the minelayer without enough ammo, but can detonate existing mines
+                       if not (W_PlacedMines(FALSE) && self.ammo_rockets < autocvar_g_balance_minelayer_ammo)
+                               weapon_action(self.weapon, WR_RELOAD);
+               }
                else if (self.BUTTON_ATCK)
                {
                        if(weapon_prepareattack(0, autocvar_g_balance_minelayer_refire))
@@ -396,18 +428,9 @@ float w_minelayer(float req)
                        }
                }
 
-               else if (self.BUTTON_ATCK2)
+               if (self.BUTTON_ATCK2)
                {
-                       minfound = 0;
-                       for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
-                       {
-                               if(!mine.minelayer_detonate)
-                               {
-                                       mine.minelayer_detonate = TRUE;
-                                       minfound = 1;
-                               }
-                       }
-                       if(minfound)
+                       if(W_PlacedMines(TRUE))
                                sound (self, CHAN_WEAPON2, "weapons/mine_det.wav", VOL_BASE, ATTN_NORM);
                }
        }
@@ -434,19 +457,17 @@ float w_minelayer(float req)
                // don't switch while placing a mine
                if (ATTACK_FINISHED(self) <= time || self.weapon != WEP_MINE_LAYER)
                {
-                       if(autocvar_g_balance_minelayer_reload_ammo)
-                       {
-                               if(self.ammo_rockets < autocvar_g_balance_minelayer_ammo && self.weapon_load[WEP_MINE_LAYER] < autocvar_g_balance_minelayer_ammo)
-                                       ammo_amount = TRUE;
-                       }
-                       else if(self.ammo_rockets < autocvar_g_balance_minelayer_ammo)
-                               ammo_amount = TRUE;
-                       return !ammo_amount;
+                       ammo_amount = self.ammo_rockets >= autocvar_g_balance_minelayer_ammo;
+                       ammo_amount += self.weapon_load[WEP_MINE_LAYER] >= autocvar_g_balance_minelayer_ammo;
+                       return ammo_amount;
                }
        }
        else if (req == WR_CHECKAMMO2)
        {
-               return FALSE;
+               if (W_PlacedMines(FALSE))
+                       return TRUE;
+               else
+                       return FALSE;
        }
        else if (req == WR_RELOAD)
        {