-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
g_controls.c
1026 lines (882 loc) · 26.5 KB
/
g_controls.c
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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $Id$
*
* Copyright (C) 1993-1996 by id Software, Inc.
*
* This source is available for distribution and/or modification
* only under the terms of the DOOM Source Code License as
* published by id Software. All rights reserved.
*
* The source is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
* for more details.
*/
/*
* g_controls.c Game controls, ticcmd building/merging
*/
// HEADER FILES ------------------------------------------------------------
#include <math.h> // required for sqrt, fabs
#if __DOOM64TC__
# include "doom64tc.h"
#elif __WOLFTC__
# include "wolftc.h"
#elif __JDOOM__
# include "jdoom.h"
#elif __JHERETIC__
# include "jheretic.h"
# include "p_inventory.h"
#elif __JHEXEN__
# include "jhexen.h"
# include "p_inventory.h"
#elif __JSTRIFE__
# include "jstrife.h"
#endif
#include "g_controls.h"
#include "p_tick.h" // for P_IsPaused()
// MACROS ------------------------------------------------------------------
#if __JDOOM__ || __JHERETIC__
# define GOTWPN(x) (cplr->weaponowned[x])
# define ISWPN(x) (cplr->readyweapon == x)
#endif
#define SLOWTURNTICS 6
#define JOY(x) (x) / (100)
// TYPES -------------------------------------------------------------------
// Joystick axes.
typedef enum joyaxis_e {
JA_X, JA_Y, JA_Z, JA_RX, JA_RY, JA_RZ, JA_SLIDER0, JA_SLIDER1,
NUM_JOYSTICK_AXES
} joyaxis_t;
#if __JHERETIC__
struct artifacthotkey_s {
int action;
int artifact;
}
ArtifactHotkeys[] =
{
{A_INVULNERABILITY, arti_invulnerability},
{A_INVISIBILITY, arti_invisibility},
{A_HEALTH, arti_health},
{A_SUPERHEALTH, arti_superhealth},
{A_TORCH, arti_torch},
{A_FIREBOMB, arti_firebomb},
{A_EGG, arti_egg},
{A_FLY, arti_fly},
{A_TELEPORT, arti_teleport},
{A_PANIC, NUMARTIFACTS},
{0, arti_none} // Terminator.
};
#endif
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static void G_UpdateCmdControls(ticcmd_t *cmd, float elapsedTime);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern boolean sendpause;
extern float turbomul; // multiplier for turbo
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// Binding classes (for the dynamic event responder chain)
bindclass_t BindClasses[] = {
{"map", GBC_CLASS1, 0, 0},
{"mapfollowoff", GBC_CLASS2, 0, 0},
{"menu", GBC_CLASS3, 0, 1},
{"menuhotkey", GBC_MENUHOTKEY, 1, 0},
{"chat", GBC_CHAT, 0, 0},
{"message", GBC_MESSAGE, 0, 1},
{NULL}
};
// Looking around.
int povangle = -1; // -1 means centered (really 0 - 7).
float targetLookOffset = 0;
float lookOffset = 0;
// Player movement.
fixed_t angleturn[3] = { 640, 1280, 320 }; // + slow turn
// for accelerative turning
float turnheld;
float lookheld;
// mouse values are used once
float mousex;
float mousey;
int dclicktime;
int dclickstate;
int dclicks;
int dclicktime2;
int dclickstate2;
int dclicks2;
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static int joymove[NUM_JOYSTICK_AXES];
// CVars for control/input
cvar_t controlCVars[] = {
// Input (settings)
// Mouse
{"input-mouse-x-sensi", CVF_NO_MAX, CVT_INT, &cfg.mouseSensiX, 0, 25},
{"input-mouse-y-sensi", CVF_NO_MAX, CVT_INT, &cfg.mouseSensiY, 0, 25},
// Joystick/Gamepad
{"input-joy-x", 0, CVT_INT, &cfg.joyaxis[0], 0, 4},
{"input-joy-y", 0, CVT_INT, &cfg.joyaxis[1], 0, 4},
{"input-joy-z", 0, CVT_INT, &cfg.joyaxis[2], 0, 4},
{"input-joy-rx", 0, CVT_INT, &cfg.joyaxis[3], 0, 4},
{"input-joy-ry", 0, CVT_INT, &cfg.joyaxis[4], 0, 4},
{"input-joy-rz", 0, CVT_INT, &cfg.joyaxis[5], 0, 4},
{"input-joy-slider1", 0, CVT_INT, &cfg.joyaxis[6], 0, 4},
{"input-joy-slider2", 0, CVT_INT, &cfg.joyaxis[7], 0, 4},
// Control (options/preferences)
{"ctl-aim-noauto", 0, CVT_INT, &cfg.noAutoAim, 0, 1},
{"ctl-turn-speed", 0, CVT_FLOAT, &cfg.turnSpeed, 1, 5},
{"ctl-run", 0, CVT_INT, &cfg.alwaysRun, 0, 1},
{"ctl-use-dclick", 0, CVT_INT, &cfg.dclickuse, 0, 1},
#if !__JDOOM__
{"ctl-use-immediate", 0, CVT_INT, &cfg.chooseAndUse, 0, 1},
{"ctl-use-next", 0, CVT_INT, &cfg.inventoryNextOnUnuse, 0, 1},
#endif
{"ctl-look-speed", 0, CVT_FLOAT, &cfg.lookSpeed, 1, 5},
{"ctl-look-spring", 0, CVT_INT, &cfg.lookSpring, 0, 1},
{"ctl-look-mouse", 0, CVT_INT, &cfg.usemlook, 0, 1},
{"ctl-look-mouse-inverse", 0, CVT_INT, &cfg.mlookInverseY, 0, 1},
{"ctl-look-pov", 0, CVT_BYTE, &cfg.povLookAround, 0, 1},
{"ctl-look-joy", 0, CVT_INT, &cfg.usejlook, 0, 1},
{"ctl-look-joy-inverse", 0, CVT_INT, &cfg.jlookInverseY, 0, 1},
{"ctl-look-joy-delta", 0, CVT_INT, &cfg.jlookDeltaMode, 0, 1},
{NULL}
};
// CODE --------------------------------------------------------------------
/*
* Register the CVars and CCmds for input/controls.
*/
void G_ControlRegister(void)
{
int i;
for(i = 0; controlCVars[i].name; i++)
Con_AddVariable(controlCVars + i);
}
/*
* Registers the additional bind classes the game requires
*
* (Doomsday manages the bind class stack which forms the
* dynamic event responder chain).
*/
void G_BindClassRegistration(void)
{
int i;
Con_Message("G_PreInit: Registering Bind Classes...\n");
for(i = 0; BindClasses[i].name; i++)
DD_AddBindClass(BindClasses + i);
}
/*
* Set default bindings for unbound Controls.
*/
void G_DefaultBindings(void)
{
int i;
const Control_t *ctr;
char evname[80], cmd[256], buff[256];
evtype_t evType;
evstate_t evState;
int evData;
// Check all Controls.
for(i = 0; controls[i].command[0]; i++)
{
ctr = controls + i;
// If this command is bound to something, skip it.
sprintf(cmd, "%s%s", ctr->flags & CLF_ACTION ? "+" : "", ctr->command);
memset(buff, 0, sizeof(buff));
if(B_BindingsForCommand(cmd, buff, -1))
continue;
// This Control has no bindings, set it to the default.
sprintf(buff, "\"%s\"", ctr->command);
if(ctr->defKey)
{
evType = EV_KEY;
evState = EVS_DOWN;
evData = ctr->defKey;
B_FormEventString(evname, evType, evState, evData);
sprintf(cmd, "%s bdc%d %s %s",
ctr->flags & CLF_REPEAT ? "safebindr" : "safebind",
controls[i].bindClass, evname + 1, buff);
DD_Execute(cmd, true);
}
if(ctr->defMouse)
{
evType = EV_MOUSE_BUTTON;
evState = EVS_DOWN;
evData = 1 << (ctr->defMouse - 1);
B_FormEventString(evname, evType, evState, evData);
sprintf(cmd, "%s bdc%d %s %s",
ctr->flags & CLF_REPEAT ? "safebindr" : "safebind",
controls[i].bindClass, evname + 1, buff);
DD_Execute(cmd, true);
}
if(ctr->defJoy)
{
evType = EV_JOY_BUTTON;
evState = EVS_DOWN;
evData = 1 << (ctr->defJoy - 1);
B_FormEventString(evname, evType, evState, evData);
sprintf(cmd, "%s bdc%d %s %s",
ctr->flags & CLF_REPEAT ? "safebindr" : "safebind",
controls[i].bindClass, evname + 1, buff);
DD_Execute(cmd, true);
}
}
}
/*
* Offset is in 'angles', where 110 corresponds 85 degrees.
* The delta has higher precision with small offsets.
*/
#if 0
char G_MakeLookDelta(float offset)
{
boolean minus = offset < 0;
offset = sqrt(fabs(offset)) * DELTAMUL;
if(minus)
offset = -offset;
// It's only a char...
if(offset > 127)
offset = 127;
if(offset < -128)
offset = -128;
return (signed char) offset;
}
#endif
/*
* Turn client angle.
*/
static void G_AdjustAngle(player_t *player, int turn, float elapsed)
{
if(!player->plr->mo || player->playerstate == PST_DEAD ||
player->viewlock)
return; // Sorry, can't help you, pal.
/* $unifiedangles */
player->plr->mo->angle += FLT2FIX(cfg.turnSpeed * elapsed * 35.f * turn);
}
static void G_AdjustLookDir(player_t *player, int look, float elapsed)
{
ddplayer_t *ddplr = player->plr;
if(look)
{
if(look == TOCENTER)
{
player->centering = true;
}
else
{
ddplr->lookdir += cfg.lookSpeed * look * elapsed * 35; /* $unifiedangles */
}
}
if(player->centering)
{
float step = 8 * elapsed * 35;
/* $unifiedangles */
if(ddplr->lookdir > step)
{
ddplr->lookdir -= step;
}
else if(ddplr->lookdir < -step)
{
ddplr->lookdir += step;
}
else
{
ddplr->lookdir = 0;
player->centering = false;
}
}
}
/*
* Updates the viewers' look angle.
* Called every tic by G_Ticker.
*/
void G_LookAround(void)
{
if(povangle != -1)
{
targetLookOffset = povangle / 8.0f;
if(targetLookOffset == .5f)
{
if(lookOffset < 0)
targetLookOffset = -.5f;
}
else if(targetLookOffset > .5)
targetLookOffset -= 1;
}
else
targetLookOffset = 0;
if(targetLookOffset != lookOffset && cfg.povLookAround)
{
float diff = (targetLookOffset - lookOffset) / 2;
// Clamp it.
if(diff > .075f)
diff = .075f;
if(diff < -.075f)
diff = -.075f;
lookOffset += diff;
}
}
static void G_SetCmdViewAngles(ticcmd_t *cmd, player_t *pl)
{
if(pl->plr->mo)
{
// These will be sent to the server (or P_MovePlayer).
cmd->angle = pl->plr->mo->angle >> 16; /* $unifiedangles */
}
// Clamp it. 110 corresponds 85 degrees.
/* $unifiedangles */
if(pl->plr->lookdir > 110)
pl->plr->lookdir = 110;
if(pl->plr->lookdir < -110)
pl->plr->lookdir = -110;
cmd->pitch = pl->plr->lookdir / 110 * DDMAXSHORT;
}
/*
* Builds a ticcmd from all of the available inputs.
*/
void G_BuildTiccmd(ticcmd_t *cmd, float elapsedTime)
{
player_t *cplr = &players[consoleplayer];
memset(cmd, 0, sizeof(*cmd));
// During demo playback, all cmds will be blank.
if(Get(DD_PLAYBACK))
return;
G_UpdateCmdControls(cmd, elapsedTime);
G_SetCmdViewAngles(cmd, cplr);
// special buttons
if(sendpause)
{
sendpause = false;
// Clients can't pause anything.
if(!IS_CLIENT)
cmd->pause = true;
}
if(IS_CLIENT)
{
// Clients mirror their local commands.
memcpy(&players[consoleplayer].cmd, cmd, sizeof(*cmd));
}
}
/*
* Combine the source ticcmd with the destination ticcmd. This is
* done when there are multiple ticcmds to execute on a single game
* tick.
*/
void G_MergeTiccmd(ticcmd_t *dest, ticcmd_t *src)
{
dest->forwardMove = src->forwardMove;
dest->sideMove = src->sideMove;
dest->angle = src->angle;
dest->pitch = src->pitch;
dest->fly = src->fly;
if(src->arti)
dest->arti = src->arti;
if(src->changeWeapon)
dest->changeWeapon = src->changeWeapon;
dest->attack |= src->attack;
dest->use |= src->use;
dest->jump |= src->jump;
dest->pause |= src->pause;
}
/*
* Response to in-game control actions (movement, inventory etc).
* Updates the ticcmd with the current control states.
*/
static void G_UpdateCmdControls(ticcmd_t *cmd, float elapsedTime)
{
static boolean mlook_pressed = false;
float elapsedTics = elapsedTime * 35;
boolean pausestate = P_IsPaused();
int i;
boolean strafe = 0;
boolean bstrafe = 0;
int speed = 0;
int turnSpeed = 0, fwdMoveSpeed = 0, sideMoveSpeed = 0;
int forward = 0;
int side = 0;
int turn = 0;
player_t *cplr = &players[consoleplayer];
int joyturn = 0, joystrafe = 0, joyfwd = 0, joylook = 0;
int *axes[5] = { 0, &joyfwd, &joyturn, &joystrafe, &joylook };
int look = 0, lspeed = 0;
int flyheight = 0;
classinfo_t *pClassInfo = PCLASS_INFO(players[consoleplayer].class);
// Check the joystick axes.
for(i = 0; i < 8; i++)
if(axes[cfg.joyaxis[i]])
*axes[cfg.joyaxis[i]] += joymove[i];
strafe = actions[A_STRAFE].on;
speed = actions[A_SPEED].on;
// Walk -> run, run -> walk.
if(cfg.alwaysRun)
speed = !speed;
// Use two stage accelerative turning on the keyboard and joystick.
if(joyturn < -0
|| joyturn > 0
|| actions[A_TURNRIGHT].on || actions[A_TURNLEFT].on)
turnheld += elapsedTics;
else
turnheld = 0;
if(turnheld < SLOWTURNTICS)
turnSpeed = 2; // slow turn
else
turnSpeed = speed;
// Determine the appropriate look speed based on how long the key
// has been held down.
if(actions[A_LOOKDOWN].on || actions[A_LOOKUP].on)
lookheld += elapsedTics;
else
lookheld = 0;
if(lookheld < SLOWTURNTICS)
lspeed = 1;
else
lspeed = 2;
// Return the max speed for the player's class.
// FIXME: the Turbo movement multiplier should happen server-side!
sideMoveSpeed = pClassInfo->sidemove[speed] * turbomul;
fwdMoveSpeed = pClassInfo->forwardmove[speed] * turbomul;
// let movement keys cancel each other out
if(strafe)
{
if(actions[A_TURNRIGHT].on)
side += sideMoveSpeed;
if(actions[A_TURNLEFT].on)
side -= sideMoveSpeed;
// Swap strafing and turning.
i = joystrafe;
joystrafe = joyturn;
joyturn = i;
}
else
{
if(actions[A_TURNRIGHT].on)
turn -= angleturn[turnSpeed];
if(actions[A_TURNLEFT].on)
turn += angleturn[turnSpeed];
}
// Joystick turn.
if(joyturn > 0)
turn -= angleturn[turnSpeed] * JOY(joyturn);
if(joyturn < -0)
turn += angleturn[turnSpeed] * JOY(-joyturn);
// Joystick strafe.
if(joystrafe < -0)
side -= sideMoveSpeed * JOY(-joystrafe);
if(joystrafe > 0)
side += sideMoveSpeed * JOY(joystrafe);
if(joyfwd < -0)
forward += fwdMoveSpeed * JOY(-joyfwd);
if(joyfwd > 0)
forward -= fwdMoveSpeed * JOY(joyfwd);
if(actions[A_FORWARD].on)
forward += fwdMoveSpeed;
if(actions[A_BACKWARD].on)
forward -= fwdMoveSpeed;
if(actions[A_STRAFERIGHT].on)
side += sideMoveSpeed;
if(actions[A_STRAFELEFT].on)
side -= sideMoveSpeed;
// Look up/down/center keys
if(!cfg.lookSpring || (cfg.lookSpring && !forward))
{
if(actions[A_LOOKUP].on)
{
look = lspeed;
}
if(actions[A_LOOKDOWN].on)
{
look = -lspeed;
}
if(actions[A_LOOKCENTER].on)
{
look = TOCENTER;
}
}
// Fly up/down/drop keys
if(actions[A_FLYUP].on)
// note that the actual flyheight will be twice this
flyheight = 5;
if(actions[A_FLYDOWN].on)
flyheight = -5;
if(actions[A_FLYCENTER].on)
{
flyheight = TOCENTER;
#if __JHERETIC__
if(!cfg.usemlook) // only in jHeretic
look = TOCENTER;
#else
look = TOCENTER;
#endif
}
#if __JHERETIC__ || __JHEXEN__ || __JSTRIFE__
// Use artifact key
if(actions[A_USEARTIFACT].on)
{
if(actions[A_SPEED].on && artiskip)
{
if(cplr->inventory[cplr->inv_ptr].type != arti_none)
{
actions[A_USEARTIFACT].on = false;
cmd->arti = 0xff;
}
}
else
{
if(ST_IsInventoryVisible())
{
cplr->readyArtifact = cplr->inventory[cplr->inv_ptr].type;
ST_Inventory(false); // close the inventory
if(cfg.chooseAndUse)
cmd->arti = cplr->inventory[cplr->inv_ptr].type;
else
cmd->arti = 0;
usearti = false;
}
else if(usearti)
{
cmd->arti = cplr->inventory[cplr->inv_ptr].type;
usearti = false;
}
}
}
#endif
//
// Artifact hot keys
//
#if __JHERETIC__
// Check Tome of Power and other artifact hotkeys.
if(actions[A_TOMEOFPOWER].on && !cmd->arti &&
!players[consoleplayer].powers[pw_weaponlevel2])
{
actions[A_TOMEOFPOWER].on = false;
cmd->arti = arti_tomeofpower;
}
for(i = 0; ArtifactHotkeys[i].artifact != arti_none && !cmd->arti; i++)
{
if(actions[ArtifactHotkeys[i].action].on)
{
actions[ArtifactHotkeys[i].action].on = false;
cmd->arti = ArtifactHotkeys[i].artifact;
break;
}
}
#endif
#if __JHEXEN__ || __JSTRIFE__
if(actions[A_PANIC].on && !cmd->arti)
{
actions[A_PANIC].on = false; // Use one of each artifact
cmd->arti = NUMARTIFACTS;
}
else if(players[consoleplayer].plr->mo && actions[A_HEALTH].on &&
!cmd->arti && (players[consoleplayer].plr->mo->health < MAXHEALTH))
{
actions[A_HEALTH].on = false;
cmd->arti = arti_health;
}
else if(actions[A_POISONBAG].on && !cmd->arti)
{
actions[A_POISONBAG].on = false;
cmd->arti = arti_poisonbag;
}
else if(actions[A_BLASTRADIUS].on && !cmd->arti)
{
actions[A_BLASTRADIUS].on = false;
cmd->arti = arti_blastradius;
}
else if(actions[A_TELEPORT].on && !cmd->arti)
{
actions[A_TELEPORT].on = false;
cmd->arti = arti_teleport;
}
else if(actions[A_TELEPORTOTHER].on && !cmd->arti)
{
actions[A_TELEPORTOTHER].on = false;
cmd->arti = arti_teleportother;
}
else if(actions[A_EGG].on && !cmd->arti)
{
actions[A_EGG].on = false;
cmd->arti = arti_egg;
}
else if(actions[A_INVULNERABILITY].on && !cmd->arti &&
!players[consoleplayer].powers[pw_invulnerability])
{
actions[A_INVULNERABILITY].on = false;
cmd->arti = arti_invulnerability;
}
else if(actions[A_MYSTICURN].on && !cmd->arti)
{
actions[A_MYSTICURN].on = false;
cmd->arti = arti_superhealth;
}
else if(actions[A_TORCH].on && !cmd->arti)
{
actions[A_TORCH].on = false;
cmd->arti = arti_torch;
}
else if(actions[A_KRATER].on && !cmd->arti)
{
actions[A_KRATER].on = false;
cmd->arti = arti_boostmana;
}
else if(actions[A_SPEEDBOOTS].on & !cmd->arti)
{
actions[A_SPEEDBOOTS].on = false;
cmd->arti = arti_speed;
}
else if(actions[A_DARKSERVANT].on && !cmd->arti)
{
actions[A_DARKSERVANT].on = false;
cmd->arti = arti_summon;
}
#endif
// Buttons
if(actions[A_FIRE].on)
cmd->attack = true;
if(actions[A_USE].on)
{
cmd->use = true;
// clear double clicks if hit use button
dclicks = 0;
}
if(actions[A_JUMP].on)
cmd->jump = true;
#if __JDOOM__
// Determine whether a weapon change should be done.
if(actions[A_WEAPONCYCLE1].on) // Fist/chainsaw.
{
if(ISWPN(wp_fist) && GOTWPN(wp_chainsaw))
i = wp_chainsaw;
else if(ISWPN(wp_chainsaw))
i = wp_fist;
else if(GOTWPN(wp_chainsaw))
i = wp_chainsaw;
else
i = wp_fist;
cmd->changeWeapon = i + 1;
}
else if(actions[A_WEAPONCYCLE2].on) // Shotgun/super sg.
{
if(ISWPN(wp_shotgun) && GOTWPN(wp_supershotgun) &&
gamemode == commercial)
i = wp_supershotgun;
else if(ISWPN(wp_supershotgun))
i = wp_shotgun;
else if(GOTWPN(wp_supershotgun) && gamemode == commercial)
i = wp_supershotgun;
else
i = wp_shotgun;
cmd->changeWeapon = i + 1;
}
else
#elif __JHERETIC__
// Determine whether a weapon change should be done.
if(actions[A_WEAPONCYCLE1].on) // Staff/Gauntlets.
{
if(ISWPN(WP_FIRST) && GOTWPN(WP_EIGHTH))
i = WP_EIGHTH;
else if(ISWPN(WP_EIGHTH))
i = WP_FIRST;
else if(GOTWPN(WP_EIGHTH))
i = WP_EIGHTH;
else
i = WP_FIRST;
cmd->changeWeapon = i + 1;
}
else
#endif
{
// Take the first weapon action.
for(i = 0; i < NUMWEAPONS; i++)
if(actions[A_WEAPON1 + i].on)
{
cmd->changeWeapon = i + 1;
break;
}
}
if(actions[A_NEXTWEAPON].on || actions[A_PREVIOUSWEAPON].on)
{
cmd->changeWeapon =
(actions[A_NEXTWEAPON].on ? TICCMD_NEXT_WEAPON :
TICCMD_PREV_WEAPON);
}
// forward double click
if(actions[A_FORWARD].on != dclickstate && dclicktime > 1 && cfg.dclickuse)
{
dclickstate = actions[A_FORWARD].on;
if(dclickstate)
dclicks++;
if(dclicks == 2)
{
cmd->use = true;
dclicks = 0;
}
else
dclicktime = 0;
}
else
{
dclicktime++;
if(dclicktime > 20)
{
dclicks = 0;
dclickstate = 0;
}
}
// strafe double click
bstrafe = strafe;
if(bstrafe != dclickstate2 && dclicktime2 > 1 && cfg.dclickuse)
{
dclickstate2 = bstrafe;
if(dclickstate2)
dclicks2++;
if(dclicks2 == 2)
{
cmd->use = true;
dclicks2 = 0;
}
else
dclicktime2 = 0;
}
else
{
dclicktime2++;
if(dclicktime2 > 20)
{
dclicks2 = 0;
dclickstate2 = 0;
}
}
// Mouse strafe and turn (X axis).
if(strafe)
side += mousex * 2;
else if(mousex)
{
// Mouse angle changes are immediate.
if(!pausestate && players[consoleplayer].plr->mo &&
players[consoleplayer].playerstate != PST_DEAD)
{
players[consoleplayer].plr->mo->angle += FLT2FIX(mousex * -8); //G_AdjustAngle(cplr, mousex * -8, 1);
}
}
if(!pausestate)
{
// Speed based turning.
G_AdjustAngle(cplr, turn, elapsedTime);
if(strafe || (!cfg.usemlook && !actions[A_MLOOK].on) ||
players[consoleplayer].playerstate == PST_DEAD)
{
forward += 8 * mousey * elapsedTics;
}
else
{
float adj =
(FLT2FIX(mousey * 8) / (float) ANGLE_180) * 180 *
110.0 / 85.0;
if(cfg.mlookInverseY)
adj = -adj;
cplr->plr->lookdir += adj; /* $unifiedangles */
}
if(cfg.usejlook)
{
if(cfg.jlookDeltaMode) /* $unifiedangles */
cplr->plr->lookdir +=
joylook / 20.0f * cfg.lookSpeed *
(cfg.jlookInverseY ? -1 : 1) * elapsedTics;
else
cplr->plr->lookdir =
joylook * 1.1f * (cfg.jlookInverseY ? -1 : 1);
}
}
G_ResetMousePos();
#define MAXPLMOVE pClassInfo->maxmove
if(forward > MAXPLMOVE)
forward = MAXPLMOVE;
else if(forward < -MAXPLMOVE)
forward = -MAXPLMOVE;
if(side > MAXPLMOVE)
side = MAXPLMOVE;
else if(side < -MAXPLMOVE)
side = -MAXPLMOVE;
#if __JHEXEN__
if(cplr->powers[pw_speed] && !cplr->morphTics)
{
// Adjust for a player with a speed artifact
forward = (3 * forward) >> 1;
side = (3 * side) >> 1;
}
#endif
if(cfg.playerMoveSpeed > 1)
cfg.playerMoveSpeed = 1;
cmd->forwardMove += forward * cfg.playerMoveSpeed;
cmd->sideMove += side * cfg.playerMoveSpeed;;
if(cfg.lookSpring && !actions[A_MLOOK].on &&
(cmd->forwardMove > MAXPLMOVE / 3 || cmd->forwardMove < -MAXPLMOVE / 3
|| cmd->sideMove > MAXPLMOVE / 3 || cmd->sideMove < -MAXPLMOVE / 3 ||
mlook_pressed))
{
// Center view when mlook released w/lookspring, or when moving.
look = TOCENTER;
}
if(players[consoleplayer].playerstate == PST_LIVE && !pausestate)
G_AdjustLookDir(cplr, look, elapsedTime);
cmd->fly = flyheight;
// Store the current mlook key state.
mlook_pressed = actions[A_MLOOK].on;
}
/*
* Called by G_Responder.
* Depending on the type of the event we may wish to eat it before
* it is sent to the engine to check for bindings.
*
* TODO: all controls should be handled by the engine.
* Merge in engine-side axis controls from 1.8 alpha.
*
* @return boolean (True) If the event should be checked for bindings
*/
boolean G_AdjustControlState(event_t* ev)
{
switch (ev->type)
{
case EV_KEY:
return false; // always let key events filter down
case EV_MOUSE_AXIS:
mousex += (float)(ev->data1 * (1 + cfg.mouseSensiX/5.0f)) / DD_MICKEY_ACCURACY;
mousey += (float)(ev->data2 * (1 + cfg.mouseSensiY/5.0f)) / DD_MICKEY_ACCURACY;
return true; // eat events
case EV_MOUSE_BUTTON:
return false; // always let mouse button events filter down
case EV_JOY_AXIS: // Joystick movement
joymove[JA_X] = ev->data1;
joymove[JA_Y] = ev->data2;
joymove[JA_Z] = ev->data3;
joymove[JA_RX] = ev->data4;
joymove[JA_RY] = ev->data5;
joymove[JA_RZ] = ev->data6;
return true; // eat events
case EV_JOY_SLIDER: // Joystick slider movement
joymove[JA_SLIDER0] = ev->data1;
joymove[JA_SLIDER1] = ev->data2;
return true;
case EV_JOY_BUTTON:
return false; // always let joy button events filter down
case EV_POV:
if(!automapactive && !menuactive)
{