]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Random items: added support for instagib.
authorLyberta <lyberta@lyberta.net>
Sat, 30 Sep 2017 08:57:36 +0000 (11:57 +0300)
committerLyberta <lyberta@lyberta.net>
Sat, 30 Sep 2017 08:57:36 +0000 (11:57 +0300)
mutators.cfg
qcsrc/common/mutators/mutator/instagib/items.qh
qcsrc/common/mutators/mutator/instagib/sv_instagib.qc
qcsrc/common/mutators/mutator/instagib/sv_instagib.qh
qcsrc/common/mutators/mutator/random_items/sv_random_items.qc
qcsrc/server/items.qc

index 7b1218e1897e98a8630fa920790de0b810249b09..9b50a64767cdf357bf1eb98227dde2b5271361c5 100644 (file)
@@ -516,6 +516,10 @@ set g_random_items_replace_item_strength "random" "Classnames to replace strengt
 set g_random_items_replace_item_shield "random" "Classnames to replace shield with."
 set g_random_items_replace_item_fuel_regen "random" "Classnames to replace fuel regeneration with."
 set g_random_items_replace_item_jetpack "random" "Classnames to replace jetpack with."
+set g_random_items_replace_item_vaporizer_cells "random" "Classnames to replace vaporizer cells with."
+set g_random_items_replace_item_invisibility "random" "Classnames to replace invisibility with."
+set g_random_items_replace_item_extralife "random" "Classnames to replace extra life with."
+set g_random_items_replace_item_speed "random" "Classnames to replace speed with."
 set g_random_items_health_probability 1 "Probability of random health items spawning in the map."
 set g_random_items_armor_probability 1 "Probability of random armor items spawning in the map."
 set g_random_items_resource_probability 1 "Probability of random ammo items spawning in the map."
@@ -559,6 +563,10 @@ set g_random_items_strength_probability 1 "Probability of random strength spawni
 set g_random_items_shield_probability 1 "Probability of random shield spawning in the map."
 set g_random_items_fuel_regen_probability 0 "Probability of random fuel regeneration spawning in the map."
 set g_random_items_jetpack_probability 0 "Probability of random jetpack spawning in the map."
+set g_random_items_vaporizer_cells_probability 20 "Probability of random vaporizer cells spawning in the map."
+set g_random_items_invisibility_probability 1 "Probability of random invisibility spawning in the map."
+set g_random_items_extralife_probability 1 "Probability of random extra life spawning in the map."
+set g_random_items_speed_probability 1 "Probability of random speed spawning in the map."
 set g_random_loot 0 "Whether to enable random loot."
 set g_random_loot_min 0 "Minimum amount of loot items."
 set g_random_loot_max 4 "Minimum amount of loot items."
@@ -607,3 +615,7 @@ set g_random_loot_strength_probability 1 "Probability of random strength spawnin
 set g_random_loot_shield_probability 1 "Probability of random shield spawning as loot."
 set g_random_loot_fuel_regen_probability 0 "Probability of random fuel regeneration spawning as loot."
 set g_random_loot_jetpack_probability 0 "Probability of random jetpack spawning as loot."
+set g_random_loot_vaporizer_cells_probability 20 "Probability of random vaporizer cells spawning as loot."
+set g_random_loot_invisibility_probability 1 "Probability of random invisibility spawning as loot."
+set g_random_loot_extralife_probability 1 "Probability of random extra life spawning as loot."
+set g_random_loot_speed_probability 1 "Probability of random speed spawning as loot."
index e80f36e1a087542eb7d3ee0c06f5c493c7902d0c..91671efcb2527a65b6055dcfcd232fc2a4526c73 100644 (file)
@@ -27,7 +27,7 @@ REGISTER_ITEM(VaporizerCells, Ammo) {
     this.m_model                =   MDL_VaporizerCells_ITEM;
     this.m_sound                =   SND_VaporizerCells;
 #endif
-    this.netname                =   "minst_cells";
+    this.netname                =   "vaporizer_cells";
     this.m_name                 =   "Vaporizer Ammo";
     this.m_icon                 =   "ammo_supercells";
 #ifdef SVQC
index a2735b5651852347b1149460dc12db2135268cd6..c62b04fcbd2b04d1f1da6c0598e68902063446a1 100644 (file)
@@ -19,7 +19,7 @@ float autocvar_g_instagib_speed_highspeed;
 
 REGISTER_MUTATOR(mutator_instagib, autocvar_g_instagib && !g_nexball);
 
-spawnfunc(item_minst_cells)
+spawnfunc(item_vaporizer_cells)
 {
        if (!g_instagib) { delete(this); return; }
        StartItem(this, ITEM_VaporizerCells);
@@ -377,13 +377,13 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, SetWeaponArena)
 
 void replace_with_insta_cells(entity item)
 {
-       entity e = new(item_minst_cells);
+       entity e = new(item_vaporizer_cells);
        setorigin(e, item.origin);
        e.noalign = item.noalign;
        e.cnt = item.cnt;
        e.team = item.team;
        e.spawnfunc_checked = true;
-       spawnfunc_item_minst_cells(e);
+       spawnfunc_item_vaporizer_cells(e);
 }
 
 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
@@ -439,7 +439,7 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
                return false;
 
        float cells = GetResourceAmount(item, RESOURCE_CELLS);
-       if(cells > autocvar_g_instagib_ammo_drop && item.classname != "item_minst_cells")
+       if(cells > autocvar_g_instagib_ammo_drop && item.classname != "item_vaporizer_cells")
                SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
 
        if(cells && !item.weapon)
index 78037e8034af3ee564940041273c85b98599190b..051c93525afcddbaf621e42448e9eb09539c0456 100644 (file)
@@ -4,7 +4,7 @@
 
 float autocvar_g_instagib_invis_alpha;
 
-spawnfunc(item_minst_cells);
+spawnfunc(item_vaporizer_cells);
 void instagib_invisibility(entity this);
 void instagib_extralife(entity this);
 void instagib_speed(entity this);
index c374d3446e54213ef94cdf0be605e9a94d01deba..22e0c77c456ff4506092eee8988b881c43df7563 100644 (file)
@@ -72,6 +72,14 @@ enum
        RANDOM_ITEM_SUBTYPE_POWERUP_JETPACK
 };
 
+enum
+{
+       RANDOM_ITEM_SUBTYPE_INSTAGIB_VAPORIZER_CELLS,
+       RANDOM_ITEM_SUBTYPE_INSTAGIB_INVISIBILITY,
+       RANDOM_ITEM_SUBTYPE_INSTAGIB_EXTRA_LIFE,
+       RANDOM_ITEM_SUBTYPE_INSTAGIB_SPEED
+};
+
 //======================= Global variables ====================================
 
 bool autocvar_g_random_items; ///< Whether to enable random items.
@@ -159,9 +167,13 @@ string autocvar_g_random_items_replace_item_fuel_regen;
 /// \brief Classnames to replace jetpack with.
 string autocvar_g_random_items_replace_item_jetpack;
 
-string autocvar_g_random_items_replace_item_minst_cells;
+/// \brief Classnames to replace vaporizer cells with.
+string autocvar_g_random_items_replace_item_vaporizer_cells;
+/// \brief Classnames to replace invisibility with.
 string autocvar_g_random_items_replace_item_invisibility;
+/// \brief Classnames to replace extra life with.
 string autocvar_g_random_items_replace_item_extralife;
+/// \brief Classnames to replace speed with.
 string autocvar_g_random_items_replace_item_speed;
 
 // Map probability cvars
@@ -258,10 +270,14 @@ float autocvar_g_random_items_fuel_regen_probability;
 /// \brief Probability of random jetpack spawning in the map.
 float autocvar_g_random_items_jetpack_probability;
 
