diff --git a/src/game/server/ddracecommands.cpp b/src/game/server/ddracecommands.cpp index d1af8431d..a89acf172 100644 --- a/src/game/server/ddracecommands.cpp +++ b/src/game/server/ddracecommands.cpp @@ -358,15 +358,14 @@ void CGameContext::ConToTeleporter(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; unsigned int TeleTo = pResult->GetInteger(0); - CGameControllerDDRace *pGameControllerDDRace = (CGameControllerDDRace *)pSelf->m_pController; - if(!pGameControllerDDRace->m_TeleOuts[TeleTo - 1].empty()) + if(!pSelf->m_pController->m_TeleOuts[TeleTo - 1].empty()) { CCharacter *pChr = pSelf->GetPlayerChar(pResult->m_ClientID); if(pChr) { - int TeleOut = pSelf->m_World.m_Core.RandomOr0(pGameControllerDDRace->m_TeleOuts[TeleTo - 1].size()); - pSelf->Teleport(pChr, pGameControllerDDRace->m_TeleOuts[TeleTo - 1][TeleOut]); + int TeleOut = pSelf->m_World.m_Core.RandomOr0(pSelf->m_pController->m_TeleOuts[TeleTo - 1].size()); + pSelf->Teleport(pChr, pSelf->m_pController->m_TeleOuts[TeleTo - 1][TeleOut]); } } } @@ -375,15 +374,14 @@ void CGameContext::ConToCheckTeleporter(IConsole::IResult *pResult, void *pUserD { CGameContext *pSelf = (CGameContext *)pUserData; unsigned int TeleTo = pResult->GetInteger(0); - CGameControllerDDRace *pGameControllerDDRace = (CGameControllerDDRace *)pSelf->m_pController; - if(!pGameControllerDDRace->m_TeleCheckOuts[TeleTo - 1].empty()) + if(!pSelf->m_pController->m_TeleCheckOuts[TeleTo - 1].empty()) { CCharacter *pChr = pSelf->GetPlayerChar(pResult->m_ClientID); if(pChr) { - int TeleOut = pSelf->m_World.m_Core.RandomOr0(pGameControllerDDRace->m_TeleCheckOuts[TeleTo - 1].size()); - pSelf->Teleport(pChr, pGameControllerDDRace->m_TeleCheckOuts[TeleTo - 1][TeleOut]); + int TeleOut = pSelf->m_World.m_Core.RandomOr0(pSelf->m_pController->m_TeleCheckOuts[TeleTo - 1].size()); + pSelf->Teleport(pChr, pSelf->m_pController->m_TeleCheckOuts[TeleTo - 1][TeleOut]); pChr->m_TeleCheckpoint = TeleTo; } } diff --git a/src/game/server/entities/laser.cpp b/src/game/server/entities/laser.cpp index 913043d5c..e0fd0e578 100644 --- a/src/game/server/entities/laser.cpp +++ b/src/game/server/entities/laser.cpp @@ -166,11 +166,10 @@ void CLaser::DoBounce() } m_ZeroEnergyBounceInLastTick = Distance == 0.0f; - CGameControllerDDRace *pControllerDDRace = (CGameControllerDDRace *)GameServer()->m_pController; - if(Res == TILE_TELEINWEAPON && !pControllerDDRace->m_TeleOuts[z - 1].empty()) + if(Res == TILE_TELEINWEAPON && !GameServer()->m_pController->m_TeleOuts[z - 1].empty()) { - int TeleOut = GameServer()->m_World.m_Core.RandomOr0(pControllerDDRace->m_TeleOuts[z - 1].size()); - m_TelePos = pControllerDDRace->m_TeleOuts[z - 1][TeleOut]; + int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->m_pController->m_TeleOuts[z - 1].size()); + m_TelePos = GameServer()->m_pController->m_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 388859148..c829f6be3 100644 --- a/src/game/server/entities/projectile.cpp +++ b/src/game/server/entities/projectile.cpp @@ -276,11 +276,10 @@ void CProjectile::Tick() z = GameServer()->Collision()->IsTeleport(x); else z = GameServer()->Collision()->IsTeleportWeapon(x); - CGameControllerDDRace *pControllerDDRace = (CGameControllerDDRace *)GameServer()->m_pController; - if(z && !pControllerDDRace->m_TeleOuts[z - 1].empty()) + if(z && !GameServer()->m_pController->m_TeleOuts[z - 1].empty()) { - int TeleOut = GameServer()->m_World.m_Core.RandomOr0(pControllerDDRace->m_TeleOuts[z - 1].size()); - m_Pos = pControllerDDRace->m_TeleOuts[z - 1][TeleOut]; + int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->m_pController->m_TeleOuts[z - 1].size()); + m_Pos = GameServer()->m_pController->m_TeleOuts[z - 1][TeleOut]; m_StartTick = Server()->Tick(); } } diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 1d656e1c8..8dd6214e1 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -38,6 +38,8 @@ IGameController::IGameController(class CGameContext *pGameServer) m_ForceBalanced = false; m_CurrentRecord = 0; + + InitTeleporter(); } IGameController::~IGameController() = default; @@ -484,6 +486,8 @@ void IGameController::OnCharacterSpawn(class CCharacter *pChr) // give default weapons pChr->GiveWeapon(WEAPON_HAMMER); pChr->GiveWeapon(WEAPON_GUN); + + pChr->SetTeleports(&m_TeleOuts, &m_TeleCheckOuts); } void IGameController::HandleCharacterTiles(CCharacter *pChr, int MapIndex) @@ -727,6 +731,31 @@ CClientMask IGameController::GetMaskForPlayerWorldEvent(int Asker, int ExceptID) return CClientMask().set().reset(ExceptID); } +void IGameController::InitTeleporter() +{ + if(!GameServer()->Collision()->Layers()->TeleLayer()) + return; + int Width = GameServer()->Collision()->Layers()->TeleLayer()->m_Width; + int Height = GameServer()->Collision()->Layers()->TeleLayer()->m_Height; + + for(int i = 0; i < Width * Height; i++) + { + int Number = GameServer()->Collision()->TeleLayer()[i].m_Number; + int Type = GameServer()->Collision()->TeleLayer()[i].m_Type; + if(Number > 0) + { + if(Type == TILE_TELEOUT) + { + m_TeleOuts[Number - 1].emplace_back(i % Width * 32.0f + 16.0f, i / 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); + } + } + } +} + void IGameController::DoTeamChange(CPlayer *pPlayer, int Team, bool DoChatMsg) { Team = ClampTeam(Team); diff --git a/src/game/server/gamecontroller.h b/src/game/server/gamecontroller.h index 22828142a..824acdd17 100644 --- a/src/game/server/gamecontroller.h +++ b/src/game/server/gamecontroller.h @@ -7,6 +7,7 @@ #include #include +#include #include /* @@ -143,10 +144,13 @@ public: int ClampTeam(int Team); virtual CClientMask GetMaskForPlayerWorldEvent(int Asker, int ExceptID = -1); + virtual void InitTeleporter(); // DDRace float m_CurrentRecord; + std::map> m_TeleOuts; + std::map> m_TeleCheckOuts; }; #endif diff --git a/src/game/server/gamemodes/DDRace.cpp b/src/game/server/gamemodes/DDRace.cpp index 7284ec910..a942f0bb3 100644 --- a/src/game/server/gamemodes/DDRace.cpp +++ b/src/game/server/gamemodes/DDRace.cpp @@ -18,8 +18,6 @@ CGameControllerDDRace::CGameControllerDDRace(class CGameContext *pGameServer) : IGameController(pGameServer), m_Teams(pGameServer), m_pLoadBestTimeResult(nullptr) { m_pGameType = g_Config.m_SvTestingCommands ? TEST_TYPE_NAME : GAME_TYPE_NAME; - - InitTeleporter(); } CGameControllerDDRace::~CGameControllerDDRace() = default; @@ -33,7 +31,6 @@ void CGameControllerDDRace::OnCharacterSpawn(CCharacter *pChr) { IGameController::OnCharacterSpawn(pChr); pChr->SetTeams(&m_Teams); - pChr->SetTeleports(&m_TeleOuts, &m_TeleCheckOuts); m_Teams.OnCharacterSpawn(pChr->GetPlayer()->GetCID()); } @@ -219,31 +216,6 @@ CClientMask CGameControllerDDRace::GetMaskForPlayerWorldEvent(int Asker, int Exc return m_Teams.TeamMask(GetPlayerTeam(Asker), ExceptID, Asker); } -void CGameControllerDDRace::InitTeleporter() -{ - if(!GameServer()->Collision()->Layers()->TeleLayer()) - return; - int Width = GameServer()->Collision()->Layers()->TeleLayer()->m_Width; - int Height = GameServer()->Collision()->Layers()->TeleLayer()->m_Height; - - for(int i = 0; i < Width * Height; i++) - { - int Number = GameServer()->Collision()->TeleLayer()[i].m_Number; - int Type = GameServer()->Collision()->TeleLayer()[i].m_Type; - if(Number > 0) - { - if(Type == TILE_TELEOUT) - { - m_TeleOuts[Number - 1].emplace_back(i % Width * 32.0f + 16.0f, i / 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); - } - } - } -} - int CGameControllerDDRace::GetPlayerTeam(int ClientID) const { return m_Teams.m_Core.Team(ClientID); diff --git a/src/game/server/gamemodes/DDRace.h b/src/game/server/gamemodes/DDRace.h index c5274f3d8..29fba0511 100644 --- a/src/game/server/gamemodes/DDRace.h +++ b/src/game/server/gamemodes/DDRace.h @@ -5,9 +5,6 @@ #include #include -#include -#include - struct CScoreLoadBestTimeResult; class CGameControllerDDRace : public IGameController { @@ -31,15 +28,10 @@ public: CClientMask GetMaskForPlayerWorldEvent(int Asker, int ExceptID = -1) override; - void InitTeleporter(); - int GetPlayerTeam(int ClientID) const; CGameTeams m_Teams; - std::map> m_TeleOuts; - std::map> m_TeleCheckOuts; - std::shared_ptr m_pLoadBestTimeResult; }; #endif // GAME_SERVER_GAMEMODES_DDRACE_H