From 4158041d6d414700111727f3d1527c791513d098 Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 11 Mar 2018 15:33:33 +0100 Subject: [PATCH] Reimplement g_pickup_respawntime_initial_random 1 to be more self-contained and to generate a different respawn time when game starts after warmup; it fixes #2000 --- qcsrc/common/t_items.qc | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index 249615d2d..02a0dc171 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -663,8 +663,6 @@ void Item_ScheduleRespawn(entity e) AUTOCVAR(g_pickup_respawntime_initial_random, int, 1, "For items that don't start spawned: 0: spawn after their normal respawntime; 1: spawn after `random * respawntime` with the *same* random; 2: same as 1 but each item has separate random"); -float shared_random; -STATIC_INIT(shared_random) { shared_random = random(); } void Item_ScheduleInitialRespawn(entity e) { Item_Show(e, 0); @@ -675,18 +673,26 @@ void Item_ScheduleInitialRespawn(entity e) // range: respawntime .. respawntime + respawntimejitter spawn_in = e.respawntime + random() * e.respawntimejitter; } - else if (autocvar_g_pickup_respawntime_initial_random == 1) + else { + float rnd; + if (autocvar_g_pickup_respawntime_initial_random == 1) + { + static float shared_random = 0; + // NOTE this code works only if items are scheduled at the same time (normal case) + // NOTE2 random() can't return exactly 1 so this check always work as intended + if (!shared_random || floor(time) > shared_random) + shared_random = floor(time) + random(); + rnd = shared_random - floor(time); + } + else + rnd = random(); + // range: // if respawntime >= ITEM_RESPAWN_TICKS: ITEM_RESPAWN_TICKS .. respawntime + respawntimejitter // else: 0 .. ITEM_RESPAWN_TICKS // this is to prevent powerups spawning unexpectedly without waypoints - spawn_in = ITEM_RESPAWN_TICKS + shared_random * (e.respawntime + e.respawntimejitter - ITEM_RESPAWN_TICKS); - } - else - { - // range: same as 1 - spawn_in = ITEM_RESPAWN_TICKS + random() * (e.respawntime + e.respawntimejitter - ITEM_RESPAWN_TICKS); + spawn_in = ITEM_RESPAWN_TICKS + rnd * (e.respawntime + e.respawntimejitter - ITEM_RESPAWN_TICKS); } Item_ScheduleRespawnIn(e, max(0, game_starttime - time) + ((e.respawntimestart) ? e.respawntimestart : spawn_in)); -- 2.39.2