Save and restore complete world status for ffa and ctf

This commit is contained in:
Benau 2019-01-03 16:27:16 +08:00
parent b2ac7489d9
commit ab353dd632
7 changed files with 59 additions and 2 deletions

View File

@ -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

View File

@ -156,6 +156,10 @@ public:
}
return progress;
}
// ------------------------------------------------------------------------
virtual void saveCompleteState(BareNetworkString* bns) OVERRIDE;
// ------------------------------------------------------------------------
virtual void restoreCompleteState(const BareNetworkString& b) OVERRIDE;
}; // CaptureTheFlag
#endif

View File

@ -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

View File

@ -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

View File

@ -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. */

View File

@ -1012,7 +1012,7 @@ void ClientLobby::liveJoinAcknowledged(Event* event)
dynamic_cast<NetworkItemManager*>(ItemManager::get());
assert(nim);
nim->restoreCompleteState(data);
w->restoreCompleteState(data);
} // liveJoinAcknowledged
//-----------------------------------------------------------------------------

View File

@ -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);