Don't allow infinite shotgun bounce (fixes #4809)

This commit is contained in:
def 2022-03-13 00:02:42 +01:00
parent 4337bcf7de
commit 6b497afba4
2 changed files with 12 additions and 3 deletions

View file

@ -112,7 +112,12 @@ void CLaser::DoBounce()
m_Pos = TempPos;
m_Dir = normalize(TempDir);
m_Energy -= distance(m_From, m_Pos) + GetTuning(m_TuneZone)->m_LaserBounceCost;
const float Distance = distance(m_From, m_Pos);
// Prevent infinite bounces
if(Distance == 0.0f)
m_Energy = -1;
else
m_Energy -= Distance + GetTuning(m_TuneZone)->m_LaserBounceCost;
m_Bounces++;
m_WasTele = false;

View file

@ -126,8 +126,12 @@ void CLaser::DoBounce()
m_Pos = TempPos;
m_Dir = normalize(TempDir);
if(!m_TuneZone)
m_Energy -= distance(m_From, m_Pos) + GameServer()->Tuning()->m_LaserBounceCost;
const float Distance = distance(m_From, m_Pos);
// Prevent infinite bounces
if(Distance == 0.0f)
m_Energy = -1;
else if(!m_TuneZone)
m_Energy -= Distance + GameServer()->Tuning()->m_LaserBounceCost;
else
m_Energy -= distance(m_From, m_Pos) + GameServer()->TuningList()[m_TuneZone].m_LaserBounceCost;