Merge pull request #8324 from ewancg/chat-practice

Add chat commands for toggling weapons in practice mode
This commit is contained in:
Dennis Felsing 2024-05-07 05:42:38 +00:00 committed by GitHub
commit df30321f52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 158 additions and 31 deletions

View file

@ -11,6 +11,8 @@
#include "player.h"
#include "score.h"
#include <optional>
bool CheckClientId(int ClientId);
void CGameContext::ConCredits(IConsole::IResult *pResult, void *pUserData)
@ -1874,6 +1876,27 @@ void CGameContext::ConLastTele(IConsole::IResult *pResult, void *pUserData)
pPlayer->Pause(CPlayer::PAUSE_NONE, true);
}
CCharacter *CGameContext::GetPracticeCharacter(IConsole::IResult *pResult)
{
if(!CheckClientId(pResult->m_ClientId))
return nullptr;
CPlayer *pPlayer = m_apPlayers[pResult->m_ClientId];
if(!pPlayer)
return nullptr;
CCharacter *pChr = pPlayer->GetCharacter();
if(!pChr)
return nullptr;
CGameTeams &Teams = m_pController->Teams();
int Team = GetDDRaceTeam(pResult->m_ClientId);
if(!Teams.IsPractice(Team))
{
SendChatTarget(pPlayer->GetCid(), "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled.");
return nullptr;
}
return pChr;
}
void CGameContext::ConPracticeUnSolo(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
@ -1899,7 +1922,6 @@ void CGameContext::ConPracticeUnSolo(IConsole::IResult *pResult, void *pUserData
pSelf->SendChatTarget(pPlayer->GetCid(), "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled.");
return;
}
pChr->SetSolo(false);
}
@ -1928,30 +1950,16 @@ void CGameContext::ConPracticeSolo(IConsole::IResult *pResult, void *pUserData)
pSelf->SendChatTarget(pPlayer->GetCid(), "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled.");
return;
}
pChr->SetSolo(true);
}
void CGameContext::ConPracticeUnDeep(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(!CheckClientId(pResult->m_ClientId))
return;
CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId];
if(!pPlayer)
return;
CCharacter *pChr = pPlayer->GetCharacter();
auto *pChr = pSelf->GetPracticeCharacter(pResult);
if(!pChr)
return;
CGameTeams &Teams = pSelf->m_pController->Teams();
int Team = pSelf->GetDDRaceTeam(pResult->m_ClientId);
if(!Teams.IsPractice(Team))
{
pSelf->SendChatTarget(pPlayer->GetCid(), "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled.");
return;
}
pChr->SetDeepFrozen(false);
pChr->UnFreeze();
}
@ -1959,26 +1967,110 @@ void CGameContext::ConPracticeUnDeep(IConsole::IResult *pResult, void *pUserData
void CGameContext::ConPracticeDeep(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(!CheckClientId(pResult->m_ClientId))
return;
CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId];
if(!pPlayer)
return;
CCharacter *pChr = pPlayer->GetCharacter();
auto *pChr = pSelf->GetPracticeCharacter(pResult);
if(!pChr)
return;
CGameTeams &Teams = pSelf->m_pController->Teams();
int Team = pSelf->GetDDRaceTeam(pResult->m_ClientId);
if(!Teams.IsPractice(Team))
{
pSelf->SendChatTarget(pPlayer->GetCid(), "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled.");
return;
}
pChr->SetDeepFrozen(true);
}
void CGameContext::ConPracticeShotgun(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(pSelf->GetPracticeCharacter(pResult))
ConShotgun(pResult, pUserData);
}
void CGameContext::ConPracticeGrenade(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(pSelf->GetPracticeCharacter(pResult))
ConGrenade(pResult, pUserData);
}
void CGameContext::ConPracticeLaser(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(pSelf->GetPracticeCharacter(pResult))
ConLaser(pResult, pUserData);
}
void CGameContext::ConPracticeJetpack(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(pSelf->GetPracticeCharacter(pResult))
ConJetpack(pResult, pUserData);
}
void CGameContext::ConPracticeWeapons(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(pSelf->GetPracticeCharacter(pResult))
ConWeapons(pResult, pUserData);
}
void CGameContext::ConPracticeUnShotgun(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(pSelf->GetPracticeCharacter(pResult))
ConUnShotgun(pResult, pUserData);
}
void CGameContext::ConPracticeUnGrenade(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(pSelf->GetPracticeCharacter(pResult))
ConUnGrenade(pResult, pUserData);
}
void CGameContext::ConPracticeUnLaser(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(pSelf->GetPracticeCharacter(pResult))
ConUnLaser(pResult, pUserData);
}
void CGameContext::ConPracticeUnJetpack(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(pSelf->GetPracticeCharacter(pResult))
ConUnJetpack(pResult, pUserData);
}
void CGameContext::ConPracticeUnWeapons(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(pSelf->GetPracticeCharacter(pResult))
ConUnWeapons(pResult, pUserData);
}
void CGameContext::ConPracticeNinja(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(pSelf->GetPracticeCharacter(pResult))
ConNinja(pResult, pUserData);
}
void CGameContext::ConPracticeUnNinja(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(pSelf->GetPracticeCharacter(pResult))
ConUnNinja(pResult, pUserData);
}
void CGameContext::ConPracticeAddWeapon(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(pSelf->GetPracticeCharacter(pResult))
ConAddWeapon(pResult, pUserData);
}
void CGameContext::ConPracticeRemoveWeapon(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(pSelf->GetPracticeCharacter(pResult))
ConRemoveWeapon(pResult, pUserData);
}
void CGameContext::ConProtectedKill(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;

View file

@ -3702,6 +3702,22 @@ void CGameContext::RegisterChatCommands()
Console()->Register("solo", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeSolo, this, "Puts you into solo part");
Console()->Register("undeep", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeUnDeep, this, "Puts you out of deep freeze");
Console()->Register("deep", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeDeep, this, "Puts you into deep freeze");
Console()->Register("addweapon", "i[weapon-id]", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeAddWeapon, this, "Gives weapon with id i to you (all = -1, hammer = 0, gun = 1, shotgun = 2, grenade = 3, laser = 4, ninja = 5)");
Console()->Register("removeweapon", "i[weapon-id]", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeRemoveWeapon, this, "removes weapon with id i from you (all = -1, hammer = 0, gun = 1, shotgun = 2, grenade = 3, laser = 4, ninja = 5)");
Console()->Register("shotgun", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeShotgun, this, "Gives a shotgun to you");
Console()->Register("grenade", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeGrenade, this, "Gives a grenade launcher to you");
Console()->Register("laser", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeLaser, this, "Gives a laser to you");
Console()->Register("rifle", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeLaser, this, "Gives a laser to you");
Console()->Register("jetpack", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeJetpack, this, "Gives jetpack to you");
Console()->Register("weapons", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeWeapons, this, "Gives all weapons to you");
Console()->Register("unshotgun", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeUnShotgun, this, "Removes the shotgun from you");
Console()->Register("ungrenade", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeUnGrenade, this, "Removes the grenade launcher from you");
Console()->Register("unlaser", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeUnLaser, this, "Removes the laser from you");
Console()->Register("unrifle", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeUnLaser, this, "Removes the laser from you");
Console()->Register("unjetpack", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeUnJetpack, this, "Removes the jetpack from you");
Console()->Register("unweapons", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeUnWeapons, this, "Removes all weapons from you");
Console()->Register("ninja", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeNinja, this, "Makes you a ninja");
Console()->Register("unninja", "", CFGFLAG_CHAT | CMDFLAG_PRACTICE, ConPracticeUnNinja, this, "Removes ninja from you");
Console()->Register("kill", "", CFGFLAG_CHAT | CFGFLAG_SERVER, ConProtectedKill, this, "Kill yourself when kill-protected during a long game (use f1, kill for regular kill)");
}

