Implement timescore using a netobj

This commit is contained in:
Learath2 2019-05-21 10:11:02 +02:00
parent 0d25bb86c4
commit c98978c9d6
6 changed files with 31 additions and 4 deletions

View file

@ -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", [

View file

@ -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);

View file

@ -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;

View file

@ -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++)

View file

@ -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
{

View file

@ -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)