src/engine/eTeam.h

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #ifndef ArmageTron_TEAM_H
00029 #define ArmageTron_TEAM_H
00030 
00031 #include "ePlayer.h"
00032 #include "nNetObject.h"
00033 #include "tList.h"
00034 #include <vector>
00035 
00036 
00037 template<class T> class nConfItem;
00038 
00039 
00040 class eTeam: public nNetObject{
00041 protected:                                                      // protected attributes
00042     int colorID;                                        // ID of the team predefined color
00043     int listID;                                         // ID in the list of all teams
00044     int score;                                          // score the team has accumulated
00045 
00046     int numHumans;                                      // number of human players on the team
00047     int numAIs;                                         // number of AI players on the team
00048 
00049     tList<ePlayerNetID> players;    // players in this team
00050 
00051     int maxPlayersLocal;                        // maximum number of players allowed in this team
00052     int maxImbalanceLocal;                      // maximum imbalance allowed here
00053 
00054     unsigned short r,g,b;                       // team color
00055     tString     name;                                   // our name
00056 
00057     bool locked_;                   
00058 
00059     static void UpdateStaticFlags();// update all internal information
00060 
00061 public:                                                 // public configuration options
00062     static int  minTeams;                       // minimum nuber of teams
00063     static int  maxTeams;               // maximum nuber of teams
00064     static int  maxPlayers;             // maximum number of players per team
00065     static int  minPlayers;             // maximum number of players per team
00066     static int  maxImbalance;           // maximum difference of player numbers allowed
00067     static bool balanceWithAIs; // use AI players to balance the teams?
00068     static bool enforceRulesOnQuit; // if the quitting of one player unbalances the teams, enforce the rules by redistributing
00069 
00070     static tList<eTeam> teams;          //  list of all teams
00071 
00072     void UpdateProperties();            // update internal properties ( player count )
00073     void UpdateAppearance();            // update name and color
00074     void Update();                                      // update all properties
00075 
00076     void SetLocked( bool locked );  // sets the lock status (whether invitations are required)
00077     bool IsLocked() const;          // returns the lock status
00078 
00079     void Invite( ePlayerNetID * player );                // invite the player to join
00080     void UnInvite( ePlayerNetID * player );              // revoke an invitation
00081     bool IsInvited( ePlayerNetID const * player ) const; // check if a player is invited
00082 
00083     static bool Enemies( eTeam const * team, ePlayerNetID const * player ); 
00084     static bool Enemies( eTeam const * team1, eTeam const * team2 ); 
00085 
00086     static void Enforce( int minTeams, int maxTeams, int maxImbalance );
00087 public:                                                                                         // public methods
00088     static void EnforceConstraints();                                   // make sure the limits on team number and such are met
00089 
00090     static void SortByScore();                                                  // brings the teams into the right order
00091 
00092     static void SwapTeamsNo(int a,int b);               // swaps the teams a and b
00093 
00094     static tString Ranking( int MAX = 6, bool cut = true );                             // return ranking information
00095     static float RankingGraph( float y, int MAX = 6 );                          // print ranking information
00096 
00097     bool                        NameTeamAfterColor ( bool wish );       // inquire or set the ability to use a color as a team name
00098 
00099     void                        AddPlayer       ( ePlayerNetID* player );                               // register a player
00100     void                        AddPlayerDirty  ( ePlayerNetID* player );                               // register a player without calling UpdateProperties
00101     void                        RemovePlayer    ( ePlayerNetID* player );                               // deregister a player
00102     virtual bool        PlayerMayJoin   ( const ePlayerNetID* player ) const;           // see if the given player may join this team
00103     static bool         NewTeamAllowed  ();                                                                                     // is it allowed to create a new team?
00104 
00105     static void     SwapPlayers     ( ePlayerNetID* player1, ePlayerNetID *player2 ); 
00106 
00107     void            Shuffle         ( int startID, int stopID ); 
00108 
00109     virtual bool BalanceThisTeam() const {
00110         return true;    // care about this team when balancing teams
00111     }
00112     virtual bool IsHuman() const {
00113         return true;    // does this team consist of humans?
00114     }
00115 
00116     int                         TeamID                  ( void  ) const {
00117         return listID;
00118     }
00119 
00120     int                         Score                   (               ) const {
00121         return score;
00122     }
00123     void                        AddScore                ( int s );
00124     void                        ResetScore              (               );
00125     void                        SetScore                ( int s );
00126 
00127     void                        AddScore                ( int points,
00128                         const tOutput& reasonwin,
00129                         const tOutput& reasonlose );
00130 
00131     // player inquiry
00132     int                         NumPlayers              (               ) const {
00133         return players.Len();    // total number of players
00134     }
00135     ePlayerNetID*       Player                  ( int i ) const {
00136         return players(i);         // player of index i
00137     }
00138     // Export a list of pointers to all the players in this team
00139     std::vector < ePlayerNetID * >      GetAllMembers () const {
00140         std::vector <ePlayerNetID *> tmp;
00141         for (int i=0; i<players.Len(); i++) {
00142             tmp.push_back( players(i) );
00143         }
00144         return tmp;
00145     }
00146 
00147 
00148     int                         NumHumanPlayers (               ) const;                                                        // number of human players
00149     int                         NumAIPlayers    (               ) const;                                                        // number of human players
00150     int                         AlivePlayers    (               ) const;                                                        // how many of the current players are currently alive?
00151     ePlayerNetID*       OldestPlayer    (               ) const;                                                        // the oldest player
00152     ePlayerNetID*       OldestHumanPlayer(              ) const;                                                        // the oldest human player
00153     ePlayerNetID*       OldestAIPlayer  (               ) const;                                                        // the oldest AI player
00154     ePlayerNetID*       YoungestPlayer  (               ) const;                                                        // the youngest player
00155     ePlayerNetID*       YoungestHumanPlayer(    ) const;                                                        // the youngest human player
00156     ePlayerNetID*       YoungestAIPlayer(               ) const;                                                        // the youngest AI player
00157     bool                        Alive                   (               ) const;                                                        // is any of the players currently alive?
00158 
00159     // name and color
00160     unsigned short      R()     const {
00161         return r;
00162     }
00163     unsigned short      G()     const {
00164         return g;
00165     }
00166     unsigned short      B()     const {
00167         return b;
00168     }
00169     const tString&      Name()  const {
00170         return name;
00171     }
00172 
00173     virtual void PrintName(tString &s) const;                                   // print out an understandable name in to s
00174 
00175 
00176     virtual bool ClearToTransmit(int user) const;               // we must not transmit an object that contains pointers to non-transmitted objects. this function is supposed to check that.
00177 
00178     // syncronisation functions:
00179     virtual void WriteSync(nMessage &m);                                // store sync message in m
00180     virtual void ReadSync(nMessage &m);                                 // guess what
00181     virtual bool SyncIsNew(nMessage &m);                                // is the message newer than the last accepted sync
00182     virtual nDescriptor&        CreatorDescriptor() const;
00183 
00184     // the extra information sent on creation:
00185     virtual void WriteCreate(nMessage &m); // store sync message in m
00186     // the information written by this function should
00187     // be read from the message in the "message"- connstructor
00188 
00189     // control functions:
00190     virtual void ReceiveControlNet(nMessage &m);
00191     // receives the control message. the data written to the message created
00192     // by *NewControlMessage() can be read directly from m.
00193 
00194     // shall the server accept sync messages from the clients?
00195     virtual bool AcceptClientSync() const       {
00196         return false;
00197     }
00198 
00199     // con/desstruction
00200     eTeam();                                                                                    // default constructor
00201     eTeam(nMessage &m);                                                                 // remote constructor
00202     ~eTeam();                                                                                   // destructor
00203 
00204 private:
00205     void                        RemovePlayerDirty( ePlayerNetID* player );                              // just remove a player from the player list, no messages, no balancing
00206 };
00207 
00208 #endif
00209 

Generated on Sat Mar 15 22:55:47 2008 for Armagetron Advanced by  doxygen 1.5.4