View file

@ -395,7 +395,6 @@ private:
static void ConUnWeapons(IConsole::IResult *pResult, void *pUserData);
static void ConAddWeapon(IConsole::IResult *pResult, void *pUserData);
static void ConRemoveWeapon(IConsole::IResult *pResult, void *pUserData);
void ModifyWeapons(IConsole::IResult *pResult, void *pUserData, int Weapon, bool Remove);
void MoveCharacter(int ClientId, int X, int Y, bool Raw = false);
static void ConGoLeft(IConsole::IResult *pResult, void *pUserData);
@ -462,10 +461,28 @@ private:
static void ConTeleXY(IConsole::IResult *pResult, void *pUserData);
static void ConTeleCursor(IConsole::IResult *pResult, void *pUserData);
static void ConLastTele(IConsole::IResult *pResult, void *pUserData);
// Chat commands for practice mode
static void ConPracticeUnSolo(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeSolo(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeUnDeep(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeDeep(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeShotgun(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeGrenade(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeLaser(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeJetpack(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeWeapons(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeUnShotgun(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeUnGrenade(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeUnLaser(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeUnJetpack(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeUnWeapons(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeNinja(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeUnNinja(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeAddWeapon(IConsole::IResult *pResult, void *pUserData);
static void ConPracticeRemoveWeapon(IConsole::IResult *pResult, void *pUserData);
static void ConProtectedKill(IConsole::IResult *pResult, void *pUserData);
static void ConVoteMute(IConsole::IResult *pResult, void *pUserData);
@ -485,6 +502,8 @@ private:
static void ConFreezeHammer(IConsole::IResult *pResult, void *pUserData);
static void ConUnFreezeHammer(IConsole::IResult *pResult, void *pUserData);
CCharacter *GetPracticeCharacter(IConsole::IResult *pResult);
enum
{
MAX_MUTES = 128,