Skip to content

Commit

Permalink
Fix ticket:3049 "Can start Multiplayer game without any Opponents"
Browse files Browse the repository at this point in the history
  • Loading branch information
perim committed Jan 21, 2012
1 parent f3f5ddf commit 4d92126
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions src/multiint.cpp
Expand Up @@ -2081,16 +2081,41 @@ bool recvPositionRequest(NETQUEUE queue)
return changePosition(player, position);
}

#define ANYENTRY 0xFF // used to allow any team slot to be used.
// if so, return that team; if not, return -1
int allPlayersOnSameTeam(int except)
{
int inSlot[MAX_PLAYERS] = {0};

int i, disallow = -1, filledSlots = 0;
// Count actual players
for (i = 0; i < game.maxPlayers; i++)
{
filledSlots += (NetPlay.players[i].ai >= 0) ? 1 : 0;
}
// tally up the team counts
for (i = 0; i < game.maxPlayers; i++)
{
if (i != except)
{
inSlot[NetPlay.players[i].team]++;
if (inSlot[NetPlay.players[i].team] >= filledSlots - (except >= 0) ? 1 : 0)
{
// Make sure all players can't be on same team.
disallow = NetPlay.players[i].team;
}
}
}
return disallow;
}

/*
* Opens a menu for a player to choose a team
* 'player' is a player id of the player who will get a new team assigned
*/
static void addTeamChooser(UDWORD player)
{
UDWORD i;
int disallow = ANYENTRY;
SDWORD inSlot[MAX_PLAYERS] = {0};
int disallow = allPlayersOnSameTeam(player);

debug(LOG_NET, "Opened team chooser for %d, current team: %d", player, NetPlay.players[player].team);

Expand All @@ -2099,20 +2124,6 @@ static void addTeamChooser(UDWORD player)
// add form.
addBlueForm(MULTIOP_PLAYERS, MULTIOP_TEAMCHOOSER_FORM, "", 7, playerBoxHeight(player), MULTIOP_ROW_WIDTH, MULTIOP_TEAMSHEIGHT);

// tally up the team counts
for (i=0; i< game.maxPlayers ; i++)
{
if (i != player)
{
inSlot[NetPlay.players[i].team]++;
if (inSlot[NetPlay.players[i].team] >= game.maxPlayers - 1)
{
// Make sure all players can't be on same team.
disallow = NetPlay.players[i].team;
}
}
}

int teamW = iV_GetImageWidth(FrontImages, IMAGE_TEAM0);
int teamH = iV_GetImageHeight(FrontImages, IMAGE_TEAM0);
int space = MULTIOP_ROW_WIDTH - 7 - teamW*(game.maxPlayers + 1);
Expand Down Expand Up @@ -2152,6 +2163,8 @@ static void closeTeamChooser(void)

static void drawReadyButton(UDWORD player)
{
int disallow = allPlayersOnSameTeam(-1);

// delete 'ready' botton form
widgDelete(psWScreen, MULTIOP_READY_FORM_ID + player);

Expand All @@ -2173,6 +2186,11 @@ static void drawReadyButton(UDWORD player)
return; // closed or open
}

if (disallow != -1)
{
return;
}

// draw 'ready' button
if (NetPlay.players[player].ready)
{
Expand Down

0 comments on commit 4d92126

Please sign in to comment.