[openjk] 110/130: SP: Cleanup g_svcmds.cpp a bit

Simon McVittie smcv at debian.org
Fri Oct 28 11:09:26 UTC 2016


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian/master
in repository openjk.

commit f4ddf75fe9f3221eefde31f49affc23bc6a8a455
Author: Ensiform <ensiform at gmail.com>
Date:   Thu Oct 20 20:00:29 2016 -0500

    SP: Cleanup g_svcmds.cpp a bit
    
    Made this file more C++11 compliant.
    Added linear search list for commands to cleanup the clusterfuck of
    ConsoleCommand Function.
    SetForceAll will only give all saberstyles if you specify an argument.
    playerTeam command now tells you your current team when no arguments are
    specified.
    Added `secrets` command to tell the player how many secrets have been
    found out of the total.
    Added stub `difficulty` command with different cvar options between each
    difficulty listed in comments.
    Added possibility to check for if player is alive but none currently use
    this feature.
---
 code/cgame/cg_servercmds.cpp |   2 +-
 code/game/g_svcmds.cpp       | 628 ++++++++++++++++++-------------------------
 code/qcommon/q_shared.cpp    |  24 ++
 code/qcommon/q_shared.h      |   9 +
 4 files changed, 297 insertions(+), 366 deletions(-)

diff --git a/code/cgame/cg_servercmds.cpp b/code/cgame/cg_servercmds.cpp
index 30d19eb..9875caf 100644
--- a/code/cgame/cg_servercmds.cpp
+++ b/code/cgame/cg_servercmds.cpp
@@ -203,7 +203,7 @@ typedef struct serverCommand_s {
 	void		(*func)(void);
 } serverCommand_t;
 
-int svcmdcmp( const void *a, const void *b ) {
+static int svcmdcmp( const void *a, const void *b ) {
 	return Q_stricmp( (const char *)a, ((serverCommand_t*)b)->cmd );
 }
 
diff --git a/code/game/g_svcmds.cpp b/code/game/g_svcmds.cpp
index 9473d17..475701d 100644
--- a/code/game/g_svcmds.cpp
+++ b/code/game/g_svcmds.cpp
@@ -557,31 +557,31 @@ void Svcmd_SaberAttackCycle_f( void )
 	switch ( saberAnimLevel )
 	{
 	case SS_FAST:
-		gi.Printf( S_COLOR_BLUE"Lightsaber Combat Style: Fast\n" );
+		gi.Printf( S_COLOR_BLUE "Lightsaber Combat Style: Fast\n" );
 		//LIGHTSABERCOMBATSTYLE_FAST
 		break;
 	case SS_MEDIUM:
-		gi.Printf( S_COLOR_YELLOW"Lightsaber Combat Style: Medium\n" );
+		gi.Printf( S_COLOR_YELLOW "Lightsaber Combat Style: Medium\n" );
 		//LIGHTSABERCOMBATSTYLE_MEDIUM
 		break;
 	case SS_STRONG:
-		gi.Printf( S_COLOR_RED"Lightsaber Combat Style: Strong\n" );
+		gi.Printf( S_COLOR_RED "Lightsaber Combat Style: Strong\n" );
 		//LIGHTSABERCOMBATSTYLE_STRONG
 		break;
 	case SS_DESANN:
-		gi.Printf( S_COLOR_CYAN"Lightsaber Combat Style: Desann\n" );
+		gi.Printf( S_COLOR_CYAN "Lightsaber Combat Style: Desann\n" );
 		//LIGHTSABERCOMBATSTYLE_DESANN
 		break;
 	case SS_TAVION:
-		gi.Printf( S_COLOR_MAGENTA"Lightsaber Combat Style: Tavion\n" );
+		gi.Printf( S_COLOR_MAGENTA "Lightsaber Combat Style: Tavion\n" );
 		//LIGHTSABERCOMBATSTYLE_TAVION
 		break;
 	case SS_DUAL:
-		gi.Printf( S_COLOR_MAGENTA"Lightsaber Combat Style: Dual\n" );
+		gi.Printf( S_COLOR_MAGENTA "Lightsaber Combat Style: Dual\n" );
 		//LIGHTSABERCOMBATSTYLE_TAVION
 		break;
 	case SS_STAFF:
-		gi.Printf( S_COLOR_MAGENTA"Lightsaber Combat Style: Staff\n" );
+		gi.Printf( S_COLOR_MAGENTA" Lightsaber Combat Style: Staff\n" );
 		//LIGHTSABERCOMBATSTYLE_TAVION
 		break;
 	}
@@ -622,437 +622,335 @@ void G_GrabEntity( gentity_t *grabber, const char *target )
 	}
 }
 
