2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #ifndef __MULTIPLAYERGAME_H__
30 #define __MULTIPLAYERGAME_H__
33 ===============================================================================
35 Basic DOOM multiplayer
37 ===============================================================================
54 PLAYER_VOTE_WAIT // mark a player allowed to vote
57 typedef struct mpPlayerState_s {
58 int ping; // player ping
59 int fragCount; // kills
60 int teamFragCount; // team kills
62 playerVote_t vote; // player's vote
63 bool scoreBoardUp; // toggle based on player scoreboard button, used to activate de-activate the scoreboard gui
67 const int NUM_CHAT_NOTIFY = 5;
68 const int CHAT_FADE_TIME = 400;
69 const int FRAGLIMIT_DELAY = 2000;
71 const int MP_PLAYER_MINFRAGS = -100;
72 const int MP_PLAYER_MAXFRAGS = 100;
73 const int MP_PLAYER_MAXWINS = 100;
74 const int MP_PLAYER_MAXPING = 999;
76 typedef struct mpChatLine_s {
78 short fade; // starts high and decreases, line is removed once reached 0
95 class idMultiplayerGame {
100 void Shutdown( void );
102 // resets everything and prepares for a match
105 // setup local data for a new player
106 void SpawnPlayer( int clientNum );
108 // checks rules and updates state of the mp game
111 // draws mp hud, scoredboard, etc..
112 bool Draw( int clientNum );
114 // updates a player vote
115 void PlayerVote( int clientNum, playerVote_t vote );
117 // updates frag counts and potentially ends the match in sudden death
118 void PlayerDeath( idPlayer *dead, idPlayer *killer, bool telefrag );
120 void AddChatLine( const char *fmt, ... ) id_attribute((format(printf,2,3)));
122 void UpdateMainGui( void );
123 idUserInterface*StartMenu( void );
124 const char* HandleGuiCommands( const char *menuCommand );
125 void SetMenuSkin( void );
127 void WriteToSnapshot( idBitMsgDelta &msg ) const;
128 void ReadFromSnapshot( const idBitMsgDelta &msg );
132 INACTIVE = 0, // not running
133 WARMUP, // warming up
134 COUNTDOWN, // post warmup pre-game
135 GAMEON, // game is on
136 SUDDENDEATH, // game is on but in sudden death, first frag wins
137 GAMEREVIEW, // game is over, scoreboard is up. we wait si_gameReviewPause seconds (which has a min value)
141 static const char *GameStateStrings[ STATE_COUNT ];
142 idMultiplayerGame::gameState_t GetGameState( void ) const;
144 static const char *GlobalSoundStrings[ SND_COUNT ];
145 void PlayGlobalSound( int to, snd_evt_t evt, const char *shader = NULL );
147 // more compact than a chat line
166 void PrintMessageEvent( int to, msg_evt_t evt, int parm1 = -1, int parm2 = -1 );
168 void DisconnectClient( int clientNum );
169 static void ForceReady_f( const idCmdArgs &args );
170 static void DropWeapon_f( const idCmdArgs &args );
171 static void MessageMode_f( const idCmdArgs &args );
172 static void VoiceChat_f( const idCmdArgs &args );
173 static void VoiceChatTeam_f( const idCmdArgs &args );
191 VOTE_PASSED, // passed, but no reset yet
193 VOTE_RESET // tell clients to reset vote state
196 static void Vote_f( const idCmdArgs &args );
197 static void CallVote_f( const idCmdArgs &args );
198 void ClientCallVote( vote_flags_t voteIndex, const char *voteValue );
199 void ServerCallVote( int clientNum, const idBitMsg &msg );
200 void ClientStartVote( int clientNum, const char *voteString );
201 void ServerStartVote( int clientNum, vote_flags_t voteIndex, const char *voteValue );
202 void ClientUpdateVote( vote_result_t result, int yesCount, int noCount );
203 void CastVote( int clientNum, bool vote );
204 void ExecuteVote( void );
206 void WantKilled( int clientNum );
207 int NumActualClients( bool countSpectators, int *teamcount = NULL );
208 void DropWeapon( int clientNum );
209 void MapRestart( void );
210 // called by idPlayer whenever it detects a team change (init or switch)
211 void SwitchToTeam( int clientNum, int oldteam, int newteam );
212 bool IsPureReady( void ) const;
213 void ProcessChatMessage( int clientNum, bool team, const char *name, const char *text, const char *sound );
214 void ProcessVoiceChat( int clientNum, bool team, int index );
216 void Precache( void );
218 // throttle UI switch rates
219 void ThrottleUserInfo( void );
220 void ToggleSpectate( void );
221 void ToggleReady( void );
222 void ToggleTeam( void );
224 void ClearFrags( int clientNum );
226 void EnterGame( int clientNum );
227 bool CanPlay( idPlayer *p );
228 bool IsInGame( int clientNum );
229 bool WantRespawn( idPlayer *p );
231 void ServerWriteInitialReliableMessages( int clientNum );
232 void ClientReadStartState( const idBitMsg &msg );
233 void ClientReadWarmupTime( const idBitMsg &msg );
235 void ServerClientConnect( int clientNum );
237 void PlayerStats( int clientNum, char *data, const int len );
240 static const char *MPGuis[];
241 static const char *ThrottleVars[];
242 static const char *ThrottleVarsInEnglish[];
243 static const int ThrottleDelay[];
246 gameState_t gameState; // what state the current game is in
247 gameState_t nextState; // state to switch to when nextStateSwitch is hit
248 int pingUpdateTime; // time to update ping
250 mpPlayerState_t playerState[ MAX_CLIENTS ];
252 // keep track of clients which are willingly in spectator mode
255 vote_flags_t vote; // active vote or VOTE_NONE
256 int voteTimeOut; // when the current vote expires
257 int voteExecTime; // delay between vote passed msg and execute
258 float yesVotes; // counter for yes votes
259 float noVotes; // and for no votes
260 idStr voteValue; // the data voted upon ( server )
261 idStr voteString; // the vote string ( client )
262 bool voted; // hide vote box ( client )
263 int kickVoteMap[ MAX_CLIENTS ];
266 int nextStateSwitch; // time next state switch
267 int warmupEndTime; // warmup till..
268 int matchStartedTime; // time current match started
271 int currentTourneyPlayer[2];// our current set of players
272 int lastWinner; // plays again
275 idStr warmupText; // text shown in warmup area of screen
276 bool one, two, three; // keeps count down voice from repeating
279 idUserInterface *scoreBoard; // scoreboard
280 idUserInterface *spectateGui; // spectate info
281 idUserInterface *guiChat; // chat text
282 idUserInterface *mainGui; // ready / nick / votes etc.
284 idUserInterface *msgmodeGui; // message mode
285 int currentMenu; // 0 - none, 1 - mainGui, 2 - msgmodeGui
286 int nextMenu; // if 0, will do mainGui
287 bool bCurrentMenuMsg; // send menu state updates to server
290 mpChatLine_t chatHistory[ NUM_CHAT_NOTIFY ];
291 int chatHistoryIndex;
292 int chatHistorySize; // 0 <= x < NUM_CHAT_NOTIFY
293 bool chatDataUpdated;
294 int lastChatLineTime;
296 // rankings are used by UpdateScoreboard and UpdateHud
297 int numRankedPlayers; // ranked players, others may be empty slots or spectators
298 idPlayer * rankedPlayers[MAX_CLIENTS];
300 bool pureReady; // defaults to false, set to true once server game is running with pure checksums
301 int fragLimitTimeout;
303 int switchThrottle[ 3 ];
304 int voiceChatThrottle;
306 gameType_t lastGameType; // for restarts
307 int startFragLimit; // synchronize to clients in initial state, set on -> GAMEON
310 void UpdatePlayerRanks();
312 // updates the passed gui with current score information
313 void UpdateRankColor( idUserInterface *gui, const char *mask, int i, const idVec3 &vec );
314 void UpdateScoreboard( idUserInterface *scoreBoard, idPlayer *player );
316 void ClearGuis( void );
317 void DrawScoreBoard( idPlayer *player );
318 void UpdateHud( idPlayer *player, idUserInterface *hud );
320 void CheckVote( void );
321 bool AllPlayersReady( void );
322 idPlayer * FragLimitHit( void );
323 idPlayer * FragLeader( void );
324 bool TimeLimitHit( void );
325 void NewState( gameState_t news, idPlayer *player = NULL );
326 void UpdateWinsLosses( idPlayer *winner );
327 // fill any empty tourney slots based on the current tourney ranks
328 void FillTourneySlots( void );
329 void CycleTourneyPlayers( void );
330 // walk through the tourneyRank to build a wait list for the clients
331 void UpdateTourneyLine( void );
332 const char * GameTime( void );
334 bool EnoughClientsToPlay( void );
335 void ClearChatData( void );
336 void DrawChat( void );
337 // go through the clients, and see if they want to be respawned, and if the game allows it
338 // called during normal gameplay for death -> respawn cycles
339 // and for a spectator who want back in the game (see param)
340 void CheckRespawns( idPlayer *spectator = NULL );
342 // when clients disconnect or join spectate during game, check if we need to end the game
343 void CheckAbortGame( void );
344 void MessageMode( const idCmdArgs &args );
345 void DisableMenu( void );
346 void SetMapShot( void );
348 void TeamScore( int entityNumber, int team, int delta );
349 void VoiceChat( const idCmdArgs &args, bool team );
350 void DumpTourneyLine( void );
351 void SuddenRespawn( void );
354 ID_INLINE idMultiplayerGame::gameState_t idMultiplayerGame::GetGameState( void ) const {
358 ID_INLINE bool idMultiplayerGame::IsPureReady( void ) const {
362 ID_INLINE void idMultiplayerGame::ClearFrags( int clientNum ) {
363 playerState[ clientNum ].fragCount = 0;
366 ID_INLINE bool idMultiplayerGame::IsInGame( int clientNum ) {
367 return playerState[ clientNum ].ingame;
370 #endif /* !__MULTIPLAYERGAME_H__ */