-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathg_game.c
2330 lines (1951 loc) · 61.2 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 : game loop functions, events handling
#include "doomdef.h"
#include "command.h"
#include "console.h"
#include "dstrings.h"
#include "d_main.h"
#include "d_net.h"
#include "d_netcmd.h"
#include "f_finale.h"
#include "p_setup.h"
#include "p_saveg.h"
#include "i_system.h"
#include "wi_stuff.h"
#include "am_map.h"
#include "m_random.h"
#include "p_local.h"
#include "p_tick.h"
// SKY handling - still the wrong place.
#include "r_data.h"
#include "r_draw.h"
#include "r_main.h"
#include "r_sky.h"
#include "s_sound.h"
#include "g_game.h"
#include "g_state.h"
#include "g_input.h"
//added:16-01-98:quick hack test of rocket trails
#include "p_fab.h"
#include "m_cheat.h"
#include "m_misc.h"
#include "m_menu.h"
#include "m_argv.h"
#include "hu_stuff.h"
#include "st_stuff.h"
#include "keys.h"
#include "w_wad.h"
#include "z_zone.h"
#include "i_video.h"
#include "p_inter.h"
#include "byteptr.h"
#include "i_joy.h"
// added 8-3-98 increse savegame size from 0x2c000 to 512*1024
#define SAVEGAMESIZE (512*1024)
#define SAVESTRINGSIZE 24
boolean G_Downgrade(int version);
boolean G_CheckDemoStatus (void);
void G_ReadDemoTiccmd (ticcmd_t* cmd,int playernum);
void G_WriteDemoTiccmd (ticcmd_t* cmd,int playernum);
void G_InitNew (skill_t skill, char* mapname);
void G_DoLoadLevel (void);
void G_DoPlayDemo (void);
void G_DoCompleted (void);
void G_DoVictory (void);
void G_DoWorldDone (void);
// demoversion the 'dynamic' version number, this should be == game VERSION
// when playing back demos, 'demoversion' receives the version number of the
// demo. At each change to the game play, demoversion is compared to
// the game version, if it's older, the changes are not done, and the older
// code is used for compatibility.
//
byte demoversion=VERSION;
//boolean respawnmonsters;
byte gameepisode;
byte gamemap;
char gamemapname[MAX_WADPATH]; // an external wad filename
gamemode_t gamemode = indetermined; // Game Mode - identify IWAD as shareware, retail etc.
gamemission_t gamemission = doom;
language_t language = english; // Language.
boolean modifiedgame; // Set if homebrew PWAD stuff has been added.
boolean paused;
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
ULONG starttime; // for comparative timing purposes
boolean viewactive;
boolean netgame; // only true if packets are broadcast
boolean multiplayer;
boolean playeringame[MAXPLAYERS];
player_t players[MAXPLAYERS];
byte consoleplayer; // player taking events and displaying
byte displayplayer; // view being displayed
byte secondarydisplayplayer; // for splitscreen
byte statusbarplayer; // player who's statusbar is displayed
// (for spying with F12)
ULONG gametic;
ULONG levelstarttic; // gametic at level start
int totalkills, totalitems, totalsecret; // for intermission
char demoname[32];
boolean demorecording;
boolean demoplayback;
byte* demobuffer;
byte* demo_p;
byte* demoend;
boolean singledemo; // quit after playing a demo from cmdline
boolean precache = true; // if true, load all graphics at start
wbstartstruct_t wminfo; // parms for world map / intermission
byte* savebuffer;
void ShowMessage_OnChange(void);
CV_PossibleValue_t showmessages_cons_t[]={{0,"Off"},{1,"On"},{2,"Not All"},{0,NULL}};
CV_PossibleValue_t crosshair_cons_t[] ={{0,"Off"},{1,"Cross"},{2,"Angle"},{3,"Point"},{0,NULL}};
consvar_t cv_crosshair = {"crosshair" ,"0",CV_SAVE,crosshair_cons_t};
consvar_t cv_autorun = {"autorun" ,"0",CV_SAVE,CV_OnOff};
consvar_t cv_invertmouse = {"invertmouse" ,"0",CV_SAVE,CV_OnOff};
consvar_t cv_alwaysfreelook = {"alwaysmlook" ,"0",CV_SAVE,CV_OnOff};
consvar_t cv_showmessages = {"showmessages","1",CV_SAVE | CV_CALL | CV_NOINIT,showmessages_cons_t,ShowMessage_OnChange};
#if MAXPLAYERS>32
#error please update "player_name" table using the new value for MAXPLAYERS
#endif
#if MAXPLAYERNAME!=21
#error please update "player_name" table using the new value for MAXPLAYERNAME
#endif
// changed to 2d array 19990220 by Kin
char player_names[MAXPLAYERS][MAXPLAYERNAME] =
{
// THESE SHOULD BE AT LEAST MAXPLAYERNAME CHARS
"Player 1\0a123456789a\0",
"Player 2\0a123456789a\0",
"Player 3\0a123456789a\0",
"Player 4\0a123456789a\0",
"Player 5\0a123456789a\0", // added 14-1-98 for support 8 players
"Player 6\0a123456789a\0", // added 14-1-98 for support 8 players
"Player 7\0a123456789a\0", // added 14-1-98 for support 8 players
"Player 8\0a123456789a\0", // added 14-1-98 for support 8 players
"Player 9\0a123456789a\0",
"Player 10\0a123456789\0",
"Player 11\0a123456789\0",
"Player 12\0a123456789\0",
"Player 13\0a123456789\0",
"Player 14\0a123456789\0",
"Player 15\0a123456789\0",
"Player 16\0a123456789\0",
"Player 17\0a123456789\0",
"Player 18\0a123456789\0",
"Player 19\0a123456789\0",
"Player 20\0a123456789\0",
"Player 21\0a123456789\0",
"Player 22\0a123456789\0",
"Player 23\0a123456789\0",
"Player 24\0a123456789\0",
"Player 25\0a123456789\0",
"Player 26\0a123456789\0",
"Player 27\0a123456789\0",
"Player 28\0a123456789\0",
"Player 29\0a123456789\0",
"Player 30\0a123456789\0",
"Player 31\0a123456789\0",
"Player 32\0a123456789\0"
};
char *team_names[MAXPLAYERS] =
{
"Team 1\0a123456789bc\0",
"Team 2\0a123456789bc\0",
"Team 3\0a123456789bc\0",
"Team 4\0a123456789bc\0",
"Team 5\0a123456789bc\0",
"Team 6\0a123456789bc\0",
"Team 7\0a123456789bc\0",
"Team 8\0a123456789bc\0",
"Team 9\0a123456789bc\0",
"Team 10\0a123456789bc\0",
"Team 11\0a123456789bc\0",
"Team 12\0a123456789bc\0", // the other name hare not used because no colors
"Team 13\0a123456789bc\0", // but who know ?
"Team 14\0a123456789bc\0",
"Team 15\0a123456789bc\0",
"Team 16\0a123456789bc\0",
"Team 17\0a123456789bc\0",
"Team 18\0a123456789bc\0",
"Team 19\0a123456789bc\0",
"Team 20\0a123456789bc\0",
"Team 21\0a123456789bc\0",
"Team 22\0a123456789bc\0",
"Team 23\0a123456789bc\0",
"Team 24\0a123456789bc\0",
"Team 25\0a123456789bc\0",
"Team 26\0a123456789bc\0",
"Team 27\0a123456789bc\0",
"Team 28\0a123456789bc\0",
"Team 29\0a123456789bc\0",
"Team 30\0a123456789bc\0",
"Team 31\0a123456789bc\0",
"Team 32\0a123456789bc\0"
};
#define BODYQUESIZE 32
mobj_t* bodyque[BODYQUESIZE];
int bodyqueslot;
void* statcopy; // for statistics driver
void ShowMessage_OnChange(void)
{
if (!cv_showmessages.value)
CONS_Printf(MSGOFF);
else
CONS_Printf(MSGON);
}
//added:16-02-98: unused ?
//int G_CmdChecksum (ticcmd_t* cmd)
//{
// unsigned int i;
// int sum = 0;
//
// for (i=0 ; i< sizeof(*cmd)/4 - 1 ; i++)
// sum += ((int *)cmd)[i];
//
// return sum;
//}
// Build an original game map name from episode and map number,
// based on the game mode (doom1, doom2...)
//
char* G_BuildMapName (int episode, int map)
{
static char mapname[9]; // internal map name (wad resource name)
if (gamemode==commercial)
strcpy (mapname, va("MAP%#02d",map));
else
{
mapname[0] = 'E';
mapname[1] = '0' + episode;
mapname[2] = 'M';
mapname[3] = '0' + map;
mapname[4] = 0;
}
return mapname;
}
//
// Clip the console player mouse aiming to the current view,
// also returns a signed char for the player ticcmd if needed.
// Used whenever the player view pitch is changed manually
//
//added:22-02-98:
//changed:3-3-98: do a angle limitation now
short G_ClipAimingPitch (int* aiming)
{
int limitangle;
//note: the current software mode implementation doesn't have true perspective
if ( rendermode == render_soft )
limitangle = 732<<ANGLETOFINESHIFT;
else
limitangle = ANG90 - 1;
if (*aiming > limitangle )
*aiming = limitangle;
else
if (*aiming < -limitangle)
*aiming = -limitangle;
return (*aiming)>>16;
}
//
// 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
//
// set secondaryplayer true to build player 2's ticcmd in splitscreen mode
//
int localaiming,localaiming2;
angle_t localangle,localangle2;
//added:06-02-98: mouseaiming (looking up/down with the mouse or keyboard)
#define KB_LOOKSPEED (1<<25)
#define MAXPLMOVE (forwardmove[1])
#define TURBOTHRESHOLD 0x32
#define SLOWTURNTICS 6
fixed_t forwardmove[2] = {25, 50};
fixed_t sidemove[2] = {24, 40};
fixed_t angleturn[3] = {640, 1280, 320}; // + slow turn
// for change this table change also nextweapon func and P_PlayerThink
char extraweapons[8]={wp_chainsaw,-1,wp_supershotgun,-1,-1,-1,-1,-1};
byte nextweaponorder[NUMWEAPONS]={wp_fist,wp_chainsaw,wp_pistol,
wp_shotgun,wp_supershotgun,wp_chaingun,wp_missile,wp_plasma,wp_bfg};
byte NextWeapon(player_t *player,int step)
{
byte w;
int i;
for (i=0;i<NUMWEAPONS;i++)
if( player->readyweapon == nextweaponorder[i] )
{
i = (i+NUMWEAPONS+step)%NUMWEAPONS;
break;
}
for (;nextweaponorder[i]!=player->readyweapon; i=(i+NUMWEAPONS+step)%NUMWEAPONS)
{
w = nextweaponorder[i];
// skip super shotgun for non-Doom2
if (gamemode!=commercial && w==wp_supershotgun)
continue;
if ( player->weaponowned[w] &&
player->ammo[weaponinfo[w].ammo] >= ammopershoot[w] )
{
if(w==wp_chainsaw)
return (BT_CHANGE | BT_EXTRAWEAPON | (wp_fist<<BT_WEAPONSHIFT));
if(w==wp_supershotgun)
return (BT_CHANGE | BT_EXTRAWEAPON | (wp_shotgun<<BT_WEAPONSHIFT));
return (BT_CHANGE | (w<<BT_WEAPONSHIFT));
}
}
return 0;
}
void G_BuildTiccmd (ticcmd_t* cmd, int realtics)
{
int i;
boolean strafe;
int speed;
int tspeed;
int forward;
int side;
ticcmd_t* base;
//added:14-02-98: these ones used for multiple conditions
boolean turnleft,turnright,mouseaiming;
static int turnheld; // for accelerative turning
static boolean keyboard_look; // true if lookup/down using keyboard
base = I_BaseTiccmd (); // empty, or external driver
memcpy (cmd,base,sizeof(*cmd));
// a little clumsy, but then the g_input.c became a lot simpler!
strafe = gamekeydown[gamecontrol[gc_strafe][0]] ||
gamekeydown[gamecontrol[gc_strafe][1]];
speed = gamekeydown[gamecontrol[gc_speed][0]] ||
gamekeydown[gamecontrol[gc_speed][1]] ||
cv_autorun.value;
turnright = gamekeydown[gamecontrol[gc_turnright][0]]
||gamekeydown[gamecontrol[gc_turnright][1]];
turnleft = gamekeydown[gamecontrol[gc_turnleft][0]]
||gamekeydown[gamecontrol[gc_turnleft][1]];
mouseaiming = gamekeydown[gamecontrol[gc_mouseaiming][0]]
||gamekeydown[gamecontrol[gc_mouseaiming][1]]
|| cv_alwaysfreelook.value;
if( !cv_splitscreen.value && Joystick.bGamepadStyle)
{
turnright = turnright || joyxmove > 0;
turnleft = turnleft || joyxmove < 0;
}
forward = side = 0;
// use two stage accelerative turning
// on the keyboard and joystick
if (turnleft || turnright)
turnheld += realtics;
else
turnheld = 0;
if (turnheld < SLOWTURNTICS)
tspeed = 2; // slow turn
else
tspeed = speed;
// let movement keys cancel each other out
if (strafe)
{
if (turnright)
side += sidemove[speed];
if (turnleft)
side -= sidemove[speed];
if (!Joystick.bGamepadStyle && !cv_splitscreen.value)
{
//faB: JOYAXISRANGE is supposed to be 1023 ( divide by 1024 )
side += ( (joyxmove * sidemove[1]) >> 10 );
}
}
else
{
if ( turnright )
cmd->angleturn -= angleturn[tspeed];
else
if ( turnleft )
cmd->angleturn += angleturn[tspeed];
if ( joyxmove && !Joystick.bGamepadStyle && !cv_splitscreen.value) {
//faB: JOYAXISRANGE should be 1023 ( divide by 1024 )
cmd->angleturn -= ( (joyxmove * angleturn[1]) >> 10 ); // ANALOG!
//CONS_Printf ("joyxmove %d angleturn %d\n", joyxmove, cmd->angleturn);
}
}
//added:07-02-98: forward with key or button
if (gamekeydown[gamecontrol[gc_forward][0]] ||
gamekeydown[gamecontrol[gc_forward][1]] ||
( joyymove < 0 && Joystick.bGamepadStyle && !cv_splitscreen.value) )
{
forward += forwardmove[speed];
}
if (gamekeydown[gamecontrol[gc_backward][0]] ||
gamekeydown[gamecontrol[gc_backward][1]] ||
( joyymove > 0 && Joystick.bGamepadStyle && !cv_splitscreen.value) )
{
forward -= forwardmove[speed];
}
if ( joyymove && !Joystick.bGamepadStyle && !cv_splitscreen.value) {
forward -= ( (joyymove * forwardmove[1]) >> 10 ); // ANALOG!
}
//added:07-02-98: some people strafe left & right with mouse buttons
if (gamekeydown[gamecontrol[gc_straferight][0]] ||
gamekeydown[gamecontrol[gc_straferight][1]])
side += sidemove[speed];
if (gamekeydown[gamecontrol[gc_strafeleft][0]] ||
gamekeydown[gamecontrol[gc_strafeleft][1]])
side -= sidemove[speed];
//added:07-02-98: fire with any button/key
if (gamekeydown[gamecontrol[gc_fire][0]] ||
gamekeydown[gamecontrol[gc_fire][1]])
cmd->buttons |= BT_ATTACK;
//added:07-02-98: use with any button/key
if (gamekeydown[gamecontrol[gc_use][0]] ||
gamekeydown[gamecontrol[gc_use][1]])
cmd->buttons |= BT_USE;
//added:22-02-98: jump button
if (cv_allowjump.value && (gamekeydown[gamecontrol[gc_jump][0]] ||
gamekeydown[gamecontrol[gc_jump][1]]))
cmd->buttons |= BT_JUMP;
//added:07-02-98: any key / button can trigger a weapon
// chainsaw overrides
if (gamekeydown[gamecontrol[gc_nextweapon][0]] ||
gamekeydown[gamecontrol[gc_nextweapon][1]])
cmd->buttons |= NextWeapon(&players[consoleplayer],1);
else
if (gamekeydown[gamecontrol[gc_prevweapon][0]] ||
gamekeydown[gamecontrol[gc_prevweapon][1]])
cmd->buttons |= NextWeapon(&players[consoleplayer],-1);
else
for (i=gc_weapon1; i<gc_weapon1+NUMWEAPONS-1; i++)
if (gamekeydown[gamecontrol[i][0]] ||
gamekeydown[gamecontrol[i][1]])
{
cmd->buttons |= BT_CHANGE | BT_EXTRAWEAPON; // extra by default
cmd->buttons |= (i-gc_weapon1)<<BT_WEAPONSHIFT;
// already have extraweapon in hand switch to the normal one
if( players[consoleplayer].readyweapon==extraweapons[i-gc_weapon1] )
cmd->buttons &= ~BT_EXTRAWEAPON;
break;
}
// mouse look stuff (mouse look is not the same as mouse aim)
if (mouseaiming)
{
keyboard_look = false;
// looking up/down
if (cv_invertmouse.value)
localaiming -= mlooky<<19;
else
localaiming += mlooky<<19;
}
else
// spring back if not using keyboard neither mouselookin'
if (!keyboard_look )
localaiming = 0;
if (gamekeydown[gamecontrol[gc_lookup][0]] ||
gamekeydown[gamecontrol[gc_lookup][1]])
{
localaiming += KB_LOOKSPEED;
keyboard_look = true;
}
else
if (gamekeydown[gamecontrol[gc_lookdown][0]] ||
gamekeydown[gamecontrol[gc_lookdown][1]])
{
localaiming -= KB_LOOKSPEED;
keyboard_look = true;
}
else
if (gamekeydown[gamecontrol[gc_centerview][0]] ||
gamekeydown[gamecontrol[gc_centerview][1]])
localaiming = 0;
cmd->aiming = G_ClipAimingPitch (&localaiming);
if (!mouseaiming)
forward += mousey;
if (strafe)
side += mousex*2;
else
cmd->angleturn -= mousex*0x8;
mousex = mousey = mlooky = 0;
if (forward > MAXPLMOVE)
forward = MAXPLMOVE;
else if (forward < -MAXPLMOVE)
forward = -MAXPLMOVE;
if (side > MAXPLMOVE)
side = MAXPLMOVE;
else if (side < -MAXPLMOVE)
side = -MAXPLMOVE;
cmd->forwardmove += forward;
cmd->sidemove += side;
#ifdef ABSOLUTEANGLE
localangle += (cmd->angleturn<<16);
cmd->angleturn = localangle >> 16;
// localaiming = cmd->aiming;
#endif
}
// like the g_buildticcmd 1 but lite version witout mouse...
void G_BuildTiccmd2 (ticcmd_t* cmd, int realtics)
{
int i;
boolean strafe;
int speed;
int tspeed;
int forward;
int side;
ticcmd_t* base;
//added:14-02-98: these ones used for multiple conditions
boolean turnleft,turnright;
static int turnheld; // for accelerative turning
base = I_BaseTiccmd (); // empty, or external driver
memcpy (cmd,base,sizeof(*cmd));
// a little clumsy, but then the g_input.c became a lot simpler!
strafe = gamekeydown[gamecontrolbis[gc_strafe][0]] ||
gamekeydown[gamecontrolbis[gc_strafe][1]];
speed = gamekeydown[gamecontrolbis[gc_speed][0]] ||
gamekeydown[gamecontrolbis[gc_speed][1]] ||
cv_autorun.value;
turnright = gamekeydown[gamecontrolbis[gc_turnright][0]]
||gamekeydown[gamecontrolbis[gc_turnright][1]];
turnleft = gamekeydown[gamecontrolbis[gc_turnleft][0]]
||gamekeydown[gamecontrolbis[gc_turnleft][1]];
if(Joystick.bGamepadStyle)
{
turnright = turnright || joyxmove > 0;
turnleft = turnleft || joyxmove < 0;
}
forward = side = 0;
// use two stage accelerative turning
// on the keyboard and joystick
if (turnleft || turnright)
turnheld += realtics;
else
turnheld = 0;
if (turnheld < SLOWTURNTICS)
tspeed = 2; // slow turn
else
tspeed = speed;
// let movement keys cancel each other out
if (strafe)
{
if (turnright)
side += sidemove[speed];
if (turnleft)
side -= sidemove[speed];
if (!Joystick.bGamepadStyle)
{
//faB: JOYAXISRANGE is supposed to be 1023 ( divide by 1024 )
side += ( (joyxmove * sidemove[1]) >> 10 );
}
}
else
{
if (turnright )
cmd->angleturn -= angleturn[tspeed];
if (turnleft )
cmd->angleturn += angleturn[tspeed];
if ( joyxmove && !Joystick.bGamepadStyle )
{
//faB: JOYAXISRANGE should be 1023 ( divide by 1024 )
cmd->angleturn -= ( (joyxmove * angleturn[1]) >> 10 ); // ANALOG!
//CONS_Printf ("joyxmove %d angleturn %d\n", joyxmove, cmd->angleturn);
}
}
//added:07-02-98: forward with key or button
if (gamekeydown[gamecontrolbis[gc_forward][0]] ||
gamekeydown[gamecontrolbis[gc_forward][1]] ||
(joyymove < 0 && Joystick.bGamepadStyle))
{
forward += forwardmove[speed];
}
if (gamekeydown[gamecontrolbis[gc_backward][0]] ||
gamekeydown[gamecontrolbis[gc_backward][1]] ||
(joyymove > 0 && Joystick.bGamepadStyle))
{
forward -= forwardmove[speed];
}
if ( joyymove && !Joystick.bGamepadStyle ) {
forward -= ( (joyymove * forwardmove[1]) >> 10 ); // ANALOG!
}
//added:07-02-98: some people strafe left & right with mouse buttons
if (gamekeydown[gamecontrolbis[gc_straferight][0]] ||
gamekeydown[gamecontrolbis[gc_straferight][1]])
side += sidemove[speed];
if (gamekeydown[gamecontrolbis[gc_strafeleft][0]] ||
gamekeydown[gamecontrolbis[gc_strafeleft][1]])
side -= sidemove[speed];
// buttons
// cmd->chatchar = HU_dequeueChatChar();
//added:07-02-98: fire with any button/key
if (gamekeydown[gamecontrolbis[gc_fire][0]] ||
gamekeydown[gamecontrolbis[gc_fire][1]])
cmd->buttons |= BT_ATTACK;
//added:07-02-98: use with any button/key
if (gamekeydown[gamecontrolbis[gc_use][0]] ||
gamekeydown[gamecontrolbis[gc_use][1]])
cmd->buttons |= BT_USE;
//added:22-02-98: jump button
if (cv_allowjump.value && (gamekeydown[gamecontrolbis[gc_jump][0]] ||
gamekeydown[gamecontrolbis[gc_jump][1]]))
cmd->buttons |= BT_JUMP;
//added:07-02-98: any key / button can trigger a weapon
// chainsaw overrides
if (gamekeydown[gamecontrolbis[gc_nextweapon][0]] ||
gamekeydown[gamecontrolbis[gc_nextweapon][1]])
cmd->buttons |= NextWeapon(&players[secondarydisplayplayer],1);
else
if (gamekeydown[gamecontrolbis[gc_prevweapon][0]] ||
gamekeydown[gamecontrolbis[gc_prevweapon][1]])
cmd->buttons |= NextWeapon(&players[secondarydisplayplayer],-1);
else
for (i=gc_weapon1; i<gc_weapon1+NUMWEAPONS-1; i++)
if (gamekeydown[gamecontrolbis[i][0]] ||
gamekeydown[gamecontrolbis[i][1]])
{
cmd->buttons |= BT_CHANGE | BT_EXTRAWEAPON; // extra by default
cmd->buttons |= (i-gc_weapon1)<<BT_WEAPONSHIFT;
// already have extraweapon in hand switch to the normal one
if( players[secondarydisplayplayer].readyweapon==extraweapons[i-gc_weapon1] )
cmd->buttons &= ~BT_EXTRAWEAPON;
break;
}
if (gamekeydown[gamecontrolbis[gc_lookup][0]] ||
gamekeydown[gamecontrolbis[gc_lookup][1]])
{
localaiming2 += KB_LOOKSPEED;
}
else
if (gamekeydown[gamecontrolbis[gc_lookdown][0]] ||
gamekeydown[gamecontrolbis[gc_lookdown][1]])
{
localaiming2 -= KB_LOOKSPEED;
}
else
if (gamekeydown[gamecontrolbis[gc_centerview][0]] ||
gamekeydown[gamecontrolbis[gc_centerview][1]])
localaiming2 = 0;
// look up max (viewheight/2) look down min -(viewheight/2)
cmd->aiming = G_ClipAimingPitch (&localaiming2);;
if (strafe)
side += mousex*2;
else
cmd->angleturn -= mousex*0x8;
if (forward > MAXPLMOVE)
forward = MAXPLMOVE;
else if (forward < -MAXPLMOVE)
forward = -MAXPLMOVE;
if (side > MAXPLMOVE)
side = MAXPLMOVE;
else if (side < -MAXPLMOVE)
side = -MAXPLMOVE;
cmd->forwardmove += forward;
cmd->sidemove += side;
#ifdef ABSOLUTEANGLE
localangle2 += (cmd->angleturn<<16);
cmd->angleturn = localangle2 >> 16;
// localaiming2 = cmd->aiming;
#endif
}
//
// G_DoLoadLevel
//
extern gamestate_t wipegamestate;
void G_DoLoadLevel (void)
{
int i;
levelstarttic = gametic; // for time calculation
if (wipegamestate == GS_LEVEL)
wipegamestate = -1; // force a wipe
gamestate = GS_LEVEL;
for (i=0 ; i<MAXPLAYERS ; i++)
{
if (playeringame[i] && players[i].playerstate == PST_DEAD)
players[i].playerstate = PST_REBORN;
memset (players[i].frags,0,sizeof(players[i].frags));
}
if (!P_SetupLevel (gameepisode, gamemap, 0, gameskill, gamemapname[0] ? gamemapname:NULL) )
return;
//BOT_InitLevelBots ();
displayplayer = consoleplayer; // view the guy you are playing
if(!cv_splitscreen.value)
secondarydisplayplayer = consoleplayer;
starttime = I_GetTime ();
gameaction = ga_nothing;
#ifdef PARANOIA
Z_CheckHeap (-2);
#endif
if (camera.chase)
P_ResetCamera (&players[displayplayer]);
// clear cmd building stuff
memset (gamekeydown, 0, sizeof(gamekeydown));
joyxmove = joyymove = 0;
mousex = mousey = 0;
// clear hud messages remains (usually from game startup)
CON_ClearHUD ();
}
//
// G_Responder
// Get info needed to make ticcmd_ts for the players.
//
boolean G_Responder (event_t* ev)
{
// allow spy mode changes even during the demo
if (gamestate == GS_LEVEL && ev->type == ev_keydown
&& ev->data1 == KEY_F12 && (singledemo || !cv_deathmatch.value) )
{
// spy mode
do
{
displayplayer++;
if (displayplayer == MAXPLAYERS)
displayplayer = 0;
} while (!playeringame[displayplayer] && displayplayer != consoleplayer);
//added:16-01-98:change statusbar also if playingback demo
if( singledemo )
ST_changeDemoView ();
//added:11-04-98: tell who's the view
CONS_Printf("Viewpoint : %s\n", player_names[displayplayer]);
return true;
}
#ifdef __WIN32_OLDSTUFF__
// console of 3dfx version on/off
if (rendermode==render_glide &&
ev->type==ev_keydown &&
ev->data1=='g')
glide_console ^= 1;
#endif
// any other key pops up menu if in demos
if (gameaction == ga_nothing && !singledemo &&
(demoplayback || gamestate == GS_DEMOSCREEN) )
{
if (ev->type == ev_keydown)
{
M_StartControlPanel ();
return true;
}
return false;
}
if (gamestate == GS_LEVEL)
{
#if 0
if (devparm && ev->type == ev_keydown && ev->data1 == ';')
{
// added Boris : test different player colors
players[consoleplayer].skincolor = (players[consoleplayer].skincolor+1) %MAXSKINCOLORS;
players[consoleplayer].mo->flags |= (players[consoleplayer].skincolor)<<MF_TRANSSHIFT;
G_DeathMatchSpawnPlayer (0);
return true;
}
#endif
if(!multiplayer)
cht_Responder (ev); // never eat
if (HU_Responder (ev))
return true; // chat ate the event
if (ST_Responder (ev))
return true; // status window ate it
if (AM_Responder (ev))
return true; // automap ate it
//added:07-02-98: map the event (key/mouse/joy) to a gamecontrol
}
if (gamestate == GS_FINALE)
{
if (F_Responder (ev))
return true; // finale ate the event
}
// update keys current state
G_MapEventsToControls (ev);
switch (ev->type)
{
case ev_keydown:
if (ev->data1 == KEY_PAUSE)
{
COM_BufAddText("pause\n");
return true;
}
return true;
case ev_keyup:
return false; // always let key up events filter down
case ev_mouse:
return true; // eat events
case ev_joystick:
return true; // eat events
default:
break;
}
return false;
}
//
// Activates the new features of Doom LEGACY, by default
// This is done at the start of D_DoomLoop, before a demo
// starts playing, because for older demos, some features
// are disabled.
//
void G_InitNewFeatures (void)
{
//activate rocket trails by default
states[S_ROCKET].action.acv = A_SmokeTrailer;
// smoke trails behind the skull heads
states[S_SKULL_ATK3].action.acv = A_SmokeTrailer;
states[S_SKULL_ATK4].action.acv = A_SmokeTrailer;
//added:02-01-98: enable transparency effect to selected sprites.
//if (transparency_enable)
//{
//added:03-02-98: activates all new features by default.
if (!fuzzymode) //only for translucency
{
//hack the states and set translucency for standard doom sprites
P_SetTranslucencies ();
}
}
//
// G_Ticker
// Make ticcmd_ts for the players.
//
void G_Ticker (void)
{
ULONG i;
int buf;
ticcmd_t* cmd;
// do player reborns if needed
for (i=0 ; i<MAXPLAYERS ; i++)
if (playeringame[i] && players[i].playerstate == PST_REBORN)
G_DoReborn (i);
// do things to change the game state
while (gameaction != ga_nothing)
{
switch (gameaction)
{
case ga_loadlevel : G_DoLoadLevel (); break;
case ga_playdemo : G_DoPlayDemo (); break;
case ga_completed : G_DoCompleted (); break;
case ga_victory : F_StartFinale (); break;
case ga_worlddone : G_DoWorldDone (); break;
case ga_screenshot: M_ScreenShot ();
gameaction = ga_nothing;
break;
case ga_nothing:
break;
}
}
// get commands, check consistancy,
// and build new consistancy check
buf = (gametic/ticdup)%BACKUPTICS;
for (i=0 ; i<MAXPLAYERS ; i++)
{
if (playeringame[i])
{
cmd = &players[i].cmd;
if (demoplayback)
G_ReadDemoTiccmd (cmd,i);
else
memcpy (cmd, &netcmds[buf][i], sizeof(ticcmd_t));
if (demorecording)
G_WriteDemoTiccmd (cmd,i);
// check for turbo cheats
if (cmd->forwardmove > TURBOTHRESHOLD
&& !(gametic&31) && ((gametic>>5)&3) == i )
{