5382: let lasers bounce with zero energy for one tick r=def- a=C0D3D3V

fixes #5380 

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [x] Considered possible null pointers and out of bounds array indexing
- [x] FIXES physics to old physics
- [x] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: c0d3d3v <c0d3d3v@mag-keinen-spam.de>
This commit is contained in:
bors[bot] 2022-06-10 13:58:30 +00:00 committed by GitHub
commit 2f08fcd469
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 2 deletions

View file

@ -20,6 +20,7 @@ CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEner
m_EvalTick = 0; m_EvalTick = 0;
m_WasTele = false; m_WasTele = false;
m_Type = Type; m_Type = Type;
m_ZeroEnergyBounceInLastTick = false;
m_TuneZone = GameWorld()->m_WorldConfig.m_UseTuneZones ? Collision()->IsTune(Collision()->GetMapIndex(m_Pos)) : 0; m_TuneZone = GameWorld()->m_WorldConfig.m_UseTuneZones ? Collision()->IsTune(Collision()->GetMapIndex(m_Pos)) : 0;
GameWorld()->InsertEntity(this); GameWorld()->InsertEntity(this);
DoBounce(); DoBounce();
@ -137,10 +138,15 @@ void CLaser::DoBounce()
const float Distance = distance(m_From, m_Pos); const float Distance = distance(m_From, m_Pos);
// Prevent infinite bounces // Prevent infinite bounces
if(Distance == 0.0f) if(Distance == 0.0f && m_ZeroEnergyBounceInLastTick)
{
m_Energy = -1; m_Energy = -1;
}
else else
{
m_Energy -= Distance + GetTuning(m_TuneZone)->m_LaserBounceCost; m_Energy -= Distance + GetTuning(m_TuneZone)->m_LaserBounceCost;
}
m_ZeroEnergyBounceInLastTick = Distance == 0.0f;
m_Bounces++; m_Bounces++;
m_WasTele = false; m_WasTele = false;

View file

@ -34,6 +34,7 @@ private:
int m_Bounces; int m_Bounces;
int m_EvalTick; int m_EvalTick;
int m_Owner; int m_Owner;
int m_ZeroEnergyBounceInLastTick;
// DDRace // DDRace

View file

@ -23,6 +23,7 @@ CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEner
m_Type = Type; m_Type = Type;
m_TeleportCancelled = false; m_TeleportCancelled = false;
m_IsBlueTeleport = false; m_IsBlueTeleport = false;
m_ZeroEnergyBounceInLastTick = false;
m_TuneZone = GameServer()->Collision()->IsTune(GameServer()->Collision()->GetMapIndex(m_Pos)); m_TuneZone = GameServer()->Collision()->IsTune(GameServer()->Collision()->GetMapIndex(m_Pos));
CCharacter *pOwnerChar = GameServer()->GetPlayerChar(m_Owner); CCharacter *pOwnerChar = GameServer()->GetPlayerChar(m_Owner);
m_TeamMask = pOwnerChar ? pOwnerChar->TeamMask() : 0; m_TeamMask = pOwnerChar ? pOwnerChar->TeamMask() : 0;
@ -150,12 +151,19 @@ void CLaser::DoBounce()
const float Distance = distance(m_From, m_Pos); const float Distance = distance(m_From, m_Pos);
// Prevent infinite bounces // Prevent infinite bounces
if(Distance == 0.0f) if(Distance == 0.0f && m_ZeroEnergyBounceInLastTick)
{
m_Energy = -1; m_Energy = -1;
}
else if(!m_TuneZone) else if(!m_TuneZone)
{
m_Energy -= Distance + GameServer()->Tuning()->m_LaserBounceCost; m_Energy -= Distance + GameServer()->Tuning()->m_LaserBounceCost;
}
else else
{
m_Energy -= distance(m_From, m_Pos) + GameServer()->TuningList()[m_TuneZone].m_LaserBounceCost; m_Energy -= distance(m_From, m_Pos) + GameServer()->TuningList()[m_TuneZone].m_LaserBounceCost;
}
m_ZeroEnergyBounceInLastTick = Distance == 0.0f;
CGameControllerDDRace *pControllerDDRace = (CGameControllerDDRace *)GameServer()->m_pController; CGameControllerDDRace *pControllerDDRace = (CGameControllerDDRace *)GameServer()->m_pController;
if(Res == TILE_TELEINWEAPON && !pControllerDDRace->m_TeleOuts[z - 1].empty()) if(Res == TILE_TELEINWEAPON && !pControllerDDRace->m_TeleOuts[z - 1].empty())

View file

@ -30,6 +30,7 @@ private:
int m_EvalTick; int m_EvalTick;
int m_Owner; int m_Owner;
int m_TeamMask; int m_TeamMask;
int m_ZeroEnergyBounceInLastTick;
// DDRace // DDRace