Skip to content

Commit

Permalink
Make the base (unmodded) game classes somewhat working
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaffeine committed Nov 24, 2024
1 parent c412e6b commit ec921da
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 1 deletion.
56 changes: 56 additions & 0 deletions src/game/server/entities/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,50 @@ void CCharacter::Die(int Killer, int Weapon)
//TODO: Move the emote stuff to a function
void CCharacter::SnapCharacter(int SnappingClient, int Id)
{
CCharacterCore *pCore;
int Tick = 0;

// write down the m_Core
if(!m_ReckoningTick || GameServer()->m_World.m_Paused)
{
Tick = 0;
pCore = &m_Core;
}
else
{
Tick = m_ReckoningTick;
pCore = &m_SendCore;
}

int EmoteNormal = m_pPlayer->GetDefaultEmote();

CNetObj_Character *pCharacter = Server()->SnapNewItem<CNetObj_Character>(Id);
if(!pCharacter)
return;

pCharacter->m_Tick = Tick;
pCore->Write(pCharacter);
if(pCharacter->m_HookedPlayer != -1)
{
if(!Server()->Translate(pCharacter->m_HookedPlayer, SnappingClient))
pCharacter->m_HookedPlayer = -1;
}
pCharacter->m_Emote = m_EmoteType;
pCharacter->m_AmmoCount = 0;
pCharacter->m_AttackTick = m_AttackTick;
pCharacter->m_Direction = m_Input.m_Direction;
pCharacter->m_Weapon = m_ActiveWeapon;

pCharacter->m_Health = m_Health;
pCharacter->m_Armor = m_Armor;

if(pCharacter->m_Emote == EmoteNormal)
{
if(250 - ((Server()->Tick() - m_LastAction) % (250)) < 5)
pCharacter->m_Emote = EMOTE_BLINK;
}

pCharacter->m_PlayerFlags = GetPlayer()->m_PlayerFlags;
}

bool CCharacter::CanSnapCharacter(int SnappingClient)
Expand Down Expand Up @@ -544,6 +588,18 @@ bool CCharacter::IsSnappingCharacterInView(int SnappingClientId)

void CCharacter::Snap(int SnappingClient)
{
int Id = m_pPlayer->GetCid();

if(!Server()->Translate(Id, SnappingClient))
return;

if(!CanSnapCharacter(SnappingClient))
return;

if(!IsSnappingCharacterInView(SnappingClient))
return;

SnapCharacter(SnappingClient, Id);
}

bool CCharacter::CanCollide(int ClientId)
Expand Down
51 changes: 50 additions & 1 deletion src/game/server/gamecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1157,11 +1157,34 @@ void IGameController::OnGameRestart()

bool IGameController::IsTeamplay() const
{
return m_GameFlags&GAMEFLAG_TEAMS;
return m_GameFlags & GAMEFLAG_TEAMS;
}

void IGameController::Snap(int SnappingClient)
{
CNetObj_GameInfo *pGameInfoObj = Server()->SnapNewItem<CNetObj_GameInfo>(0);
if(!pGameInfoObj)
return;

pGameInfoObj->m_GameFlags = m_GameFlags;
pGameInfoObj->m_GameStateFlags = 0;
if(m_GameOverTick != -1)
pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_GAMEOVER;
if(m_SuddenDeath)
pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_SUDDENDEATH;
if(GameServer()->m_World.m_Paused)
pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_PAUSED;
pGameInfoObj->m_RoundStartTick = m_RoundStartTick;
pGameInfoObj->m_WarmupTimer = m_Warmup;

pGameInfoObj->m_ScoreLimit = Config()->m_SvScorelimit;

pGameInfoObj->m_RoundNum = (str_length(Config()->m_SvMaprotation) && Config()->m_SvRoundsPerMap) ? Config()->m_SvRoundsPerMap : 0;
pGameInfoObj->m_RoundCurrent = m_RoundCount+1;

CNetObj_GameData *pGameData = static_cast<CNetObj_GameData *>(Server()->SnapNewItem(NETOBJTYPE_GAMEDATA, 0, sizeof(CNetObj_GameData)));
if(!pGameData)
return;
}

int IGameController::GetAutoTeam(int NotThisId)
Expand Down Expand Up @@ -1189,6 +1212,32 @@ int IGameController::GetAutoTeam(int NotThisId)
return -1;
}

bool IGameController::CanSpawn(int Team, vec2 *pOutPos) const
{
// spectators can't spawn
if(Team == TEAM_SPECTATORS || GameServer()->m_World.m_Paused || GameServer()->m_World.m_ResetRequested)
return false;

const int Type = Team == TEAM_RED ? 0 : 1;
if(m_avSpawnPoints[Type].size() == 0)
{
return false;
}

// get spawn point
const std::vector<vec2> &vSpawnPoints = m_avSpawnPoints[Type];
const std::size_t Count = vSpawnPoints.size();
const int RandomShift = random_int(0, Count - 1);
for(std::size_t i = 0; i < Count; i++)
{
int PosIndex = (i + RandomShift) % Count;
*pOutPos = vSpawnPoints[PosIndex];
return true;
}

return false;
}

bool IGameController::CanJoinTeam(int Team, int NotThisId)
{
if(Team == TEAM_SPECTATORS || (GameServer()->m_apPlayers[NotThisId] && GameServer()->m_apPlayers[NotThisId]->GetTeam() != TEAM_SPECTATORS))
Expand Down
2 changes: 2 additions & 0 deletions src/game/server/gamecontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ class IGameController
int GetRoundCount();
bool IsRoundEndTime();

bool CanSpawn(int Team, vec2 *pOutPos) const;

bool IsForceBalanced();

struct CMapRotationInfo
Expand Down
12 changes: 12 additions & 0 deletions src/game/server/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,18 @@ void CPlayer::SetTeam(int Team, bool DoChatMsg)

void CPlayer::TryRespawn()
{
vec2 SpawnPos;

if(!GameServer()->m_pController->CanSpawn(m_Team, &SpawnPos))
return;

m_Spawning = false;
CCharacter *pCharacter = new(m_ClientId) CCharacter(GameServer()->GameWorld());

m_pCharacter = pCharacter;
m_pCharacter->Spawn(this, SpawnPos);

GameServer()->CreatePlayerSpawn(SpawnPos);
}

void CPlayer::UpdatePlaytime()
Expand Down

0 comments on commit ec921da

Please sign in to comment.