]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Better random items.
authorLyberta <lyberta@lyberta.net>
Sat, 9 Jun 2018 21:41:06 +0000 (00:41 +0300)
committerLyberta <lyberta@lyberta.net>
Sat, 9 Jun 2018 21:41:06 +0000 (00:41 +0300)
qcsrc/common/items/item.qh
qcsrc/common/items/item/armor.qh
qcsrc/common/items/item/health.qh
qcsrc/common/mutators/mutator/instagib/items.qh
qcsrc/common/mutators/mutator/instagib/sv_instagib.qc
qcsrc/common/mutators/mutator/overkill/sv_overkill.qc
qcsrc/common/mutators/mutator/random_items/sv_random_items.qc
qcsrc/common/mutators/mutator/random_items/sv_random_items.qh
randomitems-overkill.cfg [new file with mode: 0644]
randomitems-xonotic.cfg
ruleset-overkill.cfg

index e59152076b754552eb266411710fdbab1e4efcbb..31b8f43cb17fe6041ec7c6155278db7aaad5823c 100644 (file)
@@ -72,9 +72,7 @@ const int IT_PICKUPMASK                       = IT_UNLIMITED_AMMO | IT_JETPACK | IT_FU
 enum
 {
        ITEM_FLAG_NORMAL = BIT(0), ///< Item is usable during normal gameplay.
-       ITEM_FLAG_INSTAGIB = BIT(1), ///< Item is usable in instagib.
-       ITEM_FLAG_OVERKILL = BIT(2), ///< Item is usable in overkill.
-       ITEM_FLAG_MUTATORBLOCKED = BIT(3)
+       ITEM_FLAG_MUTATORBLOCKED = BIT(1)
 };
 
 #define ITEM_HANDLE(signal, ...) __Item_Send_##signal(__VA_ARGS__)
