]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'terencehill/instagib_item_fix' into 'master'
authorbones_was_here <bones_was_here@xonotic.au>
Wed, 10 May 2023 08:10:26 +0000 (08:10 +0000)
committerbones_was_here <bones_was_here@xonotic.au>
Wed, 10 May 2023 08:10:26 +0000 (08:10 +0000)
Instagib and LMS: fix a few issues with instagib items and in particular extralife

See merge request xonotic/xonotic-data.pk3dir!1164

qcsrc/common/gamemodes/gamemode/lms/sv_lms.qc
qcsrc/common/items/inventory.qh
qcsrc/common/items/item/pickup.qc
qcsrc/common/mutators/mutator/instagib/sv_instagib.qc
qcsrc/common/mutators/mutator/instagib/sv_instagib.qh
qcsrc/server/compat/quake3.qh

index 51df1bb2ae7a1aad68432909a87da9bd4a002044..d53b213492d81e5140c14be648defa93c2fbefba 100644 (file)
@@ -643,42 +643,36 @@ MUTATOR_HOOKFUNCTION(lms, ForbidPlayerScore_Clear)
 
 MUTATOR_HOOKFUNCTION(lms, FilterItemDefinition)
 {
-       if (autocvar_g_lms_items)
+       if (autocvar_g_lms_items || autocvar_g_pickup_items > 0)
                return false;
 
-       entity definition = M_ARGV(0, entity);
-
-       if (autocvar_g_lms_extra_lives && definition == ITEM_ExtraLife)
-       {
+       entity def = M_ARGV(0, entity);
+       if (autocvar_g_powerups && autocvar_g_lms_extra_lives && (def == ITEM_ExtraLife || def == ITEM_HealthMega))
                return false;
-       }
-       return (autocvar_g_pickup_items <= 0); // only allow items if explicitly enabled
-}
 
-void lms_extralife(entity this)
-{
-       StartItem(this, ITEM_ExtraLife);
+       return true;
 }
 
-MUTATOR_HOOKFUNCTION(lms, OnEntityPreSpawn)
+void lms_replace_with_extralife(entity this)
 {
-       if (MUTATOR_RETURNVALUE) return false;
-       if (!autocvar_g_powerups) return false;
-       if (!autocvar_g_lms_extra_lives) return false;
-
-       entity ent = M_ARGV(0, entity);
-
-       // Can't use .itemdef here
-       if (ent.classname != "item_health_mega") return false;
+       entity e = new(item_extralife);
+       Item_CopyFields(this, e);
 
-       entity e = spawn();
-       setthink(e, lms_extralife);
-
-       Item_CopyFields(ent, e);
+       StartItem(e, ITEM_ExtraLife);
+}
 
-       e.nextthink = time + 0.1;
+MUTATOR_HOOKFUNCTION(lms, FilterItem)
+{
+       entity item = M_ARGV(0, entity);
+       entity def = item.itemdef;
+       if(def == ITEM_HealthMega && !(autocvar_g_lms_items || autocvar_g_pickup_items > 0))
+       {
+               if(autocvar_g_powerups && autocvar_g_lms_extra_lives)
+                       lms_replace_with_extralife(item);
+               return true;
+       }
 
-       return true;
+       return false;
 }
 
 MUTATOR_HOOKFUNCTION(lms, ItemTouch)
@@ -692,6 +686,7 @@ MUTATOR_HOOKFUNCTION(lms, ItemTouch)
        {
                Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES, autocvar_g_lms_extra_lives);
                GameRules_scoring_add(toucher, LMS_LIVES, autocvar_g_lms_extra_lives);
+               Inventory_pickupitem(item.itemdef, toucher);
                return MUT_ITEMTOUCH_PICKUP;
        }
 
index 6f6ebdc452a9f768b2626fc5aecf00e9f054876c..118b7079d0c832303ae7aa563172515fea190273 100644 (file)
@@ -154,9 +154,18 @@ void Inventory_new(PlayerState this)
        inv.owner = this;
        Net_LinkEntity(inv, false, 0, Inventory_Send);
 }
+
 void Inventory_delete(entity e) { delete(e.inventory); }
 void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; }
 
