From 844f3116febd90b3b943f91a06155a90f23c94d9 Mon Sep 17 00:00:00 2001 From: btd Date: Sun, 22 Aug 2010 17:17:57 +0400 Subject: [PATCH] D:/Portable Apps/PortableGit-1.7.1-preview20100612/pause works. Need to delete RACE_PAUSE. And check that character resurect correctly --- src/game/server/entities/character.cpp | 14 +------ src/game/server/entities/character.h | 9 +--- src/game/server/gamecontext.cpp | 21 +++++----- src/game/server/player.cpp | 58 +++++++++++++++++++------- src/game/server/player.h | 12 ++++++ 5 files changed, 69 insertions(+), 45 deletions(-) diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index ac60e64f2..993930664 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -1226,16 +1226,4 @@ void CCharacter::Snap(int SnappingClient) } Character->m_PlayerState = m_PlayerState; -} - -void CCharacter::LoadPauseData() -{ - //TODO:Load The Data For a Paused Char - m_Paused = false; -} - -void CCharacter::SavePauseData() -{ - //TODO:Save The Data For a Paused Char - m_Paused = true; -} +} \ No newline at end of file diff --git a/src/game/server/entities/character.h b/src/game/server/entities/character.h index 518fd5763..c19ac708e 100644 --- a/src/game/server/entities/character.h +++ b/src/game/server/entities/character.h @@ -39,9 +39,8 @@ public: virtual void Snap(int SnappingClient); bool IsGrounded(); - bool m_Paused; - void LoadPauseData(); - void SavePauseData(); + //bool m_Paused; + void SetWeapon(int W); void HandleWeaponSwitch(); void DoWeaponSwitch(); @@ -177,10 +176,6 @@ public: int m_ReckoningTick; // tick that we are performing dead reckoning From CCharacterCore m_SendCore; // core that we should send CCharacterCore m_ReckoningCore; // the dead reckoning core - struct Pause - { - int example;//TODO:Fill This struct with useful chardata for pause FreezeTime Pos...etc - } m_Pause; }; #endif diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 2a504c9de..166c0dd11 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -651,24 +651,23 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) if(g_Config.m_SvPauseable) { CCharacter* chr = p->GetCharacter(); - if(chr) - { - if(!p->GetTeam() && !chr->m_Paused) + + if(!p->GetTeam()) { - chr->SavePauseData(); + p->SaveCharacter(); p->SetTeam(-1); } - else if (p->GetTeam()==-1 && chr->m_Paused) + else if (p->GetTeam()==-1) { + p->m_PauseInfo.m_Respawn = true; p->SetTeam(0); - chr->LoadPauseData();//TODO:Check if this system Works + //p->LoadCharacter();//TODO:Check if this system Works } - if(chr->m_RaceState==RACE_STARTED) - chr->m_RaceState = RACE_PAUSE; - else if(chr->m_RaceState==RACE_PAUSE) - chr->m_RaceState = RACE_STARTED; - } + //if(chr->m_RaceState==RACE_STARTED) + // chr->m_RaceState = RACE_PAUSE; + //else if(chr->m_RaceState==RACE_PAUSE) + // chr->m_RaceState = RACE_STARTED;*/ } } else if(!str_comp_nocase(pMsg->m_pMessage, "/info")) { diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 0afe50e11..4fff1268f 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -20,6 +20,7 @@ CPlayer::CPlayer(CGameContext *pGameServer, int CID, int Team) m_DieTick = Server()->Tick(); m_ScoreStartTick = Server()->Tick(); Character = 0; + m_CharacterCopy = 0; m_Muted = 0; this->m_ClientID = CID; m_Team = GameServer()->m_pController->ClampTeam(Team); @@ -29,6 +30,8 @@ CPlayer::CPlayer(CGameContext *pGameServer, int CID, int Team) m_LastTarget_y = 0; m_SentAfkWarning = 0; // afk timer's 1st warning after 50% of sv_max_afk_time m_SentAfkWarning2 = 0; + + m_PauseInfo.m_Respawn = false; } CPlayer::~CPlayer() @@ -200,24 +203,51 @@ void CPlayer::SetTeam(int Team) void CPlayer::TryRespawn() { - vec2 SpawnPos = vec2(100.0f, -60.0f); - - if(!GameServer()->m_pController->CanSpawn(this, &SpawnPos)) - return; - - // check if the position is occupado - CEntity *apEnts[2] = {0}; - int NumEnts = GameServer()->m_World.FindEntities(SpawnPos, 64, apEnts, 2, NETOBJTYPE_CHARACTER); - - if(NumEnts == 0) - { - m_Spawning = false; + if(m_PauseInfo.m_Respawn) { Character = new(m_ClientID) CCharacter(&GameServer()->m_World); - Character->Spawn(this, SpawnPos); - GameServer()->CreatePlayerSpawn(SpawnPos); + Character->Spawn(this, m_PauseInfo.m_Core.m_Pos); + GameServer()->CreatePlayerSpawn(m_PauseInfo.m_Core.m_Pos); + LoadCharacter(); + } else { + vec2 SpawnPos = vec2(100.0f, -60.0f); + if(!GameServer()->m_pController->CanSpawn(this, &SpawnPos)) + return; + + // check if the position is occupado + CEntity *apEnts[2] = {0}; + int NumEnts = GameServer()->m_World.FindEntities(SpawnPos, 64, apEnts, 2, NETOBJTYPE_CHARACTER); + if(NumEnts < 3) + { + m_Spawning = false; + Character = new(m_ClientID) CCharacter(&GameServer()->m_World); + Character->Spawn(this, SpawnPos); + GameServer()->CreatePlayerSpawn(SpawnPos); + } } } +void CPlayer::LoadCharacter() { + Character->m_Core = m_PauseInfo.m_Core; + Character->m_StartTime = m_PauseInfo.m_StartTime; + Character->m_RaceState = m_PauseInfo.m_RaceState; + Character->m_RefreshTime = Server()->Tick(); + for(int i = 0; i < NUM_WEAPONS; ++i) { + if(m_PauseInfo.m_aHasWeapon[i]) { + Character->GiveWeapon(i, -1); + } + } + m_PauseInfo.m_Respawn = false; +} + +void CPlayer::SaveCharacter() { + m_PauseInfo.m_Core = Character->m_Core; + m_PauseInfo.m_StartTime = Character->m_StartTime; + m_PauseInfo.m_RaceState = Character->m_RaceState; + for(int i = 0; i < NUM_WEAPONS; ++i) { + m_PauseInfo.m_aHasWeapon[i] = Character->m_aWeapons[i].m_Got; + } + //m_PauseInfo.m_RefreshTime = Character->m_RefreshTime; +} void CPlayer::AfkTimer(int new_target_x, int new_target_y) { diff --git a/src/game/server/player.h b/src/game/server/player.h index a8a9c66c9..5ed029807 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -32,6 +32,18 @@ public: void KillCharacter(int Weapon = WEAPON_GAME); CCharacter *GetCharacter(); + CCharacter* m_CharacterCopy; + struct PauseInfo { + CCharacterCore m_Core; + int m_StartTime; + int m_RaceState; + //int m_RefreshTime; + bool m_Respawn; + bool m_aHasWeapon[NUM_WEAPONS]; + } m_PauseInfo; + void LoadCharacter(); + void SaveCharacter(); + //--------------------------------------------------------- // this is used for snapping so we know how we can clip the view for the player vec2 m_ViewPos;