diff --git a/src/game/collision.cpp b/src/game/collision.cpp index cab40df36..3210775c9 100644 --- a/src/game/collision.cpp +++ b/src/game/collision.cpp @@ -135,12 +135,9 @@ void CCollision::Init(class CLayers *pLayers) m_TeleIns.clear(); m_TeleOuts.clear(); m_TeleCheckOuts.clear(); - if(m_pLayers->TeleLayer()) + if(m_pTele) { - int Width = m_pLayers->TeleLayer()->m_Width; - int Height = m_pLayers->TeleLayer()->m_Height; - - for(int i = 0; i < Width * Height; i++) + for(int i = 0; i < m_Width * m_Height; i++) { int Number = TeleLayer()[i].m_Number; int Type = TeleLayer()[i].m_Type; @@ -148,15 +145,15 @@ void CCollision::Init(class CLayers *pLayers) { if(Type == TILE_TELEIN) { - m_TeleIns[Number - 1].emplace_back(i % Width * 32.0f + 16.0f, i / Width * 32.0f + 16.0f); + m_TeleIns[Number - 1].emplace_back(i % m_Width * 32.0f + 16.0f, i / m_Width * 32.0f + 16.0f); } else if(Type == TILE_TELEOUT) { - m_TeleOuts[Number - 1].emplace_back(i % Width * 32.0f + 16.0f, i / Width * 32.0f + 16.0f); + m_TeleOuts[Number - 1].emplace_back(i % m_Width * 32.0f + 16.0f, i / m_Width * 32.0f + 16.0f); } else if(Type == TILE_TELECHECKOUT) { - m_TeleCheckOuts[Number - 1].emplace_back(i % Width * 32.0f + 16.0f, i / Width * 32.0f + 16.0f); + m_TeleCheckOuts[Number - 1].emplace_back(i % m_Width * 32.0f + 16.0f, i / m_Width * 32.0f + 16.0f); } } } diff --git a/src/game/collision.h b/src/game/collision.h index c1a17c27b..ac595e272 100644 --- a/src/game/collision.h +++ b/src/game/collision.h @@ -117,9 +117,9 @@ public: class CLayers *Layers() { return m_pLayers; } int m_HighestSwitchNumber; - std::map> &TeleIns() { return m_TeleIns; } - std::map> &TeleOuts() { return m_TeleOuts; } - std::map> &TeleCheckOuts() { return m_TeleCheckOuts; } + const std::vector &TeleIns(int Number) { return m_TeleIns[Number]; } + const std::vector &TeleOuts(int Number) { return m_TeleOuts[Number]; } + const std::vector &TeleCheckOuts(int Number) { return m_TeleCheckOuts[Number]; } private: std::map> m_TeleIns; diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index 5557f432b..2d91bdd5e 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -70,11 +70,10 @@ float VelocityRamp(float Value, float Start, float Range, float Curvature) return 1.0f / std::pow(Curvature, (Value - Start) / Range); } -void CCharacterCore::Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams, std::map> *pTeleOuts) +void CCharacterCore::Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams) { m_pWorld = pWorld; m_pCollision = pCollision; - m_pTeleOuts = pTeleOuts; m_pTeams = pTeams; m_Id = -1; @@ -327,14 +326,14 @@ void CCharacterCore::Tick(bool UseInput, bool DoDeferredTick) m_HookState = HOOK_RETRACT_START; } - if(GoingThroughTele && m_pWorld && m_pTeleOuts && !m_pTeleOuts->empty() && !(*m_pTeleOuts)[teleNr - 1].empty()) + if(GoingThroughTele && m_pWorld && !m_pCollision->TeleOuts(teleNr - 1).empty()) { m_TriggeredEvents = 0; SetHookedPlayer(-1); m_NewHook = true; - int RandomOut = m_pWorld->RandomOr0((*m_pTeleOuts)[teleNr - 1].size()); - m_HookPos = (*m_pTeleOuts)[teleNr - 1][RandomOut] + TargetDirection * PhysicalSize() * 1.5f; + int RandomOut = m_pWorld->RandomOr0(m_pCollision->TeleOuts(teleNr - 1).size()); + m_HookPos = m_pCollision->TeleOuts(teleNr - 1)[RandomOut] + TargetDirection * PhysicalSize() * 1.5f; m_HookDir = TargetDirection; m_HookTeleBase = m_HookPos; } @@ -677,11 +676,6 @@ void CCharacterCore::SetTeamsCore(CTeamsCore *pTeams) m_pTeams = pTeams; } -void CCharacterCore::SetTeleOuts(std::map> *pTeleOuts) -{ - m_pTeleOuts = pTeleOuts; -} - bool CCharacterCore::IsSwitchActiveCb(int Number, void *pUser) { CCharacterCore *pThis = (CCharacterCore *)pUser; diff --git a/src/game/gamecore.h b/src/game/gamecore.h index 8b16cfcaa..d6f7995a3 100644 --- a/src/game/gamecore.h +++ b/src/game/gamecore.h @@ -221,7 +221,6 @@ class CCharacterCore { CWorldCore *m_pWorld = nullptr; CCollision *m_pCollision; - std::map> *m_pTeleOuts; public: static constexpr float PhysicalSize() { return 28.0f; }; @@ -269,7 +268,7 @@ public: int m_TriggeredEvents; - void Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams = nullptr, std::map> *pTeleOuts = nullptr); + void Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams = nullptr); void SetCoreWorld(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams); void Reset(); void TickDeferred(); @@ -290,7 +289,6 @@ public: // DDNet Character void SetTeamsCore(CTeamsCore *pTeams); - void SetTeleOuts(std::map> *pTeleOuts); void ReadDDNet(const CNetObj_DDNetCharacter *pObjDDNet); bool m_Solo; bool m_Jetpack; diff --git a/src/game/server/ddracecommands.cpp b/src/game/server/ddracecommands.cpp index 470a49068..dd7825d6b 100644 --- a/src/game/server/ddracecommands.cpp +++ b/src/game/server/ddracecommands.cpp @@ -361,13 +361,13 @@ void CGameContext::ConToTeleporter(IConsole::IResult *pResult, void *pUserData) CGameContext *pSelf = (CGameContext *)pUserData; unsigned int TeleTo = pResult->GetInteger(0); - if(!pSelf->Collision()->TeleOuts()[TeleTo - 1].empty()) + if(!pSelf->Collision()->TeleOuts(TeleTo - 1).empty()) { CCharacter *pChr = pSelf->GetPlayerChar(pResult->m_ClientId); if(pChr) { - int TeleOut = pSelf->m_World.m_Core.RandomOr0(pSelf->Collision()->TeleOuts()[TeleTo - 1].size()); - pSelf->Teleport(pChr, pSelf->Collision()->TeleOuts()[TeleTo - 1][TeleOut]); + int TeleOut = pSelf->m_World.m_Core.RandomOr0(pSelf->Collision()->TeleOuts(TeleTo - 1).size()); + pSelf->Teleport(pChr, pSelf->Collision()->TeleOuts(TeleTo - 1)[TeleOut]); } } } @@ -377,13 +377,13 @@ void CGameContext::ConToCheckTeleporter(IConsole::IResult *pResult, void *pUserD CGameContext *pSelf = (CGameContext *)pUserData; unsigned int TeleTo = pResult->GetInteger(0); - if(!pSelf->Collision()->TeleCheckOuts()[TeleTo - 1].empty()) + if(!pSelf->Collision()->TeleCheckOuts(TeleTo - 1).empty()) { CCharacter *pChr = pSelf->GetPlayerChar(pResult->m_ClientId); if(pChr) { - int TeleOut = pSelf->m_World.m_Core.RandomOr0(pSelf->Collision()->TeleCheckOuts()[TeleTo - 1].size()); - pSelf->Teleport(pChr, pSelf->Collision()->TeleCheckOuts()[TeleTo - 1][TeleOut]); + int TeleOut = pSelf->m_World.m_Core.RandomOr0(pSelf->Collision()->TeleCheckOuts(TeleTo - 1).size()); + pSelf->Teleport(pChr, pSelf->Collision()->TeleCheckOuts(TeleTo - 1)[TeleOut]); pChr->m_TeleCheckpoint = TeleTo; } } diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 07ab908a7..dc61f5789 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -794,7 +794,7 @@ void CCharacter::TickDeferred() // advance the dummy { CWorldCore TempWorld; - m_ReckoningCore.Init(&TempWorld, Collision(), &Teams()->m_Core, m_pTeleOuts); + m_ReckoningCore.Init(&TempWorld, Collision(), &Teams()->m_Core); m_ReckoningCore.m_Id = m_pPlayer->GetCid(); m_ReckoningCore.Tick(false); m_ReckoningCore.Move(); @@ -1293,13 +1293,6 @@ int CCharacter::Team() return Teams()->m_Core.Team(m_pPlayer->GetCid()); } -void CCharacter::SetTeleports(std::map> *pTeleOuts, std::map> *pTeleCheckOuts) -{ - m_pTeleOuts = pTeleOuts; - m_pTeleCheckOuts = pTeleCheckOuts; - m_Core.SetTeleOuts(pTeleOuts); -} - void CCharacter::FillAntibot(CAntibotCharacterData *pData) { pData->m_Pos = m_Pos; @@ -1834,12 +1827,12 @@ void CCharacter::HandleTiles(int Index) } int z = Collision()->IsTeleport(MapIndex); - if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons && z && !(*m_pTeleOuts)[z - 1].empty()) + if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons && z && !Collision()->TeleOuts(z - 1).empty()) { if(m_Core.m_Super) return; - int TeleOut = GameWorld()->m_Core.RandomOr0((*m_pTeleOuts)[z - 1].size()); - m_Core.m_Pos = (*m_pTeleOuts)[z - 1][TeleOut]; + int TeleOut = GameWorld()->m_Core.RandomOr0(Collision()->TeleOuts(z - 1).size()); + m_Core.m_Pos = Collision()->TeleOuts(z - 1)[TeleOut]; if(!g_Config.m_SvTeleportHoldHook) { ResetHook(); @@ -1849,12 +1842,12 @@ void CCharacter::HandleTiles(int Index) return; } int evilz = Collision()->IsEvilTeleport(MapIndex); - if(evilz && !(*m_pTeleOuts)[evilz - 1].empty()) + if(evilz && !Collision()->TeleOuts(evilz - 1).empty()) { if(m_Core.m_Super) return; - int TeleOut = GameWorld()->m_Core.RandomOr0((*m_pTeleOuts)[evilz - 1].size()); - m_Core.m_Pos = (*m_pTeleOuts)[evilz - 1][TeleOut]; + int TeleOut = GameWorld()->m_Core.RandomOr0(Collision()->TeleOuts(evilz - 1).size()); + m_Core.m_Pos = Collision()->TeleOuts(evilz - 1)[TeleOut]; if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons) { m_Core.m_Vel = vec2(0, 0); @@ -1878,10 +1871,10 @@ void CCharacter::HandleTiles(int Index) // first check if there is a TeleCheckOut for the current recorded checkpoint, if not check previous checkpoints for(int k = m_TeleCheckpoint - 1; k >= 0; k--) { - if(!(*m_pTeleCheckOuts)[k].empty()) + if(!Collision()->TeleCheckOuts(k).empty()) { - int TeleOut = GameWorld()->m_Core.RandomOr0((*m_pTeleCheckOuts)[k].size()); - m_Core.m_Pos = (*m_pTeleCheckOuts)[k][TeleOut]; + int TeleOut = GameWorld()->m_Core.RandomOr0(Collision()->TeleCheckOuts(k).size()); + m_Core.m_Pos = Collision()->TeleCheckOuts(k)[TeleOut]; m_Core.m_Vel = vec2(0, 0); if(!g_Config.m_SvTeleportHoldHook) @@ -1915,10 +1908,10 @@ void CCharacter::HandleTiles(int Index) // first check if there is a TeleCheckOut for the current recorded checkpoint, if not check previous checkpoints for(int k = m_TeleCheckpoint - 1; k >= 0; k--) { - if(!(*m_pTeleCheckOuts)[k].empty()) + if(!Collision()->TeleCheckOuts(k).empty()) { - int TeleOut = GameWorld()->m_Core.RandomOr0((*m_pTeleCheckOuts)[k].size()); - m_Core.m_Pos = (*m_pTeleCheckOuts)[k][TeleOut]; + int TeleOut = GameWorld()->m_Core.RandomOr0(Collision()->TeleCheckOuts(k).size()); + m_Core.m_Pos = Collision()->TeleCheckOuts(k)[TeleOut]; if(!g_Config.m_SvTeleportHoldHook) { diff --git a/src/game/server/entities/character.h b/src/game/server/entities/character.h index ae22a11cb..a401b801c 100644 --- a/src/game/server/entities/character.h +++ b/src/game/server/entities/character.h @@ -147,9 +147,6 @@ private: CCharacterCore m_Core; CGameTeams *m_pTeams = nullptr; - std::map> *m_pTeleOuts = nullptr; - std::map> *m_pTeleCheckOuts = nullptr; - // info for dead reckoning int m_ReckoningTick; // tick that we are performing dead reckoning From CCharacterCore m_SendCore; // core that we should send @@ -179,7 +176,6 @@ private: public: CGameTeams *Teams() { return m_pTeams; } void SetTeams(CGameTeams *pTeams); - void SetTeleports(std::map> *pTeleOuts, std::map> *pTeleCheckOuts); void FillAntibot(CAntibotCharacterData *pData); void Pause(bool Pause); diff --git a/src/game/server/entities/laser.cpp b/src/game/server/entities/laser.cpp index 6c21e4c39..6c393c5b7 100644 --- a/src/game/server/entities/laser.cpp +++ b/src/game/server/entities/laser.cpp @@ -164,10 +164,10 @@ void CLaser::DoBounce() } m_ZeroEnergyBounceInLastTick = Distance == 0.0f; - if(Res == TILE_TELEINWEAPON && !GameServer()->Collision()->TeleOuts()[z - 1].empty()) + if(Res == TILE_TELEINWEAPON && !GameServer()->Collision()->TeleOuts(z - 1).empty()) { - int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->Collision()->TeleOuts()[z - 1].size()); - m_TelePos = GameServer()->Collision()->TeleOuts()[z - 1][TeleOut]; + int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->Collision()->TeleOuts(z - 1).size()); + m_TelePos = GameServer()->Collision()->TeleOuts(z - 1)[TeleOut]; m_WasTele = true; } else diff --git a/src/game/server/entities/projectile.cpp b/src/game/server/entities/projectile.cpp index 0850ff030..9579b0170 100644 --- a/src/game/server/entities/projectile.cpp +++ b/src/game/server/entities/projectile.cpp @@ -276,10 +276,10 @@ void CProjectile::Tick() z = GameServer()->Collision()->IsTeleport(x); else z = GameServer()->Collision()->IsTeleportWeapon(x); - if(z && !GameServer()->Collision()->TeleOuts()[z - 1].empty()) + if(z && !GameServer()->Collision()->TeleOuts(z - 1).empty()) { - int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->Collision()->TeleOuts()[z - 1].size()); - m_Pos = GameServer()->Collision()->TeleOuts()[z - 1][TeleOut]; + int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->Collision()->TeleOuts(z - 1).size()); + m_Pos = GameServer()->Collision()->TeleOuts(z - 1)[TeleOut]; m_StartTick = Server()->Tick(); } } diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 98796b076..557503787 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -482,8 +482,6 @@ void IGameController::OnCharacterSpawn(class CCharacter *pChr) // give default weapons pChr->GiveWeapon(WEAPON_HAMMER); pChr->GiveWeapon(WEAPON_GUN); - - pChr->SetTeleports(&GameServer()->Collision()->TeleOuts(), &GameServer()->Collision()->TeleCheckOuts()); } void IGameController::HandleCharacterTiles(CCharacter *pChr, int MapIndex)