]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/instagib/sv_instagib.qc
Merge branch 'master' into Mario/strength_stat_field
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / instagib / sv_instagib.qc
index 85bef1d49c4562a40b68dbd4e5f146551a523422..272680fb20351adf6de41097db683967036ce2e2 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;
@@ -10,27 +14,16 @@ bool autocvar_g_instagib_ammo_convert_cells;
 bool autocvar_g_instagib_ammo_convert_rockets;
 bool autocvar_g_instagib_ammo_convert_shells;
 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>
-
-REGISTER_MUTATOR(mutator_instagib, autocvar_g_instagib && !g_nexball)
+IntrusiveList g_instagib_items;
+STATIC_INIT(instagib)
 {
-       MUTATOR_ONADD
-       {
-               ITEM_VaporizerCells.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
-               ITEM_Invisibility.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
-               ITEM_Speed.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
-       }
-       MUTATOR_ONROLLBACK_OR_REMOVE
-       {
-               ITEM_VaporizerCells.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
-               ITEM_Invisibility.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
-               ITEM_Speed.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
-       }
+       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)
@@ -50,6 +43,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)
@@ -68,7 +81,7 @@ void instagib_ammocheck(entity this)
 
        if(IS_DEAD(this) || game_stopped)
                instagib_stop_countdown(this);
-       else if (GetResourceAmount(this, RESOURCE_CELLS) > 0 || (this.items & IT_UNLIMITED_WEAPON_AMMO) || (this.flags & FL_GODMODE))
+       else if (GetResource(this, RES_CELLS) > 0 || (this.items & IT_UNLIMITED_AMMO) || (this.flags & FL_GODMODE))
                instagib_stop_countdown(this);
        else if(autocvar_g_rm && autocvar_g_rm_laser)
        {
@@ -80,63 +93,63 @@ void instagib_ammocheck(entity this)
        }
        else
        {
-               float hp = GetResourceAmount(this, RESOURCE_HEALTH);
+               float hp = GetResource(this, RES_HEALTH);
                this.instagib_needammo = true;
                if (hp <= 5)
                {
-                       Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
+                       Damage(this, this, this, 5, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
                        Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_INSTAGIB_TERMINATED);
                }
                else if (hp <= 10)
                {
-                       Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
+                       Damage(this, this, this, 5, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
                        Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_1);
                }
                else if (hp <= 20)
                {
-                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
+                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
                        Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_2);
                }
                else if (hp <= 30)
                {
-                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
+                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
                        Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_3);
                }
                else if (hp <= 40)
                {
-                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
+                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
                        Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_4);
                }
                else if (hp <= 50)
                {
-                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
+                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
                        Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_5);
                }
                else if (hp <= 60)
                {
-                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
+                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
                        Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_6);
                }
                else if (hp <= 70)
                {
-                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
+                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
                        Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_7);
                }
                else if (hp <= 80)
                {
-                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
+                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
                        Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_8);
                }
                else if (hp <= 90)
                {
                        Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_INSTAGIB_FINDAMMO);
-                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
+                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
                        Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_9);
                }
                else
                {
                        Send_Notification(NOTIF_ONE_ONLY, this, MSG_MULTI, MULTI_INSTAGIB_FINDAMMO);
-                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
+                       Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
                }
        }
        this.instagib_nextthink = time + 1;
@@ -147,6 +160,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);
@@ -212,8 +232,8 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
 
        if (player.items & ITEM_Invisibility.m_itemid)
        {
-               play_countdown(player, player.strength_finished, SND_POWEROFF);
-               if (time > player.strength_finished)
+               play_countdown(player, STAT(STRENGTH_FINISHED, player), SND_POWEROFF);
+               if (time > STAT(STRENGTH_FINISHED, player))
                {
                        player.alpha = default_player_alpha;
                        player.exteriorweaponentity.alpha = default_weapon_alpha;
@@ -223,7 +243,7 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
        }
        else
        {
-               if (time < player.strength_finished)
+               if (time < STAT(STRENGTH_FINISHED, player))
                {
                        player.alpha = autocvar_g_instagib_invis_alpha;
                        player.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
@@ -253,14 +273,13 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
        }
 }
 
-.float stat_sv_maxspeed;
-
-MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics)
+MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics_UpdateStats)
 {
        entity player = M_ARGV(0, entity);
+       // these automatically reset, no need to worry
 
        if(player.items & ITEM_Speed.m_itemid)
-               player.stat_sv_maxspeed = player.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
+               STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_instagib_speed_highspeed;
 }
 
 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
