[iortcw] 33/89: All: Fix g_teamAutoJoin and g_teamForceBalance
Simon McVittie
smcv at debian.org
Fri Sep 8 10:44:21 UTC 2017
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to tag 1.51b
in repository iortcw.
commit a0ba77d8757049d03473b27c2d734dc894924d4c
Author: MAN-AT-ARMS <M4N4T4RMS at gmail.com>
Date: Tue Jul 18 07:52:46 2017 -0400
All: Fix g_teamAutoJoin and g_teamForceBalance
Merge from ioq3 https://github.com/ioquake/ioq3/commit/f7c3276fe803388bd613ab6bf6ad8e0a6647b740
Adds g_localTeamPref for use with g_teamAutoJoin
TODO: Add class preference as well (i.e. g_localClassPref) to go with this.
Unused in SP but merged for the sake of coop, etc.
---
MP/code/game/ai_dmq3.c | 7 +------
MP/code/game/g_bot.c | 3 +--
MP/code/game/g_client.c | 22 +++++++++++-----------
MP/code/game/g_cmds.c | 4 ++--
MP/code/game/g_local.h | 5 +++--
MP/code/game/g_main.c | 6 +++++-
MP/code/game/g_session.c | 20 ++++++++++++++++++--
MP/code/ui/ui_main.c | 12 +++++++++++-
SP/code/game/ai_dmq3.c | 7 +------
SP/code/game/g_bot.c | 3 +--
SP/code/game/g_client.c | 22 +++++++++++-----------
SP/code/game/g_cmds.c | 2 +-
SP/code/game/g_func_decs.h | 2 +-
SP/code/game/g_local.h | 4 ++--
SP/code/game/g_main.c | 4 ++++
SP/code/game/g_session.c | 20 ++++++++++++++++++--
SP/code/ui/ui_main.c | 12 ++++++++++--
17 files changed, 101 insertions(+), 54 deletions(-)
diff --git a/MP/code/game/ai_dmq3.c b/MP/code/game/ai_dmq3.c
index d0b4526..2ba84c2 100644
--- a/MP/code/game/ai_dmq3.c
+++ b/MP/code/game/ai_dmq3.c
@@ -2763,7 +2763,7 @@ BotDeathmatchAI
==================
*/
void BotDeathmatchAI( bot_state_t *bs, float thinktime ) {
- char gender[144], name[144], buf[144];
+ char gender[144], name[144];
char userinfo[MAX_INFO_STRING];
int i;
@@ -2779,11 +2779,6 @@ void BotDeathmatchAI( bot_state_t *bs, float thinktime ) {
trap_GetUserinfo( bs->client, userinfo, sizeof( userinfo ) );
Info_SetValueForKey( userinfo, "sex", gender );
trap_SetUserinfo( bs->client, userinfo );
- //set the team
- if ( g_gametype.integer != GT_TOURNAMENT ) {
- Com_sprintf( buf, sizeof( buf ), "team %s", bs->settings.team );
- trap_EA_Command( bs->client, buf );
- }
//set the chat gender
if ( gender[0] == 'm' ) {
trap_BotSetChatGender( bs->cs, CHAT_GENDERMALE );
diff --git a/MP/code/game/g_bot.c b/MP/code/game/g_bot.c
index 4829cb0..1505c1e 100644
--- a/MP/code/game/g_bot.c
+++ b/MP/code/game/g_bot.c
@@ -454,7 +454,6 @@ qboolean G_BotConnect( int clientNum, qboolean restart ) {
Q_strncpyz( settings.characterfile, Info_ValueForKey( userinfo, "characterfile" ), sizeof( settings.characterfile ) );
settings.skill = atoi( Info_ValueForKey( userinfo, "skill" ) );
- Q_strncpyz( settings.team, Info_ValueForKey( userinfo, "team" ), sizeof( settings.team ) );
if ( !BotAISetupClient( clientNum, &settings ) ) {
trap_DropClient( clientNum, "BotAISetupClient failed" );
@@ -561,7 +560,7 @@ static void G_AddBot( const char *name, float skill, const char *team, int delay
team = "red";
}
}
- Info_SetValueForKey( userinfo, "team", team );
+ Info_SetValueForKey( userinfo, "teampref", team );
// register the userinfo
trap_SetUserinfo( clientNum, userinfo );
diff --git a/MP/code/game/g_client.c b/MP/code/game/g_client.c
index 67443f3..093dd1d 100644
--- a/MP/code/game/g_client.c
+++ b/MP/code/game/g_client.c
@@ -1332,12 +1332,6 @@ void ClientUserinfoChanged( int clientNum ) {
trap_DropClient(clientNum, "Invalid userinfo");
}
- // check for local client
- s = Info_ValueForKey( userinfo, "ip" );
- if ( s && !strcmp( s, "localhost" ) ) {
- client->pers.localClient = qtrue;
- }
-
// check the item prediction
s = Info_ValueForKey( userinfo, "cg_predictItems" );
if ( !atoi( s ) ) {
@@ -1581,11 +1575,11 @@ char *ClientConnect( int clientNum, qboolean firstTime, qboolean isBot ) {
}
client->pers.complaints = 0; // DHM - Nerve
- // read or initialize the session data
- if ( firstTime || ( g_gametype.integer < GT_WOLF && level.newSession ) ) {
- G_InitSessionData( client, userinfo );
- }
- G_ReadSessionData( client );
+ // check for local client
+ value = Info_ValueForKey( userinfo, "ip" );
+ if ( !strcmp( value, "localhost" ) ) {
+ client->pers.localClient = qtrue;
+ }
if ( isBot ) {
ent->r.svFlags |= SVF_BOT;
@@ -1595,6 +1589,12 @@ char *ClientConnect( int clientNum, qboolean firstTime, qboolean isBot ) {
}
}
+ // read or initialize the session data
+ if ( firstTime || ( g_gametype.integer < GT_WOLF && level.newSession ) ) {
+ G_InitSessionData( client, userinfo );
+ }
+ G_ReadSessionData( client );
+
// get and distribute relevent paramters
G_LogPrintf( "ClientConnect: %i\n", clientNum );
ClientUserinfoChanged( clientNum );
diff --git a/MP/code/game/g_cmds.c b/MP/code/game/g_cmds.c
index 30ac59b..80d02de 100644
--- a/MP/code/game/g_cmds.c
+++ b/MP/code/game/g_cmds.c
@@ -541,7 +541,7 @@ void Cmd_Kill_f( gentity_t *ent ) {
SetTeam
=================
*/
-void SetTeam( gentity_t *ent, char *s ) {
+void SetTeam( gentity_t *ent, const char *s ) {
int team, oldTeam;
gclient_t *client;
int clientNum;
@@ -590,7 +590,7 @@ void SetTeam( gentity_t *ent, char *s ) {
}
// NERVE - SMF - merge from team arena
- if ( g_teamForceBalance.integer ) {
+ if ( g_teamForceBalance.integer && !client->pers.localClient && !( ent->r.svFlags & SVF_BOT ) ) {
int counts[TEAM_NUM_TEAMS];
counts[TEAM_BLUE] = TeamCount( clientNum, TEAM_BLUE );
diff --git a/MP/code/game/g_local.h b/MP/code/game/g_local.h
index 5290d2d..3124fa0 100644
--- a/MP/code/game/g_local.h
+++ b/MP/code/game/g_local.h
@@ -781,7 +781,7 @@ qboolean G_CallSpawn( gentity_t *ent );
void Cmd_Score_f( gentity_t *ent );
void StopFollowing( gentity_t *ent );
//void BroadcastTeamChange( gclient_t *client, int oldTeam );
-void SetTeam( gentity_t *ent, char *s );
+void SetTeam( gentity_t *ent, const char *s );
void SetWolfData( gentity_t *ent, char *ptype, char *weap, char *grenade, char *skinnum ); // DHM - Nerve
void Cmd_FollowCycle_f( gentity_t *ent, int dir );
@@ -1054,7 +1054,6 @@ typedef struct bot_settings_s
{
char characterfile[MAX_FILEPATH];
float skill;
- char team[MAX_FILEPATH];
} bot_settings_t;
int BotAISetup( int restart );
@@ -1204,6 +1203,8 @@ extern vmCvar_t g_antilag;
extern vmCvar_t g_dbgRevive;
+extern vmCvar_t g_localTeamPref;
+
void trap_Print( const char *text );
void trap_Error( const char *text ) __attribute__((noreturn));
int trap_Milliseconds( void );
diff --git a/MP/code/game/g_main.c b/MP/code/game/g_main.c
index 563a563..01662ef 100644
--- a/MP/code/game/g_main.c
+++ b/MP/code/game/g_main.c
@@ -162,6 +162,8 @@ vmCvar_t url;
vmCvar_t g_dbgRevive;
+vmCvar_t g_localTeamPref;
+
cvarTable_t gameCvarTable[] = {
// don't override the cheat state set by the system
{ &g_cheats, "sv_cheats", "", 0, qfalse },
@@ -293,7 +295,9 @@ cvarTable_t gameCvarTable[] = {
{&g_antilag, "g_antilag", "0", CVAR_SERVERINFO | CVAR_ARCHIVE, 0, qfalse},
- {&g_dbgRevive, "g_dbgRevive", "0", 0, 0, qfalse}
+ {&g_dbgRevive, "g_dbgRevive", "0", 0, 0, qfalse},
+
+ { &g_localTeamPref, "g_localTeamPref", "", 0, 0, qfalse }
};
static int gameCvarTableSize = ARRAY_LEN( gameCvarTable );
diff --git a/MP/code/game/g_session.c b/MP/code/game/g_session.c
index 861c2d1..af9e3c2 100644
--- a/MP/code/game/g_session.c
+++ b/MP/code/game/g_session.c
@@ -146,12 +146,27 @@ void G_InitSessionData( gclient_t *client, char *userinfo ) {
sess = &client->sess;
+ // check for team preference, mainly for bots
+ value = Info_ValueForKey( userinfo, "teampref" );
+
+ // check for human's team preference set by start server menu
+ if ( !value[0] && g_localTeamPref.string[0] && client->pers.localClient ) {
+ value = g_localTeamPref.string;
+
+ // clear team so it's only used once
+ trap_Cvar_Set( "g_localTeamPref", "" );
+ }
+
// initial team determination
if ( g_gametype.integer >= GT_TEAM ) {
// always spawn as spectator in team games
sess->sessionTeam = TEAM_SPECTATOR;
+ sess->spectatorState = SPECTATOR_FREE;
+
+ if ( value[0] || g_teamAutoJoin.integer ) {
+ SetTeam( &g_entities[client - level.clients], value );
+ }
} else {
- value = Info_ValueForKey( userinfo, "team" );
if ( value[0] == 's' ) {
// a willing spectator, not a waiting-in-line
sess->sessionTeam = TEAM_SPECTATOR;
@@ -177,9 +192,10 @@ void G_InitSessionData( gclient_t *client, char *userinfo ) {
break;
}
}
+
+ sess->spectatorState = SPECTATOR_FREE;
}
- sess->spectatorState = SPECTATOR_FREE;
AddTournamentQueue(client);
// DHM - Nerve
diff --git a/MP/code/ui/ui_main.c b/MP/code/ui/ui_main.c
index 6df8bde..e4fa9cb 100644
--- a/MP/code/ui/ui_main.c
+++ b/MP/code/ui/ui_main.c
@@ -3751,7 +3751,11 @@ static void UI_StartSkirmish( qboolean next ) {
}
}
if ( g >= GT_TEAM ) {
+ // send team command for vanilla q3 game qvm
trap_Cmd_ExecuteText( EXEC_APPEND, "wait 5; team Red\n" );
+
+ // set g_localTeamPref for ioq3 game qvm
+ trap_Cvar_Set( "g_localTeamPref", "Red" );
}
#endif // #ifdef MISSIONPACK
}
@@ -7805,7 +7809,9 @@ cvarTable_t cvarTable[] = {
{ &ui_isSpectator, "ui_isSpectator", "1", 0 },
// -NERVE - SMF
- { &ui_hudAlpha, "cg_hudAlpha", "1.0", CVAR_ARCHIVE }
+ { &ui_hudAlpha, "cg_hudAlpha", "1.0", CVAR_ARCHIVE },
+
+ { NULL, "g_localTeamPref", "", 0 },
};
static int cvarTableSize = ARRAY_LEN( cvarTable );
@@ -7835,6 +7841,10 @@ void UI_UpdateCvars( void ) {
cvarTable_t *cv;
for ( i = 0, cv = cvarTable ; i < cvarTableSize ; i++, cv++ ) {
+ if ( !cv->vmCvar ) {
+ continue;
+ }
+
trap_Cvar_Update( cv->vmCvar );
}
}
diff --git a/SP/code/game/ai_dmq3.c b/SP/code/game/ai_dmq3.c
index 8bd0c28..db3ddab 100644
--- a/SP/code/game/ai_dmq3.c
+++ b/SP/code/game/ai_dmq3.c
@@ -2756,7 +2756,7 @@ BotDeathmatchAI
==================
*/
void BotDeathmatchAI( bot_state_t *bs, float thinktime ) {
- char gender[144], name[144], buf[144];
+ char gender[144], name[144];
char userinfo[MAX_INFO_STRING];
int i;
@@ -2772,11 +2772,6 @@ void BotDeathmatchAI( bot_state_t *bs, float thinktime ) {
trap_GetUserinfo( bs->client, userinfo, sizeof( userinfo ) );
Info_SetValueForKey( userinfo, "sex", gender );
trap_SetUserinfo( bs->client, userinfo );
- //set the team
- if ( g_gametype.integer != GT_TOURNAMENT ) {
- Com_sprintf( buf, sizeof( buf ), "team %s", bs->settings.team );
- trap_EA_Command( bs->client, buf );
- }
//set the chat gender
if ( gender[0] == 'm' ) {
trap_BotSetChatGender( bs->cs, CHAT_GENDERMALE );
diff --git a/SP/code/game/g_bot.c b/SP/code/game/g_bot.c
index 3c6b567..d46764e 100644
--- a/SP/code/game/g_bot.c
+++ b/SP/code/game/g_bot.c
@@ -455,7 +455,6 @@ qboolean G_BotConnect( int clientNum, qboolean restart ) {
Q_strncpyz( settings.characterfile, Info_ValueForKey( userinfo, "characterfile" ), sizeof( settings.characterfile ) );
settings.skill = atoi( Info_ValueForKey( userinfo, "skill" ) );
- Q_strncpyz( settings.team, Info_ValueForKey( userinfo, "team" ), sizeof( settings.team ) );
if ( !BotAISetupClient( clientNum, &settings ) ) {
trap_DropClient( clientNum, "BotAISetupClient failed" );
@@ -562,7 +561,7 @@ static void G_AddBot( const char *name, int skill, const char *team, int delay )
team = "red";
}
}
- Info_SetValueForKey( userinfo, "team", team );
+ Info_SetValueForKey( userinfo, "teampref", team );
// register the userinfo
trap_SetUserinfo( clientNum, userinfo );
diff --git a/SP/code/game/g_client.c b/SP/code/game/g_client.c
index 266b04c..7c1e4ac 100644
--- a/SP/code/game/g_client.c
+++ b/SP/code/game/g_client.c
@@ -1288,12 +1288,6 @@ void ClientUserinfoChanged( int clientNum ) {
trap_DropClient(clientNum, "Invalid userinfo");
}
- // check for local client
- s = Info_ValueForKey( userinfo, "ip" );
- if ( !strcmp( s, "localhost" ) ) {
- client->pers.localClient = qtrue;
- }
-
// check the item prediction
s = Info_ValueForKey( userinfo, "cg_predictItems" );
if ( !atoi( s ) ) {
@@ -1501,11 +1495,11 @@ char *ClientConnect( int clientNum, qboolean firstTime, qboolean isBot ) {
client->pers.connected = CON_CONNECTING;
- // read or initialize the session data
- if ( firstTime || level.newSession ) {
- G_InitSessionData( client, userinfo );
- }
- G_ReadSessionData( client );
+ // check for local client
+ value = Info_ValueForKey( userinfo, "ip" );
+ if ( !strcmp( value, "localhost" ) ) {
+ client->pers.localClient = qtrue;
+ }
if ( isBot ) {
ent->r.svFlags |= SVF_BOT;
@@ -1515,6 +1509,12 @@ char *ClientConnect( int clientNum, qboolean firstTime, qboolean isBot ) {
}
}
+ // read or initialize the session data
+ if ( firstTime || level.newSession ) {
+ G_InitSessionData( client, userinfo );
+ }
+ G_ReadSessionData( client );
+
// get and distribute relevent paramters
G_LogPrintf( "ClientConnect: %i\n", clientNum );
ClientUserinfoChanged( clientNum );
diff --git a/SP/code/game/g_cmds.c b/SP/code/game/g_cmds.c
index 57dddcc..d59afbf 100644
--- a/SP/code/game/g_cmds.c
+++ b/SP/code/game/g_cmds.c
@@ -562,7 +562,7 @@ void Cmd_Kill_f( gentity_t *ent ) {
SetTeam
=================
*/
-void SetTeam( gentity_t *ent, char *s ) {
+void SetTeam( gentity_t *ent, const char *s ) {
int team, oldTeam;
gclient_t *client;
int clientNum;
diff --git a/SP/code/game/g_func_decs.h b/SP/code/game/g_func_decs.h
index 00921ff..a406c1f 100644
--- a/SP/code/game/g_func_decs.h
+++ b/SP/code/game/g_func_decs.h
@@ -1065,7 +1065,7 @@ extern void Cmd_Follow_f ( gentity_t * ent ) ;
extern void Cmd_Team_f ( gentity_t * ent ) ;
extern void StopFollowing ( gentity_t * ent ) ;
extern void SetWolfData ( gentity_t * ent , char * ptype , char * weap , char * pistol , char * grenade , char * skinnum ) ;
-extern void SetTeam ( gentity_t * ent , char * s ) ;
+extern void SetTeam ( gentity_t * ent , const char * s ) ;
extern void Cmd_Kill_f ( gentity_t * ent ) ;
extern void Cmd_LevelShot_f ( gentity_t * ent ) ;
extern void Cmd_Noclip_f ( gentity_t * ent ) ;
diff --git a/SP/code/game/g_local.h b/SP/code/game/g_local.h
index a8c6c04..cefca7e 100644
--- a/SP/code/game/g_local.h
+++ b/SP/code/game/g_local.h
@@ -748,7 +748,7 @@ qboolean G_CallSpawn( gentity_t *ent );
void Cmd_Score_f( gentity_t *ent );
void StopFollowing( gentity_t *ent );
//void BroadcastTeamChange( gclient_t *client, int oldTeam );
-void SetTeam( gentity_t *ent, char *s );
+void SetTeam( gentity_t *ent, const char *s );
void SetWolfData( gentity_t *ent, char *ptype, char *weap, char *pistol, char *grenade, char *skinnum ); // DHM - Nerve
void Cmd_FollowCycle_f( gentity_t *ent, int dir );
@@ -1022,7 +1022,6 @@ typedef struct bot_settings_s
{
char characterfile[MAX_FILEPATH];
float skill;
- char team[MAX_FILEPATH];
} bot_settings_t;
int BotAISetup( int restart );
@@ -1151,6 +1150,7 @@ extern vmCvar_t g_soldierChargeTime;
extern vmCvar_t g_playerStart; //----(SA) added
+extern vmCvar_t g_localTeamPref;
void trap_Print( const char *text );
void trap_Error( const char *text ) __attribute__((noreturn));
diff --git a/SP/code/game/g_main.c b/SP/code/game/g_main.c
index 91fafb6..abe3073 100644
--- a/SP/code/game/g_main.c
+++ b/SP/code/game/g_main.c
@@ -142,6 +142,8 @@ vmCvar_t g_soldierChargeTime;
vmCvar_t g_playerStart; // set when the player enters the game
+vmCvar_t g_localTeamPref;
+
cvarTable_t gameCvarTable[] = {
// don't override the cheat state set by the system
{ &g_cheats, "sv_cheats", "", 0, qfalse },
@@ -249,6 +251,8 @@ cvarTable_t gameCvarTable[] = {
{&g_scriptName, "g_scriptName", "", CVAR_ROM, 0, qfalse},
{&ai_scriptName, "ai_scriptName", "", CVAR_ROM, 0, qfalse},
+
+ { &g_localTeamPref, "g_localTeamPref", "", 0, 0, qfalse }
};
static int gameCvarTableSize = ARRAY_LEN( gameCvarTable );
diff --git a/SP/code/game/g_session.c b/SP/code/game/g_session.c
index 0ef7cac..1864ffe 100644
--- a/SP/code/game/g_session.c
+++ b/SP/code/game/g_session.c
@@ -112,12 +112,27 @@ void G_InitSessionData( gclient_t *client, char *userinfo ) {
sess = &client->sess;
+ // check for team preference, mainly for bots
+ value = Info_ValueForKey( userinfo, "teampref" );
+
+ // check for human's team preference set by start server menu
+ if ( !value[0] && g_localTeamPref.string[0] && client->pers.localClient ) {
+ value = g_localTeamPref.string;
+
+ // clear team so it's only used once
+ trap_Cvar_Set( "g_localTeamPref", "" );
+ }
+
// initial team determination
if ( g_gametype.integer >= GT_TEAM ) {
// always spawn as spectator in team games
sess->sessionTeam = TEAM_SPECTATOR;
+ sess->spectatorState = SPECTATOR_FREE;
+
+ if ( value[0] || g_teamAutoJoin.integer ) {
+ SetTeam( &g_entities[client - level.clients], value );
+ }
} else {
- value = Info_ValueForKey( userinfo, "team" );
if ( value[0] == 's' ) {
// a willing spectator, not a waiting-in-line
sess->sessionTeam = TEAM_SPECTATOR;
@@ -143,9 +158,10 @@ void G_InitSessionData( gclient_t *client, char *userinfo ) {
break;
}
}
+
+ sess->spectatorState = SPECTATOR_FREE;
}
- sess->spectatorState = SPECTATOR_FREE;
AddTournamentQueue(client);
// DHM - Nerve
diff --git a/SP/code/ui/ui_main.c b/SP/code/ui/ui_main.c
index 97c1c88..5f8c438 100644
--- a/SP/code/ui/ui_main.c
+++ b/SP/code/ui/ui_main.c
@@ -4057,7 +4057,11 @@ static void UI_StartSkirmish( qboolean next ) {
}
}
if ( g >= GT_TEAM ) {
+ // send team command for vanilla q3 game qvm
trap_Cmd_ExecuteText( EXEC_APPEND, "wait 5; team Red\n" );
+
+ // set g_localTeamPref for ioq3 game qvm
+ trap_Cvar_Set( "g_localTeamPref", "Red" );
}
#endif // #ifdef MISSIONPACK
}
@@ -7591,9 +7595,9 @@ cvarTable_t cvarTable[] = {
{ &ui_hunkUsed, "com_hunkused", "0", 0 }, //----(SA) added
{ &ui_cameraMode, "com_cameraMode", "0", 0}, //----(SA) added
- { &ui_savegameName, "ui_savegameName", "", CVAR_ROM}
-
+ { &ui_savegameName, "ui_savegameName", "", CVAR_ROM},
+ { NULL, "g_localTeamPref", "", 0 },
};
static int cvarTableSize = ARRAY_LEN( cvarTable );
@@ -7623,6 +7627,10 @@ void UI_UpdateCvars( void ) {
cvarTable_t *cv;
for ( i = 0, cv = cvarTable ; i < cvarTableSize ; i++, cv++ ) {
+ if ( !cv->vmCvar ) {
+ continue;
+ }
+
trap_Cvar_Update( cv->vmCvar );
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/iortcw.git
More information about the Pkg-games-commits
mailing list