mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Implement timescore using a netobj
This commit is contained in:
parent
0d25bb86c4
commit
c98978c9d6
|
@ -8,6 +8,7 @@ CharacterFlags = ["SOLO", "JETPACK", "NO_COLLISION", "ENDLESS_HOOK", "ENDLESS_JU
|
|||
"NO_HAMMER_HIT", "NO_SHOTGUN_HIT", "NO_GRENADE_HIT", "NO_RIFLE_HIT", "NO_HOOK",
|
||||
"TELEGUN_GUN", "TELEGUN_GRENADE", "TELEGUN_LASER",
|
||||
"WEAPON_HAMMER", "WEAPON_GUN", "WEAPON_SHOTGUN", "WEAPON_GRENADE", "WEAPON_LASER", "WEAPON_NINJA"]
|
||||
GameInfoFlags = ["TIMESCORE"]
|
||||
|
||||
Emoticons = ["OOP", "EXCLAMATION", "HEARTS", "DROP", "DOTDOT", "MUSIC", "SORRY", "GHOST", "SUSHI", "SPLATTEE", "DEVILTEE", "ZOMG", "ZZZ", "WTF", "EYES", "QUESTION"]
|
||||
|
||||
|
@ -56,6 +57,7 @@ Flags = [
|
|||
Flags("GAMEFLAG", GameFlags),
|
||||
Flags("GAMESTATEFLAG", GameStateFlags),
|
||||
Flags("CHARACTERFLAG", CharacterFlags),
|
||||
Flags("GAMEINFOFLAG", GameInfoFlags),
|
||||
]
|
||||
|
||||
Objects = [
|
||||
|
@ -214,6 +216,10 @@ Objects = [
|
|||
NetIntRange("m_AuthLevel", "AUTHED_NO", "AUTHED_ADMIN"),
|
||||
]),
|
||||
|
||||
NetObjectEx("DDNetGameInfo", "gameinfo@netobj.ddnet.tw", [
|
||||
NetIntAny("m_Flags"),
|
||||
]),
|
||||
|
||||
## Events
|
||||
|
||||
NetEvent("Common", [
|
||||
|
|
|
@ -340,7 +340,7 @@ void CHud::RenderScoreHud()
|
|||
{
|
||||
CServerInfo Info;
|
||||
Client()->GetServerInfo(&Info);
|
||||
if(IsRace(&Info) && g_Config.m_ClDDRaceScoreBoard)
|
||||
if(m_pClient->TimeScore() && g_Config.m_ClDDRaceScoreBoard)
|
||||
{
|
||||
if(apPlayerInfo[t]->m_Score != -9999)
|
||||
str_format(aScore[t], sizeof(aScore[t]), "%02d:%02d", abs(apPlayerInfo[t]->m_Score)/60, abs(apPlayerInfo[t]->m_Score)%60);
|
||||
|
|
|
@ -231,7 +231,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
|
|||
}
|
||||
}
|
||||
|
||||
if(m_IsGameTypeRace && g_Config.m_ClDDRaceScoreBoard)
|
||||
if(m_pClient->TimeScore() && g_Config.m_ClDDRaceScoreBoard)
|
||||
{
|
||||
if (m_ServerRecord > 0)
|
||||
{
|
||||
|
@ -294,7 +294,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
|
|||
// render headlines
|
||||
y += 50.0f;
|
||||
float HeadlineFontsize = 22.0f;
|
||||
const char *pScore = (m_IsGameTypeRace && g_Config.m_ClDDRaceScoreBoard) ? Localize("Time") : Localize("Score");
|
||||
const char *pScore = (m_pClient->TimeScore() && g_Config.m_ClDDRaceScoreBoard) ? Localize("Time") : Localize("Score");
|
||||
float ScoreWidth = TextRender()->TextWidth(0, HeadlineFontsize, pScore, -1);
|
||||
tw = ScoreLength > ScoreWidth ? ScoreLength : ScoreWidth;
|
||||
TextRender()->Text(0, ScoreOffset+ScoreLength-tw, y + (HeadlineFontsize * 2.f - HeadlineFontsize) / 2.f, HeadlineFontsize, pScore, -1);
|
||||
|
@ -414,7 +414,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
|
|||
}
|
||||
|
||||
// score
|
||||
if(m_IsGameTypeRace && g_Config.m_ClDDRaceScoreBoard)
|
||||
if(m_pClient->TimeScore() && g_Config.m_ClDDRaceScoreBoard)
|
||||
{
|
||||
if (pInfo->m_Score == -9999)
|
||||
aBuf[0] = 0;
|
||||
|
|
|
@ -1173,6 +1173,10 @@ void CGameClient::OnNewSnapshot()
|
|||
s_GameOver = CurrentTickGameOver;
|
||||
s_GamePaused = (bool)(m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED);
|
||||
}
|
||||
else if(Item.m_Type == NETOBJTYPE_DDNETGAMEINFO)
|
||||
{
|
||||
m_Snap.m_pGameInfoEx = (const CNetObj_DDNetGameInfo *)pData;
|
||||
}
|
||||
else if(Item.m_Type == NETOBJTYPE_GAMEDATA)
|
||||
{
|
||||
m_Snap.m_pGameDataObj = (const CNetObj_GameData *)pData;
|
||||
|
@ -1975,6 +1979,13 @@ void CGameClient::UpdatePrediction()
|
|||
}
|
||||
}
|
||||
|
||||
bool CGameClient::TimeScore()
|
||||
{
|
||||
CServerInfo Info;
|
||||
Client()->GetServerInfo(&Info);
|
||||
return m_Snap.m_pGameInfoEx ? m_Snap.m_pGameInfoEx->m_Flags & GAMEINFOFLAG_TIMESCORE : IsRace(&Info);
|
||||
}
|
||||
|
||||
void CGameClient::UpdateRenderedCharacters()
|
||||
{
|
||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
|
|
|
@ -188,6 +188,8 @@ public:
|
|||
//const CNetObj_PlayerInfo *m_paInfoByTeam[MAX_CLIENTS];
|
||||
const CNetObj_PlayerInfo *m_paInfoByDDTeam[MAX_CLIENTS];
|
||||
|
||||
const CNetObj_DDNetGameInfo *m_pGameInfoEx;
|
||||
|
||||
int m_LocalClientID;
|
||||
int m_NumPlayers;
|
||||
int m_aTeamSize[2];
|
||||
|
@ -222,6 +224,8 @@ public:
|
|||
|
||||
CSnapState m_Snap;
|
||||
|
||||
bool TimeScore();
|
||||
|
||||
// client data
|
||||
struct CClientData
|
||||
{
|
||||
|
|
|
@ -536,6 +536,12 @@ void IGameController::Snap(int SnappingClient)
|
|||
pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_RACETIME;
|
||||
}
|
||||
}
|
||||
|
||||
CNetObj_DDNetGameInfo *pGameInfoEx = (CNetObj_DDNetGameInfo *)Server()->SnapNewItem(NETOBJTYPE_DDNETGAMEINFO, 0, sizeof(CNetObj_DDNetGameInfo));
|
||||
if(!pGameInfoEx)
|
||||
return;
|
||||
|
||||
pGameInfoEx->m_Flags = GAMEINFOFLAG_TIMESCORE;
|
||||
}
|
||||
|
||||
int IGameController::GetAutoTeam(int NotThisID)
|
||||
|
|
Loading…
Reference in a new issue