i_input.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition 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 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. 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.
  18. ===========================================================================
  19. */
  20. #include "Precompiled.h"
  21. #include "globaldata.h"
  22. #include <stdlib.h>
  23. #include <stdarg.h>
  24. #include <sys/types.h>
  25. #include "i_video.h"
  26. #include "i_system.h"
  27. #include "doomstat.h"
  28. #include "v_video.h"
  29. #include "m_argv.h"
  30. #include "d_main.h"
  31. #include "doomdef.h"
  32. #include "sys/sys_public.h"
  33. #define ALLOW_CHEATS 1
  34. extern int PLAYERCOUNT;
  35. #define NUM_BUTTONS 4
  36. static bool Cheat_God( void ) {
  37. if( PLAYERCOUNT != 1 || ::g->netgame ) {
  38. return false;
  39. }
  40. ::g->plyr->cheats ^= CF_GODMODE;
  41. if (::g->plyr->cheats & CF_GODMODE)
  42. {
  43. if (::g->plyr->mo)
  44. ::g->plyr->mo->health = 100;
  45. ::g->plyr->health = 100;
  46. ::g->plyr->message = STSTR_DQDON;
  47. }
  48. else
  49. ::g->plyr->message = STSTR_DQDOFF;
  50. return true;
  51. }
  52. #include "g_game.h"
  53. static bool Cheat_NextLevel( void ) {
  54. if( PLAYERCOUNT != 1 || ::g->netgame ) {
  55. return false;
  56. }
  57. G_ExitLevel();
  58. return true;
  59. }
  60. static bool Cheat_GiveAll( void ) {
  61. if( PLAYERCOUNT != 1 || ::g->netgame ) {
  62. return false;
  63. }
  64. ::g->plyr->armorpoints = 200;
  65. ::g->plyr->armortype = 2;
  66. int i;
  67. for (i=0;i<NUMWEAPONS;i++)
  68. ::g->plyr->weaponowned[i] = true;
  69. for (i=0;i<NUMAMMO;i++)
  70. ::g->plyr->ammo[i] = ::g->plyr->maxammo[i];
  71. for (i=0;i<NUMCARDS;i++)
  72. ::g->plyr->cards[i] = true;
  73. ::g->plyr->message = STSTR_KFAADDED;
  74. return true;
  75. }
  76. static bool Cheat_GiveAmmo( void ) {
  77. if( PLAYERCOUNT != 1 || ::g->netgame ) {
  78. return false;
  79. }
  80. ::g->plyr->armorpoints = 200;
  81. ::g->plyr->armortype = 2;
  82. int i;
  83. for (i=0;i<NUMWEAPONS;i++)
  84. ::g->plyr->weaponowned[i] = true;
  85. for (i=0;i<NUMAMMO;i++)
  86. ::g->plyr->ammo[i] = ::g->plyr->maxammo[i];
  87. ::g->plyr->message = STSTR_KFAADDED;
  88. return true;
  89. }
  90. static bool Cheat_Choppers( void ) {
  91. if( PLAYERCOUNT != 1 || ::g->netgame ) {
  92. return false;
  93. }
  94. ::g->plyr->weaponowned[wp_chainsaw] = true;
  95. ::g->plyr->message = "Chainsaw!";
  96. return true;
  97. }
  98. extern qboolean P_GivePower ( player_t* player, int /*powertype_t*/ power );
  99. static void TogglePowerUp( int i ) {
  100. if (!::g->plyr->powers[i])
  101. P_GivePower( ::g->plyr, i);
  102. else if (i!=pw_strength)
  103. ::g->plyr->powers[i] = 1;
  104. else
  105. ::g->plyr->powers[i] = 0;
  106. ::g->plyr->message = STSTR_BEHOLDX;
  107. }
  108. static bool Cheat_GiveInvul( void ) {
  109. if( PLAYERCOUNT != 1 || ::g->netgame ) {
  110. return false;
  111. }
  112. TogglePowerUp( 0 );
  113. return true;
  114. }
  115. static bool Cheat_GiveBerserk( void ) {
  116. if( PLAYERCOUNT != 1 || ::g->netgame ) {
  117. return false;
  118. }
  119. TogglePowerUp( 1 );
  120. return true;
  121. }
  122. static bool Cheat_GiveBlur( void ) {
  123. if( PLAYERCOUNT != 1 || ::g->netgame ) {
  124. return false;
  125. }
  126. TogglePowerUp( 2 );
  127. return true;
  128. }
  129. static bool Cheat_GiveRad( void ) {
  130. if( PLAYERCOUNT != 1 || ::g->netgame ) {
  131. return false;
  132. }
  133. TogglePowerUp( 3 );
  134. return true;
  135. }
  136. static bool Cheat_GiveMap( void ) {
  137. if( PLAYERCOUNT != 1 || ::g->netgame ) {
  138. return false;
  139. }
  140. TogglePowerUp( 4 );
  141. return true;
  142. }
  143. static bool Cheat_GiveLight( void ) {
  144. if( PLAYERCOUNT != 1 || ::g->netgame ) {
  145. return false;
  146. }
  147. TogglePowerUp( 5 );
  148. return true;
  149. }
  150. #ifndef __PS3__
  151. static bool tracking = false;
  152. static int currentCode[NUM_BUTTONS];
  153. static int currentCheatLength;
  154. #endif
  155. typedef bool(*cheat_command)(void);
  156. struct cheatcode_t
  157. {
  158. int code[NUM_BUTTONS];
  159. cheat_command function;
  160. };
  161. static cheatcode_t codes[] = {
  162. { {0, 1, 1, 0}, Cheat_God }, // a b b a
  163. { {0, 0, 1, 1}, Cheat_NextLevel }, // a a b b
  164. { {1, 0, 1, 0}, Cheat_GiveAmmo }, // b a b a
  165. { {1, 1, 0, 0}, Cheat_Choppers}, // b b a a
  166. { {0, 1, 0, 1}, Cheat_GiveAll }, // a b a b
  167. { {2, 3, 3, 2}, Cheat_GiveInvul }, // x y y x
  168. { {2, 2, 2, 3}, Cheat_GiveBerserk }, // x x x y
  169. { {2, 2, 3, 3}, Cheat_GiveBlur }, // x x y y
  170. { {2, 3, 3, 3}, Cheat_GiveRad }, // x y y y
  171. { {3, 2, 3, 2}, Cheat_GiveMap }, // y x y x
  172. { {3, 3, 3, 2}, Cheat_GiveLight}, // y y y x
  173. };
  174. const static int numberOfCodes = sizeof(codes) / sizeof(codes[0]);
  175. void BeginTrackingCheat( void ) {
  176. #if ALLOW_CHEATS
  177. tracking = true;
  178. currentCheatLength = 0;
  179. memset( currentCode, 0, sizeof( currentCode ) );
  180. #endif
  181. }
  182. void EndTrackingCheat( void ) {
  183. #if ALLOW_CHEATS
  184. tracking = false;
  185. #endif
  186. }
  187. extern void S_StartSound ( void* origin, int sfx_id );
  188. void CheckCheat( int button ) {
  189. #if ALLOW_CHEATS
  190. if( tracking && !::g->netgame ) {
  191. currentCode[ currentCheatLength++ ] = button;
  192. if( currentCheatLength == NUM_BUTTONS ) {
  193. for( int i = 0; i < numberOfCodes; ++i) {
  194. if( memcmp( &codes[i].code[0], &currentCode[0], sizeof(currentCode) ) == 0 ) {
  195. if(codes[i].function()) {
  196. S_StartSound(0, sfx_cybsit);
  197. }
  198. }
  199. }
  200. // reset the code
  201. memset( currentCode, 0, sizeof( currentCode ) );
  202. currentCheatLength = 0;
  203. }
  204. }
  205. #endif
  206. }
  207. float xbox_deadzone = 0.28f;
  208. // input event storage
  209. //PRIVATE TO THE INPUT THREAD!
  210. void I_InitInput(void)
  211. {
  212. }
  213. void I_ShutdownInput( void )
  214. {
  215. }
  216. static float _joyAxisConvert(short x, float xbxScale, float dScale, float deadZone)
  217. {
  218. //const float signConverted = x - 127;
  219. float y = x - 127;
  220. y = y / xbxScale;
  221. return (fabs(y) < deadZone) ? 0.f : (y * dScale);
  222. }
  223. int I_PollMouseInputEvents( controller_t *con)
  224. {
  225. int numEvents = 0;
  226. return numEvents;
  227. }
  228. int I_ReturnMouseInputEvent( const int n, event_t* e) {
  229. e->type = ev_mouse;
  230. e->data1 = e->data2 = e->data3 = 0;
  231. switch(::g->mouseEvents[n].type) {
  232. case IETAxis:
  233. switch (::g->mouseEvents[n].action)
  234. {
  235. case M_DELTAX:
  236. e->data2 = ::g->mouseEvents[n].data;
  237. break;
  238. case M_DELTAY:
  239. e->data3 = ::g->mouseEvents[n].data;
  240. break;
  241. }
  242. return 1;
  243. default:
  244. break;
  245. }
  246. return 0;
  247. }
  248. int I_PollJoystickInputEvents( controller_t *con ) {
  249. int numEvents = 0;
  250. return numEvents;
  251. }
  252. //
  253. // Translates the key currently in X_event
  254. //
  255. static int xlatekey(int key)
  256. {
  257. int rc = KEY_F1;
  258. switch (key)
  259. {
  260. case 0: // A
  261. //rc = KEY_ENTER;
  262. rc = ' ';
  263. break;
  264. case 3: // Y
  265. rc = '1';
  266. break;
  267. case 1: // B
  268. if( ::g->menuactive ) {
  269. rc = KEY_BACKSPACE;
  270. }
  271. else {
  272. rc = '2';
  273. }
  274. break;
  275. case 2: // X
  276. //rc = ' ';
  277. rc = KEY_TAB;
  278. break;
  279. case 4: // White
  280. rc = KEY_MINUS;
  281. break;
  282. case 5: // Black
  283. rc = KEY_EQUALS;
  284. break;
  285. case 6: // Left triggers
  286. rc = KEY_RSHIFT;
  287. break;
  288. case 7: // Right
  289. rc = KEY_RCTRL;
  290. break;
  291. case 8: // Up
  292. if( ::g->menuactive ) {
  293. rc = KEY_UPARROW;
  294. }
  295. else {
  296. //rc = KEY_ENTER;
  297. rc = '3';
  298. }
  299. break;
  300. case 9:
  301. if( ::g->menuactive ) {
  302. rc = KEY_DOWNARROW;
  303. }
  304. else {
  305. //rc = KEY_TAB;
  306. rc = '5';
  307. }
  308. break;
  309. case 10:
  310. if( ::g->menuactive ) {
  311. rc = KEY_UPARROW;
  312. }
  313. else {
  314. //rc = '1';
  315. rc = '6';
  316. }
  317. break;
  318. case 11:
  319. if( ::g->menuactive ) {
  320. rc = KEY_DOWNARROW;
  321. }
  322. else {
  323. //rc = '2';
  324. rc = '4';
  325. }
  326. break;
  327. case 12: // start
  328. rc = KEY_ESCAPE;
  329. break;
  330. case 13: //select
  331. //rc = KEY_ESCAPE;
  332. break;
  333. case 14: // lclick
  334. case 15: // rclick
  335. //rc = ' ';
  336. break;
  337. }
  338. return rc;
  339. }
  340. int I_ReturnJoystickInputEvent( const int n, event_t* e) {
  341. e->data1 = e->data2 = e->data3 = 0;
  342. switch(::g->joyEvents[n].type)
  343. {
  344. case IETAxis:
  345. e->type = ev_joystick;//ev_mouse;
  346. switch (::g->joyEvents[n].action)
  347. {
  348. case J_DELTAX:
  349. /*
  350. if (::g->joyEvents[n].data < 0)
  351. e->data2 = -1;
  352. else if (::g->joyEvents[n].data > 0)
  353. e->data2 = 1;
  354. */
  355. e->data2 = ::g->joyEvents[n].data;
  356. break;
  357. case J_DELTAY:
  358. e->type = ev_mouse;
  359. e->data3 = ::g->joyEvents[n].data;
  360. break;
  361. }
  362. return 1;
  363. case IETButtonAnalog:
  364. case IETButtonDigital:
  365. if (::g->joyEvents[n].data)
  366. e->type = ev_keydown;
  367. else
  368. e->type = ev_keyup;
  369. e->data1 = xlatekey(::g->joyEvents[n].action);
  370. return 1;
  371. case IETNone:
  372. break;
  373. }
  374. return 0;
  375. }
  376. void I_EndJoystickInputEvents( void ) {
  377. int i;
  378. for(i = 0; i < 18; i++)
  379. {
  380. ::g->joyEvents[i].type = IETNone;
  381. }
  382. }