-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathplayer_t.java
1522 lines (1294 loc) · 45.5 KB
/
player_t.java
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
package doom;
import static data.Defines.*;
import static data.Limits.*;
import data.Tables;
import static data.Tables.*;
import static data.info.*;
import data.sounds.sfxenum_t;
import data.state_t;
import defines.*;
import doom.SourceCode.G_Game;
import static doom.SourceCode.G_Game.*;
import doom.SourceCode.P_Pspr;
import static doom.SourceCode.P_Pspr.P_BringUpWeapon;
import static doom.SourceCode.P_Pspr.P_SetPsprite;
import static doom.SourceCode.P_Pspr.P_SetupPsprites;
import static doom.items.weaponinfo;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import static m.fixed_t.*;
import p.ActiveStates.PlayerSpriteConsumer;
import p.mobj_t;
import static p.mobj_t.*;
import p.pspdef_t;
import rr.sector_t;
import utils.C2JUtils;
import static utils.C2JUtils.*;
import static utils.GenericCopy.malloc;
import v.graphics.Palettes;
import w.DoomBuffer;
import w.DoomIO;
import w.IPackableDoomObject;
import w.IReadableDoomObject;
/**
* Extended player object info: player_t The player data structure depends on a
* number of other structs: items (internal inventory), animation states
* (closely tied to the sprites used to represent them, unfortunately).
*
* #include "d_items.h"
* #include "p_pspr.h"
*
* In addition, the player is just a special
* case of the generic moving object/actor.
* NOTE: this doesn't mean it needs to extend it, although it would be
* possible.
*
* #include "p_mobj.h"
*
* Finally, for odd reasons, the player input is buffered within
* the player data struct, as commands per game tick.
*
* #include "d_ticcmd.h"
*/
public class player_t /*extends mobj_t */ implements Cloneable, IReadableDoomObject, IPackableDoomObject {
/**
* Probably doomguy needs to know what the fuck is going on
*/
private final DoomMain<?, ?> DOOM;
/* Fugly hack to "reset" the player. Not worth the fugliness.
public static player_t nullplayer;
static {
nullplayer = new player_t();
}
*/
public player_t(DoomMain DOOM) {
this.DOOM = DOOM;
powers = new int[NUMPOWERS];
frags = new int[MAXPLAYERS];
ammo = new int[NUMAMMO];
//maxammo = new int[NUMAMMO];
maxammo = new int[NUMAMMO];
cards = new boolean[card_t.NUMCARDS.ordinal()];
weaponowned = new boolean[NUMWEAPONS];
psprites = malloc(pspdef_t::new, pspdef_t[]::new, NUMPSPRITES);
this.mo = mobj_t.createOn(DOOM);
// If a player doesn't reference himself through his object, he will have an existential crisis.
this.mo.player = this;
readyweapon = weapontype_t.wp_fist;
this.cmd = new ticcmd_t();
//weaponinfo=new weaponinfo_t();
}
public final static int CF_NOCLIP = 1; // No damage, no health loss.
public final static int CF_GODMODE = 2;
public final static int CF_NOMOMENTUM = 4; // Not really a cheat, just a debug aid.
/**
* The "mobj state" of the player is stored here, even though he "inherits"
* all mobj_t properties (except being a thinker). However, for good or bad,
* his mobj properties are modified by accessing player.mo
*/
public mobj_t mo;
/**
* playerstate_t
*/
public int playerstate;
public ticcmd_t cmd;
/**
* Determine POV, including viewpoint bobbing during movement. (fixed_t)
* Focal origin above r.z
*/
public int viewz;
/**
* (fixed_t) Base height above floor for viewz.
*/
public int viewheight;
/**
* (fixed_t) Bob/squat speed.
*/
public int deltaviewheight;
/**
* (fixed_t) bounded/scaled total momentum.
*/
public int bob;
// Heretic stuff
public int flyheight;
public int lookdir;
public boolean centering;
/**
* This is only used between levels, mo->health is used during levels.
* CORRECTION: this is also used by the automap widget.
* MAES: fugly hax, as even passing "Integers" won't work, as they are immutable.
* Fuck that, I'm doing it the fugly MPI Java way!
*/
public int[] health = new int[1];
/**
* has to be passed around :-(
*/
public int[] armorpoints = new int[1];
/**
* Armor type is 0-2.
*/
public int armortype;
/**
* Power ups. invinc and invis are tic counters.
*/
public int[] powers;
public boolean[] cards;
public boolean backpack;
// Frags, kills of other players.
public int[] frags;
public weapontype_t readyweapon;
// Is wp_nochange if not changing.
public weapontype_t pendingweapon;
public boolean[] weaponowned;
public int[] ammo;
public int[] maxammo;
/**
* True if button down last tic.
*/
public boolean attackdown;
public boolean usedown;
// Bit flags, for cheats and debug.
// See cheat_t, above.
public int cheats;
// Refired shots are less accurate.
public int refire;
// For intermission stats.
public int killcount;
public int itemcount;
public int secretcount;
// Hint messages.
public String message;
// For screen flashing (red or bright).
public int damagecount;
public int bonuscount;
// Who did damage (NULL for floors/ceilings).
public mobj_t attacker;
// So gun flashes light up areas.
public int extralight;
/**
* Current PLAYPAL, ??? can be set to REDCOLORMAP for pain, etc. MAES: "int"
* my ass. It's yet another pointer alias into colormaps. Ergo, array and
* pointer.
*/
// public byte[] fixedcolormap;
/**
* *NOT* preshifted index of colormap in light color maps.
* It could be written when the player_t object is packed. Dont shift this value,
* do shifts after retrieving this.
*/
public int fixedcolormap;
// Player skin colorshift,
// 0-3 for which color to draw player.
public int colormap;
// TODO: Overlay view sprites (gun, etc).
public pspdef_t[] psprites;
// True if secret level has been done.
public boolean didsecret;
/**
* It's probably faster to clone the null player
*/
public void reset() {
memset(ammo, 0, ammo.length);
memset(armorpoints, 0, armorpoints.length);
memset(cards, false, cards.length);
memset(frags, 0, frags.length);
memset(health, 0, health.length);
memset(maxammo, 0, maxammo.length);
memset(powers, 0, powers.length);
memset(weaponowned, false, weaponowned.length);
//memset(psprites, null, psprites.length);
this.cheats = 0; // Forgot to clear up cheats flag...
this.armortype = 0;
this.attackdown = false;
this.attacker = null;
this.backpack = false;
this.bob = 0;
}
@Override
public player_t clone()
throws CloneNotSupportedException {
return (player_t) super.clone();
}
/**
* 16 pixels of bob
*/
private static int MAXBOB = 0x100000;
/**
* P_Thrust Moves the given origin along a given angle.
*
* @param angle
* (angle_t)
* @param move
* (fixed_t)
*/
public void Thrust(long angle, int move) {
mo.momx += FixedMul(move, finecosine(angle));
mo.momy += FixedMul(move, finesine(angle));
}
protected final static int PLAYERTHRUST = 2048 / TIC_MUL;
/**
* P_MovePlayer
*/
public void MovePlayer() {
ticcmd_t cmd = this.cmd;
mo.angle += (cmd.angleturn << 16);
mo.angle &= BITS32;
// Do not let the player control movement
// if not onground.
onground = (mo.z <= mo.floorz);
if (cmd.forwardmove != 0 && onground) {
Thrust(mo.angle, cmd.forwardmove * PLAYERTHRUST);
}
if (cmd.sidemove != 0 && onground) {
Thrust((mo.angle - ANG90) & BITS32, cmd.sidemove * PLAYERTHRUST);
}
if ((cmd.forwardmove != 0 || cmd.sidemove != 0)
&& mo.mobj_state == states[statenum_t.S_PLAY.ordinal()]) {
this.mo.SetMobjState(statenum_t.S_PLAY_RUN1);
}
// Freelook code ripped off Heretic. Sieg heil!
int look = cmd.lookfly & 15;
if (look > 7) {
look -= 16;
}
if (look != 0) {
if (look == TOCENTER) {
centering = true;
} else {
lookdir += 5 * look;
if (lookdir > 90 || lookdir < -110) {
lookdir -= 5 * look;
}
}
}
// Centering is done over several tics
if (centering) {
if (lookdir > 0) {
lookdir -= 8;
} else if (lookdir < 0) {
lookdir += 8;
}
if (Math.abs(lookdir) < 8) {
lookdir = 0;
centering = false;
}
}
/* Flight stuff from Heretic
fly = cmd.lookfly>>4;
if(fly > 7)
{
fly -= 16;
}
if(fly && player->powers[pw_flight])
{
if(fly != TOCENTER)
{
player->flyheight = fly*2;
if(!(player->mo->flags2&MF2_FLY))
{
player->mo->flags2 |= MF2_FLY;
player->mo->flags |= MF_NOGRAVITY;
}
}
else
{
player->mo->flags2 &= ~MF2_FLY;
player->mo->flags &= ~MF_NOGRAVITY;
}
}
else if(fly > 0)
{
P_PlayerUseArtifact(player, arti_fly);
}
if(player->mo->flags2&MF2_FLY)
{
player->mo->momz = player->flyheight*FRACUNIT;
if(player->flyheight)
{
player->flyheight /= 2;
}
} */
}
//
// GET STUFF
//
// a weapon is found with two clip loads,
// a big item has five clip loads
public static final int[] clipammo = {10, 4, 20, 1};
/**
* P_GiveAmmo Num is the number of clip loads, not the individual count (0=
* 1/2 clip).
*
* @return false if the ammo can't be picked up at all
* @param ammo
* intended to be ammotype_t.
*/
public boolean GiveAmmo(ammotype_t amm, int num) {
int oldammo;
int ammo = amm.ordinal();
if (ammo == ammotype_t.am_noammo.ordinal()) {
return false;
}
if (ammo < 0 || ammo > NUMAMMO) {
DOOM.doomSystem.Error("P_GiveAmmo: bad type %i", ammo);
}
if (this.ammo[ammo] == maxammo[ammo]) {
return false;
}
if (num != 0) {
num *= clipammo[ammo];
} else {
num = clipammo[ammo] / 2;
}
if (DOOM.gameskill == skill_t.sk_baby
|| DOOM.gameskill == skill_t.sk_nightmare) {
// give double ammo in trainer mode,
// you'll need in nightmare
num <<= 1;
}
oldammo = this.ammo[ammo];
this.ammo[ammo] += num;
if (this.ammo[ammo] > maxammo[ammo]) {
this.ammo[ammo] = maxammo[ammo];
}
// If non zero ammo,
// don't change up weapons,
// player was lower on purpose.
if (oldammo != 0) {
return true;
}
// We were down to zero,
// so select a new weapon.
// Preferences are not user selectable.
switch (ammotype_t.values()[ammo]) {
case am_clip:
if (readyweapon == weapontype_t.wp_fist) {
if (weaponowned[weapontype_t.wp_chaingun.ordinal()]) {
pendingweapon = weapontype_t.wp_chaingun;
} else {
pendingweapon = weapontype_t.wp_pistol;
}
}
break;
case am_shell:
if (readyweapon == weapontype_t.wp_fist
|| readyweapon == weapontype_t.wp_pistol) {
if (weaponowned[weapontype_t.wp_shotgun.ordinal()]) {
pendingweapon = weapontype_t.wp_shotgun;
}
}
break;
case am_cell:
if (readyweapon == weapontype_t.wp_fist
|| readyweapon == weapontype_t.wp_pistol) {
if (weaponowned[weapontype_t.wp_plasma.ordinal()]) {
pendingweapon = weapontype_t.wp_plasma;
}
}
break;
case am_misl:
if (readyweapon == weapontype_t.wp_fist) {
if (weaponowned[weapontype_t.wp_missile.ordinal()]) {
pendingweapon = weapontype_t.wp_missile;
}
}
default:
break;
}
return true;
}
public static final int BONUSADD = 6;
/**
* P_GiveWeapon
* The weapon name may have a MF_DROPPED flag ored in.
*/
public boolean GiveWeapon(weapontype_t weapn, boolean dropped) {
boolean gaveammo;
boolean gaveweapon;
int weapon = weapn.ordinal();
if (DOOM.netgame && (DOOM.deathmatch != true) // ???? was "2"
&& !dropped) {
// leave placed weapons forever on net games
if (weaponowned[weapon]) {
return false;
}
bonuscount += BONUSADD;
weaponowned[weapon] = true;
if (DOOM.deathmatch) {
GiveAmmo(weaponinfo[weapon].ammo, 5);
} else {
GiveAmmo(weaponinfo[weapon].ammo, 2);
}
pendingweapon = weapn;
if (this == DOOM.players[DOOM.consoleplayer]) {
DOOM.doomSound.StartSound(null, sfxenum_t.sfx_wpnup);
}
return false;
}
if (weaponinfo[weapon].ammo != ammotype_t.am_noammo) {
// give one clip with a dropped weapon,
// two clips with a found weapon
if (dropped) {
gaveammo = GiveAmmo(weaponinfo[weapon].ammo, 1);
} else {
gaveammo = GiveAmmo(weaponinfo[weapon].ammo, 2);
}
} else {
gaveammo = false;
}
if (weaponowned[weapon]) {
gaveweapon = false;
} else {
gaveweapon = true;
weaponowned[weapon] = true;
pendingweapon = weapn;
}
return (gaveweapon || gaveammo);
}
/**
* P_GiveBody Returns false if the body isn't needed at all
*/
public boolean GiveBody(int num) {
if (this.health[0] >= MAXHEALTH) {
return false;
}
health[0] += num;
if (health[0] > MAXHEALTH) {
health[0] = MAXHEALTH;
}
mo.health = health[0];
return true;
}
/**
* P_GiveArmor Returns false if the armor is worse than the current armor.
*/
public boolean GiveArmor(int armortype) {
int hits;
hits = armortype * 100;
if (armorpoints[0] >= hits) {
return false; // don't pick up
}
this.armortype = armortype;
armorpoints[0] = hits;
return true;
}
/**
* P_GiveCard
*/
public void GiveCard(card_t crd) {
int card = crd.ordinal();
if (cards[card]) {
return;
}
bonuscount = BONUSADD;
cards[card] = true;
}
//
// P_GivePower
//
public boolean GivePower(int /* powertype_t */ power) // MAES:
// I
// didn't
// change
// this!
{
if (power == pw_invulnerability) {
powers[power] = INVULNTICS;
return true;
}
if (power == pw_invisibility) {
powers[power] = INVISTICS;
mo.flags |= MF_SHADOW;
return true;
}
if (power == pw_infrared) {
powers[power] = INFRATICS;
return true;
}
if (power == pw_ironfeet) {
powers[power] = IRONTICS;
return true;
}
if (power == pw_strength) {
GiveBody(100);
powers[power] = 1;
return true;
}
if (powers[power] != 0) {
return false; // already got it
}
powers[power] = 1;
return true;
}
/**
* G_PlayerFinishLevel
* Called when a player completes a level.
*/
@SourceCode.Compatible
@G_Game.C(G_PlayerFinishLevel)
public final void PlayerFinishLevel() {
memset(powers, 0, powers.length);
memset(cards, false, cards.length);
mo.flags &= ~mobj_t.MF_SHADOW; // cancel invisibility
extralight = 0; // cancel gun flashes
fixedcolormap = Palettes.COLORMAP_FIXED; // cancel ir gogles
damagecount = 0; // no palette changes
bonuscount = 0;
lookdir = 0; // From heretic
}
/**
* P_PlayerInSpecialSector
* Called every tic frame
* that the player origin is in a special sector
*/
protected void PlayerInSpecialSector() {
sector_t sector;
sector = mo.subsector.sector;
// Falling, not all the way down yet?
if (mo.z != sector.floorheight) {
return;
}
// Has hitten ground.
switch (sector.special) {
case 5:
// HELLSLIME DAMAGE
if (powers[pw_ironfeet] == 0) {
if (!flags(DOOM.leveltime, 0x1f)) {
DOOM.actions.DamageMobj(mo, null, null, 10);
}
}
break;
case 7:
// NUKAGE DAMAGE
if (powers[pw_ironfeet] == 0) {
if (!flags(DOOM.leveltime, 0x1f)) {
DOOM.actions.DamageMobj(mo, null, null, 5);
}
}
break;
case 16:
// SUPER HELLSLIME DAMAGE
case 4:
// STROBE HURT
if (!eval(powers[pw_ironfeet])
|| (DOOM.random.P_Random() < 5)) {
if (!flags(DOOM.leveltime, 0x1f)) {
DOOM.actions.DamageMobj(mo, null, null, 20);
}
}
break;
case 9:
// SECRET SECTOR
secretcount++;
sector.special = 0;
break;
case 11:
// EXIT SUPER DAMAGE! (for E1M8 finale)
cheats &= ~CF_GODMODE;
if (!flags(DOOM.leveltime, 0x1f)) {
DOOM.actions.DamageMobj(mo, null, null, 20);
}
if (health[0] <= 10) {
DOOM.ExitLevel();
}
break;
default:
DOOM.doomSystem.Error("P_PlayerInSpecialSector: unknown special %d", sector.special);
break;
};
}
//
//P_CalcHeight
//Calculate the walking / running height adjustment
//
public void CalcHeight() {
int angle;
int bob; // fixed
// Regular movement bobbing
// (needs to be calculated for gun swing
// even if not on ground)
// OPTIMIZE: tablify angle
// Note: a LUT allows for effects
// like a ramp with low health.
this.bob
= FixedMul(mo.momx, mo.momx)
+ FixedMul(mo.momy, mo.momy);
this.bob >>= 2;
if (this.bob > MAXBOB) {
this.bob = MAXBOB;
}
if (flags(cheats, CF_NOMOMENTUM) || !onground) {
viewz = mo.z + VIEWHEIGHT;
if (viewz > mo.ceilingz - 4 * FRACUNIT) {
viewz = mo.ceilingz - 4 * FRACUNIT;
}
viewz = mo.z + viewheight;
return;
}
angle = (FINEANGLES / 20 * DOOM.leveltime) & FINEMASK;
bob = FixedMul(this.bob / 2, finesine[angle]);
// move viewheight
if (playerstate == PST_LIVE) {
viewheight += deltaviewheight;
if (viewheight > VIEWHEIGHT) {
viewheight = VIEWHEIGHT;
deltaviewheight = 0;
}
if (viewheight < VIEWHEIGHT / 2) {
viewheight = VIEWHEIGHT / 2;
if (deltaviewheight <= 0) {
deltaviewheight = 1;
}
}
if (deltaviewheight != 0) {
deltaviewheight += FRACUNIT / 4;
if (deltaviewheight == 0) {
deltaviewheight = 1;
}
}
}
viewz = mo.z + viewheight + bob;
if (viewz > mo.ceilingz - 4 * FRACUNIT) {
viewz = mo.ceilingz - 4 * FRACUNIT;
}
}
private static final long ANG5 = (ANG90 / 18);
/**
* P_DeathThink
* Fall on your face when dying.
* Decrease POV height to floor height.
*
* DOOMGUY IS SO AWESOME THAT HE THINKS EVEN WHEN DEAD!!!
*
*/
public void DeathThink() {
long angle; //angle_t
long delta;
MovePsprites();
// fall to the ground
if (viewheight > 6 * FRACUNIT) {
viewheight -= FRACUNIT;
}
if (viewheight < 6 * FRACUNIT) {
viewheight = 6 * FRACUNIT;
}
deltaviewheight = 0;
onground = (mo.z <= mo.floorz);
CalcHeight();
if (attacker != null && attacker != mo) {
angle = DOOM.sceneRenderer.PointToAngle2(mo.x,
mo.y,
attacker.x,
attacker.y);
delta = Tables.addAngles(angle, -mo.angle);
if (delta < ANG5 || delta > -ANG5) {
// Looking at killer,
// so fade damage flash down.
mo.angle = angle;
if (damagecount != 0) {
damagecount--;
}
} else if (delta < ANG180) {
mo.angle += ANG5;
} else {
mo.angle -= ANG5;
}
} else if (damagecount != 0) {
damagecount--;
}
if (flags(cmd.buttons, BT_USE)) {
playerstate = PST_REBORN;
}
}
//
// P_MovePsprites
// Called every tic by player thinking routine.
//
public void MovePsprites() {
pspdef_t psp;
@SuppressWarnings("unused") // Shut up compiler
state_t state = null;
for (int i = 0; i < NUMPSPRITES; i++) {
psp = psprites[i];
// a null state means not active
if ((state = psp.state) != null) {
// drop tic count and possibly change state
// a -1 tic count never changes
if (psp.tics != -1) {
psp.tics--;
if (!eval(psp.tics)) {
this.SetPsprite(i, psp.state.nextstate);
}
}
}
}
psprites[ps_flash].sx = psprites[ps_weapon].sx;
psprites[ps_flash].sy = psprites[ps_weapon].sy;
}
/**
* P_SetPsprite
*/
@SourceCode.Exact
@P_Pspr.C(P_SetPsprite)
public void SetPsprite(int position, statenum_t newstate) {
final pspdef_t psp;
state_t state;
psp = psprites[position];
do {
if (!eval(newstate)) {
// object removed itself
psp.state = null;
break;
}
state = states[newstate.ordinal()];
psp.state = state;
psp.tics = state.tics; // could be 0
if (eval(state.misc1)) {
// coordinate set
psp.sx = state.misc1 << FRACBITS;
psp.sy = state.misc2 << FRACBITS;
}
// Call action routine.
// Modified handling.
if (state.action.isParamType(PlayerSpriteConsumer.class)) {
state.action.fun(PlayerSpriteConsumer.class).accept(DOOM.actions, this, psp);
if (!eval(psp.state)) {
break;
}
}
newstate = psp.state.nextstate;
} while (!eval(psp.tics));
// an initial state of 0 could cycle through
}
/**
* Accessory method to identify which "doomguy" we are.
* Because we can't use the [target.player-players] syntax
* in order to get an array index, in Java.
*
* If -1 is returned, then we have existential problems.
*
*/
public int identify() {
if (id >= 0) {
return id;
}
int i;
// Let's assume that we know jack.
for (i = 0; i < DOOM.players.length; i++) {
if (this == DOOM.players[i]) {
break;
}
}
return id = i;
}
private int id = -1;
private boolean onground;
/* psprnum_t enum */
public static int ps_weapon = 0,
ps_flash = 1,
NUMPSPRITES = 2;
public static int LOWERSPEED = MAPFRACUNIT * 6;
public static int RAISESPEED = MAPFRACUNIT * 6;
public static int WEAPONBOTTOM = 128 * FRACUNIT;
public static int WEAPONTOP = 32 * FRACUNIT;
// plasma cells for a bfg attack
private static int BFGCELLS = 40;
/*
P_SetPsprite
public void
SetPsprite
( player_t player,
int position,
statenum_t newstate )
{
pspdef_t psp;
state_t state;
psp = psprites[position];
do
{
if (newstate==null)
{
// object removed itself
psp.state = null;
break;
}
state = states[newstate.ordinal()];
psp.state = state;
psp.tics = (int) state.tics; // could be 0
if (state.misc1!=0)
{
// coordinate set
psp.sx = (int) (state.misc1 << FRACBITS);
psp.sy = (int) (state.misc2 << FRACBITS);
}
// Call action routine.
// Modified handling.
if (state.action.getType()==acp2)
{
P.A.dispatch(state.action,this, psp);
if (psp.state==null)
break;
}
newstate = psp.state.nextstate;