diff --git a/source/ps/Game.cpp b/source/ps/Game.cpp index df320c0c48..2686c3f674 100755 --- a/source/ps/Game.cpp +++ b/source/ps/Game.cpp @@ -9,7 +9,11 @@ #include "timer.h" #include "Profile.h" #include "Loader.h" +#include "CStr.h" +#include "EntityManager.h" +#include "CConsole.h" +extern CConsole* g_Console; CGame *g_Game=NULL; // Disable "warning C4355: 'this' : used in base member initializer list". @@ -62,7 +66,6 @@ PSRETURN CGame::RegisterInit(CGameAttributes* pAttribs) LDR_EndRegistering(); return 0; } - PSRETURN CGame::ReallyStartGame() { #ifndef NO_GUI @@ -125,9 +128,75 @@ void CGame::Update(double deltaTime) m_Simulation.Update(deltaTime); // TODO Detect game over and bring up the summary screen or something + // ^ Quick game over hack is implemented, no summary screen however + if ( m_World.GetEntityManager()->GetDeath() ) + { + UpdateGameStatus(); + if (GameStatus != 0) + EndGame(); + } + //reset death event flag + m_World.GetEntityManager()->SetDeath(false); +} +void CGame::UpdateGameStatus() +{ + bool EOG_lose = true; + bool EOG_win = true; + CPlayer *local = GetLocalPlayer(); + + for (int i=0; igetHandle(i); + if ( !handle ) + continue; + CPlayer *tmpPlayer = handle->m_entity->GetPlayer(); + + //Are we still alive? + if ( local == tmpPlayer && handle->m_entity->m_extant ) + { + EOG_lose = false; + if (EOG_win == false) + break; + } + //Are they still alive? + else if ( handle->m_entity->m_extant ) + { + EOG_win = false; + if (EOG_lose == false) + break; + } + } + if (EOG_lose && EOG_win) + GameStatus = EOG_SPECIAL_DRAW; + else if (EOG_win) + GameStatus = EOG_WIN; + else if (EOG_lose) + GameStatus = EOG_LOSE; + else + GameStatus = EOG_NEUTRAL; } - +void CGame::EndGame() +{ + g_Console->InsertMessage( L"It's the end of the game as we know it!"); + switch (GameStatus) + { + case EOG_DRAW: + g_Console->InsertMessage( L"A diplomatic draw ain't so bad, eh?"); + break; + case EOG_SPECIAL_DRAW: + g_Console->InsertMessage( L"Amazingly, you managed to draw from dieing at the same time as your opponent...you have my respect."); + break; + case EOG_LOSE: + g_Console->InsertMessage( L"My condolences on your loss."); + break; + case EOG_WIN: + g_Console->InsertMessage( L"Thou art victorious!"); + break; + default: + break; + } +} CPlayer *CGame::GetPlayer(uint idx) { if (idx > m_NumPlayers) diff --git a/source/ps/Game.h b/source/ps/Game.h index 8e5a306cb1..a817f88f95 100755 --- a/source/ps/Game.h +++ b/source/ps/Game.h @@ -30,6 +30,15 @@ class CGame uint m_NumPlayers; bool m_GameStarted; + + enum EOG + { + EOG_NEUTRAL, + EOG_DRAW, //Draw by means of agreement of civilization + EOG_SPECIAL_DRAW, //Theoretically, players could die at the same time...? + EOG_LOSE, + EOG_WIN + } GameStatus; public: CGame(); @@ -48,7 +57,9 @@ public: Perform all per-frame updates */ void Update(double deltaTime); - + void UpdateGameStatus(); + void EndGame(); + inline CPlayer *GetLocalPlayer() { return m_pLocalPlayer; } inline void SetLocalPlayer(CPlayer *pLocalPlayer)