From 2596dac47a550607bfc3510ae7d632cdcdb94fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 7 May 2023 10:58:50 +0200 Subject: [PATCH 1/4] Remove dead code --- src/game/client/prediction/entities/character.h | 3 --- src/game/server/entities/pickup.h | 1 - 2 files changed, 4 deletions(-) diff --git a/src/game/client/prediction/entities/character.h b/src/game/client/prediction/entities/character.h index 5604dde10..206212413 100644 --- a/src/game/client/prediction/entities/character.h +++ b/src/game/client/prediction/entities/character.h @@ -33,9 +33,6 @@ class CCharacter : public CEntity public: ~CCharacter(); - //character's size - static const int ms_PhysSize = 28; - void PreTick() override; void Tick() override; void TickDeferred() override; diff --git a/src/game/server/entities/pickup.h b/src/game/server/entities/pickup.h index c89b1ae5c..a448baeb6 100644 --- a/src/game/server/entities/pickup.h +++ b/src/game/server/entities/pickup.h @@ -18,7 +18,6 @@ public: private: int m_Type; int m_Subtype; - //int m_SpawnTick; // DDRace From 73091cdd83128df341664e5bffd38066d0b8e6e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 7 May 2023 10:59:48 +0200 Subject: [PATCH 2/4] Add `CPickup::Type` and `CPickup::Subtype` getters --- src/game/client/prediction/entities/pickup.h | 3 +++ src/game/server/entities/pickup.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/game/client/prediction/entities/pickup.h b/src/game/client/prediction/entities/pickup.h index 9065079fd..abcda5e9b 100644 --- a/src/game/client/prediction/entities/pickup.h +++ b/src/game/client/prediction/entities/pickup.h @@ -15,6 +15,9 @@ public: bool Match(CPickup *pPickup); bool InDDNetTile() { return m_IsCoreActive; } + int Type() const { return m_Type; } + int Subtype() const { return m_Subtype; } + private: int m_Type; int m_Subtype; diff --git a/src/game/server/entities/pickup.h b/src/game/server/entities/pickup.h index a448baeb6..70e2db3af 100644 --- a/src/game/server/entities/pickup.h +++ b/src/game/server/entities/pickup.h @@ -15,6 +15,9 @@ public: void TickPaused() override; void Snap(int SnappingClient) override; + int Type() const { return m_Type; } + int Subtype() const { return m_Subtype; } + private: int m_Type; int m_Subtype; From 72c2ed062beb4a471db604f0e8c051b675efd11b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 7 May 2023 11:02:40 +0200 Subject: [PATCH 3/4] Remove magic number `20.0f` from pickup handling --- src/game/client/prediction/entities/pickup.cpp | 4 ++-- src/game/client/prediction/entities/pickup.h | 2 ++ src/game/server/entities/pickup.cpp | 2 +- src/game/server/entities/pickup.h | 2 ++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/game/client/prediction/entities/pickup.cpp b/src/game/client/prediction/entities/pickup.cpp index d6f7aff62..5324a0a0d 100644 --- a/src/game/client/prediction/entities/pickup.cpp +++ b/src/game/client/prediction/entities/pickup.cpp @@ -11,13 +11,13 @@ void CPickup::Tick() Move(); // Check if a player intersected us CEntity *apEnts[MAX_CLIENTS]; - int Num = GameWorld()->FindEntities(m_Pos, 20.0f, apEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER); + int Num = GameWorld()->FindEntities(m_Pos, GetProximityRadius() + ms_CollisionExtraSize, apEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER); for(int i = 0; i < Num; ++i) { auto *pChr = static_cast(apEnts[i]); if(pChr) { - if(GameWorld()->m_WorldConfig.m_IsVanilla && distance(m_Pos, pChr->m_Pos) >= 20.0f * 2) // pickup distance is shorter on vanilla due to using ClosestEntity + if(GameWorld()->m_WorldConfig.m_IsVanilla && distance(m_Pos, pChr->m_Pos) >= (GetProximityRadius() + ms_CollisionExtraSize) * 2) // pickup distance is shorter on vanilla due to using ClosestEntity continue; if(m_Layer == LAYER_SWITCH && m_Number > 0 && m_Number < (int)Switchers().size() && !Switchers()[m_Number].m_aStatus[pChr->Team()]) continue; diff --git a/src/game/client/prediction/entities/pickup.h b/src/game/client/prediction/entities/pickup.h index abcda5e9b..0523e13d7 100644 --- a/src/game/client/prediction/entities/pickup.h +++ b/src/game/client/prediction/entities/pickup.h @@ -8,6 +8,8 @@ class CPickup : public CEntity { public: + static const int ms_CollisionExtraSize = 6; + void Tick() override; CPickup(CGameWorld *pGameWorld, int ID, CNetObj_Pickup *pPickup, const CNetObj_EntityEx *pEntEx = 0); diff --git a/src/game/server/entities/pickup.cpp b/src/game/server/entities/pickup.cpp index cd537e46c..be2744c8e 100644 --- a/src/game/server/entities/pickup.cpp +++ b/src/game/server/entities/pickup.cpp @@ -35,7 +35,7 @@ void CPickup::Tick() // Check if a player intersected us CEntity *apEnts[MAX_CLIENTS]; - int Num = GameWorld()->FindEntities(m_Pos, 20.0f, apEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER); + int Num = GameWorld()->FindEntities(m_Pos, GetProximityRadius() + ms_CollisionExtraSize, apEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER); for(int i = 0; i < Num; ++i) { auto *pChr = static_cast(apEnts[i]); diff --git a/src/game/server/entities/pickup.h b/src/game/server/entities/pickup.h index 70e2db3af..7c3f8a1df 100644 --- a/src/game/server/entities/pickup.h +++ b/src/game/server/entities/pickup.h @@ -8,6 +8,8 @@ class CPickup : public CEntity { public: + static const int ms_CollisionExtraSize = 6; + CPickup(CGameWorld *pGameWorld, int Type, int SubType = 0, int Layer = 0, int Number = 0); void Reset() override; From a4dc138028e15b889c724627cad9929c0a6cea44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 6 May 2023 22:32:36 +0200 Subject: [PATCH 4/4] Allow using rescue (/r) on health pickup Check if character is in range of health pickup and don't set rescue position if that's the case, so rescue can be used to get out of the health pickup's freeze effect. The existing `m_Core.m_IsInFreeze` is not set so this should not have any side-effects. Closes #3330. --- src/game/server/entities/character.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 99259cf14..71e19140d 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -2,6 +2,7 @@ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include "character.h" #include "laser.h" +#include "pickup.h" #include "projectile.h" #include @@ -2002,10 +2003,31 @@ void CCharacter::DDRaceTick() } } + // check for nearby health pickups (also freeze) + bool InHealthPickup = false; + if(!m_Core.m_IsInFreeze) + { + CEntity *apEnts[9]; + int Num = GameWorld()->FindEntities(m_Pos, GetProximityRadius() + CPickup::ms_CollisionExtraSize, apEnts, std::size(apEnts), CGameWorld::ENTTYPE_PICKUP); + for(int i = 0; i < Num; ++i) + { + CPickup *pPickup = static_cast(apEnts[i]); + if(pPickup->Type() == POWERUP_HEALTH) + { + // This uses a separate variable InHealthPickup instead of setting m_Core.m_IsInFreeze + // as the latter causes freezebars to flicker when standing in the freeze range of a + // health pickup. When the same code for client prediction is added, the freezebars + // still flicker, but only when standing at the edge of the health pickup's freeze range. + InHealthPickup = true; + break; + } + } + } + // look for save position for rescue feature if(g_Config.m_SvRescue || ((g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO || Team() > TEAM_FLOCK) && Team() >= TEAM_FLOCK && Team() < TEAM_SUPER)) { - if(!m_Core.m_IsInFreeze && IsGrounded() && !m_Core.m_DeepFrozen) + if(!m_Core.m_IsInFreeze && IsGrounded() && !m_Core.m_DeepFrozen && !InHealthPickup) { SetRescue(); }