-/*
-=================
-ConsoleCommand
-=================
-*/
-qboolean	ConsoleCommand( void ) {
-	const char	*cmd;
+static void Svcmd_ICARUS_f( void )
+{
+	Quake3Game()->Svcmd();
+}
 
-	cmd = gi.argv(0);
+template <int32_t power>
+static void Svcmd_ForceSetLevel_f(void)
+{
+	Svcmd_ForceSetLevel_f(power);
+}
 
-	if ( Q_stricmp (cmd, "entitylist") == 0 )
+static void Svcmd_SetForceAll_f(void)
+{
+	for ( int i = FP_HEAL; i < NUM_FORCE_POWERS; i++ )
 	{
-		Svcmd_EntityList_f();
-		return qtrue;
+		Svcmd_ForceSetLevel_f( i );
 	}
 
-	if (Q_stricmp (cmd, "game_memory") == 0) {
-		Svcmd_GameMem_f();
-		return qtrue;
-	}
-
-	if (Q_stricmp (cmd, "nav") == 0)
+	if( gi.argc() > 1 )
 	{
-		if ( !g_cheats->integer )
+		for ( int i = SS_NONE+1; i < SS_NUM_SABER_STYLES; i++ )
 		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
+			g_entities[0].client->ps.saberStylesKnown |= (1<<i);
 		}
-		Svcmd_Nav_f ();
-		return qtrue;
 	}
+}
 
-	if (Q_stricmp (cmd, "npc") == 0)
+static void Svcmd_SetSaberAll_f(void)
+{
+	Svcmd_ForceSetLevel_f( FP_SABERTHROW );
+	Svcmd_ForceSetLevel_f( FP_SABER_DEFENSE );
+	Svcmd_ForceSetLevel_f( FP_SABER_OFFENSE );
+	for ( int i = SS_NONE+1; i < SS_NUM_SABER_STYLES; i++ )
 	{
-		if ( !g_cheats->integer )
-		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
-		}
-		Svcmd_NPC_f ();
-		return qtrue;
+		g_entities[0].client->ps.saberStylesKnown |= (1<<i);
 	}
+}
 
-	if (Q_stricmp (cmd, "use") == 0)
+static void Svcmd_RunScript_f(void)
+{
+	const char *cmd2 = gi.argv(1);
+
+	if ( cmd2 && cmd2[0] )
 	{
-		if ( !g_cheats->integer )
+		const char *cmd3 = gi.argv(2);
+		if ( cmd3 && cmd3[0] )
 		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
+			gentity_t *found = NULL;
+			if ( (found = G_Find(NULL, FOFS(targetname), cmd2 ) ) != NULL )
+			{
+				Quake3Game()->RunScript( found, cmd3 );
+			}
+			else
+			{
+				//can't find cmd2
+				gi.Printf( S_COLOR_RED "runscript: can't find targetname %s\n", cmd2 );
+			}
 		}
-		Svcmd_Use_f ();
-		return qtrue;
-	}
-
-	if ( Q_stricmp( cmd, "ICARUS" ) == 0 )
-	{
-		if ( !g_cheats->integer )
+		else
 		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
+			Quake3Game()->RunScript( &g_entities[0], cmd2 );
 		}
-
-		Quake3Game()->Svcmd();
-
-		return qtrue;
 	}
-
-	if ( Q_stricmp( cmd, "saberColor" ) == 0 )
+	else
 	{
-		if ( !g_cheats->integer )
-		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
-		}
-		Svcmd_SaberColor_f();
-		return qtrue;
+		gi.Printf( S_COLOR_RED "usage: runscript <ent targetname> scriptname\n" );
 	}
+}
+
+static void Svcmd_PlayerTeam_f(void)
+{
+	const char *cmd2 = gi.argv(1);
 
-	if ( Q_stricmp( cmd, "saber" ) == 0 )
+	if ( !*cmd2 || !cmd2[0] )
 	{
-		if ( !g_cheats->integer )
+		gi.Printf( S_COLOR_RED "'playerteam' - change player team, requires a team name!\n" );
+		gi.Printf( S_COLOR_RED "Current team is: %s\n", GetStringForID( TeamTable, g_entities[0].client->playerTeam ) );
+		gi.Printf( S_COLOR_RED "Valid team names are:\n");
+		for ( int n = (TEAM_FREE + 1); n < TEAM_NUM_TEAMS; n++ )
 		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
+			gi.Printf( S_COLOR_RED "%s\n", GetStringForID( TeamTable, n ) );
 		}
-		Svcmd_Saber_f();
-		return qtrue;
 	}
