From debdca6df66bc3970fc1c915db0dfdda40959e8c Mon Sep 17 00:00:00 2001 From: auria Date: Mon, 8 Nov 2010 02:03:30 +0000 Subject: [PATCH] Allow duplicate karts when there are too many players for the amount of karts in the current group + fix bug in random kart selection git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6433 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/states_screens/kart_selection.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index ce040c839..cee0cdd56 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -1204,6 +1204,8 @@ void KartSelectionScreen::onUpdate(float delta, irr::video::IVideoDriver*) } } +// ----------------------------------------------------------------------------- + void KartSelectionScreen::playerConfirm(const int playerID) { DynamicRibbonWidget* w = getWidget("karts"); @@ -1220,19 +1222,25 @@ void KartSelectionScreen::playerConfirm(const int playerID) UserConfigParams::m_default_kart = selection; } - // make sure no other player selected the same identity or kart const int amount = m_kart_widgets.size(); + + // Check if we have enough karts for everybody. If there are more players than + // karts then just allow duplicates + const int availableKartCount = w->getItems().size(); + const bool willNeedDuplicates = (amount > availableKartCount); + + // make sure no other player selected the same identity or kart for (int n=0; ngetProfile()->isGuestAccount() && - m_kart_widgets[n].getAssociatedPlayer()->getProfile() == - m_kart_widgets[playerID].getAssociatedPlayer()->getProfile(); + m_kart_widgets[n].getAssociatedPlayer()->getProfile() == + m_kart_widgets[playerID].getAssociatedPlayer()->getProfile(); const bool kart_conflict = sameKart(m_kart_widgets[n], m_kart_widgets[playerID]); - if (player_ready && (ident_conflict || kart_conflict)) + if (player_ready && (ident_conflict || kart_conflict) && !willNeedDuplicates) { printf("\n***\n*** You can't select this identity or kart, someone already took it!! ***\n***\n\n"); @@ -1437,7 +1445,7 @@ void KartSelectionScreen::allPlayersDone() // mark the item as taken for (int i=0; iunsetBadge(BAD_BADGE); } + // Check if we have enough karts for everybody. If there are more players than + // karts then just allow duplicates + DynamicRibbonWidget* w = getWidget("karts"); + assert( w != NULL ); + const int availableKartCount = w->getItems().size(); + if (amount > availableKartCount) return true; + + // Check everyone for duplicates for (int n=0; n