From a72cb7295a9fdbb8202d6d1d6ec5612fe8c87a62 Mon Sep 17 00:00:00 2001 From: Buginator Date: Thu, 26 Nov 2009 18:33:03 +0000 Subject: [PATCH] Transmit and set local color array. Fixes picking of team color bug. Transmit player map position & handle picking of players correctly. fixes ticket:1075 Enable/disable AIs on maps. fixes ticket:1065 (r8410) git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@8524 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/netplay/netplay.c | 4 ++ src/multiint.c | 95 +++++++++++++++++++++++++++++++++++++++---- src/multiopt.c | 7 +++- src/multiplay.c | 1 + 4 files changed, 99 insertions(+), 8 deletions(-) diff --git a/lib/netplay/netplay.c b/lib/netplay/netplay.c index 455bf67e1..4f3e0525a 100644 --- a/lib/netplay/netplay.c +++ b/lib/netplay/netplay.c @@ -1416,6 +1416,7 @@ void NETBroadcastPlayerInfo(uint32_t index) NETstring(NetPlay.players[index].name, sizeof(NetPlay.players[index].name)); NETuint32_t(&NetPlay.players[index].heartattacktime); NETint32_t(&NetPlay.players[index].colour); + NETint32_t(&NetPlay.players[index].position); NETint32_t(&NetPlay.players[index].team); NETbool(&NetPlay.players[index].ready); NETuint32_t(&NetPlay.hostPlayer); @@ -2304,11 +2305,14 @@ static BOOL NETprocessSystemMessage(void) NETstring(NetPlay.players[index].name, sizeof(NetPlay.players[index].name)); NETuint32_t(&NetPlay.players[index].heartattacktime); NETint32_t(&NetPlay.players[index].colour); + NETint32_t(&NetPlay.players[index].position); NETint32_t(&NetPlay.players[index].team); NETbool(&NetPlay.players[index].ready); NETuint32_t(&NetPlay.hostPlayer); NETend(); debug(LOG_NET, "Receiving MSG_PLAYER_INFO for player %u (%s)", (unsigned int)index, NetPlay.players[index].allocated ? "human" : "AI"); + // update the color to the local array + setPlayerColour(index, NetPlay.players[index].colour); // If we're the game host make sure to send the updated // data to all other clients as well. diff --git a/src/multiint.c b/src/multiint.c index 8827e989d..1df41d24b 100644 --- a/src/multiint.c +++ b/src/multiint.c @@ -1464,7 +1464,7 @@ static void addColourChooser(UDWORD player) iV_GetImageHeight(FrontImages,IMAGE_WEE_GUY), //h "Player number", IMAGE_WEE_GUY, IMAGE_WEE_GUY, 10 + i); - if(isHumanPlayer(i) && i!=selectedPlayer) + if(isHumanPlayer(NetPlay.players[i].position) && i!=selectedPlayer ) { widgSetButtonState(psWScreen,MULTIOP_PLAYCHOOSER+i ,WBUT_DISABLE); } @@ -1611,12 +1611,14 @@ static BOOL changeColour(UBYTE player, UBYTE col) for (i = 0; i < MAX_PLAYERS; i++) { - if (NetPlay.players[i].colour == col) + if (getPlayerColour(i) == col) { debug(LOG_NET, "Swapping colours between players %d(%d) and %d(%d)", player, getPlayerColour(player), i, getPlayerColour(i)); setPlayerColour(i, getPlayerColour(player)); + NetPlay.players[i].colour = getPlayerColour(player); setPlayerColour(player, col); + NetPlay.players[player].colour = col; NETBroadcastPlayerInfo(player); NETBroadcastPlayerInfo(i); return true; @@ -1651,6 +1653,7 @@ static BOOL SendPositionRequest(UBYTE player, UBYTE position) } else { + debug(LOG_NET, "Requesting the host to change our position. From %d to %d", player, position); // clients tell the host which position they want NETbeginEncode(NET_POSITIONREQUEST, NET_HOST_ONLY); NETuint8_t(&player); @@ -1695,14 +1698,14 @@ BOOL recvPositionRequest() return true; } - NETbeginDecode(NET_COLOURREQUEST); + NETbeginDecode(NET_POSITIONREQUEST); NETuint8_t(&player); NETuint8_t(&position); NETend(); - + debug(LOG_NET, "Host received position request from player %d to %d", player, position); if (player > MAX_PLAYERS || position > MAX_PLAYERS) { - debug(LOG_ERROR, "Invalid NET_COLOURREQUEST from player %d: Tried to change player %d to %d", + debug(LOG_ERROR, "Invalid NET_POSITIONREQUEST from player %d: Tried to change player %d to %d", NETgetSource(), (int)player, (int)position); return false; } @@ -1954,8 +1957,13 @@ UDWORD addPlayerBox(BOOL players) sFormInit.pDisplay = displayPlayer; sFormInit.UserData = i; widgAddForm(psWScreen, &sFormInit); - addFESlider(MULTIOP_SKSLIDE+i,sFormInit.id, 43,9, DIFF_SLIDER_STOPS, +#ifdef DEBUG + addFESlider(MULTIOP_SKSLIDE+i,sFormInit.id, 63,9, DIFF_SLIDER_STOPS, (game.skDiff[i] <= DIFF_SLIDER_STOPS ? game.skDiff[i] : DIFF_SLIDER_STOPS / 2)); //set to 50% (value of UBYTE_MAX == human player) +#else + addFESlider(MULTIOP_SKSLIDE+i,sFormInit.id, 43,9, DIFF_SLIDER_STOPS, + (game.skDiff[i] <= DIFF_SLIDER_STOPS ? game.skDiff[i] : DIFF_SLIDER_STOPS / 2)); +#endif } } } @@ -2720,6 +2728,10 @@ void frontendMultiMessages(void) recvColourRequest(); break; + case NET_POSITIONREQUEST: + recvPositionRequest(); + break; + case NET_TEAMREQUEST: recvTeamRequest(); break; @@ -3021,7 +3033,8 @@ BOOL startMultiOptions(BOOL bReenter) teamChooserUp = -1; for(i=0;iwidth,psWidget->height); // right +#endif } } diff --git a/src/multiopt.c b/src/multiopt.c index c80d18bd4..e8803021a 100644 --- a/src/multiopt.c +++ b/src/multiopt.c @@ -676,11 +676,16 @@ static BOOL campInit(void) // Remove baba player for skirmish if (!game.scavengers) { - for (player = game.maxPlayers; player < MAX_PLAYERS; player++) + for (player = 1; player < MAX_PLAYERS; player++) { + // we want to remove disabled AI & all the other players that don't belong + if (game.skDiff[player] == 0 || player >= game.maxPlayers) + { clearPlayer(player, true, false); + debug(LOG_NET, "removing disabled AI (%d) from map.", player); } } + } if (NetPlay.isHost) // add oil drums { diff --git a/src/multiplay.c b/src/multiplay.c index ea8de574e..a50d087a0 100644 --- a/src/multiplay.c +++ b/src/multiplay.c @@ -731,6 +731,7 @@ BOOL recvMessage(void) ingame.JoiningInProgress[player_id] = false; break; } + // FIXME: the next 4 cases might not belong here --check (we got two loops for this) case NET_COLOURREQUEST: recvColourRequest(); break;