mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Added Fastcap support for ghost and race demo
This commit is contained in:
parent
bd3e81d5e0
commit
1c377ed00f
|
@ -63,6 +63,7 @@ bool IsCatch(const CServerInfo *pInfo);
|
|||
bool IsInsta(const CServerInfo *pInfo);
|
||||
bool IsFNG(const CServerInfo *pInfo);
|
||||
bool IsRace(const CServerInfo *pInfo);
|
||||
bool IsFastCap(const CServerInfo *pInfo);
|
||||
bool IsDDRace(const CServerInfo *pInfo);
|
||||
bool IsDDNet(const CServerInfo *pInfo);
|
||||
|
||||
|
|
|
@ -33,6 +33,11 @@ bool IsRace(const CServerInfo *pInfo)
|
|||
|| str_find_nocase(pInfo->m_aGameType, "fastcap");
|
||||
}
|
||||
|
||||
bool IsFastCap(const CServerInfo *pInfo)
|
||||
{
|
||||
return str_find_nocase(pInfo->m_aGameType, "fastcap");
|
||||
}
|
||||
|
||||
bool IsDDRace(const CServerInfo *pInfo)
|
||||
{
|
||||
return str_find_nocase(pInfo->m_aGameType, "ddrace")
|
||||
|
|
|
@ -70,7 +70,7 @@ void CGhost::OnRender()
|
|||
{
|
||||
vec2 PrevPos = m_pClient->m_PredictedPrevChar.m_Pos;
|
||||
vec2 Pos = m_pClient->m_PredictedChar.m_Pos;
|
||||
if(!m_Rendering && CRaceHelper::IsStart(m_pClient->Collision(), PrevPos, Pos))
|
||||
if(!m_Rendering && CRaceHelper::IsStart(m_pClient, PrevPos, Pos))
|
||||
StartRender();
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ void CGhost::OnRender()
|
|||
vec2 Pos = vec2(m_pClient->m_Snap.m_pLocalCharacter->m_X, m_pClient->m_Snap.m_pLocalCharacter->m_Y);
|
||||
|
||||
// detecting death, needed because race allows immediate respawning
|
||||
if(!m_Recording && CRaceHelper::IsStart(m_pClient->Collision(), PrevPos, Pos) && m_LastDeathTick < PrevTick)
|
||||
if(!m_Recording && CRaceHelper::IsStart(m_pClient, PrevPos, Pos) && m_LastDeathTick < PrevTick)
|
||||
StartRecord();
|
||||
|
||||
if(m_Recording)
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
#include <list>
|
||||
|
||||
#include <base/math.h>
|
||||
#include <game/collision.h>
|
||||
#include <engine/serverbrowser.h>
|
||||
#include <game/client/gameclient.h>
|
||||
#include <game/mapitems.h>
|
||||
|
||||
#include "race.h"
|
||||
|
||||
int CRaceHelper::ms_aFlagIndex[2] = { -1, -1 };
|
||||
|
||||
int CRaceHelper::TimeFromSecondsStr(const char *pStr)
|
||||
{
|
||||
while(*pStr == ' ') // skip leading spaces
|
||||
|
@ -65,23 +68,36 @@ int CRaceHelper::TimeFromFinishMessage(const char *pStr, char *pNameBuf, int Nam
|
|||
return TimeFromStr(pFinished + str_length(s_pFinishedStr));
|
||||
}
|
||||
|
||||
bool CRaceHelper::IsStart(CCollision *pCollision, vec2 Prev, vec2 Pos)
|
||||
bool CRaceHelper::IsStart(CGameClient *pClient, vec2 Prev, vec2 Pos)
|
||||
{
|
||||
std::list < int > Indices = pCollision->GetMapIndices(Prev, Pos);
|
||||
if(!Indices.empty())
|
||||
for(std::list < int >::iterator i = Indices.begin(); i != Indices.end(); i++)
|
||||
{
|
||||
if(pCollision->GetTileIndex(*i) == TILE_BEGIN)
|
||||
return true;
|
||||
if(pCollision->GetFTileIndex(*i) == TILE_BEGIN)
|
||||
return true;
|
||||
}
|
||||
CServerInfo ServerInfo;
|
||||
pClient->Client()->GetServerInfo(&ServerInfo);
|
||||
|
||||
|
||||
CCollision *pCollision = pClient->Collision();
|
||||
if(IsFastCap(&ServerInfo))
|
||||
{
|
||||
int EnemyTeam = pClient->m_aClients[pClient->m_Snap.m_LocalClientID].m_Team ^ 1;
|
||||
return ms_aFlagIndex[EnemyTeam] != -1 && distance(Pos, pCollision->GetPos(ms_aFlagIndex[EnemyTeam])) < 32;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(pCollision->GetTileIndex(pCollision->GetPureMapIndex(Pos)) == TILE_BEGIN)
|
||||
return true;
|
||||
if(pCollision->GetFTileIndex(pCollision->GetPureMapIndex(Pos)) == TILE_BEGIN)
|
||||
return true;
|
||||
std::list < int > Indices = pCollision->GetMapIndices(Prev, Pos);
|
||||
if(!Indices.empty())
|
||||
for(std::list < int >::iterator i = Indices.begin(); i != Indices.end(); i++)
|
||||
{
|
||||
if(pCollision->GetTileIndex(*i) == TILE_BEGIN)
|
||||
return true;
|
||||
if(pCollision->GetFTileIndex(*i) == TILE_BEGIN)
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(pCollision->GetTileIndex(pCollision->GetPureMapIndex(Pos)) == TILE_BEGIN)
|
||||
return true;
|
||||
if(pCollision->GetFTileIndex(pCollision->GetPureMapIndex(Pos)) == TILE_BEGIN)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -7,12 +7,14 @@
|
|||
class CRaceHelper
|
||||
{
|
||||
public:
|
||||
static int ms_aFlagIndex[2];
|
||||
|
||||
// these functions return the time in milliseconds, time -1 is invalid
|
||||
static int TimeFromSecondsStr(const char *pStr); // x.xxx
|
||||
static int TimeFromStr(const char *pStr); // x minute(s) x.xxx second(s)
|
||||
static int TimeFromFinishMessage(const char *pStr, char *pNameBuf, int NameBufSize); // xxx finished in: x minute(s) x.xxx second(s)
|
||||
|
||||
static bool IsStart(class CCollision *pCollision, vec2 Prev, vec2 Pos);
|
||||
static bool IsStart(class CGameClient *pClient, vec2 Prev, vec2 Pos);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -44,7 +44,7 @@ void CRaceDemo::OnRender()
|
|||
return;
|
||||
|
||||
// start the demo
|
||||
if(m_DemoStartTick < Client()->GameTick() && CRaceHelper::IsStart(m_pClient->Collision(), m_pClient->m_PredictedPrevChar.m_Pos, m_pClient->m_LocalCharacterPos))
|
||||
if(m_DemoStartTick < Client()->GameTick() && CRaceHelper::IsStart(m_pClient, m_pClient->m_PredictedPrevChar.m_Pos, m_pClient->m_LocalCharacterPos))
|
||||
{
|
||||
OnReset();
|
||||
char aBuf[512];
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
#include "components/voting.h"
|
||||
|
||||
#include <base/system.h>
|
||||
#include "components/race.h"
|
||||
#include "components/race_demo.h"
|
||||
#include "components/ghost.h"
|
||||
#include <base/tl/sorted_array.h>
|
||||
|
@ -453,6 +454,21 @@ void CGameClient::OnConnected()
|
|||
|
||||
RenderTools()->RenderTilemapGenerateSkip(Layers());
|
||||
|
||||
CRaceHelper::ms_aFlagIndex[0] = -1;
|
||||
CRaceHelper::ms_aFlagIndex[1] = -1;
|
||||
|
||||
CTile *pGameTiles = static_cast<CTile *>(Layers()->Map()->GetData(Layers()->GameLayer()->m_Data));
|
||||
|
||||
// get flag positions
|
||||
for(int i = 0; i < m_Collision.GetWidth()*m_Collision.GetHeight(); i++)
|
||||
{
|
||||
if(pGameTiles[i].m_Index - ENTITY_OFFSET == ENTITY_FLAGSTAND_RED)
|
||||
CRaceHelper::ms_aFlagIndex[TEAM_RED] = i;
|
||||
else if(pGameTiles[i].m_Index - ENTITY_OFFSET == ENTITY_FLAGSTAND_BLUE)
|
||||
CRaceHelper::ms_aFlagIndex[TEAM_BLUE] = i;
|
||||
i += pGameTiles[i].m_Skip;
|
||||
}
|
||||
|
||||
for(int i = 0; i < m_All.m_Num; i++)
|
||||
{
|
||||
m_All.m_paComponents[i]->OnMapLoad();
|
||||
|
|
Loading…
Reference in a new issue