1 // Emacs style mode select -*- C++ -*- 2 //----------------------------------------------------------------------------- 3 // 4 // $Id: c_dispatch.h 4469 2014-01-03 23:38:29Z dr_sean $ 5 // 6 // Copyright (C) 1998-2006 by Randy Heit (ZDoom). 7 // Copyright (C) 2006-2014 by The Odamex Team. 8 // 9 // This program is free software; you can redistribute it and/or 10 // modify it under the terms of the GNU General Public License 11 // as published by the Free Software Foundation; either version 2 12 // of the License, or (at your option) any later version. 13 // 14 // This program 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. 18 // 19 // DESCRIPTION: 20 // Argument processing (?) 21 // 22 //----------------------------------------------------------------------------- 23 24 25 #ifndef __C_DISPATCH_H__ 26 #define __C_DISPATCH_H__ 27 28 #include "dobject.h" 29 30 #include <string> 31 #include <vector> 32 33 void C_ExecCmdLineParams (bool onlyset, bool onlylogfile); 34 35 // add commands to the console as if they were typed in 36 // for map changing, etc 37 void AddCommandString (const std::string &cmd, bool onlycvar = false); 38 39 // parse a command string 40 const char *ParseString (const char *data); 41 42 // combine many arguments into one valid argument. 43 std::string C_ArgCombine(size_t argc, const char **argv); 44 std::string BuildString (size_t argc, std::vector<std::string> args); 45 46 // quote a string 47 std::string C_QuoteString(const std::string &argstr); 48 49 class DConsoleCommand : public DObject 50 { 51 DECLARE_CLASS (DConsoleCommand, DObject) 52 public: 53 DConsoleCommand (const char *name); 54 virtual ~DConsoleCommand (); 55 virtual void Run () = 0; IsAlias()56 virtual bool IsAlias () { return false; } PrintCommand()57 void PrintCommand () { Printf (PRINT_HIGH, "%s\n", m_Name.c_str()); } 58 59 std::string m_Name; 60 61 protected: 62 DConsoleCommand (); 63 64 AActor *m_Instigator; 65 size_t argc; 66 char **argv; 67 char *args; 68 69 friend void C_DoCommand (const char *cmd); 70 }; 71 72 #define BEGIN_COMMAND(n) \ 73 class Cmd_##n : public DConsoleCommand { \ 74 public: \ 75 Cmd_##n () : DConsoleCommand (#n) {} \ 76 Cmd_##n (const char *name) : DConsoleCommand (name) {} \ 77 void Run () 78 79 #define END_COMMAND(n) }; \ 80 static Cmd_##n Cmd_instance##n; 81 82 class DConsoleAlias : public DConsoleCommand 83 { 84 DECLARE_CLASS (DConsoleAlias, DConsoleCommand) 85 bool state_lock; 86 public: 87 DConsoleAlias (const char *name, const char *command); 88 virtual ~DConsoleAlias (); 89 virtual void Run (); IsAlias()90 virtual bool IsAlias () { return true; } PrintAlias()91 void PrintAlias () { Printf (PRINT_HIGH, "%s : %s\n", m_Name.c_str(), m_Command.c_str()); } 92 void Archive (FILE *f); 93 94 // Write out alias commands to a file for all current aliases. 95 static void C_ArchiveAliases (FILE *f); 96 97 // Destroy all aliases (used on shutdown) 98 static void DestroyAll(); 99 protected: 100 std::string m_Command; 101 std::string m_CommandParam; 102 }; 103 104 // Actions 105 #define ACTION_MLOOK 0 106 #define ACTION_KLOOK 1 107 #define ACTION_USE 2 108 #define ACTION_ATTACK 3 109 #define ACTION_SPEED 4 110 #define ACTION_MOVERIGHT 5 111 #define ACTION_MOVELEFT 6 112 #define ACTION_STRAFE 7 113 #define ACTION_LOOKDOWN 8 114 #define ACTION_LOOKUP 9 115 #define ACTION_BACK 10 116 #define ACTION_FORWARD 11 117 #define ACTION_RIGHT 12 118 #define ACTION_LEFT 13 119 #define ACTION_MOVEDOWN 14 120 #define ACTION_MOVEUP 15 121 #define ACTION_JUMP 16 122 #define ACTION_SHOWSCORES 17 123 #define NUM_ACTIONS 18 124 125 extern byte Actions[NUM_ACTIONS]; 126 127 struct ActionBits 128 { 129 unsigned int key; 130 int index; 131 char name[12]; 132 }; 133 134 extern unsigned int MakeKey (const char *s); 135 136 #endif //__C_DISPATCH_H__ 137