From b4a2ce2ac57ede8efbf32f8419925a8f2a9056b3 Mon Sep 17 00:00:00 2001 From: cypress Date: Thu, 14 Dec 2023 12:28:04 -0500 Subject: [PATCH] SERVER: Force stuck zombie respawn --- source/server/ai/zombie_core.qc | 44 +++++++++++++++++++++++++++++++++ source/server/defs/custom.qc | 2 ++ 2 files changed, 46 insertions(+) diff --git a/source/server/ai/zombie_core.qc b/source/server/ai/zombie_core.qc index 52de3af..47c1a7c 100644 --- a/source/server/ai/zombie_core.qc +++ b/source/server/ai/zombie_core.qc @@ -397,6 +397,46 @@ void(float which) SetZombieHitBox = } }; +// +// Zombie_ProcessRespawn() +// Logic called by Zombie_Think for checking +// the last origin every second, for determining +// if a zombie is "stuck" inside and needs to re-spawn. +// +void() Zombie_ProcessRespawn = +{ + // Check once every 3 seconds + if (self.respawn_timer < time && !self.outside) { + // Check if the Zombie has barely moved (16qu) + if (vlen(self.new_ofs - self.origin) <= 16) { + // Continue to iterate + self.respawn_iterator++; + + // 30 seconds have passed -- assume properly stuck, respawn. + if (self.respawn_iterator >= 10) { + self.respawn_iterator = 0; + + // Kill it. + self.th_die(); + + // This is a pseudo-hack that just tells the rounds core that we should + // spawn another. + Current_Zombies--; + Remaining_Zombies++; + } + } else { + // Set to zero -- Zombie is moving appropriately. + self.respawn_iterator = 0; + } + + // Iterate another 3 seconds. + self.respawn_timer = time + 3; + + // Update our last origin + self.new_ofs = self.origin; + } +} + void() zombie_decide; void() Zombie_Think = //called every frame for zombies { @@ -424,6 +464,9 @@ void() Zombie_Think = //called every frame for zombies } } + Zombie_ProcessRespawn(); + + // Electro-Shock Death if (self.death_timer < time && self.death_timer_activated == true) { self.th_die(); } @@ -1168,6 +1211,7 @@ void(entity ent) Zombie_Death_Cleanup = { } ent.health = 0; + ent.respawn_iterator = 0; Remaining_Zombies = Remaining_Zombies - 1; } diff --git a/source/server/defs/custom.qc b/source/server/defs/custom.qc index aaf1227..cef2b6c 100644 --- a/source/server/defs/custom.qc +++ b/source/server/defs/custom.qc @@ -395,6 +395,8 @@ float z_health; .float bleedingtime; .float time_to_die; +.float respawn_timer; +.float respawn_iterator; float crandom();