Skip to content

Commit

Permalink
Implement spawn protection
Browse files Browse the repository at this point in the history
  • Loading branch information
ResamVi committed Dec 22, 2019
1 parent 6c116e7 commit f407f8d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/engine/shared/config_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ MACRO_CONFIG_INT(InfMinPlayerNumberForMapVote, inf_min_player_number_map_vote, 1
MACRO_CONFIG_INT(InfConWaitingTime, inf_con_waiting_time, 1, 0, 60, CFGFLAG_SERVER, "Number of seconds to wait before enter the game")
MACRO_CONFIG_INT(InfCaptcha, inf_captcha, 0, 0, 1, CFGFLAG_SERVER, "Enable captcha")
MACRO_CONFIG_INT(InfShockwaveAffectHumans, inf_shock_wave_affect_humans, 1, 0, 1, CFGFLAG_SERVER, "Explosion shockwave affect humans")
MACRO_CONFIG_INT(InfSpawnProtectionTime, inf_spawn_protection_time, 1, 0, 10000, CFGFLAG_SERVER, "Time zombies stay invincible while in spawn (in seconds)")

MACRO_CONFIG_INT(InfDefenderLimit, inf_defender_limit, 40, 0, 64, CFGFLAG_SERVER, "Maximum number of defenders in game")
MACRO_CONFIG_INT(InfMedicLimit, inf_medic_limit, 20, 0, 64, CFGFLAG_SERVER, "Maximum number of medics in game")
Expand Down
38 changes: 37 additions & 1 deletion src/game/server/entities/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ m_pConsole(pConsole)
m_PoisonTick = 0;
m_HealTick = 0;
m_InfZoneTick = -1;
m_ProtectionTick = 0;
m_InAirTick = 0;
m_InWater = 0;
m_BonusTick = 0;
Expand Down Expand Up @@ -1754,7 +1755,10 @@ void CCharacter::Tick()
m_HealTick = Server()->Tick();
IncreaseHealth(1);
}
if (m_InfZoneTick < 0) m_InfZoneTick = Server()->Tick(); // Save Tick when zombie enters infection zone
if (m_InfZoneTick < 0) {
m_InfZoneTick = Server()->Tick(); // Save Tick when zombie enters infection zone
GrantSpawnProtection();
}
}
else
{
Expand Down Expand Up @@ -1814,6 +1818,25 @@ void CCharacter::Tick()

if(m_SlipperyTick > 0)
--m_SlipperyTick;

if(m_ProtectionTick > 0) {
--m_ProtectionTick;

// Indicate time left being protected via armor
int maxProtectionTick = Server()->TickSpeed() * g_Config.m_InfSpawnProtectionTime;
float timeLeft = 10 * (m_ProtectionTick / (float)maxProtectionTick);
m_Armor = (int)timeLeft;

// Player left spawn before protection ran out: remove all remaining armor
if(m_InfZoneTick == -1)
{
int maxProtectionTick = Server()->TickSpeed() * g_Config.m_InfSpawnProtectionTime;
float timeLeft = 10 * (m_ProtectionTick / (float)maxProtectionTick);
IncreaseArmor(-(int)timeLeft);

m_ProtectionTick = 0;
}
}

if(m_Poison > 0)
{
Expand Down Expand Up @@ -2868,6 +2891,11 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon, int Mode)
Dmg = DamageAccepted;
}

if(m_ProtectionTick > 0)
{
Dmg = 0;
}

if(From != m_pPlayer->GetCID() && pKillerPlayer)
{
if(IsZombie())
Expand Down Expand Up @@ -3890,6 +3918,14 @@ void CCharacter::SlipperyEffect()
m_SlipperyTick = Server()->TickSpeed()/2;
}

void CCharacter::GrantSpawnProtection()
{
IncreaseArmor(10); // Use Armor as time left indicator that ticks down

if(m_ProtectionTick <= 0)
m_ProtectionTick = Server()->TickSpeed() * g_Config.m_InfSpawnProtectionTime;
}

void CCharacter::Freeze(float Time, int Player, int Reason)
{
if(m_IsFrozen && m_FreezeReason == FREEZEREASON_UNDEAD)
Expand Down
2 changes: 2 additions & 0 deletions src/game/server/entities/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class CCharacter : public CEntity
int m_HealTick;
int m_BonusTick;
int m_InfZoneTick;
int m_ProtectionTick;

int m_FlagID;
int m_HeartID;
Expand Down Expand Up @@ -254,6 +255,7 @@ class CCharacter : public CEntity
void LoveEffect();
void HallucinationEffect();
void SlipperyEffect();
void GrantSpawnProtection();
bool IsTeleportable();
int GetInfWeaponID(int WID);
void UpdateTuningParam();
Expand Down

0 comments on commit f407f8d

Please sign in to comment.