]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
scale item respawntime according to number of players
authorMartin Taibr <taibr.martin@gmail.com>
Sat, 22 Jul 2017 01:27:52 +0000 (03:27 +0200)
committerMartin Taibr <taibr.martin@gmail.com>
Sat, 22 Jul 2017 01:27:52 +0000 (03:27 +0200)
qcsrc/common/t_items.qc
qcsrc/common/t_items.qh

index d85cf7861478c33e8b4451e8e624cb5f30c7d9c5..f40e5def2e3a9512eef057057c11496b02ddc4c5 100644 (file)
@@ -624,12 +624,35 @@ void Item_ScheduleRespawnIn(entity e, float t)
        }
 }
 
+AUTOCVAR(g_pickup_respawntime_scaling_a, float, 0.0, "Scale respawn time according to a*rt / (p+b) + c*rt where rt is normal respawn time and p number of players");
+AUTOCVAR(g_pickup_respawntime_scaling_b, float, 0.0, "Scale respawn time according to a*rt / (p+b) + c*rt where rt is normal respawn time and p number of players");
+AUTOCVAR(g_pickup_respawntime_scaling_c, float, 1.0, "Scale respawn time according to a*rt / (p+b) + c*rt where rt is normal respawn time and p number of players");
 void Item_ScheduleRespawn(entity e)
 {
        if(e.respawntime > 0)
        {
                Item_Show(e, 0);
-               Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
+
+               CheckAllowedTeams(NULL);
+               GetTeamCounts(NULL);
+               int players = 0;
+               if (c1 != -1) players += c1;
+               if (c2 != -1) players += c2;
+               if (c3 != -1) players += c3;
+               if (c4 != -1) players += c4;
+               float adjusted_respawntime;
+               if (players >= 2) {
+                       float a = autocvar_g_pickup_respawntime_scaling_a;
+                       float b = autocvar_g_pickup_respawntime_scaling_b;
+                       float c = autocvar_g_pickup_respawntime_scaling_c;
+                       adjusted_respawntime = a * e.respawntime / (players + b) + c * e.respawntime;
+               } else {
+                       adjusted_respawntime = e.respawntime;
+               }
+               //LOG_INFOF("item %s will respawn in %f\n", e.classname, adjusted_respawntime);
+               // range: adjusted_respawntime - respawntimejitter .. adjusted_respawntime + respawntimejitter
+               float actual_time = adjusted_respawntime + crandom() * e.respawntimejitter;
+               Item_ScheduleRespawnIn(e, actual_time);
        }
        else // if respawntime is -1, this item does not respawn
                Item_Show(e, -1);
@@ -1366,7 +1389,7 @@ spawnfunc(item_rockets)
 
 spawnfunc(item_bullets)
 {
-       if(!weaponswapping && autocvar_sv_q3acompat_machineshotgunswap && 
+       if(!weaponswapping && autocvar_sv_q3acompat_machineshotgunswap &&
           (this.classname != "droppedweapon"))
        {
                weaponswapping = true;
index 1b2293bcff0651d442032c328d7a0455783adb3b..20963fd269e562bc06c3d1316c30dbb1c123b197 100644 (file)
@@ -63,8 +63,6 @@ bool have_pickup_item(entity this);
 
 const float ITEM_RESPAWN_TICKS = 10;
 
-#define ITEM_RESPAWNTIME(i)         ((i).respawntime + crandom() * (i).respawntimejitter)
-       // range: respawntime - respawntimejitter .. respawntime + respawntimejitter
 #define ITEM_RESPAWNTIME_INITIAL(i) (ITEM_RESPAWN_TICKS + random() * ((i).respawntime + (i).respawntimejitter - ITEM_RESPAWN_TICKS))
        // range: 10 .. respawntime + respawntimejitter