Renamed some time checkpoint related variables.

Init some of the time checkpoint variables explicitly
This commit is contained in:
c0d3d3v 2022-07-05 16:13:48 +02:00
parent a961151b32
commit 498c2dbbcf
No known key found for this signature in database
GPG key ID: 068AF680530DFF31
13 changed files with 93 additions and 79 deletions

View file

@ -35,6 +35,13 @@ CCharacter::CCharacter(CGameWorld *pWorld, CNetObj_PlayerInput LastInput) :
m_Input.m_TargetY = -1; m_Input.m_TargetY = -1;
m_LatestPrevPrevInput = m_LatestPrevInput = m_LatestInput = m_PrevInput = m_SavedInput = m_Input; m_LatestPrevPrevInput = m_LatestPrevInput = m_LatestInput = m_PrevInput = m_SavedInput = m_Input;
m_LastTimeCp = -1;
m_LastTimeCpBroadcasted = -1;
for(float &CurrentTimeCp : m_aCurrentTimeCp)
{
CurrentTimeCp = 0.0f;
}
} }
void CCharacter::Reset() void CCharacter::Reset()
@ -1226,15 +1233,15 @@ void CCharacter::HandleBroadcast()
{ {
CPlayerData *pData = GameServer()->Score()->PlayerData(m_pPlayer->GetCID()); CPlayerData *pData = GameServer()->Score()->PlayerData(m_pPlayer->GetCID());
if(m_DDRaceState == DDRACE_STARTED && m_CpLastBroadcast != m_CpActive && if(m_DDRaceState == DDRACE_STARTED && m_pPlayer->GetClientVersion() == VERSION_VANILLA &&
m_CpActive > -1 && m_CpTick > Server()->Tick() && m_pPlayer->GetClientVersion() == VERSION_VANILLA && m_LastTimeCpBroadcasted != m_LastTimeCp && m_LastTimeCp > -1 &&
pData->m_BestTime && pData->m_aBestCpTime[m_CpActive] != 0) m_TimeCpBroadcastEndTick > Server()->Tick() && pData->m_BestTime && pData->m_aBestTimeCp[m_LastTimeCp] != 0)
{ {
char aBroadcast[128]; char aBroadcast[128];
float Diff = m_CpCurrent[m_CpActive] - pData->m_aBestCpTime[m_CpActive]; float Diff = m_aCurrentTimeCp[m_LastTimeCp] - pData->m_aBestTimeCp[m_LastTimeCp];
str_format(aBroadcast, sizeof(aBroadcast), "Checkpoint | Diff : %+5.2f", Diff); str_format(aBroadcast, sizeof(aBroadcast), "Checkpoint | Diff : %+5.2f", Diff);
GameServer()->SendBroadcast(aBroadcast, m_pPlayer->GetCID()); GameServer()->SendBroadcast(aBroadcast, m_pPlayer->GetCID());
m_CpLastBroadcast = m_CpActive; m_LastTimeCpBroadcasted = m_LastTimeCp;
m_LastBroadcast = Server()->Tick(); m_LastBroadcast = Server()->Tick();
} }
else if((m_pPlayer->m_TimerType == CPlayer::TIMERTYPE_BROADCAST || m_pPlayer->m_TimerType == CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST) && m_DDRaceState == DDRACE_STARTED && m_LastBroadcast + Server()->TickSpeed() * g_Config.m_SvTimeInBroadcastInterval <= Server()->Tick()) else if((m_pPlayer->m_TimerType == CPlayer::TIMERTYPE_BROADCAST || m_pPlayer->m_TimerType == CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST) && m_DDRaceState == DDRACE_STARTED && m_LastBroadcast + Server()->TickSpeed() * g_Config.m_SvTimeInBroadcastInterval <= Server()->Tick())
@ -1243,7 +1250,7 @@ void CCharacter::HandleBroadcast()
int Time = (int64_t)100 * ((float)(Server()->Tick() - m_StartTime) / ((float)Server()->TickSpeed())); int Time = (int64_t)100 * ((float)(Server()->Tick() - m_StartTime) / ((float)Server()->TickSpeed()));
str_time(Time, TIME_HOURS, aBuf, sizeof(aBuf)); str_time(Time, TIME_HOURS, aBuf, sizeof(aBuf));
GameServer()->SendBroadcast(aBuf, m_pPlayer->GetCID(), false); GameServer()->SendBroadcast(aBuf, m_pPlayer->GetCID(), false);
m_CpLastBroadcast = m_CpActive; m_LastTimeCpBroadcasted = m_LastTimeCp;
m_LastBroadcast = Server()->Tick(); m_LastBroadcast = Server()->Tick();
} }
} }
@ -1343,21 +1350,21 @@ bool CCharacter::IsSwitchActiveCb(int Number, void *pUser)
void CCharacter::SetTimeCheckpoint(int TimeCheckpoint) void CCharacter::SetTimeCheckpoint(int TimeCheckpoint)
{ {
if(TimeCheckpoint != -1 && m_DDRaceState == DDRACE_STARTED && TimeCheckpoint > m_CpActive) if(TimeCheckpoint != -1 && m_DDRaceState == DDRACE_STARTED && TimeCheckpoint > m_LastTimeCp)
{ {
m_CpActive = TimeCheckpoint; m_LastTimeCp = TimeCheckpoint;
m_CpCurrent[TimeCheckpoint] = m_Time; m_aCurrentTimeCp[TimeCheckpoint] = m_Time;
m_CpTick = Server()->Tick() + Server()->TickSpeed() * 2; m_TimeCpBroadcastEndTick = Server()->Tick() + Server()->TickSpeed() * 2;
if(m_pPlayer->GetClientVersion() >= VERSION_DDRACE) if(m_pPlayer->GetClientVersion() >= VERSION_DDRACE)
{ {
CPlayerData *pData = GameServer()->Score()->PlayerData(m_pPlayer->GetCID()); CPlayerData *pData = GameServer()->Score()->PlayerData(m_pPlayer->GetCID());
if(pData->m_BestTime && pData->m_aBestCpTime[m_CpActive] != 0 && m_CpActive != -1) if(pData->m_BestTime && pData->m_aBestTimeCp[m_LastTimeCp] != 0 && m_LastTimeCp != -1)
{ {
CNetMsg_Sv_DDRaceTime Msg; CNetMsg_Sv_DDRaceTime Msg;
Msg.m_Time = (int)(m_Time * 100.0f); Msg.m_Time = (int)(m_Time * 100.0f);
Msg.m_Check = 0; Msg.m_Check = 0;
Msg.m_Finish = 0; Msg.m_Finish = 0;
float Diff = (m_CpCurrent[m_CpActive] - pData->m_aBestCpTime[m_CpActive]) * 100; float Diff = (m_aCurrentTimeCp[m_LastTimeCp] - pData->m_aBestTimeCp[m_LastTimeCp]) * 100;
Msg.m_Check = (int)Diff; Msg.m_Check = (int)Diff;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, m_pPlayer->GetCID()); Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, m_pPlayer->GetCID());
} }

View file

@ -204,10 +204,12 @@ public:
int m_StartTime; int m_StartTime;
vec2 m_PrevPos; vec2 m_PrevPos;
int m_TeleCheckpoint; int m_TeleCheckpoint;
int m_CpTick;
int m_CpActive; int m_TimeCpBroadcastEndTick;
int m_CpLastBroadcast; int m_LastTimeCp;
float m_CpCurrent[25]; int m_LastTimeCpBroadcasted;
float m_aCurrentTimeCp[25];
int m_TileIndex; int m_TileIndex;
int m_TileFIndex; int m_TileFIndex;

View file

@ -89,7 +89,12 @@ void CGameControllerDDRace::HandleCharacterTiles(CCharacter *pChr, int MapIndex)
} }
m_Teams.OnCharacterStart(ClientID); m_Teams.OnCharacterStart(ClientID);
pChr->m_CpActive = -2; pChr->m_LastTimeCp = -1;
pChr->m_LastTimeCpBroadcasted = -1;
for(float &CurrentTimeCp : pChr->m_aCurrentTimeCp)
{
CurrentTimeCp = 0.0f;
}
} }
// finish // finish