-
-	if ( Q_stricmp( cmd, "saberblade" ) == 0 )
+	else
 	{
-		if ( !g_cheats->integer )
+		team_t	team;
+
+		team = (team_t)GetIDForString( TeamTable, cmd2 );
+		if ( team == (team_t)-1 )
 		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
+			gi.Printf( S_COLOR_RED "'playerteam' unrecognized team name %s!\n", cmd2 );
+			gi.Printf( S_COLOR_RED "Current team is: %s\n", GetStringForID( TeamTable, g_entities[0].client->playerTeam ) );
+			gi.Printf( S_COLOR_RED "Valid team names are:\n");
+			for ( int n = TEAM_FREE; n < TEAM_NUM_TEAMS; n++ )
+			{
+				gi.Printf( S_COLOR_RED "%s\n", GetStringForID( TeamTable, n ) );
+			}
+		}
+		else
+		{
+			g_entities[0].client->playerTeam = team;
+			//FIXME: convert Imperial, Malon, Hirogen and Klingon to Scavenger?
 		}
-		Svcmd_SaberBlade_f();
-		return qtrue;
 	}
+}
 
-	if ( Q_stricmp( cmd, "setForceJump" ) == 0 )
-	{
-		Svcmd_ForceSetLevel_f( FP_LEVITATION );
-		return qtrue;
-	}
-	if ( Q_stricmp( cmd, "setSaberThrow" ) == 0 )
-	{
-		Svcmd_ForceSetLevel_f( FP_SABERTHROW );
-		return qtrue;
-	}
-	if ( Q_stricmp( cmd, "setForceHeal" ) == 0 )
-	{
-		Svcmd_ForceSetLevel_f( FP_HEAL );
-		return qtrue;
-	}
-	if ( Q_stricmp( cmd, "setForcePush" ) == 0 )
-	{
-		Svcmd_ForceSetLevel_f( FP_PUSH );
-		return qtrue;
-	}
-	if ( Q_stricmp( cmd, "setForcePull" ) == 0 )
-	{
-		Svcmd_ForceSetLevel_f( FP_PULL );
-		return qtrue;
-	}
-	if ( Q_stricmp( cmd, "setForceSpeed" ) == 0 )
-	{
-		Svcmd_ForceSetLevel_f( FP_SPEED );
-		return qtrue;
-	}
-	if ( Q_stricmp( cmd, "setForceGrip" ) == 0 )
+static void Svcmd_Control_f(void)
+{
+	const char	*cmd2 = gi.argv(1);
+	if ( !*cmd2 || !cmd2[0] )
 	{
-		Svcmd_ForceSetLevel_f( FP_GRIP );
-		return qtrue;
+		if ( !G_ClearViewEntity( &g_entities[0] ) )
+		{
+			gi.Printf( S_COLOR_RED "control <NPC_targetname>\n", cmd2 );
+		}
 	}
-	if ( Q_stricmp( cmd, "setForceLightning" ) == 0 )
+	else
 	{
-		Svcmd_ForceSetLevel_f( FP_LIGHTNING );
-		return qtrue;
+		Q3_SetViewEntity( 0, cmd2 );
 	}
-	if ( Q_stricmp( cmd, "setMindTrick" ) == 0 )
+}
+
+static void Svcmd_Grab_f(void)
+{
+	const char	*cmd2 = gi.argv(1);
+	if ( !*cmd2 || !cmd2[0] )
 	{
-		Svcmd_ForceSetLevel_f( FP_TELEPATHY );
-		return qtrue;
+		if ( !G_ReleaseEntity( &g_entities[0] ) )
+		{
+			gi.Printf( S_COLOR_RED "grab <NPC_targetname>\n", cmd2 );
+		}
 	}
-	if ( Q_stricmp( cmd, "setSaberDefense" ) == 0 )
+	else
 	{
-		Svcmd_ForceSetLevel_f( FP_SABER_DEFENSE );
-		return qtrue;
+		G_GrabEntity( &g_entities[0], cmd2 );
 	}
-	if ( Q_stricmp( cmd, "setSaberOffense" ) == 0 )
-	{
-		Svcmd_ForceSetLevel_f( FP_SABER_OFFENSE );
-		return qtrue;
-	}
-	if ( Q_stricmp( cmd, "setForceRage" ) == 0 )
+}
+
+static void Svcmd_Knockdown_f(void)
+{
+	G_Knockdown( &g_entities[0], &g_entities[0], vec3_origin, 300, qtrue );
+}
+
+static void Svcmd_PlayerModel_f(void)
+{
+	if ( gi.argc() == 1 )
 	{
-		Svcmd_ForceSetLevel_f( FP_RAGE );
-		return qtrue;
+		gi.Printf( S_COLOR_RED "USAGE: playerModel <NPC Name>\n       playerModel <g2model> <skinhead> <skintorso> <skinlower>\n       playerModel player (builds player from customized menu settings)" S_COLOR_WHITE "\n" );
+		gi.Printf( "playerModel = %s ", va("%s %s %s %s\n", g_char_model->string, g_char_skin_head->string, g_char_skin_torso->string, g_char_skin_legs->string ) );
 	}
-	if ( Q_stricmp( cmd, "setForceDrain" ) == 0 )
+	else if ( gi.argc() == 2 )
 	{
-		Svcmd_ForceSetLevel_f( FP_DRAIN );
-		return qtrue;
+		G_ChangePlayerModel( &g_entities[0], gi.argv(1) );
 	}
-	if ( Q_stricmp( cmd, "setForceProtect" ) == 0 )
+	else if (  gi.argc() == 5 )
 	{
-		Svcmd_ForceSetLevel_f( FP_PROTECT );
-		return qtrue;
+		//instead of setting it directly via a command, we now store it in cvars
+		//G_ChangePlayerModel( &g_entities[0], va("%s|%s|%s|%s", gi.argv(1), gi.argv(2), gi.argv(3), gi.argv(4)) );
+		gi.cvar_set("g_char_model", gi.argv(1) );
+		gi.cvar_set("g_char_skin_head", gi.argv(2) );
+		gi.cvar_set("g_char_skin_torso", gi.argv(3) );
+		gi.cvar_set("g_char_skin_legs", gi.argv(4) );
+		G_InitPlayerFromCvars( &g_entities[0] );
 	}
-	if ( Q_stricmp( cmd, "setForceAbsorb" ) == 0 )
+}
+
+static void Svcmd_PlayerTint_f(void)
+{
+	if ( gi.argc() == 4 )
 	{
-		Svcmd_ForceSetLevel_f( FP_ABSORB );
-		return qtrue;
+		g_entities[0].client->renderInfo.customRGBA[0] = atoi(gi.argv(1));
+		g_entities[0].client->renderInfo.customRGBA[1] = atoi(gi.argv(2));
+		g_entities[0].client->renderInfo.customRGBA[2] = atoi(gi.argv(3));
+		gi.cvar_set("g_char_color_red", gi.argv(1) );
+		gi.cvar_set("g_char_color_green", gi.argv(2) );
+		gi.cvar_set("g_char_color_blue", gi.argv(3) );
 	}
-	if ( Q_stricmp( cmd, "setForceSight" ) == 0 )
+	else
 	{
-		Svcmd_ForceSetLevel_f( FP_SEE );
-		return qtrue;
+		gi.Printf( S_COLOR_RED "USAGE: playerTint <red 0 - 255> <green 0 - 255> <blue 0 - 255>\n" );
+		gi.Printf( "playerTint = %s\n", va("%d %d %d", g_char_color_red->integer, g_char_color_green->integer, g_char_color_blue->integer ) );
 	}
-	if ( Q_stricmp( cmd, "setForceAll" ) == 0 )
-	{
-		if ( !g_cheats->integer )
-		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
-		}
+}
 
-		for ( int i = FP_HEAL; i < NUM_FORCE_POWERS; i++ )
+static void Svcmd_IKnowKungfu_f(void)
+{
+	gi.cvar_set( "g_debugMelee", "1" );
+	G_SetWeapon( &g_entities[0], WP_MELEE );
+	for ( int i = FP_FIRST; i < NUM_FORCE_POWERS; i++ )
+	{
+		g_entities[0].client->ps.forcePowersKnown |= ( 1 << i );
+		if ( i == FP_TELEPATHY )
 		{
-			Svcmd_ForceSetLevel_f( i );
+			g_entities[0].client->ps.forcePowerLevel[i] = FORCE_LEVEL_4;
 		}
-		for ( int i = SS_NONE+1; i < SS_NUM_SABER_STYLES; i++ )
+		else
 		{
-			g_entities[0].client->ps.saberStylesKnown |= (1<<i);
+			g_entities[0].client->ps.forcePowerLevel[i] = FORCE_LEVEL_3;
 		}
-		return qtrue;
 	}
-	if ( Q_stricmp( cmd, "setSaberAll" ) == 0 )
-	{
-		if ( !g_cheats->integer )
-		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
-		}
+}
 
-		Svcmd_ForceSetLevel_f( FP_SABERTHROW );
-		Svcmd_ForceSetLevel_f( FP_SABER_DEFENSE );
-		Svcmd_ForceSetLevel_f( FP_SABER_OFFENSE );
-		for ( int i = SS_NONE+1; i < SS_NUM_SABER_STYLES; i++ )
-		{
-			g_entities[0].client->ps.saberStylesKnown |= (1<<i);
-		}
-		return qtrue;
+static void Svcmd_Secrets_f(void)
+{
+	const gentity_t *pl = &g_entities[0];
+	if(pl->client->sess.missionStats.totalSecrets < 1)
+	{
+		gi.Printf( "There are" S_COLOR_RED " NO " S_COLOR_WHITE "secrets on this map!\n" );
 	}
-	if ( Q_stricmp( cmd, "saberAttackCycle" ) == 0 )
+	else if(pl->client->sess.missionStats.secretsFound == pl->client->sess.missionStats.totalSecrets)
 	{
-		Svcmd_SaberAttackCycle_f();
-		return qtrue;
+		gi.Printf( "You've found all " S_COLOR_GREEN "%i" S_COLOR_WHITE " secrets on this map!\n", pl->client->sess.missionStats.secretsFound );
 	}
-	if ( Q_stricmp( cmd, "runscript" ) == 0 )
+	else
 	{
-		if ( !g_cheats->integer )
-		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
-		}
-		const char *cmd2 = gi.argv(1);
-
-		if ( cmd2 && cmd2[0] )
-		{
-			const char *cmd3 = gi.argv(2);
-			if ( cmd3 && cmd3[0] )
-			{
-				gentity_t *found = NULL;
-				if ( (found = G_Find(NULL, FOFS(targetname), cmd2 ) ) != NULL )
-				{
-					Quake3Game()->RunScript( found, cmd3 );
-				}
-				else
-				{
-					//can't find cmd2
-					gi.Printf( S_COLOR_RED"runscript: can't find targetname %s\n", cmd2 );
-				}
-			}
-			else
-			{
-				Quake3Game()->RunScript( &g_entities[0], cmd2 );
-			}
-		}
-		else
-		{
-			gi.Printf( S_COLOR_RED"usage: runscript <ent targetname> scriptname\n" );
-		}
-		//FIXME: else warning
-		return qtrue;
+		gi.Printf( "You've found " S_COLOR_GREEN "%i" S_COLOR_WHITE " out of " S_COLOR_GREEN "%i" S_COLOR_WHITE " secrets!\n", pl->client->sess.missionStats.secretsFound, pl->client->sess.missionStats.totalSecrets );
 	}
+}
 
-	if ( Q_stricmp( cmd, "playerteam" ) == 0 )
-	{
-		if ( !g_cheats->integer )
-		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
-		}
-		const char	*cmd2 = gi.argv(1);
-		int		n;
+// PADAWAN - g_spskill 0 + cg_crosshairForceHint 1 + handicap 100
+// JEDI - g_spskill 1 + cg_crosshairForceHint 1 + handicap 100
+// JEDI KNIGHT - g_spskill 2 + cg_crosshairForceHint 0 + handicapp 100
+// JEDI MASTER - g_spskill 2 + cg_crosshairForceHint 0 + handicap 50
 
-		if ( !*cmd2 || !cmd2[0] )
-		{
-			gi.Printf( S_COLOR_RED"'playerteam' - change player team, requires a team name!\n" );
-			gi.Printf( S_COLOR_RED"Valid team names are:\n");
-			for ( n = (TEAM_FREE + 1); n < TEAM_NUM_TEAMS; n++ )
-			{
-				gi.Printf( S_COLOR_RED"%s\n", GetStringForID( TeamTable, n ) );
-			}
-		}
-		else
-		{
-			team_t	team;
+static void Svcmd_Difficulty_f(void)
+{
+	gi.Printf( S_COLOR_RED "This command is not yet implemented!" S_COLOR_WHITE "\n" );
+}
 
-			team = (team_t)GetIDForString( TeamTable, cmd2 );
-			if ( team == (team_t)-1 )
-			{
-				gi.Printf( S_COLOR_RED"'playerteam' unrecognized team name %s!\n", cmd2 );
-				gi.Printf( S_COLOR_RED"Valid team names are:\n");
-				for ( n = TEAM_FREE; n < TEAM_NUM_TEAMS; n++ )
-				{
-					gi.Printf( S_COLOR_RED"%s\n", GetStringForID( TeamTable, n ) );
-				}
-			}
-			else
-			{
-				g_entities[0].client->playerTeam = team;
-				//FIXME: convert Imperial, Malon, Hirogen and Klingon to Scavenger?
-			}
-		}
-		return qtrue;
-	}
+#define CMD_NONE				(0x00000000u)
+#define CMD_CHEAT				(0x00000001u)
+#define CMD_ALIVE				(0x00000002u)
 
-	if ( Q_stricmp( cmd, "control" ) == 0 )
-	{
-		if ( !g_cheats->integer )
-		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
-		}
-		const char	*cmd2 = gi.argv(1);
-		if ( !*cmd2 || !cmd2[0] )
-		{
-			if ( !G_ClearViewEntity( &g_entities[0] ) )
-			{
-				gi.Printf( S_COLOR_RED"control <NPC_targetname>\n", cmd2 );
-			}
-		}
-		else
-		{
-			Q3_SetViewEntity( 0, cmd2 );
-		}
-		return qtrue;
-	}
+typedef struct svcmd_s {
+	const char	*name;
+	void		(*func)(void);
+	uint32_t	flags;
+} svcmd_t;
 
-	if ( Q_stricmp( cmd, "grab" ) == 0 )
-	{
-		if ( !g_cheats->integer )
-		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
-		}
-		const char	*cmd2 = gi.argv(1);
-		if ( !*cmd2 || !cmd2[0] )
-		{
-			if ( !G_ReleaseEntity( &g_entities[0] ) )
-			{
-				gi.Printf( S_COLOR_RED"grab <NPC_targetname>\n", cmd2 );
-			}
-		}
-		else
-		{
-			G_GrabEntity( &g_entities[0], cmd2 );
-		}
-		return qtrue;
-	}
+static int svcmdcmp( const void *a, const void *b ) {
+	return Q_stricmp( (const char *)a, ((svcmd_t*)b)->name );
+}
 
-	if ( Q_stricmp( cmd, "knockdown" ) == 0 )
-	{
-		if ( !g_cheats->integer )
-		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
-		}
-		G_Knockdown( &g_entities[0], &g_entities[0], vec3_origin, 300, qtrue );
-		return qtrue;
-	}
+// FIXME some of these should be made CMD_ALIVE too!
+static svcmd_t svcmds[] = {
+	{ "entitylist",					Svcmd_EntityList_f,							CMD_NONE },
+	{ "game_memory",				Svcmd_GameMem_f,							CMD_NONE },
+
+	{ "nav",						Svcmd_Nav_f,								CMD_CHEAT },
+	{ "npc",						Svcmd_NPC_f,								CMD_CHEAT },
+	{ "use",						Svcmd_Use_f,								CMD_CHEAT },
+	{ "ICARUS",						Svcmd_ICARUS_f,								CMD_CHEAT },
+
+	{ "saberColor",					Svcmd_SaberColor_f,							CMD_CHEAT },
+	{ "saber",						Svcmd_Saber_f,								CMD_CHEAT },
+	{ "saberBlade",					Svcmd_SaberBlade_f,							CMD_CHEAT },
+	
+	{ "setForceJump",				Svcmd_ForceSetLevel_f<FP_LEVITATION>,		CMD_CHEAT },
+	{ "setSaberThrow",				Svcmd_ForceSetLevel_f<FP_SABERTHROW>,		CMD_CHEAT },
+	{ "setForceHeal",				Svcmd_ForceSetLevel_f<FP_HEAL>,				CMD_CHEAT },
+	{ "setForcePush",				Svcmd_ForceSetLevel_f<FP_PUSH>,				CMD_CHEAT },
+	{ "setForcePull",				Svcmd_ForceSetLevel_f<FP_PULL>,				CMD_CHEAT },
+	{ "setForceSpeed",				Svcmd_ForceSetLevel_f<FP_SPEED>,			CMD_CHEAT },
+	{ "setForceGrip",				Svcmd_ForceSetLevel_f<FP_GRIP>,				CMD_CHEAT },
+	{ "setForceLightning",			Svcmd_ForceSetLevel_f<FP_LIGHTNING>,		CMD_CHEAT },
+	{ "setMindTrick",				Svcmd_ForceSetLevel_f<FP_TELEPATHY>,		CMD_CHEAT },
+	{ "setSaberDefense",			Svcmd_ForceSetLevel_f<FP_SABER_DEFENSE>,	CMD_CHEAT },
+	{ "setSaberOffense",			Svcmd_ForceSetLevel_f<FP_SABER_OFFENSE>,	CMD_CHEAT },
+	{ "setForceRage",				Svcmd_ForceSetLevel_f<FP_RAGE>,				CMD_CHEAT },
+	{ "setForceDrain",				Svcmd_ForceSetLevel_f<FP_DRAIN>,			CMD_CHEAT },
+	{ "setForceProtect",			Svcmd_ForceSetLevel_f<FP_PROTECT>,			CMD_CHEAT },
+	{ "setForceAbsorb",				Svcmd_ForceSetLevel_f<FP_ABSORB>,			CMD_CHEAT },
+	{ "setForceSight",				Svcmd_ForceSetLevel_f<FP_SEE>,				CMD_CHEAT },
+	{ "setForceAll",				Svcmd_SetForceAll_f,						CMD_CHEAT },
+	{ "setSaberAll",				Svcmd_SetSaberAll_f,						CMD_CHEAT },
+	
+	{ "saberAttackCycle",			Svcmd_SaberAttackCycle_f,					CMD_NONE },
+	
+	{ "runscript",					Svcmd_RunScript_f,							CMD_CHEAT },
+	
+	{ "playerTeam",					Svcmd_PlayerTeam_f,							CMD_CHEAT },
+	
+	{ "control",					Svcmd_Control_f,							CMD_CHEAT },
+	{ "grab",						Svcmd_Grab_f,								CMD_CHEAT },
+	{ "knockdown",					Svcmd_Knockdown_f,							CMD_CHEAT },
+	{ "playerModel",				Svcmd_PlayerModel_f,						CMD_NONE },
+	{ "playerTint",					Svcmd_PlayerTint_f,							CMD_NONE },
+	
+	{ "nexttestaxes",				G_NextTestAxes,								CMD_NONE },
+	
+	{ "exitview",					Svcmd_ExitView_f,							CMD_NONE },
+	
+	{ "iknowkungfu",				Svcmd_IKnowKungfu_f,						CMD_CHEAT },
+	
+	{ "secrets",					Svcmd_Secrets_f,							CMD_NONE },
+	{ "difficulty",					Svcmd_Difficulty_f,							CMD_NONE },
+	
+	//{ "say",						Svcmd_Say_f,						qtrue },
+	//{ "toggleallowvote",			Svcmd_ToggleAllowVote_f,			qfalse },
+	//{ "toggleuserinfovalidation",	Svcmd_ToggleUserinfoValidation_f,	qfalse },
+};
+static const size_t numsvcmds = ARRAY_LEN( svcmds );
 
-	if ( Q_stricmp( cmd, "playerModel" ) == 0 )
-	{
-		if ( gi.argc() == 1 )
-		{
-			gi.Printf( S_COLOR_RED"USAGE: playerModel <NPC Name>\n       playerModel <g2model> <skinhead> <skintorso> <skinlower>\n       playerModel player (builds player from customized menu settings)\n" );
-			gi.Printf( "playerModel = %s ", va("%s %s %s %s\n", g_char_model->string, g_char_skin_head->string, g_char_skin_torso->string, g_char_skin_legs->string ) );
-		}
-		else if ( gi.argc() == 2 )
-		{
-			G_ChangePlayerModel( &g_entities[0], gi.argv(1) );
-		}
-		else if (  gi.argc() == 5 )
-		{
-			//instead of setting it directly via a command, we now store it in cvars
-			//G_ChangePlayerModel( &g_entities[0], va("%s|%s|%s|%s", gi.argv(1), gi.argv(2), gi.argv(3), gi.argv(4)) );
-			gi.cvar_set("g_char_model", gi.argv(1) );
-			gi.cvar_set("g_char_skin_head", gi.argv(2) );
-			gi.cvar_set("g_char_skin_torso", gi.argv(3) );
-			gi.cvar_set("g_char_skin_legs", gi.argv(4) );
-			G_InitPlayerFromCvars( &g_entities[0] );
-		}
-		return qtrue;
-	}
+/*
+=================
+ConsoleCommand
+=================
+*/
+qboolean	ConsoleCommand( void ) {
+	const char *cmd = gi.argv(0);
+	const svcmd_t *command = (const svcmd_t *)Q_LinearSearch( cmd, svcmds, numsvcmds, sizeof( svcmds[0] ), svcmdcmp );
 
-	if ( Q_stricmp( cmd, "playerTint" ) == 0 )
+	if ( !command )
+		return qfalse;
+	
+	if ( (command->flags & CMD_CHEAT)
+		&& !g_cheats->integer )
 	{
-		if ( gi.argc() == 4 )
-		{
-			g_entities[0].client->renderInfo.customRGBA[0] = atoi(gi.argv(1));
-			g_entities[0].client->renderInfo.customRGBA[1] = atoi(gi.argv(2));
-			g_entities[0].client->renderInfo.customRGBA[2] = atoi(gi.argv(3));
-			gi.cvar_set("g_char_color_red", gi.argv(1) );
-			gi.cvar_set("g_char_color_green", gi.argv(2) );
-			gi.cvar_set("g_char_color_blue", gi.argv(3) );
-		}
-		else
-		{
-			gi.Printf( S_COLOR_RED"USAGE: playerTint <red 0 - 255> <green 0 - 255> <blue 0 - 255>\n" );
-			gi.Printf( "playerTint = %s\n", va("%d %d %d", g_char_color_red->integer, g_char_color_green->integer, g_char_color_blue->integer ) );
-		}
+		gi.Printf( "Cheats are not enabled on this server.\n" );
 		return qtrue;
 	}
-	if ( Q_stricmp( cmd, "nexttestaxes" ) == 0 )
-	{
-		G_NextTestAxes();
-	}
-
-	if ( Q_stricmp( cmd, "exitview" ) == 0 )
-	{
-		Svcmd_ExitView_f();
-	}
-
-	if (Q_stricmp (cmd, "iknowkungfu") == 0)
+	else if ( (command->flags & CMD_ALIVE)
+		&& (g_entities[0].health <= 0) )
 	{
-		if ( !g_cheats->integer )
-		{
-			gi.SendServerCommand( 0, "print \"Cheats are not enabled on this server.\n\"");
-			return qtrue;
-		}
-
-		gi.cvar_set( "g_debugMelee", "1" );
-		G_SetWeapon( &g_entities[0], WP_MELEE );
-		for ( int i = FP_FIRST; i < NUM_FORCE_POWERS; i++ )
-		{
-			g_entities[0].client->ps.forcePowersKnown |= ( 1 << i );
-			if ( i == FP_TELEPATHY )
-			{
-				g_entities[0].client->ps.forcePowerLevel[i] = FORCE_LEVEL_4;
-			}
-			else
-			{
-				g_entities[0].client->ps.forcePowerLevel[i] = FORCE_LEVEL_3;
-			}
-		}
+		gi.Printf( "You must be alive to use this command.\n" );
+		return qtrue;
 	}
-
-	return qfalse;
+	else
+		command->func();
+	return qtrue;
 }
 
diff --git a/code/qcommon/q_shared.cpp b/code/qcommon/q_shared.cpp
index 9c33eae..6eb1a67 100644
--- a/code/qcommon/q_shared.cpp
+++ b/code/qcommon/q_shared.cpp
@@ -1023,3 +1023,27 @@ const char *GetStringForID( const stringID_table_t *table, int id )
 
 	return NULL;
 }
+
+qboolean Q_InBitflags( const uint32_t *bits, int index, uint32_t bitsPerByte ) {
+	return ( bits[index / bitsPerByte] & (1 << (index % bitsPerByte)) ) ? qtrue : qfalse;
+}
+
+void Q_AddToBitflags( uint32_t *bits, int index, uint32_t bitsPerByte ) {
+	bits[index / bitsPerByte] |= (1 << (index % bitsPerByte));
+}
+
+void Q_RemoveFromBitflags( uint32_t *bits, int index, uint32_t bitsPerByte ) {
+	bits[index / bitsPerByte] &= ~(1 << (index % bitsPerByte));
+}
+
+void *Q_LinearSearch( const void *key, const void *ptr, size_t count,
+	size_t size, cmpFunc_t cmp )
+{
+	size_t i;
+	for ( i = 0; i < count; i++ )
+	{
+		if ( cmp( key, ptr ) == 0 ) return (void *)ptr;
+		ptr = (const char *)ptr + size;
+	}
+	return NULL;
+}
\ No newline at end of file
diff --git a/code/qcommon/q_shared.h b/code/qcommon/q_shared.h
index 20e4aaa..2bd355d 100644
--- a/code/qcommon/q_shared.h
+++ b/code/qcommon/q_shared.h
@@ -2752,4 +2752,13 @@ typedef enum
 
 } ForceReload_e;
 
+qboolean Q_InBitflags( const uint32_t *bits, int index, uint32_t bitsPerByte );
+void Q_AddToBitflags( uint32_t *bits, int index, uint32_t bitsPerByte );
+void Q_RemoveFromBitflags( uint32_t *bits, int index, uint32_t bitsPerByte );
+
+typedef int( *cmpFunc_t )(const void *a, const void *b);
+
+void *Q_LinearSearch( const void *key, const void *ptr, size_t count,
+	size_t size, cmpFunc_t cmp );
+
 #endif	// __Q_SHARED_H

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/openjk.git



More information about the Pkg-games-commits mailing list