00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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:
00042 int colorID;
00043 int listID;
00044 int score;
00045
00046 int numHumans;
00047 int numAIs;
00048
00049 tList<ePlayerNetID> players;
00050
00051 int maxPlayersLocal;
00052 int maxImbalanceLocal;
00053
00054 unsigned short r,g,b;
00055 tString name;
00056
00057 bool locked_;
00058
00059 static void UpdateStaticFlags();
00060
00061 public:
00062 static int minTeams;
00063 static int maxTeams;
00064 static int maxPlayers;
00065 static int minPlayers;
00066 static int maxImbalance;
00067 static bool balanceWithAIs;
00068 static bool enforceRulesOnQuit;
00069
00070 static tList<eTeam> teams;
00071
00072 void UpdateProperties();
00073 void UpdateAppearance();
00074 void Update();
00075
00076 void SetLocked( bool locked );
00077 bool IsLocked() const;
00078
00079 void Invite( ePlayerNetID * player );
00080 void UnInvite( ePlayerNetID * player );
00081 bool IsInvited( ePlayerNetID const * player ) const;
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:
00088 static void EnforceConstraints();
00089
00090 static void SortByScore();
00091
00092 static void SwapTeamsNo(int a,int b);
00093
00094 static tString Ranking( int MAX = 6, bool cut = true );
00095 static float RankingGraph( float y, int MAX = 6 );
00096
00097 bool NameTeamAfterColor ( bool wish );
00098
00099 void AddPlayer ( ePlayerNetID* player );
00100 void AddPlayerDirty ( ePlayerNetID* player );
00101 void RemovePlayer ( ePlayerNetID* player );
00102 virtual bool PlayerMayJoin ( const ePlayerNetID* player ) const;
00103 static bool NewTeamAllowed ();
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;
00111 }
00112 virtual bool IsHuman() const {
00113 return true;
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
00132 int NumPlayers ( ) const {
00133 return players.Len();
00134 }
00135 ePlayerNetID* Player ( int i ) const {
00136 return players(i);
00137 }
00138
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;
00149 int NumAIPlayers ( ) const;
00150 int AlivePlayers ( ) const;
00151 ePlayerNetID* OldestPlayer ( ) const;
00152 ePlayerNetID* OldestHumanPlayer( ) const;
00153 ePlayerNetID* OldestAIPlayer ( ) const;
00154 ePlayerNetID* YoungestPlayer ( ) const;
00155 ePlayerNetID* YoungestHumanPlayer( ) const;
00156 ePlayerNetID* YoungestAIPlayer( ) const;
00157 bool Alive ( ) const;
00158
00159
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;
00174
00175
00176 virtual bool ClearToTransmit(int user) const;
00177
00178
00179 virtual void WriteSync(nMessage &m);
00180 virtual void ReadSync(nMessage &m);
00181 virtual bool SyncIsNew(nMessage &m);
00182 virtual nDescriptor& CreatorDescriptor() const;
00183
00184
00185 virtual void WriteCreate(nMessage &m);
00186
00187
00188
00189
00190 virtual void ReceiveControlNet(nMessage &m);
00191
00192
00193
00194
00195 virtual bool AcceptClientSync() const {
00196 return false;
00197 }
00198
00199
00200 eTeam();
00201 eTeam(nMessage &m);
00202 ~eTeam();
00203
00204 private:
00205 void RemovePlayerDirty( ePlayerNetID* player );
00206 };
00207
00208 #endif
00209