]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Improved powerups_dropondeath setting
authorz411 <z411@omaera.org>
Fri, 5 Nov 2021 17:44:24 +0000 (14:44 -0300)
committerz411 <z411@omaera.org>
Fri, 5 Nov 2021 17:44:24 +0000 (14:44 -0300)
qcsrc/common/mutators/mutator/powerups/sv_powerups.qc
qcsrc/common/mutators/mutator/powerups/sv_powerups.qh
xonotic-server.cfg

index 47ad0c5098eff2bce12f0511a4bcb94c10d49a9e..7491d853efb5ba5c30be35d9e6de06272ced00f6 100644 (file)
@@ -80,20 +80,34 @@ MUTATOR_HOOKFUNCTION(powerups, MonsterValidTarget)
 void powerups_DropItem(entity this, StatusEffects effect)
 {
        entity item = Item_DefinitionFromInternalName(effect.netname);
-       float timeleft = StatusEffects_gettime(effect, this);
-       if((timeleft - time) <= 0 || !item)
+       float t = StatusEffects_gettime(effect, this);
+       float timeleft = t - time;
+
+       if(timeleft <= 1 || !item)
                return;
        entity e = spawn();
+
+       // If we want the timer to keep running, we enable expiring then use the exact time the powerup will finish at.
+       // If we want the timer to freeze, we disable expiring and we just use the time left of the powerup.
+       // See Item_SetExpiring() below.
+       float finished_time = (autocvar_g_powerups_dropondeath == 2 ? timeleft : t);
+
+       // If the timer is frozen, the item will stay on the floor for 60 secs (TODO hardcoded for now),
+       // otherwise it'll disappear after the timer runs out.
+       float time_to_live = (autocvar_g_powerups_dropondeath == 2 ? 60 : timeleft);
+
        // TODO: items cannot hold their "item field" yet, so we need to list all the powerups here!
        switch(item)
        {
-               case ITEM_Strength: e.strength_finished = timeleft; break;
-               case ITEM_Shield: e.invincible_finished = timeleft; break;
-               case ITEM_Invisibility: e.invisibility_finished = timeleft; break;
-               case ITEM_Speed: e.speed_finished = timeleft; break;
+               case ITEM_Strength: e.strength_finished = finished_time; break;
+               case ITEM_Shield: e.invincible_finished = finished_time; break;
+               case ITEM_Invisibility: e.invisibility_finished = finished_time; break;
+               case ITEM_Speed: e.speed_finished = finished_time; break;
        }
-       Item_InitializeLoot(e, item.m_canonical_spawnfunc, this.origin + '0 0 32', randomvec() * 175 + '0 0 175', min(timeleft - time, 10));
-       Item_SetExpiring(e, true);
+       Item_InitializeLoot(e, item.m_canonical_spawnfunc, this.origin + '0 0 32', randomvec() * 175 + '0 0 175', time_to_live);
+
+       if(autocvar_g_powerups_dropondeath != 2)
+               Item_SetExpiring(e, true);
 }
 
 MUTATOR_HOOKFUNCTION(powerups, PlayerDies)
index 1d79396c8cbacbe271a4a8e94169778677abdca1..c9e7282b5efbcebbc6cd64f1c932a1dedb61cd45 100644 (file)
@@ -5,7 +5,7 @@
 #include "powerups.qh"
 
 int autocvar_g_powerups;
-bool autocvar_g_powerups_dropondeath;
+int autocvar_g_powerups_dropondeath;
 bool autocvar_g_powerups_stack;
 
 REGISTER_MUTATOR(powerups, true);
index b1718900a83b70852cc3411787e44b0dc7390568..54e9c8be1e55bd56f759f0c3265a9ae58f752505 100644 (file)
@@ -198,7 +198,7 @@ set g_shootfromfixedorigin "" "if set to a string like 0 y z, the gun is moved t
 set g_weapon_stay 0 "1: ghost weapons can be picked up but give no ammo, thrown guns have ammo 2: ghost weapons can be picked up and refill ammo to one pickup size, thrown guns have no ammo (to prevent infinite ammo abuse)"
 set g_weapon_throwable 1 "if set to 1, weapons can be dropped"
 set g_powerups -1 "if set to 0 no powerups will spawn, if 1 they will spawn in all game modes, -1 is game mode default"
-set g_powerups_dropondeath 0 "whether or not held powerups should be droppd when the player dies"
+set g_powerups_dropondeath 0 "whether or not held powerups should be droppd when the player dies (1 = timer keeps running, 2 = timer freezes until picked up)"
 set g_powerups_stack 0 "enables stacking of powerup timers when picking up a powerup you already have; otherwise timer is reset to the time granted by the item, if greater than the time you currently have"
 set g_powerups_strength 1 "allow strength powerups to spawn"
 set g_powerups_shield 1 "allow shield powerups to spawn"