diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 5c2b9a719..ac1a4392a 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -994,7 +994,8 @@ void CCharacter::Tick() m_Core.m_HookState = HOOK_RETRACTED; m_Core.m_TriggeredEvents |= COREEVENT_HOOK_RETRACT; m_Core.m_HookState = HOOK_RETRACTED; - m_Core.m_Pos = ((CGameControllerDDRace*)GameServer()->m_pController)->m_pTeleOuts[z-1][rand()%(((CGameControllerDDRace*)GameServer()->m_pController)->m_pNumTele[z-1] - 1)]; + int Num = (((CGameControllerDDRace*)GameServer()->m_pController)->m_pNumTele[z-1] - 1); + m_Core.m_Pos = ((CGameControllerDDRace*)GameServer()->m_pController)->m_pTele2D[z-1][(!Num)?Num:rand() % Num]; m_Core.m_HookPos = m_Core.m_Pos; } int evilz = GameServer()->Collision()->IsEvilTeleport(MapIndex); @@ -1005,7 +1006,8 @@ void CCharacter::Tick() m_Core.m_TriggeredEvents |= COREEVENT_HOOK_RETRACT; m_Core.m_HookState = HOOK_RETRACTED; GameWorld()->ReleaseHooked(GetPlayer()->GetCID()); - m_Core.m_Pos = ((CGameControllerDDRace*)GameServer()->m_pController)->m_pTeleOuts[evilz-1][rand()%(((CGameControllerDDRace*)GameServer()->m_pController)->m_pNumTele[evilz-1] - 1)]; + int Num = (((CGameControllerDDRace*)GameServer()->m_pController)->m_pNumTele[z-1] - 1); + m_Core.m_Pos = ((CGameControllerDDRace*)GameServer()->m_pController)->m_pTele2D[evilz-1][(!Num)?Num:rand() % Num]; m_Core.m_HookPos = m_Core.m_Pos; m_Core.m_Vel = vec2(0,0); } diff --git a/src/game/server/gamemodes/DDRace.cpp b/src/game/server/gamemodes/DDRace.cpp index 5b1e123b0..c4eeb801b 100644 --- a/src/game/server/gamemodes/DDRace.cpp +++ b/src/game/server/gamemodes/DDRace.cpp @@ -15,8 +15,8 @@ CGameControllerDDRace::CGameControllerDDRace(class CGameContext *pGameServer) : CGameControllerDDRace::~CGameControllerDDRace() { + delete[] m_pTele1D; delete[] m_pNumTele; - delete[] m_pTeleOuts; } void CGameControllerDDRace::Tick() @@ -26,31 +26,29 @@ void CGameControllerDDRace::Tick() void CGameControllerDDRace::InitTeleporter() { - int ArraySize = 0; + m_ArraySize = 0; m_TotalTele = 0; if(GameServer()->Collision()->Layers()->TeleLayer()) { for(int i = 0; i < GameServer()->Collision()->Layers()->TeleLayer()->m_Width*GameServer()->Collision()->Layers()->TeleLayer()->m_Height; i++) { // get the array size - if(GameServer()->Collision()->TeleLayer()[i].m_Number > ArraySize) - ArraySize = GameServer()->Collision()->TeleLayer()[i].m_Number; + if(GameServer()->Collision()->TeleLayer()[i].m_Number > m_ArraySize) + m_ArraySize = GameServer()->Collision()->TeleLayer()[i].m_Number; } } - if(!ArraySize) + if(!m_ArraySize) { m_pNumTele = 0x0; return; } int *Count; - m_pNumTele = new int[ArraySize]; - Count = new int[ArraySize]; - m_pTeleOuts = new vec2*[ArraySize]; - mem_zero(m_pTeleOuts, ArraySize*sizeof(vec2)); - mem_zero(m_pNumTele, ArraySize*sizeof(int)); - mem_zero(Count, ArraySize*sizeof(int)); - for (int i = 0; i < ArraySize; ++i) + m_pNumTele = new int[m_ArraySize]; + Count = new int[m_ArraySize]; + mem_zero(m_pNumTele, m_ArraySize*sizeof(int)); + mem_zero(Count, m_ArraySize*sizeof(int)); + for (int i = 0; i < m_ArraySize; ++i) Count[i] = m_pNumTele[i] = 0; // Count @@ -63,16 +61,19 @@ void CGameControllerDDRace::InitTeleporter() m_TotalTele++; } } - for (int i = 0; i < ArraySize; ++i) + m_pTele1D = new vec2[m_TotalTele]; + mem_zero(m_pTele1D, m_TotalTele*sizeof(vec2)); + m_pTele2D = &m_pTele1D; + for (int i = 0; i < m_ArraySize; ++i) { - m_pTeleOuts[i] = new vec2[m_pNumTele[i]]; - mem_zero(m_pTeleOuts[i], m_pNumTele[i]*sizeof(vec2)); + m_pTele2D[i] = new vec2[m_pNumTele[i]]; + mem_zero(m_pTele2D[i], m_pNumTele[i]*sizeof(vec2)); } for(int i = 0; i < GameServer()->Collision()->Layers()->TeleLayer()->m_Width*GameServer()->Collision()->Layers()->TeleLayer()->m_Height; i++) { if(GameServer()->Collision()->TeleLayer()[i].m_Number > 0 && GameServer()->Collision()->TeleLayer()[i].m_Type == TILE_TELEOUT) { - m_pTeleOuts[GameServer()->Collision()->TeleLayer()[i].m_Number-1][--Count[GameServer()->Collision()->TeleLayer()[i].m_Number-1]] = vec2(i%GameServer()->Collision()->Layers()->TeleLayer()->m_Width*32+16, i/GameServer()->Collision()->Layers()->TeleLayer()->m_Width*32+16); + m_pTele2D[GameServer()->Collision()->TeleLayer()[i].m_Number-1][--Count[GameServer()->Collision()->TeleLayer()[i].m_Number-1]] = vec2(i%GameServer()->Collision()->Layers()->TeleLayer()->m_Width*32+16, i/GameServer()->Collision()->Layers()->TeleLayer()->m_Width*32+16); } } } diff --git a/src/game/server/gamemodes/DDRace.h b/src/game/server/gamemodes/DDRace.h index 7fa86b1ae..4c4a86b0b 100644 --- a/src/game/server/gamemodes/DDRace.h +++ b/src/game/server/gamemodes/DDRace.h @@ -18,8 +18,10 @@ public: CGameTeams m_Teams; int *m_pNumTele; - vec2 **m_pTeleOuts; + vec2 *m_pTele1D; + vec2 **m_pTele2D; int m_TotalTele; + int m_ArraySize; void InitTeleporter(); void InitSwitcher();