forked from Wolf3s/glDoom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
g_game.c
2304 lines (1939 loc) · 52.7 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
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $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.
//
// $Log:$
//
// DESCRIPTION: none
//
//-----------------------------------------------------------------------------
static const char
rcsid[] = "$Id: g_game.c,v 1.8 1997/02/03 22:45:09 b1 Exp $";
#include <string.h>
#include <stdlib.h>
#include "doomdef.h"
#include "doomstat.h"
#include "z_zone.h"
#include "f_finale.h"
#include "m_argv.h"
#include "m_misc.h"
#include "m_menu.h"
#include "m_random.h"
#include "i_system.h"
#include "p_setup.h"
#include "p_saveg.h"
#include "p_tick.h"
#include "d_main.h"
#include "wi_stuff.h"
#include "hu_stuff.h"
#include "st_stuff.h"
#include "am_map.h"
// Needs access to LFB.
#include "v_video.h"
#include "w_wad.h"
#include "p_local.h"
#include "s_sound.h"
// Data.
#include "dstrings.h"
#include "sounds.h"
// SKY handling - still the wrong place.
#include "r_data.h"
#include "r_sky.h"
#include "g_game.h"
#include "gconsole.h"
#include "doomcmd.h"
#include <SDL.h>
#define SAVEGAMESIZE 0x2c0000
#define SAVESTRINGSIZE 24
void lfprintf(char *message, ... );
int access( const char *path, int mode );
dboolean G_CheckDemoStatus (void);
void G_ReadDemoTiccmd (ticcmd_t* cmd);
void G_WriteDemoTiccmd (ticcmd_t* cmd);
void G_PlayerReborn (int player);
void G_InitNew (skill_t skill, int episode, int map);
void G_DoReborn (int playernum);
void G_DoLoadLevel (void);
void G_DoNewGame (void);
void G_DoLoadGame (void);
void G_DoPlayDemo (void);
void G_DoPlayDemo_II(void);
void G_DoCompleted (void);
void G_DoVictory (void);
void G_DoWorldDone (void);
void G_DoSaveGame (void);
gameaction_t gameaction;
gamestate_t gamestate;
skill_t gameskill;
dboolean respawnmonsters;
int gameepisode;
int gamemap;
dboolean paused;
dboolean sendpause; // send a pause event next tic
dboolean sendsave; // send a save event next tic
dboolean usergame; // ok to save / end game
dboolean timingdemo; // if true, exit with report on completion
dboolean nodrawers; // for comparative timing purposes
dboolean noblit; // for comparative timing purposes
int starttime; // for comparative timing purposes
int loadtime; // for fps timer
dboolean viewactive;
dboolean deathmatch; // only if started as net death
dboolean netgame; // only true if packets are broadcast
dboolean playeringame[MAXPLAYERS];
player_t players[MAXPLAYERS];
int consoleplayer; // player taking events and displaying
int displayplayer; // view being displayed
int gametic;
int levelstarttic; // gametic at level start
int totalkills, totalitems, totalsecret; // for intermission
int totalscore; // 10.15.98 scorekeeping dlw (2billion?)
char totalscoretextline[200];
char scoreuserwad[256];
char HUDscoretext[200];
char keepscore;
char showscoreHUD;
char demoname[32];
int demotype;
dboolean demorecording;
dboolean demoplayback;
dboolean netdemo;
byte* demobuffer;
byte* demo_p;
byte* demoend;
dboolean singledemo; // quit after playing a demo from cmdline
dboolean precache = true; // if true, load all graphics at start
wbstartstruct_t wminfo; // parms for world map / intermission
short consistancy[MAXPLAYERS][BACKUPTICS];
byte* savebuffer;
extern const char playername[18];
extern const char playerskin[18];
char ipaddress[4][16];
int numplayers = 0;
//
// controls (have defaults)
//
int key_lookup;
int key_lookdown;
int key_mlook;
int key_forward;
int key_leftturn;
int key_rightturn;
int key_backward;
int key_right;
int key_left;
int key_hudup = SDL_SCANCODE_EQUALS;
int key_huddn = SDL_SCANCODE_MINUS;
int key_up;
int key_down;
int key_strafeleft;
int key_straferight;
int key_fire;
int key_use;
int key_strafe;
int key_speed;
int key_mvert;
int mousebfire;
int mousebstrafe;
int mousebforward;
int mousebbackward = -1;
int mouseb1 = CMD_FIRE;
int mouseb2 = CMD_STRAFE;
int mouseb3 = CMD_FORWARD;
int gl_poffsetf, gl_poffsetu;
int gl_fog;
int gl_modeltest;
int gl_alphatest;
int gl_premalpha;
int gl_widetex;
int music;
int joybfire;
int joybstrafe;
int joybuse;
int joybspeed;
int joydead = 5000;
int joyb[32];
int joyb1;
int joyb2;
int joyb3;
int joyb4;
int joyb5;
int joyb6;
int joyb7;
int joyb8;
int joyb9;
int joyb10;
int joyb11;
int joyb12;
int joyb13;
int joyb14;
int joyb15;
int joyb16;
int joyb17;
int joyb18;
int joyb19;
int joyb20;
int joyb21;
int joyb22;
int joyb23;
int joyb24;
int joyb25;
int joyb26;
int joyb27;
int joyb28;
int joyb29;
int joyb30;
int joyb31;
int joyb32;
int autorun;
int swap_stereo;
int mouse_factor;
int mvert;
int mlook;
int nosound;
int keylink;
int link_alt;
int key_f1 = SDL_SCANCODE_F1;
int key_f2 = SDL_SCANCODE_F2;
int key_f3 = SDL_SCANCODE_F3;
int key_f4 = SDL_SCANCODE_F4;
int key_f5 = SDL_SCANCODE_F5;
int key_f6 = SDL_SCANCODE_F6;
int key_f7 = SDL_SCANCODE_F7;
int key_f8 = SDL_SCANCODE_F8;
int key_f9 = SDL_SCANCODE_F9;
int key_f10 = SDL_SCANCODE_F10;
int key_f11 = SDL_SCANCODE_F11;
int key_f12 = SDL_SCANCODE_F12;
int key_enter = SDL_SCANCODE_RETURN;
int key_backspace = SDL_SCANCODE_BACKSPACE;
int destination_keys;
int key_chat = SDL_SCANCODE_T;
int key_map_grid = SDL_SCANCODE_G;
int key_map_gobig = SDL_SCANCODE_0;
int key_map_clear = SDL_SCANCODE_C;
int key_map_mark = SDL_SCANCODE_M;
int key_map_right = SDL_SCANCODE_RIGHT;
int key_map_left = SDL_SCANCODE_LEFT;
int key_map_down = SDL_SCANCODE_DOWN;
int key_map_up = SDL_SCANCODE_UP;
int key_map_zoomout = SDL_SCANCODE_MINUS;
int key_map_zoomin = SDL_SCANCODE_EQUALS;
int key_map_follow = SDL_SCANCODE_F;
int key_weapontoggle;
int key_weapon9 = SDL_SCANCODE_9;
int key_weapon8 = SDL_SCANCODE_8;
int key_weapon7 = SDL_SCANCODE_7;
int key_weapon6 = SDL_SCANCODE_6;
int key_weapon5 = SDL_SCANCODE_5;
int key_weapon4 = SDL_SCANCODE_4;
int key_weapon3 = SDL_SCANCODE_3;
int key_weapon2 = SDL_SCANCODE_2;
int key_weapon1 = SDL_SCANCODE_1;
int key_help = SDL_SCANCODE_F1;
int key_savegame = SDL_SCANCODE_F2;
int key_loadgame = SDL_SCANCODE_F3;
int key_soundvolume = SDL_SCANCODE_F4;
int key_quicksave = SDL_SCANCODE_F6;
int key_endgame = SDL_SCANCODE_F7;
int key_messages = SDL_SCANCODE_F8;
int key_quickload = SDL_SCANCODE_F9;
int key_quit = SDL_SCANCODE_F10;
int key_gamma = SDL_SCANCODE_F11;
int key_screenshot = SDL_SCANCODE_F12;
int key_zoomout = SDL_SCANCODE_MINUS;
int key_zoomin = SDL_SCANCODE_EQUALS;
int key_spy;
int key_hud;
int key_map = SDL_SCANCODE_TAB;
int key_pause = SDL_SCANCODE_PAUSE;
int key_escape = SDL_SCANCODE_ESCAPE;
int key_menu_escape = SDL_SCANCODE_ESCAPE;
int key_menu_enter = SDL_SCANCODE_RETURN;
int key_menu_backspace = SDL_SCANCODE_BACKSPACE;
int key_menu_right = SDL_SCANCODE_RIGHT;
int key_menu_left = SDL_SCANCODE_LEFT;
int key_menu_up = SDL_SCANCODE_UP;
int key_menu_down = SDL_SCANCODE_DOWN;
int key_reverse;
int key_autorun;
int defaultskill = 2;
int default_weapon_recoil; // weapon recoil
int weapon_recoil; // weapon recoil
int default_player_bobbing; // whether player bobs or not
int player_bobbing; // whether player bobs or not
int weapon_preferences[2][NUMWEAPONS+1];
int health_red; // health amount less than which status is red
int health_yellow; // health amount less than which status is yellow
int health_green; // health amount above is blue, below is green
int armor_red; // armor amount less than which status is red
int armor_yellow; // armor amount less than which status is yellow
int armor_green; // armor amount above is blue, below is green
int ammo_red; // ammo percent less than which status is red
int ammo_yellow; // ammo percent less is yellow more green
int sts_always_red;// status numbers do not change colors
int sts_pct_always_gray;// status percents do not change colors
int hud_nosecrets; // status does not list secrets/items/kills
int sts_traditional_keys; // display keys the traditional way
int hud_list_bgon; // solid window background for list of messages
int hud_msg_lines; // number of message lines in window up to 16
#define MAXPLMOVE (forwardmove[1])
#define TURBOTHRESHOLD 0x32
fixed_t forwardmove[2] = {0x19, 0x32};
fixed_t sidemove[2] = {0x18, 0x28};
fixed_t angleturn[3] = {640, 1280, 320}; // + slow turn
#define SLOWTURNTICS 6
#define NUMKEYS 256
dboolean gamekeydown[NUMKEYS];
int turnheld; // for accelerative turning
dboolean mousearray[4];
dboolean* 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 joyxmove;
int joyymove;
dboolean joyarray[5];
dboolean* joybuttons = &joyarray[1]; // allow [-1]
int savegameslot;
char savedescription[32];
#define BODYQUESIZE 32
mobj_t* bodyque[BODYQUESIZE];
int bodyqueslot;
void* statcopy; // for statistics driver
int G_CmdChecksum (ticcmd_t* cmd)
{
int i;
int sum = 0;
for (i=0 ; i< sizeof(*cmd)/4 - 1 ; i++)
sum += ((int *)cmd)[i];
return sum;
}
extern float fXAngle;
//
// 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)
{
dboolean strafe;
dboolean bstrafe;
int speed;
int tspeed;
int forward;
int side;
ticcmd_t *base;
base = I_BaseTiccmd (); // empty, or external driver
memcpy (cmd,base,sizeof(*cmd));
cmd->consistancy = consistancy[consoleplayer][maketic%BACKUPTICS];
strafe = gamekeydown[key_strafe] || mousebuttons[mousebstrafe] || joybuttons[joybstrafe];
if ((joybspeed == 31) || (autorun == true))
speed = 1;
else
speed = gamekeydown[key_speed] || joybuttons[joybspeed];
forward = side = 0;
// use two stage accelerative turning on the keyboard and joystick
if (joyxmove < 0 || joyxmove > 0 || gamekeydown[key_right] || gamekeydown[key_left])
turnheld += ticdup;
else
turnheld = 0;
if (turnheld < SLOWTURNTICS)
tspeed = 2; // slow turn
else
tspeed = speed;
// let movement keys cancel each other out
if (strafe)
{
if (gamekeydown[key_right])
{
// fprintf(stderr, "strafe right\n");
side += sidemove[speed];
}
if (gamekeydown[key_left])
{
// fprintf(stderr, "strafe left\n");
side -= sidemove[speed];
}
if (joyxmove > 0)
side += sidemove[speed];
if (joyxmove < 0)
side -= sidemove[speed];
}
else
{
if (gamekeydown[key_right])
cmd->angleturn -= angleturn[tspeed];
if (gamekeydown[key_left])
cmd->angleturn += angleturn[tspeed];
if (joyxmove > 0)
cmd->angleturn -= angleturn[tspeed];
if (joyxmove < 0)
cmd->angleturn += angleturn[tspeed];
}
/*
if (gamekeydown[key_lookup])
{
// fprintf(stderr, "up\n");
if (fXAngle < 90.0f)
{
fXAngle += 3.0f;
}
}
if (gamekeydown[key_lookdown])
{
// fprintf(stderr, "up\n");
if (fXAngle > -90.0f)
{
fXAngle -= 3.0f;
}
}
*/
if (gamekeydown[key_up])
{
// fprintf(stderr, "up\n");
forward += forwardmove[speed];
}
if (gamekeydown[key_down])
{
// fprintf(stderr, "down\n");
forward -= forwardmove[speed];
}
if (joyymove < 0)
forward += forwardmove[speed];
if (joyymove > 0)
forward -= forwardmove[speed];
if (gamekeydown[key_straferight])
side += sidemove[speed];
if (gamekeydown[key_strafeleft])
side -= sidemove[speed];
// buttons
cmd->chatchar = HU_dequeueChatChar();
if (gamekeydown[key_fire] || mousebuttons[mousebfire] || joybuttons[joybfire])
{
cmd->buttons |= BT_ATTACK;
}
if (gamekeydown[key_use] || joybuttons[joybuse] )
{
cmd->buttons |= BT_USE;
// clear double clicks if hit use button
dclicks = 0;
}
if (gamekeydown[key_weapon1])
{
cmd->buttons |= BT_CHANGE;
cmd->buttons |= 0<<BT_WEAPONSHIFT;
}
else
if (gamekeydown[key_weapon2])
{
cmd->buttons |= BT_CHANGE;
cmd->buttons |= 1<<BT_WEAPONSHIFT;
}
else
if (gamekeydown[key_weapon3])
{
cmd->buttons |= BT_CHANGE;
cmd->buttons |= 2<<BT_WEAPONSHIFT;
}
else
if (gamekeydown[key_weapon4])
{
cmd->buttons |= BT_CHANGE;
cmd->buttons |= 3<<BT_WEAPONSHIFT;
}
else
if (gamekeydown[key_weapon5])
{
cmd->buttons |= BT_CHANGE;
cmd->buttons |= 4<<BT_WEAPONSHIFT;
}
else
if (gamekeydown[key_weapon6])
{
cmd->buttons |= BT_CHANGE;
cmd->buttons |= 5<<BT_WEAPONSHIFT;
}
else
if (gamekeydown[key_weapon7])
{
cmd->buttons |= BT_CHANGE;
cmd->buttons |= 6<<BT_WEAPONSHIFT;
}
else
if (gamekeydown[key_weapon8])
{
cmd->buttons |= BT_CHANGE;
cmd->buttons |= 7<<BT_WEAPONSHIFT;
}
/*
else
if (gamekeydown[key_weapon9])
{
cmd->buttons |= BT_CHANGE;
cmd->buttons |= 8<<BT_WEAPONSHIFT;
}
*/
/*
// chainsaw overrides
for (i = 0; i < NUMWEAPONS-1; i++)
{
if (gamekeydown[KEY_1+i])
{
cmd->buttons |= BT_CHANGE;
cmd->buttons |= i<<BT_WEAPONSHIFT;
break;
}
}
*/
// mouse
if (mousebuttons[mousebforward])
forward += forwardmove[speed];
// forward double click
if (mousebuttons[mousebforward] != dclickstate && dclicktime > 1 )
{
dclickstate = mousebuttons[mousebforward];
if (dclickstate)
dclicks++;
if (dclicks == 2)
{
cmd->buttons |= BT_USE;
dclicks = 0;
}
else
dclicktime = 0;
}
else
{
dclicktime += ticdup;
if (dclicktime > 20)
{
dclicks = 0;
dclickstate = 0;
}
}
// strafe double click
bstrafe = mousebuttons[mousebstrafe] || joybuttons[joybstrafe];
if (bstrafe != dclickstate2 && dclicktime2 > 1 )
{
dclickstate2 = bstrafe;
if (dclickstate2)
dclicks2++;
if (dclicks2 == 2)
{
cmd->buttons |= BT_USE;
dclicks2 = 0;
}
else
dclicktime2 = 0;
}
else
{
dclicktime2 += ticdup;
if (dclicktime2 > 20)
{
dclicks2 = 0;
dclickstate2 = 0;
}
}
forward += mousey;
if (strafe)
side += mousex*2;
else
cmd->angleturn -= mousex*0x8;
mousex = mousey = 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;
// special buttons
if (sendpause)
{
sendpause = false;
cmd->buttons = BT_SPECIAL | BTS_PAUSE;
}
if (sendsave)
{
sendsave = false;
cmd->buttons = BT_SPECIAL | BTS_SAVEGAME | (savegameslot << BTS_SAVESHIFT);
}
}
//
// G_DoLoadLevel
//
extern gamestate_t wipegamestate;
void G_DoLoadLevel (void)
{
int i;
// 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) // Doom II
|| ( gamemode == addon_tnt )
|| ( gamemode == addon_plut ) )
{
skytexture = R_TextureNumForName ("SKY3");
if (gamemap < 12)
skytexture = R_TextureNumForName ("SKY1");
else
if (gamemap < 21)
skytexture = R_TextureNumForName ("SKY2");
}
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));
}
P_SetupLevel (gameepisode, gamemap, 0, gameskill);
displayplayer = consoleplayer; // view the guy you are playing
starttime = I_GetTime ();
gameaction = ga_nothing;
Z_CheckHeap ();
// clear cmd building stuff
memset (gamekeydown, 0, sizeof(gamekeydown));
joyxmove = joyymove = 0;
mousex = mousey = 0;
sendpause = sendsave = paused = false;
memset (mousebuttons, 0, sizeof(mousebuttons));
memset (joybuttons, 0, sizeof(joybuttons));
R_FillBackScreen();
}
//
// G_Responder
// Get info needed to make ticcmd_ts for the players.
//
dboolean G_Responder(event_t* ev)
{
// allow spy mode changes even during the demo
if (gamestate == GS_LEVEL && ev->type == ev_keydown && ev->data1 == SDL_SCANCODE_F12 && (singledemo || !deathmatch))
{
// spy mode
do
{
displayplayer++;
if (displayplayer == MAXPLAYERS)
displayplayer = 0;
}
while (!playeringame[displayplayer] && displayplayer != consoleplayer);
return true;
}
if ((ev->type == ev_keydown) && (ev->data1 == key_mvert))
{
// don't like this - mvert = !mvert;
if (mvert == 0)
mvert = 1;
else
mvert = 0;
return true;
}
// any other key pops up menu if in demos
if (gameaction == ga_nothing && !singledemo && (demoplayback || gamestate == GS_DEMOSCREEN))
{
if (ev->type == ev_keydown || (ev->type == ev_mouse && ev->data1) || (ev->type == ev_joystick && ev->data1))
{
// except the console key...
if ((ev->type != ev_keyup))// || (ev->data1 != KEY_CONSOLE))
{
M_StartControlPanel ();
return true;
}
}
return false;
}
if (gamestate == GS_LEVEL)
{
#if 0
if (devparm && ev->type == ev_keydown && ev->data1 == ';')
{
G_DeathMatchSpawnPlayer(0);
return true;
}
#endif
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
}
if (gamestate == GS_FINALE)
{
if (F_Responder (ev))
return true; // finale ate the event
}
switch (ev->type)
{
case ev_keydown:
if (ev->data1 == SDL_SCANCODE_PAUSE)
{
sendpause = true;
return true;
}
if (ev->data1 < NUMKEYS)
gamekeydown[ev->data1] = true;
return true; // eat key down events
case ev_keyup:
if (ev->data1 < NUMKEYS)
gamekeydown[ev->data1] = false;
return false; // always let key up events filter down
//case ev_mouse:
// mousebuttons[0] = ev->data1 & 1;
// mousebuttons[1] = ev->data1 & 2;
// mousebuttons[2] = ev->data1 & 4;
// //mousex = ev->data2*(mouseSensitivity+5)/10;
// //mousey = ev->data3*(mouseSensitivity+5)/10;
// mousex = ev->data2*(mouseHorizontal*0.1*mouse_factor);
// mousey = ev->data3*(mouseVertical*0.1*mouse_factor);
// return true; // eat events
//case ev_joystick:
// joybuttons[0] = ev->data1 & 1;
// joybuttons[1] = ev->data1 & 2;
// joybuttons[2] = ev->data1 & 4;
// joybuttons[3] = ev->data1 & 8;
// joyxmove = ev->data2;
// joyymove = ev->data3;
// return true; // eat events
default:
break;
}
return false;
}
//
// G_Ticker
// Make ticcmd_ts for the players.
//
void G_Ticker (void)
{
int 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_newgame:
G_DoNewGame ();
break;
case ga_loadgame:
G_DoLoadGame ();
break;
case ga_savegame:
G_DoSaveGame ();
break;
case ga_playdemo:
if (demotype == DEMO_I)
G_DoPlayDemo();
else
G_DoPlayDemo_II();
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;
memcpy (cmd, &netcmds[i][buf], sizeof(ticcmd_t));
if (demoplayback)
{
G_ReadDemoTiccmd (cmd);
}
if (demorecording)
G_WriteDemoTiccmd (cmd);
// check for turbo cheats
if (cmd->forwardmove > TURBOTHRESHOLD
&& !(gametic&31) && ((gametic>>5)&3) == i )
{
static char turbomessage[80];
extern char *player_names[4];
sprintf (turbomessage, "%s is turbo!",player_names[i]);
players[consoleplayer].message = turbomessage;
}
if (netgame && !netdemo && !(gametic%ticdup) )
{
if (gametic > BACKUPTICS
&& consistancy[i][buf] != cmd->consistancy)
{
I_Error ("consistency failure (%i should be %i)",
cmd->consistancy, consistancy[i][buf]);
}
if (players[i].mo)
consistancy[i][buf] = players[i].mo->x;
else
consistancy[i][buf] = rndindex;
}
}
}
// check for special buttons
for (i=0 ; i<MAXPLAYERS ; i++)
{
if (playeringame[i])
{
if (players[i].cmd.buttons & BT_SPECIAL)
{
switch (players[i].cmd.buttons & BT_SPECIALMASK)
{
case BTS_PAUSE:
paused ^= 1;
if (paused)
S_PauseSound ();
else
S_ResumeSound ();
break;
case BTS_SAVEGAME:
if (!savedescription[0])
strcpy (savedescription, "NET GAME");
savegameslot =
(players[i].cmd.buttons & BTS_SAVEMASK)>>BTS_SAVESHIFT;
gameaction = ga_savegame;