mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
cleaned up gamecontroller
This commit is contained in:
parent
b32aff7d89
commit
5e4caa9b9c
|
@ -23,6 +23,7 @@ enum
|
|||
TEAM_SPECTATORS=-1,
|
||||
TEAM_RED,
|
||||
TEAM_BLUE,
|
||||
NUM_TEAMS,
|
||||
|
||||
FLAG_MISSING=-3,
|
||||
FLAG_ATSTAND,
|
||||
|
|
|
@ -544,15 +544,6 @@ void CCharacter::ResetInput()
|
|||
|
||||
void CCharacter::Tick()
|
||||
{
|
||||
if(m_pPlayer->m_ForceBalanced)
|
||||
{
|
||||
char Buf[128];
|
||||
str_format(Buf, sizeof(Buf), "You were moved to %s due to team balancing", GameServer()->m_pController->GetTeamName(m_pPlayer->GetTeam()));
|
||||
GameServer()->SendBroadcast(Buf, m_pPlayer->GetCID());
|
||||
|
||||
m_pPlayer->m_ForceBalanced = false;
|
||||
}
|
||||
|
||||
m_Core.m_Input = m_Input;
|
||||
m_Core.Tick(true);
|
||||
|
||||
|
@ -723,7 +714,7 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon)
|
|||
{
|
||||
m_Core.m_Vel += Force;
|
||||
|
||||
if(GameServer()->m_pController->IsFriendlyFire(m_pPlayer->GetCID(), From) && !g_Config.m_SvTeamdamage)
|
||||
if(GameServer()->m_pController->IsFriendlyFire(m_pPlayer->GetCID(), From))
|
||||
return false;
|
||||
|
||||
// m_pPlayer only inflicts half damage on self
|
||||
|
|
|
@ -364,9 +364,9 @@ void CGameContext::CheckPureTuning()
|
|||
if(!m_pController)
|
||||
return;
|
||||
|
||||
if( str_comp(m_pController->m_pGameType, "DM")==0 ||
|
||||
str_comp(m_pController->m_pGameType, "TDM")==0 ||
|
||||
str_comp(m_pController->m_pGameType, "CTF")==0)
|
||||
if( str_comp(m_pController->GetGameType(), "DM")==0 ||
|
||||
str_comp(m_pController->GetGameType(), "TDM")==0 ||
|
||||
str_comp(m_pController->GetGameType(), "CTF")==0)
|
||||
{
|
||||
CTuningParams p;
|
||||
if(mem_comp(&p, &m_Tuning, sizeof(p)) != 0)
|
||||
|
@ -398,10 +398,8 @@ void CGameContext::SwapTeams()
|
|||
for(int i = 0; i < MAX_CLIENTS; ++i)
|
||||
{
|
||||
if(m_apPlayers[i] && m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS)
|
||||
m_apPlayers[i]->SetTeam(m_apPlayers[i]->GetTeam()^1, false);
|
||||
m_pController->DoTeamChange(m_apPlayers[i], m_apPlayers[i]->GetTeam()^1, false);
|
||||
}
|
||||
|
||||
(void)m_pController->CheckTeamBalance();
|
||||
}
|
||||
|
||||
void CGameContext::OnTick()
|
||||
|
@ -506,13 +504,13 @@ void CGameContext::OnTick()
|
|||
|
||||
|
||||
#ifdef CONF_DEBUG
|
||||
if(g_Config.m_DbgDummies)
|
||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
{
|
||||
for(int i = 0; i < g_Config.m_DbgDummies ; i++)
|
||||
if(m_apPlayers[i] && m_apPlayers[i]->IsDummy())
|
||||
{
|
||||
CNetObj_PlayerInput Input = {0};
|
||||
Input.m_Direction = (i&1)?-1:1;
|
||||
m_apPlayers[MAX_CLIENTS-i-1]->OnPredictedInput(&Input);
|
||||
m_apPlayers[i]->OnPredictedInput(&Input);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -545,24 +543,12 @@ void CGameContext::OnClientEnter(int ClientID)
|
|||
m_VoteUpdate = true;
|
||||
}
|
||||
|
||||
void CGameContext::OnClientConnected(int ClientID)
|
||||
void CGameContext::OnClientConnected(int ClientID, bool Dummy)
|
||||
{
|
||||
// Check which team the player should be on
|
||||
const int StartTeam = g_Config.m_SvTournamentMode ? TEAM_SPECTATORS : m_pController->GetAutoTeam(ClientID);
|
||||
|
||||
m_apPlayers[ClientID] = new(ClientID) CPlayer(this, ClientID, StartTeam);
|
||||
//players[client_id].init(client_id);
|
||||
//players[client_id].client_id = client_id;
|
||||
|
||||
(void)m_pController->CheckTeamBalance();
|
||||
|
||||
#ifdef CONF_DEBUG
|
||||
if(g_Config.m_DbgDummies)
|
||||
{
|
||||
if(ClientID >= MAX_CLIENTS-g_Config.m_DbgDummies)
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
m_apPlayers[ClientID] = new(ClientID) CPlayer(this, ClientID, Dummy);
|
||||
|
||||
if(Dummy)
|
||||
return;
|
||||
|
||||
// send active vote
|
||||
if(m_VoteCloseTime)
|
||||
|
@ -577,11 +563,10 @@ void CGameContext::OnClientConnected(int ClientID)
|
|||
void CGameContext::OnClientDrop(int ClientID, const char *pReason)
|
||||
{
|
||||
AbortVoteKickOnDisconnect(ClientID);
|
||||
m_apPlayers[ClientID]->OnDisconnect(pReason);
|
||||
m_pController->OnPlayerDisconnect(m_apPlayers[ClientID], pReason);
|
||||
delete m_apPlayers[ClientID];
|
||||
m_apPlayers[ClientID] = 0;
|
||||
|
||||
(void)m_pController->CheckTeamBalance();
|
||||
m_VoteUpdate = true;
|
||||
|
||||
// update spectator modes
|
||||
|
@ -825,8 +810,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
|
|||
pPlayer->m_LastSetTeam = Server()->Tick();
|
||||
if(pPlayer->GetTeam() == TEAM_SPECTATORS || pMsg->m_Team == TEAM_SPECTATORS)
|
||||
m_VoteUpdate = true;
|
||||
pPlayer->SetTeam(pMsg->m_Team);
|
||||
(void)m_pController->CheckTeamBalance();
|
||||
m_pController->DoTeamChange(pPlayer, pMsg->m_Team);
|
||||
pPlayer->m_TeamChangeTick = Server()->Tick();
|
||||
}
|
||||
else
|
||||
|
@ -1088,8 +1072,7 @@ void CGameContext::ConSetTeam(IConsole::IResult *pResult, void *pUserData)
|
|||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
|
||||
|
||||
pSelf->m_apPlayers[ClientID]->m_TeamChangeTick = pSelf->Server()->Tick()+pSelf->Server()->TickSpeed()*Delay*60;
|
||||
pSelf->m_apPlayers[ClientID]->SetTeam(Team);
|
||||
(void)pSelf->m_pController->CheckTeamBalance();
|
||||
pSelf->m_pController->DoTeamChange(pSelf->m_apPlayers[ClientID], Team);
|
||||
}
|
||||
|
||||
void CGameContext::ConSetTeamAll(IConsole::IResult *pResult, void *pUserData)
|
||||
|
@ -1103,9 +1086,7 @@ void CGameContext::ConSetTeamAll(IConsole::IResult *pResult, void *pUserData)
|
|||
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i)
|
||||
if(pSelf->m_apPlayers[i])
|
||||
pSelf->m_apPlayers[i]->SetTeam(Team, false);
|
||||
|
||||
(void)pSelf->m_pController->CheckTeamBalance();
|
||||
pSelf->m_pController->DoTeamChange(pSelf->m_apPlayers[i], Team, false);
|
||||
}
|
||||
|
||||
void CGameContext::ConSwapTeams(IConsole::IResult *pResult, void *pUserData)
|
||||
|
@ -1135,26 +1116,24 @@ void CGameContext::ConShuffleTeams(IConsole::IResult *pResult, void *pUserData)
|
|||
if(pSelf->m_apPlayers[i] && pSelf->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS)
|
||||
{
|
||||
if(CounterRed == PlayerTeam)
|
||||
pSelf->m_apPlayers[i]->SetTeam(TEAM_BLUE, false);
|
||||
pSelf->m_pController->DoTeamChange(pSelf->m_apPlayers[i], TEAM_BLUE, false);
|
||||
else if(CounterBlue == PlayerTeam)
|
||||
pSelf->m_apPlayers[i]->SetTeam(TEAM_RED, false);
|
||||
pSelf->m_pController->DoTeamChange(pSelf->m_apPlayers[i], TEAM_RED, false);
|
||||
else
|
||||
{
|
||||
if(rand() % 2)
|
||||
{
|
||||
pSelf->m_apPlayers[i]->SetTeam(TEAM_BLUE, false);
|
||||
pSelf->m_pController->DoTeamChange(pSelf->m_apPlayers[i], TEAM_BLUE, false);
|
||||
++CounterBlue;
|
||||
}
|
||||
else
|
||||
{
|
||||
pSelf->m_apPlayers[i]->SetTeam(TEAM_RED, false);
|
||||
pSelf->m_pController->DoTeamChange(pSelf->m_apPlayers[i], TEAM_RED, false);
|
||||
++CounterRed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(void)pSelf->m_pController->CheckTeamBalance();
|
||||
}
|
||||
|
||||
void CGameContext::ConLockTeams(IConsole::IResult *pResult, void *pUserData)
|
||||
|
@ -1445,26 +1424,20 @@ void CGameContext::OnConsoleInit()
|
|||
Console()->Chain("sv_motd", ConchainSpecialMotdupdate, this);
|
||||
}
|
||||
|
||||
void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
||||
void CGameContext::OnInit()
|
||||
{
|
||||
// init everything
|
||||
m_pServer = Kernel()->RequestInterface<IServer>();
|
||||
m_pConsole = Kernel()->RequestInterface<IConsole>();
|
||||
m_World.SetGameServer(this);
|
||||
m_Events.SetGameServer(this);
|
||||
|
||||
//if(!data) // only load once
|
||||
//data = load_data_from_memory(internal_data);
|
||||
|
||||
for(int i = 0; i < NUM_NETOBJTYPES; i++)
|
||||
Server()->SnapSetStaticsize(i, m_NetObjHandler.GetObjSize(i));
|
||||
|
||||
m_Layers.Init(Kernel());
|
||||
m_Collision.Init(&m_Layers);
|
||||
|
||||
// reset everything here
|
||||
//world = new GAMEWORLD;
|
||||
//players = new CPlayer[MAX_CLIENTS];
|
||||
|
||||
// select gametype
|
||||
if(str_comp(g_Config.m_SvGametype, "mod") == 0)
|
||||
m_pController = new CGameControllerMOD(this);
|
||||
|
@ -1475,23 +1448,9 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
|||
else
|
||||
m_pController = new CGameControllerDM(this);
|
||||
|
||||
// setup core world
|
||||
//for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
// game.players[i].core.world = &game.world.core;
|
||||
|
||||
// create all entities from the game layer
|
||||
CMapItemLayerTilemap *pTileMap = m_Layers.GameLayer();
|
||||
CTile *pTiles = (CTile *)Kernel()->RequestInterface<IMap>()->GetData(pTileMap->m_Data);
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
num_spawn_points[0] = 0;
|
||||
num_spawn_points[1] = 0;
|
||||
num_spawn_points[2] = 0;
|
||||
*/
|
||||
|
||||
for(int y = 0; y < pTileMap->m_Height; y++)
|
||||
{
|
||||
for(int x = 0; x < pTileMap->m_Width; x++)
|
||||
|
@ -1506,15 +1465,11 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
|||
}
|
||||
}
|
||||
|
||||
//game.world.insert_entity(game.Controller);
|
||||
|
||||
#ifdef CONF_DEBUG
|
||||
if(g_Config.m_DbgDummies)
|
||||
{
|
||||
for(int i = 0; i < g_Config.m_DbgDummies ; i++)
|
||||
{
|
||||
OnClientConnected(MAX_CLIENTS-i-1);
|
||||
}
|
||||
OnClientConnected(MAX_CLIENTS-i-1, true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1565,7 +1520,7 @@ bool CGameContext::IsClientPlayer(int ClientID)
|
|||
return m_apPlayers[ClientID] && m_apPlayers[ClientID]->GetTeam() == TEAM_SPECTATORS ? false : true;
|
||||
}
|
||||
|
||||
const char *CGameContext::GameType() { return m_pController && m_pController->m_pGameType ? m_pController->m_pGameType : ""; }
|
||||
const char *CGameContext::GameType() { return m_pController && m_pController->GetGameType() ? m_pController->GetGameType() : ""; }
|
||||
const char *CGameContext::Version() { return GAME_VERSION; }
|
||||
const char *CGameContext::NetVersion() { return GAME_NETVERSION; }
|
||||
|
||||
|
|
|
@ -162,7 +162,8 @@ public:
|
|||
|
||||
virtual void OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID);
|
||||
|
||||
virtual void OnClientConnected(int ClientID);
|
||||
virtual void OnClientConnected(int ClientID) { OnClientConnected(ClientID, false); }
|
||||
void OnClientConnected(int ClientID, bool Dummy);
|
||||
virtual void OnClientEnter(int ClientID);
|
||||
virtual void OnClientDrop(int ClientID, const char *pReason);
|
||||
virtual void OnClientDirectInput(int ClientID, void *pInput);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -4,6 +4,7 @@
|
|||
#define GAME_SERVER_GAMECONTROLLER_H
|
||||
|
||||
#include <base/vmath.h>
|
||||
#include <game/generated/protocol.h>
|
||||
|
||||
/*
|
||||
Class: Game Controller
|
||||
|
@ -12,16 +13,33 @@
|
|||
*/
|
||||
class IGameController
|
||||
{
|
||||
vec2 m_aaSpawnPoints[3][64];
|
||||
int m_aNumSpawnPoints[3];
|
||||
|
||||
class CGameContext *m_pGameServer;
|
||||
class IServer *m_pServer;
|
||||
|
||||
protected:
|
||||
CGameContext *GameServer() const { return m_pGameServer; }
|
||||
IServer *Server() const { return m_pServer; }
|
||||
// activity
|
||||
void DoActivityCheck();
|
||||
|
||||
// balancing
|
||||
enum
|
||||
{
|
||||
TBALANCE_CHECK=-2,
|
||||
TBALANCE_OK,
|
||||
};
|
||||
int m_UnbalancedTick;
|
||||
|
||||
virtual bool CanBeMovedOnBalance(int ClientID) const;
|
||||
void CheckTeamBalance();
|
||||
void DoTeamBalance();
|
||||
|
||||
// game
|
||||
virtual void DoWincheck();
|
||||
|
||||
// map
|
||||
char m_aMapWish[128];
|
||||
|
||||
void CycleMap();
|
||||
|
||||
// spawn
|
||||
struct CSpawnEval
|
||||
{
|
||||
CSpawnEval()
|
||||
|
@ -36,59 +54,58 @@ protected:
|
|||
int m_FriendlyTeam;
|
||||
float m_Score;
|
||||
};
|
||||
vec2 m_aaSpawnPoints[3][64];
|
||||
int m_aNumSpawnPoints[3];
|
||||
|
||||
float EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos) const;
|
||||
void EvaluateSpawnType(CSpawnEval *pEval, int Type) const;
|
||||
|
||||
float EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos);
|
||||
void EvaluateSpawnType(CSpawnEval *pEval, int Type);
|
||||
bool EvaluateSpawn(class CPlayer *pP, vec2 *pPos);
|
||||
// team
|
||||
int ClampTeam(int Team) const;
|
||||
|
||||
void CycleMap();
|
||||
protected:
|
||||
CGameContext *GameServer() const { return m_pGameServer; }
|
||||
IServer *Server() const { return m_pServer; }
|
||||
|
||||
// game
|
||||
int m_GameOverTick;
|
||||
int m_RoundCount;
|
||||
int m_RoundStartTick;
|
||||
int m_SuddenDeath;
|
||||
int m_aTeamscore[NUM_TEAMS];
|
||||
int m_Warmup;
|
||||
|
||||
void EndRound();
|
||||
void ResetGame();
|
||||
|
||||
char m_aMapWish[128];
|
||||
|
||||
|
||||
int m_RoundStartTick;
|
||||
int m_GameOverTick;
|
||||
int m_SuddenDeath;
|
||||
|
||||
int m_aTeamscore[2];
|
||||
|
||||
int m_Warmup;
|
||||
int m_RoundCount;
|
||||
|
||||
// info
|
||||
int m_GameFlags;
|
||||
int m_UnbalancedTick;
|
||||
bool m_ForceBalanced;
|
||||
|
||||
public:
|
||||
const char *m_pGameType;
|
||||
|
||||
bool IsTeamplay() const;
|
||||
bool IsGameOver() const { return m_GameOverTick != -1; }
|
||||
|
||||
public:
|
||||
IGameController(class CGameContext *pGameServer);
|
||||
virtual ~IGameController();
|
||||
|
||||
virtual void DoWincheck();
|
||||
|
||||
void DoWarmup(int Seconds);
|
||||
|
||||
void StartRound();
|
||||
void EndRound();
|
||||
void ChangeMap(const char *pToMap);
|
||||
|
||||
bool IsFriendlyFire(int ClientID1, int ClientID2);
|
||||
|
||||
bool IsForceBalanced();
|
||||
virtual ~IGameController() {};
|
||||
|
||||
// event
|
||||
/*
|
||||
Function: on_CCharacter_death
|
||||
Called when a CCharacter in the world dies.
|
||||
|
||||
Arguments:
|
||||
victim - The CCharacter that died.
|
||||
killer - The player that killed it.
|
||||
weapon - What weapon that killed it. Can be -1 for undefined
|
||||
weapon when switching team or player suicides.
|
||||
*/
|
||||
virtual bool CanBeMovedOnBalance(int ClientID);
|
||||
virtual int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon);
|
||||
/*
|
||||
Function: on_CCharacter_spawn
|
||||
Called when a CCharacter spawns into the game world.
|
||||
|
||||
virtual void Tick();
|
||||
|
||||
virtual void Snap(int SnappingClient);
|
||||
Arguments:
|
||||
chr - The CCharacter that was spawned.
|
||||
*/
|
||||
virtual void OnCharacterSpawn(class CCharacter *pChr);
|
||||
|
||||
/*
|
||||
Function: on_entity
|
||||
|
@ -104,44 +121,41 @@ public:
|
|||
*/
|
||||
virtual bool OnEntity(int Index, vec2 Pos);
|
||||
|
||||
/*
|
||||
Function: on_CCharacter_spawn
|
||||
Called when a CCharacter spawns into the game world.
|
||||
void OnPlayerDisconnect(class CPlayer *pPlayer, const char *pReason);
|
||||
void OnPlayerInfoChange(class CPlayer *pPlayer);
|
||||
|
||||
Arguments:
|
||||
chr - The CCharacter that was spawned.
|
||||
*/
|
||||
virtual void OnCharacterSpawn(class CCharacter *pChr);
|
||||
void OnReset();
|
||||
|
||||
/*
|
||||
Function: on_CCharacter_death
|
||||
Called when a CCharacter in the world dies.
|
||||
// game
|
||||
void DoWarmup(int Seconds);
|
||||
|
||||
Arguments:
|
||||
victim - The CCharacter that died.
|
||||
killer - The player that killed it.
|
||||
weapon - What weapon that killed it. Can be -1 for undefined
|
||||
weapon when switching team or player suicides.
|
||||
*/
|
||||
virtual int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon);
|
||||
void StartRound();
|
||||
|
||||
// general
|
||||
virtual void Snap(int SnappingClient);
|
||||
virtual void Tick();
|
||||
|
||||
virtual void OnPlayerInfoChange(class CPlayer *pP);
|
||||
// info
|
||||
bool IsFriendlyFire(int ClientID1, int ClientID2) const;
|
||||
bool IsGameOver() const { return m_GameOverTick != -1; }
|
||||
bool IsTeamplay() const { return m_GameFlags&GAMEFLAG_TEAMS; }
|
||||
|
||||
const char *GetGameType() const { return m_pGameType; }
|
||||
const char *GetTeamName(int Team) const;
|
||||
|
||||
// map
|
||||
void ChangeMap(const char *pToMap);
|
||||
|
||||
//
|
||||
virtual bool CanSpawn(int Team, vec2 *pPos);
|
||||
//spawn
|
||||
bool CanSpawn(int Team, vec2 *pPos) const;
|
||||
|
||||
/*
|
||||
// team
|
||||
bool CanJoinTeam(int Team, int NotThisID) const;
|
||||
bool CanChangeTeam(CPlayer *pPplayer, int JoinTeam) const;
|
||||
|
||||
*/
|
||||
virtual const char *GetTeamName(int Team);
|
||||
virtual int GetAutoTeam(int NotThisID);
|
||||
virtual bool CanJoinTeam(int Team, int NotThisID);
|
||||
bool CheckTeamBalance();
|
||||
bool CanChangeTeam(CPlayer *pPplayer, int JoinTeam);
|
||||
int ClampTeam(int Team);
|
||||
|
||||
virtual void PostReset();
|
||||
void DoTeamChange(class CPlayer *pPlayer, int Team, bool DoChatMsg=true);
|
||||
|
||||
int GetStartTeam(int NotThisID);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -10,35 +10,34 @@
|
|||
#include <game/server/gamecontext.h>
|
||||
#include "ctf.h"
|
||||
|
||||
CGameControllerCTF::CGameControllerCTF(class CGameContext *pGameServer)
|
||||
CGameControllerCTF::CGameControllerCTF(CGameContext *pGameServer)
|
||||
: IGameController(pGameServer)
|
||||
{
|
||||
// game
|
||||
m_apFlags[0] = 0;
|
||||
m_apFlags[1] = 0;
|
||||
m_pGameType = "CTF";
|
||||
m_GameFlags = GAMEFLAG_TEAMS|GAMEFLAG_FLAGS;
|
||||
}
|
||||
|
||||
bool CGameControllerCTF::OnEntity(int Index, vec2 Pos)
|
||||
// balancing
|
||||
bool CGameControllerCTF::CanBeMovedOnBalance(int ClientID)
|
||||
{
|
||||
if(IGameController::OnEntity(Index, Pos))
|
||||
return true;
|
||||
|
||||
int Team = -1;
|
||||
if(Index == ENTITY_FLAGSTAND_RED) Team = TEAM_RED;
|
||||
if(Index == ENTITY_FLAGSTAND_BLUE) Team = TEAM_BLUE;
|
||||
if(Team == -1 || m_apFlags[Team])
|
||||
return false;
|
||||
|
||||
CFlag *F = new CFlag(&GameServer()->m_World, Team);
|
||||
F->m_StandPos = Pos;
|
||||
F->m_Pos = Pos;
|
||||
m_apFlags[Team] = F;
|
||||
GameServer()->m_World.InsertEntity(F);
|
||||
CCharacter* Character = GameServer()->m_apPlayers[ClientID]->GetCharacter();
|
||||
if(Character)
|
||||
{
|
||||
for(int fi = 0; fi < 2; fi++)
|
||||
{
|
||||
CFlag *F = m_apFlags[fi];
|
||||
if(F->m_pCarryingCharacter == Character)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int CGameControllerCTF::OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int WeaponID)
|
||||
// event
|
||||
int CGameControllerCTF::OnCharacterDeath(CCharacter *pVictim, CPlayer *pKiller, int WeaponID)
|
||||
{
|
||||
IGameController::OnCharacterDeath(pVictim, pKiller, WeaponID);
|
||||
int HadFlag = 0;
|
||||
|
@ -66,45 +65,48 @@ int CGameControllerCTF::OnCharacterDeath(class CCharacter *pVictim, class CPlaye
|
|||
return HadFlag;
|
||||
}
|
||||
|
||||
void CGameControllerCTF::DoWincheck()
|
||||
bool CGameControllerCTF::OnEntity(int Index, vec2 Pos)
|
||||
{
|
||||
if(m_GameOverTick == -1 && !m_Warmup)
|
||||
{
|
||||
// check score win condition
|
||||
if((g_Config.m_SvScorelimit > 0 && (m_aTeamscore[TEAM_RED] >= g_Config.m_SvScorelimit || m_aTeamscore[TEAM_BLUE] >= g_Config.m_SvScorelimit)) ||
|
||||
(g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_RoundStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60))
|
||||
{
|
||||
if(m_SuddenDeath)
|
||||
{
|
||||
if(m_aTeamscore[TEAM_RED]/100 != m_aTeamscore[TEAM_BLUE]/100)
|
||||
EndRound();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(m_aTeamscore[TEAM_RED] != m_aTeamscore[TEAM_BLUE])
|
||||
EndRound();
|
||||
else
|
||||
m_SuddenDeath = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(IGameController::OnEntity(Index, Pos))
|
||||
return true;
|
||||
|
||||
bool CGameControllerCTF::CanBeMovedOnBalance(int ClientID)
|
||||
{
|
||||
CCharacter* Character = GameServer()->m_apPlayers[ClientID]->GetCharacter();
|
||||
if(Character)
|
||||
{
|
||||
for(int fi = 0; fi < 2; fi++)
|
||||
{
|
||||
CFlag *F = m_apFlags[fi];
|
||||
if(F->m_pCarryingCharacter == Character)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
int Team = -1;
|
||||
if(Index == ENTITY_FLAGSTAND_RED) Team = TEAM_RED;
|
||||
if(Index == ENTITY_FLAGSTAND_BLUE) Team = TEAM_BLUE;
|
||||
if(Team == -1 || m_apFlags[Team])
|
||||
return false;
|
||||
|
||||
CFlag *F = new CFlag(&GameServer()->m_World, Team);
|
||||
F->m_StandPos = Pos;
|
||||
F->m_Pos = Pos;
|
||||
m_apFlags[Team] = F;
|
||||
GameServer()->m_World.InsertEntity(F);
|
||||
return true;
|
||||
}
|
||||
|
||||
// game
|
||||
void CGameControllerCTF::DoWincheck()
|
||||
{
|
||||
// check score win condition
|
||||
if((g_Config.m_SvScorelimit > 0 && (m_aTeamscore[TEAM_RED] >= g_Config.m_SvScorelimit || m_aTeamscore[TEAM_BLUE] >= g_Config.m_SvScorelimit)) ||
|
||||
(g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_RoundStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60))
|
||||
{
|
||||
if(m_SuddenDeath)
|
||||
{
|
||||
if(m_aTeamscore[TEAM_RED]/100 != m_aTeamscore[TEAM_BLUE]/100)
|
||||
EndRound();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(m_aTeamscore[TEAM_RED] != m_aTeamscore[TEAM_BLUE])
|
||||
EndRound();
|
||||
else
|
||||
m_SuddenDeath = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// general
|
||||
void CGameControllerCTF::Snap(int SnappingClient)
|
||||
{
|
||||
IGameController::Snap(SnappingClient);
|
||||
|
|
|
@ -7,17 +7,24 @@
|
|||
|
||||
class CGameControllerCTF : public IGameController
|
||||
{
|
||||
public:
|
||||
// balancing
|
||||
virtual bool CanBeMovedOnBalance(int ClientID);
|
||||
|
||||
// game
|
||||
class CFlag *m_apFlags[2];
|
||||
|
||||
CGameControllerCTF(class CGameContext *pGameServer);
|
||||
virtual void DoWincheck();
|
||||
virtual bool CanBeMovedOnBalance(int ClientID);
|
||||
|
||||
public:
|
||||
CGameControllerCTF(class CGameContext *pGameServer);
|
||||
|
||||
// event
|
||||
virtual int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon);
|
||||
virtual bool OnEntity(int Index, vec2 Pos);
|
||||
|
||||
// general
|
||||
virtual void Snap(int SnappingClient);
|
||||
virtual void Tick();
|
||||
|
||||
virtual bool OnEntity(int Index, vec2 Pos);
|
||||
virtual int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,13 +3,8 @@
|
|||
#include "dm.h"
|
||||
|
||||
|
||||
CGameControllerDM::CGameControllerDM(class CGameContext *pGameServer)
|
||||
CGameControllerDM::CGameControllerDM(CGameContext *pGameServer)
|
||||
: IGameController(pGameServer)
|
||||
{
|
||||
m_pGameType = "DM";
|
||||
}
|
||||
|
||||
void CGameControllerDM::Tick()
|
||||
{
|
||||
IGameController::Tick();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,6 @@ class CGameControllerDM : public IGameController
|
|||
{
|
||||
public:
|
||||
CGameControllerDM(class CGameContext *pGameServer);
|
||||
virtual void Tick();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -12,6 +12,7 @@ CGameControllerTDM::CGameControllerTDM(class CGameContext *pGameServer) : IGameC
|
|||
m_GameFlags = GAMEFLAG_TEAMS;
|
||||
}
|
||||
|
||||
// event
|
||||
int CGameControllerTDM::OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon)
|
||||
{
|
||||
IGameController::OnCharacterDeath(pVictim, pKiller, Weapon);
|
||||
|
@ -31,6 +32,7 @@ int CGameControllerTDM::OnCharacterDeath(class CCharacter *pVictim, class CPlaye
|
|||
return 0;
|
||||
}
|
||||
|
||||
// general
|
||||
void CGameControllerTDM::Snap(int SnappingClient)
|
||||
{
|
||||
IGameController::Snap(SnappingClient);
|
||||
|
@ -45,8 +47,3 @@ void CGameControllerTDM::Snap(int SnappingClient)
|
|||
pGameDataObj->m_FlagCarrierRed = 0;
|
||||
pGameDataObj->m_FlagCarrierBlue = 0;
|
||||
}
|
||||
|
||||
void CGameControllerTDM::Tick()
|
||||
{
|
||||
IGameController::Tick();
|
||||
}
|
||||
|
|
|
@ -9,8 +9,11 @@ class CGameControllerTDM : public IGameController
|
|||
public:
|
||||
CGameControllerTDM(class CGameContext *pGameServer);
|
||||
|
||||
int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon);
|
||||
// event
|
||||
virtual int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon);
|
||||
|
||||
// general
|
||||
virtual void Snap(int SnappingClient);
|
||||
virtual void Tick();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -125,7 +125,7 @@ void CGameWorld::Reset()
|
|||
}
|
||||
RemoveEntities();
|
||||
|
||||
GameServer()->m_pController->PostReset();
|
||||
GameServer()->m_pController->OnReset();
|
||||
RemoveEntities();
|
||||
|
||||
m_ResetRequested = false;
|
||||
|
@ -154,8 +154,6 @@ void CGameWorld::Tick()
|
|||
|
||||
if(!m_Paused)
|
||||
{
|
||||
if(GameServer()->m_pController->IsForceBalanced())
|
||||
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, "Teams have been balanced");
|
||||
// update all objects
|
||||
for(int i = 0; i < NUM_ENTTYPES; i++)
|
||||
for(CEntity *pEnt = m_apFirstEntityTypes[i]; pEnt; )
|
||||
|
|
|
@ -9,7 +9,7 @@ MACRO_ALLOC_POOL_ID_IMPL(CPlayer, MAX_CLIENTS)
|
|||
|
||||
IServer *CPlayer::Server() const { return m_pGameServer->Server(); }
|
||||
|
||||
CPlayer::CPlayer(CGameContext *pGameServer, int ClientID, int Team)
|
||||
CPlayer::CPlayer(CGameContext *pGameServer, int ClientID, bool Dummy)
|
||||
{
|
||||
m_pGameServer = pGameServer;
|
||||
m_RespawnTick = Server()->Tick();
|
||||
|
@ -17,10 +17,11 @@ CPlayer::CPlayer(CGameContext *pGameServer, int ClientID, int Team)
|
|||
m_ScoreStartTick = Server()->Tick();
|
||||
m_pCharacter = 0;
|
||||
m_ClientID = ClientID;
|
||||
m_Team = GameServer()->m_pController->ClampTeam(Team);
|
||||
m_Team = GameServer()->m_pController->GetStartTeam(ClientID);
|
||||
m_SpectatorID = SPEC_FREEVIEW;
|
||||
m_LastActionTick = Server()->Tick();
|
||||
m_TeamChangeTick = Server()->Tick();
|
||||
m_Dummy = Dummy;
|
||||
}
|
||||
|
||||
CPlayer::~CPlayer()
|
||||
|
@ -31,10 +32,7 @@ CPlayer::~CPlayer()
|
|||
|
||||
void CPlayer::Tick()
|
||||
{
|
||||
#ifdef CONF_DEBUG
|
||||
if(!g_Config.m_DbgDummies || m_ClientID < MAX_CLIENTS-g_Config.m_DbgDummies)
|
||||
#endif
|
||||
if(!Server()->ClientIngame(m_ClientID))
|
||||
if(!IsDummy() && !Server()->ClientIngame(m_ClientID))
|
||||
return;
|
||||
|
||||
Server()->SetClientScore(m_ClientID, m_Score);
|
||||
|
@ -112,10 +110,7 @@ void CPlayer::PostTick()
|
|||
|
||||
void CPlayer::Snap(int SnappingClient)
|
||||
{
|
||||
#ifdef CONF_DEBUG
|
||||
if(!g_Config.m_DbgDummies || m_ClientID < MAX_CLIENTS-g_Config.m_DbgDummies)
|
||||
#endif
|
||||
if(!Server()->ClientIngame(m_ClientID))
|
||||
if(!IsDummy() && !Server()->ClientIngame(m_ClientID))
|
||||
return;
|
||||
|
||||
CNetObj_ClientInfo *pClientInfo = static_cast<CNetObj_ClientInfo *>(Server()->SnapNewItem(NETOBJTYPE_CLIENTINFO, m_ClientID, sizeof(CNetObj_ClientInfo)));
|
||||
|
@ -155,22 +150,9 @@ void CPlayer::Snap(int SnappingClient)
|
|||
}
|
||||
}
|
||||
|
||||
void CPlayer::OnDisconnect(const char *pReason)
|
||||
void CPlayer::OnDisconnect()
|
||||
{
|
||||
KillCharacter();
|
||||
|
||||
if(Server()->ClientIngame(m_ClientID))
|
||||
{
|
||||
char aBuf[512];
|
||||
if(pReason && *pReason)
|
||||
str_format(aBuf, sizeof(aBuf), "'%s' has left the game (%s)", Server()->ClientName(m_ClientID), pReason);
|
||||
else
|
||||
str_format(aBuf, sizeof(aBuf), "'%s' has left the game", Server()->ClientName(m_ClientID));
|
||||
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
|
||||
|
||||
str_format(aBuf, sizeof(aBuf), "leave player='%d:%s'", m_ClientID, Server()->ClientName(m_ClientID));
|
||||
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "game", aBuf);
|
||||
}
|
||||
}
|
||||
|
||||
void CPlayer::OnPredictedInput(CNetObj_PlayerInput *NewInput)
|
||||
|
@ -243,29 +225,14 @@ void CPlayer::Respawn()
|
|||
|
||||
void CPlayer::SetTeam(int Team, bool DoChatMsg)
|
||||
{
|
||||
// clamp the team
|
||||
Team = GameServer()->m_pController->ClampTeam(Team);
|
||||
if(m_Team == Team)
|
||||
return;
|
||||
|
||||
char aBuf[512];
|
||||
if(DoChatMsg)
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "'%s' joined the %s", Server()->ClientName(m_ClientID), GameServer()->m_pController->GetTeamName(Team));
|
||||
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
|
||||
}
|
||||
|
||||
KillCharacter();
|
||||
|
||||
m_Team = Team;
|
||||
m_LastActionTick = Server()->Tick();
|
||||
|
||||
// we got to wait 0.5 secs before respawning
|
||||
m_RespawnTick = Server()->Tick()+Server()->TickSpeed()/2;
|
||||
str_format(aBuf, sizeof(aBuf), "team_join player='%d:%s' m_Team=%d", m_ClientID, Server()->ClientName(m_ClientID), m_Team);
|
||||
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf);
|
||||
|
||||
GameServer()->m_pController->OnPlayerInfoChange(GameServer()->m_apPlayers[m_ClientID]);
|
||||
|
||||
|
||||
if(Team == TEAM_SPECTATORS)
|
||||
{
|
||||
// update spectator modes
|
||||
|
|
|
@ -13,7 +13,7 @@ class CPlayer
|
|||
MACRO_ALLOC_POOL_ID()
|
||||
|
||||
public:
|
||||
CPlayer(CGameContext *pGameServer, int ClientID, int Team);
|
||||
CPlayer(CGameContext *pGameServer, int ClientID, bool Dummy);
|
||||
~CPlayer();
|
||||
|
||||
void Init(int CID);
|
||||
|
@ -23,6 +23,7 @@ public:
|
|||
void SetTeam(int Team, bool DoChatMsg=true);
|
||||
int GetTeam() const { return m_Team; };
|
||||
int GetCID() const { return m_ClientID; };
|
||||
bool IsDummy() const { return m_Dummy; }
|
||||
|
||||
void Tick();
|
||||
void PostTick();
|
||||
|
@ -30,7 +31,7 @@ public:
|
|||
|
||||
void OnDirectInput(CNetObj_PlayerInput *NewInput);
|
||||
void OnPredictedInput(CNetObj_PlayerInput *NewInput);
|
||||
void OnDisconnect(const char *pReason);
|
||||
void OnDisconnect();
|
||||
|
||||
void KillCharacter(int Weapon = WEAPON_GAME);
|
||||
CCharacter *GetCharacter();
|
||||
|
@ -76,7 +77,6 @@ public:
|
|||
int m_DieTick;
|
||||
int m_Score;
|
||||
int m_ScoreStartTick;
|
||||
bool m_ForceBalanced;
|
||||
int m_LastActionTick;
|
||||
int m_TeamChangeTick;
|
||||
struct
|
||||
|
@ -107,6 +107,7 @@ private:
|
|||
bool m_Spawning;
|
||||
int m_ClientID;
|
||||
int m_Team;
|
||||
bool m_Dummy;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue