3
*************************************************************************
5
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
Copyright (C) 2000 Manuel Moos (manuel@moosnet.de)
8
**************************************************************************
10
This program is free software; you can redistribute it and/or
11
modify it under the terms of the GNU General Public License
12
as published by the Free Software Foundation; either version 2
13
of the License, or (at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
***************************************************************************
28
#ifndef ArmageTron_TEAM_H
29
#define ArmageTron_TEAM_H
32
#include "nNetObject.h"
36
template<class T> class nConfItem;
39
class eTeam: public nNetObject{
40
protected: // protected attributes
41
int colorID; // ID of the team predefined color
42
int listID; // ID in the list of all teams
43
int score; // score the team has accumulated
45
int numHumans; // number of human players on the team
46
int numAIs; // number of AI players on the team
48
tList<ePlayerNetID> players; // players in this team
50
int maxPlayersLocal; // maximum number of players allowed in this team
51
int maxImbalanceLocal; // maximum imbalance allowed here
53
unsigned short r,g,b; // team color
54
tString name; // our name
56
static void UpdateStaticFlags();// update all internal information
58
public: // public configuration options
59
static int minTeams; // minimum nuber of teams
60
static int maxTeams; // maximum nuber of teams
61
static int maxPlayers; // maximum number of players per team
62
static int minPlayers; // maximum number of players per team
63
static int maxImbalance; // maximum difference of player numbers allowed
64
static bool balanceWithAIs; // use AI players to balance the teams?
65
static bool enforceRulesOnQuit; // if the quitting of one player unbalances the teams, enforce the rules by redistributing
67
static tList<eTeam> teams; // list of all teams
69
void UpdateProperties(); // update internal properties ( player count )
70
void UpdateAppearance(); // update name and color
71
void Update(); // update all properties
73
static bool Enemies( eTeam const * team, ePlayerNetID const * player ); //!< determines whether the player is an enemy of the team
74
static bool Enemies( eTeam const * team1, eTeam const * team2 ); //!< determines whether two teams are enemies
76
static void Enforce( int minTeams, int maxTeams, int maxImbalance );
77
public: // public methods
78
static void EnforceConstraints(); // make sure the limits on team number and such are met
80
static void SortByScore(); // brings the teams into the right order
82
static void SwapTeamsNo(int a,int b); // swaps the teams a and b
84
static tString Ranking( int MAX = 6, bool cut = true ); // return ranking information
86
bool NameTeamAfterColor ( bool wish ); // inquire or set the ability to use a color as a team name
88
void AddPlayer ( ePlayerNetID* player ); // register a player
89
void AddPlayerDirty ( ePlayerNetID* player ); // register a player without calling UpdateProperties
90
void RemovePlayer ( ePlayerNetID* player ); // deregister a player
91
virtual bool PlayerMayJoin ( const ePlayerNetID* player ) const; // see if the given player may join this team
92
static bool NewTeamAllowed (); // is it allowed to create a new team?
94
static void SwapPlayers ( ePlayerNetID* player1, ePlayerNetID *player2 ); //!< swaps the team positions of the two players (same team or not)
96
void Shuffle ( int startID, int stopID ); //!< shuffles the player at team postion startID to stopID
98
virtual bool BalanceThisTeam() const { return true; } // care about this team when balancing teams
99
virtual bool IsHuman() const { return true; } // does this team consist of humans?
101
int TeamID ( void ) const { return listID; }
103
int Score ( ) const { return score; }
104
void AddScore ( int s );
106
void SetScore ( int s );
108
void AddScore ( int points,
109
const tOutput& reasonwin,
110
const tOutput& reasonlose );
113
int NumPlayers ( ) const { return players.Len(); } // total number of players
114
ePlayerNetID* Player ( int i ) const { return players(i); } // player of index i
116
int NumHumanPlayers ( ) const; // number of human players
117
int NumAIPlayers ( ) const; // number of human players
118
ePlayerNetID* OldestPlayer ( ) const; // the oldest player
119
ePlayerNetID* OldestHumanPlayer( ) const; // the oldest human player
120
ePlayerNetID* OldestAIPlayer ( ) const; // the oldest AI player
121
ePlayerNetID* YoungestPlayer ( ) const; // the youngest player
122
ePlayerNetID* YoungestHumanPlayer( ) const; // the youngest human player
123
ePlayerNetID* YoungestAIPlayer( ) const; // the youngest AI player
124
bool Alive ( ) const; // is any of the players currently alive?
127
unsigned short R() const { return r; }
128
unsigned short G() const { return g; }
129
unsigned short B() const { return b; }
130
const tString& Name() const { return name; }
132
virtual void PrintName(tString &s) const; // print out an understandable name in to s
135
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.
137
// syncronisation functions:
138
virtual void WriteSync(nMessage &m); // store sync message in m
139
virtual void ReadSync(nMessage &m); // guess what
140
virtual bool SyncIsNew(nMessage &m); // is the message newer than the last accepted sync
141
virtual nDescriptor& CreatorDescriptor() const;
143
// the extra information sent on creation:
144
virtual void WriteCreate(nMessage &m); // store sync message in m
145
// the information written by this function should
146
// be read from the message in the "message"- connstructor
148
// control functions:
149
virtual void ReceiveControlNet(nMessage &m);
150
// receives the control message. the data written to the message created
151
// by *NewControlMessage() can be read directly from m.
153
// shall the server accept sync messages from the clients?
154
virtual bool AcceptClientSync() const { return false; }
157
eTeam(); // default constructor
158
eTeam(nMessage &m); // remote constructor
159
~eTeam(); // destructor
162
void RemovePlayerDirty( ePlayerNetID* player ); // just remove a player from the player list, no messages, no balancing