]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Added FilterItemDefinition hook.
authorLyberta <lyberta@lyberta.net>
Mon, 19 Mar 2018 10:59:10 +0000 (13:59 +0300)
committerLyberta <lyberta@lyberta.net>
Mon, 19 Mar 2018 10:59:10 +0000 (13:59 +0300)
qcsrc/common/items/item.qh
qcsrc/common/mutators/mutator/melee_only/sv_melee_only.qc
qcsrc/common/mutators/mutator/nix/sv_nix.qc
qcsrc/common/mutators/mutator/random_items/sv_random_items.qc
qcsrc/server/items.qc
qcsrc/server/items.qh
qcsrc/server/mutators/events.qh
qcsrc/server/mutators/mutator/gamemode_lms.qc
qcsrc/server/weapons/spawning.qc

index b7fc933e8b5dbaf35dde8a37fca1762c51a4e08a..effbf0c7eb2878ce67b63cc218c065e895c400ad 100644 (file)
@@ -7,6 +7,10 @@
 #include <common/stats.qh>
 #endif
 
+#ifdef SVQC
+#include <server/items.qh>
+#endif
+
 const int IT_UNLIMITED_WEAPON_AMMO             =  BIT(0); // when this bit is set, using a weapon does not reduce ammo. Checkpoints can give this powerup.
 const int IT_UNLIMITED_SUPERWEAPONS            =  BIT(1); // when this bit is set, superweapons don't expire. Checkpoints can give this powerup.
 
@@ -48,7 +52,14 @@ const int IT_PICKUPMASK                      = IT_UNLIMITED_AMMO | IT_JETPACK | IT_FU
 .float  invincible_finished = _STAT(INVINCIBLE_FINISHED);
 
 #define SPAWNFUNC_ITEM(name, item) \
-    spawnfunc(name) { StartItem(this, item); }
+    spawnfunc(name) \
+       { \
+               if (!Item_IsDefinitionAllowed(item)) \
+               { \
+                       return; \
+               } \
+               StartItem(this, item); \
+       }
 
 #else
 
index d6796fc0590e0581be335989330a384934bee600..5603dd4901c0601cc8940320acbc1f87b6ab1f3e 100644 (file)
@@ -25,11 +25,11 @@ MUTATOR_HOOKFUNCTION(melee_only, ForbidThrowCurrentWeapon)
        return true;
 }
 
