~ubuntu-branches/ubuntu/lucid/warzone2100/lucid

« back to all changes in this revision

Viewing changes to src/multiopt.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger, Paul Wise, Christoph Egger
  • Date: 2009-06-29 17:12:52 UTC
  • mfrom: (1.1.11 upstream) (2.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090629171252-5ddnlfg3zfchrega
Tags: 2.2.1+dfsg1-1
[ Paul Wise ]
* New upstream release (Closes: #534962)
* Adjust the flex build-depends to take account of the conflict
  with all the versions of flex 2.5.34 (LP: #372872)
* Make the -music Recommends more strict, 2.1 music doesn't work
  with 2.2.
* Upstream moved the downloads to sourceforge, update the watch file
* Bump Standards-Version, no changes needed
* Drop use of dh_desktop since it no longer does anything
* Recommend the new warzone2100-video package, version 2.2 or similar
* Mention the warzone2100 crash reports in the -dbg package description

[ Christoph Egger ]
* Replace CC-2.0 graphic from cybersphinx, create a new tarball
* Add myself to uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
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
5
5
 
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
66
66
// dpid == 0 for no new players.
67
67
void sendOptions(uint32_t dest, uint32_t play)
68
68
{
69
 
        int i, j;
 
69
        unsigned int i;
70
70
 
71
71
        NETbeginEncode(NET_OPTIONS, NET_ALL_PLAYERS);
72
72
 
112
112
        // Same goes for the alliances
113
113
        for (i = 0; i < MAX_PLAYERS; i++)
114
114
        {
 
115
                unsigned int j;
 
116
 
115
117
                for (j = 0; j < MAX_PLAYERS; j++)
116
118
                {
117
119
                        NETuint8_t(&alliances[i][j]);
167
169
// options for a game. (usually recvd in frontend)
168
170
void recvOptions()
169
171
{
170
 
        int             i, j;
 
172
        unsigned int i;
171
173
        UDWORD  play;
172
174
        UDWORD  newPl;
173
175
 
219
221
        // Alliances
220
222
        for (i = 0; i < MAX_PLAYERS; i++)
221
223
        {
 
224
                unsigned int j;
 
225
 
222
226
                for (j = 0; j < MAX_PLAYERS; j++)
223
227
                {
224
228
                        NETuint8_t(&alliances[i][j]);
302
306
        }
303
307
        else
304
308
        {
305
 
                loadMapPreview();
 
309
                loadMapPreview(false);
306
310
        }
307
311
}
308
312
 
333
337
                setPlayerName(i, ""); //Clear custom names (use default ones instead)
334
338
        }
335
339
 
336
 
 
 
340
//      FIXME: FIX ME!!! **RANDOM** ARGH!
337
341
        pl = rand()%game.maxPlayers;                                            //pick a player
338
342
 
339
343
        player2dpid[pl] = NetPlay.dpidPlayer;                           // add ourselves to the array.
429
433
#endif
430
434
 
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)
434
439
{
435
 
        /*
436
 
         * Send a leaving message, This resolves a problem with tcpip which
437
 
         * occasionally doesn't automatically notice a player leaving
438
 
         */
439
 
        NETbeginEncode(NET_LEAVING, NET_ALL_PLAYERS);
 
440
        debug(LOG_NET, "We are leaving 'nicely'");
 
441
        NETbeginEncode(NET_PLAYER_LEAVING, NET_ALL_PLAYERS);
440
442
        {
441
443
                uint32_t player_id = player2dpid[selectedPlayer];
442
444
                BOOL host = NetPlay.bHost;
546
548
 
547
549
        case SKIRMISH:
548
550
                // create the pc player list in deathmatch set.
 
551
 
 
552
                // Yes, this code really *is* as hacky as it looks.
 
553
                // I'm going to try to narrate what's going on.
 
554
 
 
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);
552
562
 
 
563
                // To reiterate:
 
564
                // Player 5 contains the human player template set.
 
565
                // Player 4 contains the AI player template set.
 
566
 
553
567
                //choose which way to do this.
554
568
                if(isHumanPlayer(CAMPAIGNTEMPLATES))
555
569
                {
 
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.
 
573
 
556
574
                        //pc first
557
575
                        for(player=0;player<game.maxPlayers;player++)
558
576
                        {
572
590
                }
573
591
                else
574
592
                {
 
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
 
598
                        // AI players.
 
599
 
575
600
                        // ensure a copy of pc templates to a pc player.
576
601
                        if(isHumanPlayer(DEATHMATCHTEMPLATES))
577
602
                        {
758
783
{
759
784
        UDWORD                  player;
760
785
        UBYTE           newPlayerArray[MAX_PLAYERS];
761
 
        UDWORD          i,j,lastAI;
762
786
        SDWORD          newPlayerTeam[MAX_PLAYERS] = {-1,-1,-1,-1,-1,-1,-1,-1};
763
787
 
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)
779
803
        {
780
 
                lastAI = 0;             //last used AI slot
 
804
                unsigned int i;
 
805
                unsigned int lastAI = 0; // last used AI slot
 
806
 
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)
783
809
                {
784
810
                        if(game.skDiff[i] < UBYTE_MAX )         //slot with enabled or disabled AI
785
811
                        {
 
812
                                unsigned int player;
 
813
 
786
814
                                //find first unused slot
787
 
                                for(j=lastAI;j<MAX_PLAYERS && isHumanPlayer(j);j++);    //skip humans
788
 
 
789
 
                                ASSERT(j<MAX_PLAYERS,"campInit: couldn't find free slot while assigning AI %d , lastAI=%d", i, lastAI);
790
 
 
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
 
817
                                     ++player);
 
818
 
 
819
                                ASSERT(player < MAX_PLAYERS, "couldn't find free slot while assigning AI %u, lastAI=%u", i, lastAI);
 
820
 
 
821
                                newPlayerArray[player] = game.skDiff[i];                //copy over
 
822
                                newPlayerTeam[player] = playerTeamGUI[i];
793
823
 
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);
797
827
 
798
 
                                lastAI = j;
 
828
                                lastAI = player;
799
829
                                lastAI++;
800
830
                        }
801
831
                        else if(game.skDiff[i] == UBYTE_MAX)    //human player
802
832
                        {
 
833
                                unsigned int player;
 
834
 
803
835
                                //find player net id
804
 
                                for(j=0;(j < MAX_PLAYERS) && (player2dpid[j] != NetPlay.players[i].dpid);j++);
805
 
 
806
 
                                ASSERT(j<MAX_PLAYERS,"campInit: couldn't find player id for GUI id %d", i);
807
 
 
808
 
                                newPlayerTeam[j] = playerTeamGUI[i];
 
836
                                for (player = 0;
 
837
                                     player < MAX_PLAYERS && player2dpid[player] != NetPlay.players[i].dpid;
 
838
                                     ++player);
 
839
 
 
840
                                ASSERT(player < MAX_PLAYERS, "couldn't find player id for GUI id %u", i);
 
841
 
 
842
                                newPlayerTeam[player] = playerTeamGUI[i];
809
843
                        }
810
844
 
811
845
                }
889
923
{
890
924
        PLAYERSTATS     st;
891
925
 
 
926
        debug(LOG_NET,"%s is shutting down.",getPlayerName(selectedPlayer));
 
927
 
892
928
        sendLeavingMsg();                                                       // say goodbye
893
929
        updateMultiStatsGames();                                        // update games played.
894
930