2
2
This file is part of Warzone 2100.
3
3
Copyright (C) 1999-2004 Eidos Interactive
4
Copyright (C) 2005-2007 Warzone Resurrection Project
4
Copyright (C) 2005-2009 Warzone Resurrection Project
6
6
Warzone 2100 is free software; you can redistribute it and/or modify
7
7
it under the terms of the GNU General Public License as published by
333
337
setPlayerName(i, ""); //Clear custom names (use default ones instead)
340
// FIXME: FIX ME!!! **RANDOM** ARGH!
337
341
pl = rand()%game.maxPlayers; //pick a player
339
343
player2dpid[pl] = NetPlay.dpidPlayer; // add ourselves to the array.
431
435
// ////////////////////////////////////////////////////////////////////////////
432
// say goodbye to everyone else
436
// Broadcast that we are leaving the game 'nicely', (we wanted to) and not
437
// because we have some kind of error. (dropped or disconnected)
433
438
BOOL sendLeavingMsg(void)
436
* Send a leaving message, This resolves a problem with tcpip which
437
* occasionally doesn't automatically notice a player leaving
439
NETbeginEncode(NET_LEAVING, NET_ALL_PLAYERS);
440
debug(LOG_NET, "We are leaving 'nicely'");
441
NETbeginEncode(NET_PLAYER_LEAVING, NET_ALL_PLAYERS);
441
443
uint32_t player_id = player2dpid[selectedPlayer];
442
444
BOOL host = NetPlay.bHost;
548
550
// create the pc player list in deathmatch set.
552
// Yes, this code really *is* as hacky as it looks.
553
// I'm going to try to narrate what's going on.
555
// Player 5 currently contains the human player template set.
556
// (i.e. Nothing but a truck)
557
// Templates from players 5, 2, and 6 are added to player 4.
558
// This puts the AI template set in player 4.
549
559
addTemplateSet(CAMPAIGNTEMPLATES,DEATHMATCHTEMPLATES);
550
560
addTemplateSet(6,DEATHMATCHTEMPLATES);
551
561
addTemplateSet(2,DEATHMATCHTEMPLATES);
564
// Player 5 contains the human player template set.
565
// Player 4 contains the AI player template set.
553
567
//choose which way to do this.
554
568
if(isHumanPlayer(CAMPAIGNTEMPLATES))
570
// Player 5 is a human. No workarounds are needed.
571
// We just copy player 4's templates onto all the AI's,
572
// then copy player 5's template onto all the humans.
557
575
for(player=0;player<game.maxPlayers;player++)
593
// Player 5 is an AI player. This is a really bad workaround.
594
// We find an AI player: pcPlayer.
595
// We copy player 4's templates onto pcPlayer.
596
// Then, we copy player 5's templates onto all the
597
// human players, and pcPlayer's templates onto all the
575
600
// ensure a copy of pc templates to a pc player.
576
601
if(isHumanPlayer(DEATHMATCHTEMPLATES))
760
785
UBYTE newPlayerArray[MAX_PLAYERS];
762
786
SDWORD newPlayerTeam[MAX_PLAYERS] = {-1,-1,-1,-1,-1,-1,-1,-1};
764
788
// if this is from a savegame, stop here!
777
801
//Convert skirmish GUI player ids to in-game ids
778
802
if(game.type == SKIRMISH)
780
lastAI = 0; //last used AI slot
805
unsigned int lastAI = 0; // last used AI slot
781
807
memset(newPlayerArray,1,MAX_PLAYERS * sizeof(newPlayerArray[0])); //'1' for humans
782
for(i=0;i<MAX_PLAYERS;i++)
808
for(i = 0; i < MAX_PLAYERS; ++i)
784
810
if(game.skDiff[i] < UBYTE_MAX ) //slot with enabled or disabled AI
786
814
//find first unused slot
787
for(j=lastAI;j<MAX_PLAYERS && isHumanPlayer(j);j++); //skip humans
789
ASSERT(j<MAX_PLAYERS,"campInit: couldn't find free slot while assigning AI %d , lastAI=%d", i, lastAI);
791
newPlayerArray[j] = game.skDiff[i]; //copy over
792
newPlayerTeam[j] = playerTeamGUI[i];
815
for (player = lastAI;
816
player < MAX_PLAYERS && isHumanPlayer(player); // skip humans
819
ASSERT(player < MAX_PLAYERS, "couldn't find free slot while assigning AI %u, lastAI=%u", i, lastAI);
821
newPlayerArray[player] = game.skDiff[i]; //copy over
822
newPlayerTeam[player] = playerTeamGUI[i];
794
824
//remove player if it was disabled in menus
795
825
if(game.skDiff[i] == 0)
796
clearPlayer(j,true,false);
826
clearPlayer(player,true,false);
801
831
else if(game.skDiff[i] == UBYTE_MAX) //human player
803
835
//find player net id
804
for(j=0;(j < MAX_PLAYERS) && (player2dpid[j] != NetPlay.players[i].dpid);j++);
806
ASSERT(j<MAX_PLAYERS,"campInit: couldn't find player id for GUI id %d", i);
808
newPlayerTeam[j] = playerTeamGUI[i];
837
player < MAX_PLAYERS && player2dpid[player] != NetPlay.players[i].dpid;
840
ASSERT(player < MAX_PLAYERS, "couldn't find player id for GUI id %u", i);
842
newPlayerTeam[player] = playerTeamGUI[i];