-MUTATOR_HOOKFUNCTION(melee_only, FilterItem)
+MUTATOR_HOOKFUNCTION(melee_only, FilterItemDefinition)
 {
-       entity item = M_ARGV(0, entity);
+       entity definition = M_ARGV(0, entity);
 
-       switch (item.itemdef)
+       switch (definition)
        {
                case ITEM_HealthSmall:
                case ITEM_ArmorSmall:
index c174b530f0a48e94cb20d6661fd069ecb0e2ecc4..953321cc0ba5a708bb30d73e0e218b8e4ad67cf0 100644 (file)
@@ -244,15 +244,15 @@ MUTATOR_HOOKFUNCTION(nix, BuildMutatorsPrettyString)
        M_ARGV(0, string) = strcat(M_ARGV(0, string), ", NIX");
 }
 
-MUTATOR_HOOKFUNCTION(nix, FilterItem)
+MUTATOR_HOOKFUNCTION(nix, FilterItemDefinition)
 {
-       entity item = M_ARGV(0, entity);
+       entity definition = M_ARGV(0, entity);
 
-       if(item.itemdef.instanceOfHealth || item.itemdef.instanceOfArmor)
+       if (definition.instanceOfHealth || definition.instanceOfArmor)
        {
                return !autocvar_g_nix_with_healtharmor;
        }
-       else if(item.itemdef.instanceOfPowerup)
+       else if (definition.instanceOfPowerup)
        {
                return !autocvar_g_nix_with_powerups;
        }
index 3d305746269e1a29cbfb718ceb536175d04693af..3d5d5c0f8e184790b709fe8d3360ec052a22d319 100644 (file)
@@ -172,7 +172,8 @@ string RandomItems_GetRandomVanillaItemClassName(string prefix)
 string RandomItems_GetRandomInstagibItemClassName(string prefix)
 {
        RandomSelection_Init();
-       FOREACH(Items, it.spawnflags & ITEM_FLAG_INSTAGIB,
+       FOREACH(Items, it.spawnflags & ITEM_FLAG_INSTAGIB &&
+               Item_IsDefinitionAllowed(it),
        {
                string cvar_name = sprintf("g_%s_%s_probability", prefix,
                        it.m_canonical_spawnfunc);
@@ -190,7 +191,8 @@ string RandomItems_GetRandomOverkillItemClassName(string prefix)
 {
        RandomSelection_Init();
        FOREACH(Items, (it.spawnflags & ITEM_FLAG_OVERKILL) &&
-               !(it.spawnflags & ITEM_FLAG_MUTATORBLOCKED),
+               !(it.spawnflags & ITEM_FLAG_MUTATORBLOCKED) &&
+               Item_IsDefinitionAllowed(it),
        {
                string cvar_name = sprintf("g_%s_overkill_%s_probability", prefix,
                        it.m_canonical_spawnfunc);
@@ -242,7 +244,8 @@ string RandomItems_GetRandomItemClassNameWithProperty(string prefix,
        .bool item_property)
 {
        RandomSelection_Init();
-       FOREACH(Items, it.item_property && (it.spawnflags & ITEM_FLAG_NORMAL),
+       FOREACH(Items, it.item_property && (it.spawnflags & ITEM_FLAG_NORMAL) &&
+               Item_IsDefinitionAllowed(it),
        {
                string cvar_name = sprintf("g_%s_%s_probability", prefix,
                        it.m_canonical_spawnfunc);
index 7d248834f72566af97313317a42a3a50c226f637..ebb16543df277b56a6b04e352e14c614c29db00c 100644 (file)
 /// this item is on the ground.
 .bool m_isexpiring;
 
+entity Item_FindDefinition(string class_name)
+{
+       FOREACH(Items, it.m_canonical_spawnfunc == class_name,
+       {
+               return it;
+       });
+       FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
+       {
+               return it.m_pickup;
+       });
+       return NULL;
+}
+
+bool Item_IsAllowed(string class_name)
+{
+       entity definition = Item_FindDefinition(class_name);
+       if (definition == NULL)
+       {
+               return false;
+       }
+       return Item_IsDefinitionAllowed(definition);
+}
+
+bool Item_IsDefinitionAllowed(entity definition)
+{
+       return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
+}
+
 entity Item_Create(string class_name, vector position, bool no_align)
 {
        entity item = spawn();
index 1abcf64e0879442a3b8ade446bc724ca8250e503..d8703370c2e570c501f51260aa21db7f231531f1 100644 (file)
@@ -4,6 +4,26 @@
 /// \brief Header file that describes the functions related to game items.
 /// \copyright GNU GPLv2 or any later version.
 
+/// \brief Returns the item definition corresponding to the given class name.
+/// \param[in] class_name Class name to search for.
+/// \return Item definition corresponding to the given class name or NULL is not
+/// found.
+entity Item_FindDefinition(string class_name);
+
+/// \brief Checks whether the items with the specified class name are allowed to
+/// spawn.
+/// \param[in] class_name Item class name to check.
+/// \return True items with the specified class name are allowed to spawn, false
+/// otherwise.
+bool Item_IsAllowed(string class_name);
+
+/// \brief Checks whether the items with the specified definition are allowed to
+/// spawn.
+/// \param[in] definition Item definition to check.
+/// \return True items with the specified definition are allowed to spawn, false
+/// otherwise.
+bool Item_IsDefinitionAllowed(entity definition);
+
 /// \brief Creates a new item.
 /// \param[in] class_name Class name of the item.
 /// \param[in] position Position of the item.
@@ -12,7 +32,7 @@
 /// \return Item on success, NULL otherwise.
 entity Item_Create(string class_name, vector position, bool no_align);
 
-/// \brief Initializes the item according to classname.
+/// \brief Initializes the item according to class name.
 /// \param[in,out] item Item to initialize.
 /// \param[in] class_name Class name to use.
 /// \return No return.
index 6853c04a15641dc69bd6e52f7da39615a41610a4..ab713e044cd17175f8860837bf0d7a1aca23292d 100644 (file)
@@ -229,6 +229,14 @@ MUTATOR_HOOKABLE(SetStartItems, EV_NO_ARGS);
     /**/
 MUTATOR_HOOKABLE(CustomizeWaypoint, EV_CustomizeWaypoint);
 
+/** Check if items having the given definition are allowed to spawn.
+ *  Return true to disallow spawning.
+ */
+#define EV_FilterItemDefinition(i, o) \
+    /** item        */ i(entity, MUTATOR_ARGV_0_entity) \
+    /**/
+MUTATOR_HOOKABLE(FilterItemDefinition, EV_FilterItemDefinition);
+
 /**
  * checks if the current item may be spawned (.items and .weapons may be read and written to, as well as the ammo_ fields)
  * return error to request removal
index 94c4a998c2cc616b4d3f1f64487eb4b5fb98e42e..a57b2ae2d07ab150bfd494492935da44e421e221 100644 (file)
@@ -317,14 +317,14 @@ MUTATOR_HOOKFUNCTION(lms, ForbidPlayerScore_Clear)
        return true;
 }
 
-MUTATOR_HOOKFUNCTION(lms, FilterItem)
+MUTATOR_HOOKFUNCTION(lms, FilterItemDefinition)
 {
-       entity item = M_ARGV(0, entity);
+       entity definition = M_ARGV(0, entity);
 
-       if(autocvar_g_lms_extra_lives)
-       if(item.itemdef == ITEM_ExtraLife)
+       if (autocvar_g_lms_extra_lives && definition == ITEM_ExtraLife)
+       {
                return false;
-
+       }
        return true;
 }
 
index d47351cb37a727aab87f100d2ccb61ddd98a5824..17f2ddeeee2bb567271f1f689c8376494168a5a6 100644 (file)
@@ -88,6 +88,13 @@ void weapon_defaultspawnfunc(entity this, Weapon e)
                }
        }
 
+       if (!Item_IsDefinitionAllowed(wpn.m_pickup))
+       {
+               delete(this);
+               startitem_failed = true;
+               return;
+       }
+
        if (!this.respawntime)
        {
                if (wpn.spawnflags & WEP_FLAG_SUPERWEAPON)