View file

@ -894,7 +894,7 @@ void CPlayer::ProcessScoreResult(CScorePlayerResult &Result)
GameServer()->CallVote(m_ClientID, Result.m_Data.m_MapVote.m_aMap, aCmd, "/map", aChatmsg); GameServer()->CallVote(m_ClientID, Result.m_Data.m_MapVote.m_aMap, aCmd, "/map", aChatmsg);
break; break;
case CScorePlayerResult::PLAYER_INFO: case CScorePlayerResult::PLAYER_INFO:
GameServer()->Score()->PlayerData(m_ClientID)->Set(Result.m_Data.m_Info.m_Time, Result.m_Data.m_Info.m_CpTime); GameServer()->Score()->PlayerData(m_ClientID)->Set(Result.m_Data.m_Info.m_Time, Result.m_Data.m_Info.m_aTimeCp);
m_Score = Result.m_Data.m_Info.m_Score; m_Score = Result.m_Data.m_Info.m_Score;
m_HasFinishScore = Result.m_Data.m_Info.m_HasFinishScore; m_HasFinishScore = Result.m_Data.m_Info.m_HasFinishScore;
// -9999 stands for no time and isn't displayed in scoreboard, so // -9999 stands for no time and isn't displayed in scoreboard, so

View file

@ -59,14 +59,14 @@ void CSaveTee::Save(CCharacter *pChr)
m_TeleCheckpoint = pChr->m_TeleCheckpoint; m_TeleCheckpoint = pChr->m_TeleCheckpoint;
m_LastPenalty = pChr->m_LastPenalty; m_LastPenalty = pChr->m_LastPenalty;
if(pChr->m_CpTick) if(pChr->m_TimeCpBroadcastEndTick)
m_CpTime = pChr->Server()->Tick() - pChr->m_CpTick; m_TimeCpBroadcastEndTime = pChr->Server()->Tick() - pChr->m_TimeCpBroadcastEndTick;
m_CpActive = pChr->m_CpActive; m_LastTimeCp = pChr->m_LastTimeCp;
m_CpLastBroadcast = pChr->m_CpLastBroadcast; m_LastTimeCpBroadcasted = pChr->m_LastTimeCpBroadcasted;
for(int i = 0; i < 25; i++) for(int i = 0; i < 25; i++)
m_aCpCurrent[i] = pChr->m_CpCurrent[i]; m_aCurrentTimeCp[i] = pChr->m_aCurrentTimeCp[i];
m_NotEligibleForFinish = pChr->m_pPlayer->m_NotEligibleForFinish; m_NotEligibleForFinish = pChr->m_pPlayer->m_NotEligibleForFinish;
@ -152,14 +152,14 @@ void CSaveTee::Load(CCharacter *pChr, int Team, bool IsSwap)
pChr->m_TeleCheckpoint = m_TeleCheckpoint; pChr->m_TeleCheckpoint = m_TeleCheckpoint;
pChr->m_LastPenalty = m_LastPenalty; pChr->m_LastPenalty = m_LastPenalty;
if(m_CpTime) if(m_TimeCpBroadcastEndTime)
pChr->m_CpTick = pChr->Server()->Tick() - m_CpTime; pChr->m_TimeCpBroadcastEndTick = pChr->Server()->Tick() - m_TimeCpBroadcastEndTime;
pChr->m_CpActive = m_CpActive; pChr->m_LastTimeCp = m_LastTimeCp;
pChr->m_CpLastBroadcast = m_CpLastBroadcast; pChr->m_LastTimeCpBroadcasted = m_LastTimeCpBroadcasted;
for(int i = 0; i < 25; i++) for(int i = 0; i < 25; i++)
pChr->m_CpCurrent[i] = m_aCpCurrent[i]; pChr->m_aCurrentTimeCp[i] = m_aCurrentTimeCp[i];
pChr->m_pPlayer->m_NotEligibleForFinish = pChr->m_pPlayer->m_NotEligibleForFinish || m_NotEligibleForFinish; pChr->m_pPlayer->m_NotEligibleForFinish = pChr->m_pPlayer->m_NotEligibleForFinish || m_NotEligibleForFinish;
@ -278,12 +278,12 @@ char *CSaveTee::GetString(const CSaveTeam *pTeam)
(int)m_HookPos.x, (int)m_HookPos.y, m_HookDir.x, m_HookDir.y, (int)m_HookPos.x, (int)m_HookPos.y, m_HookDir.x, m_HookDir.y,
(int)m_HookTeleBase.x, (int)m_HookTeleBase.y, m_HookTick, m_HookState, (int)m_HookTeleBase.x, (int)m_HookTeleBase.y, m_HookTick, m_HookState,
// time checkpoints // time checkpoints
m_CpTime, m_CpActive, m_CpLastBroadcast, m_TimeCpBroadcastEndTime, m_LastTimeCp, m_LastTimeCpBroadcasted,
m_aCpCurrent[0], m_aCpCurrent[1], m_aCpCurrent[2], m_aCpCurrent[3], m_aCpCurrent[4], m_aCurrentTimeCp[0], m_aCurrentTimeCp[1], m_aCurrentTimeCp[2], m_aCurrentTimeCp[3], m_aCurrentTimeCp[4],
m_aCpCurrent[5], m_aCpCurrent[6], m_aCpCurrent[7], m_aCpCurrent[8], m_aCpCurrent[9], m_aCurrentTimeCp[5], m_aCurrentTimeCp[6], m_aCurrentTimeCp[7], m_aCurrentTimeCp[8], m_aCurrentTimeCp[9],
m_aCpCurrent[10], m_aCpCurrent[11], m_aCpCurrent[12], m_aCpCurrent[13], m_aCpCurrent[14], m_aCurrentTimeCp[10], m_aCurrentTimeCp[11], m_aCurrentTimeCp[12], m_aCurrentTimeCp[13], m_aCurrentTimeCp[14],
m_aCpCurrent[15], m_aCpCurrent[16], m_aCpCurrent[17], m_aCpCurrent[18], m_aCpCurrent[19], m_aCurrentTimeCp[15], m_aCurrentTimeCp[16], m_aCurrentTimeCp[17], m_aCurrentTimeCp[18], m_aCurrentTimeCp[19],
m_aCpCurrent[20], m_aCpCurrent[21], m_aCpCurrent[22], m_aCpCurrent[23], m_aCpCurrent[24], m_aCurrentTimeCp[20], m_aCurrentTimeCp[21], m_aCurrentTimeCp[22], m_aCurrentTimeCp[23], m_aCurrentTimeCp[24],
m_NotEligibleForFinish, m_NotEligibleForFinish,
m_HasTelegunGun, m_HasTelegunLaser, m_HasTelegunGrenade, m_HasTelegunGun, m_HasTelegunLaser, m_HasTelegunGrenade,
m_aGameUuid, m_aGameUuid,
@ -351,12 +351,12 @@ int CSaveTee::FromString(const char *String)
&m_HookPos.x, &m_HookPos.y, &m_HookDir.x, &m_HookDir.y, &m_HookPos.x, &m_HookPos.y, &m_HookDir.x, &m_HookDir.y,
&m_HookTeleBase.x, &m_HookTeleBase.y, &m_HookTick, &m_HookState, &m_HookTeleBase.x, &m_HookTeleBase.y, &m_HookTick, &m_HookState,
// time checkpoints // time checkpoints
&m_CpTime, &m_CpActive, &m_CpLastBroadcast, &m_TimeCpBroadcastEndTime, &m_LastTimeCp, &m_LastTimeCpBroadcasted,
&m_aCpCurrent[0], &m_aCpCurrent[1], &m_aCpCurrent[2], &m_aCpCurrent[3], &m_aCpCurrent[4], &m_aCurrentTimeCp[0], &m_aCurrentTimeCp[1], &m_aCurrentTimeCp[2], &m_aCurrentTimeCp[3], &m_aCurrentTimeCp[4],
&m_aCpCurrent[5], &m_aCpCurrent[6], &m_aCpCurrent[7], &m_aCpCurrent[8], &m_aCpCurrent[9], &m_aCurrentTimeCp[5], &m_aCurrentTimeCp[6], &m_aCurrentTimeCp[7], &m_aCurrentTimeCp[8], &m_aCurrentTimeCp[9],
&m_aCpCurrent[10], &m_aCpCurrent[11], &m_aCpCurrent[12], &m_aCpCurrent[13], &m_aCpCurrent[14], &m_aCurrentTimeCp[10], &m_aCurrentTimeCp[11], &m_aCurrentTimeCp[12], &m_aCurrentTimeCp[13], &m_aCurrentTimeCp[14],
&m_aCpCurrent[15], &m_aCpCurrent[16], &m_aCpCurrent[17], &m_aCpCurrent[18], &m_aCpCurrent[19], &m_aCurrentTimeCp[15], &m_aCurrentTimeCp[16], &m_aCurrentTimeCp[17], &m_aCurrentTimeCp[18], &m_aCurrentTimeCp[19],
&m_aCpCurrent[20], &m_aCpCurrent[21], &m_aCpCurrent[22], &m_aCpCurrent[23], &m_aCpCurrent[24], &m_aCurrentTimeCp[20], &m_aCurrentTimeCp[21], &m_aCurrentTimeCp[22], &m_aCurrentTimeCp[23], &m_aCurrentTimeCp[24],
&m_NotEligibleForFinish, &m_NotEligibleForFinish,
&m_HasTelegunGun, &m_HasTelegunLaser, &m_HasTelegunGrenade, &m_HasTelegunGun, &m_HasTelegunLaser, &m_HasTelegunGrenade,
m_aGameUuid, m_aGameUuid,

