modify the race_id management to ensure that we always have ids between 0 and the number of players
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13402 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
057c8f46be
commit
a51f7bfb74
@ -79,6 +79,10 @@ bool GameSetup::removePlayer(uint8_t id)
|
||||
"Remains %u.", m_players.size());
|
||||
return true;
|
||||
}
|
||||
if (m_players[i]->race_id > id)
|
||||
{
|
||||
m_players[i]->race_id--; // all indices in [0;n[ (n = #players)
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -243,8 +243,7 @@ void ServerLobbyRoomProtocol::connectionRequested(Event* event)
|
||||
if (m_setup->getPlayerCount() < 16) // accept player
|
||||
{
|
||||
// add the player to the game setup
|
||||
while(m_setup->getProfile(m_next_id)!=NULL)
|
||||
m_next_id++;
|
||||
m_next_id = m_setup->getPlayerCount();
|
||||
// notify everybody that there is a new player
|
||||
NetworkString message;
|
||||
// new player (1) -- size of id -- id -- size of local id -- local id;
|
||||
@ -267,7 +266,7 @@ void ServerLobbyRoomProtocol::connectionRequested(Event* event)
|
||||
std::vector<NetworkPlayerProfile*> players = m_setup->getPlayers();
|
||||
for (unsigned int i = 0; i < players.size(); i++)
|
||||
{
|
||||
// do not make a duplicate of the player
|
||||
// do not duplicate the player into the message
|
||||
if (players[i]->race_id != m_next_id && players[i]->user_profile->getUserID() != player_id)
|
||||
message_ack.ai8(1).ai8(players[i]->race_id).ai8(4).ai32(players[i]->user_profile->getUserID());
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ protected:
|
||||
/** Fill the ribbon with the karts from the currently selected group */
|
||||
void setKartsFromCurrentGroup();
|
||||
|
||||
void playerConfirm(const int playerID);
|
||||
virtual void playerConfirm(const int playerID);
|
||||
|
||||
/** Stores a pointer to the current selection screen */
|
||||
static KartSelectionScreen* m_instance_ptr;
|
||||
|
@ -279,7 +279,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
}
|
||||
else if (selection == "multiplayer")
|
||||
{
|
||||
KartSelectionScreen* s = NetworkKartSelectionScreen::getInstance();
|
||||
KartSelectionScreen* s = OfflineKartSelectionScreen::getInstance();
|
||||
s->setMultiplayer(true);
|
||||
s->setFromOverworld(false);
|
||||
StateManager::get()->pushScreen( s );
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/protocols/client_lobby_room_protocol.hpp"
|
||||
#include "network/network_manager.hpp"
|
||||
#include "online/current_user.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
|
||||
using namespace GUIEngine;
|
||||
@ -32,6 +34,63 @@ void NetworkKartSelectionScreen::init()
|
||||
back_button->setImage("gui/main_quit.png");
|
||||
|
||||
m_multiplayer = false;
|
||||
|
||||
// add a widget for each player except self (already exists):
|
||||
GameSetup* setup = NetworkManager::getInstance()->getGameSetup();
|
||||
if (!setup)
|
||||
{
|
||||
Log::error("NetworkKartSelectionScreen", "No network game setup registered.");
|
||||
return;
|
||||
}
|
||||
std::vector<NetworkPlayerProfile*> players = setup->getPlayers();
|
||||
|
||||
|
||||
// ---- Get available area for karts
|
||||
// make a copy of the area, ands move it to be outside the screen
|
||||
Widget* kartsAreaWidget = getWidget("playerskarts");
|
||||
// start at the rightmost of the screen
|
||||
const int shift = irr_driver->getFrameSize().Width;
|
||||
core::recti kartsArea(kartsAreaWidget->m_x + shift,
|
||||
kartsAreaWidget->m_y,
|
||||
kartsAreaWidget->m_x + shift + kartsAreaWidget->m_w,
|
||||
kartsAreaWidget->m_y + kartsAreaWidget->m_h);
|
||||
|
||||
for (unsigned int i = 0; i < players.size(); i++)
|
||||
{
|
||||
if (players[i]->user_profile == Online::CurrentUser::get())
|
||||
return; // it is me, don't add again
|
||||
|
||||
|
||||
StateManager::ActivePlayer* aplayer =
|
||||
StateManager::get()->getActivePlayer(players[i]->race_id);
|
||||
|
||||
std::string selected_kart_group = "standard"; // standard group
|
||||
|
||||
PlayerKartWidget* newPlayerWidget =
|
||||
new PlayerKartWidget(this, aplayer, kartsArea, m_kart_widgets.size(),
|
||||
selected_kart_group);
|
||||
|
||||
manualAddWidget(newPlayerWidget);
|
||||
m_kart_widgets.push_back(newPlayerWidget);
|
||||
|
||||
newPlayerWidget->add();
|
||||
}
|
||||
|
||||
const int amount = m_kart_widgets.size();
|
||||
Widget* fullarea = getWidget("playerskarts");
|
||||
|
||||
const int splitWidth = fullarea->m_w / amount;
|
||||
|
||||
for (int n=0; n<amount; n++)
|
||||
{
|
||||
m_kart_widgets[n].move( fullarea->m_x + splitWidth*n,
|
||||
fullarea->m_y, splitWidth, fullarea->m_h);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void NetworkKartSelectionScreen::playerConfirm(const int playerID)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,6 +11,7 @@ protected:
|
||||
NetworkKartSelectionScreen();
|
||||
virtual ~NetworkKartSelectionScreen();
|
||||
|
||||
virtual void playerConfirm(const int playerID);
|
||||
public:
|
||||
virtual void init() OVERRIDE;
|
||||
virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name,
|
||||
|
Loading…
x
Reference in New Issue
Block a user