+void Inventory_pickupitem(Pickup this, entity player)
+{
+       //LOG_DEBUGF("entity %i picked up %s", player, this.m_name);
+       entity store = IS_PLAYER(player) ? PS(player) : player;
+       ++store.inventory.inv_items[this.m_id];
+       Inventory_update(store);
+}
+
 void Inventory_clear(entity store)
 {
     // NOTE: you will need to perform Inventory_update after this to update the storage entity
index a3c2d779edcde089ac3d4f7e142693de8e47070b..52cf8c3e8d07af1b933dc5eda7e05a81a518f74d 100644 (file)
@@ -10,12 +10,8 @@ METHOD(Pickup, giveTo, bool(Pickup this, entity item, entity player))
 {
     TC(Pickup, this);
     bool b = Item_GiveTo(item, player);
-    if (b) {
-        //LOG_DEBUGF("entity %i picked up %s", player, this.m_name);
-        entity store = IS_PLAYER(player) ? PS(player) : player;
-        store.inventory.inv_items[this.m_id]++;
-        Inventory_update(store);
-    }
+    if (b)
+        Inventory_pickupitem(this, player);
     return b;
 }
 
index 7b270f32f602a38afe8249e511a49bcc142f93f6..916ac06ba62eb6640f2f66e2175bc874f8d8908d 100644 (file)
@@ -17,23 +17,6 @@ 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)
-{
-       this.invisibility_finished = autocvar_g_instagib_invisibility_time;
-       StartItem(this, ITEM_Invisibility);
-}
-
-void instagib_extralife(entity this)
-{
-       StartItem(this, ITEM_ExtraLife);
-}
-
-void instagib_speed(entity this)
-{
-       this.speed_finished = autocvar_g_instagib_speed_time;
-       StartItem(this, ITEM_Speed);
-}
-
 /// \brief Returns a random classname of the instagib item.
 /// \param[in] prefix Prefix of the cvars that hold probabilities.
 /// \return Random classname of the instagib item.
@@ -294,47 +277,73 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, SetWeaponArena)
        M_ARGV(0, string) = "off";
 }
 
-void replace_with_insta_cells(entity item)
+void instagib_replace_item_with(entity this, GameItem def)
 {
-       entity e = new(item_vaporizer_cells);
-       Item_CopyFields(item, e);
-       spawnfunc_item_vaporizer_cells(e);
+       entity new_item = NULL;
+       switch (def)
+       {
+               case ITEM_Invisibility:
+                       new_item = new(item_invisibility);
+                       new_item.invisibility_finished = autocvar_g_instagib_invisibility_time;
+                       break;
+               case ITEM_Speed:
+                       new_item = new(item_speed);
+                       new_item.speed_finished = autocvar_g_instagib_speed_time;
+                       break;
+               case ITEM_ExtraLife:
+                       new_item = new(item_extralife);
+                       break;
+               case ITEM_VaporizerCells:
+                       new_item = new(item_vaporizer_cells);
+                       break;
+               default:
+                       error("Unhandled replacement item.");
+       }
+       Item_CopyFields(this, new_item);
+       StartItem(new_item, def);
 }
 
 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_item_with(item, ITEM_Invisibility);
+                       else if (r < 0.6)
+                               instagib_replace_item_with(item, ITEM_ExtraLife);
+                       else
+                               instagib_replace_item_with(item, ITEM_Speed);
                }
                return true;
        }
-       else if(item.classname == "item_rockets")
+
+       if(def == ITEM_Cells)
+       {
+               if(autocvar_g_instagib_ammo_convert_cells)
+                       instagib_replace_item_with(item, ITEM_VaporizerCells);
+               return true;
+       }
+       else if(def == ITEM_Rockets)
        {
                if(autocvar_g_instagib_ammo_convert_rockets)
-               {
-                       replace_with_insta_cells(item);
-               }
+                       instagib_replace_item_with(item, ITEM_VaporizerCells);
                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_item_with(item, ITEM_VaporizerCells);
                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_item_with(item, ITEM_VaporizerCells);
                return true;
        }
 
@@ -346,7 +355,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_item_with(item, ITEM_VaporizerCells);
                return true;
        }
 
@@ -400,46 +409,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");
index 4ee7e491fb36ea0f0993118888ff2c302019919c..97d84d49be10bcb6dc9f2ae7af05d0f8a4956e0d 100644 (file)
@@ -32,9 +32,6 @@ float autocvar_g_instagib_invisibility_time;
 /// \brief Time of speed powerup in seconds.
 float autocvar_g_instagib_speed_time;
 
-void instagib_invisibility(entity this);
-void instagib_extralife(entity this);
-void instagib_speed(entity this);
 IntrusiveList g_instagib_items;
 
 REGISTER_MUTATOR(mutator_instagib, autocvar_g_instagib && !MapInfo_LoadedGametype.m_weaponarena)
index d2c547b6f6e9d3bacce6388c7f5eed703c642be1..1253c92a93b4887d525152d86ffc7b33e6b2ae2e 100644 (file)
@@ -21,7 +21,7 @@ int GetAmmoConsumptionQ3(string netname);
        { \
                if(this.count && xonwep.ammo_type) \
                        SetResource(this, xonwep.ammo_type, this.count * GetAmmoConsumptionQ3(xonwep.netname)); \
-       SPAWNFUNC_BODY(GetAmmoItem(xonwep.ammo_type)) \
+               SPAWNFUNC_BODY(GetAmmoItem(xonwep.ammo_type)) \
        }
 
 // Ammo only, conditional