]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_minelayer.qc
Phase 2. A global ammo decreasing function. Still not fully ready
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_minelayer.qc
index 1b35ab4efd8d5a89f157da9cdbeb359e687c4a98..3c9aac6cc22090bbad023cb39c930d0f1940b4f4 100644 (file)
@@ -1,63 +1,11 @@
 #ifdef REGISTER_WEAPON
-REGISTER_WEAPON(MINE_LAYER, w_minelayer, IT_ROCKETS, 4, WEP_TYPE_SPLASH, BOT_PICKUP_RATING_HIGH, "minelayer", "minelayer", _("Mine Layer"))
+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"))
 #else
 #ifdef SVQC
 void W_Mine_Think (void);
 .float minelayer_detonate, minelayer_mines;
 .float mine_time;
 
-void W_MineLayer_SetAmmoCounter()
-{
-       // set clip_load to the weapon we have switched to, if the gun uses reloading
-       if(!autocvar_g_balance_minelayer_reload_ammo)
-               self.clip_load = 0; // also keeps crosshair ammo from displaying
-       else
-       {
-               self.clip_load = self.minelayer_load;
-               self.clip_size = autocvar_g_balance_minelayer_reload_ammo; // for the crosshair ammo display
-       }
-}
-
-void W_MineLayer_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_minelayer_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.minelayer_load = self.clip_load;
-
-       t = ATTACK_FINISHED(self) - autocvar_g_balance_minelayer_reload_time - 1;
-       ATTACK_FINISHED(self) = t;
-       w_ready();
-}
-
-void W_MineLayer_Reload()
-{
-       // return if reloading is disabled for this weapon
-       if(!autocvar_g_balance_minelayer_reload_ammo)
-               return;
-
-       if(!W_ReloadCheck(self.ammo_rockets, autocvar_g_balance_minelayer_ammo))
-               return;
-
-       float t;
-
-       sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
-
-       t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_minelayer_reload_time + 1;
-       ATTACK_FINISHED(self) = t;
-
-       weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_minelayer_reload_time, W_MineLayer_ReloadedAndReady);
-
-       self.old_clip_load = self.clip_load;
-       self.clip_load = -1;
-}
-
 void spawnfunc_weapon_minelayer (void)
 {
        weapon_defaultspawnfunc(WEP_MINE_LAYER);
@@ -162,7 +110,7 @@ void W_Mine_RemoteExplode ()
 void W_Mine_ProximityExplode ()
 {
        // make sure no friend is in the mine's radius. If there is any, explosion is delayed until he's at a safe distance
-       if(autocvar_g_balance_minelayer_protection)
+       if(autocvar_g_balance_minelayer_protection && self.minelayer_mines == 0)
        {
                entity head;
                head = findradius(self.origin, autocvar_g_balance_minelayer_radius);
@@ -183,16 +131,19 @@ void W_Mine_Think (void)
        entity head;
 
        self.nextthink = time;
-       if (time > self.cnt)
+       
+       // our lifetime has expired, it's time to die - mine_time just allows us to play a sound for this
+       // TODO: replace this mine_trigger.wav sound with a real countdown
+       if ((time > self.cnt) && (!self.mine_time))
        {
-               other = world;
-               self.projectiledeathtype |= HITTYPE_BOUNCE;
-               W_Mine_Explode();
-               return;
+               if(autocvar_g_balance_minelayer_lifetime_countdown > 0)
+                       spamsound (self, CHAN_PROJECTILE, "weapons/mine_trigger.wav", VOL_BASE, ATTN_NORM);
+               self.mine_time = time + autocvar_g_balance_minelayer_lifetime_countdown;
+               self.minelayer_mines = 1; // make the mine super aggressive
        }
 
        // a player's mines shall explode if he disconnects or dies
-       // TODO: Do this on team change too
+       // TODO: Do this on team change too -- Samual: But isn't a player killed when they switch teams?
        if(self.owner.classname != "player" || self.owner.deadflag != DEAD_NO)
        {
                other = world;
@@ -217,7 +168,10 @@ void W_Mine_Think (void)
 
        // explode if it's time to
        if(self.mine_time && time >= self.mine_time)
+       {
                W_Mine_ProximityExplode();
+               return;
+       }
 
        // remote detonation
        if (self.owner.weapon == WEP_MINE_LAYER)
@@ -266,17 +220,7 @@ void W_Mine_Attack (void)
                }
        }
 
-       // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
-       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
-       {
-               if(autocvar_g_balance_minelayer_reload_ammo)
-               {
-                       self.clip_load -= autocvar_g_balance_minelayer_ammo;
-                       self.minelayer_load = self.clip_load;
-               }
-               else
-                       self.ammo_rockets -= autocvar_g_balance_minelayer_ammo;
-       }
+       W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_minelayer_ammo, autocvar_g_balance_minelayer_reload_ammo);
 
        W_SetupShot_ProjectileSize (self, '-4 -4 -4', '4 4 4', FALSE, 5, "weapons/mine_fire.wav", CHAN_WEAPON, autocvar_g_balance_minelayer_damage);
        pointparticles(particleeffectnum("rocketlauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
@@ -308,7 +252,7 @@ void W_Mine_Attack (void)
        mine.touch = W_Mine_Touch;
        mine.think = W_Mine_Think;
        mine.nextthink = time;
-       mine.cnt = time + autocvar_g_balance_minelayer_lifetime;
+       mine.cnt = time + (autocvar_g_balance_minelayer_lifetime - autocvar_g_balance_minelayer_lifetime_countdown);
        mine.flags = FL_PROJECTILE;
 
        CSQCProjectile(mine, TRUE, PROJECTILE_MINE, TRUE);
@@ -331,6 +275,8 @@ float w_minelayer(float req)
 {
        entity mine;
        float minfound;
+       float ammo_amount;
+
        if (req == WR_AIM)
        {
                // aim and decide to fire if appropriate
@@ -429,7 +375,7 @@ 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
-                       W_MineLayer_Reload();
+                       weapon_action(self.weapon, WR_RELOAD);
                else if (self.BUTTON_ATCK)
                {
                        if(weapon_prepareattack(0, autocvar_g_balance_minelayer_refire))
@@ -453,18 +399,6 @@ float w_minelayer(float req)
                        if(minfound)
                                sound (self, CHAN_WEAPON2, "weapons/mine_det.wav", VOL_BASE, ATTN_NORM);
                }
-
-        if(self.wish_reload)
-        {
-            if(self.switchweapon == self.weapon)
-            {
-                if(self.weaponentity.state == WS_READY)
-                {
-                    self.wish_reload = 0;
-                    W_MineLayer_Reload();
-                }
-            }
-        }
        }
        else if (req == WR_PRECACHE)
        {
@@ -482,22 +416,20 @@ float w_minelayer(float req)
        else if (req == WR_SETUP)
        {
                weapon_setup(WEP_MINE_LAYER);
-               W_MineLayer_SetAmmoCounter();
        }
        else if (req == WR_CHECKAMMO1)
        {
                // don't switch while placing a mine
-               if(autocvar_g_balance_electro_reload_ammo)
+               if (ATTACK_FINISHED(self) <= time || self.weapon != WEP_MINE_LAYER)
                {
-                       if ((ATTACK_FINISHED(self) <= time || self.weapon != WEP_MINE_LAYER)
-                               && self.clip_load < autocvar_g_balance_minelayer_ammo)
-                               return FALSE;
-               }
-               else
-               {
-                       if ((ATTACK_FINISHED(self) <= time || self.weapon != WEP_MINE_LAYER)
-                               && self.ammo_rockets < autocvar_g_balance_minelayer_ammo)
-                               return FALSE;
+                       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;
                }
        }
        else if (req == WR_CHECKAMMO2)
@@ -506,16 +438,7 @@ float w_minelayer(float req)
        }
        else if (req == WR_RELOAD)
        {
-               W_MineLayer_Reload();
-       }
-       else if (req == WR_SWITCHABLE)
-       {
-               // checks if this weapon can be switched to, when reloading is enabled
-               // returns true if there's either enough load in the weapon to use it,
-               // or we have enough ammo to reload the weapon to a usable point
-               float ammo_amount;
-               ammo_amount = autocvar_g_balance_minelayer_ammo;
-               return self.minelayer_load >= ammo_amount || self.ammo_rockets >= ammo_amount;
+               W_Reload(ammo_rockets, autocvar_g_balance_minelayer_ammo, autocvar_g_balance_minelayer_reload_ammo, autocvar_g_balance_minelayer_reload_time, "weapons/reload.wav");
        }
        return TRUE;
 };
@@ -536,15 +459,15 @@ float w_minelayer(float req)
                precache_sound("weapons/mine_exp.wav");
        }
        else if (req == WR_SUICIDEMESSAGE)
-               w_deathtypestring = "%s exploded";
+               w_deathtypestring = _("%s exploded");
        else if (req == WR_KILLMESSAGE)
        {
                if(w_deathtype & HITTYPE_BOUNCE) // (remote detonation)
-                       w_deathtypestring = "%s got too close to %s's mine";
+                       w_deathtypestring = _("%s got too close to %s's mine");
                else if(w_deathtype & HITTYPE_SPLASH)
-                       w_deathtypestring = "%s almost dodged %s's mine";
+                       w_deathtypestring = _("%s almost dodged %s's mine");
                else
-                       w_deathtypestring = "%s stepped on %s's mine";
+                       w_deathtypestring = _("%s stepped on %s's mine");
        }
        return TRUE;
 }