home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / GameCCmds.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-06  |  9.7 KB  |  409 lines

  1. #include "GameCCmds.h"
  2.  
  3. #include "Game.h"
  4. #include "log.h"
  5. #include "Gui.h"
  6. #include "ConsoleFrontEnd.h"
  7. #include "Network.h"
  8. #include <stdlib.h>
  9. #include "Display.h"
  10.  
  11. CCmdGameRestart::CCmdGameRestart():CCmd("game.restart"){
  12.     usageStr="game.restart";
  13.     infoStr="restarts the game (the arena - not the whole game!)";
  14. }
  15.  
  16. CCmdGameRestart::~CCmdGameRestart(){
  17.     if(console!=NULL)
  18.         console->unregisterCCmd(this);
  19. }
  20.  
  21. bool CCmdGameRestart::exec(int argc, char* argv[]){
  22.     if(argc==0){
  23.         consoleFrontEnd->clearInputString();
  24.         if(Game::wasInit()){
  25.             Game::shutdown();
  26.             if( !Game::init() )
  27.                 Gui::mainMenu->open();
  28.             return false;
  29.         }else{
  30.             console->print("game.restart: No game running, so I'll start a new one.\n");
  31.             return Game::init();
  32.         }
  33.  
  34.     }else{
  35.         console->print("usage: %s\n", usageStr);
  36.         return false;
  37.     }
  38. }
  39.  
  40.  
  41. CCmdGameShutdown::CCmdGameShutdown():CCmd("game.shutdown"){
  42.     usageStr="game.shutdown";
  43.     infoStr="shuts down the running game and returns to main menu";
  44. }
  45.  
  46. CCmdGameShutdown::~CCmdGameShutdown(){
  47.     if(console!=NULL)
  48.         console->unregisterCCmd(this);
  49. }
  50.  
  51. bool CCmdGameShutdown::exec(int argc, char* argv[]){
  52.     if(argc==0){
  53.         if(Game::wasInit()){
  54.             Game::shutdown();
  55.             Input::showMouseCursor();
  56.             Input::freeInput();
  57.             Gui::mainMenu->open();
  58.         }else{
  59.             console->print("game.shutdown: No game running.\n");
  60.             return false;
  61.         }
  62.  
  63.         return true;
  64.     }else{
  65.         console->print("usage: %s\n", usageStr);
  66.         return false;
  67.     }
  68. }
  69.  
  70. CCmdGameStartClientGame::CCmdGameStartClientGame():CCmd("game.startClientGame"){
  71.     usageStr="game.startClientGame [server:port]";
  72.     infoStr="connects you to 'server'";
  73. }
  74.  
  75. CCmdGameStartClientGame::~CCmdGameStartClientGame(){
  76.     if(console!=NULL)
  77.         console->unregisterCCmd(this);
  78. }
  79.  
  80. bool CCmdGameStartClientGame::exec(int argc, char* argv[]){
  81.     if(argc==1){
  82.         Game::info.cvar.game_clientGame->setValStr("1");
  83.         Network::info.cvar.network_server_hostName->setValStr(argv[0]);
  84.         console->print("game.startClientGame: Calling game.restart...\n");
  85.         return Game::info.ccmd.game_restart->exec(0, NULL);
  86. //        return true;
  87.     }else{
  88.         console->print("usage: %s\n", usageStr);
  89.         return false;
  90.     }
  91. }
  92.  
  93.  
  94. CCmdGameStartServer::CCmdGameStartServer():CCmd("game.startServer"){
  95.     usageStr="game.startServer <name> <port> <dedicated>";
  96.     infoStr="starts a server on this machine";
  97. }
  98.  
  99. CCmdGameStartServer::~CCmdGameStartServer(){
  100.     if(console!=NULL)
  101.         console->unregisterCCmd(this);
  102. }
  103.  
  104. bool CCmdGameStartServer::exec(int argc, char* argv[]){
  105.     if(argc>=0 && argc<=3){
  106.         Game::info.cvar.game_clientGame->setValStr("0");
  107.         Network::info.cvar.network_server_hostName->setValStr("localhost");
  108.         if(argc>=1)
  109.             Network::info.cvar.network_server_name->setValStr(argv[0]);
  110.         if(argc>=2)
  111.             Network::info.cvar.network_server_port->setValStr(argv[1]);
  112.         if(argc>=3)
  113.             Network::info.cvar.network_server_dedicated->setValStr(argv[2]);
  114.  
  115.         console->print("game.startServer: Calling game.restart...\n");
  116.         return Game::info.ccmd.game_restart->exec(0, NULL);
  117. //        return true;
  118.     }else{
  119.         console->print("usage: %s\n", usageStr);
  120.         return false;
  121.     }
  122. }
  123.  
  124.  
  125. CCmdGameKill::CCmdGameKill():CCmd("game.kill"){
  126.     usageStr="game.kill <clientId>";
  127.     infoStr="kills a client (or yourself if no id is specified)";
  128. }
  129.  
  130. CCmdGameKill::~CCmdGameKill(){
  131.     if(console!=NULL)
  132.         console->unregisterCCmd(this);
  133. }
  134.  
  135. bool CCmdGameKill::exec(int argc, char* argv[]){
  136.     if( !Game::wasInit() ){
  137.         console->print("game.kill: No game running!");
  138.         return false;
  139.     }
  140.  
  141.     if( argc == 0 ){ // kill self
  142.         if( Network::client->vehicle != NULL ){
  143.             Network::client->sendClientKill();
  144.         }else{
  145.             console->print("game.kill: You are already dead!\n");
  146.         }
  147.  
  148.         return true;
  149.     }if( argc == 1 ){ // kill other client
  150.         if( Game::info.var.clientGame ){
  151.             console->print("game.kill: Can't kill clients on a remote server!\n");
  152.             return false;
  153.         }else{
  154.             int clientId = atoi(argv[0]);
  155.             if( clientId < 0 || clientId >= Network::server->si.maxClients ){
  156.                 console->print("game.kill: ClientId out of bounds.\n");
  157.                 return false;
  158.             }
  159.             Client* c = Network::server->clients[clientId];
  160.             if( c == NULL ){
  161.                 console->print("game.kill: ClientId invalid.\n");
  162.                 return false;
  163.             }
  164.             if( c->vehicle == NULL ){
  165.                 console->print("game.kill: Client already dead.\n");
  166.                 return false;
  167.             }
  168.  
  169.             Network::server->sendClientKill(c->clientId, c->clientId, -1);
  170.             Game::killClient(c, c, -1);
  171. //            log("%s was killed by server admin.\n", c->ci.name);
  172.         }
  173.         return true;
  174.     }else{
  175.         console->print("usage: %s\n", usageStr);
  176.         return false;
  177.     }
  178. }
  179.  
  180.  
  181. CCmdGameChatAll::CCmdGameChatAll():CCmd("game.chatAll"){
  182.     usageStr="game.chatAll <message>";
  183.     infoStr="sends a chat message to all clients";
  184. }
  185.  
  186. CCmdGameChatAll::~CCmdGameChatAll(){
  187.     if(console!=NULL)
  188.         console->unregisterCCmd(this);
  189. }
  190.  
  191. bool CCmdGameChatAll::exec(int argc, char* argv[]){
  192.     if( !Game::wasInit() ){
  193.         console->print("game.chatAll: No game running!\n");
  194.         return false;
  195.     }
  196.  
  197.     if( argc == 0 ){ // open chat prompt
  198.         if( !Gui::hud->chatPrompt->isActive )
  199.             Gui::hud->chatPrompt->activate( GAME_CHAT_MODE_ALL );
  200.  
  201.         return true;
  202.     }if( argc == 1 ){ // send messsage
  203.         Game::chatMessageAll(argv[0]);
  204.  
  205.         return true;
  206.     }else{
  207.         console->print("usage: %s\n", usageStr);
  208.         return false;
  209.     }
  210. }
  211.  
  212.  
  213. CCmdGameChatTeam::CCmdGameChatTeam():CCmd("game.chatTeam"){
  214.     usageStr="game.chatTeam <message>";
  215.     infoStr="sends a chat message to all team members";
  216. }
  217.  
  218. CCmdGameChatTeam::~CCmdGameChatTeam(){
  219.     if(console!=NULL)
  220.         console->unregisterCCmd(this);
  221. }
  222.  
  223. bool CCmdGameChatTeam::exec(int argc, char* argv[]){
  224.     if( !Game::wasInit() ){
  225.         console->print("game.chatTeam: No game running!\n");
  226.         return false;
  227.     }
  228.  
  229.     if( argc == 0 ){ // open chat prompt
  230.         if( !Gui::hud->chatPrompt->isActive )
  231.             Gui::hud->chatPrompt->activate( GAME_CHAT_MODE_TEAM );
  232.  
  233.         return true;
  234.     }if( argc == 1 ){ // send messsage
  235.         Game::chatMessageTeam(argv[0]);
  236.  
  237.         return true;
  238.     }else{
  239.         console->print("usage: %s\n", usageStr);
  240.         return false;
  241.     }
  242. }
  243.  
  244.  
  245.  
  246. CCmdGameVoiceAll::CCmdGameVoiceAll():CCmd("game.voiceAll"){
  247.     usageStr="game.voiceAll [voiceMessage]";
  248.     infoStr="sends a voice message to all clients";
  249. }
  250.  
  251. CCmdGameVoiceAll::~CCmdGameVoiceAll(){
  252.     if(console!=NULL)
  253.         console->unregisterCCmd(this);
  254. }
  255.  
  256. bool CCmdGameVoiceAll::exec(int argc, char* argv[]){
  257.     if( !Game::wasInit() ){
  258.         console->print("game.voiceAll: No game running!\n");
  259.         return false;
  260.     }
  261.  
  262.     if( argc == 1 ){ // send messsage
  263. //        Game::chatMessageAll("VOICE ALL");
  264.         char messageId = (char)Game::getVoiceMessageId(argv[0]);
  265.         if( messageId != -1 ){
  266.             Network::client->sendVoiceMessage( GAME_CHAT_MODE_ALL, messageId);
  267.         }else{
  268.             console->print("game.voiceAll: messageId invalid.\n");
  269.         }
  270.  
  271.         return true;
  272.     }else{
  273.         console->print("usage: %s\n", usageStr);
  274.         return false;
  275.     }
  276. }
  277.  
  278.  
  279. CCmdGameVoiceTeam::CCmdGameVoiceTeam():CCmd("game.voiceTeam"){
  280.     usageStr="game.voiceTeam [voiceMessage]";
  281.     infoStr="sends a voice message to all team members";
  282. }
  283.  
  284. CCmdGameVoiceTeam::~CCmdGameVoiceTeam(){
  285.     if(console!=NULL)
  286.         console->unregisterCCmd(this);
  287. }
  288.  
  289. bool CCmdGameVoiceTeam::exec(int argc, char* argv[]){
  290.     if( !Game::wasInit() ){
  291.         console->print("game.voiceTeam: No game running!\n");
  292.         return false;
  293.     }
  294.  
  295.     if( argc == 1 ){ // send messsage
  296. //        Game::chatMessageTeam("VOICE TEAM");
  297.         char messageId = (char)Game::getVoiceMessageId(argv[0]);
  298.         if( messageId != -1 ){
  299.             Network::client->sendVoiceMessage( GAME_CHAT_MODE_TEAM, messageId);
  300.         }else{
  301.             console->print("game.voiceTeam: messageId invalid.\n");
  302.         }
  303.  
  304.         return true;
  305.     }else{
  306.         console->print("usage: %s\n", usageStr);
  307.         return false;
  308.     }
  309. }
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316. CCmdGameCameraChaseNext::CCmdGameCameraChaseNext():CCmd("game.camera.chaseNext"){
  317.     usageStr="game.camera.chaseNext";
  318.     infoStr="chase next client with camera";
  319. }
  320.  
  321. CCmdGameCameraChaseNext::~CCmdGameCameraChaseNext(){
  322.     if(console!=NULL)
  323.         console->unregisterCCmd(this);
  324. }
  325.  
  326. bool CCmdGameCameraChaseNext::exec(int argc, char* argv[]){
  327.     if( !Game::wasInit() ){
  328.         console->print("game.camera.chaseNext: No game running!");
  329.         return false;
  330.     }
  331.  
  332.     if(argc == 0){
  333.         Game::cam.chaseNext();
  334.         return true;
  335.     }else{
  336.         console->print("usage: %s\n", usageStr);
  337.         return false;
  338.     }
  339. }
  340.  
  341.  
  342. CCmdGameCameraChasePrevious::CCmdGameCameraChasePrevious():CCmd("game.camera.chasePrevious"){
  343.     usageStr="game.camera.chasePrevious";
  344.     infoStr="chase previous client with camera";
  345. }
  346.  
  347. CCmdGameCameraChasePrevious::~CCmdGameCameraChasePrevious(){
  348.     if(console!=NULL)
  349.         console->unregisterCCmd(this);
  350. }
  351.  
  352. bool CCmdGameCameraChasePrevious::exec(int argc, char* argv[]){
  353.     if( !Game::wasInit() ){
  354.         console->print("game.camera.chasePrevious: No game running!");
  355.         return false;
  356.     }
  357.  
  358.     if(argc == 0){
  359.         Game::cam.chasePrevious();
  360.         return true;
  361.     }else{
  362.         console->print("usage: %s\n", usageStr);
  363.         return false;
  364.     }
  365. }
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375. CCmdGameDebugCmd1::CCmdGameDebugCmd1():CCmd("game.debugCmd1"){
  376.     usageStr="game.debugCmd1";
  377.     infoStr="macht irgendwas nuetzliches...";
  378. }
  379.  
  380. CCmdGameDebugCmd1::~CCmdGameDebugCmd1(){
  381.     if(console!=NULL)
  382.         console->unregisterCCmd(this);
  383. }
  384.  
  385. bool CCmdGameDebugCmd1::exec(int argc, char* argv[]){
  386.     if(argc == 0){
  387.         if( Game::wasInit() ){
  388. //            Display::takeScreenshot();
  389. //            castRay();
  390.  
  391. /*
  392.             vec3_t col, pos;
  393.             vectorInit3d(0.8f, 0.6f, 0.1f, col);
  394.             //vectorInit3d(frand(1.0f), frand(1.0f), frand(1.0f), col);
  395.             vectorAdd3d(Network::client->cs.pos, Network::client->cs.dir, pos);
  396.             Renderer::particleSystem.linkParticleCluster(new DynamicLightParticleCluster(pos, col, 1.5f, 100));
  397. */
  398.  
  399.             return true;
  400.         }else{
  401.             console->print("No game running!\n");
  402.             return false;
  403.         }
  404.     }else{
  405.         console->print("usage: %s\n", usageStr);
  406.         return false;
  407.     }
  408. }
  409.