@@ -308,11 +327,11 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, Damage_Calculate)
                        if(!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker))
                                frag_force = '0 0 0';
 
-                       float armor = GetResourceAmount(frag_target, RESOURCE_ARMOR);
+                       float armor = GetResource(frag_target, RES_ARMOR);
                        if(armor)
                        {
                                armor -= 1;
-                               SetResourceAmount(frag_target, RESOURCE_ARMOR, armor);
+                               SetResource(frag_target, RES_ARMOR, armor);
                                frag_damage = 0;
                                frag_target.damage_dealt += 1;
                                frag_attacker.damage_dealt += 1;
@@ -333,7 +352,6 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, Damage_Calculate)
 
                                if(frag_target != frag_attacker)
                                {
-                                       if(frag_damage <= 0 && GetResourceAmount(frag_target, RESOURCE_HEALTH) > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
                                        if(!autocvar_g_instagib_blaster_keepforce)
                                                frag_force = '0 0 0';
                                }
@@ -346,11 +364,11 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, Damage_Calculate)
        if(frag_mirrordamage > 0)
        {
                // just lose extra LIVES, don't kill the player for mirror damage
-               float armor = GetResourceAmount(frag_attacker, RESOURCE_ARMOR);
+               float armor = GetResource(frag_attacker, RES_ARMOR);
                if(armor > 0)
                {
                        armor -= 1;
-                       SetResourceAmount(frag_attacker, RESOURCE_ARMOR, armor);
+                       SetResource(frag_attacker, RES_ARMOR, armor);
                        Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
                        frag_attacker.damage_dealt += frag_mirrordamage;
                }
@@ -366,7 +384,7 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, Damage_Calculate)
        M_ARGV(6, vector) = frag_force;
 }
 
-MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
+MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems, CBC_ORDER_LAST)
 {
        start_health       = warmup_start_health       = 100;
        start_armorvalue   = warmup_start_armorvalue   = 0;
@@ -438,7 +456,7 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
 
        if(item.weapon == WEP_VAPORIZER.m_id && Item_IsLoot(item))
        {
-               SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
+               SetResource(item, RES_CELLS, autocvar_g_instagib_ammo_drop);
                return false;
        }
 
@@ -451,9 +469,9 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
        if(item.flags & FL_POWERUP)
                return false;
 
-       float cells = GetResourceAmount(item, RESOURCE_CELLS);
+       float cells = GetResource(item, RES_CELLS);
        if(cells > autocvar_g_instagib_ammo_drop && item.classname != "item_vaporizer_cells")
-               SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
+               SetResource(item, RES_CELLS, autocvar_g_instagib_ammo_drop);
 
        if(cells && !item.weapon)
                return false;
@@ -488,10 +506,10 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
        entity item = M_ARGV(0, entity);
        entity toucher = M_ARGV(1, entity);
 
-       if(GetResourceAmount(item, RESOURCE_CELLS))
+       if(GetResource(item, RES_CELLS))
        {
                // play some cool sounds ;)
-               float hp = GetResourceAmount(toucher, RESOURCE_HEALTH);
+               float hp = GetResource(toucher, RES_HEALTH);
                if (IS_CLIENT(toucher))
                {
                        if(hp <= 5)
@@ -501,15 +519,15 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
                }
 
                if(hp < 100)
-                       SetResourceAmount(toucher, RESOURCE_HEALTH, 100);
+                       SetResource(toucher, RES_HEALTH, 100);
 
                return MUT_ITEMTOUCH_CONTINUE;
        }
 
        if(item.itemdef == ITEM_ExtraLife)
        {
-               GiveResource(toucher, RESOURCE_ARMOR, autocvar_g_instagib_extralives);
-               Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES);
+               GiveResource(toucher, RES_ARMOR, autocvar_g_instagib_extralives);
+               Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES, autocvar_g_instagib_extralives);
                return MUT_ITEMTOUCH_PICKUP;
        }