5280: fix swap does not swap no collision and no hook r=def- a=C0D3D3V

- remove duplicated variable for no collision and no hook

fixes https://github.com/ddnet/ddnet/issues/5279

https://youtu.be/3VM64OVNgYM

I chose the no variables because I found them more meaningful than the one without no. Furthermore, the initialisation with false corresponds to the standard initialisation.

## 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] Changed no physics that affect existing maps
- [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-05-30 20:17:07 +00:00 committed by GitHub
commit a7d4be0f2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 38 deletions

View file

@ -829,23 +829,23 @@ void CCharacter::HandleTiles(int Index)
}
// collide with others
if(((m_TileIndex == TILE_NPC_DISABLE) || (m_TileFIndex == TILE_NPC_DISABLE)) && m_Core.m_Collision)
if(((m_TileIndex == TILE_NPC_DISABLE) || (m_TileFIndex == TILE_NPC_DISABLE)) && !m_Core.m_NoCollision)
{
m_Core.m_Collision = false;
m_Core.m_NoCollision = true;
}
else if(((m_TileIndex == TILE_NPC_ENABLE) || (m_TileFIndex == TILE_NPC_ENABLE)) && !m_Core.m_Collision)
else if(((m_TileIndex == TILE_NPC_ENABLE) || (m_TileFIndex == TILE_NPC_ENABLE)) && m_Core.m_NoCollision)
{
m_Core.m_Collision = true;
m_Core.m_NoCollision = false;
}
// hook others
if(((m_TileIndex == TILE_NPH_DISABLE) || (m_TileFIndex == TILE_NPH_DISABLE)) && m_Core.m_Hook)
if(((m_TileIndex == TILE_NPH_DISABLE) || (m_TileFIndex == TILE_NPH_DISABLE)) && !m_Core.m_NoHookHit)
{
m_Core.m_Hook = false;
m_Core.m_NoHookHit = true;
}
else if(((m_TileIndex == TILE_NPH_ENABLE) || (m_TileFIndex == TILE_NPH_ENABLE)) && !m_Core.m_Hook)
else if(((m_TileIndex == TILE_NPH_ENABLE) || (m_TileFIndex == TILE_NPH_ENABLE)) && m_Core.m_NoHookHit)
{
m_Core.m_Hook = true;
m_Core.m_NoHookHit = false;
}
// unlimited air jumps
@ -1131,8 +1131,8 @@ void CCharacter::ResetPrediction()
m_Jetpack = false;
m_NinjaJetpack = false;
m_Core.m_Jumps = 2;
m_Core.m_Hook = true;
m_Core.m_Collision = true;
m_Core.m_NoHookHit = false;
m_Core.m_NoCollision = false;
m_NumInputs = 0;
m_FreezeTime = 0;
m_Core.m_FreezeTick = 0;
@ -1268,8 +1268,8 @@ void CCharacter::Read(CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtende
// set player collision
SetSolo(!Tuning()->m_PlayerCollision && !Tuning()->m_PlayerHooking);
m_Core.m_Collision = Tuning()->m_PlayerCollision;
m_Core.m_Hook = Tuning()->m_PlayerHooking;
m_Core.m_NoCollision = !Tuning()->m_PlayerCollision;
m_Core.m_NoHookHit = !Tuning()->m_PlayerHooking;
if(m_Core.m_HookTick != 0)
m_EndlessHook = false;

View file

@ -86,8 +86,6 @@ void CCharacterCore::Reset()
m_JumpedTotal = 0;
m_Jumps = 2;
m_TriggeredEvents = 0;
m_Hook = true;
m_Collision = true;
// DDNet Character
m_Solo = false;
@ -275,7 +273,7 @@ void CCharacterCore::Tick(bool UseInput)
}
// Check against other players first
if(this->m_Hook && m_pWorld && m_Tuning.m_PlayerHooking)
if(!this->m_NoHookHit && m_pWorld && m_Tuning.m_PlayerHooking)
{
float Distance = 0.0f;
for(int i = 0; i < MAX_CLIENTS; i++)
@ -409,7 +407,7 @@ void CCharacterCore::Tick(bool UseInput)
{
vec2 Dir = normalize(m_Pos - pCharCore->m_Pos);
bool CanCollide = (m_Super || pCharCore->m_Super) || (pCharCore->m_Collision && m_Collision && !m_NoCollision && !pCharCore->m_NoCollision && m_Tuning.m_PlayerCollision);
bool CanCollide = (m_Super || pCharCore->m_Super) || (!m_NoCollision && !pCharCore->m_NoCollision && m_Tuning.m_PlayerCollision);
if(CanCollide && Distance < PhysicalSize() * 1.25f && Distance > 0.0f)
{
@ -426,7 +424,7 @@ void CCharacterCore::Tick(bool UseInput)
}
// handle hook influence
if(m_Hook && m_HookedPlayer == i && m_Tuning.m_PlayerHooking)
if(!m_NoHookHit && m_HookedPlayer == i && m_Tuning.m_PlayerHooking)
{
if(Distance > PhysicalSize() * 1.50f) // TODO: fix tweakable variable
{
@ -482,7 +480,7 @@ void CCharacterCore::Move()
m_Vel.x = m_Vel.x * (1.0f / RampValue);
if(m_pWorld && (m_Super || (m_Tuning.m_PlayerCollision && m_Collision && !m_NoCollision && !m_Solo)))
if(m_pWorld && (m_Super || (m_Tuning.m_PlayerCollision && !m_NoCollision && !m_Solo)))
{
// check player collision
float Distance = distance(m_Pos, NewPos);
@ -499,7 +497,7 @@ void CCharacterCore::Move()
CCharacterCore *pCharCore = m_pWorld->m_apCharacters[p];
if(!pCharCore || pCharCore == this)
continue;
if((!(pCharCore->m_Super || m_Super) && (m_Solo || pCharCore->m_Solo || !pCharCore->m_Collision || pCharCore->m_NoCollision || (m_Id != -1 && !m_pTeams->CanCollide(m_Id, p)))))
if((!(pCharCore->m_Super || m_Super) && (m_Solo || pCharCore->m_Solo || pCharCore->m_NoCollision || (m_Id != -1 && !m_pTeams->CanCollide(m_Id, p)))))
continue;
float D = distance(Pos, pCharCore->m_Pos);
if(D < PhysicalSize() && D >= 0.0f)
@ -574,9 +572,6 @@ void CCharacterCore::ReadDDNet(const CNetObj_DDNetCharacter *pObjDDNet)
m_NoHookHit = pObjDDNet->m_Flags & CHARACTERFLAG_NO_HOOK;
m_Super = pObjDDNet->m_Flags & CHARACTERFLAG_SUPER;
m_Hook = !m_NoHookHit;
m_Collision = !m_NoCollision;
// Endless
m_EndlessHook = pObjDDNet->m_Flags & CHARACTERFLAG_ENDLESS_HOOK;
m_EndlessJump = pObjDDNet->m_Flags & CHARACTERFLAG_ENDLESS_JUMP;

View file

@ -212,8 +212,6 @@ public:
static constexpr vec2 PhysicalSizeVec2() { return vec2(28.0f, 28.0f); };
vec2 m_Pos;
vec2 m_Vel;
bool m_Hook;
bool m_Collision;
vec2 m_HookPos;
vec2 m_HookDir;

View file

@ -1231,9 +1231,9 @@ void CCharacter::Snap(int SnappingClient)
pDDNetCharacter->m_Flags |= CHARACTERFLAG_SUPER;
if(m_EndlessHook)
pDDNetCharacter->m_Flags |= CHARACTERFLAG_ENDLESS_HOOK;
if(!m_Core.m_Collision || !GameServer()->Tuning()->m_PlayerCollision)
if(m_Core.m_NoCollision || !GameServer()->Tuning()->m_PlayerCollision)
pDDNetCharacter->m_Flags |= CHARACTERFLAG_NO_COLLISION;
if(!m_Core.m_Hook || !GameServer()->Tuning()->m_PlayerHooking)
if(m_Core.m_NoHookHit || !GameServer()->Tuning()->m_PlayerHooking)
pDDNetCharacter->m_Flags |= CHARACTERFLAG_NO_HOOK;
if(m_SuperJump)
pDDNetCharacter->m_Flags |= CHARACTERFLAG_ENDLESS_JUMP;
@ -1577,36 +1577,32 @@ void CCharacter::HandleTiles(int Index)
}
// collide with others
if(((m_TileIndex == TILE_NPC_DISABLE) || (m_TileFIndex == TILE_NPC_DISABLE)) && m_Core.m_Collision)
if(((m_TileIndex == TILE_NPC_DISABLE) || (m_TileFIndex == TILE_NPC_DISABLE)) && !m_Core.m_NoCollision)
{
GameServer()->SendChatTarget(GetPlayer()->GetCID(), "You can't collide with others");
m_Core.m_Collision = false;
m_Core.m_NoCollision = true;
m_NeededFaketuning |= FAKETUNE_NOCOLL;
GameServer()->SendTuningParams(m_pPlayer->GetCID(), m_TuneZone); // update tunings
}
else if(((m_TileIndex == TILE_NPC_ENABLE) || (m_TileFIndex == TILE_NPC_ENABLE)) && !m_Core.m_Collision)
else if(((m_TileIndex == TILE_NPC_ENABLE) || (m_TileFIndex == TILE_NPC_ENABLE)) && m_Core.m_NoCollision)
{
GameServer()->SendChatTarget(GetPlayer()->GetCID(), "You can collide with others");
m_Core.m_Collision = true;
m_Core.m_NoCollision = false;
m_NeededFaketuning &= ~FAKETUNE_NOCOLL;
GameServer()->SendTuningParams(m_pPlayer->GetCID(), m_TuneZone); // update tunings
}
// hook others
if(((m_TileIndex == TILE_NPH_DISABLE) || (m_TileFIndex == TILE_NPH_DISABLE)) && m_Core.m_Hook)
if(((m_TileIndex == TILE_NPH_DISABLE) || (m_TileFIndex == TILE_NPH_DISABLE)) && !m_Core.m_NoHookHit)
{
GameServer()->SendChatTarget(GetPlayer()->GetCID(), "You can't hook others");
m_Core.m_Hook = false;
m_Core.m_NoHookHit = true;
m_NeededFaketuning |= FAKETUNE_NOHOOK;
GameServer()->SendTuningParams(m_pPlayer->GetCID(), m_TuneZone); // update tunings
}
else if(((m_TileIndex == TILE_NPH_ENABLE) || (m_TileFIndex == TILE_NPH_ENABLE)) && !m_Core.m_Hook)
else if(((m_TileIndex == TILE_NPH_ENABLE) || (m_TileFIndex == TILE_NPH_ENABLE)) && m_Core.m_NoHookHit)
{
GameServer()->SendChatTarget(GetPlayer()->GetCID(), "You can hook others");
m_Core.m_Hook = true;
m_Core.m_NoHookHit = false;
m_NeededFaketuning &= ~FAKETUNE_NOHOOK;
GameServer()->SendTuningParams(m_pPlayer->GetCID(), m_TuneZone); // update tunings

View file

@ -77,8 +77,8 @@ void CSaveTee::Save(CCharacter *pChr)
// Core
m_CorePos = pChr->m_Core.m_Pos;
m_Vel = pChr->m_Core.m_Vel;
m_Hook = pChr->m_Core.m_Hook;
m_Collision = pChr->m_Core.m_Collision;
m_Hook = !pChr->m_Core.m_NoHookHit;
m_Collision = !pChr->m_Core.m_NoCollision;
m_ActiveWeapon = pChr->m_Core.m_ActiveWeapon;
m_Jumped = pChr->m_Core.m_Jumped;
m_JumpedTotal = pChr->m_Core.m_JumpedTotal;
@ -170,8 +170,8 @@ void CSaveTee::Load(CCharacter *pChr, int Team, bool IsSwap)
// Core
pChr->m_Core.m_Pos = m_CorePos;
pChr->m_Core.m_Vel = m_Vel;
pChr->m_Core.m_Hook = m_Hook;
pChr->m_Core.m_Collision = m_Collision;
pChr->m_Core.m_NoHookHit = !m_Hook;
pChr->m_Core.m_NoCollision = !m_Collision;
pChr->m_Core.m_ActiveWeapon = m_ActiveWeapon;
pChr->m_Core.m_Jumped = m_Jumped;
pChr->m_Core.m_JumpedTotal = m_JumpedTotal;