codemp/cgame/cg_consolecmds.c

Go to the documentation of this file.
00001 // Copyright (C) 1999-2000 Id Software, Inc.
00002 //
00003 // cg_consolecmds.c -- text commands typed in at the local console, or
00004 // executed by a key binding
00005 
00006 #include "cg_local.h"
00007 #include "../ui/ui_shared.h"
00008 #include "bg_saga.h"
00009 extern menuDef_t *menuScoreboard;
00010 
00011 
00012 
00013 void CG_TargetCommand_f( void ) {
00014         int             targetNum;
00015         char    test[4];
00016 
00017         targetNum = CG_CrosshairPlayer();
00018         if (!targetNum ) {
00019                 return;
00020         }
00021 
00022         trap_Argv( 1, test, 4 );
00023         trap_SendConsoleCommand( va( "gc %i %i", targetNum, atoi( test ) ) );
00024 }
00025 
00026 
00027 
00028 /*
00029 =================
00030 CG_SizeUp_f
00031 
00032 Keybinding command
00033 =================
00034 */
00035 static void CG_SizeUp_f (void) {
00036         trap_Cvar_Set("cg_viewsize", va("%i",(int)(cg_viewsize.integer+10)));
00037 }
00038 
00039 
00040 /*
00041 =================
00042 CG_SizeDown_f
00043 
00044 Keybinding command
00045 =================
00046 */
00047 static void CG_SizeDown_f (void) {
00048         trap_Cvar_Set("cg_viewsize", va("%i",(int)(cg_viewsize.integer-10)));
00049 }
00050 
00051 
00052 /*
00053 =============
00054 CG_Viewpos_f
00055 
00056 Debugging command to print the current position
00057 =============
00058 */
00059 static void CG_Viewpos_f (void) {
00060         CG_Printf ("%s (%i %i %i) : %i\n", cgs.mapname, (int)cg.refdef.vieworg[0],
00061                 (int)cg.refdef.vieworg[1], (int)cg.refdef.vieworg[2], 
00062                 (int)cg.refdef.viewangles[YAW]);
00063 }
00064 
00065 
00066 static void CG_ScoresDown_f( void ) {
00067 
00068         CG_BuildSpectatorString();
00069         if ( cg.scoresRequestTime + 2000 < cg.time ) {
00070                 // the scores are more than two seconds out of data,
00071                 // so request new ones
00072                 cg.scoresRequestTime = cg.time;
00073                 trap_SendClientCommand( "score" );
00074 
00075                 // leave the current scores up if they were already
00076                 // displayed, but if this is the first hit, clear them out
00077                 if ( !cg.showScores ) {
00078                         cg.showScores = qtrue;
00079                         cg.numScores = 0;
00080                 }
00081         } else {
00082                 // show the cached contents even if they just pressed if it
00083                 // is within two seconds
00084                 cg.showScores = qtrue;
00085         }
00086 }
00087 
00088 static void CG_ScoresUp_f( void ) {
00089         if ( cg.showScores ) {
00090                 cg.showScores = qfalse;
00091                 cg.scoreFadeTime = cg.time;
00092         }
00093 }
00094 
00095 extern menuDef_t *menuScoreboard;
00096 void Menu_Reset();                      // FIXME: add to right include file
00097 
00098 static void CG_scrollScoresDown_f( void) {
00099         if (menuScoreboard && cg.scoreBoardShowing) {
00100                 Menu_ScrollFeeder(menuScoreboard, FEEDER_SCOREBOARD, qtrue);
00101                 Menu_ScrollFeeder(menuScoreboard, FEEDER_REDTEAM_LIST, qtrue);
00102                 Menu_ScrollFeeder(menuScoreboard, FEEDER_BLUETEAM_LIST, qtrue);
00103         }
00104 }
00105 
00106 
00107 static void CG_scrollScoresUp_f( void) {
00108         if (menuScoreboard && cg.scoreBoardShowing) {
00109                 Menu_ScrollFeeder(menuScoreboard, FEEDER_SCOREBOARD, qfalse);
00110                 Menu_ScrollFeeder(menuScoreboard, FEEDER_REDTEAM_LIST, qfalse);
00111                 Menu_ScrollFeeder(menuScoreboard, FEEDER_BLUETEAM_LIST, qfalse);
00112         }
00113 }
00114 
00115 
00116 static void CG_spWin_f( void) {
00117         trap_Cvar_Set("cg_cameraOrbit", "2");
00118         trap_Cvar_Set("cg_cameraOrbitDelay", "35");
00119         trap_Cvar_Set("cg_thirdPerson", "1");
00120         trap_Cvar_Set("cg_thirdPersonAngle", "0");
00121         trap_Cvar_Set("cg_thirdPersonRange", "100");
00122         CG_AddBufferedSound(cgs.media.winnerSound);
00123         //trap_S_StartLocalSound(cgs.media.winnerSound, CHAN_ANNOUNCER);
00124         CG_CenterPrint(CG_GetStringEdString("MP_INGAME", "YOU_WIN"), SCREEN_HEIGHT * .30, 0);
00125 }
00126 
00127 static void CG_spLose_f( void) {
00128         trap_Cvar_Set("cg_cameraOrbit", "2");
00129         trap_Cvar_Set("cg_cameraOrbitDelay", "35");
00130         trap_Cvar_Set("cg_thirdPerson", "1");
00131         trap_Cvar_Set("cg_thirdPersonAngle", "0");
00132         trap_Cvar_Set("cg_thirdPersonRange", "100");
00133         CG_AddBufferedSound(cgs.media.loserSound);
00134         //trap_S_StartLocalSound(cgs.media.loserSound, CHAN_ANNOUNCER);
00135         CG_CenterPrint(CG_GetStringEdString("MP_INGAME", "YOU_LOSE"), SCREEN_HEIGHT * .30, 0);
00136 }
00137 
00138 
00139 static void CG_TellTarget_f( void ) {
00140         int             clientNum;
00141         char    command[128];
00142         char    message[128];
00143 
00144         clientNum = CG_CrosshairPlayer();
00145         if ( clientNum == -1 ) {
00146                 return;
00147         }
00148 
00149         trap_Args( message, 128 );
00150         Com_sprintf( command, 128, "tell %i %s", clientNum, message );
00151         trap_SendClientCommand( command );
00152 }
00153 
00154 static void CG_TellAttacker_f( void ) {
00155         int             clientNum;
00156         char    command[128];
00157         char    message[128];
00158 
00159         clientNum = CG_LastAttacker();
00160         if ( clientNum == -1 ) {
00161                 return;
00162         }
00163 
00164         trap_Args( message, 128 );
00165         Com_sprintf( command, 128, "tell %i %s", clientNum, message );
00166         trap_SendClientCommand( command );
00167 }
00168 
00169 
00170 /*
00171 ==================
00172 CG_StartOrbit_f
00173 ==================
00174 */
00175 
00176 static void CG_StartOrbit_f( void ) {
00177         char var[MAX_TOKEN_CHARS];
00178 
00179         trap_Cvar_VariableStringBuffer( "developer", var, sizeof( var ) );
00180         if ( !atoi(var) ) {
00181                 return;
00182         }
00183         if (cg_cameraOrbit.value != 0) {
00184                 trap_Cvar_Set ("cg_cameraOrbit", "0");
00185                 trap_Cvar_Set("cg_thirdPerson", "0");
00186         } else {
00187                 trap_Cvar_Set("cg_cameraOrbit", "5");
00188                 trap_Cvar_Set("cg_thirdPerson", "1");
00189                 trap_Cvar_Set("cg_thirdPersonAngle", "0");
00190                 trap_Cvar_Set("cg_thirdPersonRange", "100");
00191         }
00192 }
00193 
00194 void CG_SiegeBriefingDisplay(int team, int dontshow);
00195 static void CG_SiegeBriefing_f(void)
00196 {
00197         int team;
00198 
00199         if (cgs.gametype != GT_SIEGE)
00200         { //Cannot be displayed unless in this gametype
00201                 return;
00202         }
00203 
00204         team = cg.predictedPlayerState.persistant[PERS_TEAM];
00205 
00206         if (team != SIEGETEAM_TEAM1 &&
00207                 team != SIEGETEAM_TEAM2)
00208         { //cannot be displayed if not on a valid team
00209                 return;
00210         }
00211 
00212         CG_SiegeBriefingDisplay(team, 0);
00213 }
00214 
00215 static void CG_SiegeCvarUpdate_f(void)
00216 {
00217         int team;
00218 
00219         if (cgs.gametype != GT_SIEGE)
00220         { //Cannot be displayed unless in this gametype
00221                 return;
00222         }
00223 
00224         team = cg.predictedPlayerState.persistant[PERS_TEAM];
00225 
00226         if (team != SIEGETEAM_TEAM1 &&
00227                 team != SIEGETEAM_TEAM2)
00228         { //cannot be displayed if not on a valid team
00229                 return;
00230         }
00231 
00232         CG_SiegeBriefingDisplay(team, 1);
00233 }
00234 static void CG_SiegeCompleteCvarUpdate_f(void)
00235 {
00236 
00237         if (cgs.gametype != GT_SIEGE)
00238         { //Cannot be displayed unless in this gametype
00239                 return;
00240         }
00241 
00242         // Set up cvars for both teams
00243         CG_SiegeBriefingDisplay(SIEGETEAM_TEAM1, 1);
00244         CG_SiegeBriefingDisplay(SIEGETEAM_TEAM2, 1);
00245 }
00246 /*
00247 static void CG_Camera_f( void ) {
00248         char name[1024];
00249         trap_Argv( 1, name, sizeof(name));
00250         if (trap_loadCamera(name)) {
00251                 cg.cameraMode = qtrue;
00252                 trap_startCamera(cg.time);
00253         } else {
00254                 CG_Printf ("Unable to load camera %s\n",name);
00255         }
00256 }
00257 */
00258 
00259 
00260 typedef struct {
00261         char    *cmd;
00262         void    (*function)(void);
00263 } consoleCommand_t;
00264 
00265 static consoleCommand_t commands[] = {
00266         { "testgun", CG_TestGun_f },
00267         { "testmodel", CG_TestModel_f },
00268         { "nextframe", CG_TestModelNextFrame_f },
00269         { "prevframe", CG_TestModelPrevFrame_f },
00270         { "nextskin", CG_TestModelNextSkin_f },
00271         { "prevskin", CG_TestModelPrevSkin_f },
00272         { "viewpos", CG_Viewpos_f },
00273         { "+scores", CG_ScoresDown_f },
00274         { "-scores", CG_ScoresUp_f },
00275         { "sizeup", CG_SizeUp_f },
00276         { "sizedown", CG_SizeDown_f },
00277         { "weapnext", CG_NextWeapon_f },
00278         { "weapprev", CG_PrevWeapon_f },
00279         { "weapon", CG_Weapon_f },
00280         { "weaponclean", CG_WeaponClean_f },
00281         { "tell_target", CG_TellTarget_f },
00282         { "tell_attacker", CG_TellAttacker_f },
00283         { "tcmd", CG_TargetCommand_f },
00284         { "spWin", CG_spWin_f },
00285         { "spLose", CG_spLose_f },
00286         { "scoresDown", CG_scrollScoresDown_f },
00287         { "scoresUp", CG_scrollScoresUp_f },
00288         { "startOrbit", CG_StartOrbit_f },
00289         //{ "camera", CG_Camera_f },
00290         { "loaddeferred", CG_LoadDeferredPlayers },
00291         { "invnext", CG_NextInventory_f },
00292         { "invprev", CG_PrevInventory_f },
00293         { "forcenext", CG_NextForcePower_f },
00294         { "forceprev", CG_PrevForcePower_f },
00295         { "briefing", CG_SiegeBriefing_f },
00296         { "siegeCvarUpdate", CG_SiegeCvarUpdate_f },
00297         { "siegeCompleteCvarUpdate", CG_SiegeCompleteCvarUpdate_f },
00298 };
00299 
00300 
00301 /*
00302 =================
00303 CG_ConsoleCommand
00304 
00305 The string has been tokenized and can be retrieved with
00306 Cmd_Argc() / Cmd_Argv()
00307 =================
00308 */
00309 qboolean CG_ConsoleCommand( void ) {
00310         const char      *cmd;
00311         int             i;
00312 
00313         cmd = CG_Argv(0);
00314 
00315         for ( i = 0 ; i < sizeof( commands ) / sizeof( commands[0] ) ; i++ ) {
00316                 if ( !Q_stricmp( cmd, commands[i].cmd ) ) {
00317                         commands[i].function();
00318                         return qtrue;
00319                 }
00320         }
00321 
00322         return qfalse;
00323 }
00324 
00325 
00326 /*
00327 =================
00328 CG_InitConsoleCommands
00329 
00330 Let the client system know about all of our commands
00331 so it can perform tab completion
00332 =================
00333 */
00334 void CG_InitConsoleCommands( void ) {
00335         int             i;
00336 
00337         for ( i = 0 ; i < sizeof( commands ) / sizeof( commands[0] ) ; i++ ) {
00338                 trap_AddCommand( commands[i].cmd );
00339         }
00340 
00341         //
00342         // the game server will interpret these commands, which will be automatically
00343         // forwarded to the server after they are not recognized locally
00344         //
00345         trap_AddCommand ("forcechanged");
00346         trap_AddCommand ("sv_invnext");
00347         trap_AddCommand ("sv_invprev");
00348         trap_AddCommand ("sv_forcenext");
00349         trap_AddCommand ("sv_forceprev");
00350         trap_AddCommand ("sv_saberswitch");
00351         trap_AddCommand ("engage_duel");
00352         trap_AddCommand ("force_heal");
00353         trap_AddCommand ("force_speed");
00354         trap_AddCommand ("force_throw");
00355         trap_AddCommand ("force_pull");
00356         trap_AddCommand ("force_distract");
00357         trap_AddCommand ("force_rage");
00358         trap_AddCommand ("force_protect");
00359         trap_AddCommand ("force_absorb");
00360         trap_AddCommand ("force_healother");
00361         trap_AddCommand ("force_forcepowerother");
00362         trap_AddCommand ("force_seeing");
00363         trap_AddCommand ("use_seeker");
00364         trap_AddCommand ("use_field");
00365         trap_AddCommand ("use_bacta");
00366         trap_AddCommand ("use_electrobinoculars");
00367         trap_AddCommand ("zoom");
00368         trap_AddCommand ("use_sentry");
00369         trap_AddCommand ("bot_order");
00370         trap_AddCommand ("saberAttackCycle");
00371         trap_AddCommand ("kill");
00372         trap_AddCommand ("say");
00373         trap_AddCommand ("say_team");
00374         trap_AddCommand ("tell");
00375         trap_AddCommand ("give");
00376         trap_AddCommand ("god");
00377         trap_AddCommand ("notarget");
00378         trap_AddCommand ("noclip");
00379         trap_AddCommand ("team");
00380         trap_AddCommand ("follow");
00381         trap_AddCommand ("levelshot");
00382         trap_AddCommand ("addbot");
00383         trap_AddCommand ("setviewpos");
00384         trap_AddCommand ("callvote");
00385         trap_AddCommand ("vote");
00386         trap_AddCommand ("callteamvote");
00387         trap_AddCommand ("teamvote");
00388         trap_AddCommand ("stats");
00389         trap_AddCommand ("teamtask");
00390         trap_AddCommand ("loaddefered");        // spelled wrong, but not changing for demo
00391 }