mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
rank/teamrank: Display how much better you are
This commit is contained in:
parent
989d26bfec
commit
b28cdc933a
|
@ -665,7 +665,11 @@ bool CScore::ShowRankThread(IDbConnection *pSqlServer, const ISqlData *pGameData
|
|||
char aBuf[600];
|
||||
|
||||
str_format(aBuf, sizeof(aBuf),
|
||||
"SELECT Rank, Name, Time "
|
||||
"SELECT Rank, Time, "
|
||||
" 100.0 - 100.0 * (Rank - 1) / ("
|
||||
" SELECT COUNT(DISTINCT Name) - 1 "
|
||||
" FROM %s_race WHERE Map = ?"
|
||||
" ) AS BetterThanPercent "
|
||||
"FROM ("
|
||||
" SELECT RANK() OVER w AS Rank, Name, MIN(Time) AS Time "
|
||||
" FROM %s_race "
|
||||
|
@ -674,29 +678,30 @@ bool CScore::ShowRankThread(IDbConnection *pSqlServer, const ISqlData *pGameData
|
|||
" WINDOW w AS (ORDER BY Time)"
|
||||
") as a "
|
||||
"WHERE Name = ?;",
|
||||
pSqlServer->GetPrefix());
|
||||
pSqlServer->GetPrefix(), pSqlServer->GetPrefix());
|
||||
pSqlServer->PrepareStatement(aBuf);
|
||||
pSqlServer->BindString(1, pData->m_Map);
|
||||
pSqlServer->BindString(2, pData->m_Name);
|
||||
pSqlServer->BindString(2, pData->m_Map);
|
||||
pSqlServer->BindString(3, pData->m_Name);
|
||||
|
||||
if(pSqlServer->Step())
|
||||
{
|
||||
int Rank = pSqlServer->GetInt(1);
|
||||
float Time = pSqlServer->GetFloat(3);
|
||||
float Time = pSqlServer->GetFloat(2);
|
||||
// CEIL and FLOOR are not supported in SQLite
|
||||
int BetterThanPercent = std::floor(pSqlServer->GetFloat(3));
|
||||
str_time_float(Time, TIME_HOURS_CENTISECS, aBuf, sizeof(aBuf));
|
||||
if(g_Config.m_SvHideScore)
|
||||
{
|
||||
str_format(pResult->m_Data.m_aaMessages[0], sizeof(pResult->m_Data.m_aaMessages[0]),
|
||||
"Your time: %s", aBuf);
|
||||
"Your time: %s, better than %d%%", aBuf, BetterThanPercent);
|
||||
}
|
||||
else
|
||||
{
|
||||
char aName[MAX_NAME_LENGTH];
|
||||
pSqlServer->GetString(2, aName, sizeof(aName));
|
||||
pResult->m_MessageKind = CScorePlayerResult::ALL;
|
||||
str_format(pResult->m_Data.m_aaMessages[0], sizeof(pResult->m_Data.m_aaMessages[0]),
|
||||
"%d. %s Time: %s, requested by %s",
|
||||
Rank, aName, aBuf, pData->m_RequestingPlayer);
|
||||
"%d. %s Time: %s, better than %d%%, requested by %s",
|
||||
Rank, pData->m_Name, aBuf, BetterThanPercent, pData->m_RequestingPlayer);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -723,7 +728,11 @@ bool CScore::ShowTeamRankThread(IDbConnection *pSqlServer, const ISqlData *pGame
|
|||
char aBuf[2400];
|
||||
|
||||
str_format(aBuf, sizeof(aBuf),
|
||||
"SELECT l.ID, Name, Time, Rank "
|
||||
"SELECT l.ID, Name, Time, Rank, "
|
||||
" 100.0 - 100.0 * (Rank - 1) / ("
|
||||
" SELECT COUNT(DISTINCT ID) - 1 "
|
||||
" FROM %s_teamrace WHERE Map = ?"
|
||||
" ) AS BetterThanPercent "
|
||||
"FROM (" // teamrank score board
|
||||
" SELECT RANK() OVER w AS Rank, ID "
|
||||
" FROM %s_teamrace "
|
||||
|
@ -738,17 +747,21 @@ bool CScore::ShowTeamRankThread(IDbConnection *pSqlServer, const ISqlData *pGame
|
|||
" LIMIT 1"
|
||||
") AS l ON TeamRank.ID = l.ID "
|
||||
"INNER JOIN %s_teamrace AS r ON l.ID = r.ID ",
|
||||
pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->GetPrefix());
|
||||
pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->GetPrefix(),
|
||||
pSqlServer->GetPrefix());
|
||||
pSqlServer->PrepareStatement(aBuf);
|
||||
pSqlServer->BindString(1, pData->m_Map);
|
||||
pSqlServer->BindString(2, pData->m_Map);
|
||||
pSqlServer->BindString(3, pData->m_Name);
|
||||
pSqlServer->BindString(3, pData->m_Map);
|
||||
pSqlServer->BindString(4, pData->m_Name);
|
||||
|
||||
if(pSqlServer->Step())
|
||||
{
|
||||
float Time = pSqlServer->GetFloat(3);
|
||||
str_time_float(Time, TIME_HOURS_CENTISECS, aBuf, sizeof(aBuf));
|
||||
int Rank = pSqlServer->GetInt(4);
|
||||
// CEIL and FLOOR are not supported in SQLite
|
||||
int BetterThanPercent = std::floor(pSqlServer->GetFloat(5));
|
||||
CTeamrank Teamrank;
|
||||
Teamrank.NextSqlResult(pSqlServer);
|
||||
|
||||
|
@ -766,14 +779,14 @@ bool CScore::ShowTeamRankThread(IDbConnection *pSqlServer, const ISqlData *pGame
|
|||
if(g_Config.m_SvHideScore)
|
||||
{
|
||||
str_format(pResult->m_Data.m_aaMessages[0], sizeof(pResult->m_Data.m_aaMessages[0]),
|
||||
"Your team time: %s", aBuf);
|
||||
"Your team time: %s, better than %d%%", aBuf, BetterThanPercent);
|
||||
}
|
||||
else
|
||||
{
|
||||
pResult->m_MessageKind = CScorePlayerResult::ALL;
|
||||
str_format(pResult->m_Data.m_aaMessages[0], sizeof(pResult->m_Data.m_aaMessages[0]),
|
||||
"%d. %s Team time: %s, requested by %s",
|
||||
Rank, aFormattedNames, aBuf, pData->m_RequestingPlayer);
|
||||
"%d. %s Team time: %s, better than %d%%, requested by %s",
|
||||
Rank, aFormattedNames, aBuf, BetterThanPercent, pData->m_RequestingPlayer);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue