/
g_game.c
3334 lines (2959 loc) · 70.5 KB
/
g_game.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
//**************************************************************************
//**
//** G_GAME.C
//**
//** Top-level game routines.
//** Compiles for jDoom, jHeretic and jHexen.
//** Could use some tidying up.
//**
//**************************************************************************
// HEADER FILES ------------------------------------------------------------
#if __JDOOM__
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "doomdef.h"
#include "doomstat.h"
#include "d_action.h"
#include "d_config.h"
#include "m_argv.h"
#include "m_misc.h"
#include "m_menu.h"
#include "m_random.h"
#include "p_local.h"
#include "p_setup.h"
#include "p_saveg.h"
#include "p_tick.h"
#include "d_main.h"
#include "d_netjd.h"
#include "wi_stuff.h"
#include "hu_stuff.h"
#include "st_stuff.h"
#include "am_map.h"
#include "p_local.h"
#include "s_sound.h"
#include "dstrings.h"
#include "g_game.h"
#endif
#if __JHERETIC__
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "DoomDef.h"
#include "P_local.h"
#include "H_Action.h"
#include "soundst.h"
#include "settings.h"
#include "P_Saveg.h"
#endif
#if __JHEXEN__
#include <string.h>
#include <math.h>
#include <assert.h>
#include "h2def.h"
#include "p_local.h"
#include "soundst.h"
#include "Settings.h"
#include "g_demo.h"
#include "h2_actn.h"
#include "d_net.h"
#endif
#include "f_infine.h"
// MACROS ------------------------------------------------------------------
#define LOCKF_FULL 0x10000
#define LOCKF_MASK 0xff
#if __JDOOM__
#define MAXPLMOVE (forwardmove[1])
#define TURBOTHRESHOLD 0x32
#endif
#if __JHERETIC__
#define MAXPLMOVE 0x32
#endif
#define SLOWTURNTICS 6
#define NUMGKEYS 256
#define BODYQUESIZE 32
#define JOY(x) (x /*-cfg.joydead*/) / (100 /*-cfg.joydead*/)
#define NUM_MOUSE_BUTTONS 6
// TYPES -------------------------------------------------------------------
// Joystick axes.
enum
{
JA_X, JA_Y, JA_Z, JA_RX, JA_RY, JA_RZ, JA_SLIDER0, JA_SLIDER1,
NUM_JOYSTICK_AXES
};
#if __JHERETIC__
struct
{
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.
};
struct
{
mobjtype_t type;
int speed[2];
} MonsterMissileInfo[] =
{
{ MT_IMPBALL, 10, 20 },
{ MT_MUMMYFX1, 9, 18 },
{ MT_KNIGHTAXE, 9, 18 },
{ MT_REDAXE, 9, 18 },
{ MT_BEASTBALL, 12, 20 },
{ MT_WIZFX1, 18, 24 },
{ MT_SNAKEPRO_A, 14, 20 },
{ MT_SNAKEPRO_B, 14, 20 },
{ MT_HEADFX1, 13, 20 },
{ MT_HEADFX3, 10, 18 },
{ MT_MNTRFX1, 20, 26 },
{ MT_MNTRFX2, 14, 20 },
{ MT_SRCRFX1, 20, 28 },
{ MT_SOR2FX1, 20, 28 },
{ -1, -1, -1 } // Terminator
};
#endif
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
void P_InitPlayerValues(player_t *p);
void P_RunPlayers();
#if __JHERETIC__
void D_PageTicker(void);
void D_AdvanceDemo(void);
#endif
#if __JHEXEN__
void P_InitSky(int map);
void P_PlayerNextArtifact(player_t *player);
#endif
void HU_UpdatePsprites(void);
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void G_PlayerReborn (int player);
void G_InitNew (skill_t skill, int episode, int map);
void G_DoInitNew(void);
void G_DoReborn (int playernum);
void G_DoLoadLevel(void);
void G_DoNewGame (void);
void G_DoLoadGame (void);
void G_DoPlayDemo (void);
void G_DoCompleted (void);
void G_DoVictory (void);
void G_DoWorldDone (void);
void G_DoSaveGame (void);
#if __JHEXEN__
void G_DoTeleportNewMap(void);
void G_DoSingleReborn(void);
void H2_PageTicker(void);
void H2_AdvanceDemo(void);
#endif
void G_StopDemo(void);
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
#if __JDOOM__
extern char* pagename;
#endif
#if __JHERETIC__
extern boolean inventory;
extern int curpos;
extern int inv_ptr;
extern boolean noartiskip;
extern int curpos;
extern int inv_ptr;
extern int playerkeys;
#endif
#if __JHEXEN__
extern boolean mn_SuicideConsole;
extern boolean inventory;
extern int curpos;
extern int inv_ptr;
extern boolean artiskip;
#endif
// PUBLIC DATA DEFINITIONS -------------------------------------------------
gameaction_t gameaction;
gamestate_t gamestate = GS_DEMOSCREEN;
skill_t gameskill;
int gameepisode;
int gamemap;
#ifndef __JHEXEN__
boolean respawnmonsters;
#endif
#ifndef __JDOOM__
int prevmap;
#endif
boolean paused;
boolean sendpause; // send a pause event next tic
boolean usergame; // ok to save / end game
boolean timingdemo; // if true, exit with report on completion
boolean nodrawers; // for comparative timing purposes
boolean noblit; // for comparative timing purposes
int starttime; // for comparative timing purposes
boolean viewactive;
boolean deathmatch; // only if started as net death
player_t players[MAXPLAYERS];
int levelstarttic; // gametic at level start
int totalkills, totalitems, totalsecret; // for intermission
char defdemoname[32];
boolean singledemo; // quit after playing a demo from cmdline
boolean precache = true; // if true, load all graphics at start
#if __JDOOM__
wbstartstruct_t wminfo; // parms for world map / intermission
jdoom_config_t cfg;
#elif __JHERETIC__
jheretic_config_t cfg;
#elif __JHEXEN__
jhexen_config_t cfg;
//#error "sbarscale and others need to be initialized."
#endif
// Looking around.
int povangle = -1; // -1 means centered (really 0 - 7).
float targetLookOffset=0;
float lookOffset = 0;
fixed_t angleturn[3] = {640, 1280, 320}; // + slow turn
#if __JDOOM__ || __JHERETIC__
fixed_t forwardmove[2] = {0x19, 0x32};
fixed_t sidemove[2] = {0x18, 0x28};
#else
fixed_t MaxPlayerMove[NUMCLASSES] = { 0x3C, 0x32, 0x2D, 0x31 };
fixed_t forwardmove[NUMCLASSES][2] =
{
{ 0x1D, 0x3C },
{ 0x19, 0x32 },
{ 0x16, 0x2E },
{ 0x18, 0x31 }
};
fixed_t sidemove[NUMCLASSES][2] =
{
{ 0x1B, 0x3B },
{ 0x18, 0x28 },
{ 0x15, 0x25 },
{ 0x17, 0x27 }
};
#endif
boolean gamekeydown[NUMGKEYS];
int turnheld; // for accelerative turning
//int do_chimes;
boolean mousearray[NUM_MOUSE_BUTTONS + 1];
boolean* mousebuttons = &mousearray[1]; // allow [-1]
// mouse values are used once
int mousex;
int mousey;
int dclicktime;
int dclickstate;
int dclicks;
int dclicktime2;
int dclickstate2;
int dclicks2;
// joystick values are repeated
int joymove[NUM_JOYSTICK_AXES]; // X, Y, Z, Rx, Ry, Rz, S1, S2
boolean joyarray[33];
boolean* joybuttons = &joyarray[1]; // allow [-1]
int savegameslot;
char savedescription[32];
#if __JDOOM__
mobj_t* bodyque[BODYQUESIZE];
int bodyqueslot;
#endif
#if __JHERETIC__ || __JHEXEN__
int lookheld;
int inventoryTics;
#endif
#if __JHEXEN__
byte demoDisabled = 0; // is demo playing disabled?
// Position indicator for cooperative net-play reborn
int RebornPosition;
int LeaveMap;
int LeavePosition;
#endif
boolean secretexit;
char savename[256];
// PRIVATE DATA DEFINITIONS ------------------------------------------------
boolean usearti = true;
#if __JHEXEN__
static skill_t TempSkill;
static int TempEpisode;
static int TempMap;
static int GameLoadSlot;
#endif
// CODE --------------------------------------------------------------------
#if __JHERETIC__ || __JHEXEN__
static int findWeapon(player_t *plr, boolean forward)
{
int i, c;
for(i=plr->readyweapon + (forward? 1 : -1), c=0;
#if __JHERETIC__
c<NUMWEAPONS-1; c++, forward? i++ : i--)
{
if(i >= NUMWEAPONS-1) i = 0;
if(i < 0) i = NUMWEAPONS-2;
#else
c<NUMWEAPONS; c++, forward? i++ : i--)
{
if(i > NUMWEAPONS-1) i = 0;
if(i < 0) i = NUMWEAPONS-1;
#endif
if(plr->weaponowned[i]) return i;
}
return plr->readyweapon;
}
static boolean inventoryMove(player_t *plr, int dir)
{
inventoryTics = 5*35;
if(!inventory)
{
inventory = true;
return(false);
}
if(dir == 0)
{
inv_ptr--;
if(inv_ptr < 0)
{
inv_ptr = 0;
}
else
{
curpos--;
if(curpos < 0)
{
curpos = 0;
}
}
}
else
{
inv_ptr++;
if(inv_ptr >= plr->inventorySlotNum)
{
inv_ptr--;
if(inv_ptr < 0)
inv_ptr = 0;
}
else
{
curpos++;
if(curpos > 6)
{
curpos = 6;
}
}
}
return(true);
}
int CCmdInventory(int argc, char **argv)
{
inventoryMove(players+consoleplayer, !stricmp(argv[0], "invright"));
return true;
}
#endif
// Offset is in 'angles', where 110 corresponds 85 degrees.
// The delta has higher precision with small offsets.
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;
}
void G_AdjustAngle(player_t *player, int turn)
{
if(!player->plr->mo) return; // Sorry, can't help you, pal.
// Turn around.
if(player->playerstate != PST_DEAD)
player->plr->clAngle += (turn << FRACBITS);
}
void G_AdjustLookDir(player_t *player, int look)
{
ddplayer_t *ddplr = player->plr;
if(look)
{
if(look == TOCENTER)
{
player->centering = true;
}
else
{
int spd = cfg.lookSpeed;
ddplr->clLookDir += spd*look;
}
}
if(player->centering)
{
if(ddplr->clLookDir > 0)
{
ddplr->clLookDir -= 8;
}
else if(ddplr->clLookDir < 0)
{
ddplr->clLookDir += 8;
}
if(abs(ddplr->clLookDir) < 8)
{
ddplr->clLookDir = 0;
player->centering = false;
}
}
}
void G_SetCmdViewAngles(ticcmd_t *cmd, player_t *pl)
{
// These will be sent to the server (or P_MovePlayer).
cmd->angle = pl->plr->clAngle >> 16;
// 110 corresponds 85 degrees.
if(pl->plr->clLookDir > 110) pl->plr->clLookDir = 110;
if(pl->plr->clLookDir < -110) pl->plr->clLookDir = -110;
cmd->lookdir = pl->plr->clLookDir/110 * DDMAXSHORT;
}
//
// G_BuildTiccmd
// Builds a ticcmd from all of the available inputs
// or reads it from the demo buffer.
// If recording a demo, write it out
//
void G_BuildTiccmd (ticcmd_t* cmd)
{
static boolean mlook_pressed = false;
#if __JDOOM__
boolean pausestate = paused || (!IS_NETGAME && menuactive);
#endif
int i;
boolean strafe;
boolean bstrafe;
int speed;
int tspeed;
int forward;
int side;
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 };
#if __JHERETIC__ || __JHEXEN__
int flyheight, look, arti, lspeed;
#endif
#if __JHEXEN__
int pClass = players[consoleplayer].class;
#endif
memset(cmd, 0, sizeof(*cmd));
// During demo playback, all cmds will be blank.
if(Get(DD_PLAYBACK)) return;
// 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;
#if __JDOOM__
forward = side = 0;
#else
forward = side = look = arti = flyheight = 0;
#endif
// Walk -> run, run -> walk.
if(cfg.alwaysRun) speed = !speed;
// Use two stage accelerative turning on the keyboard and joystick.
if(joyturn < -0 /*cfg.joydead*/
|| joyturn > 0 /*cfg.joydead*/
|| actions[A_TURNRIGHT].on
|| actions[A_TURNLEFT].on)
turnheld++;
else
turnheld = 0;
if(turnheld < SLOWTURNTICS)
tspeed = 2; // slow turn
else
tspeed = speed;
#if __JHERETIC__ || __JHEXEN__
if(actions[A_LOOKDOWN].on || actions[A_LOOKUP].on)
{
lookheld++;
}
else
{
lookheld = 0;
}
if(lookheld < SLOWTURNTICS)
{
lspeed = 1;
}
else
{
lspeed = 2;
}
#endif
// let movement keys cancel each other out
if(strafe)
{
#if __JDOOM__ || __JHERETIC__
if(actions[A_TURNRIGHT].on) side += sidemove[speed];
if(actions[A_TURNLEFT].on) side -= sidemove[speed];
#else
if(actions[A_TURNRIGHT].on) side += sidemove[pClass][speed];
if(actions[A_TURNLEFT].on) side -= sidemove[pClass][speed];
#endif
// Swap strafing and turning.
i = joystrafe;
joystrafe = joyturn;
joyturn = i;
}
else
{
if(actions[A_TURNRIGHT].on) turn -= angleturn[tspeed];
if(actions[A_TURNLEFT].on) turn += angleturn[tspeed];
}
// Joystick turn.
if (joyturn > 0 /*cfg.joydead*/)
turn -= angleturn[tspeed] * JOY(joyturn);
if (joyturn < -0 /*cfg.joydead*/)
turn += angleturn[tspeed] * JOY(-joyturn);
// Joystick strafe.
#ifndef __JHEXEN__
if(joystrafe < -0 /*cfg.joydead*/)
side -= sidemove[speed] * JOY(-joystrafe);
if(joystrafe > 0 /*cfg.joydead*/)
side += sidemove[speed] * JOY(joystrafe);
#else
if(joystrafe < -0 /*cfg.joydead*/)
side -= sidemove[pClass][speed] * JOY(-joystrafe);
if(joystrafe > 0 /*cfg.joydead*/)
side += sidemove[pClass][speed] * JOY(joystrafe);
#endif
if(actions[A_FORWARD].on)
{
#if __JHEXEN__
forward += forwardmove[pClass][speed];
#else
forward += forwardmove[speed];
#endif
}
if(actions[A_BACKWARD].on)
{
#if __JHEXEN__
forward -= forwardmove[pClass][speed];
#else
forward -= forwardmove[speed];
#endif
}
#ifndef __JHEXEN__
if(joyfwd < -0 /*cfg.joydead*/)
forward += forwardmove[speed] * JOY(-joyfwd);
if(joyfwd > 0 /*cfg.joydead*/)
forward -= forwardmove[speed] * JOY(joyfwd);
#else
if(joyfwd < -0 /*cfg.joydead*/)
forward += forwardmove[pClass][speed] * JOY(-joyfwd);
if(joyfwd > 0 /*cfg.joydead*/)
forward -= forwardmove[pClass][speed] * JOY(joyfwd);
#endif
#ifndef __JHEXEN__
if(actions[A_STRAFERIGHT].on) side += sidemove[speed];
if(actions[A_STRAFELEFT].on) side -= sidemove[speed];
if(joystrafe < -0 /*cfg.joydead*/)
side -= sidemove[speed] * JOY(-joystrafe);
if(joystrafe > 0 /*cfg.joydead*/)
side += sidemove[speed] * JOY(joystrafe);
#else
if(actions[A_STRAFERIGHT].on) side += sidemove[pClass][speed];
if(actions[A_STRAFELEFT].on) side -= sidemove[pClass][speed];
if(joystrafe < -0 /*cfg.joydead*/)
side -= sidemove[pClass][speed] * JOY(-joystrafe);
if(joystrafe > 0 /*cfg.joydead*/)
side += sidemove[pClass][speed] * JOY(joystrafe);
#endif
#if __JHERETIC__
// 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)
{
flyheight = 5; // note that the actual flyheight will be twice this
}
if(actions[A_FLYDOWN].on)
{
flyheight = -5;
}
if(actions[A_FLYCENTER].on)
{
flyheight = TOCENTER;
if(!cfg.usemlook) look = TOCENTER;
}
// Use artifact key
if(actions[A_USEARTIFACT].on)
{
if(actions[A_SPEED].on && !noartiskip)
{
if(players[consoleplayer].inventory[inv_ptr].type != arti_none)
{
actions[A_USEARTIFACT].on = false;
cmd->arti = 0xff; // skip artifact code
}
}
else
{
if(inventory)
{
players[consoleplayer].readyArtifact =
players[consoleplayer].inventory[inv_ptr].type;
inventory = false;
cmd->arti = cfg.chooseAndUse? players[consoleplayer].inventory[inv_ptr].type : 0;
usearti = false;
}
else if(usearti)
{
cmd->arti = players[consoleplayer].inventory[inv_ptr].type;
usearti = false;
}
}
}
// 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__
// 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)
{
flyheight = 5; // note that the actual flyheight will be twice this
}
if(actions[A_FLYDOWN].on)
{
flyheight = -5;
}
if(actions[A_FLYCENTER].on)
{
flyheight = TOCENTER;
look = TOCENTER;
}
// Use artifact key
if(actions[A_USEARTIFACT].on)
{
if(speed && artiskip)
{
if(players[consoleplayer].inventory[inv_ptr].type != arti_none)
{ // Skip an artifact
actions[A_USEARTIFACT].on = false;
P_PlayerNextArtifact(&players[consoleplayer]);
}
}
else
{
if(inventory)
{
players[consoleplayer].readyArtifact =
players[consoleplayer].inventory[inv_ptr].type;
inventory = false;
if(cfg.chooseAndUse)
cmd->arti |= players[consoleplayer].inventory[inv_ptr].type&AFLAG_MASK;
else
cmd->arti = 0;
}
else if(usearti)
{
cmd->arti |=
players[consoleplayer].inventory[inv_ptr].type&AFLAG_MASK;
}
}
actions[A_USEARTIFACT].on = false;
}
if(actions[A_JUMP].on)
{
cmd->arti |= AFLAG_JUMP;
}
if(mn_SuicideConsole)
{
cmd->arti |= AFLAG_SUICIDE;
mn_SuicideConsole = false;
}
// Artifact hot keys
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->buttons |= BT_ATTACK;
if(actions[A_USE].on)
{
cmd->buttons |= BT_USE;
// clear double clicks if hit use button
dclicks = 0;
}
#if __JDOOM__
if(actions[A_JUMP].on) cmd->buttons |= BT_JUMP;
#elif __JHERETIC__
if(actions[A_JUMP].on) cmd->arti |= AFLAG_JUMP;
#endif
#if __JDOOM__
#define GOTWPN(x) (cplr->weaponowned[x])
#define ISWPN(x) (cplr->readyweapon == x)
// 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->buttons &= ~BT_JUMP;
cmd->buttons |= BT_CHANGE;
cmd->buttons |= i << BT_WEAPONSHIFT;
}
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->buttons &= ~BT_JUMP;
cmd->buttons |= BT_CHANGE;
cmd->buttons |= i << BT_WEAPONSHIFT;
}
else
{
// Take the first weapon action.
for(i = 0; i < NUMWEAPONS; i++)
if(actions[A_WEAPON1+i].on)
{
cmd->buttons &= ~BT_JUMP;
cmd->buttons |= BT_CHANGE;
cmd->buttons |= i << BT_WEAPONSHIFT;
break;
}
}
if(actions[A_NEXTWEAPON].on || actions[A_PREVIOUSWEAPON].on)
{
cmd->buttons = BT_SPECIAL
| (actions[A_NEXTWEAPON].on? BTS_NEXTWEAPON : BTS_PREVWEAPON);
}
#else
if(actions[A_PREVIOUSWEAPON].on)
{
cmd->buttons |= BT_CHANGE | (findWeapon(players+consoleplayer,
false) << BT_WEAPONSHIFT);
}
else if(actions[A_NEXTWEAPON].on)
{
cmd->buttons |= BT_CHANGE | (findWeapon(players+consoleplayer,
true) << BT_WEAPONSHIFT);
}
#if __JHERETIC__
else for(i = 0; i < NUMWEAPONS-2; i++)
#else
else for(i = 0; i < NUMWEAPONS; i++)
#endif
{
if(actions[A_WEAPON1+i].on)
{
cmd->buttons |= BT_CHANGE;
cmd->buttons |= i<<BT_WEAPONSHIFT;
break;
}
}
#endif
// 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->buttons |= BT_USE;
dclicks = 0;
}
else
dclicktime = 0;
}
else
{
dclicktime++;