From ab353dd632be791e18396997bd9a8b7f408f9ebc Mon Sep 17 00:00:00 2001 From: Benau Date: Thu, 3 Jan 2019 16:27:16 +0800 Subject: [PATCH] Save and restore complete world status for ffa and ctf --- src/modes/capture_the_flag.cpp | 18 ++++++++++++++++++ src/modes/capture_the_flag.hpp | 4 ++++ src/modes/free_for_all.cpp | 14 ++++++++++++++ src/modes/free_for_all.hpp | 10 ++++++++++ src/modes/world.hpp | 11 ++++++++++- src/network/protocols/client_lobby.cpp | 2 +- src/network/protocols/server_lobby.cpp | 2 ++ 7 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/modes/capture_the_flag.cpp b/src/modes/capture_the_flag.cpp index e13670c52..31e1335e6 100644 --- a/src/modes/capture_the_flag.cpp +++ b/src/modes/capture_the_flag.cpp @@ -402,6 +402,9 @@ void CaptureTheFlag::ctfScored(int kart_id, bool red_team_scored, scored_msg = _("%s captured the red flag!", name); } #ifndef SERVER_ONLY + // Don't set animation and show message if receiving in live join + if (isStartPhase()) + return; m_race_gui->addMessage(scored_msg, NULL, 3.0f); kart->getKartModel() ->setAnimation(KartModel::AF_WIN_START, true/*play_non_loop*/); @@ -537,3 +540,18 @@ const std::string& CaptureTheFlag::getIdent() const { return IDENT_CTF; } // getIdent + +// ---------------------------------------------------------------------------- +void CaptureTheFlag::saveCompleteState(BareNetworkString* bns) +{ + FreeForAll::saveCompleteState(bns); + bns->addUInt32(m_red_scores).addUInt32(m_blue_scores); +} // saveCompleteState + +// ---------------------------------------------------------------------------- +void CaptureTheFlag::restoreCompleteState(const BareNetworkString& b) +{ + FreeForAll::restoreCompleteState(b); + m_red_scores = b.getUInt32(); + m_blue_scores = b.getUInt32(); +} // restoreCompleteState diff --git a/src/modes/capture_the_flag.hpp b/src/modes/capture_the_flag.hpp index 918638352..2d946a84f 100644 --- a/src/modes/capture_the_flag.hpp +++ b/src/modes/capture_the_flag.hpp @@ -156,6 +156,10 @@ public: } return progress; } + // ------------------------------------------------------------------------ + virtual void saveCompleteState(BareNetworkString* bns) OVERRIDE; + // ------------------------------------------------------------------------ + virtual void restoreCompleteState(const BareNetworkString& b) OVERRIDE; }; // CaptureTheFlag #endif diff --git a/src/modes/free_for_all.cpp b/src/modes/free_for_all.cpp index fc5536354..185eae627 100644 --- a/src/modes/free_for_all.cpp +++ b/src/modes/free_for_all.cpp @@ -227,3 +227,17 @@ bool FreeForAll::getKartFFAResult(int kart_id) const int top_score = getKartScore(k->getWorldKartId()); return getKartScore(kart_id) == top_score; } // getKartFFAResult + +// ---------------------------------------------------------------------------- +void FreeForAll::saveCompleteState(BareNetworkString* bns) +{ + for (unsigned i = 0; i < m_scores.size(); i++) + bns->addUInt32(m_scores[i]); +} // saveCompleteState + +// ---------------------------------------------------------------------------- +void FreeForAll::restoreCompleteState(const BareNetworkString& b) +{ + for (unsigned i = 0; i < m_scores.size(); i++) + m_scores[i] = b.getUInt32(); +} // restoreCompleteState diff --git a/src/modes/free_for_all.hpp b/src/modes/free_for_all.hpp index 7ff5ecba0..0b4a4075e 100644 --- a/src/modes/free_for_all.hpp +++ b/src/modes/free_for_all.hpp @@ -85,6 +85,16 @@ public: (float)race_manager->getHitCaptureLimit() * 100.0f); return progress; } + // ------------------------------------------------------------------------ + virtual void addReservedKart(int kart_id) OVERRIDE + { + WorldWithRank::addReservedKart(kart_id); + m_scores.at(kart_id) = 0; + } + // ------------------------------------------------------------------------ + virtual void saveCompleteState(BareNetworkString* bns) OVERRIDE; + // ------------------------------------------------------------------------ + virtual void restoreCompleteState(const BareNetworkString& b) OVERRIDE; }; // FreeForAll diff --git a/src/modes/world.hpp b/src/modes/world.hpp index 7a4274bf8..d72a8ac0d 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -41,6 +41,7 @@ #include "LinearMath/btTransform.h" class AbstractKart; +class BareNetworkString; class btRigidBody; class Controller; class ItemState; @@ -326,7 +327,15 @@ public: unsigned int getCurrentNumPlayers() const { return m_num_players - m_eliminated_players;} // ------------------------------------------------------------------------ - virtual void addReservedKart(int kart_id) { m_eliminated_karts--; } + virtual void addReservedKart(int kart_id) + { + if (m_eliminated_karts > 0) + m_eliminated_karts--; + } + // ------------------------------------------------------------------------ + virtual void saveCompleteState(BareNetworkString* bns) {} + // ------------------------------------------------------------------------ + virtual void restoreCompleteState(const BareNetworkString& buffer) {} // ------------------------------------------------------------------------ /** The code that draws the timer should call this first to know * whether the game mode wants a timer drawn. */ diff --git a/src/network/protocols/client_lobby.cpp b/src/network/protocols/client_lobby.cpp index 024ccccbe..5778e0334 100644 --- a/src/network/protocols/client_lobby.cpp +++ b/src/network/protocols/client_lobby.cpp @@ -1012,7 +1012,7 @@ void ClientLobby::liveJoinAcknowledged(Event* event) dynamic_cast(ItemManager::get()); assert(nim); nim->restoreCompleteState(data); - + w->restoreCompleteState(data); } // liveJoinAcknowledged //----------------------------------------------------------------------------- diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index b24fce217..d373ac232 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -868,6 +868,8 @@ void ServerLobby::finishedLoadingLiveJoinClient(Event* event) nim->saveCompleteState(ns); nim->addLiveJoinPeer(peer); + w->saveCompleteState(ns); + m_peers_ready[peer] = false; peer->setWaitingForGame(false);