View file

@ -74,10 +74,10 @@ private:
int m_TeleCheckpoint; int m_TeleCheckpoint;
int m_LastPenalty; int m_LastPenalty;
int m_CpTime; int m_TimeCpBroadcastEndTime;
int m_CpActive; int m_LastTimeCp;
int m_CpLastBroadcast; int m_LastTimeCpBroadcasted;
float m_aCpCurrent[25]; float m_aCurrentTimeCp[25];
int m_NotEligibleForFinish; int m_NotEligibleForFinish;

View file

@ -132,7 +132,7 @@ void CScore::MapInfo(int ClientID, const char *MapName)
ExecPlayerThread(CScoreWorker::MapInfo, "map info", ClientID, MapName, 0); ExecPlayerThread(CScoreWorker::MapInfo, "map info", ClientID, MapName, 0);
} }
void CScore::SaveScore(int ClientID, float Time, const char *pTimestamp, float CpTime[NUM_CHECKPOINTS], bool NotEligible) void CScore::SaveScore(int ClientID, float Time, const char *pTimestamp, float aTimeCp[NUM_CHECKPOINTS], bool NotEligible)
{ {
CConsole *pCon = (CConsole *)GameServer()->Console(); CConsole *pCon = (CConsole *)GameServer()->Console();
if(pCon->m_Cheated || NotEligible) if(pCon->m_Cheated || NotEligible)
@ -150,7 +150,7 @@ void CScore::SaveScore(int ClientID, float Time, const char *pTimestamp, float C
Tmp->m_Time = Time; Tmp->m_Time = Time;
str_copy(Tmp->m_aTimestamp, pTimestamp, sizeof(Tmp->m_aTimestamp)); str_copy(Tmp->m_aTimestamp, pTimestamp, sizeof(Tmp->m_aTimestamp));
for(int i = 0; i < NUM_CHECKPOINTS; i++) for(int i = 0; i < NUM_CHECKPOINTS; i++)
Tmp->m_aCpCurrent[i] = CpTime[i]; Tmp->m_aCurrentTimeCp[i] = aTimeCp[i];
m_pPool->ExecuteWrite(CScoreWorker::SaveScore, std::move(Tmp), "save score"); m_pPool->ExecuteWrite(CScoreWorker::SaveScore, std::move(Tmp), "save score");
} }

View file

@ -47,7 +47,7 @@ public:
void MapInfo(int ClientID, const char *pMapName); void MapInfo(int ClientID, const char *pMapName);
void MapVote(int ClientID, const char *pMapName); void MapVote(int ClientID, const char *pMapName);
void LoadPlayerData(int ClientID, const char *pName = ""); void LoadPlayerData(int ClientID, const char *pName = "");
void SaveScore(int ClientID, float Time, const char *pTimestamp, float aCpTime[NUM_CHECKPOINTS], bool NotEligible); void SaveScore(int ClientID, float Time, const char *pTimestamp, float aTimeCp[NUM_CHECKPOINTS], bool NotEligible);
void SaveTeamScore(int *pClientIDs, unsigned int Size, float Time, const char *pTimestamp); void SaveTeamScore(int *pClientIDs, unsigned int Size, float Time, const char *pTimestamp);

View file

@ -41,8 +41,8 @@ void CScorePlayerResult::SetVariant(Variant v)
m_Data.m_Info.m_Birthday = 0; m_Data.m_Info.m_Birthday = 0;
m_Data.m_Info.m_HasFinishScore = false; m_Data.m_Info.m_HasFinishScore = false;
m_Data.m_Info.m_Time = 0; m_Data.m_Info.m_Time = 0;
for(float &CpTime : m_Data.m_Info.m_CpTime) for(float &TimeCp : m_Data.m_Info.m_aTimeCp)
CpTime = 0; TimeCp = 0;
} }
} }
@ -171,7 +171,7 @@ bool CScoreWorker::LoadPlayerData(IDbConnection *pSqlServer, const ISqlData *pGa
for(int i = 0; i < NUM_CHECKPOINTS; i++) for(int i = 0; i < NUM_CHECKPOINTS; i++)
{ {
pResult->m_Data.m_Info.m_CpTime[i] = pSqlServer->GetFloat(i + 2); pResult->m_Data.m_Info.m_aTimeCp[i] = pSqlServer->GetFloat(i + 2);
} }
} }
@ -457,15 +457,15 @@ bool CScoreWorker::SaveScore(IDbConnection *pSqlServer, const ISqlData *pGameDat
" ?, %s)", " ?, %s)",
pSqlServer->InsertIgnore(), pSqlServer->GetPrefix(), pSqlServer->InsertIgnore(), pSqlServer->GetPrefix(),
pSqlServer->InsertTimestampAsUtc(), pData->m_Time, pSqlServer->InsertTimestampAsUtc(), pData->m_Time,
pData->m_aCpCurrent[0], pData->m_aCpCurrent[1], pData->m_aCpCurrent[2], pData->m_aCurrentTimeCp[0], pData->m_aCurrentTimeCp[1], pData->m_aCurrentTimeCp[2],
pData->m_aCpCurrent[3], pData->m_aCpCurrent[4], pData->m_aCpCurrent[5], pData->m_aCurrentTimeCp[3], pData->m_aCurrentTimeCp[4], pData->m_aCurrentTimeCp[5],
pData->m_aCpCurrent[6], pData->m_aCpCurrent[7], pData->m_aCpCurrent[8], pData->m_aCurrentTimeCp[6], pData->m_aCurrentTimeCp[7], pData->m_aCurrentTimeCp[8],
pData->m_aCpCurrent[9], pData->m_aCpCurrent[10], pData->m_aCpCurrent[11], pData->m_aCurrentTimeCp[9], pData->m_aCurrentTimeCp[10], pData->m_aCurrentTimeCp[11],
pData->m_aCpCurrent[12], pData->m_aCpCurrent[13], pData->m_aCpCurrent[14], pData->m_aCurrentTimeCp[12], pData->m_aCurrentTimeCp[13], pData->m_aCurrentTimeCp[14],
pData->m_aCpCurrent[15], pData->m_aCpCurrent[16], pData->m_aCpCurrent[17], pData->m_aCurrentTimeCp[15], pData->m_aCurrentTimeCp[16], pData->m_aCurrentTimeCp[17],
pData->m_aCpCurrent[18], pData->m_aCpCurrent[19], pData->m_aCpCurrent[20], pData->m_aCurrentTimeCp[18], pData->m_aCurrentTimeCp[19], pData->m_aCurrentTimeCp[20],
pData->m_aCpCurrent[21], pData->m_aCpCurrent[22], pData->m_aCpCurrent[23], pData->m_aCurrentTimeCp[21], pData->m_aCurrentTimeCp[22], pData->m_aCurrentTimeCp[23],
pData->m_aCpCurrent[24], pSqlServer->False()); pData->m_aCurrentTimeCp[24], pSqlServer->False());
if(pSqlServer->PrepareStatement(aBuf, pError, ErrorSize)) if(pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
{ {
return true; return true;

View file

@ -46,7 +46,7 @@ struct CScorePlayerResult : ISqlResult
struct struct
{ {
float m_Time; float m_Time;
float m_CpTime[NUM_CHECKPOINTS]; float m_aTimeCp[NUM_CHECKPOINTS];
int m_Score; int m_Score;
int m_HasFinishScore; int m_HasFinishScore;
int m_Birthday; // 0 indicates no birthday int m_Birthday; // 0 indicates no birthday
@ -141,7 +141,7 @@ struct CSqlScoreData : ISqlData
int m_ClientID; int m_ClientID;
float m_Time; float m_Time;
char m_aTimestamp[TIMESTAMP_STR_LENGTH]; char m_aTimestamp[TIMESTAMP_STR_LENGTH];
float m_aCpCurrent[NUM_CHECKPOINTS]; float m_aCurrentTimeCp[NUM_CHECKPOINTS];
int m_Num; int m_Num;
bool m_Search; bool m_Search;
char m_aRequestingPlayer[MAX_NAME_LENGTH]; char m_aRequestingPlayer[MAX_NAME_LENGTH];
@ -233,21 +233,21 @@ public:
{ {
m_BestTime = 0; m_BestTime = 0;
m_CurrentTime = 0; m_CurrentTime = 0;
for(float &BestCpTime : m_aBestCpTime) for(float &BestTimeCp : m_aBestTimeCp)
BestCpTime = 0; BestTimeCp = 0;
} }
void Set(float Time, float CpTime[NUM_CHECKPOINTS]) void Set(float Time, float aTimeCp[NUM_CHECKPOINTS])
{ {
m_BestTime = Time; m_BestTime = Time;
m_CurrentTime = Time; m_CurrentTime = Time;
for(int i = 0; i < NUM_CHECKPOINTS; i++) for(int i = 0; i < NUM_CHECKPOINTS; i++)
m_aBestCpTime[i] = CpTime[i]; m_aBestTimeCp[i] = aTimeCp[i];
} }
float m_BestTime; float m_BestTime;
float m_CurrentTime; float m_CurrentTime;
float m_aBestCpTime[NUM_CHECKPOINTS]; float m_aBestTimeCp[NUM_CHECKPOINTS];
}; };
struct CTeamrank struct CTeamrank

View file

@ -615,24 +615,24 @@ void CGameTeams::SetStartTime(CPlayer *Player, int StartTime)
pChar->m_StartTime = StartTime; pChar->m_StartTime = StartTime;
} }
void CGameTeams::SetCpActive(CPlayer *Player, int CpActive) void CGameTeams::SetLastTimeCp(CPlayer *Player, int LastTimeCp)
{ {
if(!Player) if(!Player)
return; return;
CCharacter *pChar = Player->GetCharacter(); CCharacter *pChar = Player->GetCharacter();
if(pChar) if(pChar)
pChar->m_CpActive = CpActive; pChar->m_LastTimeCp = LastTimeCp;
} }
float *CGameTeams::GetCpCurrent(CPlayer *Player) float *CGameTeams::GetCurrentTimeCp(CPlayer *Player)
{ {
if(!Player) if(!Player)
return NULL; return NULL;
CCharacter *pChar = Player->GetCharacter(); CCharacter *pChar = Player->GetCharacter();
if(pChar) if(pChar)
return pChar->m_CpCurrent; return pChar->m_aCurrentTimeCp;
return NULL; return NULL;
} }
@ -667,7 +667,7 @@ void CGameTeams::OnFinish(CPlayer *Player, float Time, const char *pTimestamp)
CPlayerData *pData = GameServer()->Score()->PlayerData(ClientID); CPlayerData *pData = GameServer()->Score()->PlayerData(ClientID);
char aBuf[128]; char aBuf[128];
SetCpActive(Player, -2); SetLastTimeCp(Player, -1);
// Note that the "finished in" message is parsed by the client // Note that the "finished in" message is parsed by the client
str_format(aBuf, sizeof(aBuf), str_format(aBuf, sizeof(aBuf),
"%s finished in: %d minute(s) %5.2f second(s)", "%s finished in: %d minute(s) %5.2f second(s)",
@ -727,14 +727,14 @@ void CGameTeams::OnFinish(CPlayer *Player, float Time, const char *pTimestamp)
if(!pData->m_BestTime || Time < pData->m_BestTime) if(!pData->m_BestTime || Time < pData->m_BestTime)
{ {
// update the score // update the score
pData->Set(Time, GetCpCurrent(Player)); pData->Set(Time, GetCurrentTimeCp(Player));
CallSaveScore = true; CallSaveScore = true;
} }
if(CallSaveScore) if(CallSaveScore)
if(g_Config.m_SvNamelessScore || !str_startswith(Server()->ClientName(ClientID), "nameless tee")) if(g_Config.m_SvNamelessScore || !str_startswith(Server()->ClientName(ClientID), "nameless tee"))
GameServer()->Score()->SaveScore(ClientID, Time, pTimestamp, GameServer()->Score()->SaveScore(ClientID, Time, pTimestamp,
GetCpCurrent(Player), Player->m_NotEligibleForFinish); GetCurrentTimeCp(Player), Player->m_NotEligibleForFinish);
bool NeedToSendNewRecord = false; bool NeedToSendNewRecord = false;
// update server best time // update server best time

View file

@ -114,10 +114,10 @@ public:
int GetDDRaceState(CPlayer *Player); int GetDDRaceState(CPlayer *Player);
int GetStartTime(CPlayer *Player); int GetStartTime(CPlayer *Player);
float *GetCpCurrent(CPlayer *Player); float *GetCurrentTimeCp(CPlayer *Player);
void SetDDRaceState(CPlayer *Player, int DDRaceState); void SetDDRaceState(CPlayer *Player, int DDRaceState);
void SetStartTime(CPlayer *Player, int StartTime); void SetStartTime(CPlayer *Player, int StartTime);
void SetCpActive(CPlayer *Player, int CpActive); void SetLastTimeCp(CPlayer *Player, int LastTimeCp);
void KillSavedTeam(int ClientID, int Team); void KillSavedTeam(int ClientID, int Team);
void ResetSavedTeam(int ClientID, int Team); void ResetSavedTeam(int ClientID, int Team);
void RequestTeamSwap(CPlayer *pPlayer, CPlayer *pTargetPlayer, int Team); void RequestTeamSwap(CPlayer *pPlayer, CPlayer *pTargetPlayer, int Team);

View file

@ -101,7 +101,7 @@ struct Score : public testing::TestWithParam<IDbConnection *>
ScoreData.m_Time = Time; ScoreData.m_Time = Time;
str_copy(ScoreData.m_aTimestamp, "2021-11-24 19:24:08", sizeof(ScoreData.m_aTimestamp)); str_copy(ScoreData.m_aTimestamp, "2021-11-24 19:24:08", sizeof(ScoreData.m_aTimestamp));
for(int i = 0; i < NUM_CHECKPOINTS; i++) for(int i = 0; i < NUM_CHECKPOINTS; i++)
ScoreData.m_aCpCurrent[i] = WithTimeCheckPoints ? i : 0; ScoreData.m_aCurrentTimeCp[i] = WithTimeCheckPoints ? i : 0;
str_copy(ScoreData.m_aRequestingPlayer, "deen", sizeof(ScoreData.m_aRequestingPlayer)); str_copy(ScoreData.m_aRequestingPlayer, "deen", sizeof(ScoreData.m_aRequestingPlayer));
ASSERT_FALSE(CScoreWorker::SaveScore(m_pConn, &ScoreData, false, m_aError, sizeof(m_aError))) << m_aError; ASSERT_FALSE(CScoreWorker::SaveScore(m_pConn, &ScoreData, false, m_aError, sizeof(m_aError))) << m_aError;
} }
@ -185,7 +185,7 @@ TEST_P(SingleScore, LoadPlayerData)
ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_Time, 0.0); ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_Time, 0.0);
for(int i = 0; i < NUM_CHECKPOINTS; i++) for(int i = 0; i < NUM_CHECKPOINTS; i++)
{ {
ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_CpTime[i], 0); ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_aTimeCp[i], 0);
} }
str_copy(m_PlayerRequest.m_aRequestingPlayer, "nameless tee", sizeof(m_PlayerRequest.m_aRequestingPlayer)); str_copy(m_PlayerRequest.m_aRequestingPlayer, "nameless tee", sizeof(m_PlayerRequest.m_aRequestingPlayer));
@ -196,7 +196,7 @@ TEST_P(SingleScore, LoadPlayerData)
ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_Time, 100.0); ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_Time, 100.0);
for(int i = 0; i < NUM_CHECKPOINTS; i++) for(int i = 0; i < NUM_CHECKPOINTS; i++)
{ {
ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_CpTime[i], i); ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_aTimeCp[i], i);
} }
str_copy(m_PlayerRequest.m_aRequestingPlayer, "finishless", sizeof(m_PlayerRequest.m_aRequestingPlayer)); str_copy(m_PlayerRequest.m_aRequestingPlayer, "finishless", sizeof(m_PlayerRequest.m_aRequestingPlayer));
@ -207,7 +207,7 @@ TEST_P(SingleScore, LoadPlayerData)
ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_Time, 0.0); ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_Time, 0.0);
for(int i = 0; i < NUM_CHECKPOINTS; i++) for(int i = 0; i < NUM_CHECKPOINTS; i++)
{ {
ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_CpTime[i], i); ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_aTimeCp[i], i);
} }
} }