Debian Codegraph @

prboom2/src/p_user.c

raw
1 /* Emacs style mode select -*- C -*-
2 *-----------------------------------------------------------------------------
3 *
4 *
5 * PrBoom: a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2000 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11 * Copyright 2005, 2006 by
12 * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 * 02111-1307, USA.
28 *
29 * DESCRIPTION:
30 * Player related stuff.
31 * Bobbing POV/weapon, movement.
32 * Pending weapon.
33 *
34 *-----------------------------------------------------------------------------*/
35
36 #include <math.h>
37
38 #include "doomstat.h"
39 #include "d_event.h"
40 #include "r_main.h"
41 #include "lprintf.h"
42 #include "p_map.h"
43 #include "p_maputl.h"
44 #include "p_enemy.h"
45 #include "p_spec.h"
46 #include "p_user.h"
47 #include "smooth.h"
48 #include "r_fps.h"
49 #include "g_game.h"
50 #include "p_tick.h"
51 #include "e6y.h"//e6y
52
53 #include "dsda/aim.h"
54 #include "dsda/death.h"
55 #include "dsda/excmd.h"
56 #include "dsda/map_format.h"
57 #include "dsda/mapinfo.h"
58 #include "dsda/settings.h"
59
60 // heretic needs
61 #include "heretic/def.h"
62 #include "s_sound.h"
63 #include "sounds.h"
64 #include "p_inter.h"
65 #include "m_random.h"
66
67 //
68 // Movement.
69 //
70
71 // 16 pixels of bob
72
73 #define MAXBOB 0x100000
74
75 dboolean onground; // whether player is on ground or in air
76
77 // heretic
78 int newtorch; // used in the torch flicker effect.
79 int newtorchdelta;
80
81 fixed_t P_PlayerSpeed(player_t* player)
82 {
83 double vx, vy;
84
85 vx = (double) player->mo->momx / FRACUNIT;
86 vy = (double) player->mo->momy / FRACUNIT;
87
88 return (fixed_t) (sqrt(vx * vx + vy * vy) * FRACUNIT);
89 }
90
91 //
92 // P_Thrust
93 // Moves the given origin along a given angle.
94 //
95
96 void P_CompatiblePlayerThrust(player_t* player, angle_t angle, fixed_t move)
97 {
98 player->mo->momx += FixedMul(move, finecosine[angle]);
99 player->mo->momy += FixedMul(move, finesine[angle]);
100 }
101
102 void P_HereticPlayerThrust(player_t* player, angle_t angle, fixed_t move)
103 {
104 if (player->powers[pw_flight] && !(player->mo->z <= player->mo->floorz))
105 {
106 player->mo->momx += FixedMul(move, finecosine[angle]);
107 player->mo->momy += FixedMul(move, finesine[angle]);
108 }
109 else if (player->mo->subsector->sector->special == 15)
110 {
111 player->mo->momx += FixedMul(move >> 2, finecosine[angle]);
112 player->mo->momy += FixedMul(move >> 2, finesine[angle]);
113 }
114 else
115 {
116 player->mo->momx += FixedMul(move, finecosine[angle]);
117 player->mo->momy += FixedMul(move, finesine[angle]);
118 }
119 }
120
121 void P_HexenPlayerThrust(player_t* player, angle_t angle, fixed_t move)
122 {
123 if (player->powers[pw_flight] && !(player->mo->z <= player->mo->floorz))
124 {
125 player->mo->momx += FixedMul(move, finecosine[angle]);
126 player->mo->momy += FixedMul(move, finesine[angle]);
127 }
128 else if (P_GetThingFloorType(player->mo) == FLOOR_ICE) // Friction_Low
129 {
130 player->mo->momx += FixedMul(move >> 1, finecosine[angle]);
131 player->mo->momy += FixedMul(move >> 1, finesine[angle]);
132 }
133 else
134 {
135 player->mo->momx += FixedMul(move, finecosine[angle]);
136 player->mo->momy += FixedMul(move, finesine[angle]);
137 }
138 }
139
140 // In doom, P_Thrust is always player-originated
141 // In heretic / hexen P_Thrust can come from effects
142 // Need to differentiate the two because of the flight cheat
143 void P_ForwardThrust(player_t* player,angle_t angle,fixed_t move)
144 {
145 angle >>= ANGLETOFINESHIFT;
146
147 if ((player->mo->flags & MF_FLY) && player->mo->pitch != 0)
148 {
149 angle_t pitch = player->mo->pitch >> ANGLETOFINESHIFT;
150 fixed_t zpush = FixedMul(move, finesine[pitch]);
151 player->mo->momz -= zpush;
152 move = FixedMul(move, finecosine[pitch]);
153 }
154
155 map_format.player_thrust(player, angle, move);
156 }
157
158 void P_Thrust(player_t* player,angle_t angle,fixed_t move)
159 {
160 angle >>= ANGLETOFINESHIFT;
161
162 map_format.player_thrust(player, angle, move);
163 }
164
165 /*
166 * P_Bob
167 * Same as P_Thrust, but only affects bobbing.
168 *
169 * killough 10/98: We apply thrust separately between the real physical player
170 * and the part which affects bobbing. This way, bobbing only comes from player
171 * motion, nothing external, avoiding many problems, e.g. bobbing should not
172 * occur on conveyors, unless the player walks on one, and bobbing should be
173 * reduced at a regular rate, even on ice (where the player coasts).
174 */
175
176 static void P_Bob(player_t *player, angle_t angle, fixed_t move)
177 {
178 //e6y
179 if (!mbf_features && !prboom_comp[PC_PRBOOM_FRICTION].state)
180 return;
181
182 player->momx += FixedMul(move,finecosine[angle >>= ANGLETOFINESHIFT]);
183 player->momy += FixedMul(move,finesine[angle]);
184 }
185
186 //
187 // P_CalcHeight
188 // Calculate the walking / running height adjustment
189 //
190
191 void P_CalcHeight (player_t* player)
192 {
193 int angle;
194 fixed_t bob;
195
196 // Regular movement bobbing
197 // (needs to be calculated for gun swing
198 // even if not on ground)
199 // OPTIMIZE: tablify angle
200 // Note: a LUT allows for effects
201 // like a ramp with low health.
202
203
204 /* killough 10/98: Make bobbing depend only on player-applied motion.
205 *
206 * Note: don't reduce bobbing here if on ice: if you reduce bobbing here,
207 * it causes bobbing jerkiness when the player moves from ice to non-ice,
208 * and vice-versa.
209 */
210
211 player->bob = 0;
212
213 if ((player->mo->flags & MF_FLY) && !onground)
214 {
215 player->bob = FRACUNIT / 2;
216 }
217
218 if (mbf_features)
219 {
220 if (player_bobbing)
221 {
222 player->bob = (FixedMul(player->momx, player->momx) +
223 FixedMul(player->momy, player->momy)) >> 2;
224 }
225 }
226 else
227 {
228 if (demo_compatibility || player_bobbing || prboom_comp[PC_FORCE_INCORRECT_BOBBING_IN_BOOM].state)
229 {
230 player->bob = (FixedMul(player->mo->momx, player->mo->momx) +
231 FixedMul(player->mo->momy, player->mo->momy)) >> 2;
232 }
233 }
234
235 //e6y
236 if (!prboom_comp[PC_PRBOOM_FRICTION].state &&
237 compatibility_level >= boom_202_compatibility &&
238 compatibility_level <= lxdoom_1_compatibility &&
239 player->mo->friction > ORIG_FRICTION) // ice?
240 {
241 if (player->bob > (MAXBOB >> 2))
242 player->bob = MAXBOB >> 2;
243 }
244 else
245 {
246 if (player->bob > MAXBOB)
247 player->bob = MAXBOB;
248 }
249
250 if (player->mo->flags2 & MF2_FLY && !onground)
251 {
252 player->bob = FRACUNIT / 2;
253 }
254
255 if (!onground && !raven)
256 {
257 player->viewz = player->mo->z + g_viewheight;
258
259 if (player->viewz > player->mo->ceilingz - 4 * FRACUNIT)
260 player->viewz = player->mo->ceilingz - 4 * FRACUNIT;
261
262 return;
263 }
264
265 angle = (FINEANGLES / 20 * leveltime) & FINEMASK;
266 bob = player->bob * dsda_ViewBob() / 4;
267 bob = FixedMul(bob / 2, finesine[angle]);
268
269 // move viewheight
270
271 if (player->playerstate == PST_LIVE)
272 {
273 player->viewheight += player->deltaviewheight;
274
275 if (player->viewheight > g_viewheight)
276 {
277 player->viewheight = g_viewheight;
278 player->deltaviewheight = 0;
279 }
280
281 if (player->viewheight < g_viewheight / 2)
282 {
283 player->viewheight = g_viewheight / 2;
284 if (player->deltaviewheight <= 0)
285 player->deltaviewheight = 1;
286 }
287
288 if (player->deltaviewheight)
289 {
290 player->deltaviewheight += FRACUNIT / 4;
291 if (!player->deltaviewheight)
292 player->deltaviewheight = 1;
293 }
294 }
295
296 if (player->chickenTics || player->morphTics)
297 {
298 player->viewz = player->mo->z + player->viewheight - (20 * FRACUNIT);
299 }
300 else
301 {
302 player->viewz = player->mo->z + player->viewheight + bob;
303 }
304
305 if (player->playerstate != PST_DEAD && player->mo->z <= player->mo->floorz)
306 {
307 if (player->mo->floorclip)
308 player->viewz -= player->mo->floorclip;
309 else if (player->mo->flags2 & MF2_FEETARECLIPPED)
310 player->viewz -= FOOTCLIPSIZE;
311 }
312
313 if (player->viewz > player->mo->ceilingz - 4 * FRACUNIT)
314 player->viewz = player->mo->ceilingz - 4 * FRACUNIT;
315
316 if (heretic && player->viewz < player->mo->floorz + 4 * FRACUNIT)
317 player->viewz = player->mo->floorz + 4 * FRACUNIT;
318 }
319
320 //
321 // P_MovePlayer
322 //
323 // Adds momentum if the player is not in the air
324 //
325 // killough 10/98: simplified
326
327 void P_HandleExCmdLook(player_t* player)
328 {
329 int look;
330
331 look = player->cmd.ex.look;
332 if (look)
333 {
334 if (look == XC_LOOK_RESET)
335 {
336 player->mo->pitch = 0;
337 }
338 else
339 {
340 player->mo->pitch += look << 16;
341 CheckPitch((signed int *) &player->mo->pitch);
342 }
343 }
344 }
345
346 void P_MovePlayer (player_t* player)
347 {
348 ticcmd_t *cmd;
349 mobj_t *mo;
350
351 P_HandleExCmdLook(player);
352
353 if (raven) return Raven_P_MovePlayer(player);
354
355 cmd = &player->cmd;
356 mo = player->mo;
357 mo->angle += cmd->angleturn << 16;
358
359 if (demo_smoothturns && player == &players[displayplayer])
360 {
361 R_SmoothPlaying_Add(cmd->angleturn << 16);
362 }
363
364 onground = (mo->z <= mo->floorz || mo->flags2 & MF2_ONMOBJ);
365
366 if ((player->mo->flags & MF_FLY) && player == &players[consoleplayer] && upmove != 0)
367 {
368 mo->momz = upmove << 8;
369 }
370
371 // killough 10/98:
372 //
373 // We must apply thrust to the player and bobbing separately, to avoid
374 // anomalies. The thrust applied to bobbing is always the same strength on
375 // ice, because the player still "works just as hard" to move, while the
376 // thrust applied to the movement varies with 'movefactor'.
377
378 //e6y
379 if ((!demo_compatibility && !mbf_features && !prboom_comp[PC_PRBOOM_FRICTION].state) ||
380 (cmd->forwardmove | cmd->sidemove)) // killough 10/98
381 {
382 if (onground || mo->flags & MF_BOUNCES || (mo->flags & MF_FLY)) // killough 8/9/98
383 {
384 int friction, movefactor = P_GetMoveFactor(mo, &friction);
385
386 // killough 11/98:
387 // On sludge, make bobbing depend on efficiency.
388 // On ice, make it depend on effort.
389
390 int bobfactor =
391 friction < ORIG_FRICTION ? movefactor : ORIG_FRICTION_FACTOR;
392
393 if (map_format.zdoom && !movefactor)
394 bobfactor = movefactor;
395
396 if (cmd->forwardmove)
397 {
398 P_Bob(player,mo->angle,cmd->forwardmove*bobfactor);
399 P_ForwardThrust(player,mo->angle,cmd->forwardmove*movefactor);
400 }
401
402 if (cmd->sidemove)
403 {
404 P_Bob(player,mo->angle-ANG90,cmd->sidemove*bobfactor);
405 P_Thrust(player,mo->angle-ANG90,cmd->sidemove*movefactor);
406 }
407 }
408 else if (map_info.air_control)
409 {
410 int friction, movefactor = P_GetMoveFactor(mo, &friction);
411
412 movefactor = FixedMul(movefactor, map_info.air_control);
413
414 if (cmd->forwardmove)
415 {
416 P_Bob(player, mo->angle, cmd->forwardmove * movefactor);
417 P_Thrust(player, player->mo->angle, cmd->forwardmove * movefactor);
418 }
419
420 if (cmd->sidemove)
421 {
422 P_Bob(player, mo->angle - ANG90, cmd->sidemove * movefactor);
423 P_Thrust(player, player->mo->angle - ANG90, cmd->sidemove * movefactor);
424 }
425 }
426 if (mo->state == states+S_PLAY)
427 P_SetMobjState(mo,S_PLAY_RUN1);
428 }
429 }
430
431 #define ANG5 (ANG90/18)
432
433 //
434 // P_DeathThink
435 // Fall on your face when dying.
436 // Decrease POV height to floor height.
437 //
438
439 void P_DeathThink (player_t* player)
440 {
441 angle_t angle;
442 angle_t delta;
443
444 P_MovePsprites(player);
445
446 // fall to the ground
447
448 onground = (player->mo->z <= player->mo->floorz);
449 if (player->mo->type == g_skullpop_mt || (hexen && player->mo->type == HEXEN_MT_ICECHUNK))
450 {
451 // Flying bloody skull
452 player->viewheight = 6*FRACUNIT;
453 player->deltaviewheight = 0;
454 if (onground)
455 {
456 if (raven && !dsda_FreeAim())
457 {
458 if (player->lookdir < 60)
459 {
460 int lookDelta;
461
462 lookDelta = (60 - player->lookdir) / 8;
463 if (lookDelta < 1 && (leveltime & 1))
464 {
465 lookDelta = 1;
466 }
467 else if (lookDelta > 6)
468 {
469 lookDelta = 6;
470 }
471 player->lookdir += lookDelta;
472 }
473 }
474 else if ((int)player->mo->pitch > -(int)ANG1*19)
475 {
476 player->mo->pitch -= ((int)ANG1*19 - player->mo->pitch) / 8;
477 }
478 }
479 }
480 else if (!(player->mo->flags2 & MF2_ICEDAMAGE))
481 {
482 if (player->viewheight > 6*FRACUNIT)
483 player->viewheight -= FRACUNIT;
484
485 if (player->viewheight < 6*FRACUNIT)
486 player->viewheight = 6*FRACUNIT;
487
488 player->deltaviewheight = 0;
489
490 if (dsda_FreeAim())
491 {
492 const int delta = dsda_LookDirToPitch(-6);
493
494 if ((int) player->mo->pitch > 0)
495 {
496 player->mo->pitch -= delta;
497 }
498 else if ((int) player->mo->pitch < 0)
499 {
500 player->mo->pitch += delta;
501 }
502
503 if (abs((int) player->mo->pitch) < delta)
504 {
505 player->mo->pitch = 0;
506 }
507 }
508 else
509 {
510 if (player->lookdir > 0)
511 {
512 player->lookdir -= 6;
513 }
514 else if (player->lookdir < 0)
515 {
516 player->lookdir += 6;
517 }
518 if (abs(player->lookdir) < 6)
519 {
520 player->lookdir = 0;
521 }
522 }
523 }
524
525 P_CalcHeight(player);
526
527 if (player->attacker && player->attacker != player->mo)
528 {
529 if (hexen)
530 {
531 int dir = P_FaceMobj(player->mo, player->attacker, &delta);
532 if (delta < ANG1 * 10)
533 { // Looking at killer, so fade damage and poison counters
534 if (player->damagecount)
535 {
536 player->damagecount--;
537 }
538 if (player->poisoncount)
539 {
540 player->poisoncount--;
541 }
542 }
543 delta = delta / 8;
544 if (delta > ANG1 * 5)
545 {
546 delta = ANG1 * 5;
547 }
548 if (dir)
549 { // Turn clockwise
550 player->mo->angle += delta;
551 }
552 else
553 { // Turn counter clockwise
554 player->mo->angle -= delta;
555 }
556 }
557 else
558 {
559 angle = R_PointToAngle2(player->mo->x,
560 player->mo->y,
561 player->attacker->x,
562 player->attacker->y);
563
564 delta = angle - player->mo->angle;
565
566 if (delta < ANG5 || delta > (unsigned)-ANG5)
567 {
568 // Looking at killer,
569 // so fade damage flash down.
570
571 player->mo->angle = angle;
572
573 if (player->damagecount)
574 player->damagecount--;
575 }
576 else if (delta < ANG180)
577 player->mo->angle += ANG5;
578 else
579 player->mo->angle -= ANG5;
580 }
581 }
582 else if (player->damagecount || player->poisoncount)
583 {
584 if (player->damagecount)
585 player->damagecount--;
586 else
587 player->poisoncount--;
588 }
589
590 if (player->cmd.buttons & BT_USE)
591 {
592 dsda_DeathUse(player);
593 }
594
595 R_SmoothPlaying_Reset(player); // e6y
596 }
597
598 void P_PlayerEndFlight(player_t * player)
599 {
600 if (player->mo->z != player->mo->floorz)
601 {
602 player->centering = true;
603 }
604
605 player->mo->flags2 &= ~MF2_FLY;
606 player->mo->flags &= ~MF_NOGRAVITY;
607 }
608
609 //
610 // P_PlayerThink
611 //
612
613 void P_MorphPlayerThink(player_t * player);
614
615 void P_PlayerThink (player_t* player)
616 {
617 ticcmd_t* cmd;
618 weapontype_t newweapon;
619 int floorType;
620
621 if (movement_smooth)
622 {
623 player->prev_viewz = player->viewz;
624 player->prev_viewangle = R_SmoothPlaying_Get(player);
625 player->prev_viewpitch = dsda_PlayerPitch(player);
626
627 if (&players[displayplayer] == player)
628 {
629 P_ResetWalkcam();
630 }
631 }
632
633 // killough 2/8/98, 3/21/98:
634 if (player->cheats & CF_NOCLIP)
635 player->mo->flags |= MF_NOCLIP;
636 else
637 player->mo->flags &= ~MF_NOCLIP;
638
639 // chain saw run forward
640
641 cmd = &player->cmd;
642 if (player->mo->flags & MF_JUSTATTACKED)
643 {
644 cmd->angleturn = 0;
645 cmd->forwardmove = 0xc800 / 512;
646 cmd->sidemove = 0;
647 player->mo->flags &= ~MF_JUSTATTACKED;
648 }
649
650 if (hexen)
651 player->worldTimer++;
652
653 if (player->playerstate == PST_DEAD)
654 {
655 P_DeathThink(player);
656 return;
657 }
658
659 if (player->chickenTics)
660 {
661 P_ChickenPlayerThink(player);
662 }
663
664 if (player->jumpTics)
665 {
666 player->jumpTics--;
667 }
668
669 if (player->morphTics)
670 {
671 P_MorphPlayerThink(player);
672 }
673
674 // Move around.
675 // Reactiontime is used to prevent movement
676 // for a bit after a teleport.
677
678 if (player->mo->reactiontime)
679 player->mo->reactiontime--;
680 else
681 {
682 P_MovePlayer(player);
683
684 if (hexen)
685 {
686 mobj_t *pmo = player->mo;
687 if (player->powers[pw_speed] && !(leveltime & 1)
688 && P_AproxDistance(pmo->momx, pmo->momy) > 12 * FRACUNIT)
689 {
690 mobj_t *speedMo;
691 int playerNum;
692
693 speedMo = P_SpawnMobj(pmo->x, pmo->y, pmo->z, HEXEN_MT_PLAYER_SPEED);
694 if (speedMo)
695 {
696 speedMo->angle = pmo->angle;
697 playerNum = P_GetPlayerNum(player);
698 if (player->pclass == PCLASS_FIGHTER)
699 {
700 // The first type should be blue, and the
701 // third should be the Fighter's original gold color
702 if (playerNum == 0)
703 {
704 speedMo->flags |= 2 << MF_TRANSSHIFT;
705 }
706 else if (playerNum != 2)
707 {
708 speedMo->flags |= playerNum << MF_TRANSSHIFT;
709 }
710 }
711 else if (playerNum)
712 { // Set color translation bits for player sprites
713 speedMo->flags |= playerNum << MF_TRANSSHIFT;
714 }
715 P_SetTarget(&speedMo->target, pmo);
716 speedMo->special1.i = player->pclass;
717 if (speedMo->special1.i > 2)
718 {
719 speedMo->special1.i = 0;
720 }
721 speedMo->sprite = pmo->sprite;
722 speedMo->floorclip = pmo->floorclip;
723 if (player == &players[consoleplayer])
724 {
725 speedMo->flags2 |= MF2_DONTDRAW;
726 }
727 }
728 }
729 }
730 }
731
732 P_CalcHeight (player); // Determines view height and bobbing
733
734 // Determine if there's anything about the sector you're in that's
735 // going to affect you, like painful floors.
736
737 if (P_IsSpecialSector(player->mo->subsector->sector))
738 P_PlayerInSpecialSector(player);
739
740 if (hexen)
741 {
742 if ((floorType = P_GetThingFloorType(player->mo)) != FLOOR_SOLID)
743 {
744 P_PlayerOnSpecialFlat(player, floorType);
745 }
746
747 switch (player->pclass)
748 {
749 case PCLASS_FIGHTER:
750 if (player->mo->momz <= -35 * FRACUNIT
751 && player->mo->momz >= -40 * FRACUNIT && !player->morphTics
752 && !S_GetSoundPlayingInfo(player->mo,
753 hexen_sfx_player_fighter_falling_scream))
754 {
755 S_StartMobjSound(player->mo, hexen_sfx_player_fighter_falling_scream);
756 }
757 break;
758 case PCLASS_CLERIC:
759 if (player->mo->momz <= -35 * FRACUNIT
760 && player->mo->momz >= -40 * FRACUNIT && !player->morphTics
761 && !S_GetSoundPlayingInfo(player->mo,
762 hexen_sfx_player_cleric_falling_scream))
763 {
764 S_StartMobjSound(player->mo, hexen_sfx_player_cleric_falling_scream);
765 }
766 break;
767 case PCLASS_MAGE:
768 if (player->mo->momz <= -35 * FRACUNIT
769 && player->mo->momz >= -40 * FRACUNIT && !player->morphTics
770 && !S_GetSoundPlayingInfo(player->mo,
771 hexen_sfx_player_mage_falling_scream))
772 {
773 S_StartMobjSound(player->mo, hexen_sfx_player_mage_falling_scream);
774 }
775 break;
776 default:
777 break;
778 }
779
780 if (cmd->arti)
781 { // Use an artifact
782 if ((cmd->arti & AFLAG_JUMP) && onground && !player->jumpTics)
783 {
784 if (player->morphTics)
785 {
786 player->mo->momz = 6 * FRACUNIT;
787 }
788 else
789 {
790 player->mo->momz = 9 * FRACUNIT;
791 }
792 player->mo->flags2 &= ~MF2_ONMOBJ;
793 player->jumpTics = 18;
794 }
795 else if (cmd->arti & AFLAG_SUICIDE)
796 {
797 P_DamageMobj(player->mo, NULL, NULL, 10000);
798 }
799 if (cmd->arti == HEXEN_NUMARTIFACTS)
800 { // use one of each artifact (except puzzle artifacts)
801 int i;
802
803 for (i = 1; i < hexen_arti_firstpuzzitem; i++)
804 {
805 P_PlayerUseArtifact(player, i);
806 }
807 }
808 else
809 {
810 P_PlayerUseArtifact(player, cmd->arti & AFLAG_MASK);
811 }
812 }
813 }
814 else
815 {
816 if (cmd->arti)
817 { // Use an artifact
818 if (cmd->arti == 0xff)
819 {
820 P_PlayerNextArtifact(player);
821 }
822 else
823 {
824 P_PlayerUseArtifact(player, cmd->arti);
825 }
826 }
827 }
828
829 if (dsda_AllowExCmd())
830 {
831 if (cmd->ex.actions & XC_JUMP && onground && !player->jumpTics)
832 {
833 player->mo->momz = g_jump * FRACUNIT;
834 player->mo->flags2 &= ~MF2_ONMOBJ;
835 player->jumpTics = 18;
836 }
837 }
838
839 if (raven && cmd->buttons & BT_SPECIAL)
840 {
841 cmd->buttons = 0;
842 }
843
844 // Check for weapon change.
845 if (cmd->buttons & BT_CHANGE && !player->morphTics)
846 {
847 // The actual changing of the weapon is done
848 // when the weapon psprite can do it
849 // (read: not in the middle of an attack).
850
851 newweapon = (cmd->buttons & BT_WEAPONMASK) >> BT_WEAPONSHIFT;
852
853 // killough 3/22/98: For demo compatibility we must perform the fist
854 // and SSG weapons switches here, rather than in G_BuildTiccmd(). For
855 // other games which rely on user preferences, we must use the latter.
856
857 if (demo_compatibility)
858 { // compatibility mode -- required for old demos -- killough
859 //e6y
860 if (!prboom_comp[PC_ALLOW_SSG_DIRECT].state)
861 newweapon = (cmd->buttons & BT_WEAPONMASK_OLD)>>BT_WEAPONSHIFT;
862
863 if (!hexen)
864 {
865 if (
866 newweapon == g_wp_fist && player->weaponowned[g_wp_chainsaw]
867 && (
868 player->readyweapon != g_wp_chainsaw ||
869 (!heretic && !player->powers[pw_strength])
870 )
871 )
872 newweapon = g_wp_chainsaw;
873
874 if (!heretic &&
875 gamemode == commercial &&
876 newweapon == wp_shotgun &&
877 player->weaponowned[wp_supershotgun] &&
878 player->readyweapon != wp_supershotgun)
879 newweapon = wp_supershotgun;
880 }
881 }
882
883 // killough 2/8/98, 3/22/98 -- end of weapon selection changes
884
885 if (player->weaponowned[newweapon] && newweapon != player->readyweapon)
886
887 // Do not go to plasma or BFG in shareware,
888 // even if cheated.
889
890 // heretic_note: ignoring this...not sure it's worth worrying about
891 if ((newweapon != wp_plasma && newweapon != wp_bfg)
892 || (gamemode != shareware) )
893 player->pendingweapon = newweapon;
894 }
895
896 // check for use
897
898 if (cmd->buttons & BT_USE)
899 {
900 if (!player->usedown)
901 {
902 P_UseLines(player);
903 player->usedown = true;
904 }
905 }
906 else
907 player->usedown = false;
908
909 // Chicken counter
910 if (player->chickenTics)
911 {
912 if (player->chickenPeck)
913 { // Chicken attack counter
914 player->chickenPeck -= 3;
915 }
916 if (!--player->chickenTics)
917 { // Attempt to undo the chicken
918 P_UndoPlayerChicken(player);
919 }
920 }
921
922 // Morph counter
923 if (player->morphTics)
924 {
925 if (!--player->morphTics)
926 { // Attempt to undo the pig
927 P_UndoPlayerMorph(player);
928 }
929 }
930
931 // cycle psprites
932 P_MovePsprites (player);
933
934 // Counters, time dependent power ups.
935
936 // Strength counts up to diminish fade.
937
938 if (player->powers[pw_strength])
939 player->powers[pw_strength]++;
940
941 // killough 1/98: Make idbeholdx toggle:
942
943 if (player->powers[pw_invulnerability] > 0) // killough
944 {
945 if (player->pclass == PCLASS_CLERIC)
946 {
947 if (!(leveltime & 7) && player->mo->flags & MF_SHADOW
948 && !(player->mo->flags2 & MF2_DONTDRAW))
949 {
950 player->mo->flags &= ~MF_SHADOW;
951 if (!(player->mo->flags & MF_ALTSHADOW))
952 {
953 player->mo->flags2 |= MF2_DONTDRAW | MF2_NONSHOOTABLE;
954 }
955 }
956 if (!(leveltime & 31))
957 {
958 if (player->mo->flags2 & MF2_DONTDRAW)
959 {
960 if (!(player->mo->flags & MF_SHADOW))
961 {
962 player->mo->flags |= MF_SHADOW | MF_ALTSHADOW;
963 }
964 else
965 {
966 player->mo->flags2 &=
967 ~(MF2_DONTDRAW | MF2_NONSHOOTABLE);
968 }
969 }
970 else
971 {
972 player->mo->flags |= MF_SHADOW;
973 player->mo->flags &= ~MF_ALTSHADOW;
974 }
975 }
976 }
977
978 if (!(--player->powers[pw_invulnerability]))
979 {
980 player->mo->flags2 &= ~(MF2_INVULNERABLE | MF2_REFLECTIVE);
981 if (player->pclass == PCLASS_CLERIC)
982 {
983 player->mo->flags2 &= ~(MF2_DONTDRAW | MF2_NONSHOOTABLE);
984 player->mo->flags &= ~(MF_SHADOW | MF_ALTSHADOW);
985 }
986 }
987 }
988
989 if (player->powers[pw_minotaur])
990 player->powers[pw_minotaur]--;
991
992 if (player->powers[pw_speed])
993 player->powers[pw_speed]--;
994
995 if (player->powers[pw_invisibility] > 0) // killough
996 if (! --player->powers[pw_invisibility] )
997 player->mo->flags &= ~MF_SHADOW;
998
999 if (player->powers[pw_infrared] > 0) // killough
1000 player->powers[pw_infrared]--;
1001
1002 if (player->powers[pw_ironfeet] > 0) // killough
1003 player->powers[pw_ironfeet]--;
1004
1005 if (player->powers[pw_flight] && (!hexen || netgame))
1006 {
1007 if (!--player->powers[pw_flight])
1008 {
1009 P_PlayerEndFlight(player);
1010 }
1011 }
1012
1013 if (player->powers[pw_weaponlevel2])
1014 {
1015 if (!--player->powers[pw_weaponlevel2])
1016 {
1017 if ((player->readyweapon == wp_phoenixrod)
1018 && (player->psprites[ps_weapon].state
1019 != &states[HERETIC_S_PHOENIXREADY])
1020 && (player->psprites[ps_weapon].state
1021 != &states[HERETIC_S_PHOENIXUP]))
1022 {
1023 P_SetPsprite(player, ps_weapon, HERETIC_S_PHOENIXREADY);
1024 player->ammo[am_phoenixrod] -= USE_PHRD_AMMO_2;
1025 player->refire = 0;
1026 }
1027 else if ((player->readyweapon == wp_gauntlets)
1028 || (player->readyweapon == wp_staff))
1029 {
1030 player->pendingweapon = player->readyweapon;
1031 }
1032 }
1033 }
1034
1035 if (player->damagecount)
1036 player->damagecount--;
1037
1038 if (player->bonuscount)
1039 player->bonuscount--;
1040
1041 if (player->hazardcount)
1042 {
1043 player->hazardcount--;
1044 if (!(leveltime % player->hazardinterval) && player->hazardcount > 16 * TICRATE)
1045 P_DamageMobj(player->mo, NULL, NULL, 5);
1046 }
1047
1048 if (player->poisoncount && !(leveltime & 15))
1049 {
1050 player->poisoncount -= 5;
1051 if (player->poisoncount < 0)
1052 {
1053 player->poisoncount = 0;
1054 }
1055 P_PoisonDamage(player, player->poisoner, 1, true);
1056 }
1057
1058 // Handling colormaps.
1059 // killough 3/20/98: reformat to terse C syntax
1060 if (!raven)
1061 player->fixedcolormap = dsda_PowerPalette() &&
1062 (player->powers[pw_invulnerability] > 4*32 ||
1063 player->powers[pw_invulnerability] & 8) ? INVERSECOLORMAP :
1064 player->powers[pw_infrared] > 4*32 || player->powers[pw_infrared] & 8;
1065 else
1066 {
1067 if (!hexen && player->powers[pw_invulnerability])
1068 {
1069 if (player->powers[pw_invulnerability] > BLINKTHRESHOLD
1070 || (player->powers[pw_invulnerability] & 8))
1071 {
1072 player->fixedcolormap = INVERSECOLORMAP;
1073 }
1074 else
1075 {
1076 player->fixedcolormap = 0;
1077 }
1078 }
1079 else if (player->powers[pw_infrared])
1080 {
1081 if (player->powers[pw_infrared] <= BLINKTHRESHOLD)
1082 {
1083 if (player->powers[pw_infrared] & 8)
1084 {
1085 player->fixedcolormap = 0;
1086 }
1087 else
1088 {
1089 player->fixedcolormap = 1;
1090 }
1091 }
1092 else if (!(leveltime & 16) && player == &players[consoleplayer])
1093 {
1094 if (newtorch)
1095 {
1096 if (player->fixedcolormap + newtorchdelta > 7
1097 || player->fixedcolormap + newtorchdelta < 1
1098 || newtorch == player->fixedcolormap)
1099 {
1100 newtorch = 0;
1101 }
1102 else
1103 {
1104 player->fixedcolormap += newtorchdelta;
1105 }
1106 }
1107 else
1108 {
1109 newtorch = (M_Random() & 7) + 1;
1110 newtorchdelta = (newtorch == player->fixedcolormap) ?
1111 0 : ((newtorch > player->fixedcolormap) ? 1 : -1);
1112 }
1113 }
1114 }
1115 else
1116 {
1117 player->fixedcolormap = 0;
1118 }
1119 }
1120 }
1121
1122 // heretic
1123
1124 #include "p_tick.h"
1125
1126 void P_PlayerNextArtifact(player_t * player);
1127
1128 int P_GetPlayerNum(player_t * player)
1129 {
1130 int i;
1131
1132 for (i = 0; i < g_maxplayers; i++)
1133 {
1134 if (player == &players[i])
1135 {
1136 return (i);
1137 }
1138 }
1139 return (0);
1140 }
1141
1142 dboolean P_UndoPlayerChicken(player_t * player)
1143 {
1144 mobj_t *fog;
1145 mobj_t *mo;
1146 mobj_t *pmo;
1147 fixed_t x;
1148 fixed_t y;
1149 fixed_t z;
1150 angle_t angle;
1151 int playerNum;
1152 weapontype_t weapon;
1153 int oldFlags;
1154 int oldFlags2;
1155
1156 pmo = player->mo;
1157 x = pmo->x;
1158 y = pmo->y;
1159 z = pmo->z;
1160 angle = pmo->angle;
1161 weapon = pmo->special1.i;
1162 oldFlags = pmo->flags;
1163 oldFlags2 = pmo->flags2;
1164 P_SetMobjState(pmo, HERETIC_S_FREETARGMOBJ);
1165 mo = P_SpawnMobj(x, y, z, g_mt_player);
1166 if (P_TestMobjLocation(mo) == false)
1167 { // Didn't fit
1168 P_RemoveMobj(mo);
1169 mo = P_SpawnMobj(x, y, z, HERETIC_MT_CHICPLAYER);
1170 mo->angle = angle;
1171 mo->health = player->health;
1172 mo->special1.i = weapon;
1173 mo->player = player;
1174 mo->flags = oldFlags;
1175 mo->flags2 = oldFlags2;
1176 player->mo = mo;
1177 player->chickenTics = 2 * 35;
1178 return (false);
1179 }
1180 playerNum = P_GetPlayerNum(player);
1181 if (playerNum != 0)
1182 { // Set color translation
1183 mo->flags |= playerNum << MF_TRANSSHIFT;
1184 }
1185 mo->angle = angle;
1186 mo->player = player;
1187 mo->reactiontime = 18;
1188 if (oldFlags2 & MF2_FLY)
1189 {
1190 mo->flags2 |= MF2_FLY;
1191 mo->flags |= MF_NOGRAVITY;
1192 }
1193 player->chickenTics = 0;
1194 player->powers[pw_weaponlevel2] = 0;
1195 player->health = mo->health = MAXHEALTH;
1196 player->mo = mo;
1197 angle >>= ANGLETOFINESHIFT;
1198 fog = P_SpawnMobj(x + 20 * finecosine[angle],
1199 y + 20 * finesine[angle], z + TELEFOGHEIGHT, HERETIC_MT_TFOG);
1200 S_StartMobjSound(fog, heretic_sfx_telept);
1201 P_PostChickenWeapon(player, weapon);
1202 return (true);
1203 }
1204
1205 void P_ArtiTele(player_t * player)
1206 {
1207 int i;
1208 int selections;
1209 fixed_t destX;
1210 fixed_t destY;
1211 angle_t destAngle;
1212
1213 if (deathmatch)
1214 {
1215 selections = deathmatch_p - deathmatchstarts;
1216 i = P_Random(pr_heretic) % selections;
1217 destX = deathmatchstarts[i].x;
1218 destY = deathmatchstarts[i].y;
1219 destAngle = ANG45 * (deathmatchstarts[i].angle / 45);
1220 }
1221 else
1222 {
1223 destX = playerstarts[0][0].x;
1224 destY = playerstarts[0][0].y;
1225 destAngle = ANG45 * (playerstarts[0][0].angle / 45);
1226 }
1227 P_Teleport(player->mo, destX, destY, destAngle, true);
1228 if (player->morphTics)
1229 { // Teleporting away will undo any morph effects (pig)
1230 P_UndoPlayerMorph(player);
1231 }
1232 if (heretic)
1233 S_StartVoidSound(heretic_sfx_wpnup); // Full volume laugh
1234 }
1235
1236 void P_PlayerNextArtifact(player_t * player)
1237 {
1238 if (player == &players[consoleplayer])
1239 {
1240 inv_ptr--;
1241 if (inv_ptr < 6)
1242 {
1243 curpos--;
1244 if (curpos < 0)
1245 {
1246 curpos = 0;
1247 }
1248 }
1249 if (inv_ptr < 0)
1250 {
1251 inv_ptr = player->inventorySlotNum - 1;
1252 if (inv_ptr < 6)
1253 {
1254 curpos = inv_ptr;
1255 }
1256 else
1257 {
1258 curpos = 6;
1259 }
1260 }
1261 player->readyArtifact = player->inventory[inv_ptr].type;
1262 }
1263 }
1264
1265 void P_PlayerRemoveArtifact(player_t * player, int slot)
1266 {
1267 int i;
1268 player->artifactCount--;
1269 if (!(--player->inventory[slot].count))
1270 { // Used last of a type - compact the artifact list
1271 player->readyArtifact = arti_none;
1272 player->inventory[slot].type = arti_none;
1273 for (i = slot + 1; i < player->inventorySlotNum; i++)
1274 {
1275 player->inventory[i - 1] = player->inventory[i];
1276 }
1277 player->inventorySlotNum--;
1278 if (player == &players[consoleplayer])
1279 { // Set position markers and get next readyArtifact
1280 inv_ptr--;
1281 if (inv_ptr < 6)
1282 {
1283 curpos--;
1284 if (curpos < 0)
1285 {
1286 curpos = 0;
1287 }
1288 }
1289 if (inv_ptr >= player->inventorySlotNum)
1290 {
1291 inv_ptr = player->inventorySlotNum - 1;
1292 }
1293 if (inv_ptr < 0)
1294 {
1295 inv_ptr = 0;
1296 }
1297 player->readyArtifact = player->inventory[inv_ptr].type;
1298 }
1299 }
1300 }
1301
1302 void P_PlayerUseArtifact(player_t * player, artitype_t arti)
1303 {
1304 int i;
1305
1306 for (i = 0; i < player->inventorySlotNum; i++)
1307 {
1308 if (player->inventory[i].type == arti)
1309 { // Found match - try to use
1310 if (P_UseArtifact(player, arti))
1311 { // Artifact was used - remove it from inventory
1312 P_PlayerRemoveArtifact(player, i);
1313 if (player == &players[consoleplayer])
1314 {
1315 if (hexen)
1316 {
1317 if (arti < hexen_arti_firstpuzzitem)
1318 {
1319 S_StartVoidSound(hexen_sfx_artifact_use);
1320 }
1321 else
1322 {
1323 S_StartVoidSound(hexen_sfx_puzzle_success);
1324 }
1325 }
1326 else
1327 {
1328 S_StartVoidSound(heretic_sfx_artiuse);
1329 }
1330 ArtifactFlash = 4;
1331 }
1332 }
1333 else if (!hexen || arti < hexen_arti_firstpuzzitem)
1334 { // Unable to use artifact, advance pointer
1335 P_PlayerNextArtifact(player);
1336 }
1337 break;
1338 }
1339 }
1340 }
1341
1342 static dboolean Hexen_P_UseArtifact(player_t * player, artitype_t arti);
1343
1344 dboolean P_UseArtifact(player_t * player, artitype_t arti)
1345 {
1346 mobj_t *mo;
1347 angle_t angle;
1348
1349 if (hexen) return Hexen_P_UseArtifact(player, arti);
1350
1351 switch (arti)
1352 {
1353 case arti_invulnerability:
1354 if (!P_GivePower(player, pw_invulnerability))
1355 {
1356 return (false);
1357 }
1358 break;
1359 case arti_invisibility:
1360 if (!P_GivePower(player, pw_invisibility))
1361 {
1362 return (false);
1363 }
1364 break;
1365 case arti_health:
1366 if (!P_GiveBody(player, 25))
1367 {
1368 return (false);
1369 }
1370 break;
1371 case arti_superhealth:
1372 if (!P_GiveBody(player, 100))
1373 {
1374 return (false);
1375 }
1376 break;
1377 case arti_tomeofpower:
1378 if (player->chickenTics)
1379 { // Attempt to undo chicken
1380 if (P_UndoPlayerChicken(player) == false)
1381 { // Failed
1382 P_DamageMobj(player->mo, NULL, NULL, 10000);
1383 }
1384 else
1385 { // Succeeded
1386 player->chickenTics = 0;
1387 S_StartMobjSound(player->mo, heretic_sfx_wpnup);
1388 }
1389 }
1390 else
1391 {
1392 if (!P_GivePower(player, pw_weaponlevel2))
1393 {
1394 return (false);
1395 }
1396 if (player->readyweapon == wp_staff)
1397 {
1398 P_SetPsprite(player, ps_weapon, HERETIC_S_STAFFREADY2_1);
1399 }
1400 else if (player->readyweapon == wp_gauntlets)
1401 {
1402 P_SetPsprite(player, ps_weapon, HERETIC_S_GAUNTLETREADY2_1);
1403 }
1404 }
1405 break;
1406 case arti_torch:
1407 if (!P_GivePower(player, pw_infrared))
1408 {
1409 return (false);
1410 }
1411 break;
1412 case arti_firebomb:
1413 angle = player->mo->angle >> ANGLETOFINESHIFT;
1414
1415 // Vanilla bug here:
1416 // Original code here looks like:
1417 // (player->mo->flags2 & MF2_FEETARECLIPPED != 0),
1418 // Which under C's operator precedence is:
1419 // (player->mo->flags2 & (MF2_FEETARECLIPPED != 0)),
1420 // Which simplifies to:
1421 // (player->mo->flags2 & 1),
1422 mo = P_SpawnMobj(player->mo->x + 24 * finecosine[angle],
1423 player->mo->y + 24 * finesine[angle],
1424 player->mo->z -
1425 15 * FRACUNIT * (player->mo->flags2 & 1),
1426 HERETIC_MT_FIREBOMB);
1427 P_SetTarget(&mo->target, player->mo);
1428 break;
1429 case arti_egg:
1430 mo = player->mo;
1431 P_SpawnPlayerMissile(mo, HERETIC_MT_EGGFX);
1432 P_SPMAngle(mo, HERETIC_MT_EGGFX, mo->angle - (ANG45 / 6));
1433 P_SPMAngle(mo, HERETIC_MT_EGGFX, mo->angle + (ANG45 / 6));
1434 P_SPMAngle(mo, HERETIC_MT_EGGFX, mo->angle - (ANG45 / 3));
1435 P_SPMAngle(mo, HERETIC_MT_EGGFX, mo->angle + (ANG45 / 3));
1436 break;
1437 case arti_fly:
1438 if (!P_GivePower(player, pw_flight))
1439 {
1440 return (false);
1441 }
1442 break;
1443 case arti_teleport:
1444 P_ArtiTele(player);
1445 break;
1446 default:
1447 return (false);
1448 }
1449 return (true);
1450 }
1451
1452 void Raven_P_MovePlayer(player_t * player)
1453 {
1454 int look;
1455 int fly;
1456 ticcmd_t *cmd;
1457
1458 cmd = &player->cmd;
1459 player->mo->angle += (cmd->angleturn << 16);
1460
1461 if (demo_smoothturns && player == &players[displayplayer])
1462 {
1463 R_SmoothPlaying_Add(cmd->angleturn << 16);
1464 }
1465
1466 onground = (player->mo->z <= player->mo->floorz
1467 || (player->mo->flags2 & MF2_ONMOBJ));
1468
1469 if (player->chickenTics)
1470 { // Chicken speed
1471 if (cmd->forwardmove && (onground || player->mo->flags2 & MF2_FLY))
1472 P_ForwardThrust(player, player->mo->angle, cmd->forwardmove * 2500);
1473 if (cmd->sidemove && (onground || player->mo->flags2 & MF2_FLY))
1474 P_Thrust(player, player->mo->angle - ANG90, cmd->sidemove * 2500);
1475 }
1476 else
1477 { // Normal speed
1478 if (cmd->forwardmove)
1479 {
1480 if (onground || player->mo->flags2 & MF2_FLY)
1481 P_ForwardThrust(player, player->mo->angle, cmd->forwardmove * 2048);
1482 else if (hexen)
1483 P_ForwardThrust(player, player->mo->angle, map_info.air_control);
1484 }
1485
1486 if (cmd->sidemove)
1487 {
1488 if (onground || player->mo->flags2 & MF2_FLY)
1489 P_Thrust(player, player->mo->angle - ANG90, cmd->sidemove * 2048);
1490 else if (hexen)
1491 P_Thrust(player, player->mo->angle, map_info.air_control);
1492 }
1493 }
1494
1495 if (cmd->forwardmove || cmd->sidemove)
1496 {
1497 if (player->chickenTics)
1498 {
1499 if (player->mo->state == &states[HERETIC_S_CHICPLAY])
1500 {
1501 P_SetMobjState(player->mo, HERETIC_S_CHICPLAY_RUN1);
1502 }
1503 }
1504 else
1505 {
1506 if (player->mo->state == &states[pclass[player->pclass].normal_state])
1507 {
1508 P_SetMobjState(player->mo, pclass[player->pclass].run_state);
1509 }
1510 }
1511 }
1512
1513 look = cmd->lookfly & 15;
1514 if (look > 7)
1515 {
1516 look -= 16;
1517 }
1518 if (look)
1519 {
1520 if (look == TOCENTER)
1521 {
1522 player->centering = true;
1523 }
1524 else
1525 {
1526 player->lookdir += 5 * look;
1527 if (player->lookdir > 90 || player->lookdir < -110)
1528 {
1529 player->lookdir -= 5 * look;
1530 }
1531 }
1532 }
1533 if (player->centering)
1534 {
1535 if (player->lookdir > 0)
1536 {
1537 player->lookdir -= 8;
1538 }
1539 else if (player->lookdir < 0)
1540 {
1541 player->lookdir += 8;
1542 }
1543 if (abs(player->lookdir) < 8)
1544 {
1545 player->lookdir = 0;
1546 player->centering = false;
1547 }
1548 }
1549 fly = cmd->lookfly >> 4;
1550 if (fly > 7)
1551 {
1552 fly -= 16;
1553 }
1554 if (fly && player->powers[pw_flight])
1555 {
1556 if (fly != TOCENTER)
1557 {
1558 player->flyheight = fly * 2;
1559 if (!(player->mo->flags2 & MF2_FLY))
1560 {
1561 player->mo->flags2 |= MF2_FLY;
1562 player->mo->flags |= MF_NOGRAVITY;
1563 if (hexen && player->mo->momz <= -39 * FRACUNIT)
1564 { // stop falling scream
1565 S_StopSound(player->mo);
1566 }
1567 }
1568 }
1569 else
1570 {
1571 player->mo->flags2 &= ~MF2_FLY;
1572 player->mo->flags &= ~MF_NOGRAVITY;
1573 }
1574 }
1575 else if (fly > 0)
1576 {
1577 P_PlayerUseArtifact(player, g_arti_fly);
1578 }
1579 if (player->mo->flags2 & MF2_FLY)
1580 {
1581 player->mo->momz = player->flyheight * FRACUNIT;
1582 if (player->flyheight)
1583 {
1584 player->flyheight /= 2;
1585 }
1586 }
1587 }
1588
1589 void P_ChickenPlayerThink(player_t * player)
1590 {
1591 mobj_t *pmo;
1592
1593 if (player->health > 0)
1594 { // Handle beak movement
1595 P_UpdateBeak(player, &player->psprites[ps_weapon]);
1596 }
1597 if (player->chickenTics & 15)
1598 {
1599 return;
1600 }
1601 pmo = player->mo;
1602 if (!(pmo->momx + pmo->momy) && P_Random(pr_heretic) < 160)
1603 { // Twitch view angle
1604 pmo->angle += P_SubRandom() << 19;
1605 }
1606 if ((pmo->z <= pmo->floorz) && (P_Random(pr_heretic) < 32))
1607 { // Jump and noise
1608 pmo->momz += FRACUNIT;
1609 P_SetMobjState(pmo, HERETIC_S_CHICPLAY_PAIN);
1610 return;
1611 }
1612 if (P_Random(pr_heretic) < 48)
1613 { // Just noise
1614 S_StartMobjSound(pmo, heretic_sfx_chicact);
1615 }
1616 }
1617
1618 // hexen
1619
1620 #define BLAST_RADIUS_DIST 255*FRACUNIT
1621 #define BLAST_SPEED 20*FRACUNIT
1622 #define BLAST_FULLSTRENGTH 255
1623
1624 void ResetBlasted(mobj_t * mo)
1625 {
1626 mo->flags2 &= ~MF2_BLASTED;
1627 if (!(mo->flags & MF_ICECORPSE))
1628 {
1629 mo->flags2 &= ~MF2_SLIDE;
1630 }
1631 }
1632
1633 void P_BlastMobj(mobj_t * source, mobj_t * victim, fixed_t strength)
1634 {
1635 angle_t angle, ang;
1636 mobj_t *mo;
1637 fixed_t x, y, z;
1638
1639 angle = R_PointToAngle2(source->x, source->y, victim->x, victim->y);
1640 angle >>= ANGLETOFINESHIFT;
1641 if (strength < BLAST_FULLSTRENGTH)
1642 {
1643 victim->momx = FixedMul(strength, finecosine[angle]);
1644 victim->momy = FixedMul(strength, finesine[angle]);
1645 if (victim->player)
1646 {
1647 // Players handled automatically
1648 }
1649 else
1650 {
1651 victim->flags2 |= MF2_SLIDE;
1652 victim->flags2 |= MF2_BLASTED;
1653 }
1654 }
1655 else // full strength blast from artifact
1656 {
1657 if (victim->flags & MF_MISSILE)
1658 {
1659 switch (victim->type)
1660 {
1661 case HEXEN_MT_SORCBALL1: // don't blast sorcerer balls
1662 case HEXEN_MT_SORCBALL2:
1663 case HEXEN_MT_SORCBALL3:
1664 return;
1665 break;
1666 case HEXEN_MT_MSTAFF_FX2: // Reflect to originator
1667 P_SetTarget(&victim->special1.m, victim->target);
1668 P_SetTarget(&victim->target, source);
1669 break;
1670 default:
1671 break;
1672 }
1673 }
1674 if (victim->type == HEXEN_MT_HOLY_FX)
1675 {
1676 if (victim->special1.m == source)
1677 {
1678 P_SetTarget(&victim->special1.m, victim->target);
1679 P_SetTarget(&victim->target, source);
1680 }
1681 }
1682 victim->momx = FixedMul(BLAST_SPEED, finecosine[angle]);
1683 victim->momy = FixedMul(BLAST_SPEED, finesine[angle]);
1684
1685 // Spawn blast puff
1686 ang = R_PointToAngle2(victim->x, victim->y, source->x, source->y);
1687 ang >>= ANGLETOFINESHIFT;
1688 x = victim->x + FixedMul(victim->radius + FRACUNIT, finecosine[ang]);
1689 y = victim->y + FixedMul(victim->radius + FRACUNIT, finesine[ang]);
1690 z = victim->z - victim->floorclip + (victim->height >> 1);
1691 mo = P_SpawnMobj(x, y, z, HEXEN_MT_BLASTEFFECT);
1692 if (mo)
1693 {
1694 mo->momx = victim->momx;
1695 mo->momy = victim->momy;
1696 }
1697
1698 if (victim->flags & MF_MISSILE)
1699 {
1700 victim->momz = 8 * FRACUNIT;
1701 mo->momz = victim->momz;
1702 }
1703 else
1704 {
1705 victim->momz = (1000 / victim->info->mass) << FRACBITS;
1706 }
1707 if (victim->player)
1708 {
1709 // Players handled automatically
1710 }
1711 else
1712 {
1713 victim->flags2 |= MF2_SLIDE;
1714 victim->flags2 |= MF2_BLASTED;
1715 }
1716 }
1717 }
1718
1719 // Blast all mobj things away
1720 void P_BlastRadius(player_t * player)
1721 {
1722 mobj_t *mo;
1723 mobj_t *pmo = player->mo;
1724 thinker_t *think;
1725 fixed_t dist;
1726
1727 S_StartMobjSound(pmo, hexen_sfx_artifact_blast);
1728 P_NoiseAlert(player->mo, player->mo);
1729
1730 for (think = thinkercap.next; think != &thinkercap; think = think->next)
1731 {
1732 if (think->function != P_MobjThinker)
1733 { // Not a mobj thinker
1734 continue;
1735 }
1736 mo = (mobj_t *) think;
1737 if ((mo == pmo) || (mo->flags2 & MF2_BOSS))
1738 { // Not a valid monster
1739 continue;
1740 }
1741 if ((mo->type == HEXEN_MT_POISONCLOUD) || // poison cloud
1742 (mo->type == HEXEN_MT_HOLY_FX) || // holy fx
1743 (mo->flags & MF_ICECORPSE)) // frozen corpse
1744 {
1745 // Let these special cases go
1746 }
1747 else if ((mo->flags & MF_COUNTKILL) && (mo->health <= 0))
1748 {
1749 continue;
1750 }
1751 else if (!(mo->flags & MF_COUNTKILL) &&
1752 !(mo->player) && !(mo->flags & MF_MISSILE))
1753 { // Must be monster, player, or missile
1754 continue;
1755 }
1756 if (mo->flags2 & MF2_DORMANT)
1757 {
1758 continue; // no dormant creatures
1759 }
1760 if ((mo->type == HEXEN_MT_WRAITHB) && (mo->flags2 & MF2_DONTDRAW))
1761 {
1762 continue; // no underground wraiths
1763 }
1764 if ((mo->type == HEXEN_MT_SPLASHBASE) || (mo->type == HEXEN_MT_SPLASH))
1765 {
1766 continue;
1767 }
1768 if (mo->type == HEXEN_MT_SERPENT || mo->type == HEXEN_MT_SERPENTLEADER)
1769 {
1770 continue;
1771 }
1772 dist = P_AproxDistance(pmo->x - mo->x, pmo->y - mo->y);
1773 if (dist > BLAST_RADIUS_DIST)
1774 { // Out of range
1775 continue;
1776 }
1777 P_BlastMobj(pmo, mo, BLAST_FULLSTRENGTH);
1778 }
1779 }
1780
1781 void P_MorphPlayerThink(player_t * player)
1782 {
1783 mobj_t *pmo;
1784
1785 if (player->morphTics & 15)
1786 {
1787 return;
1788 }
1789 pmo = player->mo;
1790 if (!(pmo->momx + pmo->momy) && P_Random(pr_hexen) < 64)
1791 { // Snout sniff
1792 P_SetPspriteNF(player, ps_weapon, HEXEN_S_SNOUTATK2);
1793 S_StartMobjSound(pmo, hexen_sfx_pig_active1); // snort
1794 return;
1795 }
1796 if (P_Random(pr_hexen) < 48)
1797 {
1798 if (P_Random(pr_hexen) < 128)
1799 {
1800 S_StartMobjSound(pmo, hexen_sfx_pig_active1);
1801 }
1802 else
1803 {
1804 S_StartMobjSound(pmo, hexen_sfx_pig_active2);
1805 }
1806 }
1807 }
1808
1809 dboolean P_UndoPlayerMorph(player_t * player)
1810 {
1811 mobj_t *fog;
1812 mobj_t *mo;
1813 mobj_t *pmo;
1814 fixed_t x;
1815 fixed_t y;
1816 fixed_t z;
1817 angle_t angle;
1818 int playerNum;
1819 weapontype_t weapon;
1820 int oldFlags;
1821 int oldFlags2;
1822 int oldBeast;
1823
1824 pmo = player->mo;
1825 x = pmo->x;
1826 y = pmo->y;
1827 z = pmo->z;
1828 angle = pmo->angle;
1829 weapon = pmo->special1.i;
1830 oldFlags = pmo->flags;
1831 oldFlags2 = pmo->flags2;
1832 oldBeast = pmo->type;
1833 P_SetMobjState(pmo, HEXEN_S_FREETARGMOBJ);
1834 playerNum = P_GetPlayerNum(player);
1835 switch (PlayerClass[playerNum])
1836 {
1837 case PCLASS_FIGHTER:
1838 mo = P_SpawnMobj(x, y, z, HEXEN_MT_PLAYER_FIGHTER);
1839 break;
1840 case PCLASS_CLERIC:
1841 mo = P_SpawnMobj(x, y, z, HEXEN_MT_PLAYER_CLERIC);
1842 break;
1843 case PCLASS_MAGE:
1844 mo = P_SpawnMobj(x, y, z, HEXEN_MT_PLAYER_MAGE);
1845 break;
1846 default:
1847 I_Error("P_UndoPlayerMorph: Unknown player class %d\n",
1848 player->pclass);
1849 return false;
1850 }
1851 if (P_TestMobjLocation(mo) == false)
1852 { // Didn't fit
1853 P_RemoveMobj(mo);
1854 mo = P_SpawnMobj(x, y, z, oldBeast);
1855 mo->angle = angle;
1856 mo->health = player->health;
1857 mo->special1.i = weapon;
1858 mo->player = player;
1859 mo->flags = oldFlags;
1860 mo->flags2 = oldFlags2;
1861 player->mo = mo;
1862 player->morphTics = 2 * 35;
1863 return (false);
1864 }
1865 if (player->pclass == PCLASS_FIGHTER)
1866 {
1867 // The first type should be blue, and the third should be the
1868 // Fighter's original gold color
1869 if (playerNum == 0)
1870 {
1871 mo->flags |= 2 << MF_TRANSSHIFT;
1872 }
1873 else if (playerNum != 2)
1874 {
1875 mo->flags |= playerNum << MF_TRANSSHIFT;
1876 }
1877 }
1878 else if (playerNum)
1879 { // Set color translation bits for player sprites
1880 mo->flags |= playerNum << MF_TRANSSHIFT;
1881 }
1882 mo->angle = angle;
1883 mo->player = player;
1884 mo->reactiontime = 18;
1885 if (oldFlags2 & MF2_FLY)
1886 {
1887 mo->flags2 |= MF2_FLY;
1888 mo->flags |= MF_NOGRAVITY;
1889 }
1890 player->morphTics = 0;
1891 player->health = mo->health = MAXHEALTH;
1892 player->mo = mo;
1893 player->pclass = PlayerClass[playerNum];
1894 angle >>= ANGLETOFINESHIFT;
1895 fog = P_SpawnMobj(x + 20 * finecosine[angle],
1896 y + 20 * finesine[angle], z + TELEFOGHEIGHT, HEXEN_MT_TFOG);
1897 S_StartMobjSound(fog, hexen_sfx_teleport);
1898 P_PostMorphWeapon(player, weapon);
1899 return (true);
1900 }
1901
1902 void P_ArtiTeleportOther(player_t * player)
1903 {
1904 mobj_t *mo;
1905
1906 mo = P_SpawnPlayerMissile(player->mo, HEXEN_MT_TELOTHER_FX1);
1907 if (mo)
1908 {
1909 P_SetTarget(&mo->target, player->mo);
1910 }
1911 }
1912
1913
1914 void P_TeleportToPlayerStarts(mobj_t * victim)
1915 {
1916 int i, selections = 0;
1917 fixed_t destX, destY;
1918 angle_t destAngle;
1919
1920 for (i = 0; i < g_maxplayers; i++)
1921 {
1922 if (!playeringame[i])
1923 continue;
1924 selections++;
1925 }
1926 i = P_Random(pr_hexen) % selections;
1927 destX = playerstarts[0][i].x;
1928 destY = playerstarts[0][i].y;
1929 destAngle = ANG45 * (playerstarts[0][i].angle / 45);
1930 P_Teleport(victim, destX, destY, destAngle, true);
1931 }
1932
1933 void P_TeleportToDeathmatchStarts(mobj_t * victim)
1934 {
1935 int i, selections;
1936 fixed_t destX, destY;
1937 angle_t destAngle;
1938
1939 selections = deathmatch_p - deathmatchstarts;
1940 if (selections)
1941 {
1942 i = P_Random(pr_hexen) % selections;
1943 destX = deathmatchstarts[i].x;
1944 destY = deathmatchstarts[i].y;
1945 destAngle = ANG45 * (deathmatchstarts[i].angle / 45);
1946 P_Teleport(victim, destX, destY, destAngle, true);
1947 }
1948 else
1949 {
1950 P_TeleportToPlayerStarts(victim);
1951 }
1952 }
1953
1954 void P_TeleportOther(mobj_t * victim)
1955 {
1956 if (victim->player)
1957 {
1958 if (deathmatch)
1959 P_TeleportToDeathmatchStarts(victim);
1960 else
1961 P_TeleportToPlayerStarts(victim);
1962 }
1963 else
1964 {
1965 // If death action, run it upon teleport
1966 if (victim->flags & MF_COUNTKILL && victim->special)
1967 {
1968 map_format.remove_mobj_thing_id(victim);
1969 map_format.execute_line_special(victim->special, victim->special_args, NULL, 0, victim);
1970 victim->special = 0;
1971 }
1972
1973 // Send all monsters to deathmatch spots
1974 P_TeleportToDeathmatchStarts(victim);
1975 }
1976 }
1977
1978 #define HEAL_RADIUS_DIST 255*FRACUNIT
1979
1980 // Do class specific effect for everyone in radius
1981 dboolean P_HealRadius(player_t * player)
1982 {
1983 mobj_t *mo;
1984 mobj_t *pmo = player->mo;
1985 thinker_t *think;
1986 fixed_t dist;
1987 int effective = false;
1988 int amount;
1989
1990 for (think = thinkercap.next; think != &thinkercap; think = think->next)
1991 {
1992 if (think->function != P_MobjThinker)
1993 { // Not a mobj thinker
1994 continue;
1995 }
1996 mo = (mobj_t *) think;
1997
1998 if (!mo->player)
1999 continue;
2000 if (mo->health <= 0)
2001 continue;
2002 dist = P_AproxDistance(pmo->x - mo->x, pmo->y - mo->y);
2003 if (dist > HEAL_RADIUS_DIST)
2004 { // Out of range
2005 continue;
2006 }
2007
2008 switch (player->pclass)
2009 {
2010 case PCLASS_FIGHTER: // Radius armor boost
2011 if ((Hexen_P_GiveArmor(mo->player, ARMOR_ARMOR, 1)) ||
2012 (Hexen_P_GiveArmor(mo->player, ARMOR_SHIELD, 1)) ||
2013 (Hexen_P_GiveArmor(mo->player, ARMOR_HELMET, 1)) ||
2014 (Hexen_P_GiveArmor(mo->player, ARMOR_AMULET, 1)))
2015 {
2016 effective = true;
2017 S_StartMobjSound(mo, hexen_sfx_mysticincant);
2018 }
2019 break;
2020 case PCLASS_CLERIC: // Radius heal
2021 amount = 50 + (P_Random(pr_hexen) % 50);
2022 if (P_GiveBody(mo->player, amount))
2023 {
2024 effective = true;
2025 S_StartMobjSound(mo, hexen_sfx_mysticincant);
2026 }
2027 break;
2028 case PCLASS_MAGE: // Radius mana boost
2029 amount = 50 + (P_Random(pr_hexen) % 50);
2030 if ((P_GiveMana(mo->player, MANA_1, amount)) ||
2031 (P_GiveMana(mo->player, MANA_2, amount)))
2032 {
2033 effective = true;
2034 S_StartMobjSound(mo, hexen_sfx_mysticincant);
2035 }
2036 break;
2037 case PCLASS_PIG:
2038 default:
2039 break;
2040 }
2041 }
2042 return (effective);
2043 }
2044
2045 static dboolean Hexen_P_UseArtifact(player_t * player, artitype_t arti)
2046 {
2047 mobj_t *mo;
2048 angle_t angle;
2049 int i;
2050 int count;
2051
2052 switch (arti)
2053 {
2054 case hexen_arti_invulnerability:
2055 if (!P_GivePower(player, pw_invulnerability))
2056 {
2057 return (false);
2058 }
2059 break;
2060 case hexen_arti_health:
2061 if (!P_GiveBody(player, 25))
2062 {
2063 return (false);
2064 }
2065 break;
2066 case hexen_arti_superhealth:
2067 if (!P_GiveBody(player, 100))
2068 {
2069 return (false);
2070 }
2071 break;
2072 case hexen_arti_healingradius:
2073 if (!P_HealRadius(player))
2074 {
2075 return (false);
2076 }
2077 break;
2078 case hexen_arti_torch:
2079 if (!P_GivePower(player, pw_infrared))
2080 {
2081 return (false);
2082 }
2083 break;
2084 case hexen_arti_egg:
2085 mo = player->mo;
2086 P_SpawnPlayerMissile(mo, HEXEN_MT_EGGFX);
2087 P_SPMAngle(mo, HEXEN_MT_EGGFX, mo->angle - (ANG45 / 6));
2088 P_SPMAngle(mo, HEXEN_MT_EGGFX, mo->angle + (ANG45 / 6));
2089 P_SPMAngle(mo, HEXEN_MT_EGGFX, mo->angle - (ANG45 / 3));
2090 P_SPMAngle(mo, HEXEN_MT_EGGFX, mo->angle + (ANG45 / 3));
2091 break;
2092 case hexen_arti_fly:
2093 if (!P_GivePower(player, pw_flight))
2094 {
2095 return (false);
2096 }
2097 if (player->mo->momz <= -35 * FRACUNIT)
2098 { // stop falling scream
2099 S_StopSound(player->mo);
2100 }
2101 break;
2102 case hexen_arti_summon:
2103 mo = P_SpawnPlayerMissile(player->mo, HEXEN_MT_SUMMON_FX);
2104 if (mo)
2105 {
2106 P_SetTarget(&mo->target, player->mo);
2107 P_SetTarget(&mo->special1.m, player->mo);
2108 mo->momz = 5 * FRACUNIT;
2109 }
2110 break;
2111 case hexen_arti_teleport:
2112 P_ArtiTele(player);
2113 break;
2114 case hexen_arti_teleportother:
2115 P_ArtiTeleportOther(player);
2116 break;
2117 case hexen_arti_poisonbag:
2118 angle = player->mo->angle >> ANGLETOFINESHIFT;
2119 if (player->pclass == PCLASS_CLERIC)
2120 {
2121 mo = P_SpawnMobj(player->mo->x + 16 * finecosine[angle],
2122 player->mo->y + 24 * finesine[angle],
2123 player->mo->z - player->mo->floorclip +
2124 8 * FRACUNIT, HEXEN_MT_POISONBAG);
2125 if (mo)
2126 {
2127 P_SetTarget(&mo->target, player->mo);
2128 }
2129 }
2130 else if (player->pclass == PCLASS_MAGE)
2131 {
2132 mo = P_SpawnMobj(player->mo->x + 16 * finecosine[angle],
2133 player->mo->y + 24 * finesine[angle],
2134 player->mo->z - player->mo->floorclip +
2135 8 * FRACUNIT, HEXEN_MT_FIREBOMB);
2136 if (mo)
2137 {
2138 P_SetTarget(&mo->target, player->mo);
2139 }
2140 }
2141 else // PCLASS_FIGHTER, obviously (also pig, not so obviously)
2142 {
2143 mo = P_SpawnMobj(player->mo->x, player->mo->y,
2144 player->mo->z - player->mo->floorclip +
2145 35 * FRACUNIT, HEXEN_MT_THROWINGBOMB);
2146 if (mo)
2147 {
2148 mo->angle =
2149 player->mo->angle + (((P_Random(pr_hexen) & 7) - 4) << 24);
2150 mo->momz =
2151 4 * FRACUNIT + (dsda_PlayerLookDir(player) << (FRACBITS - 4));
2152 mo->z += dsda_PlayerLookDir(player) << (FRACBITS - 4);
2153 P_ThrustMobj(mo, mo->angle, mo->info->speed);
2154 mo->momx += player->mo->momx >> 1;
2155 mo->momy += player->mo->momy >> 1;
2156 P_SetTarget(&mo->target, player->mo);
2157 mo->tics -= P_Random(pr_hexen) & 3;
2158 P_CheckMissileSpawn(mo);
2159 }
2160 }
2161 break;
2162 case hexen_arti_speed:
2163 if (!P_GivePower(player, pw_speed))
2164 {
2165 return (false);
2166 }
2167 break;
2168 case hexen_arti_boostmana:
2169 if (!P_GiveMana(player, MANA_1, MAX_MANA))
2170 {
2171 if (!P_GiveMana(player, MANA_2, MAX_MANA))
2172 {
2173 return false;
2174 }
2175
2176 }
2177 else
2178 {
2179 P_GiveMana(player, MANA_2, MAX_MANA);
2180 }
2181 break;
2182 case hexen_arti_boostarmor:
2183 count = 0;
2184
2185 for (i = 0; i < NUMARMOR; i++)
2186 {
2187 count += Hexen_P_GiveArmor(player, i, 1); // 1 point per armor type
2188 }
2189 if (!count)
2190 {
2191 return false;
2192 }
2193 break;
2194 case hexen_arti_blastradius:
2195 P_BlastRadius(player);
2196 break;
2197
2198 case hexen_arti_puzzskull:
2199 case hexen_arti_puzzgembig:
2200 case hexen_arti_puzzgemred:
2201 case hexen_arti_puzzgemgreen1:
2202 case hexen_arti_puzzgemgreen2:
2203 case hexen_arti_puzzgemblue1:
2204 case hexen_arti_puzzgemblue2:
2205 case hexen_arti_puzzbook1:
2206 case hexen_arti_puzzbook2:
2207 case hexen_arti_puzzskull2:
2208 case hexen_arti_puzzfweapon:
2209 case hexen_arti_puzzcweapon:
2210 case hexen_arti_puzzmweapon:
2211 case hexen_arti_puzzgear1:
2212 case hexen_arti_puzzgear2:
2213 case hexen_arti_puzzgear3:
2214 case hexen_arti_puzzgear4:
2215 if (P_UsePuzzleItem(player, arti - hexen_arti_firstpuzzitem))
2216 {
2217 return true;
2218 }
2219 else
2220 {
2221 P_SetYellowMessage(player, TXT_USEPUZZLEFAILED, false);
2222 return false;
2223 }
2224 break;
2225 default:
2226 return false;
2227 }
2228 return true;
2229 }
2230
2231 void A_SpeedFade(mobj_t * actor)
2232 {
2233 actor->flags |= MF_SHADOW;
2234 actor->flags &= ~MF_ALTSHADOW;
2235 actor->sprite = actor->target->sprite;
2236 }