forked from RobertBeckebans/RBDOOM-3-BFG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi_input.cpp
474 lines (382 loc) · 8.92 KB
/
i_input.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
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.
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.
===========================================================================
*/
#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() {
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() {
if( PLAYERCOUNT != 1 || ::g->netgame ) {
return false;
}
G_ExitLevel();
return true;
}
static bool Cheat_GiveAll() {
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() {
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() {
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 /*powertype_t*/ 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() {
if( PLAYERCOUNT != 1 || ::g->netgame ) {
return false;
}
TogglePowerUp( 0 );
return true;
}
static bool Cheat_GiveBerserk() {
if( PLAYERCOUNT != 1 || ::g->netgame ) {
return false;
}
TogglePowerUp( 1 );
return true;
}
static bool Cheat_GiveBlur() {
if( PLAYERCOUNT != 1 || ::g->netgame ) {
return false;
}
TogglePowerUp( 2 );
return true;
}
static bool Cheat_GiveRad() {
if( PLAYERCOUNT != 1 || ::g->netgame ) {
return false;
}
TogglePowerUp( 3 );
return true;
}
static bool Cheat_GiveMap() {
if( PLAYERCOUNT != 1 || ::g->netgame ) {
return false;
}
TogglePowerUp( 4 );
return true;
}
static bool Cheat_GiveLight() {
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 }, // a b b a
{ {0, 0, 1, 1}, Cheat_NextLevel }, // a a b b
{ {1, 0, 1, 0}, Cheat_GiveAmmo }, // b a b a
{ {1, 1, 0, 0}, Cheat_Choppers}, // b b a a
{ {0, 1, 0, 1}, Cheat_GiveAll }, // a b a b
{ {2, 3, 3, 2}, Cheat_GiveInvul }, // x y y x
{ {2, 2, 2, 3}, Cheat_GiveBerserk }, // x x x y
{ {2, 2, 3, 3}, Cheat_GiveBlur }, // x x y y
{ {2, 3, 3, 3}, Cheat_GiveRad }, // x y y y
{ {3, 2, 3, 2}, Cheat_GiveMap }, // y x y x
{ {3, 3, 3, 2}, Cheat_GiveLight}, // y y y x
};
const static int numberOfCodes = sizeof(codes) / sizeof(codes[0]);
void BeginTrackingCheat() {
#if ALLOW_CHEATS
tracking = true;
currentCheatLength = 0;
memset( currentCode, 0, sizeof( currentCode ) );
#endif
}
void EndTrackingCheat() {
#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);
}
}
}
// reset the code
memset( currentCode, 0, sizeof( currentCode ) );
currentCheatLength = 0;
}
}
#endif
}
float xbox_deadzone = 0.28f;
// input event storage
//PRIVATE TO THE INPUT THREAD!
void I_InitInput(void)
{
}
void I_ShutdownInput()
{
}
static float _joyAxisConvert(short x, float xbxScale, float dScale, float deadZone)
{
//const float signConverted = x - 127;
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;
}
//
// Translates the key currently in X_event
//
static int xlatekey(int key)
{
int rc = KEY_F1;
switch (key)
{
case 0: // A
//rc = KEY_ENTER;
rc = ' ';
break;
case 3: // Y
rc = '1';
break;
case 1: // B
if( ::g->menuactive ) {
rc = KEY_BACKSPACE;
}
else {
rc = '2';
}
break;
case 2: // X
//rc = ' ';
rc = KEY_TAB;
break;
case 4: // White
rc = KEY_MINUS;
break;
case 5: // Black
rc = KEY_EQUALS;
break;
case 6: // Left triggers
rc = KEY_RSHIFT;
break;
case 7: // Right
rc = KEY_RCTRL;
break;
case 8: // Up
if( ::g->menuactive ) {
rc = KEY_UPARROW;
}
else {
//rc = KEY_ENTER;
rc = '3';
}
break;
case 9:
if( ::g->menuactive ) {
rc = KEY_DOWNARROW;
}
else {
//rc = KEY_TAB;
rc = '5';
}
break;
case 10:
if( ::g->menuactive ) {
rc = KEY_UPARROW;
}
else {
//rc = '1';
rc = '6';
}
break;
case 11:
if( ::g->menuactive ) {
rc = KEY_DOWNARROW;
}
else {
//rc = '2';
rc = '4';
}
break;
case 12: // start
rc = KEY_ESCAPE;
break;
case 13: //select
//rc = KEY_ESCAPE;
break;
case 14: // lclick
case 15: // rclick
//rc = ' ';
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;//ev_mouse;
switch (::g->joyEvents[n].action)
{
case J_DELTAX:
/*
if (::g->joyEvents[n].data < 0)
e->data2 = -1;
else if (::g->joyEvents[n].data > 0)
e->data2 = 1;
*/
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() {
int i;
for(i = 0; i < 18; i++)
{
::g->joyEvents[i].type = IETNone;
}
}