Improve Checkpoint-teleporters: if no matching destination is found for the current checkpoint, check previous ones

This commit is contained in:
Ravomavain 2011-09-03 00:42:01 +02:00 committed by GreYFoX
parent fe5e9f4ad7
commit 04981004d5

View file

@ -1413,17 +1413,22 @@ void CCharacter::HandleTiles(int Index)
}
if(GameServer()->Collision()->IsCheckTeleport(MapIndex))
{
if(m_TeleCheckpoint && ((CGameControllerDDRace*)GameServer()->m_pController)->m_TeleCheckOuts[m_TeleCheckpoint-1].size())
// 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--)
{
m_Core.m_HookedPlayer = -1;
m_Core.m_HookState = HOOK_RETRACTED;
m_Core.m_TriggeredEvents |= COREEVENT_HOOK_RETRACT;
m_Core.m_HookState = HOOK_RETRACTED;
int Num = (((CGameControllerDDRace*)GameServer()->m_pController)->m_TeleCheckOuts[m_TeleCheckpoint-1].size());
m_Core.m_Pos = ((CGameControllerDDRace*)GameServer()->m_pController)->m_TeleCheckOuts[m_TeleCheckpoint-1][(!Num)?Num:rand() % Num];
m_Core.m_HookPos = m_Core.m_Pos;
return;
if(Controller->m_TeleCheckOuts[k].size())
{
m_Core.m_HookedPlayer = -1;
m_Core.m_HookState = HOOK_RETRACTED;
m_Core.m_TriggeredEvents |= COREEVENT_HOOK_RETRACT;
m_Core.m_HookState = HOOK_RETRACTED;
int Num = Controller->m_TeleCheckOuts[k].size();
m_Core.m_Pos = Controller->m_TeleCheckOuts[k][(!Num)?Num:rand() % Num];
m_Core.m_HookPos = m_Core.m_Pos;
return;
}
}
// if no checkpointout have been found (or if there no recorded checkpoint), teleport to start
vec2 SpawnPos;
if(GameServer()->m_pController->CanSpawn(m_pPlayer->GetTeam(), &SpawnPos))
{
@ -1434,6 +1439,7 @@ void CCharacter::HandleTiles(int Index)
m_Core.m_Pos = SpawnPos;
m_Core.m_HookPos = m_Core.m_Pos;
}
return;
}
}