input.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // input.h
  19. // Project: Postal
  20. //
  21. // History:
  22. // 12/05/96 MJR Started.
  23. //
  24. // 02/19/97 BRH Modified to include the keys we are currently using
  25. // for CDude control in the game. Added functions for
  26. // getting and setting input for local and remote play.
  27. //
  28. // 03/03/97 JMI Added macros for keys 1 through 5 (CDude will use
  29. // these to chose a weapon).
  30. //
  31. // 03/14/97 JMI Added macros for space key.
  32. //
  33. // 03/24/97 JMI Changed typedef for UINPUT from U16 to U32.
  34. // Added INPUT_ROT_MASK. The first 9 bits are now reserved
  35. // for a rotation value between 0 and 359 inclusive. This
  36. // pushed all the other bits up a bit, but I don't think that
  37. // anything currently uses this API w/o the INPUT_* macros.
  38. //
  39. // 03/26/97 JMI Was getting rotation for mouse input backwards. Fixed.
  40. //
  41. // 03/27/97 JMI Added macros for numpad 0 key (CDude will use this for
  42. // duck).
  43. //
  44. // 03/27/97 JMI Shortcutted INSERT to same as numpad 0 as patch for now.
  45. //
  46. // 03/31/97 JMI Now the actual keys used are chosen by g_InputSettings.
  47. // Therefore, macros are now more generic (e.g., INPUT_R
  48. // became INPUT_RIGHT, and INPUT_ALT became INPUT_FIRE).
  49. // Added g_InputSettings declaration.
  50. //
  51. // 04/01/97 JMI Now we used 10 bits for the rotation value and, although
  52. // it is stored as unsigned (0..720), it represents a postive
  53. // or negative delta between -360 and 360.
  54. //
  55. // 04/03/97 JMI Now checks rspIsBackground() before doing mouse stuff.
  56. //
  57. // 04/11/97 MJR Moved lots of stuff into input.cpp and added support for
  58. // recording and playing back inputs for self-playing mode.
  59. //
  60. // 04/11/97 JMI Changed INPUT_MENU to INPUT_SUICIDE.
  61. // Also, added INPUT_NEXT_LEVEL.
  62. // Added an RInputEvent* to GetLocalInput() proto.
  63. // externs for m_aInputs were not specifying a type and, there-
  64. // fore, it was an 'int' array instead of UINPUT.
  65. //
  66. // 04/22/97 JMI Added extern of g_InputSettings.
  67. //
  68. // 04/24/97 JMI Moved around INPUT_JUMP, INPUT_SUICIDE, and
  69. // INPUT_NEXT_LEVEL.
  70. // Also, added INPUT_WEAPON_6...9 and INPUT_EXECUTE.
  71. // Consequently, we're out of inputs (and we still don't have
  72. // INPUT_TOGGLE_HUMANSHIELD).
  73. //
  74. // 05/02/97 JMI Increased number of available input bits by reducing
  75. // the weapon changing bits to 4 bits (now a number instead of
  76. // bit fields).
  77. //
  78. // 05/13/97 JMI Changed INPUT_RUN to INPUT_WALK.
  79. //
  80. // 05/14/97 JMI Added INPUT_PICKUP.
  81. //
  82. // 06/09/97 JMI Changed INPUT_WALK to INPUT_RUN.
  83. //
  84. // 06/15/97 MJR Removed INPUT_NEXT_LEVEL, which has now been replaced by
  85. // an client/server mechanism.
  86. //
  87. // 06/15/97 MJR Changed to separate InputDemoInit() and InputDemoKill()
  88. // functions to make it real obvious and clean.
  89. //
  90. // 07/15/97 JMI Added INPUT_WEAPONS_BIT.
  91. //
  92. // 07/19/97 JMI Added InitLocalInput().
  93. //
  94. // 07/25/97 JMI Added more INPUT_*'s and changed INPUT_WEAPON_11,12,13,14
  95. // to INPUT_CHEAT_11,12,13,14. There are now 20 possible
  96. // cheat inputs.
  97. // Also, removed INPUT_PICKUP.
  98. //
  99. // 08/06/97 JMI Changed InitLocalInput() to ClearLocalInput().
  100. //
  101. // 08/10/97 JMI Added StrafeLeft and StrafeRight inputs.
  102. // Also, changed Jump to Revive and INPUT_JUMP to INPUT_REVIVE.
  103. // Had put INPUT_JUMP back temporarily b/c I want to check in
  104. // this and all the files that depend on the new INPUT_REVIVE
  105. // in but play.cpp has been checked out for a long time now.
  106. //
  107. // 08/12/97 JMI Now requires an input event for cheats for GetLocalInput().
  108. //
  109. // 08/17/97 JMI Got rid of INPUT_JUMP, now play.cpp uses INPUT_REVIVE.
  110. //
  111. // 08/26/97 BRH Added query function InputIsDemoOver() for the special
  112. // case ending demo that will be played when the player wins,
  113. //
  114. // 09/06/97 MJR Added INPUT_IDLE.
  115. //
  116. ////////////////////////////////////////////////////////////////////////////////
  117. #ifndef INPUT_H
  118. #define INPUT_H
  119. #include "RSPiX.h"
  120. #include "realm.h"
  121. #include "InputSettings.h"
  122. // Maximum number of dudes supported by this module. Just about any value
  123. // will work, it merely uses up a few extra bytes per dude, and no extra
  124. // processing. This is currently set to a value likely to be far beyond any
  125. // the number of dudes that the main app could support.
  126. #define INPUT_MAX_DUDES 32
  127. // Macros to access bits within an UINPUT type. There are two types of macros:
  128. // "masks" and "bit numbers". The masks are designed to set or get the value
  129. // of a bit. The bit numbers are designed to make it easier to shift the bits
  130. // around. Note that the bit numbers go from 0 to 'n' (currently 15).
  131. //
  132. // The order of the bits should not be changed without carefully weighing the
  133. // consequences. It is highly likely that some code will end up relying on the
  134. // order of the bits for efficiency sake, so changing the order of the bits
  135. // could break existing code. Any such code should certainly refer to these
  136. // macros in some way, so that if it becomes absolutely necessary to change
  137. // this stuff, we can at least track down all the code that uses it.
  138. // The first 10 bits are reserved for a rotation delta value between -359 and 359.
  139. #define INPUT_ROT_MASK 0x000003FF
  140. #define INPUT_REVIVE 0x00000400
  141. #define INPUT_REVIVE_BIT 10
  142. #define INPUT_SUICIDE 0x00000800
  143. #define INPUT_SUICIDE_BIT 11
  144. #define INPUT_RIGHT 0x00001000
  145. #define INPUT_RIGHT_BIT 12
  146. #define INPUT_LEFT 0x00002000
  147. #define INPUT_LEFT_BIT 13
  148. #define INPUT_BACKWARD 0x00004000
  149. #define INPUT_BACKWARD_BIT 14
  150. #define INPUT_FORWARD 0x00008000
  151. #define INPUT_FORWARD_BIT 15
  152. #define INPUT_DIR_MASK 0x0000f000
  153. #define INPUT_STRAFE 0x00010000
  154. #define INPUT_STRAFE_BIT 16
  155. #define INPUT_FIRE 0x00020000
  156. #define INPUT_FIRE_BIT 17
  157. #define INPUT_RUN 0x00040000
  158. #define INPUT_RUN_BIT 18
  159. #define INPUT_DUCK 0x00080000
  160. #define INPUT_DUCK_BIT 19
  161. #define INPUT_WEAPON_0 0x00100000
  162. #define INPUT_WEAPON_1 0x00200000
  163. #define INPUT_WEAPON_2 0x00300000
  164. #define INPUT_WEAPON_3 0x00400000
  165. #define INPUT_WEAPON_4 0x00500000
  166. #define INPUT_WEAPON_5 0x00600000
  167. #define INPUT_WEAPON_6 0x00700000
  168. #define INPUT_WEAPON_7 0x00800000
  169. #define INPUT_WEAPON_8 0x00900000
  170. #define INPUT_WEAPON_9 0x00A00000
  171. #define INPUT_WEAPON_10 0x00B00000
  172. #define INPUT_CHEAT_11 0x00C00000
  173. #define INPUT_CHEAT_12 0x00D00000
  174. #define INPUT_CHEAT_13 0x00E00000
  175. #define INPUT_CHEAT_14 0x00F00000
  176. #define INPUT_CHEAT_15 0x01000000
  177. #define INPUT_CHEAT_16 0x01100000
  178. #define INPUT_CHEAT_17 0x01200000
  179. #define INPUT_CHEAT_18 0x01300000
  180. #define INPUT_CHEAT_19 0x01400000
  181. #define INPUT_CHEAT_20 0x01500000
  182. #define INPUT_CHEAT_21 0x01600000
  183. #define INPUT_CHEAT_22 0x01700000
  184. #define INPUT_CHEAT_23 0x01800000
  185. #define INPUT_CHEAT_24 0x01900000
  186. #define INPUT_CHEAT_25 0x01A00000
  187. #define INPUT_CHEAT_26 0x01B00000
  188. #define INPUT_CHEAT_27 0x01C00000
  189. #define INPUT_CHEAT_28 0x01D00000
  190. #define INPUT_CHEAT_29 0x01E00000
  191. #define INPUT_CHEAT_30 0x01F00000
  192. #define INPUT_WEAPONS_MASK 0x01F00000 // Includes cheats!
  193. #define INPUT_WEAPONS_BIT 20 // thru 24.
  194. //#ifdef MOBILE
  195. #define INPUT_WEAPON_NEXT 0x02000000
  196. #define INPUT_WEAPON_PREV 0x04000000
  197. #define INPUT_ROT_IS_ABS 0x08000000
  198. //#endif
  199. #define INPUT_EXECUTE 0x40000000
  200. #define INPUT_EXECUTE_BIT 30
  201. // Extra flags for keyboard "twinstick" inputs. We could have done this with the ROT_IS_ABS for moving OR shooting
  202. // but then we'd be stuck on the other.
  203. #define INPUT_MOVE_UP 0x00100000000LL
  204. #define INPUT_MOVE_DOWN 0x00200000000LL
  205. #define INPUT_MOVE_LEFT 0x00400000000LL
  206. #define INPUT_MOVE_RIGHT 0x00800000000LL
  207. #define INPUT_FIRE_UP 0x01000000000LL
  208. #define INPUT_FIRE_DOWN 0x02000000000LL
  209. #define INPUT_FIRE_LEFT 0x04000000000LL
  210. #define INPUT_FIRE_RIGHT 0x08000000000LL
  211. #define INPUT_STRAFE_LEFT 0x10000000000LL
  212. #define INPUT_STRAFE_RIGHT 0x20000000000LL
  213. // Use this for when you don't want the dude to do anything
  214. #define INPUT_IDLE 360
  215. // Available input modes
  216. typedef enum
  217. {
  218. INPUT_MODE_LIVE,
  219. INPUT_MODE_RECORD,
  220. INPUT_MODE_PLAYBACK
  221. } INPUT_MODE;
  222. // UINPUT type
  223. // Had to rename this from INPUT because of a pre-existing type
  224. // Redefined to U64 because we ran out of input room.
  225. typedef U64 UINPUT;
  226. // Global input settings.
  227. extern CInputSettings g_InputSettings;
  228. ////////////////////////////////////////////////////////////////////////////////
  229. //
  230. // Set input mode.
  231. //
  232. // InputDemoInit() and InputDemoLoad() must be called before setting playback
  233. // mode.
  234. //
  235. // InputDemoInit() must be called before setting record mode.
  236. //
  237. ////////////////////////////////////////////////////////////////////////////////
  238. extern void SetInputMode(
  239. INPUT_MODE mode); // In: Input mode
  240. ////////////////////////////////////////////////////////////////////////////////
  241. //
  242. // Get current input mode
  243. //
  244. ////////////////////////////////////////////////////////////////////////////////
  245. extern INPUT_MODE GetInputMode(void); // Returns current mode
  246. ////////////////////////////////////////////////////////////////////////////////
  247. //
  248. // Init demo mode. Must be called before setting playback or record modes.
  249. //
  250. ////////////////////////////////////////////////////////////////////////////////
  251. extern short InputDemoInit(void); // Returns 0 if successfull, non-zero otherwise
  252. ////////////////////////////////////////////////////////////////////////////////
  253. //
  254. // Kill demo mode. Must be called if InputDemoInit() was successfull (safe
  255. // to call even if it wasn't.)
  256. //
  257. ////////////////////////////////////////////////////////////////////////////////
  258. extern void InputDemoKill(void);
  259. ////////////////////////////////////////////////////////////////////////////////
  260. //
  261. // Load previously saved input demo data
  262. //
  263. ////////////////////////////////////////////////////////////////////////////////
  264. extern short InputDemoLoad( // Returns 0 if successfull, non-zero otherwise
  265. RFile* pFile); // In: RFile to load from
  266. ////////////////////////////////////////////////////////////////////////////////
  267. //
  268. // Save current input demo data
  269. //
  270. ////////////////////////////////////////////////////////////////////////////////
  271. extern short InputDemoSave( // Returns 0 if successfull, non-zero otherwise
  272. RFile* pFile); // In: RFile to save to
  273. ////////////////////////////////////////////////////////////////////////////////
  274. //
  275. // Reset/Clear/Initialize local input. This should be done just prior to
  276. // iteratively calling GetLocalInput(). It resets the last input storage and
  277. // positions the mouse, if mouse input is active.
  278. //
  279. ////////////////////////////////////////////////////////////////////////////////
  280. extern void ClearLocalInput(void);
  281. ////////////////////////////////////////////////////////////////////////////////
  282. //
  283. // InputIsDemoOver - query function that returns true if there is no more
  284. // demo data. It will always return true if we are not in
  285. // demo playback mode.
  286. //
  287. ////////////////////////////////////////////////////////////////////////////////
  288. extern bool InputIsDemoOver(void); // Returns true when demo is over
  289. ////////////////////////////////////////////////////////////////////////////////
  290. //
  291. // Get local input
  292. //
  293. ////////////////////////////////////////////////////////////////////////////////
  294. extern UINPUT GetLocalInput( // Returns local input structure.
  295. CRealm* prealm, // In: Realm (used to access realm timer)
  296. RInputEvent* pie = NULL); // In: Latest input event. NULL to
  297. // disable cheats in a way that will be
  298. // harder to hack.
  299. ////////////////////////////////////////////////////////////////////////////////
  300. //
  301. // Get input for specified dude
  302. //
  303. ////////////////////////////////////////////////////////////////////////////////
  304. inline UINPUT GetInput(short sDudeNumber)
  305. {
  306. ASSERT(sDudeNumber < INPUT_MAX_DUDES);
  307. extern UINPUT m_aInputs[INPUT_MAX_DUDES];
  308. return m_aInputs[sDudeNumber];
  309. }
  310. ////////////////////////////////////////////////////////////////////////////////
  311. //
  312. // Set input for specified dude
  313. //
  314. ////////////////////////////////////////////////////////////////////////////////
  315. inline void SetInput(short sDudeNumber, UINPUT input)
  316. {
  317. ASSERT(sDudeNumber < INPUT_MAX_DUDES);
  318. extern UINPUT m_aInputs[INPUT_MAX_DUDES];
  319. m_aInputs[sDudeNumber] = input;
  320. }
  321. #endif //INPUT_H
  322. ////////////////////////////////////////////////////////////////////////////////
  323. // EOF
  324. ////////////////////////////////////////////////////////////////////////////////