123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- #include "Precompiled.h"
- #include "globaldata.h"
- #include <stdlib.h>
- #include <stdarg.h>
- #include <sys/types.h>
- #include "i_video.h"
- #include "i_system.h"
- #include "doomstat.h"
- #include "v_video.h"
- #include "m_argv.h"
- #include "d_main.h"
- #include "doomdef.h"
- #include "sys/sys_public.h"
- #define ALLOW_CHEATS 1
- extern int PLAYERCOUNT;
- #define NUM_BUTTONS 4
- static bool Cheat_God( void ) {
- if( PLAYERCOUNT != 1 || ::g->netgame ) {
- return false;
- }
- ::g->plyr->cheats ^= CF_GODMODE;
- if (::g->plyr->cheats & CF_GODMODE)
- {
- if (::g->plyr->mo)
- ::g->plyr->mo->health = 100;
- ::g->plyr->health = 100;
- ::g->plyr->message = STSTR_DQDON;
- }
- else
- ::g->plyr->message = STSTR_DQDOFF;
- return true;
- }
- #include "g_game.h"
- static bool Cheat_NextLevel( void ) {
- if( PLAYERCOUNT != 1 || ::g->netgame ) {
- return false;
- }
- G_ExitLevel();
- return true;
- }
- static bool Cheat_GiveAll( void ) {
- if( PLAYERCOUNT != 1 || ::g->netgame ) {
- return false;
- }
- ::g->plyr->armorpoints = 200;
- ::g->plyr->armortype = 2;
- int i;
- for (i=0;i<NUMWEAPONS;i++)
- ::g->plyr->weaponowned[i] = true;
- for (i=0;i<NUMAMMO;i++)
- ::g->plyr->ammo[i] = ::g->plyr->maxammo[i];
- for (i=0;i<NUMCARDS;i++)
- ::g->plyr->cards[i] = true;
- ::g->plyr->message = STSTR_KFAADDED;
- return true;
- }
- static bool Cheat_GiveAmmo( void ) {
- if( PLAYERCOUNT != 1 || ::g->netgame ) {
- return false;
- }
- ::g->plyr->armorpoints = 200;
- ::g->plyr->armortype = 2;
- int i;
- for (i=0;i<NUMWEAPONS;i++)
- ::g->plyr->weaponowned[i] = true;
- for (i=0;i<NUMAMMO;i++)
- ::g->plyr->ammo[i] = ::g->plyr->maxammo[i];
- ::g->plyr->message = STSTR_KFAADDED;
- return true;
- }
- static bool Cheat_Choppers( void ) {
- if( PLAYERCOUNT != 1 || ::g->netgame ) {
- return false;
- }
- ::g->plyr->weaponowned[wp_chainsaw] = true;
- ::g->plyr->message = "Chainsaw!";
- return true;
- }
- extern qboolean P_GivePower ( player_t* player, int power );
- static void TogglePowerUp( int i ) {
- if (!::g->plyr->powers[i])
- P_GivePower( ::g->plyr, i);
- else if (i!=pw_strength)
- ::g->plyr->powers[i] = 1;
- else
- ::g->plyr->powers[i] = 0;
- ::g->plyr->message = STSTR_BEHOLDX;
- }
- static bool Cheat_GiveInvul( void ) {
- if( PLAYERCOUNT != 1 || ::g->netgame ) {
- return false;
- }
- TogglePowerUp( 0 );
- return true;
- }
- static bool Cheat_GiveBerserk( void ) {
- if( PLAYERCOUNT != 1 || ::g->netgame ) {
- return false;
- }
- TogglePowerUp( 1 );
- return true;
- }
- static bool Cheat_GiveBlur( void ) {
- if( PLAYERCOUNT != 1 || ::g->netgame ) {
- return false;
- }
- TogglePowerUp( 2 );
- return true;
- }
- static bool Cheat_GiveRad( void ) {
- if( PLAYERCOUNT != 1 || ::g->netgame ) {
- return false;
- }
- TogglePowerUp( 3 );
- return true;
- }
- static bool Cheat_GiveMap( void ) {
- if( PLAYERCOUNT != 1 || ::g->netgame ) {
- return false;
- }
- TogglePowerUp( 4 );
- return true;
- }
- static bool Cheat_GiveLight( void ) {
- if( PLAYERCOUNT != 1 || ::g->netgame ) {
- return false;
- }
- TogglePowerUp( 5 );
- return true;
- }
- #ifndef __PS3__
- static bool tracking = false;
- static int currentCode[NUM_BUTTONS];
- static int currentCheatLength;
- #endif
- typedef bool(*cheat_command)(void);
- struct cheatcode_t
- {
- int code[NUM_BUTTONS];
- cheat_command function;
- };
- static cheatcode_t codes[] = {
- { {0, 1, 1, 0}, Cheat_God },
- { {0, 0, 1, 1}, Cheat_NextLevel },
- { {1, 0, 1, 0}, Cheat_GiveAmmo },
- { {1, 1, 0, 0}, Cheat_Choppers},
- { {0, 1, 0, 1}, Cheat_GiveAll },
- { {2, 3, 3, 2}, Cheat_GiveInvul },
- { {2, 2, 2, 3}, Cheat_GiveBerserk },
- { {2, 2, 3, 3}, Cheat_GiveBlur },
- { {2, 3, 3, 3}, Cheat_GiveRad },
- { {3, 2, 3, 2}, Cheat_GiveMap },
- { {3, 3, 3, 2}, Cheat_GiveLight},
- };
- const static int numberOfCodes = sizeof(codes) / sizeof(codes[0]);
- void BeginTrackingCheat( void ) {
- #if ALLOW_CHEATS
- tracking = true;
- currentCheatLength = 0;
- memset( currentCode, 0, sizeof( currentCode ) );
- #endif
- }
- void EndTrackingCheat( void ) {
- #if ALLOW_CHEATS
- tracking = false;
- #endif
- }
- extern void S_StartSound ( void* origin, int sfx_id );
- void CheckCheat( int button ) {
- #if ALLOW_CHEATS
- if( tracking && !::g->netgame ) {
- currentCode[ currentCheatLength++ ] = button;
- if( currentCheatLength == NUM_BUTTONS ) {
- for( int i = 0; i < numberOfCodes; ++i) {
- if( memcmp( &codes[i].code[0], ¤tCode[0], sizeof(currentCode) ) == 0 ) {
- if(codes[i].function()) {
- S_StartSound(0, sfx_cybsit);
- }
- }
- }
-
- memset( currentCode, 0, sizeof( currentCode ) );
- currentCheatLength = 0;
- }
- }
- #endif
- }
- float xbox_deadzone = 0.28f;
- void I_InitInput(void)
- {
- }
- void I_ShutdownInput( void )
- {
- }
- static float _joyAxisConvert(short x, float xbxScale, float dScale, float deadZone)
- {
-
- float y = x - 127;
- y = y / xbxScale;
- return (fabs(y) < deadZone) ? 0.f : (y * dScale);
- }
- int I_PollMouseInputEvents( controller_t *con)
- {
- int numEvents = 0;
- return numEvents;
- }
- int I_ReturnMouseInputEvent( const int n, event_t* e) {
- e->type = ev_mouse;
- e->data1 = e->data2 = e->data3 = 0;
- switch(::g->mouseEvents[n].type) {
- case IETAxis:
- switch (::g->mouseEvents[n].action)
- {
- case M_DELTAX:
- e->data2 = ::g->mouseEvents[n].data;
- break;
- case M_DELTAY:
- e->data3 = ::g->mouseEvents[n].data;
- break;
- }
- return 1;
- default:
- break;
- }
- return 0;
- }
- int I_PollJoystickInputEvents( controller_t *con ) {
- int numEvents = 0;
- return numEvents;
- }
- static int xlatekey(int key)
- {
- int rc = KEY_F1;
-
- switch (key)
- {
- case 0:
-
- rc = ' ';
- break;
- case 3:
- rc = '1';
- break;
- case 1:
- if( ::g->menuactive ) {
- rc = KEY_BACKSPACE;
- }
- else {
- rc = '2';
- }
- break;
- case 2:
-
- rc = KEY_TAB;
- break;
- case 4:
- rc = KEY_MINUS;
- break;
- case 5:
- rc = KEY_EQUALS;
- break;
- case 6:
- rc = KEY_RSHIFT;
- break;
- case 7:
- rc = KEY_RCTRL;
- break;
- case 8:
- if( ::g->menuactive ) {
- rc = KEY_UPARROW;
- }
- else {
-
- rc = '3';
- }
- break;
- case 9:
- if( ::g->menuactive ) {
- rc = KEY_DOWNARROW;
- }
- else {
-
- rc = '5';
- }
- break;
- case 10:
- if( ::g->menuactive ) {
- rc = KEY_UPARROW;
- }
- else {
-
- rc = '6';
- }
- break;
- case 11:
- if( ::g->menuactive ) {
- rc = KEY_DOWNARROW;
- }
- else {
-
- rc = '4';
- }
- break;
- case 12:
- rc = KEY_ESCAPE;
- break;
- case 13:
-
- break;
- case 14:
- case 15:
-
- break;
- }
- return rc;
- }
- int I_ReturnJoystickInputEvent( const int n, event_t* e) {
- e->data1 = e->data2 = e->data3 = 0;
- switch(::g->joyEvents[n].type)
- {
- case IETAxis:
- e->type = ev_joystick;
- switch (::g->joyEvents[n].action)
- {
- case J_DELTAX:
- e->data2 = ::g->joyEvents[n].data;
- break;
- case J_DELTAY:
- e->type = ev_mouse;
- e->data3 = ::g->joyEvents[n].data;
- break;
- }
- return 1;
- case IETButtonAnalog:
- case IETButtonDigital:
- if (::g->joyEvents[n].data)
- e->type = ev_keydown;
- else
- e->type = ev_keyup;
- e->data1 = xlatekey(::g->joyEvents[n].action);
- return 1;
- case IETNone:
- break;
- }
- return 0;
- }
- void I_EndJoystickInputEvents( void ) {
- int i;
- for(i = 0; i < 18; i++)
- {
- ::g->joyEvents[i].type = IETNone;
- }
- }
|