-//float autocvar_g_random_items_minst_cells_probability;
-//float autocvar_g_random_items_invisibility_probability;
-//float autocvar_g_random_items_extralife_probability;
-//float autocvar_g_random_items_speed_probability;
+/// \brief Probability of random vaporizer cells spawning in the map.
+float autocvar_g_random_items_vaporizer_cells_probability;
+/// \brief Probability of random invisibility spawning in the map.
+float autocvar_g_random_items_invisibility_probability;
+/// \brief Probability of random extra life spawning in the map.
+float autocvar_g_random_items_extralife_probability;
+/// \brief Probability of random speed spawning in the map.
+float autocvar_g_random_items_speed_probability;
 
 // Loot
 
@@ -366,6 +382,15 @@ float autocvar_g_random_loot_fuel_regen_probability;
 /// \brief Probability of random jetpack spawning as loot.
 float autocvar_g_random_loot_jetpack_probability;
 
+/// \brief Probability of random vaporizer cells spawning as loot.
+float autocvar_g_random_loot_vaporizer_cells_probability;
+/// \brief Probability of random invisibility spawning as loot.
+float autocvar_g_random_loot_invisibility_probability;
+/// \brief Probability of random extra life spawning as loot.
+float autocvar_g_random_loot_extralife_probability;
+/// \brief Probability of random speed spawning as loot.
+float autocvar_g_random_loot_speed_probability;
+
 /// \brief Holds whether random item is spawning. Used to prevent infinite
 /// recursion.
 bool random_items_is_spawning = false;
@@ -541,9 +566,9 @@ string RandomItems_GetItemReplacementClassNames(entity item)
                {
                        return autocvar_g_random_items_replace_item_jetpack;
                }
-               case "item_minst_cells":
+               case "item_vaporizer_cells":
                {
-                       return autocvar_g_random_items_replace_item_minst_cells;
+                       return autocvar_g_random_items_replace_item_vaporizer_cells;
                }
                case "item_invisibility":
                {
@@ -579,21 +604,61 @@ string RandomItems_GetItemReplacementClassNames(entity item)
                                }
                                default:
                                {
-                                       return string_null;
+                                       return "";
                                }
                        }
                }
                default:
                {
-                       return string_null;
+                       return "";
+               }
+       }
+}
+
+/// \brief Returns a random instagib classname of the map item.
+/// \return Random instagib classname of the map item.
+string RandomItems_GetRandomInstagibMapItemClassName()
+{
+       RandomSelection_Init();
+       RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_VAPORIZER_CELLS,
+               autocvar_g_random_items_vaporizer_cells_probability, 1);
+       RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_INVISIBILITY,
+               autocvar_g_random_items_invisibility_probability, 1);
+       RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_EXTRA_LIFE,
+               autocvar_g_random_items_extralife_probability, 1);
+       RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_SPEED,
+               autocvar_g_random_items_speed_probability, 1);
+       int item_type = RandomSelection_chosen_float;
+       switch (item_type)
+       {
+               case RANDOM_ITEM_SUBTYPE_INSTAGIB_VAPORIZER_CELLS:
+               {
+                       return "item_vaporizer_cells";
+               }
+               case RANDOM_ITEM_SUBTYPE_INSTAGIB_INVISIBILITY:
+               {
+                       return "item_invisibility";
+               }
+               case RANDOM_ITEM_SUBTYPE_INSTAGIB_EXTRA_LIFE:
+               {
+                       return "item_extralife";
+               }
+               case RANDOM_ITEM_SUBTYPE_INSTAGIB_SPEED:
+               {
+                       return "item_speed";
                }
        }
+       return "";
 }
 
 /// \brief Returns a random classname of the map item.
 /// \return Random classname of the map item.
 string RandomItems_GetRandomMapItemClassName()
 {
+       if (autocvar_g_instagib)
+       {
+               return RandomItems_GetRandomInstagibMapItemClassName();
+       }
        RandomSelection_Init();
        RandomSelection_AddFloat(RANDOM_ITEM_TYPE_HEALTH,
                autocvar_g_random_items_health_probability, 1);
@@ -639,7 +704,7 @@ string RandomItems_GetRandomMapItemClassName()
                                        return "item_health_mega";
                                }
                        }
