Send new scores as a whole and optimize
This commit is contained in:
parent
bff2a5f9f2
commit
ddeab51917
@ -243,8 +243,9 @@ void CaptureTheFlag::update(int ticks)
|
||||
NetworkConfig::get()->isServer())
|
||||
{
|
||||
int red_holder = m_red_flag->getHolder();
|
||||
int new_score = m_scores.at(red_holder) + g_captured_score;
|
||||
m_scores.at(red_holder) = new_score;
|
||||
int new_kart_scores = m_scores.at(red_holder) + g_captured_score;
|
||||
int new_blue_scores = m_blue_scores + 1;
|
||||
m_scores.at(red_holder) = new_kart_scores;
|
||||
if (NetworkConfig::get()->isServer())
|
||||
{
|
||||
NetworkString p(PROTOCOL_GAME_EVENTS);
|
||||
@ -252,10 +253,13 @@ void CaptureTheFlag::update(int ticks)
|
||||
p.addUInt8(GameEventsProtocol::GE_CTF_SCORED)
|
||||
.addUInt8((int8_t)red_holder)
|
||||
.addUInt8(0/*red_team_scored*/)
|
||||
.addUInt32(new_score);
|
||||
.addUInt16((int16_t)new_kart_scores)
|
||||
.addUInt8((uint8_t)m_red_scores)
|
||||
.addUInt8((uint8_t)new_blue_scores);
|
||||
STKHost::get()->sendPacketToAllPeers(&p, true);
|
||||
}
|
||||
ctfScored(red_holder, false/*red_team_scored*/, new_score);
|
||||
ctfScored(red_holder, false/*red_team_scored*/, new_kart_scores,
|
||||
m_red_scores, new_blue_scores);
|
||||
}
|
||||
m_last_captured_flag_ticks = World::getWorld()->getTicksSinceStart();
|
||||
m_red_flag->resetToBase();
|
||||
@ -269,8 +273,9 @@ void CaptureTheFlag::update(int ticks)
|
||||
NetworkConfig::get()->isServer())
|
||||
{
|
||||
int blue_holder = m_blue_flag->getHolder();
|
||||
int new_score = m_scores.at(blue_holder) + g_captured_score;
|
||||
m_scores.at(blue_holder) = new_score;
|
||||
int new_kart_scores = m_scores.at(blue_holder) + g_captured_score;
|
||||
int new_red_scores = m_red_scores + 1;
|
||||
m_scores.at(blue_holder) = new_kart_scores;
|
||||
if (NetworkConfig::get()->isServer())
|
||||
{
|
||||
NetworkString p(PROTOCOL_GAME_EVENTS);
|
||||
@ -278,10 +283,13 @@ void CaptureTheFlag::update(int ticks)
|
||||
p.addUInt8(GameEventsProtocol::GE_CTF_SCORED)
|
||||
.addUInt8((int8_t)blue_holder)
|
||||
.addUInt8(1/*red_team_scored*/)
|
||||
.addUInt32(new_score);
|
||||
.addUInt16((int16_t)new_kart_scores)
|
||||
.addUInt8((uint8_t)new_red_scores)
|
||||
.addUInt8((uint8_t)m_blue_scores);
|
||||
STKHost::get()->sendPacketToAllPeers(&p, true);
|
||||
}
|
||||
ctfScored(blue_holder, true/*red_team_scored*/, new_score);
|
||||
ctfScored(blue_holder, true/*red_team_scored*/, new_kart_scores,
|
||||
new_red_scores, m_blue_scores);
|
||||
}
|
||||
m_last_captured_flag_ticks = World::getWorld()->getTicksSinceStart();
|
||||
m_blue_flag->resetToBase();
|
||||
@ -372,21 +380,22 @@ const Vec3& CaptureTheFlag::getBlueFlag() const
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void CaptureTheFlag::ctfScored(int kart_id, bool red_team_scored,
|
||||
int new_score)
|
||||
int new_kart_score, int new_red_score,
|
||||
int new_blue_score)
|
||||
{
|
||||
m_scores.at(kart_id) = new_score;
|
||||
m_scores.at(kart_id) = new_kart_score;
|
||||
AbstractKart* kart = getKart(kart_id);
|
||||
core::stringw scored_msg;
|
||||
const core::stringw& name = kart->getController()->getName();
|
||||
m_red_scores = new_red_score;
|
||||
m_blue_scores = new_blue_score;
|
||||
if (red_team_scored)
|
||||
{
|
||||
scored_msg = _("%s captured the blue flag!", name);
|
||||
m_red_scores++;
|
||||
}
|
||||
else
|
||||
{
|
||||
scored_msg = _("%s captured the red flag!", name);
|
||||
m_blue_scores++;
|
||||
}
|
||||
#ifndef SERVER_ONLY
|
||||
m_race_gui->addMessage(scored_msg, NULL, 3.0f);
|
||||
|
@ -126,7 +126,8 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
const Vec3& getBlueFlag() const;
|
||||
// ------------------------------------------------------------------------
|
||||
void ctfScored(int kart_id, bool red_team_scored, int new_score);
|
||||
void ctfScored(int kart_id, bool red_team_scored, int new_kart_score,
|
||||
int new_red_score, int new_blue_score);
|
||||
// ------------------------------------------------------------------------
|
||||
void loseFlagForKart(int kart_id);
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -123,9 +123,9 @@ void FreeForAll::handleScoreInServer(int kart_id, int hitter)
|
||||
p.setSynchronous(true);
|
||||
p.addUInt8(GameEventsProtocol::GE_BATTLE_KART_SCORE);
|
||||
if (kart_id == hitter || hitter == -1)
|
||||
p.addUInt8((uint8_t)kart_id).addUInt32(new_score);
|
||||
p.addUInt8((uint8_t)kart_id).addUInt16((int16_t)new_score);
|
||||
else
|
||||
p.addUInt8((uint8_t)hitter).addUInt32(new_score);
|
||||
p.addUInt8((uint8_t)hitter).addUInt16((int16_t)new_score);
|
||||
STKHost::get()->sendPacketToAllPeers(&p, true);
|
||||
}
|
||||
} // handleScoreInServer
|
||||
@ -134,7 +134,7 @@ void FreeForAll::handleScoreInServer(int kart_id, int hitter)
|
||||
void FreeForAll::setKartScoreFromServer(NetworkString& ns)
|
||||
{
|
||||
int kart_id = ns.getUInt8();
|
||||
int score = ns.getUInt32();
|
||||
int16_t score = ns.getUInt16();
|
||||
m_scores.at(kart_id) = score;
|
||||
} // setKartScoreFromServer
|
||||
|
||||
|
@ -83,8 +83,11 @@ bool GameEventsProtocol::notifyEvent(Event* event)
|
||||
throw std::invalid_argument("No CTF world");
|
||||
uint8_t kart_id = data.getUInt8();
|
||||
bool red_team_scored = data.getUInt8() == 1;
|
||||
int new_score = data.getUInt32();
|
||||
ctf->ctfScored(kart_id, red_team_scored, new_score);
|
||||
int16_t new_kart_scores = data.getUInt16();
|
||||
int new_red_scores = data.getUInt8();
|
||||
int new_blue_scores = data.getUInt8();
|
||||
ctf->ctfScored(kart_id, red_team_scored, new_kart_scores,
|
||||
new_red_scores, new_blue_scores);
|
||||
break;
|
||||
}
|
||||
case GE_STARTUP_BOOST:
|
||||
|
@ -13,10 +13,10 @@ public:
|
||||
{
|
||||
GE_KART_FINISHED_RACE = 1,
|
||||
GE_STARTUP_BOOST = 2,
|
||||
GE_CTF_SCORED = 3,
|
||||
GE_RESET_BALL = 4,
|
||||
GE_PLAYER_GOAL = 5,
|
||||
GE_BATTLE_KART_SCORE = 6,
|
||||
GE_BATTLE_KART_SCORE = 3,
|
||||
GE_CTF_SCORED = 4,
|
||||
GE_RESET_BALL = 5,
|
||||
GE_PLAYER_GOAL = 6,
|
||||
}; // GameEventType
|
||||
private:
|
||||
int m_last_finished_position;
|
||||
@ -32,10 +32,10 @@ public:
|
||||
void kartFinishedRace(const NetworkString &ns);
|
||||
void sendStartupBoost(uint8_t kart_id);
|
||||
virtual void setup() OVERRIDE {}
|
||||
virtual void update(int ticks) OVERRIDE {};
|
||||
virtual void asynchronousUpdate() OVERRIDE{}
|
||||
virtual void update(int ticks) OVERRIDE {}
|
||||
virtual void asynchronousUpdate() OVERRIDE {}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE
|
||||
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE
|
||||
{
|
||||
return false;
|
||||
} // notifyEventAsynchronous
|
||||
|
Loading…
Reference in New Issue
Block a user