From fb13eb105e73d5ee2cc0c05c75772902907f0f0f Mon Sep 17 00:00:00 2001 From: Benau Date: Thu, 25 Oct 2018 00:36:47 +0800 Subject: [PATCH] Fix ranking messed up in network when finishing race --- src/modes/capture_the_flag.cpp | 2 +- src/modes/capture_the_flag.hpp | 2 +- src/network/game_setup.cpp | 4 ++-- src/network/protocols/game_events_protocol.cpp | 9 ++++++++- src/network/protocols/game_events_protocol.hpp | 2 ++ 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/modes/capture_the_flag.cpp b/src/modes/capture_the_flag.cpp index a68d3524f..7a3b653b0 100644 --- a/src/modes/capture_the_flag.cpp +++ b/src/modes/capture_the_flag.cpp @@ -511,7 +511,7 @@ bool CaptureTheFlag::isRaceOver() } // isRaceOver // ---------------------------------------------------------------------------- -void CaptureTheFlag::loseFlagForKart(unsigned int kart_id) +void CaptureTheFlag::loseFlagForKart(int kart_id) { if (!(m_red_holder == kart_id || m_blue_holder == kart_id)) return; diff --git a/src/modes/capture_the_flag.hpp b/src/modes/capture_the_flag.hpp index 7a7612948..dc418efe6 100644 --- a/src/modes/capture_the_flag.hpp +++ b/src/modes/capture_the_flag.hpp @@ -130,7 +130,7 @@ public: // ------------------------------------------------------------------------ const Vec3& getBlueFlag() const { return (Vec3&)m_blue_trans.getOrigin(); } // ------------------------------------------------------------------------ - void loseFlagForKart(unsigned int kart_id); + void loseFlagForKart(int kart_id); }; // CaptureTheFlag diff --git a/src/network/game_setup.cpp b/src/network/game_setup.cpp index 53491d481..a920bfd97 100644 --- a/src/network/game_setup.cpp +++ b/src/network/game_setup.cpp @@ -111,7 +111,7 @@ void GameSetup::update(bool remove_disconnected_players) continue; } AbstractKart* k = World::getWorld()->getKart(i); - if (!k->isEliminated()) + if (!k->isEliminated() && !k->hasFinishedRace()) { CaptureTheFlag* ctf = dynamic_cast (World::getWorld()); @@ -122,7 +122,7 @@ void GameSetup::update(bool remove_disconnected_players) false/*notify_of_elimination*/); k->setPosition( World::getWorld()->getCurrentNumKarts() + 1); - k->finishedRace(World::getWorld()->getTime()); + k->finishedRace(World::getWorld()->getTime(), true/*from_server*/); NetworkString p(PROTOCOL_GAME_EVENTS); p.setSynchronous(true); p.addUInt8(GameEventsProtocol::GE_PLAYER_DISCONNECT).addUInt8(i); diff --git a/src/network/protocols/game_events_protocol.cpp b/src/network/protocols/game_events_protocol.cpp index a51f311ad..086d70803 100644 --- a/src/network/protocols/game_events_protocol.cpp +++ b/src/network/protocols/game_events_protocol.cpp @@ -11,6 +11,7 @@ #include "network/rewind_manager.hpp" #include "network/stk_host.hpp" #include "network/stk_peer.hpp" +#include "race/race_manager.hpp" #include @@ -26,6 +27,7 @@ */ GameEventsProtocol::GameEventsProtocol() : Protocol(PROTOCOL_GAME_EVENTS) { + m_last_finished_position = 1; } // GameEventsProtocol // ---------------------------------------------------------------------------- @@ -147,7 +149,7 @@ void GameEventsProtocol::eliminatePlayer(const NetworkString &data) World::getWorld()->getKart(kartid)->setPosition( World::getWorld()->getCurrentNumKarts() + 1); World::getWorld()->getKart(kartid)->finishedRace( - World::getWorld()->getTime()); + World::getWorld()->getTime(), true/*from_server*/); } // eliminatePlayer // ---------------------------------------------------------------------------- @@ -183,6 +185,11 @@ void GameEventsProtocol::kartFinishedRace(const NetworkString &ns) float time = ns.getFloat(); World::getWorld()->getKart(kart_id)->finishedRace(time, /*from_server*/true); + if (race_manager->modeHasLaps()) + { + World::getWorld()->getKart(kart_id) + ->setPosition(m_last_finished_position++); + } } // kartFinishedRace // ---------------------------------------------------------------------------- diff --git a/src/network/protocols/game_events_protocol.hpp b/src/network/protocols/game_events_protocol.hpp index 5edf76d0e..47ccaf737 100644 --- a/src/network/protocols/game_events_protocol.hpp +++ b/src/network/protocols/game_events_protocol.hpp @@ -21,6 +21,8 @@ public: GE_STARTUP_BOOST = 8, }; // GameEventType private: + int m_last_finished_position; + void eliminatePlayer(const NetworkString &ns); public: