/
p_user.c
1982 lines (1742 loc) · 53.8 KB
/
p_user.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
/**\file p_user.c
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2000-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
*\author Copyright © 1999 Activision
*\author Copyright © 1993-1996 by id Software, Inc.
*
* 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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/**
* Player related stuff.
*
* Bobbing POV/weapon, movement, pending weapon...
*/
#include "common.h"
#include "p_user.h"
#include <math.h>
#include <string.h>
#include "fi_lib.h"
#include "g_common.h"
#include "d_net.h"
#include "d_netcl.h"
#include "player.h"
#include "p_tick.h" // for Pause_IsPaused()
#include "p_view.h"
#include "player.h"
#include "p_map.h"
#include "g_common.h"
#include "hu_stuff.h"
#include "r_common.h"
#include "g_controls.h"
#if __JHERETIC__ || __JHEXEN__
# include "p_inventory.h"
# include "hu_inventory.h"
#endif
#define ANG5 (ANG90/18)
dd_bool onground;
float turboMul = 1.0f; // Multiplier for running speed.
int maxHealth; // 100
#if __JDOOM__ || __JDOOM64__
int healthLimit; // 200
int godModeHealth; // 100
int soulSphereLimit; // 200
int megaSphereHealth; // 200
int soulSphereHealth; // 100
int armorPoints[4]; // Green, blue, IDFA and IDKFA points.
int armorClass[4]; // Green, blue, IDFA and IDKFA armor classes.
#endif
#if __JDOOM__ || __JDOOM64__
classinfo_t classInfo[NUM_PLAYER_CLASSES] = {
{ // Player
PCLASS_PLAYER, NULL, true,
MT_PLAYER,
S_PLAY,
S_PLAY_RUN1,
S_PLAY_ATK1,
S_PLAY_ATK2,
20,
0x32,
{0x19, 0x32},
{0x18, 0x28},
2048,
{640, 1280},
24,
SFX_NOWAY
}
};
#elif __JHERETIC__
classinfo_t classInfo[NUM_PLAYER_CLASSES] = {
{ // Player
PCLASS_PLAYER, NULL, true,
MT_PLAYER,
S_PLAY,
S_PLAY_RUN1,
S_PLAY_ATK1,
S_PLAY_ATK2,
20,
0x32,
{0x19, 0x32},
{0x18, 0x28},
2048,
{640, 1280},
24,
SFX_NONE
},
{
PCLASS_CHICKEN, NULL, false,
MT_CHICPLAYER,
S_CHICPLAY,
S_CHICPLAY_RUN1,
S_CHICPLAY_ATK1,
S_CHICPLAY_ATK1,
20,
0x32,
{0x19, 0x32},
{0x18, 0x28},
2500,
{640, 1280},
24,
SFX_NONE
},
};
#elif __JHEXEN__
classinfo_t classInfo[NUM_PLAYER_CLASSES] = {
{
PCLASS_FIGHTER, NULL, true,
MT_PLAYER_FIGHTER,
S_FPLAY,
S_FPLAY_RUN1,
S_FPLAY_ATK1,
S_FPLAY_ATK2,
20,
15 * FRACUNIT,
0x3C,
{0x1D, 0x3C},
{0x1B, 0x3B},
2048,
{640, 1280},
18,
SFX_PLAYER_FIGHTER_FAILED_USE,
{25 * FRACUNIT, 20 * FRACUNIT, 15 * FRACUNIT, 5 * FRACUNIT},
{ TXT_SKILLF1, TXT_SKILLF2, TXT_SKILLF3, TXT_SKILLF4, TXT_SKILLF5 },
{ { { 190, 0 }, "WPIECEF1" }, { { 225, 0 }, "WPIECEF2" }, { { 234, 0 }, "WPIECEF3" } },
"WPFULL0"
},
{ // Cleric
PCLASS_CLERIC, NULL, true,
MT_PLAYER_CLERIC,
S_CPLAY,
S_CPLAY_RUN1,
S_CPLAY_ATK1,
S_CPLAY_ATK3,
18,
10 * FRACUNIT,
0x32,
{0x19, 0x32},
{0x18, 0x28},
2048,
{640, 1280},
18,
SFX_PLAYER_CLERIC_FAILED_USE,
{10 * FRACUNIT, 25 * FRACUNIT, 5 * FRACUNIT, 20 * FRACUNIT},
{ TXT_SKILLC1, TXT_SKILLC2, TXT_SKILLC3, TXT_SKILLC4, TXT_SKILLC5 },
{ { { 190, 0 }, "WPIECEC1" }, { { 212, 0 }, "WPIECEC2" }, { { 225, 0 }, "WPIECEC3" } },
"WPFULL1"
},
{ // Mage
PCLASS_MAGE, NULL, true,
MT_PLAYER_MAGE,
S_MPLAY,
S_MPLAY_RUN1,
S_MPLAY_ATK1,
S_MPLAY_ATK2,
16,
5 * FRACUNIT,
0x2D,
{0x16, 0x2E},
{0x15, 0x25},
2048,
{640, 1280},
18,
SFX_PLAYER_MAGE_FAILED_USE,
{5 * FRACUNIT, 15 * FRACUNIT, 10 * FRACUNIT, 25 * FRACUNIT},
{ TXT_SKILLM1, TXT_SKILLM2, TXT_SKILLM3, TXT_SKILLM4, TXT_SKILLM5 },
{ { { 190, 0 }, "WPIECEM1" }, { { 205, 0 }, "WPIECEM2" }, { { 224, 0 }, "WPIECEM3" } },
"WPFULL2"
},
{ // Pig
PCLASS_PIG, NULL, false,
MT_PIGPLAYER,
S_PIGPLAY,
S_PIGPLAY_RUN1,
S_PIGPLAY_ATK1,
S_PIGPLAY_ATK1,
1,
0,
0x31,
{0x18, 0x31},
{0x17, 0x27},
2048,
{640, 1280},
18
},
};
#endif
#if __JHERETIC__ || __JHEXEN__
static int newTorch[MAXPLAYERS]; // Used in the torch flicker effect.
static int newTorchDelta[MAXPLAYERS];
#endif
/**
* Moves the given origin along a given angle.
*/
void P_Thrust(player_t *player, angle_t angle, coord_t move)
{
mobj_t *mo = player->plr->mo;
uint an = angle >> ANGLETOFINESHIFT;
/*coord_t xmul=1, ymul=1;
// How about Quake-flying? -- jk
if(quakeFly)
{
float ang = LOOKDIR2RAD(player->plr->lookDir);
xmul = ymul = cos(ang);
mo->mom[MZ] += sin(ang) * move;
}*/
if(!(player->powers[PT_FLIGHT] && !(mo->origin[VZ] <= mo->floorZ)))
{
move *= Mobj_ThrustMul(mo);
}
mo->mom[MX] += move * FIX2FLT(finecosine[an]);
mo->mom[MY] += move * FIX2FLT(finesine[an]);
}
/**
* Returns true if the player is currently standing on ground
* or on top of another mobj.
*/
dd_bool P_IsPlayerOnGround(player_t* player)
{
dd_bool onground = (player->plr->mo->origin[VZ] <= player->plr->mo->floorZ);
#if __JHEXEN__
if((player->plr->mo->onMobj) && !onground)
{
onground = true; //(player->plr->mo->origin[VZ] <= on->pos[VZ] + on->height);
}
#else
if(player->plr->mo->onMobj && !onground && !(player->plr->mo->flags2 & MF2_FLY))
{
mobj_t *on = player->plr->mo->onMobj;
onground = (player->plr->mo->origin[VZ] <= on->origin[VZ] + on->height);
}
#endif
return onground;
}
/**
* Will make the player jump if the latest command so instructs,
* providing that jumping is possible.
*/
void P_CheckPlayerJump(player_t* player)
{
float power = (IS_CLIENT ? netJumpPower : cfg.common.jumpPower);
if(player->plr->flags & DDPF_CAMERA)
return; // Cameras don't jump.
// Check if we are allowed to jump.
if(cfg.common.jumpEnabled && power > 0 && P_IsPlayerOnGround(player) &&
player->brain.jump && player->jumpTics <= 0)
{
// Jump, then!
#if __JHEXEN__
if(player->morphTics) // Pigs don't jump that high.
player->plr->mo->mom[MZ] = (2 * power / 3);
else
#endif
player->plr->mo->mom[MZ] = power;
player->jumpTics = PCLASS_INFO(player->class_)->jumpTics;
#if __JHEXEN__
player->plr->mo->onMobj = NULL;
#endif
}
}
/**
* Moves a player according to its smoother.
*/
void P_PlayerRemoteMove(player_t *player)
{
int plrNum = player - players;
ddplayer_t *ddpl = player->plr;
Smoother *smoother = Net_PlayerSmoother(plrNum);
mobj_t *mo = player->plr->mo;
coord_t xyz[3];
if(!IS_NETGAME || !mo || !smoother)
return;
// On client, the console player is not remote.
if(IS_CLIENT && plrNum == CONSOLEPLAYER)
return;
#if !defined (DENG_MOBILE)
// On server, there must be valid coordinates.
if(IS_SERVER && !Sv_CanTrustClientPos(plrNum))
return;
#endif
// Unless there is a pending momentum fix, clear the mobj's momentum.
if(ddpl->fixCounter.mom == ddpl->fixAcked.mom && !(ddpl->flags & DDPF_FIXMOM))
{
// As the mobj is being moved by the smoother, it has no momentum in the regular
// physics sense.
mo->mom[VX] = 0;
mo->mom[VY] = 0;
mo->mom[VZ] = 0;
}
if(!Smoother_Evaluate(smoother, xyz))
{
// The smoother has no coordinates for us, so we won't touch the mobj.
return;
}
if(IS_SERVER)
{
// On the server, the move must trigger all the usual player movement side-effects
// (e.g., teleporting).
if(P_TryMoveXYZ(mo, xyz[VX], xyz[VY], xyz[VZ]))
{
if(INRANGE_OF(mo->origin[VX], xyz[VX], .001f) &&
INRANGE_OF(mo->origin[VY], xyz[VY], .001f))
{
if(Smoother_IsOnFloor(smoother))
{
// It successfully moved to the right XY coords.
mo->origin[VZ] = mo->floorZ;
App_Log(DE2_DEV_MAP_XVERBOSE,
"Player %i: Smooth move to %f, %f, %f (floorz)",
plrNum, mo->origin[VX], mo->origin[VY], mo->origin[VZ]);
}
else
{
App_Log(DE2_DEV_MAP_XVERBOSE,
"Player %i: Smooth move to %f, %f, %f",
plrNum, mo->origin[VX], mo->origin[VY], mo->origin[VZ]);
}
}
if(players[plrNum].plr->flags & DDPF_FIXORIGIN)
{
// The player must have teleported.
App_Log(DE2_DEV_MAP_MSG, "Player %i: Clearing smoother because of FIXPOS", plrNum);
Smoother_Clear(smoother);
}
}
else
{
App_Log(DE2_DEV_MAP_NOTE,
"P_PlayerRemoteMove: Player %i: Smooth move to %f, %f, %f FAILED!",
plrNum, mo->origin[VX], mo->origin[VY], mo->origin[VZ]);
}
}
}
void P_MovePlayer(player_t *player)
{
ddplayer_t* dp = player->plr;
mobj_t* plrmo = player->plr->mo;
playerbrain_t *brain = &player->brain;
classinfo_t* pClassInfo = PCLASS_INFO(player->class_);
int speed;
coord_t forwardMove;
coord_t sideMove;
if(!plrmo) return;
if(IS_NETWORK_SERVER)
{
// Server starts the walking animation for remote players.
if((NON_ZERO(dp->forwardMove) || NON_ZERO(dp->sideMove)) &&
plrmo->state == &STATES[pClassInfo->normalState])
{
P_MobjChangeState(plrmo, pClassInfo->runState);
}
else if(P_PlayerInWalkState(player) && IS_ZERO(dp->forwardMove) && IS_ZERO(dp->sideMove))
{
// If in a walking frame, stop moving.
P_MobjChangeState(plrmo, pClassInfo->normalState);
}
return;
}
// Slow > fast. Fast > slow.
speed = brain->speed;
if(cfg.common.alwaysRun)
speed = !speed;
// Do not let the player control movement if not onground.
onground = P_IsPlayerOnGround(player);
if(dp->flags & DDPF_CAMERA) // $democam
{
static const coord_t cameraSpeed[2] = { FIX2FLT(0x19), FIX2FLT(0x54) };
int moveMul = 2048;
// Cameramen have 3D thrusters!
P_Thrust3D(player, plrmo->angle, dp->lookDir,
brain->forwardMove * cameraSpeed[speed] * moveMul,
brain->sideMove * cameraSpeed[speed] * moveMul);
}
else
{
// 'Move while in air' hack (server doesn't know about this!!).
// Movement while in air traditionally disabled.
int const movemul = (onground || (plrmo->flags2 & MF2_FLY))?
pClassInfo->moveMul : (cfg.common.airborneMovement? cfg.common.airborneMovement * 64 : 0);
if(!brain->lunge)
{
coord_t const maxMove = FIX2FLT(pClassInfo->maxMove) * turboMul;
forwardMove = FIX2FLT(pClassInfo->forwardMove[speed]) * turboMul * MINMAX_OF(-1.f, brain->forwardMove, 1.f);
sideMove = FIX2FLT(pClassInfo->sideMove[speed]) * turboMul * MINMAX_OF(-1.f, brain->sideMove, 1.f);
// Players can opt to reduce their maximum possible movement speed.
if((int) cfg.common.playerMoveSpeed != 1)
{
// A divsor has been specified, apply it.
coord_t m = MINMAX_OF(0.f, cfg.common.playerMoveSpeed, 1.f);
forwardMove *= m;
sideMove *= m;
}
// Make sure it's within valid bounds.
forwardMove = MINMAX_OF(-maxMove, forwardMove, maxMove);
sideMove = MINMAX_OF(-maxMove, sideMove, maxMove);
#if __JHEXEN__
// The speed power gives an extra boost .
if(player->powers[PT_SPEED] && !player->morphTics)
{
forwardMove = (3 * forwardMove) / 2;
sideMove = (3 * sideMove) / 2;
}
#endif
}
else
{
/**
* Do the "lunge" move.
*
* @note Normal valid range clamp not used with lunge as with
* it; the amount of forward velocity is not sufficent to
* prevent the player from easily backing out while lunging.
*/
forwardMove = FIX2FLT(0xc800 / 512);
sideMove = 0;
}
if(NON_ZERO(forwardMove) && movemul)
{
P_Thrust(player, plrmo->angle, forwardMove * movemul);
}
if(NON_ZERO(sideMove) && movemul)
{
P_Thrust(player, plrmo->angle - ANG90, sideMove * movemul);
}
if((NON_ZERO(forwardMove) || NON_ZERO(sideMove)) &&
plrmo->state == &STATES[pClassInfo->normalState])
{
P_MobjChangeState(plrmo, pClassInfo->runState);
}
//P_CheckPlayerJump(player); // done in a different place
}
#if __JHEXEN__
// Look up/down using the delta.
/* if(cmd->lookdirdelta)
{
float fd = cmd->lookdirdelta / DELTAMUL;
float delta = fd * fd;
if(cmd->lookdirdelta < 0) delta = -delta;
player->plr->lookDir += delta;
} */
// 110 corresponds 85 degrees.
dp->lookDir = MINMAX_OF(-LOOKDIRMAX, dp->lookDir, LOOKDIRMAX);
#endif
}
/**
* Fall on your ass when dying. Decrease viewheight to floor height.
*/
void P_DeathThink(player_t* player)
{
#if __JDOOM__ || __JDOOM64__ || __JHERETIC__
angle_t angle;
#endif
angle_t delta;
int lookDelta;
if(player->rebornWait > 0)
player->rebornWait--;
P_MovePsprites(player);
onground = (player->plr->mo->origin[VZ] <= player->plr->mo->floorZ);
#if __JDOOM__ || __JDOOM64__
if(cfg.deathLookUp)
#elif __JHERETIC__
if(player->plr->mo->type == MT_BLOODYSKULL)
#elif __JHEXEN__
if(player->plr->mo->type == MT_BLOODYSKULL ||
player->plr->mo->type == MT_ICECHUNK)
#endif
{ // Flying bloody skull
player->viewHeight = 6;
player->viewHeightDelta = 0;
if(onground)
{
if(player->plr->lookDir < 60)
{
lookDelta = (60 - player->plr->lookDir) / 8;
if(lookDelta < 1 && (mapTime & 1))
{
lookDelta = 1;
}
else if(lookDelta > 6)
{
lookDelta = 6;
}
player->plr->lookDir += lookDelta;
player->plr->flags |= DDPF_INTERPITCH;
player->plr->flags |= DDPF_FIXANGLES;
}
}
}
#if __JHEXEN__
else if(!(player->plr->mo->flags2 & MF2_ICEDAMAGE)) // (if not frozen)
#else
else // fall to the ground
#endif
{
if(player->viewHeight > 6)
player->viewHeight -= 1;
if(player->viewHeight < 6)
player->viewHeight = 6;
player->viewHeightDelta = 0;
#if __JHERETIC__ || __JHEXEN__
if(player->plr->lookDir > 0)
player->plr->lookDir -= 6;
else if(player->plr->lookDir < 0)
player->plr->lookDir += 6;
if(abs((int) player->plr->lookDir) < 6)
player->plr->lookDir = 0;
#endif
player->plr->flags |= DDPF_INTERPITCH;
player->plr->flags |= DDPF_FIXANGLES;
}
#if __JHEXEN__
player->update |= PSF_VIEW_HEIGHT;
#endif
P_CalcHeight(player);
// Keep track of the killer.
if(player->attacker && player->attacker != player->plr->mo)
{
#if __JHEXEN__
int dir = P_FaceMobj(player->plr->mo, player->attacker, &delta);
if(delta < ANGLE_1 * 10)
{ // Looking at killer, so fade damage and poison counters
if(player->damageCount)
{
player->damageCount--;
}
if(player->poisonCount)
{
player->poisonCount--;
}
}
delta = delta / 8;
if(delta > ANGLE_1 * 5)
{
delta = ANGLE_1 * 5;
}
if(dir)
player->plr->mo->angle += delta; // Turn clockwise
else
player->plr->mo->angle -= delta; // Turn counter clockwise
#else
angle = M_PointToAngle2(player->plr->mo->origin, player->attacker->origin);
delta = angle - player->plr->mo->angle;
if(delta < ANG5 || delta > (unsigned) -ANG5)
{
// Looking at killer, so fade damage flash down.
player->plr->mo->angle = angle;
if(player->damageCount)
player->damageCount--;
}
else if(delta < ANG180)
player->plr->mo->angle += ANG5; // Turn clockwise
else
player->plr->mo->angle -= ANG5; // Turn counter clockwise
player->plr->flags |= DDPF_INTERYAW;
#endif
// Update client.
player->plr->flags |= DDPF_FIXANGLES;
}
else
{
if(player->damageCount)
player->damageCount--;
#if __JHEXEN__
if(player->poisonCount)
player->poisonCount--;
#endif
}
if(!(player->rebornWait > 0) && player->brain.doReborn)
{
if(IS_CLIENT)
{
NetCl_PlayerActionRequest(player, GPA_USE, 0);
}
else
{
P_PlayerReborn(player);
}
}
}
/**
* Called when a dead player wishes to be reborn.
*
* @param player Player that wishes to be reborn.
*/
void P_PlayerReborn(player_t *player)
{
int const plrNum = player - players;
if(plrNum == CONSOLEPLAYER)
{
App_Log(DE2_DEV_SCR_MSG, "Reseting Infine due to console player being reborn");
// Clear the currently playing script, if any.
FI_StackClear();
}
player->playerState = PST_REBORN;
#if __JHERETIC__ || __JHEXEN__
player->plr->flags &= ~DDPF_VIEW_FILTER;
newTorch[player - players] = 0;
newTorchDelta[player - players] = 0;
# if __JHEXEN__
player->plr->mo->special1 = player->class_;
if(player->plr->mo->special1 > 2)
{
player->plr->mo->special1 = 0;
}
# endif
// Let the mobj know the player has entered the reborn state. Some
// mobjs need to know when it's ok to remove themselves.
player->plr->mo->special2 = 666;
#endif
}
#if __JHERETIC__ || __JHEXEN__
void P_MorphThink(player_t *player)
{
mobj_t *pmo;
#if __JHEXEN__
if(player->morphTics & 15)
return;
pmo = player->plr->mo;
if(IS_ZERO(pmo->mom[MX]) && IS_ZERO(pmo->mom[MY]) && P_Random() < 64)
{ // Snout sniff
P_SetPspriteNF(player, ps_weapon, S_SNOUTATK2);
S_StartSound(SFX_PIG_ACTIVE1, pmo); // snort
return;
}
if(P_Random() < 48)
{
if(P_Random() < 128)
S_StartSound(SFX_PIG_ACTIVE1, pmo);
else
S_StartSound(SFX_PIG_ACTIVE2, pmo);
}
# else
if(player->health > 0)
P_UpdateBeak(player, &player->pSprites[ps_weapon]); // Handle beak movement
if(player->chickenPeck)
{ // Chicken attack counter.
player->chickenPeck -= 3;
}
if(/*IS_CLIENT || */ player->morphTics & 15)
return;
pmo = player->plr->mo;
if(INRANGE_OF(pmo->mom[MX], 0, NOMOM_THRESHOLD) &&
INRANGE_OF(pmo->mom[MY], 0, NOMOM_THRESHOLD) && P_Random() < 160)
{ // Twitch view angle
pmo->angle += (P_Random() - P_Random()) << 19;
}
if(!IS_NETGAME || IS_CLIENT)
{
if(IS_ZERO(pmo->mom[MX]) && IS_ZERO(pmo->mom[MY]) && P_Random() < 160)
{ // Twitch view angle
pmo->angle += (P_Random() - P_Random()) << 19;
}
/* }
if(!IS_NETGAME || !IS_CLIENT)
{*/
if(pmo->origin[VZ] <= pmo->floorZ && (P_Random() < 32))
{ // Jump and noise
pmo->mom[MZ] += 1;
P_MobjChangeState(pmo, S_CHICPLAY_PAIN);
return;
}
}
if(P_Random() < 48)
{ // Just noise.
S_StartSound(SFX_CHICACT, pmo);
}
# endif
}
dd_bool P_UndoPlayerMorph(player_t* player)
{
mobj_t* fog = 0, *mo = 0, *pmo = 0;
coord_t pos[3];
unsigned int an;
angle_t angle;
int playerNum;
weapontype_t weapon;
int oldFlags, oldFlags2, oldBeast;
if(IS_CLIENT) return false;
# if __JHEXEN__
player->update |= PSF_MORPH_TIME | PSF_POWERS | PSF_HEALTH;
# endif
pmo = player->plr->mo;
memcpy(pos, pmo->origin, sizeof(pos));
angle = pmo->angle;
weapon = pmo->special1;
oldFlags = pmo->flags;
oldFlags2 = pmo->flags2;
# if __JHEXEN__
oldBeast = pmo->type;
# else
oldBeast = MT_CHICPLAYER;
# endif
P_MobjChangeState(pmo, S_FREETARGMOBJ);
playerNum = P_GetPlayerNum(player);
# if __JHEXEN__
mo = P_SpawnMobj(PCLASS_INFO(cfg.playerClass[playerNum])->mobjType,
pos, angle, 0);
# else
mo = P_SpawnMobj(MT_PLAYER, pos, angle, 0);
# endif
if(!mo) return false;
if(P_TestMobjLocation(mo) == false)
{
// Didn't fit
P_MobjRemove(mo, false);
if((mo = P_SpawnMobj(oldBeast, pos, angle, 0)))
{
mo->health = player->health;
mo->special1 = weapon;
mo->player = player;
mo->dPlayer = player->plr;
mo->flags = oldFlags;
mo->flags2 = oldFlags2;
player->plr->mo = mo;
player->morphTics = 2 * 35;
}
return false;
}
if(playerNum != 0)
{
// Set color translation bits for player sprites
mo->flags |= playerNum << MF_TRANSSHIFT; /// @todo Use configured color? -jk
}
mo->player = player;
mo->dPlayer = player->plr;
mo->reactionTime = 18;
if(oldFlags2 & MF2_FLY)
{
mo->flags2 |= MF2_FLY;
mo->flags |= MF_NOGRAVITY;
}
player->morphTics = 0;
# if __JHERETIC__
player->powers[PT_WEAPONLEVEL2] = 0;
# endif
player->health = mo->health = maxHealth;
player->plr->mo = mo;
# if __JHERETIC__
player->class_ = PCLASS_PLAYER;
# else
player->class_ = cfg.playerClass[playerNum];
# endif
an = angle >> ANGLETOFINESHIFT;
if((fog = P_SpawnMobjXYZ(MT_TFOG,
pos[VX] + 20 * FIX2FLT(finecosine[an]),
pos[VY] + 20 * FIX2FLT(finesine[an]),
pos[VZ] + TELEFOGHEIGHT, angle + ANG180, 0)))
{
# if __JHERETIC__
S_StartSound(SFX_TELEPT, fog);
# else
S_StartSound(SFX_TELEPORT, fog);
# endif
}
P_PostMorphWeapon(player, weapon);
player->update |= PSF_MORPH_TIME | PSF_HEALTH;
player->plr->flags |= DDPF_FIXORIGIN | DDPF_FIXMOM;
return true;
}
#endif
void P_PlayerThinkState(player_t* player)
{
if(player->plr->mo)
{
mobj_t* plrmo = player->plr->mo;
// jDoom
// Selector 0 = Generic (used by default)
// Selector 1 = Fist
// Selector 2 = Pistol
// Selector 3 = Shotgun
// Selector 4 = Fist
// Selector 5 = Chaingun
// Selector 6 = Missile
// Selector 7 = Plasma
// Selector 8 = BFG
// Selector 9 = Chainsaw
// Selector 10 = Super shotgun
// jHexen
// Selector 0 = Generic (used by default)
// Selector 1..4 = Weapon 1..4
plrmo->selector =
(plrmo->selector & ~DDMOBJ_SELECTOR_MASK) | (player->readyWeapon + 1);
// Reactiontime is used to prevent movement for a bit after a teleport.
if(plrmo->reactionTime > 0)
{
plrmo->reactionTime--;
}
else
{
plrmo->reactionTime = 0;
}
}
if(player->playerState != PST_DEAD)
{
// Clear the view angle interpolation flags by default.
player->plr->flags &= ~(DDPF_INTERYAW | DDPF_INTERPITCH);
}
}
void P_PlayerThinkCheat(player_t *player)
{
if(player->plr->mo)
{
mobj_t *plrmo = player->plr->mo;
// fixme: do this in the cheat code
if(P_GetPlayerCheats(player) & CF_NOCLIP)
plrmo->flags |= MF_NOCLIP;
else
plrmo->flags &= ~MF_NOCLIP;
}
}
void P_PlayerThinkAttackLunge(player_t *player)
{
mobj_t* plrmo = player->plr->mo;
// Normally we don't lunge.
player->brain.lunge = false;
if(plrmo && (plrmo->flags & MF_JUSTATTACKED))
{
player->brain.lunge = true;
plrmo->flags &= ~MF_JUSTATTACKED;
player->plr->flags |= DDPF_FIXANGLES;
}
}
/**
* @return @c true, if thinking should be stopped. Otherwise,
* @c false.
*/
dd_bool P_PlayerThinkDeath(player_t *player)
{
if(player->playerState == PST_DEAD)
{
P_DeathThink(player);
return true; // stop!
}
return false; // don't stop
}
void P_PlayerThinkMorph(player_t *player)
{
#if __JHERETIC__ || __JHEXEN__
if(player->morphTics)
{
P_MorphThink(player);
if(!--player->morphTics)
{ // Attempt to undo the pig/chicken.
P_UndoPlayerMorph(player);
}
}
#endif
}
void P_PlayerThinkMove(player_t *player)
{
mobj_t* plrmo = player->plr->mo;
// Move around.
// Reactiontime is used to prevent movement for a bit after a teleport.
if(plrmo && !plrmo->reactionTime)
{
P_MovePlayer(player);
#if __JHEXEN__
plrmo = player->plr->mo;
if(player->powers[PT_SPEED] && !(mapTime & 1) &&
M_ApproxDistance(plrmo->mom[MX], plrmo->mom[MY]) > 12)
{
mobj_t* speedMo;
int playerNum;
if((speedMo = P_SpawnMobj(MT_PLAYER_SPEED, plrmo->origin,
plrmo->angle, 0)))
{
playerNum = P_GetPlayerNum(player);
if(playerNum)
{
// Set color translation bits for player sprites.
speedMo->flags |= playerNum << MF_TRANSSHIFT; /// @todo Use configured color? -jk
}
speedMo->target = plrmo;