~luke-jr/tr2norigins/armagetron-0.2.8-t2o-accesslvls

« back to all changes in this revision

Viewing changes to src/engine/eTeam.h

  • Committer: luke-jr
  • Date: 2006-05-29 01:55:42 UTC
  • Revision ID: svn-v3-list-QlpoOTFBWSZTWZvbKhsAAAdRgAAQABK6798QIABURMgAAaeoNT1TxT1DQbKaeobXKiyAmlWT7Y5MkdJOtXDtB7w7DOGFBHiOBxaUIu7HQyyQSvxdyRThQkJvbKhs:7d95bf1e-0414-0410-9756-b78462a59f44:armagetronad%2Fbranches%2F0.2.8%2Farmagetronad:4612
Unify tags/branches of modules released together

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
*************************************************************************
 
4
 
 
5
ArmageTron -- Just another Tron Lightcycle Game in 3D.
 
6
Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
 
7
 
 
8
**************************************************************************
 
9
 
 
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.
 
14
 
 
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.
 
19
 
 
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.
 
23
  
 
24
***************************************************************************
 
25
 
 
26
*/
 
27
 
 
28
#ifndef ArmageTron_TEAM_H
 
29
#define ArmageTron_TEAM_H
 
30
 
 
31
#include "ePlayer.h"
 
32
#include "nNetObject.h"
 
33
#include "tList.h"
 
34
 
 
35
 
 
36
template<class T> class nConfItem;
 
37
 
 
38
 
 
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
 
44
 
 
45
    int numHumans;                                      // number of human players on the team
 
46
    int numAIs;                                         // number of AI players on the team
 
47
 
 
48
    tList<ePlayerNetID> players;    // players in this team
 
49
 
 
50
    int maxPlayersLocal;                        // maximum number of players allowed in this team
 
51
    int maxImbalanceLocal;                      // maximum imbalance allowed here
 
52
 
 
53
    unsigned short r,g,b;                       // team color
 
54
    tString     name;                                   // our name
 
55
 
 
56
    static void UpdateStaticFlags();// update all internal information
 
57
 
 
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
 
66
 
 
67
    static tList<eTeam> teams;          //  list of all teams
 
68
 
 
69
    void UpdateProperties();            // update internal properties ( player count )
 
70
    void UpdateAppearance();            // update name and color
 
71
    void Update();                                      // update all properties
 
72
 
 
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
 
75
 
 
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
 
79
 
 
80
    static void SortByScore();                                                  // brings the teams into the right order
 
81
 
 
82
    static void SwapTeamsNo(int a,int b);               // swaps the teams a and b
 
83
 
 
84
    static tString Ranking( int MAX = 6, bool cut = true );                             // return ranking information
 
85
 
 
86
    bool                        NameTeamAfterColor ( bool wish );       // inquire or set the ability to use a color as a team name
 
87
 
 
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?
 
93
 
 
94
    static void     SwapPlayers     ( ePlayerNetID* player1, ePlayerNetID *player2 ); //!< swaps the team positions of the two players (same team or not)
 
95
 
 
96
    void            Shuffle         ( int startID, int stopID ); //!< shuffles the player at team postion startID to stopID
 
97
 
 
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?
 
100
 
 
101
    int                         TeamID                  ( void  ) const { return listID; }
 
102
 
 
103
    int                         Score                   (               ) const { return score; }
 
104
    void                        AddScore                ( int s );
 
105
    void                        ResetScore              (               );
 
106
    void                        SetScore                ( int s );
 
107
 
 
108
    void                        AddScore                ( int points,
 
109
                        const tOutput& reasonwin,
 
110
                        const tOutput& reasonlose );
 
111
 
 
112
    // player inquiry
 
113
    int                         NumPlayers              (               ) const { return players.Len(); }       // total number of players
 
114
    ePlayerNetID*       Player                  ( int i ) const { return players(i);    }       // player of index i
 
115
 
 
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?
 
125
 
 
126
    // name and color
 
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; }
 
131
 
 
132
    virtual void PrintName(tString &s) const;                                   // print out an understandable name in to s
 
133
 
 
134
 
 
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.
 
136
 
 
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;
 
142
 
 
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
 
147
 
 
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.
 
152
 
 
153
    // shall the server accept sync messages from the clients?
 
154
    virtual bool AcceptClientSync() const       { return false; }
 
155
 
 
156
    // con/desstruction
 
157
    eTeam();                                                                                    // default constructor
 
158
    eTeam(nMessage &m);                                                                 // remote constructor
 
159
    ~eTeam();                                                                                   // destructor
 
160
 
 
161
private:
 
162
    void                        RemovePlayerDirty( ePlayerNetID* player );                              // just remove a player from the player list, no messages, no balancing
 
163
};
 
164
 
 
165
#endif
 
166