]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/instagib/sv_instagib.qc
LMS and Instagib: fix extralife not counted in the Itemstats panel and wrongly displa...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / instagib / sv_instagib.qc
index 7b270f32f602a38afe8249e511a49bcc142f93f6..a6ac55d9308f41f54ed60035b52fe1c13811a830 100644 (file)
@@ -17,21 +17,30 @@ bool autocvar_g_instagib_ammo_convert_rockets;
 bool autocvar_g_instagib_ammo_convert_shells;
 bool autocvar_g_instagib_ammo_convert_bullets;
 
-void instagib_invisibility(entity this)
+void instagib_replace_with_invisibility(entity this)
 {
-       this.invisibility_finished = autocvar_g_instagib_invisibility_time;
-       StartItem(this, ITEM_Invisibility);
+       entity e = new(item_invisibility);
+       Item_CopyFields(this, e);
+
+       e.invisibility_finished = autocvar_g_instagib_invisibility_time;
+       StartItem(e, ITEM_Invisibility);
 }
 
-void instagib_extralife(entity this)
+void instagib_replace_with_extralife(entity this)
 {
-       StartItem(this, ITEM_ExtraLife);
+       entity e = new(item_extralife);
+       Item_CopyFields(this, e);
+
+       StartItem(e, ITEM_ExtraLife);
 }
 
-void instagib_speed(entity this)
+void instagib_replace_with_speed(entity this)
 {
-       this.speed_finished = autocvar_g_instagib_speed_time;
-       StartItem(this, ITEM_Speed);
+       entity e = new(item_speed);
+       Item_CopyFields(this, e);
+
+       e.speed_finished = autocvar_g_instagib_speed_time;
+       StartItem(e, ITEM_Speed);
 }
 
 /// \brief Returns a random classname of the instagib item.
@@ -294,47 +303,54 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, SetWeaponArena)
        M_ARGV(0, string) = "off";
 }
 
-void replace_with_insta_cells(entity item)
+void instagib_replace_with_vaporizer_cells(entity item)
 {
        entity e = new(item_vaporizer_cells);
        Item_CopyFields(item, e);
-       spawnfunc_item_vaporizer_cells(e);
+       StartItem(e, ITEM_VaporizerCells);
 }
 
 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
 {
        entity item = M_ARGV(0, entity);
-
-       if(item.classname == "item_cells")
+       entity def = item.itemdef;
+       if(def == ITEM_Strength || def == ITEM_Shield || def == ITEM_HealthMega || def == ITEM_ArmorMega)
        {
-               if(autocvar_g_instagib_ammo_convert_cells)
+               if(autocvar_g_powerups)
                {
-                       replace_with_insta_cells(item);
+                       float r = random();
+                       if (r < 0.3)
+                               instagib_replace_with_invisibility(item);
+                       else if (r < 0.6)
+                               instagib_replace_with_extralife(item);
+                       else
+                               instagib_replace_with_speed(item);
                }
                return true;
        }
-       else if(item.classname == "item_rockets")
+
+       if(def == ITEM_Cells)
+       {
+               if(autocvar_g_instagib_ammo_convert_cells)
+                       instagib_replace_with_vaporizer_cells(item);
+               return true;
+       }
+       else if(def == ITEM_Rockets)
        {
                if(autocvar_g_instagib_ammo_convert_rockets)
-               {
-                       replace_with_insta_cells(item);
-               }
+                       instagib_replace_with_vaporizer_cells(item);
                return true;
        }
-       else if(item.classname == "item_shells")
+       else if(def == ITEM_Shells)
        {
                if(autocvar_g_instagib_ammo_convert_shells)
-               {
-                       replace_with_insta_cells(item);
-               }
+                       instagib_replace_with_vaporizer_cells(item);
                return true;
        }
-       else if(item.classname == "item_bullets")
+       else if(def == ITEM_Bullets)
        {
                if(autocvar_g_instagib_ammo_convert_bullets)
-               {
-                       replace_with_insta_cells(item);
-               }
+                       instagib_replace_with_vaporizer_cells(item);
                return true;
        }
 
@@ -346,7 +362,7 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
 
        if(item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id)
        {
-               replace_with_insta_cells(item);
+               instagib_replace_with_vaporizer_cells(item);
                return true;
        }
 
@@ -400,46 +416,13 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
        {
                GiveResource(toucher, RES_ARMOR, autocvar_g_instagib_extralives);
                Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES, autocvar_g_instagib_extralives);
+               Inventory_pickupitem(item.itemdef, toucher);
                return MUT_ITEMTOUCH_PICKUP;
        }
 
        return MUT_ITEMTOUCH_CONTINUE;
 }
 
-MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
-{
-       if (MUTATOR_RETURNVALUE) return false;
-       if (!autocvar_g_powerups) { return; }
-       entity ent = M_ARGV(0, entity);
-       // Can't use .itemdef here
-       if (!(ent.classname == "item_strength" || ent.classname == "item_shield" || ent.classname == "item_invincible" || ent.classname == "item_health_mega"))
-               return;
-
-       entity e = spawn();
-
-       float r = random();
-       if (r < 0.3)
-       {
-               e.classname = "item_invisibility";
-               setthink(e, instagib_invisibility);
-       }
-       else if (r < 0.6)
-       {
-               e.classname = "item_extralife";
-               setthink(e, instagib_extralife);
-       }
-       else
-       {
-               e.classname = "item_speed";
-               setthink(e, instagib_speed);
-       }
-
-       Item_CopyFields(ent, e);
-       e.nextthink = time + 0.1;
-
-       return true;
-}
-
 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
 {
        M_ARGV(0, string) = strcat(M_ARGV(0, string), ":instagib");