index 7f37c75aec002465260b1852810253e05c6a4b11..b00ccc0f26b7908fc9a948c808594e4560f80564 100644 (file)
@@ -34,7 +34,7 @@ void item_armorsmall_init(entity item)
 REGISTER_ITEM(ArmorSmall, Armor) {
     this.m_canonical_spawnfunc = "item_armor_small";
 #ifdef GAMEQC
-    this.spawnflags = ITEM_FLAG_NORMAL | ITEM_FLAG_OVERKILL;
+    this.spawnflags = ITEM_FLAG_NORMAL;
     this.m_model                =   MDL_ArmorSmall_ITEM;
     this.m_sound                =   SND_ArmorSmall;
 #endif
@@ -72,7 +72,7 @@ void item_armormedium_init(entity item)
 REGISTER_ITEM(ArmorMedium, Armor) {
     this.m_canonical_spawnfunc = "item_armor_medium";
 #ifdef GAMEQC
-    this.spawnflags = ITEM_FLAG_NORMAL | ITEM_FLAG_OVERKILL;
+    this.spawnflags = ITEM_FLAG_NORMAL;
     this.m_model                =   MDL_ArmorMedium_ITEM;
     this.m_sound                =   SND_ArmorMedium;
 #endif
@@ -110,7 +110,7 @@ void item_armorbig_init(entity item)
 REGISTER_ITEM(ArmorBig, Armor) {
     this.m_canonical_spawnfunc = "item_armor_big";
 #ifdef GAMEQC
-    this.spawnflags = ITEM_FLAG_NORMAL | ITEM_FLAG_OVERKILL;
+    this.spawnflags = ITEM_FLAG_NORMAL;
     this.m_model                =   MDL_ArmorBig_ITEM;
     this.m_sound                =   SND_ArmorBig;
 #endif
@@ -150,7 +150,7 @@ void item_armormega_init(entity item)
 REGISTER_ITEM(ArmorMega, Armor) {
     this.m_canonical_spawnfunc = "item_armor_mega";
 #ifdef GAMEQC
-    this.spawnflags = ITEM_FLAG_NORMAL | ITEM_FLAG_OVERKILL;
+    this.spawnflags = ITEM_FLAG_NORMAL;
     this.m_model                =   MDL_ArmorMega_ITEM;
     this.m_sound                =   SND_ArmorMega;
 #endif
index da431086e18587448cf697c8127390fd166134f0..879ee5101a668cc67ee9858a0e2d1d5a42d7dcfc 100644 (file)
@@ -150,7 +150,7 @@ void item_healthmega_init(entity item)
 REGISTER_ITEM(HealthMega, Health) {
     this.m_canonical_spawnfunc = "item_health_mega";
 #ifdef GAMEQC
-    this.spawnflags = ITEM_FLAG_NORMAL | ITEM_FLAG_OVERKILL;
+    this.spawnflags = ITEM_FLAG_NORMAL;
     this.m_model                =   MDL_HealthMega_ITEM;
     this.m_sound                =   SND_HealthMega;
 #endif
index fe0070afcb1589bd8cbcd45af5e6486aa4632430..ad7ba6ba40ff13f21ca51924639a419e781b644d 100644 (file)
@@ -25,7 +25,7 @@ void ammo_vaporizercells_init(entity item)
 REGISTER_ITEM(VaporizerCells, Ammo) {
     this.m_canonical_spawnfunc = "item_vaporizer_cells";
 #ifdef GAMEQC
-    this.spawnflags = ITEM_FLAG_INSTAGIB | ITEM_FLAG_MUTATORBLOCKED;
+    this.spawnflags = ITEM_FLAG_MUTATORBLOCKED;
     this.m_model                =   MDL_VaporizerCells_ITEM;
     this.m_sound                =   SND_VaporizerCells;
 #endif
@@ -52,8 +52,7 @@ SOUND(ExtraLife, Item_Sound("megahealth"));
 REGISTER_ITEM(ExtraLife, Powerup) {
     this.m_canonical_spawnfunc = "item_extralife";
 #ifdef GAMEQC
-       this.spawnflags = ITEM_FLAG_INSTAGIB;
-    this.m_model                =   MDL_ExtraLife_ITEM;
+       this.m_model                =   MDL_ExtraLife_ITEM;
     this.m_sound                =   SND_ExtraLife;
 #endif
     this.netname                =   "extralife";
@@ -82,7 +81,7 @@ void powerup_invisibility_init(entity item);
 REGISTER_ITEM(Invisibility, Powerup) {
     this.m_canonical_spawnfunc = "item_invisibility";
 #ifdef GAMEQC
-       this.spawnflags = ITEM_FLAG_INSTAGIB | ITEM_FLAG_MUTATORBLOCKED;
+       this.spawnflags = ITEM_FLAG_MUTATORBLOCKED;
     this.m_model            =   MDL_Invisibility_ITEM;
     this.m_sound            =   SND_Invisibility;
     this.m_glow             =   true;
@@ -117,7 +116,7 @@ void powerup_speed_init(entity item);
 REGISTER_ITEM(Speed, Powerup) {
     this.m_canonical_spawnfunc = "item_speed";
 #ifdef GAMEQC
-       this.spawnflags = ITEM_FLAG_INSTAGIB | ITEM_FLAG_MUTATORBLOCKED;
+       this.spawnflags = ITEM_FLAG_MUTATORBLOCKED;
     this.m_model            =   MDL_Speed_ITEM;
     this.m_sound            =   SND_Speed;
     this.m_glow             =   true;
index f93b69235df1213ce71b19aa5e446c8c0383dda7..3cda4485f1a3efde2bcb324335fbc2da635ea11b 100644 (file)
@@ -1,5 +1,9 @@
 #include "sv_instagib.qh"
 
+#include <server/client.qh>
+#include <common/items/_mod.qh>
+#include "../random_items/sv_random_items.qh"
+
 bool autocvar_g_instagib_damagedbycontents = true;
 bool autocvar_g_instagib_blaster_keepdamage = false;
 bool autocvar_g_instagib_blaster_keepforce = false;
@@ -13,9 +17,15 @@ bool autocvar_g_instagib_ammo_convert_bullets;
 int autocvar_g_instagib_extralives;
 float autocvar_g_instagib_speed_highspeed;
 
-#include <server/client.qh>
-
-#include <common/items/_mod.qh>
+IntrusiveList g_instagib_items;
+STATIC_INIT()
+{
+       g_instagib_items = IL_NEW();
+       IL_PUSH(g_instagib_items, ITEM_VaporizerCells);
+       IL_PUSH(g_instagib_items, ITEM_ExtraLife);
+       IL_PUSH(g_instagib_items, ITEM_Invisibility);
+       IL_PUSH(g_instagib_items, ITEM_Speed);
+}
 
 void instagib_invisibility(entity this)
 {
@@ -34,6 +44,26 @@ void instagib_speed(entity this)
        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.
+string RandomItems_GetRandomInstagibItemClassName(string prefix)
+{
+       RandomSelection_Init();
+       IL_EACH(g_instagib_items, Item_IsDefinitionAllowed(it),
+       {
+               string cvar_name = sprintf("g_%s_%s_probability", prefix,
+                       it.m_canonical_spawnfunc);
+               if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
+               {
+                       LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
+                       continue;
+               }
+               RandomSelection_AddString(it.m_canonical_spawnfunc, cvar(cvar_name), 1);
+       });
+       return RandomSelection_chosen_string;
+}
+
 .float instagib_nextthink;
 .float instagib_needammo;
 void instagib_stop_countdown(entity e)
@@ -131,6 +161,13 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd)
        FOREACH_CLIENT(IS_PLAYER(it), { instagib_stop_countdown(it); });
 }
 
+MUTATOR_HOOKFUNCTION(mutator_instagib, RandomItems_GetRandomItemClassName)
+{
+       M_ARGV(1, string) = RandomItems_GetRandomInstagibItemClassName(
+               M_ARGV(0, string));
+       return true;
+}
+
 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
 {
        entity item = M_ARGV(1, entity);
index f4432a9cbb830973f25fea4a1e6dffc4e6203f77..b6ff5e14d37fdf83e2d82e915ef36b0fe830b067 100644 (file)
@@ -6,6 +6,64 @@ bool autocvar_g_overkill_itemwaypoints = true;
 
 .Weapon ok_lastwep[MAX_WEAPONSLOTS];
 
+IntrusiveList g_overkill_items;
+STATIC_INIT()
+{
+       g_overkill_items = IL_NEW();
+       IL_PUSH(g_overkill_items, ITEM_HealthMega);
+       IL_PUSH(g_overkill_items, ITEM_ArmorSmall);
+       IL_PUSH(g_overkill_items, ITEM_ArmorMedium);
+       IL_PUSH(g_overkill_items, ITEM_ArmorBig);
+       IL_PUSH(g_overkill_items, ITEM_ArmorMega);
+}
+
+/// \brief Returns a random classname of the overkill item.
+/// \param[in] prefix Prefix of the cvars that hold probabilities.
+/// \return Random classname of the overkill item.
+string RandomItems_GetRandomOverkillItemClassName(string prefix)
+{
+       RandomSelection_Init();
+       IL_EACH(g_overkill_items, !(it.spawnflags & ITEM_FLAG_MUTATORBLOCKED) &&
+               Item_IsDefinitionAllowed(it),
+       {
+               string cvar_name = sprintf("g_%s_%s_probability", prefix,
+                       it.m_canonical_spawnfunc);
+               if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
+               {
+                       LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
+                       continue;
+               }
+               RandomSelection_AddString(it.m_canonical_spawnfunc, cvar(cvar_name), 1);
+       });
+       string cvar_name = sprintf("g_%s_weapon_okhmg_probability", prefix);
+       if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
+       {
+               LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
+       }
+       else
+       {
+               RandomSelection_AddString("weapon_okhmg", cvar(cvar_name), 1);
+       }
+       cvar_name = sprintf("g_%s_weapon_okrpc_probability", prefix);
+       if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
+       {
+               LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
+       }
+       else
+       {
+               RandomSelection_AddString("weapon_okrpc", cvar(cvar_name), 1);
+       }
+       return RandomSelection_chosen_string;
+}
+
+
+MUTATOR_HOOKFUNCTION(ok, RandomItems_GetRandomItemClassName)
+{
+       M_ARGV(1, string) = RandomItems_GetRandomOverkillItemClassName(
+               M_ARGV(0, string));
+       return true;
+}
+
 MUTATOR_HOOKFUNCTION(ok, Damage_Calculate, CBC_ORDER_LAST)
 {
        entity frag_attacker = M_ARGV(1, entity);
index 251e57b8749cad4a70dbfe747daa8303d08bf3aa..183808021b92ecdbdc2324a2431a5ecdbe135c9d 100644 (file)
@@ -53,13 +53,9 @@ string RandomItems_GetRandomItemClassNameWithProperty(string prefix,
 
 string RandomItems_GetRandomItemClassName(string prefix)
 {
-       if (MUTATOR_IS_ENABLED(mutator_instagib))
+       if (MUTATOR_CALLHOOK(RandomItems_GetRandomItemClassName, prefix))
        {
-               return RandomItems_GetRandomInstagibItemClassName(prefix);
-       }
-       if (MUTATOR_IS_ENABLED(ok))
-       {
-               return RandomItems_GetRandomOverkillItemClassName(prefix);
+               return M_ARGV(1, string);
        }
        return RandomItems_GetRandomVanillaItemClassName(prefix,
                RANDOM_ITEM_TYPE_ALL);
@@ -196,61 +192,6 @@ string RandomItems_GetRandomVanillaItemClassName(string prefix, int types)
        return "";
 }
 
-string RandomItems_GetRandomInstagibItemClassName(string prefix)
-{
-       RandomSelection_Init();
-       FOREACH(Items, it.spawnflags & ITEM_FLAG_INSTAGIB &&
-               Item_IsDefinitionAllowed(it),
-       {
-               string cvar_name = sprintf("g_%s_%s_probability", prefix,
-                       it.m_canonical_spawnfunc);
-               if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
-               {
-                       LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
-                       continue;
-               }
-               RandomSelection_AddString(it.m_canonical_spawnfunc, cvar(cvar_name), 1);
-       });
-       return RandomSelection_chosen_string;
-}
-
-string RandomItems_GetRandomOverkillItemClassName(string prefix)
-{
-       RandomSelection_Init();
-       FOREACH(Items, (it.spawnflags & ITEM_FLAG_OVERKILL) &&
-               !(it.spawnflags & ITEM_FLAG_MUTATORBLOCKED) &&
-               Item_IsDefinitionAllowed(it),
-       {
-               string cvar_name = sprintf("g_%s_overkill_%s_probability", prefix,
-                       it.m_canonical_spawnfunc);
-               if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
-               {
-                       LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
-                       continue;
-               }
-               RandomSelection_AddString(it.m_canonical_spawnfunc, cvar(cvar_name), 1);
-       });
-       string cvar_name = sprintf("g_%s_overkill_weapon_okhmg_probability", prefix);
-       if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
-       {
-               LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
-       }
-       else
-       {
-               RandomSelection_AddString("weapon_okhmg", cvar(cvar_name), 1);
-       }
-       cvar_name = sprintf("g_%s_overkill_weapon_okrpc_probability", prefix);
-       if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
-       {
-               LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
-       }
-       else
-       {
-               RandomSelection_AddString("weapon_okrpc", cvar(cvar_name), 1);
-       }
-       return RandomSelection_chosen_string;
-}
-
 //========================= Free functions ====================================
 
 /// \brief Returns list of classnames to replace a map item with.
index d49e3effa83fed685b08f5144fad4d8cfb19f6d0..c94375ceaeeb98d7648179ed6845bfff251dacd1 100644 (file)
@@ -33,15 +33,13 @@ string RandomItems_GetRandomItemClassName(string prefix);
 /// jetpack and new toys.
 string RandomItems_GetRandomVanillaItemClassName(string prefix, int types);
 
-/// \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.
-string RandomItems_GetRandomInstagibItemClassName(string prefix);
-
-/// \brief Returns a random classname of the overkill item.
-/// \param[in] prefix Prefix of the cvars that hold probabilities.
-/// \return Random classname of the overkill item.
-string RandomItems_GetRandomOverkillItemClassName(string prefix);
+/// \brief Called when random item classname is requested.
+#define EV_RandomItems_GetRandomItemClassName(i, o) \
+       /** prefix */    i(string, MUTATOR_ARGV_0_string) \
+       /** classname */ o(string, MUTATOR_ARGV_1_string) \
+    /**/
+MUTATOR_HOOKABLE(RandomItems_GetRandomItemClassName,
+       EV_RandomItems_GetRandomItemClassName);
 
 REGISTER_MUTATOR(random_items, (autocvar_g_random_items ||
        autocvar_g_random_loot));
diff --git a/randomitems-overkill.cfg b/randomitems-overkill.cfg
new file mode 100644 (file)
index 0000000..e2a2617
--- /dev/null
@@ -0,0 +1,21 @@
+// Random items mutator config for Overkill ruleset
+
+// Map items
+
+set g_random_items_item_health_mega_probability 1 "Probability of random mega health spawning in the map during overkill."
+set g_random_items_item_armor_small_probability 10 "Probability of random small armor spawning in the map during overkill."
+set g_random_items_item_armor_medium_probability 4 "Probability of random medium armor spawning in the map during overkill."
+set g_random_items_item_armor_big_probability 2 "Probability of random big armor spawning in the map during overkill."
+set g_random_items_item_armor_mega_probability 1 "Probability of random mega armor spawning in the map during overkill."
+set g_random_items_weapon_okhmg_probability 0.5 "Probability of random overkill HMG spawning in the map during overkill."
+set g_random_items_weapon_okrpc_probability 0.5 "Probability of random overkill RPC spawning in the map during overkill."
+
+// Loot
+
+set g_random_loot_item_health_mega_probability 1 "Probability of random mega health spawning as loot during overkill."
+set g_random_loot_item_armor_small_probability 10 "Probability of random small armor spawning as loot during overkill."
+set g_random_loot_item_armor_medium_probability 4 "Probability of random medium armor spawning as loot during overkill."
+set g_random_loot_item_armor_big_probability 2 "Probability of random big armor spawning as loot during overkill."
+set g_random_loot_item_armor_mega_probability 1 "Probability of random mega armor spawning as loot during overkill."
+set g_random_loot_weapon_okhmg_probability 1 "Probability of random overkill HMG spawning as loot during overkill."
+set g_random_loot_weapon_okrpc_probability 1 "Probability of random overkill RPC spawning as loot during overkill."
index 1491ffd0c9ea0284b83e6556e37dca69592a4170..bffa2b1ac466fe903b9aceedbdfaab9ab2f804cd 100644 (file)
@@ -99,13 +99,6 @@ set g_random_items_item_vaporizer_cells_probability 20 "Probability of random va
 set g_random_items_item_invisibility_probability 1 "Probability of random invisibility spawning in the map."
 set g_random_items_item_extralife_probability 1 "Probability of random extra life spawning in the map."
 set g_random_items_item_speed_probability 1 "Probability of random speed spawning in the map."
-set g_random_items_overkill_item_health_mega_probability 1 "Probability of random mega health spawning in the map during overkill."
-set g_random_items_overkill_item_armor_small_probability 10 "Probability of random small armor spawning in the map during overkill."
-set g_random_items_overkill_item_armor_medium_probability 4 "Probability of random medium armor spawning in the map during overkill."
-set g_random_items_overkill_item_armor_big_probability 2 "Probability of random big armor spawning in the map during overkill."
-set g_random_items_overkill_item_armor_mega_probability 1 "Probability of random mega armor spawning in the map during overkill."
-set g_random_items_overkill_weapon_okhmg_probability 0.5 "Probability of random overkill HMG spawning in the map during overkill."
-set g_random_items_overkill_weapon_okrpc_probability 0.5 "Probability of random overkill RPC spawning in the map during overkill."
 
 // Loot
 
@@ -163,10 +156,3 @@ set g_random_loot_item_vaporizer_cells_probability 20 "Probability of random vap
 set g_random_loot_item_invisibility_probability 1 "Probability of random invisibility spawning as loot."
 set g_random_loot_item_extralife_probability 1 "Probability of random extra life spawning as loot."
 set g_random_loot_item_speed_probability 1 "Probability of random speed spawning as loot."
-set g_random_loot_overkill_item_health_mega_probability 1 "Probability of random mega health spawning as loot during overkill."
-set g_random_loot_overkill_item_armor_small_probability 10 "Probability of random small armor spawning as loot during overkill."
-set g_random_loot_overkill_item_armor_medium_probability 4 "Probability of random medium armor spawning as loot during overkill."
-set g_random_loot_overkill_item_armor_big_probability 2 "Probability of random big armor spawning as loot during overkill."
-set g_random_loot_overkill_item_armor_mega_probability 1 "Probability of random mega armor spawning as loot during overkill."
-set g_random_loot_overkill_weapon_okhmg_probability 1 "Probability of random overkill HMG spawning as loot during overkill."
-set g_random_loot_overkill_weapon_okrpc_probability 1 "Probability of random overkill RPC spawning as loot during overkill."
index 49eb730c93d2c19c4a6b22eb3313ca547eace313..cc512e0c40dee4247caae0f4dcd920f52c6aa2e7 100644 (file)
@@ -5,6 +5,7 @@
 exec xonotic-server.cfg
 exec balance-overkill.cfg
 exec physicsOverkill.cfg
+exec randomitems-overkill.cfg
 
 // general gameplay
 set g_overkill 1