2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition 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 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
2012-12-22 15:18:19 +00:00
|
|
|
#include "precompiled.h"
|
2012-11-26 18:58:24 +00:00
|
|
|
#pragma hdrstop
|
|
|
|
|
|
|
|
#include "Game_local.h"
|
|
|
|
|
|
|
|
// could be a problem if players manage to go down sudden deaths till this .. oh well
|
|
|
|
#define LASTMAN_NOLIVES -20
|
|
|
|
|
|
|
|
extern idCVar ui_skinIndex;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* idMultiplayerGame::teamNames[] = { "#str_02499", "#str_02500" };
|
|
|
|
const char* idMultiplayerGame::skinNames[] =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
"skins/characters/player/marine_mp",
|
|
|
|
"skins/characters/player/marine_mp_red",
|
|
|
|
"skins/characters/player/marine_mp_blue",
|
|
|
|
"skins/characters/player/marine_mp_green",
|
|
|
|
"skins/characters/player/marine_mp_yellow",
|
|
|
|
"skins/characters/player/marine_mp_purple",
|
|
|
|
"skins/characters/player/marine_mp_grey",
|
|
|
|
"skins/characters/player/marine_mp_orange"
|
|
|
|
};
|
2012-11-28 15:47:07 +00:00
|
|
|
const idVec3 idMultiplayerGame::skinColors[] =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3( 0.25f, 0.25f, 0.25f ), // light grey
|
|
|
|
idVec3( 1.00f, 0.00f, 0.00f ), // red
|
|
|
|
idVec3( 0.20f, 0.50f, 0.80f ), // blue
|
|
|
|
idVec3( 0.00f, 0.80f, 0.10f ), // green
|
|
|
|
idVec3( 1.00f, 0.80f, 0.10f ), // yellow
|
|
|
|
idVec3( 0.39f, 0.199f, 0.3f ), // purple
|
|
|
|
idVec3( 0.425f, 0.484f, 0.445f ), // dark grey
|
2012-11-28 15:47:07 +00:00
|
|
|
idVec3( 0.484f, 0.312f, 0.074f ) // orange
|
2012-11-26 18:58:24 +00:00
|
|
|
};
|
|
|
|
const int idMultiplayerGame::numSkins = sizeof( idMultiplayerGame::skinNames ) / sizeof( idMultiplayerGame::skinNames[0] );
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* idMultiplayerGame::GetTeamName( int team ) const
|
|
|
|
{
|
|
|
|
return teamNames[idMath::ClampInt( 0, 1, team )];
|
|
|
|
}
|
|
|
|
const char* idMultiplayerGame::GetSkinName( int skin ) const
|
|
|
|
{
|
|
|
|
return skinNames[idMath::ClampInt( 0, numSkins - 1, skin )];
|
|
|
|
}
|
|
|
|
const idVec3& idMultiplayerGame::GetSkinColor( int skin ) const
|
|
|
|
{
|
|
|
|
return skinColors[idMath::ClampInt( 0, numSkins - 1, skin )];
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
// make CTF not included in game modes for consoles
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* gameTypeNames_WithCTF[] = { "Deathmatch", "Tourney", "Team DM", "Last Man", "CTF", "" };
|
|
|
|
const char* gameTypeDisplayNames_WithCTF[] = { "#str_04260", "#str_04261", "#str_04262", "#str_04263", "#str_swf_mode_ctf", "" };
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* gameTypeNames_WithoutCTF[] = { "Deathmatch", "Tourney", "Team DM", "Last Man", "" };
|
|
|
|
const char* gameTypeDisplayNames_WithoutCTF[] = { "#str_04260", "#str_04261", "#str_04262", "#str_04263", "" };
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
compile_time_assert( GAME_DM == 0 );
|
|
|
|
compile_time_assert( GAME_TOURNEY == 1 );
|
|
|
|
compile_time_assert( GAME_TDM == 2 );
|
|
|
|
compile_time_assert( GAME_LASTMAN == 3 );
|
|
|
|
compile_time_assert( GAME_CTF == 4 );
|
|
|
|
|
|
|
|
idCVar g_spectatorChat( "g_spectatorChat", "0", CVAR_GAME | CVAR_ARCHIVE | CVAR_BOOL, "let spectators talk to everyone during game" );
|
|
|
|
|
|
|
|
// global sounds transmitted by index - 0 .. SND_COUNT
|
|
|
|
// sounds in this list get precached on MP start
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* idMultiplayerGame::GlobalSoundStrings[] =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
"sound/vo/feedback/voc_youwin.wav",
|
|
|
|
"sound/vo/feedback/voc_youlose.wav",
|
|
|
|
"sound/vo/feedback/fight.wav",
|
|
|
|
"sound/vo/feedback/three.wav",
|
|
|
|
"sound/vo/feedback/two.wav",
|
|
|
|
"sound/vo/feedback/one.wav",
|
|
|
|
"sound/vo/feedback/sudden_death.wav",
|
|
|
|
"sound/vo/ctf/flag_capped_yours.wav",
|
|
|
|
"sound/vo/ctf/flag_capped_theirs.wav",
|
|
|
|
"sound/vo/ctf/flag_return.wav",
|
|
|
|
"sound/vo/ctf/flag_taken_yours.wav",
|
|
|
|
"sound/vo/ctf/flag_taken_theirs.wav",
|
|
|
|
"sound/vo/ctf/flag_dropped_yours.wav",
|
|
|
|
"sound/vo/ctf/flag_dropped_theirs.wav"
|
|
|
|
};
|
|
|
|
|
|
|
|
// handy verbose
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* idMultiplayerGame::GameStateStrings[] =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
"INACTIVE",
|
|
|
|
"WARMUP",
|
|
|
|
"COUNTDOWN",
|
|
|
|
"GAMEON",
|
|
|
|
"SUDDENDEATH",
|
|
|
|
"GAMEREVIEW",
|
|
|
|
"NEXTGAME"
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::idMultiplayerGame
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idMultiplayerGame::idMultiplayerGame()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
teamFlags[0] = NULL;
|
|
|
|
teamFlags[1] = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
teamPoints[0] = 0;
|
|
|
|
teamPoints[1] = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
flagMsgOn = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
player_blue_flag = -1;
|
|
|
|
player_red_flag = -1;
|
|
|
|
|
|
|
|
Clear();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardManager = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::Shutdown
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::Shutdown()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::Reset
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::Reset()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Clear();
|
|
|
|
ClearChatData();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( common->IsMultiplayer() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardManager = new idMenuHandler_Scoreboard();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( scoreboardManager != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardManager->Initialize( "scoreboard", common->SW() );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ClearChatData();
|
|
|
|
warmupEndTime = 0;
|
|
|
|
lastChatLineTime = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::ServerClientConnect
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::ServerClientConnect( int clientNum )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( &playerState[ clientNum ], 0, sizeof( playerState[ clientNum ] ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::SpawnPlayer
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::SpawnPlayer( int clientNum )
|
|
|
|
{
|
|
|
|
idLobbyBase& lobby = session->GetActingGameStateLobbyBase();
|
|
|
|
lobbyUserID_t& lobbyUserID = gameLocal.lobbyUserIDs[clientNum];
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( idLocalization::GetString( "#str_07177" ), lobby.GetLobbyUserName( lobbyUserID ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( &playerState[ clientNum ], 0, sizeof( playerState[ clientNum ] ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !common->IsClient() )
|
|
|
|
{
|
|
|
|
if( gameLocal.gameType == GAME_LASTMAN )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// Players spawn with no lives to prevent them from getting the clean slate achievement if
|
|
|
|
// they didn't earn it.
|
|
|
|
playerState[ clientNum ].fragCount = LASTMAN_NOLIVES;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idPlayer* p = static_cast< idPlayer* >( gameLocal.entities[ clientNum ] );
|
2012-11-26 18:58:24 +00:00
|
|
|
p->spawnedTime = gameLocal.serverTime;
|
|
|
|
p->team = 0;
|
|
|
|
p->tourneyRank = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.gameType == GAME_TOURNEY && gameState == GAMEON )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
p->tourneyRank++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::Clear
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::Clear()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameState = INACTIVE;
|
|
|
|
nextState = INACTIVE;
|
|
|
|
nextStateSwitch = 0;
|
|
|
|
matchStartedTime = 0;
|
|
|
|
currentTourneyPlayer[ 0 ] = -1;
|
|
|
|
currentTourneyPlayer[ 1 ] = -1;
|
|
|
|
one = two = three = false;
|
|
|
|
memset( &playerState, 0 , sizeof( playerState ) );
|
|
|
|
lastWinner = -1;
|
|
|
|
pureReady = false;
|
|
|
|
|
|
|
|
CleanupScoreboard();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
fragLimitTimeout = 0;
|
|
|
|
voiceChatThrottle = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < NUM_CHAT_NOTIFY; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
chatHistory[ i ].line.Clear();
|
|
|
|
}
|
|
|
|
startFragLimit = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::Clear
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::CleanupScoreboard()
|
|
|
|
{
|
|
|
|
if( scoreboardManager != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
delete scoreboardManager;
|
|
|
|
scoreboardManager = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::GetFlagPoints
|
|
|
|
|
|
|
|
Gets number of captures in CTF game.
|
|
|
|
|
|
|
|
0 = red team
|
|
|
|
1 = blue team
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
int idMultiplayerGame::GetFlagPoints( int team )
|
|
|
|
{
|
|
|
|
assert( team <= 1 );
|
|
|
|
|
|
|
|
return teamPoints[ team ];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::UpdatePlayerRanks
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::UpdatePlayerRanks()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, j, k;
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* players[MAX_CLIENTS];
|
|
|
|
idEntity* ent;
|
|
|
|
idPlayer* player;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( players, 0, sizeof( players ) );
|
|
|
|
numRankedPlayers = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ent = gameLocal.entities[ i ];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
player = static_cast< idPlayer* >( ent );
|
|
|
|
if( !CanPlay( player ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.gameType == GAME_TOURNEY )
|
|
|
|
{
|
|
|
|
if( i != currentTourneyPlayer[ 0 ] && i != currentTourneyPlayer[ 1 ] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.gameType == GAME_LASTMAN && playerState[ i ].fragCount == LASTMAN_NOLIVES )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
for( j = 0; j < numRankedPlayers; j++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bool insert = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( IsGametypeTeamBased() ) /* CTF */
|
|
|
|
{
|
|
|
|
if( player->team != players[ j ]->team )
|
|
|
|
{
|
|
|
|
if( playerState[ i ].teamFragCount > playerState[ players[ j ]->entityNumber ].teamFragCount )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// team scores
|
|
|
|
insert = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( playerState[ i ].teamFragCount == playerState[ players[ j ]->entityNumber ].teamFragCount && player->team < players[ j ]->team )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// at equal scores, sort by team number
|
|
|
|
insert = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( playerState[ i ].fragCount > playerState[ players[ j ]->entityNumber ].fragCount )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// in the same team, sort by frag count
|
|
|
|
insert = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
insert = ( playerState[ i ].fragCount > playerState[ players[ j ]->entityNumber ].fragCount );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( insert )
|
|
|
|
{
|
|
|
|
for( k = numRankedPlayers; k > j; k-- )
|
|
|
|
{
|
|
|
|
players[ k ] = players[ k - 1 ];
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
players[ j ] = player;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( j == numRankedPlayers )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
players[ numRankedPlayers ] = player;
|
|
|
|
}
|
|
|
|
numRankedPlayers++;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
memcpy( rankedPlayers, players, sizeof( players ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::UpdateRankColor
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::UpdateRankColor( idUserInterface* gui, const char* mask, int i, const idVec3& vec )
|
|
|
|
{
|
|
|
|
for( int j = 1; j < 4; j++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gui->SetStateFloat( va( mask, i, j ), vec[ j - 1 ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::IsScoreboardActive
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idMultiplayerGame::IsScoreboardActive()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( scoreboardManager != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return scoreboardManager->IsActive();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::HandleGuiEvent
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idMultiplayerGame::HandleGuiEvent( const sysEvent_t* sev )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( scoreboardManager != NULL && scoreboardManager->IsActive() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardManager->HandleGuiEvent( sev );
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::UpdateScoreboard
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::UpdateScoreboard( idMenuHandler_Scoreboard* scoreboard, idPlayer* owner )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( owner == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int redScore = 0;
|
|
|
|
int blueScore = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idLobbyBase& lobby = session->GetActingGameStateLobbyBase();
|
2012-11-26 18:58:24 +00:00
|
|
|
idList< mpScoreboardInfo > scoreboardInfo;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < MAX_CLIENTS; ++i )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( i < gameLocal.numClients )
|
|
|
|
{
|
|
|
|
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* player = static_cast<idPlayer*>( ent );
|
|
|
|
if( !player )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr spectateData;
|
|
|
|
idStr playerName;
|
|
|
|
int score = 0;
|
|
|
|
int wins = 0;
|
|
|
|
int ping = 0;
|
|
|
|
int playerNum = player->entityNumber;
|
|
|
|
int team = - 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
lobbyUserID_t& lobbyUserID = gameLocal.lobbyUserIDs[ playerNum ];
|
|
|
|
|
|
|
|
if( IsGametypeTeamBased() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
team = player->team;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( team == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
redScore = playerState[ playerNum ].teamFragCount;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( team == 1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
blueScore = playerState[ playerNum ].teamFragCount;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
score = idMath::ClampInt( MP_PLAYER_MINFRAGS, MP_PLAYER_MAXFRAGS, playerState[ playerNum ].fragCount );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
// HACK -
|
|
|
|
if( gameLocal.gameType == GAME_LASTMAN && score == LASTMAN_NOLIVES )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
score = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
wins = idMath::ClampInt( 0, MP_PLAYER_MAXWINS, playerState[ playerNum ].wins );
|
|
|
|
ping = playerState[ playerNum ].ping;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameState == WARMUP )
|
|
|
|
{
|
|
|
|
if( player->spectating )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
spectateData = idLocalization::GetString( "#str_04246" );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
spectateData = idLocalization::GetString( "#str_04247" );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( gameLocal.gameType == GAME_LASTMAN && playerState[ playerNum ].fragCount == LASTMAN_NOLIVES )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
spectateData = idLocalization::GetString( "#str_06736" );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( player->spectating )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
spectateData = idLocalization::GetString( "#str_04246" );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( playerNum == owner->entityNumber )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playerName = "^3";
|
|
|
|
playerName.Append( lobby.GetLobbyUserName( lobbyUserID ) );
|
|
|
|
playerName.Append( "^0" );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playerName = lobby.GetLobbyUserName( lobbyUserID );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
mpScoreboardInfo info;
|
|
|
|
info.voiceState = session->GetDisplayStateFromVoiceState( session->GetLobbyUserVoiceState( lobbyUserID ) );
|
|
|
|
info.name = playerName;
|
|
|
|
info.team = team;
|
|
|
|
info.score = score;
|
|
|
|
info.wins = wins;
|
|
|
|
info.ping = ping;
|
|
|
|
info.playerNum = playerNum;
|
|
|
|
info.spectateData = spectateData;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
bool added = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < scoreboardInfo.Num(); ++i )
|
|
|
|
{
|
|
|
|
if( info.team == scoreboardInfo[i].team )
|
|
|
|
{
|
|
|
|
if( info.score > scoreboardInfo[i].score )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardInfo.Insert( info, i );
|
|
|
|
added = true;
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( info.team < scoreboardInfo[i].team )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardInfo.Insert( info, i );
|
|
|
|
added = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !added )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardInfo.Append( info );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr gameInfo;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameState == GAMEREVIEW )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int timeRemaining = nextStateSwitch - gameLocal.serverTime;
|
2012-11-28 15:47:07 +00:00
|
|
|
int ms = ( int ) ceilf( timeRemaining / 1000.0f );
|
|
|
|
if( ms == 1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameInfo = idLocalization::GetString( "#str_online_game_starts_in_second" );
|
|
|
|
gameInfo.Replace( "<DNT_VAL>", idStr( ms ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( ms > 0 && ms < 30 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameInfo = idLocalization::GetString( "#str_online_game_starts_in_seconds" );
|
2012-11-28 15:47:07 +00:00
|
|
|
gameInfo.Replace( "<DNT_VAL>", idStr( ms ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( gameLocal.gameType == GAME_LASTMAN )
|
|
|
|
{
|
|
|
|
if( gameState == GAMEON || gameState == SUDDENDEATH )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameInfo = va( "%s: %i", idLocalization::GetString( "#str_04264" ), startFragLimit );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameInfo = va( "%s: %i", idLocalization::GetString( "#str_04264" ), gameLocal.serverInfo.GetInt( "si_fragLimit" ) );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( gameLocal.gameType == GAME_CTF )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int captureLimit = gameLocal.serverInfo.GetInt( "si_fragLimit" );
|
|
|
|
gameInfo = va( idLocalization::GetString( "#str_11108" ), captureLimit );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameInfo = va( "%s: %i", idLocalization::GetString( "#str_01982" ), gameLocal.serverInfo.GetInt( "si_fragLimit" ) );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameLocal.serverInfo.GetInt( "si_timeLimit" ) > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameInfo.Append( va( " %s: %i", idLocalization::GetString( "#str_01983" ), gameLocal.serverInfo.GetInt( "si_timeLimit" ) ) );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( scoreboardManager )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( IsGametypeFlagBased() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardManager->SetTeamScores( GetFlagPoints( 0 ), GetFlagPoints( 1 ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( IsGametypeTeamBased() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardManager->SetTeamScores( redScore, blueScore );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardManager->UpdateScoreboard( scoreboardInfo, gameInfo );
|
|
|
|
scoreboardManager->UpdateScoreboardSelection();
|
|
|
|
scoreboardManager->Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::GameTime
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* idMultiplayerGame::GameTime()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
static char buff[16];
|
|
|
|
int m, s, t, ms;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameState == COUNTDOWN )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ms = warmupEndTime - gameLocal.serverTime;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// we never want to show double dashes.
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ms <= 0 )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Try to setup time again.
|
2012-11-28 15:47:07 +00:00
|
|
|
warmupEndTime = gameLocal.serverTime + 1000 * cvarSystem->GetCVarInteger( "g_countDown" );
|
2012-11-26 18:58:24 +00:00
|
|
|
ms = warmupEndTime - gameLocal.serverTime;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
s = ms / 1000 + 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ms <= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
strcpy( buff, "WMP --" );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
sprintf( buff, "WMP %i", s );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int timeLimit = gameLocal.serverInfo.GetInt( "si_timeLimit" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( timeLimit )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ms = ( timeLimit * 60000 ) - ( gameLocal.serverTime - matchStartedTime );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ms = gameLocal.serverTime - matchStartedTime;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ms < 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ms = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
s = ms / 1000;
|
|
|
|
m = s / 60;
|
|
|
|
s -= m * 60;
|
|
|
|
t = s / 10;
|
|
|
|
s -= t * 10;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
sprintf( buff, "%i:%i%i", m, t, s );
|
|
|
|
}
|
|
|
|
return &buff[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::NumActualClients
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idMultiplayerGame::NumActualClients( bool countSpectators, int* teamcounts )
|
|
|
|
{
|
|
|
|
idPlayer* p;
|
2012-11-26 18:58:24 +00:00
|
|
|
int c = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( teamcounts )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
teamcounts[ 0 ] = teamcounts[ 1 ] = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0 ; i < gameLocal.numClients ; i++ )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
p = static_cast< idPlayer* >( ent );
|
|
|
|
if( countSpectators || CanPlay( p ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
c++;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( teamcounts && CanPlay( p ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
teamcounts[ p->team ]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::EnoughClientsToPlay
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idMultiplayerGame::EnoughClientsToPlay()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int teamCount[ 2 ];
|
|
|
|
int clients = NumActualClients( false, teamCount );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( IsGametypeTeamBased() ) /* CTF */
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return clients >= 2 && teamCount[ 0 ] && teamCount[ 1 ];
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return clients >= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::FragLimitHit
|
|
|
|
return the winning player (team player)
|
|
|
|
if there is no FragLeader(), the game is tied and we return NULL
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* idMultiplayerGame::FragLimitHit()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
|
|
|
int fragLimit = gameLocal.serverInfo.GetInt( "si_fragLimit" );
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* leader;
|
|
|
|
|
|
|
|
if( IsGametypeFlagBased() ) /* CTF */
|
2012-11-26 18:58:24 +00:00
|
|
|
return NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
leader = FragLeader();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !leader )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( fragLimit <= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
fragLimit = MP_PLAYER_MAXFRAGS;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameLocal.gameType == GAME_LASTMAN )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// we have a leader, check if any other players have frags left
|
2012-11-28 15:47:07 +00:00
|
|
|
assert( !static_cast< idPlayer* >( leader )->lastManOver );
|
|
|
|
for( i = 0 ; i < gameLocal.numClients ; i++ )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !CanPlay( static_cast< idPlayer* >( ent ) ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ent == leader )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( playerState[ ent->entityNumber ].fragCount > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// there is a leader, his score may even be negative, but no one else has frags left or is !lastManOver
|
|
|
|
return leader;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( IsGametypeTeamBased() ) /* CTF */
|
|
|
|
{
|
|
|
|
if( playerState[ leader->entityNumber ].teamFragCount >= fragLimit )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return leader;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( playerState[ leader->entityNumber ].fragCount >= fragLimit )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return leader;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::TimeLimitHit
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idMultiplayerGame::TimeLimitHit()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int timeLimit = gameLocal.serverInfo.GetInt( "si_timeLimit" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( timeLimit )
|
|
|
|
{
|
|
|
|
if( gameLocal.serverTime >= matchStartedTime + timeLimit * 60000 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::WinningTeam
|
|
|
|
return winning team
|
|
|
|
-1 if tied or no players
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idMultiplayerGame::WinningTeam()
|
|
|
|
{
|
|
|
|
if( teamPoints[0] > teamPoints[1] )
|
2012-11-26 18:58:24 +00:00
|
|
|
return 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( teamPoints[0] < teamPoints[1] )
|
2012-11-26 18:58:24 +00:00
|
|
|
return 1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::PointLimitHit
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idMultiplayerGame::PointLimitHit()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int pointLimit = gameLocal.serverInfo.GetInt( "si_fragLimit" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// default to MP_CTF_MAXPOINTS if needed
|
2012-11-28 15:47:07 +00:00
|
|
|
if( pointLimit > MP_CTF_MAXPOINTS )
|
2012-11-26 18:58:24 +00:00
|
|
|
pointLimit = MP_CTF_MAXPOINTS;
|
2012-11-28 15:47:07 +00:00
|
|
|
else if( pointLimit <= 0 )
|
2012-11-26 18:58:24 +00:00
|
|
|
pointLimit = MP_CTF_MAXPOINTS;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( teamPoints[0] == teamPoints[1] )
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( teamPoints[0] >= pointLimit ||
|
|
|
|
teamPoints[1] >= pointLimit )
|
|
|
|
return true;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::FragLeader
|
|
|
|
return the current winner ( or a player from the winning team )
|
|
|
|
NULL if even
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* idMultiplayerGame::FragLeader()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
|
|
|
int frags[ MAX_CLIENTS ];
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* leader = NULL;
|
|
|
|
idEntity* ent;
|
|
|
|
idPlayer* p;
|
2012-11-26 18:58:24 +00:00
|
|
|
int high = -9999;
|
|
|
|
int count = 0;
|
|
|
|
bool teamLead[ 2 ] = { false, false };
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0 ; i < gameLocal.numClients ; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ent = gameLocal.entities[ i ];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !CanPlay( static_cast< idPlayer* >( ent ) ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.gameType == GAME_TOURNEY && ent->entityNumber != currentTourneyPlayer[ 0 ] && ent->entityNumber != currentTourneyPlayer[ 1 ] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( static_cast< idPlayer* >( ent )->lastManOver )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int fragc = ( IsGametypeTeamBased() ) ? playerState[i].teamFragCount : playerState[i].fragCount; /* CTF */
|
2012-11-28 15:47:07 +00:00
|
|
|
if( fragc > high )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
high = fragc;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
frags[ i ] = fragc;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ent = gameLocal.entities[ i ];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
p = static_cast< idPlayer* >( ent );
|
2012-11-26 18:58:24 +00:00
|
|
|
p->SetLeader( false );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !CanPlay( p ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.gameType == GAME_TOURNEY && ent->entityNumber != currentTourneyPlayer[ 0 ] && ent->entityNumber != currentTourneyPlayer[ 1 ] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( p->lastManOver )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( p->spectating )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( frags[ i ] >= high )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
leader = p;
|
|
|
|
count++;
|
|
|
|
p->SetLeader( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( IsGametypeTeamBased() ) /* CTF */
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
teamLead[ p->team ] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !IsGametypeTeamBased() ) /* CTF */
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// more than one player at the highest frags
|
2012-11-28 15:47:07 +00:00
|
|
|
if( count > 1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return leader;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( teamLead[ 0 ] && teamLead[ 1 ] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// even game in team play
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return leader;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idGameLocal::UpdateWinsLosses
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::UpdateWinsLosses( idPlayer* winner )
|
|
|
|
{
|
|
|
|
if( winner )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// run back through and update win/loss count
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* player = static_cast<idPlayer*>( ent );
|
|
|
|
if( IsGametypeTeamBased() ) /* CTF */
|
|
|
|
{
|
|
|
|
if( player == winner || ( player != winner && player->team == winner->team ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playerState[ i ].wins++;
|
|
|
|
PlayGlobalSound( i, SND_YOUWIN );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PlayGlobalSound( i, SND_YOULOSE );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( gameLocal.gameType == GAME_LASTMAN )
|
|
|
|
{
|
|
|
|
if( player == winner )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playerState[ i ].wins++;
|
|
|
|
PlayGlobalSound( i, SND_YOUWIN );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( !player->wantSpectate )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PlayGlobalSound( i, SND_YOULOSE );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( gameLocal.gameType == GAME_TOURNEY )
|
|
|
|
{
|
|
|
|
if( player == winner )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playerState[ i ].wins++;
|
|
|
|
PlayGlobalSound( i, SND_YOUWIN );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( i == currentTourneyPlayer[ 0 ] || i == currentTourneyPlayer[ 1 ] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PlayGlobalSound( i, SND_YOULOSE );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( player == winner )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playerState[i].wins++;
|
|
|
|
PlayGlobalSound( i, SND_YOUWIN );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( !player->wantSpectate )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PlayGlobalSound( i, SND_YOULOSE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( IsGametypeFlagBased() ) /* CTF */
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int winteam = WinningTeam();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( winteam != -1 ) // TODO : print a message telling it why the hell the game ended with no winning team?
|
|
|
|
for( int i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
idPlayer* player = static_cast<idPlayer*>( ent );
|
|
|
|
|
|
|
|
if( player->team == winteam )
|
|
|
|
{
|
|
|
|
PlayGlobalSound( i, SND_YOUWIN );
|
|
|
|
playerState[ i ].wins++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlayGlobalSound( i, SND_YOULOSE );
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( winner )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
lastWinner = winner->entityNumber;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
lastWinner = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::TeamScoreCTF
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::TeamScoreCTF( int team, int delta )
|
|
|
|
{
|
|
|
|
if( team < 0 || team > 1 )
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
teamPoints[team] += delta;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameState == GAMEON || gameState == SUDDENDEATH )
|
|
|
|
PrintMessageEvent( MSG_SCOREUPDATE, teamPoints[0], teamPoints[1] );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::PlayerScoreCTF
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::PlayerScoreCTF( int playerIdx, int delta )
|
|
|
|
{
|
|
|
|
if( playerIdx < 0 || playerIdx >= MAX_CLIENTS )
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
playerState[ playerIdx ].fragCount += delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::GetFlagCarrier
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idMultiplayerGame::GetFlagCarrier( int team )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int iFlagCarrier = -1;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idPlayer* player = static_cast<idPlayer*>( ent );
|
|
|
|
if( player->team != team )
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( player->carryingFlag )
|
|
|
|
{
|
|
|
|
if( iFlagCarrier != -1 )
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Warning( "BUG: more than one flag carrier on %s team", team == 0 ? "red" : "blue" );
|
|
|
|
iFlagCarrier = i;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return iFlagCarrier;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::TeamScore
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::TeamScore( int entityNumber, int team, int delta )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playerState[ entityNumber ].fragCount += delta;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0 ; i < gameLocal.numClients ; i++ )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* player = static_cast<idPlayer*>( ent );
|
|
|
|
if( player->team == team )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playerState[ player->entityNumber ].teamFragCount += delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::PlayerDeath
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::PlayerDeath( idPlayer* dead, idPlayer* killer, bool telefrag )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
// don't do PrintMessageEvent and shit
|
|
|
|
assert( !common->IsClient() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameState == COUNTDOWN || gameState == WARMUP )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// No Kill scores are gained during warmup.
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( dead == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::Warning( "idMultiplayerGame::PlayerDeath dead ptr == NULL, kill will not count" );
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
playerState[ dead->entityNumber ].deaths++;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( killer )
|
|
|
|
{
|
|
|
|
if( gameLocal.gameType == GAME_LASTMAN )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playerState[ dead->entityNumber ].fragCount--;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( IsGametypeTeamBased() ) /* CTF */
|
|
|
|
{
|
|
|
|
if( killer == dead || killer->team == dead->team )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// suicide or teamkill
|
|
|
|
TeamScore( killer->entityNumber, killer->team, -1 );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
TeamScore( killer->entityNumber, killer->team, +1 );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playerState[ killer->entityNumber ].fragCount += ( killer == dead ) ? -1 : 1;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( killer && killer == dead )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PrintMessageEvent( MSG_SUICIDE, dead->entityNumber );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( killer )
|
|
|
|
{
|
|
|
|
if( telefrag )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
killer->GetAchievementManager().EventCompletesAchievement( ACHIEVEMENT_MP_KILL_PLAYER_VIA_TELEPORT );
|
|
|
|
PrintMessageEvent( MSG_TELEFRAGGED, dead->entityNumber, killer->entityNumber );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( IsGametypeTeamBased() && dead->team == killer->team ) /* CTF */
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PrintMessageEvent( MSG_KILLEDTEAM, dead->entityNumber, killer->entityNumber );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( killer->PowerUpActive( INVISIBILITY ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
killer->GetAchievementManager().EventCompletesAchievement( ACHIEVEMENT_MP_KILL_5_PLAYERS_USING_INVIS );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( killer->PowerUpActive( BERSERK ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
killer->GetAchievementManager().EventCompletesAchievement( ACHIEVEMENT_MP_USE_BERSERK_TO_KILL_PLAYER );
|
|
|
|
}
|
|
|
|
PrintMessageEvent( MSG_KILLED, dead->entityNumber, killer->entityNumber );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PrintMessageEvent( MSG_DIED, dead->entityNumber );
|
|
|
|
playerState[ dead->entityNumber ].fragCount--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::PlayerStats
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::PlayerStats( int clientNum, char* data, const int len )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idEntity* ent;
|
2012-11-26 18:58:24 +00:00
|
|
|
int team;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
*data = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// make sure we don't exceed the client list
|
2012-11-28 15:47:07 +00:00
|
|
|
if( clientNum < 0 || clientNum > gameLocal.numClients )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// find which team this player is on
|
2012-11-28 15:47:07 +00:00
|
|
|
ent = gameLocal.entities[ clientNum ];
|
|
|
|
if( ent && ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
|
|
|
team = static_cast< idPlayer* >( ent )->team;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr::snPrintf( data, len, "team=%d score=%ld tks=%ld", team, playerState[ clientNum ].fragCount, playerState[ clientNum ].teamFragCount );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::DumpTourneyLine
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::DumpTourneyLine()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
if( gameLocal.entities[ i ] && gameLocal.entities[ i ]->IsType( idPlayer::Type ) )
|
|
|
|
{
|
|
|
|
common->Printf( "client %d: rank %d\n", i, static_cast< idPlayer* >( gameLocal.entities[ i ] )->tourneyRank );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::NewState
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::NewState( gameState_t news, idPlayer* player )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idBitMsg outMsg;
|
|
|
|
byte msgBuf[MAX_GAME_MESSAGE_SIZE];
|
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( news != gameState );
|
|
|
|
assert( !common->IsClient() );
|
|
|
|
assert( news < STATE_COUNT );
|
|
|
|
gameLocal.DPrintf( "%s -> %s\n", GameStateStrings[ gameState ], GameStateStrings[ news ] );
|
2012-11-28 15:47:07 +00:00
|
|
|
switch( news )
|
|
|
|
{
|
|
|
|
case GAMEON:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.LocalMapRestart();
|
|
|
|
outMsg.InitWrite( msgBuf, sizeof( msgBuf ) );
|
|
|
|
outMsg.WriteBits( 0, 1 );
|
|
|
|
session->GetActingGameStateLobbyBase().SendReliable( GAME_RELIABLE_MESSAGE_RESTART, outMsg, false );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
teamPoints[0] = 0;
|
|
|
|
teamPoints[1] = 0;
|
|
|
|
|
|
|
|
PlayGlobalSound( -1, SND_FIGHT );
|
|
|
|
matchStartedTime = gameLocal.serverTime;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idBitMsg matchStartedTimeMsg;
|
|
|
|
byte matchStartedTimeMsgBuf[ sizeof( matchStartedTime ) ];
|
|
|
|
matchStartedTimeMsg.InitWrite( matchStartedTimeMsgBuf, sizeof( matchStartedTimeMsgBuf ) );
|
|
|
|
matchStartedTimeMsg.WriteLong( matchStartedTime );
|
|
|
|
session->GetActingGameStateLobbyBase().SendReliable( GAME_RELIABLE_MESSAGE_MATCH_STARTED_TIME, matchStartedTimeMsg, false );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
fragLimitTimeout = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* p = static_cast<idPlayer*>( ent );
|
2012-11-26 18:58:24 +00:00
|
|
|
p->wantSpectate = false; // Make sure everyone is in the game.
|
|
|
|
p->SetLeader( false ); // don't carry the flag from previous games
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.gameType == GAME_TOURNEY && currentTourneyPlayer[ 0 ] != i && currentTourneyPlayer[ 1 ] != i )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
p->ServerSpectate( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
idLib::Printf( "TOURNEY NewState GAMEON :> Player %d Benched \n", p->entityNumber );
|
2012-11-26 18:58:24 +00:00
|
|
|
p->tourneyRank++;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int fragLimit = gameLocal.serverInfo.GetInt( "si_fragLimit" );
|
|
|
|
int startingCount = ( gameLocal.gameType == GAME_LASTMAN ) ? fragLimit : 0;
|
|
|
|
playerState[ i ].fragCount = startingCount;
|
|
|
|
playerState[ i ].teamFragCount = startingCount;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !static_cast<idPlayer*>( ent )->wantSpectate )
|
|
|
|
{
|
|
|
|
static_cast<idPlayer*>( ent )->ServerSpectate( false );
|
|
|
|
idLib::Printf( "TOURNEY NewState :> Player %d On Deck \n", ent->entityNumber );
|
|
|
|
if( gameLocal.gameType == GAME_TOURNEY )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
p->tourneyRank = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( CanPlay( p ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
p->lastManPresent = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
p->lastManPresent = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NewState_GameOn_ServerAndClient();
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case GAMEREVIEW:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SetFlagMsg( false );
|
|
|
|
nextState = INACTIVE; // used to abort a game. cancel out any upcoming state change
|
|
|
|
// set all players spectating
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
static_cast<idPlayer*>( ent )->ServerSpectate( true );
|
|
|
|
idLib::Printf( "TOURNEY NewState GAMEREVIEW :> Player %d Benched \n", ent->entityNumber );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
UpdateWinsLosses( player );
|
|
|
|
SetFlagMsg( true );
|
|
|
|
NewState_GameReview_ServerAndClient();
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case SUDDENDEATH:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PrintMessageEvent( MSG_SUDDENDEATH );
|
|
|
|
PlayGlobalSound( -1, SND_SUDDENDEATH );
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case COUNTDOWN:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idBitMsg outMsg;
|
|
|
|
byte msgBuf[ 128 ];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
warmupEndTime = gameLocal.serverTime + 1000 * cvarSystem->GetCVarInteger( "g_countDown" );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
outMsg.InitWrite( msgBuf, sizeof( msgBuf ) );
|
|
|
|
outMsg.WriteLong( warmupEndTime );
|
|
|
|
session->GetActingGameStateLobbyBase().SendReliable( GAME_RELIABLE_MESSAGE_WARMUPTIME, outMsg, false );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Reset all the scores.
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int fragLimit = gameLocal.serverInfo.GetInt( "si_fragLimit" );
|
|
|
|
int startingCount = ( gameLocal.gameType == GAME_LASTMAN ) ? fragLimit : 0;
|
|
|
|
playerState[ i ].fragCount = startingCount;
|
|
|
|
playerState[ i ].teamFragCount = startingCount;
|
|
|
|
playerState[ i ].deaths = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState_Countdown_ServerAndClient();
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case WARMUP:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
teamPoints[0] = 0;
|
|
|
|
teamPoints[1] = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( IsGametypeFlagBased() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// reset player scores to zero, only required for CTF
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
playerState[ i ].fragCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NewState_Warmup_ServerAndClient();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameState = news;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::NewState_Warmup_ServerAndClient
|
|
|
|
Called on both servers and clients once when the game state changes to WARMUP.
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::NewState_Warmup_ServerAndClient()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SetScoreboardActive( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::NewState_Countdown_ServerAndClient
|
|
|
|
Called on both servers and clients once when the game state changes to COUNTDOWN.
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::NewState_Countdown_ServerAndClient()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SetScoreboardActive( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::NewState_GameOn_ServerAndClient
|
|
|
|
Called on both servers and clients once when the game state changes to GAMEON.
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::NewState_GameOn_ServerAndClient()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
startFragLimit = gameLocal.serverInfo.GetInt( "si_fragLimit" );
|
|
|
|
SetScoreboardActive( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::NewState_GameReview_ServerAndClient
|
|
|
|
Called on both servers and clients once when the game state changes to GAMEREVIEW.
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::NewState_GameReview_ServerAndClient()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SetScoreboardActive( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::FillTourneySlots
|
|
|
|
NOTE: called each frame during warmup to keep the tourney slots filled
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::FillTourneySlots( )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, j, rankmax, rankmaxindex;
|
2012-11-28 15:47:07 +00:00
|
|
|
idEntity* ent;
|
|
|
|
idPlayer* p;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::Printf( "TOURNEY :> Executing FillTourneySlots \n" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// fill up the slots based on tourney ranks
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < 2; i++ )
|
|
|
|
{
|
|
|
|
if( currentTourneyPlayer[ i ] != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
rankmax = -1;
|
|
|
|
rankmaxindex = -1;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( j = 0; j < gameLocal.numClients; j++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ent = gameLocal.entities[ j ];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( currentTourneyPlayer[ 0 ] == j || currentTourneyPlayer[ 1 ] == j )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
p = static_cast< idPlayer* >( ent );
|
|
|
|
if( p->wantSpectate )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::Printf( "FillTourneySlots: Skipping Player %d ( Wants Spectate )\n", p->entityNumber );
|
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
if( p->tourneyRank >= rankmax )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// when ranks are equal, use time in game
|
2012-11-28 15:47:07 +00:00
|
|
|
if( p->tourneyRank == rankmax )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( rankmaxindex >= 0 );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( p->spawnedTime > static_cast< idPlayer* >( gameLocal.entities[ rankmaxindex ] )->spawnedTime )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
rankmax = static_cast< idPlayer* >( ent )->tourneyRank;
|
2012-11-26 18:58:24 +00:00
|
|
|
rankmaxindex = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentTourneyPlayer[ i ] = rankmaxindex; // may be -1 if we found nothing
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::Printf( "TOURNEY :> Player 1: %d Player 2: %d \n", currentTourneyPlayer[ 0 ], currentTourneyPlayer[ 1 ] );
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::UpdateTourneyLine
|
|
|
|
we manipulate tourneyRank on player entities for internal ranking. it's easier to deal with.
|
|
|
|
but we need a real wait list to be synced down to clients for GUI
|
|
|
|
ignore current players, ignore wantSpectate
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::UpdateTourneyLine()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( !common->IsClient() );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.gameType != GAME_TOURNEY )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int globalmax = -1;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int j = 1; j <= gameLocal.numClients; j++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int max = -1;
|
|
|
|
int imax = -1;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
if( currentTourneyPlayer[ 0 ] == i || currentTourneyPlayer[ 1 ] == i )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* p = static_cast< idPlayer* >( gameLocal.entities[ i ] );
|
|
|
|
if( !p || p->wantSpectate )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( p->tourneyRank > max && ( globalmax == -1 || p->tourneyRank < globalmax ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
max = p->tourneyRank;
|
|
|
|
imax = i;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( imax == -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idBitMsg outMsg;
|
|
|
|
byte msgBuf[1024];
|
|
|
|
outMsg.InitWrite( msgBuf, sizeof( msgBuf ) );
|
|
|
|
outMsg.WriteByte( j );
|
|
|
|
session->GetActingGameStateLobbyBase().SendReliableToLobbyUser( gameLocal.lobbyUserIDs[imax], GAME_RELIABLE_MESSAGE_TOURNEYLINE, outMsg );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
globalmax = max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::CycleTourneyPlayers
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::CycleTourneyPlayers( )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
idEntity* ent;
|
|
|
|
idPlayer* player;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
currentTourneyPlayer[ 0 ] = -1;
|
|
|
|
currentTourneyPlayer[ 1 ] = -1;
|
|
|
|
// if any, winner from last round will play again
|
2012-11-28 15:47:07 +00:00
|
|
|
if( lastWinner != -1 )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ lastWinner ];
|
|
|
|
if( ent && ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
|
|
|
currentTourneyPlayer[ 0 ] = lastWinner;
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
FillTourneySlots( );
|
|
|
|
// force selected players in/out of the game and update the ranks
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0 ; i < gameLocal.numClients ; i++ )
|
|
|
|
{
|
|
|
|
if( currentTourneyPlayer[ 0 ] == i || currentTourneyPlayer[ 1 ] == i )
|
|
|
|
{
|
|
|
|
player = static_cast<idPlayer*>( gameLocal.entities[ i ] );
|
2012-11-26 18:58:24 +00:00
|
|
|
player->ServerSpectate( false );
|
2012-11-28 15:47:07 +00:00
|
|
|
idLib::Printf( "TOURNEY CycleTourneyPlayers:> Player %d On Deck \n", player->entityNumber );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ent = gameLocal.entities[ i ];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ent && ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
|
|
|
player = static_cast<idPlayer*>( gameLocal.entities[ i ] );
|
2012-11-26 18:58:24 +00:00
|
|
|
player->ServerSpectate( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
idLib::Printf( "TOURNEY CycleTourneyPlayers:> Player %d Benched \n", player->entityNumber );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UpdateTourneyLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::Warmup
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idMultiplayerGame::Warmup()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ( gameState == WARMUP );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::GameHasBeenWon()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
// Only allow leaderboard submissions within public games.
|
|
|
|
const idMatchParameters& matchParameters = session->GetActingGameStateLobbyBase().GetMatchParms();
|
|
|
|
|
|
|
|
if( matchParameters.matchFlags & MATCH_RANKED )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Upload all player's scores to the leaderboard.
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int playerIdx = 0; playerIdx < gameLocal.numClients; playerIdx++ )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
leaderboardStats_t stats = { playerState[ playerIdx ].fragCount, playerState[ playerIdx ].wins, playerState[ playerIdx ].teamFragCount, playerState[ playerIdx].deaths };
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
LeaderboardLocal_Upload( gameLocal.lobbyUserIDs[ playerIdx ], gameLocal.gameType, stats );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Flush all the collectively queued leaderboards all at once. ( Otherwise you get a busy signal on the second "flush" )
|
|
|
|
session->LeaderboardFlush();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
// Award Any players that have not died. An Achievement
|
|
|
|
for( int i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
idPlayer* player = static_cast< idPlayer* >( gameLocal.entities[ i ] );
|
|
|
|
if( player == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Only validate players that were in the tourney.
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.gameType == GAME_TOURNEY )
|
|
|
|
{
|
|
|
|
if( i != currentTourneyPlayer[ 0 ] && i != currentTourneyPlayer[ 1 ] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// In LMS, players that join mid-game will not have ever died
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.gameType == GAME_LASTMAN )
|
|
|
|
{
|
|
|
|
if( playerState[i].fragCount == LASTMAN_NOLIVES )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( playerState[ i ].deaths == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
player->GetAchievementManager().EventCompletesAchievement( ACHIEVEMENT_MP_COMPLETE_MATCH_WITHOUT_DYING );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::Run
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::Run()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, timeLeft;
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* player;
|
2012-11-26 18:58:24 +00:00
|
|
|
int gameReviewPause;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( common->IsMultiplayer() );
|
|
|
|
assert( !common->IsClient() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
pureReady = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameState == INACTIVE )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState( WARMUP );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
CheckRespawns();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( nextState != INACTIVE && gameLocal.serverTime > nextStateSwitch )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState( nextState );
|
|
|
|
nextState = INACTIVE;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idLobbyBase& lobby = session->GetActingGameStateLobbyBase();
|
|
|
|
for( i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
idPlayer* player = static_cast<idPlayer*>( gameLocal.entities[i] );
|
|
|
|
if( player != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playerState[i].ping = lobby.GetLobbyUserQoS( gameLocal.lobbyUserIDs[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
switch( gameState )
|
|
|
|
{
|
|
|
|
case GAMEREVIEW:
|
|
|
|
{
|
|
|
|
if( nextState == INACTIVE )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameReviewPause = cvarSystem->GetCVarInteger( "g_gameReviewPause" );
|
|
|
|
nextState = NEXTGAME;
|
|
|
|
nextStateSwitch = gameLocal.serverTime + 1000 * gameReviewPause;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case NEXTGAME:
|
|
|
|
{
|
|
|
|
if( nextState == INACTIVE )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// make sure flags are returned
|
2012-11-28 15:47:07 +00:00
|
|
|
if( IsGametypeFlagBased() )
|
|
|
|
{
|
|
|
|
idItemTeam* flag;
|
2012-11-26 18:58:24 +00:00
|
|
|
flag = GetTeamFlag( 0 );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( flag )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
flag->Return();
|
|
|
|
}
|
|
|
|
flag = GetTeamFlag( 1 );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( flag )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
flag->Return();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NewState( WARMUP );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.gameType == GAME_TOURNEY )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
CycleTourneyPlayers();
|
|
|
|
}
|
|
|
|
// put everyone back in from endgame spectate
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( ent && ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
|
|
|
if( !static_cast< idPlayer* >( ent )->wantSpectate )
|
|
|
|
{
|
|
|
|
CheckRespawns( static_cast<idPlayer*>( ent ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case WARMUP:
|
|
|
|
{
|
|
|
|
if( EnoughClientsToPlay() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState( COUNTDOWN );
|
|
|
|
nextState = GAMEON;
|
|
|
|
nextStateSwitch = gameLocal.serverTime + 1000 * cvarSystem->GetCVarInteger( "g_countDown" );
|
|
|
|
}
|
|
|
|
one = two = three = false;
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case COUNTDOWN:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
timeLeft = ( nextStateSwitch - gameLocal.serverTime ) / 1000 + 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( timeLeft == 3 && !three )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PlayGlobalSound( -1, SND_THREE );
|
|
|
|
three = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( timeLeft == 2 && !two )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PlayGlobalSound( -1, SND_TWO );
|
|
|
|
two = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( timeLeft == 1 && !one )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PlayGlobalSound( -1, SND_ONE );
|
|
|
|
one = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case GAMEON:
|
|
|
|
{
|
|
|
|
if( IsGametypeFlagBased() ) /* CTF */
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// totally different logic branch for CTF
|
2012-11-28 15:47:07 +00:00
|
|
|
if( PointLimitHit() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int team = WinningTeam();
|
|
|
|
assert( team != -1 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState( GAMEREVIEW, NULL );
|
|
|
|
PrintMessageEvent( MSG_POINTLIMIT, team );
|
|
|
|
GameHasBeenWon();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else if( TimeLimitHit() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int team = WinningTeam();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( EnoughClientsToPlay() && team == -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState( SUDDENDEATH );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NewState( GAMEREVIEW, NULL );
|
2012-11-26 18:58:24 +00:00
|
|
|
PrintMessageEvent( MSG_TIMELIMIT );
|
|
|
|
GameHasBeenWon();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
player = FragLimitHit();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( player )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// delay between detecting frag limit and ending game. let the death anims play
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !fragLimitTimeout )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->DPrintf( "enter FragLimit timeout, player %d is leader\n", player->entityNumber );
|
|
|
|
fragLimitTimeout = gameLocal.serverTime + FRAGLIMIT_DELAY;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.serverTime > fragLimitTimeout )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState( GAMEREVIEW, player );
|
|
|
|
PrintMessageEvent( MSG_FRAGLIMIT, IsGametypeTeamBased() ? player->team : player->entityNumber );
|
|
|
|
GameHasBeenWon();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( fragLimitTimeout )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// frag limit was hit and cancelled. means the two teams got even during FRAGLIMIT_DELAY
|
|
|
|
// enter sudden death, the next frag leader will win
|
|
|
|
SuddenRespawn();
|
|
|
|
PrintMessageEvent( MSG_HOLYSHIT );
|
|
|
|
fragLimitTimeout = 0;
|
|
|
|
NewState( SUDDENDEATH );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( TimeLimitHit() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
player = FragLeader();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !player )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState( SUDDENDEATH );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState( GAMEREVIEW, player );
|
|
|
|
PrintMessageEvent( MSG_TIMELIMIT );
|
|
|
|
GameHasBeenWon();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
BalanceTeams();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case SUDDENDEATH:
|
|
|
|
{
|
|
|
|
if( IsGametypeFlagBased() ) /* CTF */
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int team = WinningTeam();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( team != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// TODO : implement pointLimitTimeout
|
|
|
|
NewState( GAMEREVIEW, NULL );
|
|
|
|
PrintMessageEvent( MSG_POINTLIMIT, team );
|
|
|
|
GameHasBeenWon();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
player = FragLeader();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( player )
|
|
|
|
{
|
|
|
|
if( !fragLimitTimeout )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->DPrintf( "enter sudden death FragLeader timeout, player %d is leader\n", player->entityNumber );
|
|
|
|
fragLimitTimeout = gameLocal.serverTime + FRAGLIMIT_DELAY;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.serverTime > fragLimitTimeout )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState( GAMEREVIEW, player );
|
|
|
|
PrintMessageEvent( MSG_FRAGLIMIT, IsGametypeTeamBased() ? player->team : player->entityNumber );
|
|
|
|
GameHasBeenWon();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( fragLimitTimeout )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SuddenRespawn();
|
|
|
|
PrintMessageEvent( MSG_HOLYSHIT );
|
|
|
|
fragLimitTimeout = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::Draw
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idMultiplayerGame::Draw( int clientNum )
|
|
|
|
{
|
|
|
|
idPlayer* player, *viewPlayer;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// clear the render entities for any players that don't need
|
|
|
|
// icons and which might not be thinking because they weren't in
|
|
|
|
// the last snapshot.
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
player = static_cast<idPlayer*>( gameLocal.entities[ i ] );
|
|
|
|
if( player && !player->NeedsIcon() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
player->HidePlayerIcons();
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
player = viewPlayer = static_cast<idPlayer*>( gameLocal.entities[ clientNum ] );
|
|
|
|
|
|
|
|
if( player == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( player->spectating )
|
|
|
|
{
|
|
|
|
viewPlayer = static_cast<idPlayer*>( gameLocal.entities[ player->spectator ] );
|
|
|
|
if( viewPlayer == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
// if the player you are viewing is holding a flag, hide it.
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity* flag = GetTeamFlag( viewPlayer->team ? 0 : 1 );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( flag )
|
|
|
|
{
|
|
|
|
if( viewPlayer->carryingFlag )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
flag->Hide();
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
flag->Show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
UpdatePlayerRanks();
|
|
|
|
UpdateHud( viewPlayer, player->hudManager );
|
|
|
|
// use the hud of the local player
|
|
|
|
viewPlayer->playerView.RenderPlayerView( player->hudManager );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr spectatetext[ 2 ];
|
|
|
|
GetSpectateText( player, spectatetext, true );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( scoreboardManager != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardManager->UpdateSpectating( spectatetext[0].c_str(), spectatetext[1].c_str() );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
DrawChat( player );
|
|
|
|
DrawScoreBoard( player );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::GetSpectateText
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::GetSpectateText( idPlayer* player, idStr spectatetext[ 2 ], bool scoreboard )
|
|
|
|
{
|
|
|
|
if( !player->spectating )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( player->wantSpectate && !scoreboard )
|
|
|
|
{
|
|
|
|
if( gameLocal.gameType == GAME_LASTMAN && gameState == GAMEON )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// If we're in GAMEON in lastman, you can't actully spawn, or you'll have an unfair
|
|
|
|
// advantage with more lives than everyone else.
|
|
|
|
spectatetext[ 0 ] = idLocalization::GetString( "#str_04246" );
|
|
|
|
spectatetext[ 0 ] += idLocalization::GetString( "#str_07003" );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
if( gameLocal.gameType == GAME_TOURNEY &&
|
|
|
|
( currentTourneyPlayer[0] != -1 && currentTourneyPlayer[1] != -1 ) &&
|
|
|
|
( currentTourneyPlayer[0] != player->entityNumber && currentTourneyPlayer[1] != player->entityNumber ) )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
spectatetext[ 0 ] = idLocalization::GetString( "#str_04246" );
|
2012-11-28 15:47:07 +00:00
|
|
|
switch( player->tourneyLine )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
spectatetext[ 0 ] += idLocalization::GetString( "#str_07003" );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
spectatetext[ 0 ] += idLocalization::GetString( "#str_07004" );
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
spectatetext[ 0 ] += idLocalization::GetString( "#str_07005" );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
spectatetext[ 0 ] += va( idLocalization::GetString( "#str_07006" ), player->tourneyLine );
|
|
|
|
break;
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
spectatetext[ 0 ] = idLocalization::GetString( "#str_respawn_message" );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( gameLocal.gameType == GAME_TOURNEY )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
spectatetext[ 0 ] = idLocalization::GetString( "#str_04246" );
|
2012-11-28 15:47:07 +00:00
|
|
|
switch( player->tourneyLine )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
case 0:
|
|
|
|
spectatetext[ 0 ] += idLocalization::GetString( "#str_07003" );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
spectatetext[ 0 ] += idLocalization::GetString( "#str_07004" );
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
spectatetext[ 0 ] += idLocalization::GetString( "#str_07005" );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
spectatetext[ 0 ] += va( idLocalization::GetString( "#str_07006" ), player->tourneyLine );
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( gameLocal.gameType == GAME_LASTMAN )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
spectatetext[ 0 ] = idLocalization::GetString( "#str_07007" );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
spectatetext[ 0 ] = idLocalization::GetString( "#str_04246" );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( player->spectator != player->entityNumber )
|
|
|
|
{
|
|
|
|
idLobbyBase& lobby = session->GetActingGameStateLobbyBase();
|
2012-11-26 18:58:24 +00:00
|
|
|
spectatetext[ 1 ] = va( idLocalization::GetString( "#str_07008" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[ player->spectator ] ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::UpdateHud
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::UpdateHud( idPlayer* player, idMenuHandler_HUD* hudManager )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( hudManager && hudManager->GetHud() )
|
|
|
|
{
|
|
|
|
|
|
|
|
idMenuScreen_HUD* hud = hudManager->GetHud();
|
|
|
|
|
|
|
|
if( Warmup() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
hud->UpdateMessage( true, "#str_04251" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( IsGametypeTeamBased() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
hud->SetTeamScore( 0, 0 );
|
|
|
|
hud->SetTeamScore( 1, 0 );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else if( gameState == SUDDENDEATH )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
hud->UpdateMessage( true, "#str_04252" );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
hud->UpdateGameTime( GameTime() );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( IsGametypeTeamBased() || IsGametypeFlagBased() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
hud->ToggleMPInfo( true, true, IsGametypeFlagBased() );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
hud->ToggleMPInfo( true, false );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameState == GAMEON || gameState == COUNTDOWN || gameState == WARMUP )
|
|
|
|
{
|
|
|
|
if( IsGametypeTeamBased() && !IsGametypeFlagBased() )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < gameLocal.numClients; ++i )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( ent == NULL || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idPlayer* player = static_cast< idPlayer* >( ent );
|
2012-11-26 18:58:24 +00:00
|
|
|
hud->SetTeamScore( player->team, playerState[ player->entityNumber ].teamFragCount );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( IsGametypeFlagBased() || IsGametypeTeamBased() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
hud->SetTeam( player->team );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
hud->SetTeam( -1 );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::SetScoreboardActive
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::SetScoreboardActive( bool active )
|
|
|
|
{
|
|
|
|
if( scoreboardManager != NULL )
|
|
|
|
{
|
|
|
|
if( active )
|
|
|
|
{
|
|
|
|
if( IsGametypeTeamBased() || IsGametypeFlagBased() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardManager->SetActivationScreen( SCOREBOARD_AREA_TEAM, MENU_TRANSITION_SIMPLE );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardManager->SetActivationScreen( SCOREBOARD_AREA_DEFAULT, MENU_TRANSITION_SIMPLE );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardManager->ActivateMenu( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardManager->ActivateMenu( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::DrawScoreBoard
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::DrawScoreBoard( idPlayer* player )
|
|
|
|
{
|
|
|
|
if( scoreboardManager && scoreboardManager->IsActive() == true )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
UpdateScoreboard( scoreboardManager, player );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idMultiplayerGame::ClearChatData
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::ClearChatData()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
chatHistoryIndex = 0;
|
|
|
|
chatHistorySize = 0;
|
|
|
|
chatDataUpdated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idMultiplayerGame::AddChatLine
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::AddChatLine( const char* fmt, ... )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr temp;
|
|
|
|
va_list argptr;
|
|
|
|
|
|
|
|
va_start( argptr, fmt );
|
|
|
|
vsprintf( temp, fmt, argptr );
|
|
|
|
va_end( argptr );
|
|
|
|
|
|
|
|
gameLocal.Printf( "%s\n", temp.c_str() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
chatHistory[ chatHistoryIndex % NUM_CHAT_NOTIFY ].line = temp;
|
|
|
|
chatHistory[ chatHistoryIndex % NUM_CHAT_NOTIFY ].fade = 6;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
chatHistoryIndex++;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( chatHistorySize < NUM_CHAT_NOTIFY )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
chatHistorySize++;
|
|
|
|
}
|
|
|
|
chatDataUpdated = true;
|
|
|
|
lastChatLineTime = Sys_Milliseconds();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idMultiplayerGame::DrawChat
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::DrawChat( idPlayer* player )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, j;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( player )
|
|
|
|
{
|
|
|
|
if( Sys_Milliseconds() - lastChatLineTime > CHAT_FADE_TIME )
|
|
|
|
{
|
|
|
|
if( chatHistorySize > 0 )
|
|
|
|
{
|
|
|
|
for( i = chatHistoryIndex - chatHistorySize; i < chatHistoryIndex; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
chatHistory[ i % NUM_CHAT_NOTIFY ].fade--;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( chatHistory[ i % NUM_CHAT_NOTIFY ].fade < 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
chatHistorySize--; // this assumes the removals are always at the beginning
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chatDataUpdated = true;
|
|
|
|
}
|
|
|
|
lastChatLineTime = Sys_Milliseconds();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( chatDataUpdated )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
j = 0;
|
|
|
|
i = chatHistoryIndex - chatHistorySize;
|
2012-11-28 15:47:07 +00:00
|
|
|
while( i < chatHistoryIndex )
|
|
|
|
{
|
|
|
|
player->AddChatMessage( j, Min( 4, ( int )chatHistory[ i % NUM_CHAT_NOTIFY ].fade ), chatHistory[ i % NUM_CHAT_NOTIFY ].line );
|
|
|
|
j++;
|
|
|
|
i++;
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
while( j < NUM_CHAT_NOTIFY )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
player->ClearChatMessage( j );
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
chatDataUpdated = false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//D3XP: Adding one to frag count to allow for the negative flag in numbers greater than 255
|
2012-11-28 15:47:07 +00:00
|
|
|
const int ASYNC_PLAYER_FRAG_BITS = -( idMath::BitsForInteger( MP_PLAYER_MAXFRAGS - MP_PLAYER_MINFRAGS ) + 1 ); // player can have negative frags
|
2012-11-26 18:58:24 +00:00
|
|
|
const int ASYNC_PLAYER_WINS_BITS = idMath::BitsForInteger( MP_PLAYER_MAXWINS );
|
|
|
|
const int ASYNC_PLAYER_PING_BITS = idMath::BitsForInteger( MP_PLAYER_MAXPING );
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::WriteToSnapshot
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::WriteToSnapshot( idBitMsg& msg ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
|
|
|
int value;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// This is a hack - I need a place to read the lobby ids before the player entities are
|
|
|
|
// read (SpawnPlayer requires a valid lobby id for the player).
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < gameLocal.lobbyUserIDs.Num(); ++i )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.lobbyUserIDs[i].WriteToMsg( msg );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
msg.WriteByte( gameState );
|
|
|
|
msg.WriteLong( nextStateSwitch );
|
|
|
|
msg.WriteShort( currentTourneyPlayer[ 0 ] );
|
|
|
|
msg.WriteShort( currentTourneyPlayer[ 1 ] );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < MAX_CLIENTS; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// clamp all values to min/max possible value that we can send over
|
|
|
|
value = idMath::ClampInt( MP_PLAYER_MINFRAGS, MP_PLAYER_MAXFRAGS, playerState[i].fragCount );
|
|
|
|
msg.WriteBits( value, ASYNC_PLAYER_FRAG_BITS );
|
|
|
|
value = idMath::ClampInt( MP_PLAYER_MINFRAGS, MP_PLAYER_MAXFRAGS, playerState[i].teamFragCount );
|
|
|
|
msg.WriteBits( value, ASYNC_PLAYER_FRAG_BITS );
|
|
|
|
value = idMath::ClampInt( 0, MP_PLAYER_MAXWINS, playerState[i].wins );
|
|
|
|
msg.WriteBits( value, ASYNC_PLAYER_WINS_BITS );
|
|
|
|
value = idMath::ClampInt( 0, MP_PLAYER_MAXPING, playerState[i].ping );
|
|
|
|
msg.WriteBits( value, ASYNC_PLAYER_PING_BITS );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
msg.WriteShort( teamPoints[0] );
|
|
|
|
msg.WriteShort( teamPoints[1] );
|
|
|
|
msg.WriteShort( player_red_flag );
|
|
|
|
msg.WriteShort( player_blue_flag );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::ReadFromSnapshot
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::ReadFromSnapshot( const idBitMsg& msg )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
|
|
|
gameState_t newState;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// This is a hack - I need a place to read the lobby ids before the player entities are
|
|
|
|
// read (SpawnPlayer requires a valid lobby id for the player).
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < gameLocal.lobbyUserIDs.Num(); ++i )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.lobbyUserIDs[i].ReadFromMsg( msg );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
newState = ( idMultiplayerGame::gameState_t )msg.ReadByte();
|
2012-11-26 18:58:24 +00:00
|
|
|
nextStateSwitch = msg.ReadLong();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( newState != gameState && newState < STATE_COUNT )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.DPrintf( "%s -> %s\n", GameStateStrings[ gameState ], GameStateStrings[ newState ] );
|
|
|
|
gameState = newState;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
switch( gameState )
|
|
|
|
{
|
|
|
|
case GAMEON:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState_GameOn_ServerAndClient();
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case GAMEREVIEW:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState_GameReview_ServerAndClient();
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case WARMUP:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState_Warmup_ServerAndClient();
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case COUNTDOWN:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState_Countdown_ServerAndClient();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentTourneyPlayer[ 0 ] = msg.ReadShort();
|
|
|
|
currentTourneyPlayer[ 1 ] = msg.ReadShort();
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < MAX_CLIENTS; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playerState[i].fragCount = msg.ReadBits( ASYNC_PLAYER_FRAG_BITS );
|
|
|
|
playerState[i].teamFragCount = msg.ReadBits( ASYNC_PLAYER_FRAG_BITS );
|
|
|
|
playerState[i].wins = msg.ReadBits( ASYNC_PLAYER_WINS_BITS );
|
|
|
|
playerState[i].ping = msg.ReadBits( ASYNC_PLAYER_PING_BITS );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
teamPoints[0] = msg.ReadShort();
|
|
|
|
teamPoints[1] = msg.ReadShort();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
player_red_flag = msg.ReadShort();
|
|
|
|
player_blue_flag = msg.ReadShort();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::PlayGlobalSound
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::PlayGlobalSound( int toPlayerNum, snd_evt_t evt, const char* shader )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( toPlayerNum < 0 || toPlayerNum == gameLocal.GetLocalClientNum() )
|
|
|
|
{
|
|
|
|
if( shader )
|
|
|
|
{
|
|
|
|
if( gameSoundWorld )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameSoundWorld->PlayShaderDirectly( shader );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( gameSoundWorld )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ evt ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !common->IsClient() && toPlayerNum != gameLocal.GetLocalClientNum() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idBitMsg outMsg;
|
|
|
|
byte msgBuf[1024];
|
|
|
|
outMsg.InitWrite( msgBuf, sizeof( msgBuf ) );
|
|
|
|
int type = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( shader )
|
|
|
|
{
|
|
|
|
const idSoundShader* shaderDecl = declManager->FindSound( shader );
|
|
|
|
if( !shaderDecl )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
outMsg.WriteLong( gameLocal.ServerRemapDecl( -1, DECL_SOUND, shaderDecl->Index() ) );
|
|
|
|
type = GAME_RELIABLE_MESSAGE_SOUND_INDEX;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
outMsg.WriteByte( evt );
|
|
|
|
type = GAME_RELIABLE_MESSAGE_SOUND_EVENT;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( toPlayerNum >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
session->GetActingGameStateLobbyBase().SendReliableToLobbyUser( gameLocal.lobbyUserIDs[toPlayerNum], type, outMsg );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
session->GetActingGameStateLobbyBase().SendReliable( type, outMsg, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::PlayTeamSound
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::PlayTeamSound( int toTeam, snd_evt_t evt, const char* shader )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* player = static_cast<idPlayer*>( ent );
|
|
|
|
if( player->team != toTeam )
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
PlayGlobalSound( i, evt, shader );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::PrintMessageEvent
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::PrintMessageEvent( msg_evt_t evt, int parm1, int parm2 )
|
|
|
|
{
|
|
|
|
idLobbyBase& lobby = session->GetActingGameStateLobbyBase();
|
|
|
|
|
|
|
|
switch( evt )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
case MSG_LEFTGAME:
|
|
|
|
assert( parm1 >= 0 );
|
|
|
|
AddChatLine( idLocalization::GetString( "#str_11604" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm1] ) );
|
|
|
|
break;
|
|
|
|
case MSG_SUICIDE:
|
|
|
|
assert( parm1 >= 0 );
|
|
|
|
AddChatLine( idLocalization::GetString( "#str_04293" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm1] ) );
|
|
|
|
break;
|
|
|
|
case MSG_KILLED:
|
|
|
|
assert( parm1 >= 0 && parm2 >= 0 );
|
|
|
|
AddChatLine( idLocalization::GetString( "#str_04292" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm1] ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm2] ) );
|
|
|
|
break;
|
|
|
|
case MSG_KILLEDTEAM:
|
|
|
|
assert( parm1 >= 0 && parm2 >= 0 );
|
|
|
|
AddChatLine( idLocalization::GetString( "#str_04291" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm1] ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm2] ) );
|
|
|
|
break;
|
|
|
|
case MSG_TELEFRAGGED:
|
|
|
|
assert( parm1 >= 0 && parm2 >= 0 );
|
|
|
|
AddChatLine( idLocalization::GetString( "#str_04290" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm1] ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm2] ) );
|
|
|
|
break;
|
|
|
|
case MSG_DIED:
|
|
|
|
assert( parm1 >= 0 );
|
|
|
|
AddChatLine( idLocalization::GetString( "#str_04289" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm1] ) );
|
|
|
|
break;
|
|
|
|
case MSG_SUDDENDEATH:
|
|
|
|
AddChatLine( idLocalization::GetString( "#str_04287" ) );
|
|
|
|
break;
|
|
|
|
case MSG_JOINEDSPEC:
|
|
|
|
AddChatLine( idLocalization::GetString( "#str_04285" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm1] ) );
|
|
|
|
break;
|
|
|
|
case MSG_TIMELIMIT:
|
|
|
|
AddChatLine( idLocalization::GetString( "#str_04284" ) );
|
|
|
|
break;
|
|
|
|
case MSG_FRAGLIMIT:
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.gameType == GAME_LASTMAN )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( idLocalization::GetString( "#str_04283" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm1] ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( IsGametypeTeamBased() ) /* CTF */
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( idLocalization::GetString( "#str_04282" ), idLocalization::GetString( teamNames[ parm1 ] ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( idLocalization::GetString( "#str_04281" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm1] ) );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MSG_JOINTEAM:
|
|
|
|
AddChatLine( idLocalization::GetString( "#str_04280" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm1] ), parm2 ? idLocalization::GetString( "#str_02500" ) : idLocalization::GetString( "#str_02499" ) );
|
|
|
|
break;
|
|
|
|
case MSG_HOLYSHIT:
|
|
|
|
AddChatLine( idLocalization::GetString( "#str_06732" ) );
|
|
|
|
break;
|
|
|
|
case MSG_POINTLIMIT:
|
2012-11-28 15:47:07 +00:00
|
|
|
AddChatLine( idLocalization::GetString( "#str_11100" ), parm1 ? idLocalization::GetString( "#str_11110" ) : idLocalization::GetString( "#str_11111" ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
case MSG_FLAGTAKEN :
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.GetLocalPlayer() == NULL )
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( parm2 < 0 || parm2 >= MAX_CLIENTS )
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameLocal.GetLocalPlayer()->team != parm1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( idLocalization::GetString( "#str_11101" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm2] ) ); // your team
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( idLocalization::GetString( "#str_11102" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm2] ) ); // enemy
|
|
|
|
}
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
case MSG_FLAGDROP :
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.GetLocalPlayer() == NULL )
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameLocal.GetLocalPlayer()->team != parm1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( idLocalization::GetString( "#str_11103" ) ); // your team
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( idLocalization::GetString( "#str_11104" ) ); // enemy
|
|
|
|
}
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
case MSG_FLAGRETURN :
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.GetLocalPlayer() == NULL )
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( parm2 >= 0 && parm2 < MAX_CLIENTS )
|
|
|
|
{
|
|
|
|
if( gameLocal.GetLocalPlayer()->team != parm1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( idLocalization::GetString( "#str_11120" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm2] ) ); // your team
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( idLocalization::GetString( "#str_11121" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm2] ) ); // enemy
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AddChatLine( idLocalization::GetString( "#str_11105" ), parm1 ? idLocalization::GetString( "#str_11110" ) : idLocalization::GetString( "#str_11111" ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
case MSG_FLAGCAPTURE :
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.GetLocalPlayer() == NULL )
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( parm2 < 0 || parm2 >= MAX_CLIENTS )
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameLocal.GetLocalPlayer()->team != parm1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( idLocalization::GetString( "#str_11122" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm2] ) ); // your team
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( idLocalization::GetString( "#str_11123" ), lobby.GetLobbyUserName( gameLocal.lobbyUserIDs[parm2] ) ); // enemy
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
// AddChatLine( idLocalization::GetString( "#str_11106" ), parm1 ? idLocalization::GetString( "#str_11110" ) : idLocalization::GetString( "#str_11111" ) );
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
case MSG_SCOREUPDATE:
|
|
|
|
AddChatLine( idLocalization::GetString( "#str_11107" ), parm1, parm2 );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gameLocal.DPrintf( "PrintMessageEvent: unknown message type %d\n", evt );
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !common->IsClient() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idBitMsg outMsg;
|
|
|
|
byte msgBuf[1024];
|
|
|
|
outMsg.InitWrite( msgBuf, sizeof( msgBuf ) );
|
|
|
|
outMsg.WriteByte( evt );
|
|
|
|
outMsg.WriteByte( parm1 );
|
|
|
|
outMsg.WriteByte( parm2 );
|
|
|
|
session->GetActingGameStateLobbyBase().SendReliable( GAME_RELIABLE_MESSAGE_DB, outMsg, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::SuddenRespawns
|
|
|
|
solely for LMN if an end game ( fragLimitTimeout ) was entered and aborted before expiration
|
|
|
|
LMN players which still have lives left need to be respawned without being marked lastManOver
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::SuddenRespawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameLocal.gameType != GAME_LASTMAN )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
if( !gameLocal.entities[ i ] || !gameLocal.entities[ i ]->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !CanPlay( static_cast< idPlayer* >( gameLocal.entities[ i ] ) ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( static_cast< idPlayer* >( gameLocal.entities[ i ] )->lastManOver )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
static_cast< idPlayer* >( gameLocal.entities[ i ] )->lastManPlayAgain = true;
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::CheckSpawns
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::CheckRespawns( idPlayer* spectator )
|
|
|
|
{
|
|
|
|
for( int i = 0 ; i < gameLocal.numClients ; i++ )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* p = static_cast<idPlayer*>( ent );
|
2012-11-26 18:58:24 +00:00
|
|
|
// once we hit sudden death, nobody respawns till game has ended
|
2012-11-28 15:47:07 +00:00
|
|
|
if( WantRespawn( p ) || p == spectator )
|
|
|
|
{
|
|
|
|
if( gameState == SUDDENDEATH && gameLocal.gameType != GAME_LASTMAN )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// respawn rules while sudden death are different
|
|
|
|
// sudden death may trigger while a player is dead, so there are still cases where we need to respawn
|
|
|
|
// don't do any respawns while we are in end game delay though
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !fragLimitTimeout )
|
|
|
|
{
|
|
|
|
if( IsGametypeTeamBased() || p->IsLeader() ) /* CTF */
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
#ifdef _DEBUG
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.gameType == GAME_TOURNEY )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( p->entityNumber == currentTourneyPlayer[ 0 ] || p->entityNumber == currentTourneyPlayer[ 1 ] );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
p->ServerSpectate( false );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( !p->IsLeader() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// sudden death is rolling, this player is not a leader, have him spectate
|
|
|
|
p->ServerSpectate( true );
|
|
|
|
CheckAbortGame();
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( gameLocal.gameType == GAME_DM || // CTF : 3wave sboily, was DM really included before?
|
|
|
|
IsGametypeTeamBased() )
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameState == WARMUP || gameState == COUNTDOWN || gameState == GAMEON )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
p->ServerSpectate( false );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( gameLocal.gameType == GAME_TOURNEY )
|
|
|
|
{
|
|
|
|
if( i == currentTourneyPlayer[ 0 ] || i == currentTourneyPlayer[ 1 ] )
|
|
|
|
{
|
|
|
|
if( gameState == WARMUP || gameState == COUNTDOWN || gameState == GAMEON )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
p->ServerSpectate( false );
|
2012-11-28 15:47:07 +00:00
|
|
|
idLib::Printf( "TOURNEY CheckRespawns :> Player %d On Deck \n", p->entityNumber );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( gameState == WARMUP )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// make sure empty tourney slots get filled first
|
|
|
|
FillTourneySlots( );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( i == currentTourneyPlayer[ 0 ] || i == currentTourneyPlayer[ 1 ] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
p->ServerSpectate( false );
|
2012-11-28 15:47:07 +00:00
|
|
|
idLib::Printf( "TOURNEY CheckRespawns WARMUP :> Player %d On Deck \n", p->entityNumber );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( gameLocal.gameType == GAME_LASTMAN )
|
|
|
|
{
|
|
|
|
if( gameState == WARMUP || gameState == COUNTDOWN )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// Player has spawned in game, give him lives.
|
|
|
|
playerState[ i ].fragCount = gameLocal.serverInfo.GetInt( "si_fragLimit" );
|
|
|
|
p->ServerSpectate( false );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( gameState == GAMEON || gameState == SUDDENDEATH )
|
|
|
|
{
|
|
|
|
if( gameState == GAMEON && playerState[ i ].fragCount > 0 && p->lastManPresent )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( !p->lastManOver );
|
|
|
|
p->ServerSpectate( false );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( p->lastManPlayAgain && p->lastManPresent )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( gameState == SUDDENDEATH );
|
|
|
|
p->ServerSpectate( false );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// if a fragLimitTimeout was engaged, do NOT mark lastManOver as that could mean
|
|
|
|
// everyone ends up spectator and game is stalled with no end
|
|
|
|
// if the frag limit delay is engaged and cancels out before expiring, LMN players are
|
|
|
|
// respawned to play the tie again ( through SuddenRespawn and lastManPlayAgain )
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !fragLimitTimeout && !p->lastManOver )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->DPrintf( "client %d has lost all last man lives\n", i );
|
|
|
|
// end of the game for this guy, send him to spectators
|
|
|
|
p->lastManOver = true;
|
|
|
|
// clients don't have access to lastManOver
|
|
|
|
// so set the fragCount to something silly ( used in scoreboard and player ranking )
|
|
|
|
playerState[ i ].fragCount = LASTMAN_NOLIVES;
|
|
|
|
p->ServerSpectate( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Check for a situation where the last two player dies at the same time and don't
|
|
|
|
//try to respawn manually...This was causing all players to go into spectate mode
|
|
|
|
//and the server got stuck
|
|
|
|
{
|
|
|
|
int j;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( j = 0; j < gameLocal.numClients; j++ )
|
|
|
|
{
|
|
|
|
if( !gameLocal.entities[ j ] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !CanPlay( static_cast< idPlayer* >( gameLocal.entities[ j ] ) ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !static_cast< idPlayer* >( gameLocal.entities[ j ] )->lastManOver )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( j == gameLocal.numClients )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Everyone is dead so don't allow this player to spectate
|
|
|
|
//so the match will end
|
|
|
|
p->ServerSpectate( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( p->wantSpectate && !p->spectating )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playerState[ i ].fragCount = 0; // whenever you willingly go spectate during game, your score resets
|
|
|
|
p->ServerSpectate( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
idLib::Printf( "TOURNEY CheckRespawns :> Player %d Wants Spectate \n", p->entityNumber );
|
2012-11-26 18:58:24 +00:00
|
|
|
UpdateTourneyLine();
|
|
|
|
CheckAbortGame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::DropWeapon
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::DropWeapon( int clientNum )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( !common->IsClient() );
|
2012-11-28 15:47:07 +00:00
|
|
|
idEntity* ent = gameLocal.entities[ clientNum ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
static_cast< idPlayer* >( ent )->DropWeapon( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::DropWeapon_f
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::DropWeapon_f( const idCmdArgs& args )
|
|
|
|
{
|
|
|
|
if( !common->IsMultiplayer() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "clientDropWeapon: only valid in multiplayer\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
idBitMsg outMsg;
|
|
|
|
session->GetActingGameStateLobbyBase().SendReliableToHost( GAME_RELIABLE_MESSAGE_DROPWEAPON, outMsg );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::MessageMode_f
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::MessageMode_f( const idCmdArgs& args )
|
|
|
|
{
|
|
|
|
if( !common->IsMultiplayer() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
gameLocal.mpGame.MessageMode( args );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::MessageMode
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::MessageMode( const idCmdArgs& args )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ gameLocal.GetLocalClientNum() ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* player = static_cast< idPlayer* >( ent );
|
|
|
|
if( player && !player->spectating )
|
|
|
|
{
|
|
|
|
if( args.Argc() != 2 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
player->isChatting = 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
player->isChatting = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::DisconnectClient
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::DisconnectClient( int clientNum )
|
|
|
|
{
|
|
|
|
if( lastWinner == clientNum )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
lastWinner = -1;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Show that the user has left the game.
|
|
|
|
PrintMessageEvent( MSG_LEFTGAME, clientNum, -1 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
UpdatePlayerRanks();
|
|
|
|
CheckAbortGame();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::CheckAbortGame
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::CheckAbortGame()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.gameType == GAME_TOURNEY && gameState == WARMUP )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// if a tourney player joined spectators, let someone else have his spot
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < 2; i++ )
|
|
|
|
{
|
|
|
|
if( !gameLocal.entities[ currentTourneyPlayer[ i ] ] || static_cast< idPlayer* >( gameLocal.entities[ currentTourneyPlayer[ i ] ] )->spectating )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
currentTourneyPlayer[ i ] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// only checks for aborts -> game review below
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameState != COUNTDOWN && gameState != GAMEON && gameState != SUDDENDEATH )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
switch( gameLocal.gameType )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
case GAME_TOURNEY:
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < 2; i++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
idPlayer* player = static_cast< idPlayer* >( gameLocal.entities[ currentTourneyPlayer[ i ] ] );
|
|
|
|
|
|
|
|
if( !gameLocal.entities[ currentTourneyPlayer[ i ] ] || player->spectating )
|
|
|
|
{
|
|
|
|
NewState( GAMEREVIEW );
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !EnoughClientsToPlay() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState( GAMEREVIEW );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::MapRestart
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::MapRestart()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
assert( !common->IsClient() );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameState != WARMUP )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
NewState( WARMUP );
|
|
|
|
nextState = INACTIVE;
|
|
|
|
nextStateSwitch = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
teamPoints[0] = 0;
|
|
|
|
teamPoints[1] = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
BalanceTeams();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::BalanceTeams
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::BalanceTeams()
|
|
|
|
{
|
|
|
|
if( !IsGametypeTeamBased() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int teamCount[ 2 ] = { 0, 0 };
|
|
|
|
NumActualClients( false, teamCount );
|
|
|
|
int outOfBalance = abs( teamCount[0] - teamCount[1] );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( outOfBalance <= 1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Teams are out of balance
|
|
|
|
// Move N players from the large team to the small team
|
|
|
|
int numPlayersToMove = outOfBalance / 2;
|
|
|
|
int smallTeam = MinIndex( teamCount[0], teamCount[1] );
|
|
|
|
int largeTeam = 1 - smallTeam;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idLobbyBase& lobby = session->GetActingGameStateLobbyBase();
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// First move players from the large team that match a party token on the small team
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int a = 0; a < gameLocal.numClients; a++ )
|
|
|
|
{
|
|
|
|
idPlayer* playerA = gameLocal.GetClientByNum( a );
|
|
|
|
if( playerA->team == largeTeam && CanPlay( playerA ) )
|
|
|
|
{
|
|
|
|
for( int b = 0; b < gameLocal.numClients; b++ )
|
|
|
|
{
|
|
|
|
if( a == b )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* playerB = gameLocal.GetClientByNum( b );
|
|
|
|
if( playerB->team == smallTeam && CanPlay( playerB ) )
|
|
|
|
{
|
|
|
|
if( lobby.GetLobbyUserPartyToken( gameLocal.lobbyUserIDs[ a ] ) == lobby.GetLobbyUserPartyToken( gameLocal.lobbyUserIDs[ b ] ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SwitchToTeam( a, largeTeam, smallTeam );
|
|
|
|
numPlayersToMove--;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( numPlayersToMove == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Then move players from the large team that DON'T match party tokens on the large team
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int a = 0; a < gameLocal.numClients; a++ )
|
|
|
|
{
|
|
|
|
idPlayer* playerA = gameLocal.GetClientByNum( a );
|
|
|
|
if( playerA->team == largeTeam && CanPlay( playerA ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bool match = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int b = 0; b < gameLocal.numClients; b++ )
|
|
|
|
{
|
|
|
|
if( a == b )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* playerB = gameLocal.GetClientByNum( b );
|
|
|
|
if( playerB->team == largeTeam && CanPlay( playerB ) )
|
|
|
|
{
|
|
|
|
if( lobby.GetLobbyUserPartyToken( gameLocal.lobbyUserIDs[ a ] ) == lobby.GetLobbyUserPartyToken( gameLocal.lobbyUserIDs[ b ] ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !match )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SwitchToTeam( a, largeTeam, smallTeam );
|
|
|
|
numPlayersToMove--;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( numPlayersToMove == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Then move any players from the large team to the small team
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int a = 0; a < gameLocal.numClients; a++ )
|
|
|
|
{
|
|
|
|
idPlayer* playerA = gameLocal.GetClientByNum( a );
|
|
|
|
if( playerA->team == largeTeam && CanPlay( playerA ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SwitchToTeam( a, largeTeam, smallTeam );
|
|
|
|
numPlayersToMove--;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( numPlayersToMove == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::SwitchToTeam
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::SwitchToTeam( int clientNum, int oldteam, int newteam )
|
|
|
|
{
|
|
|
|
idPlayer* p = static_cast<idPlayer*>( gameLocal.entities[ clientNum ] );
|
2012-11-26 18:58:24 +00:00
|
|
|
p->team = newteam;
|
|
|
|
session->GetActingGameStateLobbyBase().SetLobbyUserTeam( gameLocal.lobbyUserIDs[ clientNum ], newteam );
|
|
|
|
session->SetVoiceGroupsToTeams();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( IsGametypeTeamBased() ); /* CTF */
|
|
|
|
assert( oldteam != newteam );
|
|
|
|
assert( !common->IsClient() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !common->IsClient() && newteam >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PrintMessageEvent( MSG_JOINTEAM, clientNum, newteam );
|
|
|
|
}
|
|
|
|
// assign the right teamFragCount
|
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
if( i == clientNum )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( ent && ent->IsType( idPlayer::Type ) && static_cast< idPlayer* >( ent )->team == newteam )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playerState[ clientNum ].teamFragCount = playerState[ i ].teamFragCount;
|
|
|
|
break;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( i == gameLocal.numClients )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// alone on this team
|
|
|
|
playerState[ clientNum ].teamFragCount = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ( gameState == GAMEON || ( IsGametypeFlagBased() && gameState == SUDDENDEATH ) ) && oldteam != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// when changing teams during game, kill and respawn
|
2012-11-28 15:47:07 +00:00
|
|
|
if( p->IsInTeleport() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
p->ServerSendEvent( idPlayer::EVENT_ABORT_TELEPORTER, NULL, false );
|
|
|
|
p->SetPrivateCameraView( NULL );
|
|
|
|
}
|
|
|
|
p->Kill( true, true );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( IsGametypeFlagBased() )
|
2012-11-26 18:58:24 +00:00
|
|
|
p->DropFlag();
|
|
|
|
CheckAbortGame();
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( IsGametypeFlagBased() && oldteam != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
p->DropFlag();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::ProcessChatMessage
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::ProcessChatMessage( int clientNum, bool team, const char* name, const char* text, const char* sound )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idBitMsg outMsg;
|
|
|
|
byte msgBuf[ 256 ];
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* prefix = NULL;
|
2012-11-26 18:58:24 +00:00
|
|
|
int send_to; // 0 - all, 1 - specs, 2 - team
|
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
idEntity* ent;
|
|
|
|
idPlayer* pfrom;
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr prefixed_name;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( !common->IsClient() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( clientNum >= 0 )
|
|
|
|
{
|
|
|
|
pfrom = static_cast< idPlayer* >( gameLocal.entities[ clientNum ] );
|
|
|
|
if( !( pfrom && pfrom->IsType( idPlayer::Type ) ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( pfrom->spectating )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
prefix = "spectating";
|
2012-11-28 15:47:07 +00:00
|
|
|
if( team || ( !g_spectatorChat.GetBool() && ( gameState == GAMEON || gameState == SUDDENDEATH ) ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// to specs
|
|
|
|
send_to = 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// to all
|
|
|
|
send_to = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( team )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
prefix = "team";
|
|
|
|
// to team
|
|
|
|
send_to = 2;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// to all
|
|
|
|
send_to = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
pfrom = NULL;
|
|
|
|
send_to = 0;
|
|
|
|
}
|
|
|
|
// put the message together
|
|
|
|
outMsg.InitWrite( msgBuf, sizeof( msgBuf ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( prefix )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
prefixed_name = va( "(%s) %s", prefix, name );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
prefixed_name = name;
|
|
|
|
}
|
|
|
|
outMsg.WriteString( prefixed_name );
|
|
|
|
outMsg.WriteString( text, -1, false );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !send_to )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( "%s^0: %s\n", prefixed_name.c_str(), text );
|
|
|
|
session->GetActingGameStateLobbyBase().SendReliable( GAME_RELIABLE_MESSAGE_CHAT, outMsg, false );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( sound )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PlayGlobalSound( -1, SND_COUNT, sound );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
ent = gameLocal.entities[ i ];
|
|
|
|
if( !ent || !ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* pent = static_cast< idPlayer* >( ent );
|
|
|
|
if( send_to == 1 && pent->spectating )
|
|
|
|
{
|
|
|
|
if( sound )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PlayGlobalSound( i, SND_COUNT, sound );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( i == gameLocal.GetLocalClientNum() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( "%s^0: %s\n", prefixed_name.c_str(), text );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
session->GetActingGameStateLobbyBase().SendReliableToLobbyUser( gameLocal.lobbyUserIDs[i], GAME_RELIABLE_MESSAGE_CHAT, outMsg );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( send_to == 2 && pent->team == pfrom->team )
|
|
|
|
{
|
|
|
|
if( sound )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PlayGlobalSound( i, SND_COUNT, sound );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( i == gameLocal.GetLocalClientNum() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
AddChatLine( "%s^0: %s\n", prefixed_name.c_str(), text );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
session->GetActingGameStateLobbyBase().SendReliableToLobbyUser( gameLocal.lobbyUserIDs[i], GAME_RELIABLE_MESSAGE_CHAT, outMsg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::Precache
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::Precache()
|
|
|
|
{
|
|
|
|
if( !common->IsMultiplayer() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// player
|
|
|
|
declManager->FindType( DECL_ENTITYDEF, gameLocal.GetMPPlayerDefName(), false );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// skins
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < numSkins; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr baseSkinName = skinNames[ i ];
|
|
|
|
declManager->FindSkin( baseSkinName, false );
|
|
|
|
declManager->FindSkin( baseSkinName + "_berserk", false );
|
|
|
|
declManager->FindSkin( baseSkinName + "_invuln", false );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// MP game sounds
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < SND_COUNT; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
declManager->FindSound( GlobalSoundStrings[ i ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::ToggleSpectate
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::ToggleSpectate()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( common->IsClient() || gameLocal.GetLocalClientNum() == 0 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idPlayer* player = ( idPlayer* )gameLocal.entities[gameLocal.GetLocalClientNum()];
|
2012-11-26 18:58:24 +00:00
|
|
|
bool spectating = player->spectating;
|
|
|
|
// only allow toggling to spectate if spectators are enabled.
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !spectating && !gameLocal.serverInfo.GetBool( "si_spectators" ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.mpGame.AddChatLine( idLocalization::GetString( "#str_06747" ) );
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
byte msgBuf[ 256 ];
|
|
|
|
idBitMsg outMsg;
|
|
|
|
outMsg.InitWrite( msgBuf, sizeof( msgBuf ) );
|
|
|
|
outMsg.WriteBool( !spectating );
|
|
|
|
outMsg.WriteByteAlign();
|
|
|
|
session->GetActingGameStateLobbyBase().SendReliableToHost( GAME_RELIABLE_MESSAGE_SPECTATE, outMsg );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::CanPlay
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idMultiplayerGame::CanPlay( idPlayer* p )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return !p->wantSpectate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::WantRespawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idMultiplayerGame::WantRespawn( idPlayer* p )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return p->forceRespawn && !p->wantSpectate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::VoiceChat
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::VoiceChat_f( const idCmdArgs& args )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.mpGame.VoiceChat( args, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::VoiceChatTeam
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::VoiceChatTeam_f( const idCmdArgs& args )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.mpGame.VoiceChat( args, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::VoiceChat
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::VoiceChat( const idCmdArgs& args, bool team )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idBitMsg outMsg;
|
|
|
|
byte msgBuf[128];
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* voc;
|
|
|
|
const idDict* spawnArgs;
|
|
|
|
const idKeyValue* keyval;
|
2012-11-26 18:58:24 +00:00
|
|
|
int index;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !common->IsMultiplayer() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "clientVoiceChat: only valid in multiplayer\n" );
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( args.Argc() != 2 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "clientVoiceChat: bad args\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// throttle
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.realClientTime < voiceChatThrottle )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.GetLocalPlayer() == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
voc = args.Argv( 1 );
|
|
|
|
|
|
|
|
spawnArgs = &gameLocal.GetLocalPlayer()->spawnArgs;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
keyval = spawnArgs->MatchPrefix( "snd_voc_", NULL );
|
|
|
|
index = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
while( keyval )
|
|
|
|
{
|
|
|
|
if( !keyval->GetValue().Icmp( voc ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
keyval = spawnArgs->MatchPrefix( "snd_voc_", keyval );
|
|
|
|
index++;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !keyval )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "Voice command not found: %s\n", voc );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
voiceChatThrottle = gameLocal.realClientTime + 1000;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
outMsg.InitWrite( msgBuf, sizeof( msgBuf ) );
|
|
|
|
outMsg.WriteLong( index );
|
|
|
|
outMsg.WriteBits( team ? 1 : 0, 1 );
|
|
|
|
session->GetActingGameStateLobbyBase().SendReliableToHost( GAME_RELIABLE_MESSAGE_VCHAT, outMsg );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::ProcessVoiceChat
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::ProcessVoiceChat( int clientNum, bool team, int index )
|
|
|
|
{
|
|
|
|
const idDict* spawnArgs;
|
|
|
|
const idKeyValue* keyval;
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr name;
|
|
|
|
idStr snd_key;
|
|
|
|
idStr text_key;
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* p;
|
|
|
|
|
|
|
|
p = static_cast< idPlayer* >( gameLocal.entities[ clientNum ] );
|
|
|
|
if( !( p && p->IsType( idPlayer::Type ) ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( p->spectating )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// lookup the sound def
|
|
|
|
spawnArgs = &p->spawnArgs;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
keyval = spawnArgs->MatchPrefix( "snd_voc_", NULL );
|
2012-11-28 15:47:07 +00:00
|
|
|
while( index > 0 && keyval )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
keyval = spawnArgs->MatchPrefix( "snd_voc_", keyval );
|
|
|
|
index--;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !keyval )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->DPrintf( "ProcessVoiceChat: unknown chat index %d\n", index );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
snd_key = keyval->GetKey();
|
|
|
|
name = session->GetActingGameStateLobbyBase().GetLobbyUserName( gameLocal.lobbyUserIDs[ clientNum ] );
|
|
|
|
sprintf( text_key, "txt_%s", snd_key.Right( snd_key.Length() - 4 ).c_str() );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( team || gameState == COUNTDOWN || gameState == GAMEREVIEW )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ProcessChatMessage( clientNum, team, name, spawnArgs->GetString( text_key ), spawnArgs->GetString( snd_key ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
p->StartSound( snd_key, SND_CHANNEL_ANY, 0, true, NULL );
|
|
|
|
ProcessChatMessage( clientNum, team, name, spawnArgs->GetString( text_key ), NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::ServerWriteInitialReliableMessages
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::ServerWriteInitialReliableMessages( int clientNum, lobbyUserID_t lobbyUserID )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idBitMsg outMsg;
|
|
|
|
byte msgBuf[ MAX_GAME_MESSAGE_SIZE ];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
outMsg.InitWrite( msgBuf, sizeof( msgBuf ) );
|
|
|
|
outMsg.BeginWriting();
|
|
|
|
// send the game state and start time
|
|
|
|
outMsg.WriteByte( gameState );
|
|
|
|
outMsg.WriteLong( matchStartedTime );
|
|
|
|
outMsg.WriteShort( startFragLimit );
|
|
|
|
// send the powerup states and the spectate states
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < gameLocal.numClients; i++ )
|
|
|
|
{
|
|
|
|
idEntity* ent = gameLocal.entities[ i ];
|
|
|
|
if( i != clientNum && ent && ent->IsType( idPlayer::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
outMsg.WriteByte( i );
|
2012-11-28 15:47:07 +00:00
|
|
|
outMsg.WriteBits( static_cast< idPlayer* >( ent )->inventory.powerups, 15 );
|
|
|
|
outMsg.WriteBits( static_cast< idPlayer* >( ent )->spectating, 1 );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
outMsg.WriteByte( MAX_CLIENTS );
|
|
|
|
session->GetActingGameStateLobbyBase().SendReliableToLobbyUser( lobbyUserID, GAME_RELIABLE_MESSAGE_STARTSTATE, outMsg );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// warmup time
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameState == COUNTDOWN )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
outMsg.BeginWriting();
|
|
|
|
outMsg.WriteByte( GAME_RELIABLE_MESSAGE_WARMUPTIME );
|
|
|
|
outMsg.WriteLong( warmupEndTime );
|
|
|
|
session->GetActingGameStateLobbyBase().SendReliableToLobbyUser( lobbyUserID, GAME_RELIABLE_MESSAGE_WARMUPTIME, outMsg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::ClientReadStartState
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::ClientReadStartState( const idBitMsg& msg )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// read the state in preparation for reading snapshot updates
|
2012-11-28 15:47:07 +00:00
|
|
|
gameState = ( idMultiplayerGame::gameState_t )msg.ReadByte();
|
2012-11-26 18:58:24 +00:00
|
|
|
matchStartedTime = msg.ReadLong( );
|
|
|
|
startFragLimit = msg.ReadShort( );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int client;
|
2012-11-28 15:47:07 +00:00
|
|
|
while( ( client = msg.ReadByte() ) != MAX_CLIENTS )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Do not process players that are not here.
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameLocal.entities[ client ] == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( gameLocal.entities[ client ] && gameLocal.entities[ client ]->IsType( idPlayer::Type ) );
|
|
|
|
int powerup = msg.ReadBits( 15 );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < MAX_POWERUPS; i++ )
|
|
|
|
{
|
|
|
|
if( powerup & ( 1 << i ) )
|
|
|
|
{
|
|
|
|
static_cast< idPlayer* >( gameLocal.entities[ client ] )->GivePowerUp( i, 0, ITEM_GIVE_FEEDBACK | ITEM_GIVE_UPDATE_STATE );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bool spectate = ( msg.ReadBits( 1 ) != 0 );
|
2012-11-28 15:47:07 +00:00
|
|
|
static_cast< idPlayer* >( gameLocal.entities[ client ] )->Spectate( spectate );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::ClientReadWarmupTime
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::ClientReadWarmupTime( const idBitMsg& msg )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
warmupEndTime = msg.ReadLong();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::ClientReadWarmupTime
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::ClientReadMatchStartedTime( const idBitMsg& msg )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
matchStartedTime = msg.ReadLong();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::ClientReadAchievementUnlock
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::ClientReadAchievementUnlock( const idBitMsg& msg )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
int playerid = msg.ReadByte();
|
|
|
|
achievement_t achieve = ( achievement_t )msg.ReadByte();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idPlayer* player = static_cast<idPlayer*>( gameLocal.entities[ playerid ] );
|
|
|
|
|
|
|
|
if( player != NULL )
|
|
|
|
{
|
|
|
|
|
|
|
|
idLib::Printf( "Client Receiving Achievement\n" );
|
2012-11-26 18:58:24 +00:00
|
|
|
player->GetAchievementManager().EventCompletesAchievement( achieve );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::IsGametypeTeamBased
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
bool idMultiplayerGame::IsGametypeTeamBased() /* CTF */
|
|
|
|
{
|
2012-11-28 15:47:07 +00:00
|
|
|
switch( gameLocal.gameType )
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
2012-11-28 15:47:07 +00:00
|
|
|
case GAME_SP:
|
|
|
|
case GAME_DM:
|
|
|
|
case GAME_TOURNEY:
|
|
|
|
case GAME_LASTMAN:
|
|
|
|
return false;
|
|
|
|
case GAME_CTF:
|
|
|
|
case GAME_TDM:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert( !"Add support for your new gametype here." );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
2012-11-28 15:47:07 +00:00
|
|
|
idMultiplayerGame::IsGametypeFlagBased
|
2012-11-26 18:58:24 +00:00
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idMultiplayerGame::IsGametypeFlagBased()
|
|
|
|
{
|
|
|
|
switch( gameLocal.gameType )
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
2012-11-28 15:47:07 +00:00
|
|
|
case GAME_SP:
|
|
|
|
case GAME_DM:
|
|
|
|
case GAME_TOURNEY:
|
|
|
|
case GAME_LASTMAN:
|
|
|
|
case GAME_TDM:
|
|
|
|
return false;
|
|
|
|
case GAME_CTF:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
assert( !"Add support for your new gametype here." );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::GetTeamFlag
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idItemTeam* idMultiplayerGame::GetTeamFlag( int team )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( team == 0 || team == 1 );
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !IsGametypeFlagBased() || ( team != 0 && team != 1 ) ) /* CTF */
|
2012-11-26 18:58:24 +00:00
|
|
|
return NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// TODO : just call on map start
|
|
|
|
FindTeamFlags();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return teamFlags[team];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::GetTeamFlag
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::FindTeamFlags()
|
|
|
|
{
|
2012-12-11 22:48:55 +00:00
|
|
|
const char* flagDefs[2] =
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
|
|
|
"team_CTF_redflag",
|
|
|
|
"team_CTF_blueflag"
|
|
|
|
};
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < 2; i++ )
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
2012-11-28 15:47:07 +00:00
|
|
|
idEntity* entity = gameLocal.FindEntityUsingDef( NULL, flagDefs[i] );
|
2012-11-26 18:58:24 +00:00
|
|
|
do
|
|
|
|
{
|
2012-11-28 15:47:07 +00:00
|
|
|
if( entity == NULL )
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idItemTeam* flag = static_cast<idItemTeam*>( entity );
|
|
|
|
|
|
|
|
if( flag->team == i )
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
|
|
|
teamFlags[i] = flag;
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
entity = gameLocal.FindEntityUsingDef( entity, flagDefs[i] );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
while( entity );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::GetFlagStatus
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
flagStatus_t idMultiplayerGame::GetFlagStatus( int team )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//assert( IsGametypeFlagBased() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idItemTeam* teamFlag = GetTeamFlag( team );
|
2012-11-26 18:58:24 +00:00
|
|
|
//assert( teamFlag != NULL );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( teamFlag != NULL )
|
|
|
|
{
|
|
|
|
if( teamFlag->carried == false && teamFlag->dropped == false )
|
2012-11-26 18:58:24 +00:00
|
|
|
return FLAGSTATUS_INBASE;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( teamFlag->carried == true )
|
2012-11-26 18:58:24 +00:00
|
|
|
return FLAGSTATUS_TAKEN;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( teamFlag->carried == false && teamFlag->dropped == true )
|
2012-11-26 18:58:24 +00:00
|
|
|
return FLAGSTATUS_STRAY;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//assert( !"Invalid flag state." );
|
|
|
|
return FLAGSTATUS_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::SetFlagMsgs
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::SetFlagMsg( bool b )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
flagMsgOn = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::IsFlagMsgOn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idMultiplayerGame::IsFlagMsgOn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ( GetGameState() == WARMUP || GetGameState() == GAMEON || GetGameState() == SUDDENDEATH ) && flagMsgOn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::ReloadScoreboard
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiplayerGame::ReloadScoreboard()
|
|
|
|
{
|
|
|
|
|
|
|
|
if( scoreboardManager != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
scoreboardManager->Initialize( "scoreboard", common->SW() );
|
|
|
|
}
|
|
|
|
|
|
|
|
Precache();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiplayerGame::GetGameModes
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idMultiplayerGame::GetGameModes( const char** * gameModes, const char** * gameModesDisplay )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
bool defaultValue = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( session->GetTitleStorageBool( "CTF_Enabled", defaultValue ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
*gameModes = gameTypeNames_WithCTF;
|
|
|
|
*gameModesDisplay = gameTypeDisplayNames_WithCTF;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return GAME_COUNT;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
*gameModes = gameTypeNames_WithoutCTF;
|
|
|
|
*gameModesDisplay = gameTypeDisplayNames_WithoutCTF;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return GAME_COUNT - 1;
|
|
|
|
}
|
|
|
|
}
|