-
Notifications
You must be signed in to change notification settings - Fork 5
/
g_game.pas
2961 lines (2559 loc) · 73.9 KB
/
g_game.pas
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
//------------------------------------------------------------------------------
//
// FPCDoom - Port of Doom to Free Pascal Compiler
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 2004-2007 by Jim Valavanis
// Copyright (C) 2017-2022 by Jim Valavanis
//
// This program 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 2
// of the License, or (at your option) any later version.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//------------------------------------------------------------------------------
// E-Mail: [email protected]
// Site : https://sourceforge.net/projects/fpcdoom/
//------------------------------------------------------------------------------
{$I FPCDoom.inc}
unit g_game;
interface
uses
doomdef,
m_fixed,
d_event,
d_player,
d_ticcmd;
//==============================================================================
// G_DeathMatchSpawnPlayer
//
// GAME
//
//==============================================================================
procedure G_DeathMatchSpawnPlayer(playernum: integer);
//==============================================================================
//
// G_InitNew
//
//==============================================================================
procedure G_InitNew(skill: skill_t; episode: integer; map: integer);
//==============================================================================
// G_DeferedInitNew
//
// Can be called by the startup code or M_Responder.
// A normal game starts at map 1,
// but a warp test can start elsewhere
//
//==============================================================================
procedure G_DeferedInitNew(skill: skill_t; episode: integer; map: integer);
//==============================================================================
//
// G_CmdNewGame
//
//==============================================================================
procedure G_CmdNewGame(const parm1, parm2: string);
//==============================================================================
//
// G_DeferedPlayDemo
//
//==============================================================================
function G_DeferedPlayDemo(const name: string): boolean;
//==============================================================================
//
// G_CmdPlayDemo
//
//==============================================================================
procedure G_CmdPlayDemo(const name: string);
{ Can be called by the startup code or M_Responder, }
{ calls P_SetupLevel or W_EnterWorld. }
//==============================================================================
//
// G_LoadGame
//
//==============================================================================
procedure G_LoadGame(const name: string);
//==============================================================================
//
// G_DoLoadGame
//
//==============================================================================
procedure G_DoLoadGame;
{ Called by M_Responder. }
//==============================================================================
//
// G_SaveGame
//
//==============================================================================
procedure G_SaveGame(slot: integer; const description: string);
//==============================================================================
//
// G_CmdSaveGame
//
//==============================================================================
procedure G_CmdSaveGame(const sname: string; const description: string);
{ Only called by startup code. }
//==============================================================================
//
// G_RecordDemo
//
//==============================================================================
procedure G_RecordDemo(const name: string);
//==============================================================================
//
// G_BeginRecording
//
//==============================================================================
procedure G_BeginRecording;
//==============================================================================
//
// G_TimeDemo
//
//==============================================================================
procedure G_TimeDemo(const name: string);
//==============================================================================
//
// G_CheckDemoStatus
//
//==============================================================================
function G_CheckDemoStatus: boolean;
//==============================================================================
//
// G_ExitLevel
//
//==============================================================================
procedure G_ExitLevel;
//==============================================================================
//
// G_SecretExitLevel
//
//==============================================================================
procedure G_SecretExitLevel;
//==============================================================================
//
// G_WorldDone
//
//==============================================================================
procedure G_WorldDone;
//==============================================================================
//
// G_Ticker
//
//==============================================================================
procedure G_Ticker;
//==============================================================================
//
// G_Responder
//
//==============================================================================
function G_Responder(ev: Pevent_t): boolean;
//==============================================================================
//
// G_ScreenShot
//
//==============================================================================
procedure G_ScreenShot;
//==============================================================================
//
// G_IsOldDemoPlaying
//
//==============================================================================
function G_IsOldDemoPlaying: boolean;
//==============================================================================
//
// G_Quit
//
//==============================================================================
procedure G_Quit;
var
sendpause: boolean; // send a pause event next tic
paused: boolean;
//
// controls (have defaults)
//
key_right: integer;
key_left: integer;
key_up: integer;
key_down: integer;
// JVAL Look Up and Down
key_lookup: integer;
key_lookdown: integer;
key_lookcenter: integer;
// JVAL Look Left and Right
key_lookright: integer;
key_lookleft: integer;
key_lookforward: integer;
key_strafeleft: integer;
key_straferight: integer;
key_fire: integer;
key_use: integer;
key_strafe: integer;
key_speed: integer;
// JVAL Jump
key_jump: integer;
// JVAL 20191207 Key bindings for weapon change
key_weapon0: integer = Ord('1');
key_weapon1: integer = Ord('2');
key_weapon2: integer = Ord('3');
key_weapon3: integer = Ord('4');
key_weapon4: integer = Ord('5');
key_weapon5: integer = Ord('6');
key_weapon6: integer = Ord('7');
key_weapon7: integer = Ord('8');
KEY_WEAPONS: array[0..Ord(NUMWEAPONS) - 1] of PInteger;
usemouse: boolean;
invertmouseturn: boolean;
invertmouselook: boolean;
mousebfire: integer;
mousebstrafe: integer;
mousebforward: integer;
usejoystick: boolean;
joybfire: integer;
joybstrafe: integer;
joybuse: integer;
joybspeed: integer;
joybjump: integer;
joyblleft: integer;
joyblright: integer;
demoplayback: boolean;
preparingdemoplayback: boolean = false;
gameepisode: integer;
gamemap: integer;
deathmatch: integer; // only if started as net death
netgame: boolean; // only true if packets are broadcast
playeringame: array[0..MAXPLAYERS - 1] of boolean;
consoleplayer: integer; // player taking events and displaying
displayplayer: integer; // view being displayed
gametic: integer;
// https://www.doomworld.com/forum/topic/95719-a_tracer-and-gametic/?do=findComment&comment=1788516
demostarttic: integer; // JVAL: Thanks fabian :)
totalkills, totalitems, totalsecret: integer; // for intermission
wminfo: wbstartstruct_t; // parms for world map / intermission
gameskill: skill_t;
bodyqueslot: integer;
precache: boolean; // if true, load all graphics at start
respawnmonsters: boolean;
viewactive: boolean;
singledemo: boolean; // quit after playing a demo from cmdline
demorecording: boolean = false;
gameaction: gameaction_t;
usergame: boolean; // ok to save / end game
//==============================================================================
//
// G_PlayerReborn
//
//==============================================================================
procedure G_PlayerReborn(player: integer);
//==============================================================================
//
// G_BuildTiccmd
//
//==============================================================================
procedure G_BuildTiccmd(cmd: Pticcmd_t);
var
statcopy: pointer = nil; // for statistics driver
var
forwardmove: array[0..1] of shortint;
sidemove: array[0..1] of shortint;
angleturn: array[0..2] of smallint;
//==============================================================================
//
// G_NeedsCompatibilityMode
//
//==============================================================================
function G_NeedsCompatibilityMode: boolean;
//==============================================================================
//
// G_PlayingEngineVersion
//
//==============================================================================
function G_PlayingEngineVersion: byte;
var
compatibilitymode: boolean = false;
oldcompatibilitymode: boolean = false;
type
//
// LOAD GAME MENU
//
load_e = (
load1,
load2,
load3,
load4,
load5,
load6,
load7,
load8,
load_end
);
var
autorunmode: integer = 2;
keepcheatsinplayerreborn: boolean = false;
allowplayerjumps: boolean = true;
majorbossdeathendsdoom1level: boolean = false;
var
// DOOM Par Times
pars: array[1..3, 1..9] of integer;
// DOOM II Par Times
cpars: array[0..31] of integer;
implementation
uses
d_fpc,
c_cmds,
z_memory,
doomstat,
doomdata,
am_map,
d_net,
d_main,
f_finale,
info_h,
info,
info_rnd,
i_input,
i_system,
e_endoom,
m_argv,
m_misc,
m_menu,
m_rnd,
p_setup,
p_saveg,
p_tick,
p_local,
p_mobj_h,
p_mobj,
p_inter,
p_map,
wi_stuff,
hu_stuff,
st_stuff,
w_wad,
s_sound,
// Data.
d_english,
sounds,
// SKY handling - still the wrong place.
r_data,
r_sky,
r_defs,
r_main,
r_draw,
r_intrpl,
r_mirror,
tables;
const
SAVEGAMESIZE = $800000; // Originally $2C000
SAVESTRINGSIZE = 24;
//==============================================================================
//
// G_ReadDemoTiccmd
//
//==============================================================================
procedure G_ReadDemoTiccmd(cmd: Pticcmd_t); forward;
//==============================================================================
//
// G_WriteDemoTiccmd
//
//==============================================================================
procedure G_WriteDemoTiccmd(cmd: Pticcmd_t); forward;
//==============================================================================
//
// G_DoReborn
//
//==============================================================================
procedure G_DoReborn(playernum: integer); forward;
//==============================================================================
//
// G_DoLoadLevel
//
//==============================================================================
procedure G_DoLoadLevel; forward;
//==============================================================================
//
// G_DoNewGame
//
//==============================================================================
procedure G_DoNewGame; forward;
//==============================================================================
//
// G_DoPlayDemo
//
//==============================================================================
procedure G_DoPlayDemo; forward;
//==============================================================================
//
// G_DoCompleted
//
//==============================================================================
procedure G_DoCompleted; forward;
//==============================================================================
//
// G_DoWorldDone
//
//==============================================================================
procedure G_DoWorldDone; forward;
//==============================================================================
//
// G_DoSaveGame
//
//==============================================================================
procedure G_DoSaveGame; forward;
//==============================================================================
//
// G_FinishedDemoPlayback
//
//==============================================================================
procedure G_FinishedDemoPlayback;
begin
demoplayback := false;
// Restore old compatibility mode
compatibilitymode := oldcompatibilitymode;
end;
var
sendsave: boolean; // send a save event next tic
sendcmdsave: boolean; // send a save event next tic (console)
timingdemo: boolean; // if true, exit with report on completion
starttime: integer; // for comparative timing purposes
demoname: string;
netdemo: boolean;
demobuffer: PByteArray;
demo_p: PByteArray;
demoend: PByte;
olddemo: boolean;
consistency: array[0..MAXPLAYERS - 1] of array[0..BACKUPTICS - 1] of smallint;
savebuffer: PByteArray;
const
TURBOTHRESHOLD = $32;
//==============================================================================
//
// MAXPLMOVE
//
//==============================================================================
function MAXPLMOVE: fixed_t;
begin
result := forwardmove[1];
end;
const
SLOWTURNTICS = 6;
NUMKEYS = 256;
var
gamekeydown: array[0..NUMKEYS - 1] of boolean;
turnheld: integer;
lookheld: integer; // JVAL Look UP and DOWN
lookheld2: integer; // JVAL Look RIGHT and LEFT
mousearray: array[0..2] of boolean;
mousebuttons: PBooleanArray;
// mouse values are used once
mousex: integer = 0;
mousey: integer = 0;
dclicktime: integer;
dclickstate: boolean;
dclicks: integer;
dclicktime2: integer;
dclickstate2: boolean;
dclicks2: integer;
// joystick values are repeated
joyxmove: integer;
joyymove: integer;
joyarray: array[0..NUMJOYBUTTONS - 1] of boolean;
joybuttons: PBooleanArray;
savegameslot: integer;
savedescription: string;
const
BODYQUESIZE = 32;
var
bodyque: array[0..BODYQUESIZE - 1] of Pmobj_t;
//==============================================================================
//
// G_CmdChecksum
//
//==============================================================================
function G_CmdChecksum(cmd: Pticcmd_t): integer;
var
i: integer;
begin
result := 0;
for i := 0 to SizeOf(cmd^) div 4 - 2 do
result := result + PIntegerArray(cmd)[i];
end;
//==============================================================================
//
// 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
//
//==============================================================================
procedure G_BuildTiccmd(cmd: Pticcmd_t);
var
i: integer;
strafe: boolean;
bstrafe: boolean;
speed: integer;
tspeed: integer;
lspeed: integer; // JVAL Look up and down
lspeed2: integer; // JVAL look left and right
_forward: integer;
side: integer;
look: integer; // JVAL Look up and down
look16: integer; // JVAL Smooth Look Up/Down
look2: integer; // JVAL look left and right
base: Pticcmd_t;
imousex: integer;
imousey: integer;
begin
base := I_BaseTiccmd; // empty, or external driver
memcpy(cmd, base, SizeOf(cmd^));
cmd.consistency := consistency[consoleplayer][maketic mod BACKUPTICS];
strafe := gamekeydown[key_strafe] or
(usemouse and mousebuttons[mousebstrafe]) or
(usejoystick and joybuttons[joybstrafe]);
speed := intval(gamekeydown[key_speed] or joybuttons[joybspeed]);
if autorunmode = 0 then
else if autorunmode = 1 then
speed := 1 - speed
else if I_GetCapsLock then
speed := 1 - speed;
_forward := 0;
side := 0;
look := 0;
look16 := 0; // JVAL Smooth Look Up/Down
look2 := 0;
// use two stage accelerative turning
// on the keyboard and joystick
if (joyxmove <> 0) or
(gamekeydown[key_right]) or
(gamekeydown[key_left]) then
turnheld := turnheld + ticdup
else
turnheld := 0;
if turnheld < SLOWTURNTICS then
tspeed := 2 // slow turn
else
tspeed := speed;
if gamekeydown[key_lookdown] or gamekeydown[key_lookup] then
lookheld := lookheld + ticdup
else
lookheld := 0;
if lookheld < SLOWTURNTICS then
lspeed := 1
else
lspeed := 2;
if gamekeydown[key_lookleft] or gamekeydown[key_lookright] or
(usejoystick and (joybuttons[joyblleft] or joybuttons[joyblright])) then
lookheld2 := lookheld2 + ticdup
else
lookheld2 := 0;
if lookheld2 < SLOWTURNTICS then
lspeed2 := 1
else
lspeed2 := 2;
// let movement keys cancel each other out
if strafe then
begin
if gamekeydown[key_right] then
side := side + sidemove[speed];
if gamekeydown[key_left] then
side := side - sidemove[speed];
if joyxmove > 0 then
side := side + sidemove[speed];
if joyxmove < 0 then
side := side - sidemove[speed];
end
else
begin
if gamekeydown[key_right] then
cmd.angleturn := cmd.angleturn - angleturn[tspeed];
if gamekeydown[key_left] then
cmd.angleturn := cmd.angleturn + angleturn[tspeed];
if joyxmove > 0 then
cmd.angleturn := cmd.angleturn - angleturn[tspeed];
if joyxmove < 0 then
cmd.angleturn := cmd.angleturn + angleturn[tspeed];
end;
if gamekeydown[key_up] then
_forward := _forward + forwardmove[speed];
if gamekeydown[key_down] then
_forward := _forward - forwardmove[speed];
// JVAL Look up/down/center keys
if zaxisshift then
begin
if gamekeydown[key_lookup] then
look := lspeed;
if gamekeydown[key_lookdown] then
look := -lspeed;
if gamekeydown[key_lookcenter] then
look := TOCENTER;
look16 := 256 * look; // JVAL Smooth Look Up/Down
end;
// JVAL Look right/left/forward keys
if gamekeydown[key_lookleft] or (usejoystick and joybuttons[joyblleft]) then
look2 := lspeed2;
if gamekeydown[key_lookright] or (usejoystick and joybuttons[joyblright]) then
look2 := -lspeed2;
if gamekeydown[key_lookforward] then
look2 := TOFORWARD;
if joyymove < 0 then
_forward := _forward + forwardmove[speed];
if joyymove > 0 then
_forward := _forward - forwardmove[speed];
if gamekeydown[key_straferight] then
side := side + sidemove[speed];
if gamekeydown[key_strafeleft] then
side := side - sidemove[speed];
// buttons
cmd.chatchar := Ord(HU_dequeueChatChar);
if gamekeydown[key_fire] or
(usemouse and mousebuttons[mousebfire]) or
(usejoystick and joybuttons[joybfire]) then
cmd.buttons := cmd.buttons or BT_ATTACK;
if gamekeydown[key_use] or (usejoystick and joybuttons[joybuse]) then
begin
cmd.buttons := cmd.buttons or BT_USE;
// clear double clicks if hit use button
dclicks := 0;
end;
// chainsaw overrides
for i := 0 to Ord(NUMWEAPONS) - 2 do
if gamekeydown[KEY_WEAPONS[i]^] then
begin
cmd.buttons := cmd.buttons or BT_CHANGE;
cmd.buttons := cmd.buttons or _SHL(i, BT_WEAPONSHIFT);
break;
end;
// mouse
if (usemouse and mousebuttons[mousebforward]) then
_forward := _forward + forwardmove[speed];
// forward double click
if usemouse and (mousebuttons[mousebforward] <> dclickstate) and (dclicktime > 1) then
begin
dclickstate := mousebuttons[mousebforward];
if dclickstate then
inc(dclicks);
if dclicks = 2 then
begin
cmd.buttons := cmd.buttons or BT_USE;
dclicks := 0;
end
else
dclicktime := 0;
end
else
begin
dclicktime := dclicktime + ticdup;
if dclicktime > 20 then
begin
dclicks := 0;
dclickstate := false;
end
end;
// strafe double click
bstrafe := (usemouse and mousebuttons[mousebstrafe]) or
(usejoystick and joybuttons[joybstrafe]);
if (bstrafe <> dclickstate2) and (dclicktime2 > 1) then
begin
dclickstate2 := bstrafe;
if bstrafe then
inc(dclicks2);
if dclicks2 = 2 then
begin
cmd.buttons := cmd.buttons or BT_USE;
dclicks2 := 0;
end
else
dclicktime2 := 0;
end
else
begin
dclicktime2 := dclicktime2 + ticdup;
if dclicktime2 > 20 then
begin
dclicks2 := 0;
dclickstate2 := false;
end;
end;
// JVAL: invert mouse
if invertmouseturn then
imousex := -mousex
else
imousex := mousex;
if strafe then
side := side - imousex * 2
else
cmd.angleturn := cmd.angleturn + imousex * $8;
if invertmouselook then
imousey := -mousey
else
imousey := mousey;
if usemouse then
begin
look := look + imousey div 16;
if imousey < 0 then
begin
if look < -4 then
look := -4;
end
else if imousey > 0 then
begin
if look > 4 then
look := 4;
end;
// JVAL Smooth Look Up/Down
if G_PlayingEngineVersion < VERSION111 then
look16 := 256 * look
else
begin
look16 := look16 + imousey * 16;
if imousey < 0 then
begin
if look16 < -4 * 256 then
look16 := -4 * 256;
end
else if imousey > 0 then
begin
if look16 > 4 * 256 then
look16 := 4 * 256;
end;
end;
end;
// For smooth mouse movement
mousex := mousex div 4;
mousey := mousey div 4;
if _forward > MAXPLMOVE then
_forward := MAXPLMOVE
else if _forward < -MAXPLMOVE then
_forward := -MAXPLMOVE;
if side > MAXPLMOVE then
side := MAXPLMOVE
else if side < -MAXPLMOVE then
side := -MAXPLMOVE;
cmd.forwardmove := cmd.forwardmove + _forward;
cmd.sidemove := cmd.sidemove + side;
if players[consoleplayer].playerstate = PST_LIVE then
begin
if zaxisshift then
begin
// JVAL Look Up/Down
if look16 < 0 then
look16 := look16 + 16 * 256;
cmd.lookupdown16 := look16;
end;
if look2 < 0 then
look2 := look2 + 16;
cmd.lookleftright := look2;
// JVAL
// allowplayerjumps variable controls if we accept input for jumping
if allowplayerjumps and (gamekeydown[key_jump] or (usejoystick and joybuttons[joybjump])) then
begin
if players[consoleplayer].oldjump <> 0 then
cmd.jump := 1
else
cmd.jump := 2
end
else
cmd.jump := 0;
players[consoleplayer].oldjump := cmd.jump;
end;
// special buttons
if sendpause then
begin
sendpause := false;
cmd.buttons := BT_SPECIAL or BTS_PAUSE;
end;
if sendsave then
begin
sendsave := false;
cmd.buttons := BT_SPECIAL or BTS_SAVEGAME or _SHL(savegameslot, BTS_SAVESHIFT);
end;
if sendcmdsave then
begin
sendcmdsave := false;
cmd.commands := CM_SAVEGAME;
end;
cmd.flags := 0;
if mirrormode and MR_ENVIROMENT <> 0 then
cmd.flags := cmd.flags or CF_MIRROR;
end;
//==============================================================================
// G_MirrorTiccmd
//
// G_DoLoadLevel
//
//==============================================================================
procedure G_MirrorTiccmd(cmd: Pticcmd_t);
begin
cmd.angleturn := - cmd.angleturn;
cmd.lookleftright := 16 - cmd.lookleftright;
cmd.sidemove := -cmd.sidemove;
end;
//==============================================================================
//
// G_DoLoadLevel
//
//==============================================================================
procedure G_DoLoadLevel;
var
i: integer;
begin
// Set the sky map.
// First thing, we have a dummy sky texture name,
// a flat. The data is in the WAD only because
// we look for an actual index, instead of simply
// setting one.
skyflatnum := R_FlatNumForName(SKYFLATNAME);
// DOOM determines the sky texture to be used
// depending on the current episode, and the game version.
if (gamemode = commercial) or
(gamemission = pack_tnt) or
(gamemission = pack_plutonia) then
begin
if gamemap < 12 then
skytexture := R_TextureNumForName('SKY1')
else if gamemap < 21 then
skytexture := R_TextureNumForName('SKY2')
else
skytexture := R_TextureNumForName('SKY3');
end
else
skytexture := R_TextureNumForName('SKY' + Chr(Ord('0') + gameepisode));
if wipegamestate = Ord(GS_LEVEL) then
wipegamestate := -1; // force a wipe
gamestate := GS_LEVEL;
for i := 0 to MAXPLAYERS - 1 do
begin
if playeringame[i] and (players[i].playerstate = PST_DEAD) then
players[i].playerstate := PST_REBORN;
ZeroMemory(@players[i].frags, SizeOf(players[i].frags));
end;
P_SetupLevel(gameepisode, gamemap);
// JVAL: Prevent erroneous demos
for i := 0 to MAXPLAYERS - 1 do
if playeringame[i] then
if players[i].mo = nil then
begin
I_Warning('G_DoLoadLevel(): Null player actor, is player start missing?'#13#10);
gamestate := GS_DEMOSCREEN;
D_StartTitle;
exit;
end;
displayplayer := consoleplayer; // view the guy you are playing
starttime := I_GetTime;