mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #2321
2321: Use the 0.7 race features better r=def- a=Learath2 Mostly tested, couldn't test the diffs though as I don't have score set up. It looks good to me though. Co-authored-by: Learath <learath2@gmail.com>
This commit is contained in:
commit
6384ebf13f
|
@ -1419,7 +1419,7 @@ void CGameContext::ConTime(IConsole::IResult *pResult, void *pUserData)
|
|||
pSelf->SendBroadcast(aBuftime, pResult->m_ClientID);
|
||||
}
|
||||
|
||||
static const char s_aaMsg[3][128] = {"game/round timer.", "broadcast.", "both game/round timer and broadcast."};
|
||||
static const char s_aaMsg[4][128] = {"game/round timer.", "broadcast.", "both game/round timer and broadcast.", "racetime."};
|
||||
|
||||
void CGameContext::ConSetTimerType(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
|
@ -1437,49 +1437,27 @@ void CGameContext::ConSetTimerType(IConsole::IResult *pResult, void *pUserData)
|
|||
if(pResult->NumArguments() > 0)
|
||||
{
|
||||
int OldType = pPlayer->m_TimerType;
|
||||
bool Result = false;
|
||||
|
||||
if(str_comp_nocase(pResult->GetString(0), "gametimer") == 0)
|
||||
{
|
||||
if(pPlayer->GetClientVersion() >= VERSION_DDNET_GAMETICK)
|
||||
pPlayer->m_TimerType = CPlayer::TIMERTYPE_GAMETIMER;
|
||||
else
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "timer", "gametimer is not supported by your client.");
|
||||
}
|
||||
if(str_comp_nocase(pResult->GetString(0), "default") == 0)
|
||||
Result = pPlayer->SetTimerType(CPlayer::TIMERTYPE_DEFAULT);
|
||||
else if(str_comp_nocase(pResult->GetString(0), "gametimer") == 0)
|
||||
Result = pPlayer->SetTimerType(CPlayer::TIMERTYPE_GAMETIMER);
|
||||
else if(str_comp_nocase(pResult->GetString(0), "broadcast") == 0)
|
||||
pPlayer->m_TimerType = CPlayer::TIMERTYPE_BROADCAST;
|
||||
Result = pPlayer->SetTimerType(CPlayer::TIMERTYPE_BROADCAST);
|
||||
else if(str_comp_nocase(pResult->GetString(0), "both") == 0)
|
||||
{
|
||||
if(pPlayer->GetClientVersion() >= VERSION_DDNET_GAMETICK)
|
||||
pPlayer->m_TimerType = CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST;
|
||||
else
|
||||
{
|
||||
pPlayer->m_TimerType = CPlayer::TIMERTYPE_BROADCAST;
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "timer", "gametimer is not supported by your client.");
|
||||
}
|
||||
}
|
||||
Result = pPlayer->SetTimerType(CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST);
|
||||
else if(str_comp_nocase(pResult->GetString(0), "none") == 0)
|
||||
pPlayer->m_TimerType = CPlayer::TIMERTYPE_NONE;
|
||||
else if(str_comp_nocase(pResult->GetString(0), "cycle") == 0)
|
||||
{
|
||||
if(pPlayer->GetClientVersion() >= VERSION_DDNET_GAMETICK)
|
||||
{
|
||||
if(pPlayer->m_TimerType < CPlayer::TIMERTYPE_NONE)
|
||||
pPlayer->m_TimerType++;
|
||||
else if(pPlayer->m_TimerType == CPlayer::TIMERTYPE_NONE)
|
||||
pPlayer->m_TimerType = CPlayer::TIMERTYPE_GAMETIMER;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(pPlayer->m_TimerType < CPlayer::TIMERTYPE_NONE)
|
||||
pPlayer->m_TimerType = CPlayer::TIMERTYPE_NONE;
|
||||
else if(pPlayer->m_TimerType == CPlayer::TIMERTYPE_NONE)
|
||||
pPlayer->m_TimerType = CPlayer::TIMERTYPE_BROADCAST;
|
||||
}
|
||||
}
|
||||
Result = pPlayer->SetTimerType(CPlayer::TIMERTYPE_NONE);
|
||||
else
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "Unknown \"%s\" parameter. Accepted values: gametimer, broadcast, both, none, cycle", pResult->GetString(0));
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "timer", aBuf);
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "timer", "Unknown parameter. Accepted values: default, gametimer, broadcast, both, none");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!Result)
|
||||
{
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "timer", "Selected timertype is not supported by your client");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1487,7 +1465,7 @@ void CGameContext::ConSetTimerType(IConsole::IResult *pResult, void *pUserData)
|
|||
pSelf->SendBroadcast("", pResult->m_ClientID);
|
||||
}
|
||||
|
||||
if(pPlayer->m_TimerType <= CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST && pPlayer->m_TimerType >= CPlayer::TIMERTYPE_GAMETIMER)
|
||||
if(pPlayer->m_TimerType <= CPlayer::TIMERTYPE_SIXUP && pPlayer->m_TimerType >= CPlayer::TIMERTYPE_GAMETIMER)
|
||||
str_format(aBuf, sizeof(aBuf), "Timer is displayed in %s", s_aaMsg[pPlayer->m_TimerType]);
|
||||
else if(pPlayer->m_TimerType == CPlayer::TIMERTYPE_NONE)
|
||||
str_format(aBuf, sizeof(aBuf), "Timer isn't displayed.");
|
||||
|
|
|
@ -333,8 +333,12 @@ void CGameContext::CallVote(int ClientID, const char *pDesc, const char *pCmd, c
|
|||
pPlayer->m_LastVoteCall = Now;
|
||||
}
|
||||
|
||||
void CGameContext::SendChatTarget(int To, const char *pText)
|
||||
void CGameContext::SendChatTarget(int To, const char *pText, int Flags)
|
||||
{
|
||||
if(!((Server()->IsSixup(To) && (Flags & CHAT_SIXUP)) ||
|
||||
(!Server()->IsSixup(To) && (Flags & CHAT_SIX))))
|
||||
return;
|
||||
|
||||
CNetMsg_Sv_Chat Msg;
|
||||
Msg.m_Team = 0;
|
||||
Msg.m_ClientID = -1;
|
||||
|
|
|
@ -200,7 +200,7 @@ public:
|
|||
|
||||
// network
|
||||
void CallVote(int ClientID, const char *aDesc, const char *aCmd, const char *pReason, const char *aChatmsg);
|
||||
void SendChatTarget(int To, const char *pText);
|
||||
void SendChatTarget(int To, const char *pText, int Flags = CHAT_SIX | CHAT_SIXUP);
|
||||
void SendChatTeam(int Team, const char *pText);
|
||||
void SendChat(int ClientID, int Team, const char *pText, int SpamProtectionClientID = -1, int Flags = CHAT_SIX | CHAT_SIXUP);
|
||||
void SendEmoticon(int ClientID, int Emoticon);
|
||||
|
|
|
@ -67,7 +67,11 @@ void CPlayer::Reset()
|
|||
m_ChatScore = 0;
|
||||
m_Moderating = false;
|
||||
m_EyeEmote = true;
|
||||
m_TimerType = (g_Config.m_SvDefaultTimerType == CPlayer::TIMERTYPE_GAMETIMER || g_Config.m_SvDefaultTimerType == CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST) ? CPlayer::TIMERTYPE_BROADCAST : g_Config.m_SvDefaultTimerType;
|
||||
if(Server()->IsSixup(m_ClientID))
|
||||
m_TimerType = TIMERTYPE_SIXUP;
|
||||
else
|
||||
m_TimerType = (g_Config.m_SvDefaultTimerType == TIMERTYPE_GAMETIMER || g_Config.m_SvDefaultTimerType == TIMERTYPE_GAMETIMER_AND_BROADCAST) ? TIMERTYPE_BROADCAST : g_Config.m_SvDefaultTimerType;
|
||||
|
||||
m_DefEmote = EMOTE_NORMAL;
|
||||
m_Afk = true;
|
||||
m_LastWhisperTo = -1;
|
||||
|
@ -400,6 +404,13 @@ void CPlayer::Snap(int SnappingClient)
|
|||
pDDNetPlayer->m_Flags |= EXPLAYERFLAG_SPEC;
|
||||
if(m_Paused == PAUSE_PAUSED)
|
||||
pDDNetPlayer->m_Flags |= EXPLAYERFLAG_PAUSED;
|
||||
|
||||
if(Server()->IsSixup(SnappingClient) && m_pCharacter->m_DDRaceState == DDRACE_STARTED &&
|
||||
GameServer()->m_apPlayers[SnappingClient]->m_TimerType == TIMERTYPE_SIXUP)
|
||||
{
|
||||
protocol7::CNetObj_PlayerInfoRace *pRaceInfo = static_cast<protocol7::CNetObj_PlayerInfoRace *>(Server()->SnapNewItem(-protocol7::NETOBJTYPE_PLAYERINFORACE, id, sizeof(protocol7::CNetObj_PlayerInfoRace)));
|
||||
pRaceInfo->m_RaceStartTick = m_pCharacter->m_StartTime;
|
||||
}
|
||||
}
|
||||
|
||||
void CPlayer::FakeSnap()
|
||||
|
@ -641,6 +652,52 @@ void CPlayer::SetTeam(int Team, bool DoChatMsg)
|
|||
}
|
||||
}
|
||||
|
||||
bool CPlayer::SetTimerType(int TimerType)
|
||||
{
|
||||
if(TimerType == TIMERTYPE_DEFAULT)
|
||||
{
|
||||
if(Server()->IsSixup(m_ClientID))
|
||||
m_TimerType = TIMERTYPE_SIXUP;
|
||||
else
|
||||
SetTimerType(g_Config.m_SvDefaultTimerType);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(Server()->IsSixup(m_ClientID))
|
||||
{
|
||||
if(TimerType == TIMERTYPE_SIXUP || TimerType == TIMERTYPE_NONE)
|
||||
{
|
||||
m_TimerType = TimerType;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
if(TimerType == TIMERTYPE_GAMETIMER)
|
||||
{
|
||||
if(GetClientVersion() >= VERSION_DDNET_GAMETICK)
|
||||
m_TimerType = TimerType;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if(TimerType == TIMERTYPE_GAMETIMER_AND_BROADCAST)
|
||||
{
|
||||
if(GetClientVersion() >= VERSION_DDNET_GAMETICK)
|
||||
m_TimerType = TimerType;
|
||||
else
|
||||
{
|
||||
m_TimerType = TIMERTYPE_BROADCAST;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
m_TimerType = TimerType;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CPlayer::TryRespawn()
|
||||
{
|
||||
vec2 SpawnPos;
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
int GetTeam() const { return m_Team; };
|
||||
int GetCID() const { return m_ClientID; };
|
||||
int GetClientVersion() const;
|
||||
bool SetTimerType(int NewType);
|
||||
|
||||
void Tick();
|
||||
void PostTick();
|
||||
|
@ -144,9 +145,11 @@ public:
|
|||
|
||||
enum
|
||||
{
|
||||
TIMERTYPE_DEFAULT=-1,
|
||||
TIMERTYPE_GAMETIMER=0,
|
||||
TIMERTYPE_BROADCAST,
|
||||
TIMERTYPE_GAMETIMER_AND_BROADCAST,
|
||||
TIMERTYPE_SIXUP,
|
||||
TIMERTYPE_NONE,
|
||||
};
|
||||
|
||||
|
|
|
@ -550,24 +550,26 @@ void CGameTeams::OnFinish(CPlayer* Player, float Time, const char *pTimestamp)
|
|||
if (!Player || !Player->IsPlaying())
|
||||
return;
|
||||
//TODO:DDRace:btd: this ugly
|
||||
CPlayerData *pData = GameServer()->Score()->PlayerData(Player->GetCID());
|
||||
const int ClientID = Player->GetCID();
|
||||
CPlayerData *pData = GameServer()->Score()->PlayerData(ClientID);
|
||||
|
||||
char aBuf[128];
|
||||
SetCpActive(Player, -2);
|
||||
str_format(aBuf, sizeof(aBuf),
|
||||
"%s finished in: %d minute(s) %5.2f second(s)",
|
||||
Server()->ClientName(Player->GetCID()), (int)Time / 60,
|
||||
Server()->ClientName(ClientID), (int)Time / 60,
|
||||
Time - ((int)Time / 60 * 60));
|
||||
if (g_Config.m_SvHideScore || !g_Config.m_SvSaveWorseScores)
|
||||
GameServer()->SendChatTarget(Player->GetCID(), aBuf);
|
||||
GameServer()->SendChatTarget(ClientID, aBuf, CGameContext::CHAT_SIX);
|
||||
else
|
||||
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
|
||||
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, -1., CGameContext::CHAT_SIX);
|
||||
|
||||
float Diff = fabs(Time - pData->m_BestTime);
|
||||
|
||||
if (Time - pData->m_BestTime < 0)
|
||||
{
|
||||
// new record \o/
|
||||
Server()->SaveDemo(Player->GetCID(), Time);
|
||||
Server()->SaveDemo(ClientID, Time);
|
||||
|
||||
if (Diff >= 60)
|
||||
str_format(aBuf, sizeof(aBuf), "New record: %d minute(s) %5.2f second(s) better.",
|
||||
|
@ -576,17 +578,17 @@ void CGameTeams::OnFinish(CPlayer* Player, float Time, const char *pTimestamp)
|
|||
str_format(aBuf, sizeof(aBuf), "New record: %5.2f second(s) better.",
|
||||
Diff);
|
||||
if (g_Config.m_SvHideScore || !g_Config.m_SvSaveWorseScores)
|
||||
GameServer()->SendChatTarget(Player->GetCID(), aBuf);
|
||||
GameServer()->SendChatTarget(ClientID, aBuf, CGameContext::CHAT_SIX);
|
||||
else
|
||||
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
|
||||
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, CGameContext::CHAT_SIX);
|
||||
}
|
||||
else if (pData->m_BestTime != 0) // tee has already finished?
|
||||
{
|
||||
Server()->StopRecord(Player->GetCID());
|
||||
Server()->StopRecord(ClientID);
|
||||
|
||||
if (Diff <= 0.005f)
|
||||
{
|
||||
GameServer()->SendChatTarget(Player->GetCID(),
|
||||
GameServer()->SendChatTarget(ClientID,
|
||||
"You finished with your best time.");
|
||||
}
|
||||
else
|
||||
|
@ -598,12 +600,12 @@ void CGameTeams::OnFinish(CPlayer* Player, float Time, const char *pTimestamp)
|
|||
str_format(aBuf, sizeof(aBuf),
|
||||
"%5.2f second(s) worse, better luck next time.",
|
||||
Diff);
|
||||
GameServer()->SendChatTarget(Player->GetCID(), aBuf); //this is private, sent only to the tee
|
||||
GameServer()->SendChatTarget(ClientID, aBuf, CGameContext::CHAT_SIX); //this is private, sent only to the tee
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Server()->SaveDemo(Player->GetCID(), Time);
|
||||
Server()->SaveDemo(ClientID, Time);
|
||||
}
|
||||
|
||||
bool CallSaveScore = false;
|
||||
|
@ -619,8 +621,8 @@ void CGameTeams::OnFinish(CPlayer* Player, float Time, const char *pTimestamp)
|
|||
}
|
||||
|
||||
if (CallSaveScore)
|
||||
if (g_Config.m_SvNamelessScore || !str_startswith(Server()->ClientName(Player->GetCID()), "nameless tee"))
|
||||
GameServer()->Score()->SaveScore(Player->GetCID(), Time, pTimestamp,
|
||||
if (g_Config.m_SvNamelessScore || !str_startswith(Server()->ClientName(ClientID), "nameless tee"))
|
||||
GameServer()->Score()->SaveScore(ClientID, Time, pTimestamp,
|
||||
GetCpCurrent(Player), Player->m_NotEligibleForFinish);
|
||||
|
||||
bool NeedToSendNewRecord = false;
|
||||
|
@ -629,7 +631,7 @@ void CGameTeams::OnFinish(CPlayer* Player, float Time, const char *pTimestamp)
|
|||
|| Time < GameServer()->m_pController->m_CurrentRecord)
|
||||
{
|
||||
// check for nameless
|
||||
if (g_Config.m_SvNamelessScore || !str_startswith(Server()->ClientName(Player->GetCID()), "nameless tee"))
|
||||
if (g_Config.m_SvNamelessScore || !str_startswith(Server()->ClientName(ClientID), "nameless tee"))
|
||||
{
|
||||
GameServer()->m_pController->m_CurrentRecord = Time;
|
||||
//dbg_msg("character", "Finish");
|
||||
|
@ -670,7 +672,17 @@ void CGameTeams::OnFinish(CPlayer* Player, float Time, const char *pTimestamp)
|
|||
Msg.m_Check = (int)Diff;
|
||||
}
|
||||
|
||||
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, Player->GetCID());
|
||||
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID);
|
||||
}
|
||||
|
||||
{
|
||||
protocol7::CNetMsg_Sv_RaceFinish Msg;
|
||||
Msg.m_ClientID = ClientID;
|
||||
Msg.m_Time = Time * 1000;
|
||||
Msg.m_Diff = Diff * 1000 * (Time < pData->m_BestTime ? -1 : 1);
|
||||
Msg.m_RecordPersonal = Time < pData->m_BestTime;
|
||||
Msg.m_RecordServer = Time < GameServer()->m_pController->m_CurrentRecord;
|
||||
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, -1);
|
||||
}
|
||||
|
||||
int TTime = 0 - (int)Time;
|
||||
|
|
Loading…
Reference in a new issue