2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
32 #include "../Game_local.h"
41 float Cmd_GetFloatArg( const idCmdArgs &args, int &argNum ) {
44 value = args.Argv( argNum++ );
53 void Cmd_EntityList_f( const idCmdArgs &args ) {
60 if ( args.Argc() > 1 ) {
62 match.Replace( " ", "" );
70 gameLocal.Printf( "%-4s %-20s %-20s %s\n", " Num", "EntityDef", "Class", "Name" );
71 gameLocal.Printf( "--------------------------------------------------------------------\n" );
72 for( e = 0; e < MAX_GENTITIES; e++ ) {
73 check = gameLocal.entities[ e ];
79 if ( !check->name.Filter( match, true ) ) {
83 gameLocal.Printf( "%4i: %-20s %-20s %s\n", e,
84 check->GetEntityDefName(), check->GetClassname(), check->name.c_str() );
87 size += check->spawnArgs.Allocated();
90 gameLocal.Printf( "...%d entities\n...%d bytes of spawnargs\n", count, size );
95 Cmd_ActiveEntityList_f
98 void Cmd_ActiveEntityList_f( const idCmdArgs &args ) {
104 gameLocal.Printf( "%-4s %-20s %-20s %s\n", " Num", "EntityDef", "Class", "Name" );
105 gameLocal.Printf( "--------------------------------------------------------------------\n" );
106 for( check = gameLocal.activeEntities.Next(); check != NULL; check = check->activeNode.Next() ) {
107 char dormant = check->fl.isDormant ? '-' : ' ';
108 gameLocal.Printf( "%4i:%c%-20s %-20s %s\n", check->entityNumber, dormant, check->GetEntityDefName(), check->GetClassname(), check->name.c_str() );
112 gameLocal.Printf( "...%d active entities\n", count );
120 void Cmd_ListSpawnArgs_f( const idCmdArgs &args ) {
124 ent = gameLocal.FindEntity( args.Argv( 1 ) );
126 gameLocal.Printf( "entity not found\n" );
130 for ( i = 0; i < ent->spawnArgs.GetNumKeyVals(); i++ ) {
131 const idKeyValue *kv = ent->spawnArgs.GetKeyVal( i );
132 gameLocal.Printf( "\"%s\" "S_COLOR_WHITE"\"%s\"\n", kv->GetKey().c_str(), kv->GetValue().c_str() );
141 void Cmd_ReloadScript_f( const idCmdArgs &args ) {
142 // shutdown the map because entities may point to script objects
143 gameLocal.MapShutdown();
145 // recompile the scripts
146 gameLocal.program.Startup( SCRIPT_DEFAULT );
149 // loads a game specific main script file
152 for ( i = 0; i < 2; i++ ) {
154 gamedir = cvarSystem->GetCVarString( "fs_game_base" );
155 } else if ( i == 1 ) {
156 gamedir = cvarSystem->GetCVarString( "fs_game" );
158 if ( gamedir.Length() > 0 ) {
159 idStr scriptFile = va( "script/%s_main.script", gamedir.c_str() );
160 if ( fileSystem->ReadFile(scriptFile.c_str(), NULL) > 0 ) {
161 gameLocal.program.CompileFile( scriptFile.c_str() );
162 gameLocal.program.FinishCompilation();
168 // error out so that the user can rerun the scripts
169 gameLocal.Error( "Exiting map to reload scripts" );
177 void Cmd_Script_f( const idCmdArgs &args ) {
181 static int funccount = 0;
183 const function_t *func;
186 if ( !gameLocal.CheatsOk() ) {
190 sprintf( funcname, "ConsoleFunction_%d", funccount++ );
192 script = args.Args();
193 sprintf( text, "void %s() {%s;}\n", funcname.c_str(), script );
194 if ( gameLocal.program.CompileText( "console", text, true ) ) {
195 func = gameLocal.program.FindFunction( funcname );
197 // set all the entity names in case the user named one in the script that wasn't referenced in the default script
198 for( ent = gameLocal.spawnedEntities.Next(); ent != NULL; ent = ent->spawnNode.Next() ) {
199 gameLocal.program.SetEntity( ent->name, ent );
202 thread = new idThread( func );
212 Kills all the entities of the given class in a level.
215 void KillEntities( const idCmdArgs &args, const idTypeInfo &superClass ) {
221 if ( !gameLocal.GetLocalPlayer() || !gameLocal.CheatsOk( false ) ) {
225 for( i = 1; i < args.Argc(); i++ ) {
226 name = args.Argv( i );
227 ignore.Append( name );
230 for( ent = gameLocal.spawnedEntities.Next(); ent != NULL; ent = ent->spawnNode.Next() ) {
231 if ( ent->IsType( superClass ) ) {
232 for( i = 0; i < ignore.Num(); i++ ) {
233 if ( ignore[ i ] == ent->name ) {
238 if ( i >= ignore.Num() ) {
239 ent->PostEventMS( &EV_Remove, 0 );
249 Kills all the monsters in a level.
252 void Cmd_KillMonsters_f( const idCmdArgs &args ) {
253 KillEntities( args, idAI::Type );
255 // kill any projectiles as well since they have pointers to the monster that created them
256 KillEntities( args, idProjectile::Type );
263 Kills all the moveables in a level.
266 void Cmd_KillMovables_f( const idCmdArgs &args ) {
267 if ( !gameLocal.GetLocalPlayer() || !gameLocal.CheatsOk( false ) ) {
270 KillEntities( args, idMoveable::Type );
277 Kills all the ragdolls in a level.
280 void Cmd_KillRagdolls_f( const idCmdArgs &args ) {
281 if ( !gameLocal.GetLocalPlayer() || !gameLocal.CheatsOk( false ) ) {
284 KillEntities( args, idAFEntity_Generic::Type );
285 KillEntities( args, idAFEntity_WithAttachedHead::Type );
292 Give items to a client
295 void Cmd_Give_f( const idCmdArgs &args ) {
301 player = gameLocal.GetLocalPlayer();
302 if ( !player || !gameLocal.CheatsOk() ) {
306 name = args.Argv( 1 );
308 if ( idStr::Icmp( name, "all" ) == 0 ) {
314 if ( give_all || ( idStr::Cmpn( name, "weapon", 6 ) == 0 ) ) {
315 if ( gameLocal.world->spawnArgs.GetBool( "no_Weapons" ) ) {
316 gameLocal.world->spawnArgs.SetBool( "no_Weapons", false );
317 for( i = 0; i < gameLocal.numClients; i++ ) {
318 if ( gameLocal.entities[ i ] ) {
319 gameLocal.entities[ i ]->PostEventSec( &EV_Player_SelectWeapon, 0.5f, gameLocal.entities[ i ]->spawnArgs.GetString( "def_weapon1" ) );
325 if ( ( idStr::Cmpn( name, "weapon_", 7 ) == 0 ) || ( idStr::Cmpn( name, "item_", 5 ) == 0 ) || ( idStr::Cmpn( name, "ammo_", 5 ) == 0 ) ) {
326 player->GiveItem( name );
330 if ( give_all || idStr::Icmp( name, "health" ) == 0 ) {
331 player->health = player->inventory.maxHealth;
337 if ( give_all || idStr::Icmp( name, "weapons" ) == 0 ) {
338 player->inventory.weapons = BIT( MAX_WEAPONS ) - 1;
339 player->CacheWeapons();
346 if ( give_all || idStr::Icmp( name, "ammo" ) == 0 ) {
347 for ( i = 0 ; i < AMMO_NUMTYPES; i++ ) {
348 player->inventory.ammo[ i ] = player->inventory.MaxAmmoForAmmoClass( player, idWeapon::GetAmmoNameForNum( ( ammo_t )i ) );
355 if ( give_all || idStr::Icmp( name, "armor" ) == 0 ) {
356 player->inventory.armor = player->inventory.maxarmor;
362 if ( idStr::Icmp( name, "berserk" ) == 0 ) {
363 player->GivePowerUp( BERSERK, SEC2MS( 30.0f ) );
367 if ( idStr::Icmp( name, "invis" ) == 0 ) {
368 player->GivePowerUp( INVISIBILITY, SEC2MS( 30.0f ) );
373 if ( idStr::Icmp( name, "invulnerability" ) == 0 ) {
374 if ( args.Argc() > 2 ) {
375 player->GivePowerUp( INVULNERABILITY, atoi( args.Argv( 2 ) ) );
378 player->GivePowerUp( INVULNERABILITY, 30000 );
383 if ( idStr::Icmp( name, "helltime" ) == 0 ) {
384 if ( args.Argc() > 2 ) {
385 player->GivePowerUp( HELLTIME, atoi( args.Argv( 2 ) ) );
388 player->GivePowerUp( HELLTIME, 30000 );
393 if ( idStr::Icmp( name, "envirosuit" ) == 0 ) {
394 if ( args.Argc() > 2 ) {
395 player->GivePowerUp( ENVIROSUIT, atoi( args.Argv( 2 ) ) );
398 player->GivePowerUp( ENVIROSUIT, 30000 );
403 if ( idStr::Icmp( name, "pda" ) == 0 ) {
404 player->GivePDA( args.Argv(2), NULL );
408 if ( idStr::Icmp( name, "video" ) == 0 ) {
409 player->GiveVideo( args.Argv(2), NULL );
413 if ( !give_all && !player->Give( args.Argv(1), args.Argv(2) ) ) {
414 gameLocal.Printf( "unknown item\n" );
422 Centers the players pitch
425 void Cmd_CenterView_f( const idCmdArgs &args ) {
429 player = gameLocal.GetLocalPlayer();
434 ang = player->viewAngles;
436 player->SetViewAngles( ang );
443 Sets client to godmode
448 void Cmd_God_f( const idCmdArgs &args ) {
452 player = gameLocal.GetLocalPlayer();
453 if ( !player || !gameLocal.CheatsOk() ) {
457 if ( player->godmode ) {
458 player->godmode = false;
459 msg = "godmode OFF\n";
461 player->godmode = true;
462 msg = "godmode ON\n";
465 gameLocal.Printf( "%s", msg );
472 Sets client to notarget
477 void Cmd_Notarget_f( const idCmdArgs &args ) {
481 player = gameLocal.GetLocalPlayer();
482 if ( !player || !gameLocal.CheatsOk() ) {
486 if ( player->fl.notarget ) {
487 player->fl.notarget = false;
488 msg = "notarget OFF\n";
490 player->fl.notarget = true;
491 msg = "notarget ON\n";
494 gameLocal.Printf( "%s", msg );
504 void Cmd_Noclip_f( const idCmdArgs &args ) {
508 player = gameLocal.GetLocalPlayer();
509 if ( !player || !gameLocal.CheatsOk() ) {
513 if ( player->noclip ) {
514 msg = "noclip OFF\n";
518 player->noclip = !player->noclip;
520 gameLocal.Printf( "%s", msg );
528 void Cmd_Kill_f( const idCmdArgs &args ) {
531 if ( gameLocal.isMultiplayer ) {
532 if ( gameLocal.isClient ) {
534 byte msgBuf[ MAX_GAME_MESSAGE_SIZE ];
535 outMsg.Init( msgBuf, sizeof( msgBuf ) );
536 outMsg.WriteByte( GAME_RELIABLE_MESSAGE_KILL );
537 networkSystem->ClientSendReliableMessage( outMsg );
539 player = gameLocal.GetClientByCmdArgs( args );
541 common->Printf( "kill <client nickname> or kill <client index>\n" );
544 player->Kill( false, false );
545 cmdSystem->BufferCommandText( CMD_EXEC_NOW, va( "say killed client %d '%s^0'\n", player->entityNumber, gameLocal.userInfo[ player->entityNumber ].GetString( "ui_name" ) ) );
548 player = gameLocal.GetLocalPlayer();
552 player->Kill( false, false );
561 void Cmd_PlayerModel_f( const idCmdArgs &args ) {
567 player = gameLocal.GetLocalPlayer();
568 if ( !player || !gameLocal.CheatsOk() ) {
572 if ( args.Argc() < 2 ) {
573 gameLocal.Printf( "usage: playerModel <modelname>\n" );
577 name = args.Argv( 1 );
578 player->spawnArgs.Set( "model", name );
580 pos = player->GetPhysics()->GetOrigin();
581 ang = player->viewAngles;
582 player->SpawnToPoint( pos, ang );
590 static void Cmd_Say( bool team, const idCmdArgs &args ) {
593 const char *cmd = team ? "sayTeam" : "say" ;
595 if ( !gameLocal.isMultiplayer ) {
596 gameLocal.Printf( "%s can only be used in a multiplayer game\n", cmd );
600 if ( args.Argc() < 2 ) {
601 gameLocal.Printf( "usage: %s <text>\n", cmd );
606 if ( text.Length() == 0 ) {
610 if ( text[ text.Length() - 1 ] == '\n' ) {
611 text[ text.Length() - 1 ] = '\0';
617 // here we need to special case a listen server to use the real client name instead of "server"
618 // "server" will only appear on a dedicated server
619 if ( gameLocal.isClient || cvarSystem->GetCVarInteger( "net_serverDedicated" ) == 0 ) {
620 player = gameLocal.localClientNum >= 0 ? static_cast<idPlayer *>( gameLocal.entities[ gameLocal.localClientNum ] ) : NULL;
622 name = player->GetUserInfo()->GetString( "ui_name", "player" );
626 // Append the player's location to team chat messages in CTF
627 if ( gameLocal.mpGame.IsGametypeFlagBased() && team && player ) {
628 idLocationEntity *locationEntity = gameLocal.LocationForPoint( player->GetEyePosition() );
630 if ( locationEntity ) {
632 temp += locationEntity->GetLocation();
646 if ( gameLocal.isClient ) {
649 outMsg.Init( msgBuf, sizeof( msgBuf ) );
650 outMsg.WriteByte( team ? GAME_RELIABLE_MESSAGE_TCHAT : GAME_RELIABLE_MESSAGE_CHAT );
651 outMsg.WriteString( name );
652 outMsg.WriteString( text, -1, false );
653 networkSystem->ClientSendReliableMessage( outMsg );
655 gameLocal.mpGame.ProcessChatMessage( gameLocal.localClientNum, team, name, text, NULL );
664 static void Cmd_Say_f( const idCmdArgs &args ) {
665 Cmd_Say( false, args );
673 static void Cmd_SayTeam_f( const idCmdArgs &args ) {
674 Cmd_Say( true, args );
682 static void Cmd_AddChatLine_f( const idCmdArgs &args ) {
683 gameLocal.mpGame.AddChatLine( args.Argv( 1 ) );
691 static void Cmd_Kick_f( const idCmdArgs &args ) {
694 if ( !gameLocal.isMultiplayer ) {
695 gameLocal.Printf( "kick can only be used in a multiplayer game\n" );
699 if ( gameLocal.isClient ) {
700 gameLocal.Printf( "You have no such power. This is a server command\n" );
704 player = gameLocal.GetClientByCmdArgs( args );
706 gameLocal.Printf( "usage: kick <client nickname> or kick <client index>\n" );
709 cmdSystem->BufferCommandText( CMD_EXEC_NOW, va( "say kicking out client %d '%s^0'\n", player->entityNumber, gameLocal.userInfo[ player->entityNumber ].GetString( "ui_name" ) ) );
710 cmdSystem->BufferCommandText( CMD_EXEC_NOW, va( "kick %d\n", player->entityNumber ) );
718 void Cmd_GetViewpos_f( const idCmdArgs &args ) {
723 player = gameLocal.GetLocalPlayer();
728 const renderView_t *view = player->GetRenderView();
730 gameLocal.Printf( "(%s) %.1f\n", view->vieworg.ToString(), view->viewaxis[0].ToYaw() );
732 player->GetViewPos( origin, axis );
733 gameLocal.Printf( "(%s) %.1f\n", origin.ToString(), axis[0].ToYaw() );
742 void Cmd_SetViewpos_f( const idCmdArgs &args ) {
748 player = gameLocal.GetLocalPlayer();
749 if ( !player || !gameLocal.CheatsOk() ) {
753 if ( ( args.Argc() != 4 ) && ( args.Argc() != 5 ) ) {
754 gameLocal.Printf( "usage: setviewpos <x> <y> <z> <yaw>\n" );
759 if ( args.Argc() == 5 ) {
760 angles.yaw = atof( args.Argv( 4 ) );
763 for ( i = 0 ; i < 3 ; i++ ) {
764 origin[i] = atof( args.Argv( i + 1 ) );
766 origin.z -= pm_normalviewheight.GetFloat() - 0.25f;
768 player->Teleport( origin, angles, NULL );
776 void Cmd_Teleport_f( const idCmdArgs &args ) {
782 player = gameLocal.GetLocalPlayer();
783 if ( !player || !gameLocal.CheatsOk() ) {
787 if ( args.Argc() != 2 ) {
788 gameLocal.Printf( "usage: teleport <name of entity to teleport to>\n" );
792 ent = gameLocal.FindEntity( args.Argv( 1 ) );
794 gameLocal.Printf( "entity not found\n" );
799 angles.yaw = ent->GetPhysics()->GetAxis()[ 0 ].ToYaw();
800 origin = ent->GetPhysics()->GetOrigin();
802 player->Teleport( origin, angles, ent );
810 void Cmd_Trigger_f( const idCmdArgs &args ) {
816 player = gameLocal.GetLocalPlayer();
817 if ( !player || !gameLocal.CheatsOk() ) {
821 if ( args.Argc() != 2 ) {
822 gameLocal.Printf( "usage: trigger <name of entity to trigger>\n" );
826 ent = gameLocal.FindEntity( args.Argv( 1 ) );
828 gameLocal.Printf( "entity not found\n" );
832 ent->Signal( SIG_TRIGGER );
833 ent->ProcessEvent( &EV_Activate, player );
842 void Cmd_Spawn_f( const idCmdArgs &args ) {
843 const char *key, *value;
850 player = gameLocal.GetLocalPlayer();
851 if ( !player || !gameLocal.CheatsOk( false ) ) {
855 if ( args.Argc() & 1 ) { // must always have an even number of arguments
856 gameLocal.Printf( "usage: spawn classname [key/value pairs]\n" );
860 yaw = player->viewAngles.yaw;
862 value = args.Argv( 1 );
863 dict.Set( "classname", value );
864 dict.Set( "angle", va( "%f", yaw + 180 ) );
866 org = player->GetPhysics()->GetOrigin() + idAngles( 0, yaw, 0 ).ToForward() * 80 + idVec3( 0, 0, 1 );
867 dict.Set( "origin", org.ToString() );
869 for( i = 2; i < args.Argc() - 1; i += 2 ) {
871 key = args.Argv( i );
872 value = args.Argv( i + 1 );
874 dict.Set( key, value );
877 gameLocal.SpawnEntityDef( dict );
884 Damages the specified entity
887 void Cmd_Damage_f( const idCmdArgs &args ) {
888 if ( !gameLocal.GetLocalPlayer() || !gameLocal.CheatsOk( false ) ) {
891 if ( args.Argc() != 3 ) {
892 gameLocal.Printf( "usage: damage <name of entity to damage> <damage>\n" );
896 idEntity *ent = gameLocal.FindEntity( args.Argv( 1 ) );
898 gameLocal.Printf( "entity not found\n" );
902 ent->Damage( gameLocal.world, gameLocal.world, idVec3( 0, 0, 1 ), "damage_moverCrush", atoi( args.Argv( 2 ) ), INVALID_JOINT );
910 Removes the specified entity
913 void Cmd_Remove_f( const idCmdArgs &args ) {
914 if ( !gameLocal.GetLocalPlayer() || !gameLocal.CheatsOk( false ) ) {
917 if ( args.Argc() != 2 ) {
918 gameLocal.Printf( "usage: remove <name of entity to remove>\n" );
922 idEntity *ent = gameLocal.FindEntity( args.Argv( 1 ) );
924 gameLocal.Printf( "entity not found\n" );
936 void Cmd_TestLight_f( const idCmdArgs &args ) {
939 const char *key, *value, *name;
943 player = gameLocal.GetLocalPlayer();
944 if ( !player || !gameLocal.CheatsOk( false ) ) {
948 renderView_t *rv = player->GetRenderView();
950 float fov = tan( idMath::M_DEG2RAD * rv->fov_x / 2 );
953 dict.SetMatrix( "rotation", mat3_default );
954 dict.SetVector( "origin", rv->vieworg );
955 dict.SetVector( "light_target", rv->viewaxis[0] );
956 dict.SetVector( "light_right", rv->viewaxis[1] * -fov );
957 dict.SetVector( "light_up", rv->viewaxis[2] * fov );
958 dict.SetVector( "light_start", rv->viewaxis[0] * 16 );
959 dict.SetVector( "light_end", rv->viewaxis[0] * 1000 );
961 if ( args.Argc() >= 2 ) {
962 value = args.Argv( 1 );
963 filename = args.Argv(1);
964 filename.DefaultFileExtension( ".tga" );
965 dict.Set( "texture", filename );
968 dict.Set( "classname", "light" );
969 for( i = 2; i < args.Argc() - 1; i += 2 ) {
971 key = args.Argv( i );
972 value = args.Argv( i + 1 );
974 dict.Set( key, value );
977 for ( i = 0; i < MAX_GENTITIES; i++ ) {
978 name = va( "spawned_light_%d", i ); // not just light_, or it might pick up a prelight shadow
979 if ( !gameLocal.FindEntity( name ) ) {
983 dict.Set( "name", name );
985 gameLocal.SpawnEntityDef( dict );
987 gameLocal.Printf( "Created new light\n");
995 void Cmd_TestPointLight_f( const idCmdArgs &args ) {
996 const char *key, *value, *name;
1001 player = gameLocal.GetLocalPlayer();
1002 if ( !player || !gameLocal.CheatsOk( false ) ) {
1006 dict.SetVector("origin", player->GetRenderView()->vieworg);
1008 if ( args.Argc() >= 2 ) {
1009 value = args.Argv( 1 );
1010 dict.Set("light", value);
1012 dict.Set("light", "300");
1015 dict.Set( "classname", "light" );
1016 for( i = 2; i < args.Argc() - 1; i += 2 ) {
1018 key = args.Argv( i );
1019 value = args.Argv( i + 1 );
1021 dict.Set( key, value );
1024 for ( i = 0; i < MAX_GENTITIES; i++ ) {
1025 name = va( "light_%d", i );
1026 if ( !gameLocal.FindEntity( name ) ) {
1030 dict.Set( "name", name );
1032 gameLocal.SpawnEntityDef( dict );
1034 gameLocal.Printf( "Created new point light\n");
1042 void Cmd_PopLight_f( const idCmdArgs &args ) {
1044 idMapEntity *mapEnt;
1045 idMapFile *mapFile = gameLocal.GetLevelMap();
1049 if ( !gameLocal.CheatsOk() ) {
1053 bool removeFromMap = ( args.Argc() > 1 );
1057 for( ent = gameLocal.spawnedEntities.Next(); ent != NULL; ent = ent->spawnNode.Next() ) {
1058 if ( !ent->IsType( idLight::Type ) ) {
1062 if ( gameLocal.spawnIds[ ent->entityNumber ] > last ) {
1063 last = gameLocal.spawnIds[ ent->entityNumber ];
1064 lastLight = static_cast<idLight*>( ent );
1069 // find map file entity
1070 mapEnt = mapFile->FindEntity( lastLight->name );
1072 if ( removeFromMap && mapEnt ) {
1073 mapFile->RemoveEntity( mapEnt );
1075 gameLocal.Printf( "Removing light %i\n", lastLight->GetLightDefHandle() );
1078 gameLocal.Printf( "No lights to clear.\n" );
1084 ====================
1086 ====================
1088 void Cmd_ClearLights_f( const idCmdArgs &args ) {
1092 idMapEntity *mapEnt;
1093 idMapFile *mapFile = gameLocal.GetLevelMap();
1095 bool removeFromMap = ( args.Argc() > 1 );
1097 gameLocal.Printf( "Clearing all lights.\n" );
1098 for( ent = gameLocal.spawnedEntities.Next(); ent != NULL; ent = next ) {
1099 next = ent->spawnNode.Next();
1100 if ( !ent->IsType( idLight::Type ) ) {
1104 light = static_cast<idLight*>( ent );
1105 mapEnt = mapFile->FindEntity( light->name );
1107 if ( removeFromMap && mapEnt ) {
1108 mapFile->RemoveEntity( mapEnt );
1120 void Cmd_TestFx_f( const idCmdArgs &args ) {
1126 player = gameLocal.GetLocalPlayer();
1127 if ( !player || !gameLocal.CheatsOk() ) {
1131 // delete the testModel if active
1132 if ( gameLocal.testFx ) {
1133 delete gameLocal.testFx;
1134 gameLocal.testFx = NULL;
1137 if ( args.Argc() < 2 ) {
1141 name = args.Argv( 1 );
1143 offset = player->GetPhysics()->GetOrigin() + player->viewAngles.ToForward() * 100.0f;
1145 dict.Set( "origin", offset.ToString() );
1146 dict.Set( "test", "1");
1147 dict.Set( "fx", name );
1148 gameLocal.testFx = ( idEntityFx * )gameLocal.SpawnEntityType( idEntityFx::Type, &dict );
1151 #define MAX_DEBUGLINES 128
1161 gameDebugLine_t debugLines[MAX_DEBUGLINES];
1168 static void Cmd_AddDebugLine_f( const idCmdArgs &args ) {
1172 if ( !gameLocal.CheatsOk() ) {
1176 if ( args.Argc () < 7 ) {
1177 gameLocal.Printf( "usage: addline <x y z> <x y z> <color>\n" );
1180 for ( i = 0; i < MAX_DEBUGLINES; i++ ) {
1181 if ( !debugLines[i].used ) {
1185 if ( i >= MAX_DEBUGLINES ) {
1186 gameLocal.Printf( "no free debug lines\n" );
1189 value = args.Argv( 0 );
1190 if ( !idStr::Icmp( value, "addarrow" ) ) {
1191 debugLines[i].arrow = true;
1193 debugLines[i].arrow = false;
1195 debugLines[i].used = true;
1196 debugLines[i].blink = false;
1198 debugLines[i].start.x = Cmd_GetFloatArg( args, argNum );
1199 debugLines[i].start.y = Cmd_GetFloatArg( args, argNum );
1200 debugLines[i].start.z = Cmd_GetFloatArg( args, argNum );
1201 debugLines[i].end.x = Cmd_GetFloatArg( args, argNum );
1202 debugLines[i].end.y = Cmd_GetFloatArg( args, argNum );
1203 debugLines[i].end.z = Cmd_GetFloatArg( args, argNum );
1204 debugLines[i].color = Cmd_GetFloatArg( args, argNum );
1209 Cmd_RemoveDebugLine_f
1212 static void Cmd_RemoveDebugLine_f( const idCmdArgs &args ) {
1216 if ( !gameLocal.CheatsOk() ) {
1220 if ( args.Argc () < 2 ) {
1221 gameLocal.Printf( "usage: removeline <num>\n" );
1224 value = args.Argv( 1 );
1226 for ( i = 0; i < MAX_DEBUGLINES; i++ ) {
1227 if ( debugLines[i].used ) {
1233 if ( i >= MAX_DEBUGLINES ) {
1234 gameLocal.Printf( "line not found\n" );
1237 debugLines[i].used = false;
1242 Cmd_BlinkDebugLine_f
1245 static void Cmd_BlinkDebugLine_f( const idCmdArgs &args ) {
1249 if ( !gameLocal.CheatsOk() ) {
1253 if ( args.Argc () < 2 ) {
1254 gameLocal.Printf( "usage: blinkline <num>\n" );
1257 value = args.Argv( 1 );
1258 num = atoi( value );
1259 for ( i = 0; i < MAX_DEBUGLINES; i++ ) {
1260 if ( debugLines[i].used ) {
1266 if ( i >= MAX_DEBUGLINES ) {
1267 gameLocal.Printf( "line not found\n" );
1270 debugLines[i].blink = !debugLines[i].blink;
1278 static void PrintFloat( float f ) {
1281 for ( i = sprintf( buf, "%3.2f", f ); i < 7; i++ ) {
1285 gameLocal.Printf( buf );
1290 Cmd_ListDebugLines_f
1293 static void Cmd_ListDebugLines_f( const idCmdArgs &args ) {
1296 if ( !gameLocal.CheatsOk() ) {
1301 gameLocal.Printf( "line num: x1 y1 z1 x2 y2 z2 c b a\n" );
1302 for ( i = 0; i < MAX_DEBUGLINES; i++ ) {
1303 if ( debugLines[i].used ) {
1304 gameLocal.Printf( "line %3d: ", num );
1305 PrintFloat( debugLines[i].start.x );
1306 PrintFloat( debugLines[i].start.y );
1307 PrintFloat( debugLines[i].start.z );
1308 PrintFloat( debugLines[i].end.x );
1309 PrintFloat( debugLines[i].end.y );
1310 PrintFloat( debugLines[i].end.z );
1311 gameLocal.Printf( "%d %d %d\n", debugLines[i].color, debugLines[i].blink, debugLines[i].arrow );
1316 gameLocal.Printf( "no debug lines\n" );
1325 void D_DrawDebugLines( void ) {
1327 idVec3 forward, right, up, p1, p2;
1331 for ( i = 0; i < MAX_DEBUGLINES; i++ ) {
1332 if ( debugLines[i].used ) {
1333 if ( !debugLines[i].blink || (gameLocal.time & (1<<9)) ) {
1334 color = idVec4( debugLines[i].color&1, (debugLines[i].color>>1)&1, (debugLines[i].color>>2)&1, 1 );
1335 gameRenderWorld->DebugLine( color, debugLines[i].start, debugLines[i].end );
1337 if ( debugLines[i].arrow ) {
1338 // draw a nice arrow
1339 forward = debugLines[i].end - debugLines[i].start;
1340 l = forward.Normalize() * 0.2f;
1341 forward.NormalVectors( right, up);
1346 p1 = debugLines[i].end - l * forward + (l * 0.4f) * right;
1347 p2 = debugLines[i].end - l * forward - (l * 0.4f) * right;
1348 gameRenderWorld->DebugLine( color, debugLines[i].end, p1 );
1349 gameRenderWorld->DebugLine( color, debugLines[i].end, p2 );
1350 gameRenderWorld->DebugLine( color, p1, p2 );
1359 Cmd_ListCollisionModels_f
1362 static void Cmd_ListCollisionModels_f( const idCmdArgs &args ) {
1363 if ( !gameLocal.CheatsOk() ) {
1367 collisionModelManager->ListModels();
1372 Cmd_CollisionModelInfo_f
1375 static void Cmd_CollisionModelInfo_f( const idCmdArgs &args ) {
1378 if ( !gameLocal.CheatsOk() ) {
1382 if ( args.Argc () < 2 ) {
1383 gameLocal.Printf( "usage: collisionModelInfo <modelNum>\n"
1384 "use 'all' instead of the model number for accumulated info\n" );
1388 value = args.Argv( 1 );
1389 if ( !idStr::Icmp( value, "all" ) ) {
1390 collisionModelManager->ModelInfo( -1 );
1392 collisionModelManager->ModelInfo( atoi(value) );
1401 static void Cmd_ExportModels_f( const idCmdArgs &args ) {
1402 idModelExport exporter;
1405 // don't allow exporting models when cheats are disabled,
1406 // but if we're not in the game, it's ok
1407 if ( gameLocal.GetLocalPlayer() && !gameLocal.CheatsOk( false ) ) {
1411 if ( args.Argc() < 2 ) {
1412 exporter.ExportModels( "def", ".def" );
1414 name = args.Argv( 1 );
1415 name = "def/" + name;
1416 name.DefaultFileExtension( ".def" );
1417 exporter.ExportDefFile( name );
1423 Cmd_ReexportModels_f
1426 static void Cmd_ReexportModels_f( const idCmdArgs &args ) {
1427 idModelExport exporter;
1430 // don't allow exporting models when cheats are disabled,
1431 // but if we're not in the game, it's ok
1432 if ( gameLocal.GetLocalPlayer() && !gameLocal.CheatsOk( false ) ) {
1436 idAnimManager::forceExport = true;
1437 if ( args.Argc() < 2 ) {
1438 exporter.ExportModels( "def", ".def" );
1440 name = args.Argv( 1 );
1441 name = "def/" + name;
1442 name.DefaultFileExtension( ".def" );
1443 exporter.ExportDefFile( name );
1445 idAnimManager::forceExport = false;
1453 static void Cmd_ReloadAnims_f( const idCmdArgs &args ) {
1454 // don't allow reloading anims when cheats are disabled,
1455 // but if we're not in the game, it's ok
1456 if ( gameLocal.GetLocalPlayer() && !gameLocal.CheatsOk( false ) ) {
1460 animationLib.ReloadAnims();
1468 static void Cmd_ListAnims_f( const idCmdArgs &args ) {
1473 idAnimator * animator;
1474 const char * classname;
1475 const idDict * dict;
1478 if ( args.Argc() > 1 ) {
1479 idAnimator animator;
1481 classname = args.Argv( 1 );
1483 dict = gameLocal.FindEntityDefDict( classname, false );
1485 gameLocal.Printf( "Entitydef '%s' not found\n", classname );
1488 animator.SetModel( dict->GetString( "model" ) );
1490 gameLocal.Printf( "----------------\n" );
1491 num = animator.NumAnims();
1492 for( i = 0; i < num; i++ ) {
1493 gameLocal.Printf( "%s\n", animator.AnimFullName( i ) );
1495 gameLocal.Printf( "%d anims\n", num );
1497 animationLib.ListAnims();
1501 for( ent = gameLocal.spawnedEntities.Next(); ent != NULL; ent = ent->spawnNode.Next() ) {
1502 animator = ent->GetAnimator();
1504 alloced = animator->Allocated();
1510 gameLocal.Printf( "%d memory used in %d entity animators\n", size, num );
1519 static void Cmd_AASStats_f( const idCmdArgs &args ) {
1522 if ( !gameLocal.CheatsOk() ) {
1526 aasNum = aas_test.GetInteger();
1527 idAAS *aas = gameLocal.GetAAS( aasNum );
1529 gameLocal.Printf( "No aas #%d loaded\n", aasNum );
1540 static void Cmd_TestDamage_f( const idCmdArgs &args ) {
1542 const char *damageDefName;
1544 player = gameLocal.GetLocalPlayer();
1545 if ( !player || !gameLocal.CheatsOk() ) {
1549 if ( args.Argc() < 2 || args.Argc() > 3 ) {
1550 gameLocal.Printf( "usage: testDamage <damageDefName> [angle]\n" );
1554 damageDefName = args.Argv( 1 );
1557 if ( args.Argc() == 3 ) {
1558 float angle = atof( args.Argv( 2 ) );
1560 idMath::SinCos( DEG2RAD( angle ), dir[1], dir[0] );
1566 // give the player full health before and after
1567 // running the damage
1568 player->health = player->inventory.maxHealth;
1569 player->Damage( NULL, NULL, dir, damageDefName, 1.0f, INVALID_JOINT );
1570 player->health = player->inventory.maxHealth;
1578 static void Cmd_TestBoneFx_f( const idCmdArgs &args ) {
1580 const char *bone, *fx;
1582 player = gameLocal.GetLocalPlayer();
1583 if ( !player || !gameLocal.CheatsOk() ) {
1587 if ( args.Argc() < 3 || args.Argc() > 4 ) {
1588 gameLocal.Printf( "usage: testBoneFx <fxName> <boneName>\n" );
1592 fx = args.Argv( 1 );
1593 bone = args.Argv( 2 );
1595 player->StartFxOnBone( fx, bone );
1603 static void Cmd_TestDeath_f( const idCmdArgs &args ) {
1606 player = gameLocal.GetLocalPlayer();
1607 if ( !player || !gameLocal.CheatsOk() ) {
1612 idMath::SinCos( DEG2RAD( 45.0f ), dir[1], dir[0] );
1615 g_testDeath.SetBool( 1 );
1616 player->Damage( NULL, NULL, dir, "damage_triggerhurt_1000", 1.0f, INVALID_JOINT );
1617 if ( args.Argc() >= 2) {
1618 player->SpawnGibs( dir, "damage_triggerhurt_1000" );
1628 static void Cmd_WeaponSplat_f( const idCmdArgs &args ) {
1631 player = gameLocal.GetLocalPlayer();
1632 if ( !player || !gameLocal.CheatsOk() ) {
1636 player->weapon.GetEntity()->BloodSplat( 2.0f );
1644 static void Cmd_SaveSelected_f( const idCmdArgs &args ) {
1648 idMapEntity *mapEnt;
1649 idMapFile *mapFile = gameLocal.GetLevelMap();
1654 player = gameLocal.GetLocalPlayer();
1655 if ( !player || !gameLocal.CheatsOk() ) {
1659 s = player->dragEntity.GetSelected();
1661 gameLocal.Printf( "no entity selected, set g_dragShowSelection 1 to show the current selection\n" );
1665 if ( args.Argc() > 1 ) {
1666 mapName = args.Argv( 1 );
1667 mapName = "maps/" + mapName;
1670 mapName = mapFile->GetName();
1673 // find map file entity
1674 mapEnt = mapFile->FindEntity( s->name );
1675 // create new map file entity if there isn't one for this articulated figure
1677 mapEnt = new idMapEntity();
1678 mapFile->AddEntity( mapEnt );
1679 for ( i = 0; i < 9999; i++ ) {
1680 name = va( "%s_%d", s->GetEntityDefName(), i );
1681 if ( !gameLocal.FindEntity( name ) ) {
1686 mapEnt->epairs.Set( "classname", s->GetEntityDefName() );
1687 mapEnt->epairs.Set( "name", s->name );
1690 if ( s->IsType( idMoveable::Type ) ) {
1691 // save the moveable state
1692 mapEnt->epairs.Set( "origin", s->GetPhysics()->GetOrigin().ToString( 8 ) );
1693 mapEnt->epairs.Set( "rotation", s->GetPhysics()->GetAxis().ToString( 8 ) );
1695 else if ( s->IsType( idAFEntity_Generic::Type ) || s->IsType( idAFEntity_WithAttachedHead::Type ) ) {
1696 // save the articulated figure state
1698 static_cast<idAFEntity_Base *>(s)->SaveState( dict );
1699 mapEnt->epairs.Copy( dict );
1702 // write out the map file
1703 mapFile->Write( mapName, ".map" );
1708 Cmd_DeleteSelected_f
1711 static void Cmd_DeleteSelected_f( const idCmdArgs &args ) {
1714 player = gameLocal.GetLocalPlayer();
1715 if ( !player || !gameLocal.CheatsOk() ) {
1720 player->dragEntity.DeleteSelected();
1729 static void Cmd_SaveMoveables_f( const idCmdArgs &args ) {
1732 idMapEntity *mapEnt;
1733 idMapFile *mapFile = gameLocal.GetLevelMap();
1737 if ( !gameLocal.CheatsOk() ) {
1741 for( e = 0; e < MAX_GENTITIES; e++ ) {
1742 m = static_cast<idMoveable *>(gameLocal.entities[ e ]);
1744 if ( !m || !m->IsType( idMoveable::Type ) ) {
1748 if ( m->IsBound() ) {
1752 if ( !m->IsAtRest() ) {
1757 if ( e < MAX_GENTITIES ) {
1758 gameLocal.Warning( "map not saved because the moveable entity %s is not at rest", gameLocal.entities[ e ]->name.c_str() );
1762 if ( args.Argc() > 1 ) {
1763 mapName = args.Argv( 1 );
1764 mapName = "maps/" + mapName;
1767 mapName = mapFile->GetName();
1770 for( e = 0; e < MAX_GENTITIES; e++ ) {
1771 m = static_cast<idMoveable *>(gameLocal.entities[ e ]);
1773 if ( !m || !m->IsType( idMoveable::Type ) ) {
1777 if ( m->IsBound() ) {
1781 // find map file entity
1782 mapEnt = mapFile->FindEntity( m->name );
1783 // create new map file entity if there isn't one for this articulated figure
1785 mapEnt = new idMapEntity();
1786 mapFile->AddEntity( mapEnt );
1787 for ( i = 0; i < 9999; i++ ) {
1788 name = va( "%s_%d", m->GetEntityDefName(), i );
1789 if ( !gameLocal.FindEntity( name ) ) {
1794 mapEnt->epairs.Set( "classname", m->GetEntityDefName() );
1795 mapEnt->epairs.Set( "name", m->name );
1797 // save the moveable state
1798 mapEnt->epairs.Set( "origin", m->GetPhysics()->GetOrigin().ToString( 8 ) );
1799 mapEnt->epairs.Set( "rotation", m->GetPhysics()->GetAxis().ToString( 8 ) );
1802 // write out the map file
1803 mapFile->Write( mapName, ".map" );
1811 static void Cmd_SaveRagdolls_f( const idCmdArgs &args ) {
1813 idAFEntity_Base *af;
1814 idMapEntity *mapEnt;
1815 idMapFile *mapFile = gameLocal.GetLevelMap();
1820 if ( !gameLocal.CheatsOk() ) {
1824 if ( args.Argc() > 1 ) {
1825 mapName = args.Argv( 1 );
1826 mapName = "maps/" + mapName;
1829 mapName = mapFile->GetName();
1832 for( e = 0; e < MAX_GENTITIES; e++ ) {
1833 af = static_cast<idAFEntity_Base *>(gameLocal.entities[ e ]);
1839 if ( !af->IsType( idAFEntity_WithAttachedHead::Type ) && !af->IsType( idAFEntity_Generic::Type ) ) {
1843 if ( af->IsBound() ) {
1847 if ( !af->IsAtRest() ) {
1848 gameLocal.Warning( "the articulated figure for entity %s is not at rest", gameLocal.entities[ e ]->name.c_str() );
1852 af->SaveState( dict );
1854 // find map file entity
1855 mapEnt = mapFile->FindEntity( af->name );
1856 // create new map file entity if there isn't one for this articulated figure
1858 mapEnt = new idMapEntity();
1859 mapFile->AddEntity( mapEnt );
1860 for ( i = 0; i < 9999; i++ ) {
1861 name = va( "%s_%d", af->GetEntityDefName(), i );
1862 if ( !gameLocal.FindEntity( name ) ) {
1867 mapEnt->epairs.Set( "classname", af->GetEntityDefName() );
1868 mapEnt->epairs.Set( "name", af->name );
1870 // save the articulated figure state
1871 mapEnt->epairs.Copy( dict );
1874 // write out the map file
1875 mapFile->Write( mapName, ".map" );
1883 static void Cmd_BindRagdoll_f( const idCmdArgs &args ) {
1886 player = gameLocal.GetLocalPlayer();
1887 if ( !player || !gameLocal.CheatsOk() ) {
1892 player->dragEntity.BindSelected();
1901 static void Cmd_UnbindRagdoll_f( const idCmdArgs &args ) {
1904 player = gameLocal.GetLocalPlayer();
1905 if ( !player || !gameLocal.CheatsOk() ) {
1910 player->dragEntity.UnbindSelected();
1919 static void Cmd_GameError_f( const idCmdArgs &args ) {
1920 gameLocal.Error( "game error" );
1928 static void Cmd_SaveLights_f( const idCmdArgs &args ) {
1931 idMapEntity *mapEnt;
1932 idMapFile *mapFile = gameLocal.GetLevelMap();
1937 if ( !gameLocal.CheatsOk() ) {
1941 if ( args.Argc() > 1 ) {
1942 mapName = args.Argv( 1 );
1943 mapName = "maps/" + mapName;
1946 mapName = mapFile->GetName();
1949 for( e = 0; e < MAX_GENTITIES; e++ ) {
1950 light = static_cast<idLight*>(gameLocal.entities[ e ]);
1952 if ( !light || !light->IsType( idLight::Type ) ) {
1957 light->SaveState( &dict );
1959 // find map file entity
1960 mapEnt = mapFile->FindEntity( light->name );
1961 // create new map file entity if there isn't one for this light
1963 mapEnt = new idMapEntity();
1964 mapFile->AddEntity( mapEnt );
1965 for ( i = 0; i < 9999; i++ ) {
1966 name = va( "%s_%d", light->GetEntityDefName(), i );
1967 if ( !gameLocal.FindEntity( name ) ) {
1972 mapEnt->epairs.Set( "classname", light->GetEntityDefName() );
1973 mapEnt->epairs.Set( "name", light->name );
1975 // save the light state
1976 mapEnt->epairs.Copy( dict );
1979 // write out the map file
1980 mapFile->Write( mapName, ".map" );
1989 static void Cmd_SaveParticles_f( const idCmdArgs &args ) {
1992 idMapEntity *mapEnt;
1993 idMapFile *mapFile = gameLocal.GetLevelMap();
1995 idStr mapName, strModel;
1997 if ( !gameLocal.CheatsOk() ) {
2001 if ( args.Argc() > 1 ) {
2002 mapName = args.Argv( 1 );
2003 mapName = "maps/" + mapName;
2006 mapName = mapFile->GetName();
2009 for( e = 0; e < MAX_GENTITIES; e++ ) {
2011 ent = static_cast<idStaticEntity*> ( gameLocal.entities[ e ] );
2017 strModel = ent->spawnArgs.GetString( "model" );
2018 if ( strModel.Length() && strModel.Find( ".prt") > 0 ) {
2020 dict.Set( "model", ent->spawnArgs.GetString( "model" ) );
2021 dict.SetVector( "origin", ent->GetPhysics()->GetOrigin() );
2023 // find map file entity
2024 mapEnt = mapFile->FindEntity( ent->name );
2025 // create new map file entity if there isn't one for this entity
2029 // save the particle state
2030 mapEnt->epairs.Copy( dict );
2034 // write out the map file
2035 mapFile->Write( mapName, ".map" );
2044 static void Cmd_DisasmScript_f( const idCmdArgs &args ) {
2045 gameLocal.program.Disassemble();
2053 static void Cmd_TestSave_f( const idCmdArgs &args ) {
2056 f = fileSystem->OpenFileWrite( "test.sav" );
2057 gameLocal.SaveGame( f );
2058 fileSystem->CloseFile( f );
2063 Cmd_RecordViewNotes_f
2066 static void Cmd_RecordViewNotes_f( const idCmdArgs &args ) {
2071 if ( args.Argc() <= 3 ) {
2075 player = gameLocal.GetLocalPlayer();
2080 player->GetViewPos( origin, axis );
2082 // Argv(1) = filename for map (viewnotes/mapname/person)
2083 // Argv(2) = note number (person0001)
2084 // Argv(3) = comments
2086 idStr str = args.Argv(1);
2087 str.SetFileExtension( ".txt" );
2090 idFile *file = fileSystem->OpenFileAppend( str, false, "fs_cdpath" );
2092 idFile *file = fileSystem->OpenFileAppend( str );
2096 file->WriteFloatString( "\"view\"\t( %s )\t( %s )\r\n", origin.ToString(), axis.ToString() );
2097 file->WriteFloatString( "\"comments\"\t\"%s: %s\"\r\n\r\n", args.Argv(2), args.Argv(3) );
2098 fileSystem->CloseFile( file );
2101 idStr viewComments = args.Argv(1);
2102 viewComments.StripLeading("viewnotes/");
2103 viewComments += " -- Loc: ";
2104 viewComments += origin.ToString();
2105 viewComments += "\n";
2106 viewComments += args.Argv(3);
2107 player->hud->SetStateString( "viewcomments", viewComments );
2108 player->hud->HandleNamedEvent( "showViewComments" );
2113 Cmd_CloseViewNotes_f
2116 static void Cmd_CloseViewNotes_f( const idCmdArgs &args ) {
2117 idPlayer *player = gameLocal.GetLocalPlayer();
2123 player->hud->SetStateString( "viewcomments", "" );
2124 player->hud->HandleNamedEvent( "hideViewComments" );
2132 static void Cmd_ShowViewNotes_f( const idCmdArgs &args ) {
2133 static idLexer parser( LEXFL_ALLOWPATHNAMES | LEXFL_NOSTRINGESCAPECHARS | LEXFL_NOSTRINGCONCAT | LEXFL_NOFATALERRORS );
2139 player = gameLocal.GetLocalPlayer();
2145 if ( !parser.IsLoaded() ) {
2146 idStr str = "viewnotes/";
2147 str += gameLocal.GetMapName();
2148 str.StripFileExtension();
2150 if ( args.Argc() > 1 ) {
2151 str += args.Argv( 1 );
2155 str.SetFileExtension( ".txt" );
2156 if ( !parser.LoadFile( str ) ) {
2157 gameLocal.Printf( "No view notes for %s\n", gameLocal.GetMapName() );
2162 if ( parser.ExpectTokenString( "view" ) && parser.Parse1DMatrix( 3, origin.ToFloatPtr() ) &&
2163 parser.Parse1DMatrix( 9, axis.ToFloatPtr() ) && parser.ExpectTokenString( "comments" ) && parser.ReadToken( &token ) ) {
2164 player->hud->SetStateString( "viewcomments", token );
2165 player->hud->HandleNamedEvent( "showViewComments" );
2166 player->Teleport( origin, axis.ToAngles(), NULL );
2168 parser.FreeSource();
2169 player->hud->HandleNamedEvent( "hideViewComments" );
2178 helper function for Cmd_NextGUI_f. Checks the passed entity to determine if it
2179 has any valid gui surfaces.
2182 bool FindEntityGUIs( idEntity *ent, const modelSurface_t ** surfaces, int maxSurfs, int &guiSurfaces ) {
2183 renderEntity_t *renderEnt;
2184 idRenderModel *renderModel;
2185 const modelSurface_t *surf;
2186 const idMaterial *shader;
2189 assert( surfaces != NULL );
2190 assert( ent != NULL );
2192 memset( surfaces, 0x00, sizeof( modelSurface_t *) * maxSurfs );
2195 renderEnt = ent->GetRenderEntity();
2196 renderModel = renderEnt->hModel;
2197 if ( renderModel == NULL ) {
2201 for( i = 0; i < renderModel->NumSurfaces(); i++ ) {
2202 surf = renderModel->Surface( i );
2203 if ( surf == NULL ) {
2206 shader = surf->shader;
2207 if ( shader == NULL ) {
2210 if ( shader->GetEntityGui() > 0 ) {
2211 surfaces[ guiSurfaces++ ] = surf;
2215 return ( guiSurfaces != 0 );
2223 void Cmd_NextGUI_f( const idCmdArgs &args ) {
2230 renderEntity_t *renderEnt;
2232 srfTriangles_t *geom;
2236 const modelSurface_t *surfaces[ MAX_RENDERENTITY_GUI ];
2238 player = gameLocal.GetLocalPlayer();
2239 if ( !player || !gameLocal.CheatsOk() ) {
2243 if ( args.Argc() != 1 ) {
2244 gameLocal.Printf( "usage: nextgui\n" );
2248 // start at the last entity
2249 ent = gameLocal.lastGUIEnt.GetEntity();
2251 // see if we have any gui surfaces left to go to on the current entity.
2254 if ( ent == NULL ) {
2256 } else if ( FindEntityGUIs( ent, surfaces, MAX_RENDERENTITY_GUI, guiSurfaces ) == true ) {
2257 if ( gameLocal.lastGUI >= guiSurfaces ) {
2261 // no actual gui surfaces on this ent, so skip it
2265 if ( newEnt == true ) {
2266 // go ahead and skip to the next entity with a gui...
2267 if ( ent == NULL ) {
2268 ent = gameLocal.spawnedEntities.Next();
2270 ent = ent->spawnNode.Next();
2273 for ( ; ent != NULL; ent = ent->spawnNode.Next() ) {
2274 if ( ent->spawnArgs.GetString( "gui", NULL ) != NULL ) {
2278 if ( ent->spawnArgs.GetString( "gui2", NULL ) != NULL ) {
2282 if ( ent->spawnArgs.GetString( "gui3", NULL ) != NULL ) {
2286 // try the next entity
2287 gameLocal.lastGUIEnt = ent;
2290 gameLocal.lastGUIEnt = ent;
2291 gameLocal.lastGUI = 0;
2294 gameLocal.Printf( "No more gui entities. Starting over...\n" );
2299 if ( FindEntityGUIs( ent, surfaces, MAX_RENDERENTITY_GUI, guiSurfaces ) == false ) {
2300 gameLocal.Printf( "Entity \"%s\" has gui properties but no gui surfaces.\n", ent->name.c_str() );
2303 if ( guiSurfaces == 0 ) {
2304 gameLocal.Printf( "Entity \"%s\" has gui properties but no gui surfaces!\n", ent->name.c_str() );
2308 gameLocal.Printf( "Teleporting to gui entity \"%s\", gui #%d.\n" , ent->name.c_str (), gameLocal.lastGUI );
2310 renderEnt = ent->GetRenderEntity();
2311 surfIndex = gameLocal.lastGUI++;
2312 geom = surfaces[ surfIndex ]->geometry;
2313 if ( geom == NULL ) {
2314 gameLocal.Printf( "Entity \"%s\" has gui surface %d without geometry!\n", ent->name.c_str(), surfIndex );
2318 assert( geom->facePlanes != NULL );
2320 modelMatrix = idMat4( renderEnt->axis, renderEnt->origin );
2321 normal = geom->facePlanes[ 0 ].Normal() * renderEnt->axis;
2322 center = geom->bounds.GetCenter() * modelMatrix;
2324 origin = center + (normal * 32.0f);
2325 origin.z -= player->EyeHeight();
2327 angles = normal.ToAngles ();
2329 // make sure the player is in noclip
2330 player->noclip = true;
2331 player->Teleport( origin, angles, NULL );
2335 void Cmd_SetActorState_f( const idCmdArgs &args ) {
2337 if ( args.Argc() != 3 ) {
2338 common->Printf( "usage: setActorState <entity name> <state>\n" );
2343 ent = gameLocal.FindEntity( args.Argv( 1 ) );
2345 gameLocal.Printf( "entity not found\n" );
2350 if(!ent->IsType(idActor::Type)) {
2351 gameLocal.Printf( "entity not an actor\n" );
2355 idActor* actor = (idActor*)ent;
2356 actor->PostEventMS(&AI_SetState, 0, args.Argv(2));
2360 static void ArgCompletion_DefFile( const idCmdArgs &args, void(*callback)( const char *s ) ) {
2361 cmdSystem->ArgCompletion_FolderExtension( args, callback, "def/", true, ".def", NULL );
2367 outputs a string from the string table for the specified id
2370 void Cmd_TestId_f( const idCmdArgs &args ) {
2373 if ( args.Argc() == 1 ) {
2374 common->Printf( "usage: testid <string id>\n" );
2378 for ( i = 1; i < args.Argc(); i++ ) {
2379 id += args.Argv( i );
2381 if ( idStr::Cmpn( id, STRTABLE_ID, STRTABLE_ID_LENGTH ) != 0 ) {
2382 id = STRTABLE_ID + id;
2384 gameLocal.mpGame.AddChatLine( common->GetLanguageDict()->GetString( id ), "<nothing>", "<nothing>", "<nothing>" );
2389 idGameLocal::InitConsoleCommands
2391 Let the system know about all of our commands
2392 so it can perform tab completion
2395 void idGameLocal::InitConsoleCommands( void ) {
2396 cmdSystem->AddCommand( "listTypeInfo", ListTypeInfo_f, CMD_FL_GAME, "list type info" );
2397 cmdSystem->AddCommand( "writeGameState", WriteGameState_f, CMD_FL_GAME, "write game state" );
2398 cmdSystem->AddCommand( "testSaveGame", TestSaveGame_f, CMD_FL_GAME|CMD_FL_CHEAT, "test a save game for a level" );
2399 cmdSystem->AddCommand( "game_memory", idClass::DisplayInfo_f, CMD_FL_GAME, "displays game class info" );
2400 cmdSystem->AddCommand( "listClasses", idClass::ListClasses_f, CMD_FL_GAME, "lists game classes" );
2401 cmdSystem->AddCommand( "listThreads", idThread::ListThreads_f, CMD_FL_GAME|CMD_FL_CHEAT, "lists script threads" );
2402 cmdSystem->AddCommand( "listEntities", Cmd_EntityList_f, CMD_FL_GAME|CMD_FL_CHEAT, "lists game entities" );
2403 cmdSystem->AddCommand( "listActiveEntities", Cmd_ActiveEntityList_f, CMD_FL_GAME|CMD_FL_CHEAT, "lists active game entities" );
2404 cmdSystem->AddCommand( "listMonsters", idAI::List_f, CMD_FL_GAME|CMD_FL_CHEAT, "lists monsters" );
2405 cmdSystem->AddCommand( "listSpawnArgs", Cmd_ListSpawnArgs_f, CMD_FL_GAME|CMD_FL_CHEAT, "list the spawn args of an entity", idGameLocal::ArgCompletion_EntityName );
2406 cmdSystem->AddCommand( "say", Cmd_Say_f, CMD_FL_GAME, "text chat" );
2407 cmdSystem->AddCommand( "sayTeam", Cmd_SayTeam_f, CMD_FL_GAME, "team text chat" );
2408 cmdSystem->AddCommand( "addChatLine", Cmd_AddChatLine_f, CMD_FL_GAME, "internal use - core to game chat lines" );
2409 cmdSystem->AddCommand( "gameKick", Cmd_Kick_f, CMD_FL_GAME, "same as kick, but recognizes player names" );
2410 cmdSystem->AddCommand( "give", Cmd_Give_f, CMD_FL_GAME|CMD_FL_CHEAT, "gives one or more items" );
2411 cmdSystem->AddCommand( "centerview", Cmd_CenterView_f, CMD_FL_GAME, "centers the view" );
2412 cmdSystem->AddCommand( "god", Cmd_God_f, CMD_FL_GAME|CMD_FL_CHEAT, "enables god mode" );
2413 cmdSystem->AddCommand( "notarget", Cmd_Notarget_f, CMD_FL_GAME|CMD_FL_CHEAT, "disables the player as a target" );
2414 cmdSystem->AddCommand( "noclip", Cmd_Noclip_f, CMD_FL_GAME|CMD_FL_CHEAT, "disables collision detection for the player" );
2415 cmdSystem->AddCommand( "kill", Cmd_Kill_f, CMD_FL_GAME, "kills the player" );
2416 cmdSystem->AddCommand( "where", Cmd_GetViewpos_f, CMD_FL_GAME|CMD_FL_CHEAT, "prints the current view position" );
2417 cmdSystem->AddCommand( "getviewpos", Cmd_GetViewpos_f, CMD_FL_GAME|CMD_FL_CHEAT, "prints the current view position" );
2418 cmdSystem->AddCommand( "setviewpos", Cmd_SetViewpos_f, CMD_FL_GAME|CMD_FL_CHEAT, "sets the current view position" );
2419 cmdSystem->AddCommand( "teleport", Cmd_Teleport_f, CMD_FL_GAME|CMD_FL_CHEAT, "teleports the player to an entity location", idGameLocal::ArgCompletion_EntityName );
2420 cmdSystem->AddCommand( "trigger", Cmd_Trigger_f, CMD_FL_GAME|CMD_FL_CHEAT, "triggers an entity", idGameLocal::ArgCompletion_EntityName );
2421 cmdSystem->AddCommand( "spawn", Cmd_Spawn_f, CMD_FL_GAME|CMD_FL_CHEAT, "spawns a game entity", idCmdSystem::ArgCompletion_Decl<DECL_ENTITYDEF> );
2422 cmdSystem->AddCommand( "damage", Cmd_Damage_f, CMD_FL_GAME|CMD_FL_CHEAT, "apply damage to an entity", idGameLocal::ArgCompletion_EntityName );
2423 cmdSystem->AddCommand( "remove", Cmd_Remove_f, CMD_FL_GAME|CMD_FL_CHEAT, "removes an entity", idGameLocal::ArgCompletion_EntityName );
2424 cmdSystem->AddCommand( "killMonsters", Cmd_KillMonsters_f, CMD_FL_GAME|CMD_FL_CHEAT, "removes all monsters" );
2425 cmdSystem->AddCommand( "killMoveables", Cmd_KillMovables_f, CMD_FL_GAME|CMD_FL_CHEAT, "removes all moveables" );
2426 cmdSystem->AddCommand( "killRagdolls", Cmd_KillRagdolls_f, CMD_FL_GAME|CMD_FL_CHEAT, "removes all ragdolls" );
2427 cmdSystem->AddCommand( "addline", Cmd_AddDebugLine_f, CMD_FL_GAME|CMD_FL_CHEAT, "adds a debug line" );
2428 cmdSystem->AddCommand( "addarrow", Cmd_AddDebugLine_f, CMD_FL_GAME|CMD_FL_CHEAT, "adds a debug arrow" );
2429 cmdSystem->AddCommand( "removeline", Cmd_RemoveDebugLine_f, CMD_FL_GAME|CMD_FL_CHEAT, "removes a debug line" );
2430 cmdSystem->AddCommand( "blinkline", Cmd_BlinkDebugLine_f, CMD_FL_GAME|CMD_FL_CHEAT, "blinks a debug line" );
2431 cmdSystem->AddCommand( "listLines", Cmd_ListDebugLines_f, CMD_FL_GAME|CMD_FL_CHEAT, "lists all debug lines" );
2432 cmdSystem->AddCommand( "playerModel", Cmd_PlayerModel_f, CMD_FL_GAME|CMD_FL_CHEAT, "sets the given model on the player", idCmdSystem::ArgCompletion_Decl<DECL_MODELDEF> );
2433 cmdSystem->AddCommand( "testFx", Cmd_TestFx_f, CMD_FL_GAME|CMD_FL_CHEAT, "tests an FX system", idCmdSystem::ArgCompletion_Decl<DECL_FX> );
2434 cmdSystem->AddCommand( "testBoneFx", Cmd_TestBoneFx_f, CMD_FL_GAME|CMD_FL_CHEAT, "tests an FX system bound to a joint", idCmdSystem::ArgCompletion_Decl<DECL_FX> );
2435 cmdSystem->AddCommand( "testLight", Cmd_TestLight_f, CMD_FL_GAME|CMD_FL_CHEAT, "tests a light" );
2436 cmdSystem->AddCommand( "testPointLight", Cmd_TestPointLight_f, CMD_FL_GAME|CMD_FL_CHEAT, "tests a point light" );
2437 cmdSystem->AddCommand( "popLight", Cmd_PopLight_f, CMD_FL_GAME|CMD_FL_CHEAT, "removes the last created light" );
2438 cmdSystem->AddCommand( "testDeath", Cmd_TestDeath_f, CMD_FL_GAME|CMD_FL_CHEAT, "tests death" );
2439 cmdSystem->AddCommand( "testSave", Cmd_TestSave_f, CMD_FL_GAME|CMD_FL_CHEAT, "writes out a test savegame" );
2440 cmdSystem->AddCommand( "testModel", idTestModel::TestModel_f, CMD_FL_GAME|CMD_FL_CHEAT, "tests a model", idTestModel::ArgCompletion_TestModel );
2441 cmdSystem->AddCommand( "testSkin", idTestModel::TestSkin_f, CMD_FL_GAME|CMD_FL_CHEAT, "tests a skin on an existing testModel", idCmdSystem::ArgCompletion_Decl<DECL_SKIN> );
2442 cmdSystem->AddCommand( "testShaderParm", idTestModel::TestShaderParm_f, CMD_FL_GAME|CMD_FL_CHEAT, "sets a shaderParm on an existing testModel" );
2443 cmdSystem->AddCommand( "keepTestModel", idTestModel::KeepTestModel_f, CMD_FL_GAME|CMD_FL_CHEAT, "keeps the last test model in the game" );
2444 cmdSystem->AddCommand( "testAnim", idTestModel::TestAnim_f, CMD_FL_GAME|CMD_FL_CHEAT, "tests an animation", idTestModel::ArgCompletion_TestAnim );
2445 cmdSystem->AddCommand( "testParticleStopTime", idTestModel::TestParticleStopTime_f,CMD_FL_GAME|CMD_FL_CHEAT, "tests particle stop time on a test model" );
2446 cmdSystem->AddCommand( "nextAnim", idTestModel::TestModelNextAnim_f, CMD_FL_GAME|CMD_FL_CHEAT, "shows next animation on test model" );
2447 cmdSystem->AddCommand( "prevAnim", idTestModel::TestModelPrevAnim_f, CMD_FL_GAME|CMD_FL_CHEAT, "shows previous animation on test model" );
2448 cmdSystem->AddCommand( "nextFrame", idTestModel::TestModelNextFrame_f, CMD_FL_GAME|CMD_FL_CHEAT, "shows next animation frame on test model" );
2449 cmdSystem->AddCommand( "prevFrame", idTestModel::TestModelPrevFrame_f, CMD_FL_GAME|CMD_FL_CHEAT, "shows previous animation frame on test model" );
2450 cmdSystem->AddCommand( "testBlend", idTestModel::TestBlend_f, CMD_FL_GAME|CMD_FL_CHEAT, "tests animation blending" );
2451 cmdSystem->AddCommand( "reloadScript", Cmd_ReloadScript_f, CMD_FL_GAME|CMD_FL_CHEAT, "reloads scripts" );
2452 cmdSystem->AddCommand( "script", Cmd_Script_f, CMD_FL_GAME|CMD_FL_CHEAT, "executes a line of script" );
2453 cmdSystem->AddCommand( "listCollisionModels", Cmd_ListCollisionModels_f, CMD_FL_GAME, "lists collision models" );
2454 cmdSystem->AddCommand( "collisionModelInfo", Cmd_CollisionModelInfo_f, CMD_FL_GAME, "shows collision model info" );
2455 cmdSystem->AddCommand( "reexportmodels", Cmd_ReexportModels_f, CMD_FL_GAME|CMD_FL_CHEAT, "reexports models", ArgCompletion_DefFile );
2456 cmdSystem->AddCommand( "reloadanims", Cmd_ReloadAnims_f, CMD_FL_GAME|CMD_FL_CHEAT, "reloads animations" );
2457 cmdSystem->AddCommand( "listAnims", Cmd_ListAnims_f, CMD_FL_GAME, "lists all animations" );
2458 cmdSystem->AddCommand( "aasStats", Cmd_AASStats_f, CMD_FL_GAME, "shows AAS stats" );
2459 cmdSystem->AddCommand( "testDamage", Cmd_TestDamage_f, CMD_FL_GAME|CMD_FL_CHEAT, "tests a damage def", idCmdSystem::ArgCompletion_Decl<DECL_ENTITYDEF> );
2460 cmdSystem->AddCommand( "weaponSplat", Cmd_WeaponSplat_f, CMD_FL_GAME|CMD_FL_CHEAT, "projects a blood splat on the player weapon" );
2461 cmdSystem->AddCommand( "saveSelected", Cmd_SaveSelected_f, CMD_FL_GAME|CMD_FL_CHEAT, "saves the selected entity to the .map file" );
2462 cmdSystem->AddCommand( "deleteSelected", Cmd_DeleteSelected_f, CMD_FL_GAME|CMD_FL_CHEAT, "deletes selected entity" );
2463 cmdSystem->AddCommand( "saveMoveables", Cmd_SaveMoveables_f, CMD_FL_GAME|CMD_FL_CHEAT, "save all moveables to the .map file" );
2464 cmdSystem->AddCommand( "saveRagdolls", Cmd_SaveRagdolls_f, CMD_FL_GAME|CMD_FL_CHEAT, "save all ragdoll poses to the .map file" );
2465 cmdSystem->AddCommand( "bindRagdoll", Cmd_BindRagdoll_f, CMD_FL_GAME|CMD_FL_CHEAT, "binds ragdoll at the current drag position" );
2466 cmdSystem->AddCommand( "unbindRagdoll", Cmd_UnbindRagdoll_f, CMD_FL_GAME|CMD_FL_CHEAT, "unbinds the selected ragdoll" );
2467 cmdSystem->AddCommand( "saveLights", Cmd_SaveLights_f, CMD_FL_GAME|CMD_FL_CHEAT, "saves all lights to the .map file" );
2468 cmdSystem->AddCommand( "saveParticles", Cmd_SaveParticles_f, CMD_FL_GAME|CMD_FL_CHEAT, "saves all lights to the .map file" );
2469 cmdSystem->AddCommand( "clearLights", Cmd_ClearLights_f, CMD_FL_GAME|CMD_FL_CHEAT, "clears all lights" );
2470 cmdSystem->AddCommand( "gameError", Cmd_GameError_f, CMD_FL_GAME|CMD_FL_CHEAT, "causes a game error" );
2472 #ifndef ID_DEMO_BUILD
2473 cmdSystem->AddCommand( "disasmScript", Cmd_DisasmScript_f, CMD_FL_GAME|CMD_FL_CHEAT, "disassembles script" );
2474 cmdSystem->AddCommand( "recordViewNotes", Cmd_RecordViewNotes_f, CMD_FL_GAME|CMD_FL_CHEAT, "record the current view position with notes" );
2475 cmdSystem->AddCommand( "showViewNotes", Cmd_ShowViewNotes_f, CMD_FL_GAME|CMD_FL_CHEAT, "show any view notes for the current map, successive calls will cycle to the next note" );
2476 cmdSystem->AddCommand( "closeViewNotes", Cmd_CloseViewNotes_f, CMD_FL_GAME|CMD_FL_CHEAT, "close the view showing any notes for this map" );
2477 cmdSystem->AddCommand( "exportmodels", Cmd_ExportModels_f, CMD_FL_GAME|CMD_FL_CHEAT, "exports models", ArgCompletion_DefFile );
2479 // multiplayer client commands ( replaces old impulses stuff )
2480 cmdSystem->AddCommand( "clientDropWeapon", idMultiplayerGame::DropWeapon_f, CMD_FL_GAME, "drop current weapon" );
2481 cmdSystem->AddCommand( "clientMessageMode", idMultiplayerGame::MessageMode_f, CMD_FL_GAME, "ingame gui message mode" );
2483 // cmdSystem->AddCommand( "clientVote", idMultiplayerGame::Vote_f, CMD_FL_GAME, "cast your vote: clientVote yes | no" );
2484 // cmdSystem->AddCommand( "clientCallVote", idMultiplayerGame::CallVote_f, CMD_FL_GAME, "call a vote: clientCallVote si_.. proposed_value" );
2485 cmdSystem->AddCommand( "clientVoiceChat", idMultiplayerGame::VoiceChat_f, CMD_FL_GAME, "voice chats: clientVoiceChat <sound shader>" );
2486 cmdSystem->AddCommand( "clientVoiceChatTeam", idMultiplayerGame::VoiceChatTeam_f, CMD_FL_GAME, "team voice chats: clientVoiceChat <sound shader>" );
2488 // multiplayer server commands
2489 cmdSystem->AddCommand( "serverMapRestart", idGameLocal::MapRestart_f, CMD_FL_GAME, "restart the current game" );
2490 cmdSystem->AddCommand( "serverForceReady", idMultiplayerGame::ForceReady_f,CMD_FL_GAME, "force all players ready" );
2491 cmdSystem->AddCommand( "serverNextMap", idGameLocal::NextMap_f, CMD_FL_GAME, "change to the next map" );
2494 // localization help commands
2495 cmdSystem->AddCommand( "nextGUI", Cmd_NextGUI_f, CMD_FL_GAME|CMD_FL_CHEAT, "teleport the player to the next func_static with a gui" );
2496 cmdSystem->AddCommand( "testid", Cmd_TestId_f, CMD_FL_GAME|CMD_FL_CHEAT, "output the string for the specified id." );
2499 cmdSystem->AddCommand( "setActorState", Cmd_SetActorState_f, CMD_FL_GAME|CMD_FL_CHEAT, "Manually sets an actors script state", idGameLocal::ArgCompletion_EntityName );
2505 idGameLocal::ShutdownConsoleCommands
2508 void idGameLocal::ShutdownConsoleCommands( void ) {
2509 cmdSystem->RemoveFlaggedCommands( CMD_FL_GAME );