From d76e35463312f99268e71c65c1305f4a58b975f3 Mon Sep 17 00:00:00 2001 From: Martin Taibr Date: Sat, 22 Jul 2017 03:27:52 +0200 Subject: [PATCH] scale item respawntime according to number of players --- qcsrc/common/t_items.qc | 27 +++++++++++++++++++++++++-- qcsrc/common/t_items.qh | 2 -- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index d85cf7861..f40e5def2 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -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; diff --git a/qcsrc/common/t_items.qh b/qcsrc/common/t_items.qh index 1b2293bcf..20963fd26 100644 --- a/qcsrc/common/t_items.qh +++ b/qcsrc/common/t_items.qh @@ -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 -- 2.39.2