Handle first-team assignment better when joining in the middle of game

This commit is contained in:
Benau 2018-11-25 15:49:04 +08:00
parent 1f1734e5a7
commit 4c534dc28c
3 changed files with 22 additions and 1 deletions

View File

@ -1618,7 +1618,7 @@ void ServerLobby::handleUnencryptedConnection(std::shared_ptr<STKPeer> peer,
}
unsigned player_count = data.getUInt8();
auto red_blue = m_game_setup->getPlayerTeamInfo();
auto red_blue = STKHost::get()->getAllPlayersTeamInfo();
for (unsigned i = 0; i < player_count; i++)
{
core::stringw name;

View File

@ -25,6 +25,7 @@
#include "network/game_setup.hpp"
#include "network/network_config.hpp"
#include "network/network_console.hpp"
#include "network/network_player_profile.hpp"
#include "network/network_string.hpp"
#include "network/network_timer_synchronizer.hpp"
#include "network/protocols/connect_to_peer.hpp"
@ -1248,3 +1249,20 @@ void STKHost::initClientNetwork(ENetEvent& event, Network* new_network)
if (pm && !pm->isExiting())
pm->propagateEvent(new Event(&event, stk_peer));
} // replaceNetwork
// ----------------------------------------------------------------------------
std::pair<int, int> STKHost::getAllPlayersTeamInfo() const
{
int red_count = 0;
int blue_count = 0;
auto pp = getAllPlayerProfiles();
for (auto& player : pp)
{
if (player->getTeam() == KART_TEAM_RED)
red_count++;
else if (player->getTeam() == KART_TEAM_BLUE)
blue_count++;
}
return std::make_pair(red_count, blue_count);
} // getAllPlayersTeamInfo

View File

@ -337,6 +337,9 @@ public:
// ------------------------------------------------------------------------
void setNetworkTimer(uint64_t ticks)
{ m_network_timer.store(StkTime::getRealTimeMs() - ticks); }
// ------------------------------------------------------------------------
std::pair<int, int> getAllPlayersTeamInfo() const;
}; // class STKHost
#endif // STK_HOST_HPP