-                       return string_null;
+                       return "";
                }
                case RANDOM_ITEM_TYPE_ARMOR:
                {
@@ -672,7 +737,7 @@ string RandomItems_GetRandomMapItemClassName()
                                        return "item_armor_mega";
                                }
                        }
-                       return string_null;
+                       return "";
                }
                case RANDOM_ITEM_TYPE_RESOURCE:
                {
@@ -717,7 +782,7 @@ string RandomItems_GetRandomMapItemClassName()
                                        return "item_fuel";
                                }
                        }
-                       return string_null;
+                       return "";
                }
                case RANDOM_ITEM_TYPE_WEAPON:
                {
@@ -846,7 +911,7 @@ string RandomItems_GetRandomMapItemClassName()
                                        return "weapon_vaporizer";
                                }
                        }
-                       return string_null;
+                       return "";
                }
                case RANDOM_ITEM_TYPE_POWERUP:
                {
@@ -879,10 +944,10 @@ string RandomItems_GetRandomMapItemClassName()
                                        return "item_jetpack";
                                }
                        }
-                       return string_null;
+                       return "";
                }
        }
-       return string_null;
+       return "";
 }
 
 /// \brief Replaces a map item.
@@ -890,38 +955,44 @@ string RandomItems_GetRandomMapItemClassName()
 /// \return Spawned item on success, NULL otherwise.
 entity RandomItems_ReplaceMapItem(entity item)
 {
-       string classnames = RandomItems_GetItemReplacementClassNames(item);
-       if (!classnames)
+       //PrintToChatAll(strcat("Replacing ", item.classname));
+       string new_classnames = RandomItems_GetItemReplacementClassNames(item);
+       if (new_classnames == "")
        {
                return NULL;
        }
-       string class_name;
-       if (classnames == "random")
+       string new_classname;
+       if (new_classnames == "random")
        {
-               class_name = RandomItems_GetRandomMapItemClassName();
-               if (!class_name)
+               new_classname = RandomItems_GetRandomMapItemClassName();
+               if (new_classname == "")
                {
                        return NULL;
                }
        }
        else
        {
-               int num_classnames = tokenize_console(classnames);
-               if (num_classnames == 1)
+               int num_new_classnames = tokenize_console(new_classnames);
+               if (num_new_classnames == 1)
                {
-                       class_name = classnames;
+                       new_classname = new_classnames;
                }
                else
                {
-                       int classname_index = floor(random() * num_classnames);
-                       class_name = argv(classname_index);
+                       int classname_index = floor(random() * num_new_classnames);
+                       new_classname = argv(classname_index);
                }
        }
+       //PrintToChatAll(strcat("Replacing with ", new_classname));
+       if (new_classname == item.classname)
+       {
+               return NULL;
+       }
        random_items_is_spawning = true;
        entity new_item = spawn();
-       new_item.classname = strzone(class_name);
+       new_item.classname = strzone(new_classname);
        new_item.spawnfunc_checked = true;
-       Item_Initialize(new_item, class_name);
+       Item_Initialize(new_item, new_classname);
        random_items_is_spawning = false;
        if (wasfreed(new_item))
        {
@@ -931,10 +1002,51 @@ entity RandomItems_ReplaceMapItem(entity item)
        return new_item;
 }
 
+/// \brief Returns a random instagib classname of the loot item.
+/// \return Random instagib classname of the loot item.
+string RandomItems_GetRandomInstagibLootItemClassName()
+{
+       RandomSelection_Init();
+       RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_VAPORIZER_CELLS,
+               autocvar_g_random_loot_vaporizer_cells_probability, 1);
+       RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_INVISIBILITY,
+               autocvar_g_random_loot_invisibility_probability, 1);
+       RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_EXTRA_LIFE,
+               autocvar_g_random_loot_extralife_probability, 1);
+       RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_SPEED,
+               autocvar_g_random_loot_speed_probability, 1);
+       int item_type = RandomSelection_chosen_float;
+       switch (item_type)
+       {
+               case RANDOM_ITEM_SUBTYPE_INSTAGIB_VAPORIZER_CELLS:
+               {
+                       return "item_vaporizer_cells";
+               }
+               case RANDOM_ITEM_SUBTYPE_INSTAGIB_INVISIBILITY:
+               {
+                       return "item_invisibility";
+               }
+               case RANDOM_ITEM_SUBTYPE_INSTAGIB_EXTRA_LIFE:
+               {
+                       return "item_extralife";
+               }
+               case RANDOM_ITEM_SUBTYPE_INSTAGIB_SPEED:
+               {
+                       return "item_speed";
+               }
+       }
+       return "";
+}
+
+
 /// \brief Returns a random classname of the loot item.
 /// \return Random classname of the loot item.
 string RandomItems_GetRandomLootItemClassName()
 {
+       if (autocvar_g_instagib)
+       {
+               return RandomItems_GetRandomInstagibLootItemClassName();
+       }
        RandomSelection_Init();
        RandomSelection_AddFloat(RANDOM_ITEM_TYPE_HEALTH,
                autocvar_g_random_loot_health_probability, 1);
@@ -980,7 +1092,7 @@ string RandomItems_GetRandomLootItemClassName()
                                        return "item_health_mega";
                                }
                        }
-                       return string_null;
+                       return "";
                }
                case RANDOM_ITEM_TYPE_ARMOR:
                {
@@ -1013,7 +1125,7 @@ string RandomItems_GetRandomLootItemClassName()
                                        return "item_armor_mega";
                                }
                        }
-                       return string_null;
+                       return "";
                }
                case RANDOM_ITEM_TYPE_RESOURCE:
                {
@@ -1058,7 +1170,7 @@ string RandomItems_GetRandomLootItemClassName()
                                        return "item_fuel";
                                }
                        }
-                       return string_null;
+                       return "";
                }
                case RANDOM_ITEM_TYPE_WEAPON:
                {
@@ -1187,7 +1299,7 @@ string RandomItems_GetRandomLootItemClassName()
                                        return "weapon_vaporizer";
                                }
                        }
-                       return string_null;
+                       return "";
                }
                case RANDOM_ITEM_TYPE_POWERUP:
                {
@@ -1220,10 +1332,10 @@ string RandomItems_GetRandomLootItemClassName()
                                        return "item_jetpack";
                                }
                        }
-                       return string_null;
+                       return "";
                }
        }
-       return string_null;
+       return "";
 }
 
 /// \brief Spawns a random loot item.
@@ -1232,7 +1344,7 @@ string RandomItems_GetRandomLootItemClassName()
 void RandomItems_SpawnLootItem(vector position)
 {
        string class_name = RandomItems_GetRandomLootItemClassName();
-       if (!class_name)
+       if (class_name == "")
        {
                return;
        }
@@ -1299,7 +1411,7 @@ MUTATOR_HOOKFUNCTION(random_items, ItemTouched, CBC_ORDER_LAST)
        entity new_item = RandomItems_ReplaceMapItem(item);
        if (new_item == NULL)
        {
-               return false;
+               return;
        }
        Item_ScheduleRespawn(new_item);
        delete(item);
index 56c59d263194a85df2be96733a5fb152a4568f20..0f5735d9ee705b354950984009001715937b798b 100644 (file)
@@ -214,9 +214,9 @@ void Item_Initialize(entity item, string class_name)
                        spawnfunc_item_jetpack(item);
                        return;
                }
-               case "item_minst_cells":
+               case "item_vaporizer_cells":
                {
-                       spawnfunc_item_minst_cells(item);
+                       spawnfunc_item_vaporizer_cells(item);
                        return;
                }
                case "item_invisibility":
@@ -235,7 +235,7 @@ void Item_Initialize(entity item, string class_name)
                        return;
                }
        }
-       error("Item_Initialize: Invalid classname");
+       error("Item_Initialize: Invalid classname ", class_name);
 }
 
 entity Item_CreateLoot(string class_name, vector position, vector vel,