Debian Codegraph @

prboom2/src/p_inter.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 * Handling interactions (i.e., collisions).
31 *
32 *-----------------------------------------------------------------------------*/
33
34 #include "doomstat.h"
35 #include "dstrings.h"
36 #include "m_random.h"
37 #include "am_map.h"
38 #include "r_main.h"
39 #include "s_sound.h"
40 #include "smooth.h"
41 #include "sounds.h"
42 #include "d_deh.h" // Ty 03/22/98 - externalized strings
43 #include "p_tick.h"
44 #include "lprintf.h"
45
46 #include "p_inter.h"
47 #include "p_enemy.h"
48 #include "p_spec.h"
49 #include "p_pspr.h"
50 #include "p_user.h"
51
52 #include "p_inter.h"
53 #include "e6y.h"//e6y
54
55 #include "dsda.h"
56 #include "dsda/map_format.h"
57 #include "dsda/mapinfo.h"
58 #include "dsda/messenger.h"
59 #include "dsda/skill_info.h"
60
61 #include "heretic/def.h"
62 #include "heretic/sb_bar.h"
63
64 #include "hexen/p_acs.h"
65
66 // Ty 03/07/98 - add deh externals
67 // Maximums and such were hardcoded values. Need to externalize those for
68 // dehacked support (and future flexibility). Most var names came from the key
69 // strings used in dehacked.
70
71 int initial_health = 100;
72 int initial_bullets = 50;
73 int maxhealth = 100; // was MAXHEALTH as a #define, used only in this module
74 int maxhealthbonus = 200;
75 int max_armor = 200;
76 int green_armor_class = 1; // these are involved with armortype below
77 int blue_armor_class = 2;
78 int max_soul = 200;
79 int soul_health = 100;
80 int mega_health = 200;
81 int god_health = 100; // these are used in cheats (see st_stuff.c)
82 int idfa_armor = 200;
83 int idfa_armor_class = 2;
84 // not actually used due to pairing of cheat_k and cheat_fa
85 int idkfa_armor = 200;
86 int idkfa_armor_class = 2;
87
88 int bfgcells = 40; // used in p_pspr.c
89 int monsters_infight = 0; // e6y: Dehacked support - monsters infight
90 // Ty 03/07/98 - end deh externals
91
92 // a weapon is found with two clip loads,
93 // a big item has five clip loads
94 int maxammo[NUMAMMO] = {200, 50, 300, 50, 0, 0}; // heretic +2 ammo types
95 int clipammo[NUMAMMO] = { 10, 4, 20, 1, 0, 0}; // heretic +2 ammo types
96
97 //
98 // GET STUFF
99 //
100
101 // heretic
102 static weapontype_t GetAmmoChange[] = {
103 wp_goldwand,
104 wp_crossbow,
105 wp_blaster,
106 wp_skullrod,
107 wp_phoenixrod,
108 wp_mace
109 };
110
111 //
112 // P_AutoSwitchWeapon
113 // Autoswitches player to a weapon,
114 // Based on config and other conditions.
115 //
116
117 static void P_AutoSwitchWeapon(player_t *player, weapontype_t weapon)
118 {
119 int autoswitch_config = dsda_IntConfig(dsda_config_switch_weapon_on_pickup);
120 int autoswitch = ((allow_incompatibility && !deathmatch && !netgame) ? autoswitch_config : true);
121
122 if (!autoswitch) return;
123
124 player->pendingweapon = weapon;
125 }
126
127 //
128 // P_GiveAmmo
129 // Num is the number of clip loads,
130 // not the individual count (0= 1/2 clip).
131 // Returns false if the ammo can't be picked up at all
132 //
133
134 static dboolean P_GiveAmmoAutoSwitch(player_t *player, ammotype_t ammo, int oldammo)
135 {
136 int i;
137
138 if (
139 weaponinfo[player->readyweapon].flags & WPF_AUTOSWITCHFROM &&
140 weaponinfo[player->readyweapon].ammo != ammo
141 )
142 {
143 for (i = NUMWEAPONS - 1; i > player->readyweapon; --i)
144 {
145 if (
146 player->weaponowned[i] &&
147 !(weaponinfo[i].flags & WPF_NOAUTOSWITCHTO) &&
148 weaponinfo[i].ammo == ammo &&
149 weaponinfo[i].ammopershot > oldammo &&
150 weaponinfo[i].ammopershot <= player->ammo[ammo]
151 )
152 {
153 P_AutoSwitchWeapon(player, i);
154 break;
155 }
156 }
157 }
158
159 return true;
160 }
161
162 static dboolean P_GiveAmmo(player_t *player, ammotype_t ammo, int num)
163 {
164 int oldammo;
165
166 if (ammo == am_noammo)
167 return false;
168
169 #ifdef RANGECHECK
170 if (ammo < 0 || ammo > NUMAMMO)
171 I_Error ("P_GiveAmmo: bad type %i", ammo);
172 #endif
173
174 if ( player->ammo[ammo] == player->maxammo[ammo] )
175 return false;
176
177 if (num)
178 num *= clipammo[ammo];
179 else
180 num = clipammo[ammo]/2;
181
182 if (skill_info.ammo_factor)
183 num = FixedMul(num, skill_info.ammo_factor);
184
185 oldammo = player->ammo[ammo];
186 player->ammo[ammo] += num;
187
188 if (player->ammo[ammo] > player->maxammo[ammo])
189 player->ammo[ammo] = player->maxammo[ammo];
190
191 if (mbf21)
192 return P_GiveAmmoAutoSwitch(player, ammo, oldammo);
193
194 // If non zero ammo, don't change up weapons, player was lower on purpose.
195 if (oldammo)
196 return true;
197
198 // We were down to zero, so select a new weapon.
199 // Preferences are not user selectable.
200
201 if (heretic) {
202 if (player->readyweapon == wp_staff || player->readyweapon == wp_gauntlets)
203 {
204 if (player->weaponowned[GetAmmoChange[ammo]])
205 {
206 P_AutoSwitchWeapon(player, GetAmmoChange[ammo]);
207 }
208 }
209
210 return true;
211 }
212
213 switch (ammo)
214 {
215 case am_clip:
216 if (player->readyweapon == wp_fist) {
217 if (player->weaponowned[wp_chaingun])
218 P_AutoSwitchWeapon(player, wp_chaingun);
219 else
220 P_AutoSwitchWeapon(player, wp_pistol);
221 }
222 break;
223
224 case am_shell:
225 if (player->readyweapon == wp_fist || player->readyweapon == wp_pistol)
226 if (player->weaponowned[wp_shotgun])
227 P_AutoSwitchWeapon(player, wp_shotgun);
228 break;
229
230 case am_cell:
231 if (player->readyweapon == wp_fist || player->readyweapon == wp_pistol)
232 if (player->weaponowned[wp_plasma])
233 P_AutoSwitchWeapon(player, wp_plasma);
234 break;
235
236 case am_misl:
237 if (player->readyweapon == wp_fist)
238 if (player->weaponowned[wp_missile])
239 P_AutoSwitchWeapon(player, wp_missile);
240 default:
241 break;
242 }
243 return true;
244 }
245
246 //
247 // P_GiveWeapon
248 // The weapon name may have a MF_DROPPED flag ored in.
249 //
250
251 dboolean P_GiveWeapon(player_t *player, weapontype_t weapon, dboolean dropped)
252 {
253 dboolean gaveammo;
254 dboolean gaveweapon;
255
256 if (heretic) return Heretic_P_GiveWeapon(player, weapon);
257
258 if (netgame && deathmatch!=2 && !dropped)
259 {
260 // leave placed weapons forever on net games
261 if (player->weaponowned[weapon])
262 return false;
263
264 player->bonuscount += BONUSADD;
265 player->weaponowned[weapon] = true;
266
267 P_GiveAmmo(player, weaponinfo[weapon].ammo, deathmatch ? 5 : 2);
268 P_AutoSwitchWeapon(player, weapon);
269 /* cph 20028/10 - for old-school DM addicts, allow old behavior
270 * where only consoleplayer's pickup sounds are heard */
271 // displayplayer, not consoleplayer, for viewing multiplayer demos
272 if (!comp[comp_sound])
273 S_StartSound (player->mo, sfx_wpnup|PICKUP_SOUND); // killough 4/25/98
274 else if (player == &players[displayplayer])
275 S_StartVoidSound (sfx_wpnup|PICKUP_SOUND);
276 return false;
277 }
278
279 if (weaponinfo[weapon].ammo != am_noammo)
280 {
281 // give one clip with a dropped weapon,
282 // two clips with a found weapon
283 gaveammo = P_GiveAmmo (player, weaponinfo[weapon].ammo, dropped ? 1 : 2);
284 }
285 else
286 gaveammo = false;
287
288 if (player->weaponowned[weapon])
289 gaveweapon = false;
290 else
291 {
292 gaveweapon = true;
293 player->weaponowned[weapon] = true;
294 P_AutoSwitchWeapon(player, weapon);
295 }
296 return gaveweapon || gaveammo;
297 }
298
299 int P_PlayerHealthIncrease(int value)
300 {
301 if (skill_info.health_factor)
302 value = FixedMul(value, skill_info.health_factor);
303
304 return value;
305 }
306
307 int P_PlayerArmorIncrease(int value)
308 {
309 if (skill_info.armor_factor)
310 value = FixedMul(value, skill_info.armor_factor);
311
312 return value;
313 }
314
315 //
316 // P_GiveBody
317 // Returns false if the body isn't needed at all
318 //
319
320 dboolean P_GiveBody(player_t * player, int num)
321 {
322 int max;
323
324 max = maxhealth;
325 if (player->chickenTics)
326 {
327 max = MAXCHICKENHEALTH;
328 }
329 if (player->morphTics)
330 {
331 max = MAXMORPHHEALTH;
332 }
333 if (player->health >= max)
334 {
335 return (false);
336 }
337 player->health += P_PlayerHealthIncrease(num);
338 if (player->health > max)
339 {
340 player->health = max;
341 }
342 player->mo->health = player->health;
343 return (true);
344 }
345
346 void P_HealMobj(mobj_t *mo, int num)
347 {
348 player_t *player = mo->player;
349
350 if (mo->health <= 0 || (player && player->playerstate == PST_DEAD))
351 return;
352
353 if (player)
354 {
355 P_GiveBody(player, num);
356 return;
357 }
358 else
359 {
360 int max = P_MobjSpawnHealth(mo);
361
362 mo->health += num;
363 if (mo->health > max)
364 mo->health = max;
365 }
366 }
367
368 //
369 // P_GiveArmor
370 // Returns false if the armor is worse
371 // than the current armor.
372 //
373
374 static dboolean P_GiveArmor(player_t *player, int armortype)
375 {
376 int hits = P_PlayerArmorIncrease(armortype * 100);
377 if (player->armorpoints[ARMOR_ARMOR] >= hits)
378 return false; // don't pick up
379 player->armortype = armortype;
380 player->armorpoints[ARMOR_ARMOR] = hits;
381 return true;
382 }
383
384 //
385 // P_GiveCard
386 //
387
388 void P_GiveCard(player_t *player, card_t card)
389 {
390 if (player->cards[card])
391 return;
392 player->bonuscount = BONUSADD;
393 player->cards[card] = 1;
394
395 if (player == &players[consoleplayer])
396 player->ravenkeys |= 1 << card;
397
398 dsda_WatchCard(card);
399 }
400
401 //
402 // P_GivePower
403 //
404 // Rewritten by Lee Killough
405 //
406
407 dboolean P_GivePower(player_t *player, int power)
408 {
409 static const int tics[NUMPOWERS] = {
410 INVULNTICS, 1 /* strength */, INVISTICS,
411 IRONTICS, 1 /* allmap */, INFRATICS,
412 WPNLEV2TICS, FLIGHTTICS, 1 /* shield */, 1 /* health2 */,
413 SPEEDTICS, MAULATORTICS
414 };
415
416 if (
417 raven &&
418 tics[power] > 1 &&
419 power != pw_ironfeet && power != pw_minotaur &&
420 player->powers[power] > BLINKTHRESHOLD
421 ) return false;
422
423 switch (power)
424 {
425 case pw_invulnerability:
426 if (hexen)
427 {
428 player->mo->flags2 |= MF2_INVULNERABLE;
429 if (player->pclass == PCLASS_MAGE)
430 {
431 player->mo->flags2 |= MF2_REFLECTIVE;
432 }
433 }
434 break;
435 case pw_invisibility:
436 player->mo->flags |= MF_SHADOW;
437 break;
438 case pw_allmap:
439 if (player->powers[pw_allmap])
440 return false;
441 break;
442 case pw_strength:
443 P_GiveBody(player,100);
444 break;
445 case pw_flight:
446 player->mo->flags2 |= MF2_FLY;
447 player->mo->flags |= MF_NOGRAVITY;
448 if (player->mo->z <= player->mo->floorz)
449 {
450 player->flyheight = 10; // thrust the player in the air a bit
451 }
452 break;
453 }
454
455 if (hexen && player->powers[power])
456 return false;
457
458 // Unless player has infinite duration cheat, set duration (killough)
459
460 if (player->powers[power] >= 0)
461 player->powers[power] = tics[power];
462 return true;
463 }
464
465 //
466 // P_TouchSpecialThing
467 //
468
469 static void Heretic_P_TouchSpecialThing(mobj_t * special, mobj_t * toucher);
470 static void Hexen_P_TouchSpecialThing(mobj_t * special, mobj_t * toucher);
471
472 void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher)
473 {
474 player_t *player;
475 int i;
476 int sound;
477 fixed_t delta = special->z - toucher->z;
478
479 if (heretic) return Heretic_P_TouchSpecialThing(special, toucher);
480 if (hexen) return Hexen_P_TouchSpecialThing(special, toucher);
481
482 if (delta > toucher->height || delta < -8*FRACUNIT)
483 return; // out of reach
484
485 sound = sfx_itemup;
486 player = toucher->player;
487
488 // Dead thing touching.
489 // Can happen with a sliding player corpse.
490 if (toucher->health <= 0)
491 return;
492
493 // Identify by sprite.
494 switch (special->sprite)
495 {
496 // armor
497 case SPR_ARM1:
498 if (!P_GiveArmor (player, green_armor_class))
499 return;
500 dsda_AddPlayerMessage(s_GOTARMOR, player);
501 break;
502
503 case SPR_ARM2:
504 if (!P_GiveArmor (player, blue_armor_class))
505 return;
506 dsda_AddPlayerMessage(s_GOTMEGA, player);
507 break;
508
509 // bonus items
510 case SPR_BON1:
511 // can go over 100%
512 player->health += P_PlayerHealthIncrease(1);
513 if (player->health > (maxhealthbonus))//e6y
514 player->health = (maxhealthbonus);//e6y
515 player->mo->health = player->health;
516 dsda_AddPlayerMessage(s_GOTHTHBONUS, player);
517 break;
518
519 case SPR_BON2:
520 // can go over 100%
521 player->armorpoints[ARMOR_ARMOR] += P_PlayerArmorIncrease(1);
522 // e6y
523 // Doom 1.2 does not do check of armor points on overflow.
524 // If you set the "IDKFA Armor" to MAX_INT (DWORD at 0x00064B5A -> FFFFFF7F)
525 // and pick up one or more armor bonuses, your armor becomes negative
526 // and you will die after reception of any damage since this moment.
527 // It happens because the taken health damage depends from armor points
528 // if they are present and becomes equal to very large value in this case
529 if (player->armorpoints[ARMOR_ARMOR] > max_armor && compatibility_level != doom_12_compatibility)
530 player->armorpoints[ARMOR_ARMOR] = max_armor;
531 // e6y
532 // We always give armor type 1 for the armor bonuses;
533 // dehacked only affects the GreenArmor.
534 if (!player->armortype)
535 player->armortype =
536 ((!demo_compatibility || prboom_comp[PC_APPLY_GREEN_ARMOR_CLASS_TO_ARMOR_BONUSES].state) ?
537 green_armor_class : 1);
538 dsda_AddPlayerMessage(s_GOTARMBONUS, player);
539 break;
540
541 case SPR_SOUL:
542 player->health += P_PlayerHealthIncrease(soul_health);
543 if (player->health > max_soul)
544 player->health = max_soul;
545 player->mo->health = player->health;
546 dsda_AddPlayerMessage(s_GOTSUPER, player);
547 sound = sfx_getpow;
548 break;
549
550 case SPR_MEGA:
551 if (gamemode != commercial)
552 return;
553 player->health = mega_health;
554 player->mo->health = player->health;
555 // e6y
556 // We always give armor type 2 for the megasphere;
557 // dehacked only affects the MegaArmor.
558 P_GiveArmor (player,
559 ((!demo_compatibility || prboom_comp[PC_APPLY_BLUE_ARMOR_CLASS_TO_MEGASPHERE].state) ?
560 blue_armor_class : 2));
561 dsda_AddPlayerMessage(s_GOTMSPHERE, player);
562 sound = sfx_getpow;
563 break;
564
565 // cards
566 // leave cards for everyone
567 case SPR_BKEY:
568 if (!player->cards[it_bluecard])
569 dsda_AddPlayerMessage(s_GOTBLUECARD, player);
570 P_GiveCard (player, it_bluecard);
571 if (!netgame)
572 break;
573 return;
574
575 case SPR_YKEY:
576 if (!player->cards[it_yellowcard])
577 dsda_AddPlayerMessage(s_GOTYELWCARD, player);
578 P_GiveCard (player, it_yellowcard);
579 if (!netgame)
580 break;
581 return;
582
583 case SPR_RKEY:
584 if (!player->cards[it_redcard])
585 dsda_AddPlayerMessage(s_GOTREDCARD, player);
586 P_GiveCard (player, it_redcard);
587 if (!netgame)
588 break;
589 return;
590
591 case SPR_BSKU:
592 if (!player->cards[it_blueskull])
593 dsda_AddPlayerMessage(s_GOTBLUESKUL, player);
594 P_GiveCard (player, it_blueskull);
595 if (!netgame)
596 break;
597 return;
598
599 case SPR_YSKU:
600 if (!player->cards[it_yellowskull])
601 dsda_AddPlayerMessage(s_GOTYELWSKUL, player);
602 P_GiveCard (player, it_yellowskull);
603 if (!netgame)
604 break;
605 return;
606
607 case SPR_RSKU:
608 if (!player->cards[it_redskull])
609 dsda_AddPlayerMessage(s_GOTREDSKULL, player);
610 P_GiveCard (player, it_redskull);
611 if (!netgame)
612 break;
613 return;
614
615 // medikits, heals
616 case SPR_STIM:
617 if (!P_GiveBody (player, 10))
618 return;
619 dsda_AddPlayerMessage(s_GOTSTIM, player);
620 break;
621
622 case SPR_MEDI:
623 if (!P_GiveBody (player, 25))
624 return;
625
626 if (player->health < 50) // cph - 25 + the 25 just added, thanks to Quasar for reporting this bug
627 dsda_AddPlayerMessage(s_GOTMEDINEED, player);
628 else
629 dsda_AddPlayerMessage(s_GOTMEDIKIT, player);
630 break;
631
632
633 // power ups
634 case SPR_PINV:
635 if (!P_GivePower (player, pw_invulnerability))
636 return;
637 dsda_AddPlayerMessage(s_GOTINVUL, player);
638 sound = sfx_getpow;
639 break;
640
641 case SPR_PSTR:
642 if (!P_GivePower (player, pw_strength))
643 return;
644 dsda_AddPlayerMessage(s_GOTBERSERK, player);
645 if (player->readyweapon != wp_fist)
646 P_AutoSwitchWeapon(player, wp_fist);
647 sound = sfx_getpow;
648 break;
649
650 case SPR_PINS:
651 if (!P_GivePower (player, pw_invisibility))
652 return;
653 dsda_AddPlayerMessage(s_GOTINVIS, player);
654 sound = sfx_getpow;
655 break;
656
657 case SPR_SUIT:
658 if (!P_GivePower (player, pw_ironfeet))
659 return;
660 dsda_AddPlayerMessage(s_GOTSUIT, player);
661 sound = sfx_getpow;
662 break;
663
664 case SPR_PMAP:
665 if (!P_GivePower (player, pw_allmap))
666 return;
667 dsda_AddPlayerMessage(s_GOTMAP, player);
668 sound = sfx_getpow;
669 break;
670
671 case SPR_PVIS:
672 if (!P_GivePower (player, pw_infrared))
673 return;
674 dsda_AddPlayerMessage(s_GOTVISOR, player);
675 sound = sfx_getpow;
676 break;
677
678 // ammo
679 case SPR_CLIP:
680 if (special->flags & MF_DROPPED)
681 {
682 if (!P_GiveAmmo (player,am_clip,0))
683 return;
684 }
685 else
686 {
687 if (!P_GiveAmmo (player,am_clip,1))
688 return;
689 }
690 dsda_AddPlayerMessage(s_GOTCLIP, player);
691 break;
692
693 case SPR_AMMO:
694 if (!P_GiveAmmo (player, am_clip,5))
695 return;
696 dsda_AddPlayerMessage(s_GOTCLIPBOX, player);
697 break;
698
699 case SPR_ROCK:
700 if (!P_GiveAmmo (player, am_misl,1))
701 return;
702 dsda_AddPlayerMessage(s_GOTROCKET, player);
703 break;
704
705 case SPR_BROK:
706 if (!P_GiveAmmo (player, am_misl,5))
707 return;
708 dsda_AddPlayerMessage(s_GOTROCKBOX, player);
709 break;
710
711 case SPR_CELL:
712 if (!P_GiveAmmo (player, am_cell,1))
713 return;
714 dsda_AddPlayerMessage(s_GOTCELL, player);
715 break;
716
717 case SPR_CELP:
718 if (!P_GiveAmmo (player, am_cell,5))
719 return;
720 dsda_AddPlayerMessage(s_GOTCELLBOX, player);
721 break;
722
723 case SPR_SHEL:
724 if (!P_GiveAmmo (player, am_shell,1))
725 return;
726 dsda_AddPlayerMessage(s_GOTSHELLS, player);
727 break;
728
729 case SPR_SBOX:
730 if (!P_GiveAmmo (player, am_shell,5))
731 return;
732 dsda_AddPlayerMessage(s_GOTSHELLBOX, player);
733 break;
734
735 case SPR_BPAK:
736 if (!player->backpack)
737 {
738 for (i=0 ; i<NUMAMMO ; i++)
739 player->maxammo[i] *= 2;
740 player->backpack = true;
741 }
742 for (i=0 ; i<NUMAMMO ; i++)
743 P_GiveAmmo (player, i, 1);
744 dsda_AddPlayerMessage(s_GOTBACKPACK, player);
745 break;
746
747 // weapons
748 case SPR_BFUG:
749 if (!P_GiveWeapon (player, wp_bfg, false) )
750 return;
751 dsda_AddPlayerMessage(s_GOTBFG9000, player);
752 sound = sfx_wpnup;
753 break;
754
755 case SPR_MGUN:
756 if (!P_GiveWeapon (player, wp_chaingun, (special->flags&MF_DROPPED)!=0) )
757 return;
758 dsda_AddPlayerMessage(s_GOTCHAINGUN, player);
759 sound = sfx_wpnup;
760 break;
761
762 case SPR_CSAW:
763 if (!P_GiveWeapon (player, wp_chainsaw, false) )
764 return;
765 dsda_AddPlayerMessage(s_GOTCHAINSAW, player);
766 sound = sfx_wpnup;
767 break;
768
769 case SPR_LAUN:
770 if (!P_GiveWeapon (player, wp_missile, false) )
771 return;
772 dsda_AddPlayerMessage(s_GOTLAUNCHER, player);
773 sound = sfx_wpnup;
774 break;
775
776 case SPR_PLAS:
777 if (!P_GiveWeapon (player, wp_plasma, false) )
778 return;
779 dsda_AddPlayerMessage(s_GOTPLASMA, player);
780 sound = sfx_wpnup;
781 break;
782
783 case SPR_SHOT:
784 if (!P_GiveWeapon (player, wp_shotgun, (special->flags&MF_DROPPED)!=0 ) )
785 return;
786 dsda_AddPlayerMessage(s_GOTSHOTGUN, player);
787 sound = sfx_wpnup;
788 break;
789
790 case SPR_SGN2:
791 if (!P_GiveWeapon(player, wp_supershotgun, (special->flags&MF_DROPPED)!=0))
792 return;
793 dsda_AddPlayerMessage(s_GOTSHOTGUN2, player);
794 sound = sfx_wpnup;
795 break;
796
797 default:
798 I_Error ("P_SpecialThing: Unknown gettable thing");
799 }
800
801 if (special->special)
802 {
803 map_format.execute_line_special(special->special, special->special_args, NULL, 0, player->mo);
804 special->special = 0;
805 }
806
807 if (special->flags & MF_COUNTITEM)
808 player->itemcount++;
809
810 if (special->flags2 & MF2_COUNTSECRET)
811 P_PlayerCollectSecret(player);
812
813 P_RemoveMobj (special);
814 player->bonuscount += BONUSADD;
815
816 /* cph 20028/10 - for old-school DM addicts, allow old behavior
817 * where only consoleplayer's pickup sounds are heard */
818 // displayplayer, not consoleplayer, for viewing multiplayer demos
819 if (!comp[comp_sound])
820 S_StartSound (player->mo, sound | PICKUP_SOUND); // killough 4/25/98
821 else if (player == &players[displayplayer])
822 S_StartVoidSound (sound | PICKUP_SOUND);
823 }
824
825 //
826 // KillMobj
827 //
828
829 static mobj_t *ActiveMinotaur(player_t * master);
830
831 // killough 11/98: make static
832 static void P_KillMobj(mobj_t *source, mobj_t *target)
833 {
834 mobjtype_t item;
835 mobj_t *mo;
836 int xdeath_limit;
837
838 target->flags &= ~(MF_SHOOTABLE|MF_FLOAT|MF_SKULLFLY);
839
840 if (target->type != MT_SKULL)
841 target->flags &= ~MF_NOGRAVITY;
842
843 target->flags |= MF_CORPSE|MF_DROPOFF;
844 target->height >>= 2;
845
846 // heretic
847 target->flags2 &= ~MF2_PASSMOBJ;
848
849 if (
850 mbf21 || (
851 compatibility_level == mbf_compatibility &&
852 !prboom_comp[PC_MBF_REMOVE_THINKER_IN_KILLMOBJ].state
853 )
854 )
855 {
856 // killough 8/29/98: remove from threaded list
857 P_UpdateThinker(&target->thinker);
858 }
859
860 if (!((target->flags ^ MF_COUNTKILL) & (MF_FRIEND | MF_COUNTKILL)))
861 totallive--;
862
863 dsda_WatchDeath(target);
864
865 if (map_format.hexen && target->special)
866 {
867 if (!hexen || (target->flags & MF_COUNTKILL || target->type == HEXEN_MT_ZBELL))
868 { // Initiate monster death actions
869 if (hexen && target->type == HEXEN_MT_SORCBOSS)
870 {
871 byte dummyArgs[3] = {0, 0, 0};
872 P_StartACS(target->special, 0, dummyArgs, target, NULL, 0);
873 }
874 else
875 {
876 map_format.execute_line_special(
877 target->special, target->special_args, NULL, 0,
878 map_info.flags & MI_ACTIVATE_OWN_DEATH_SPECIALS ? target : source
879 );
880 }
881 }
882 }
883
884 if (source && source->player)
885 {
886 // count for intermission
887 if (target->flags & MF_COUNTKILL)
888 {
889 dsda_WatchKill(source->player, target);
890 }
891 if (target->player)
892 {
893 source->player->frags[target->player-players]++;
894
895 if (heretic && target != source)
896 {
897 if (source->player == &players[consoleplayer])
898 {
899 S_StartVoidSound(heretic_sfx_gfrag);
900 }
901 if (source->player->chickenTics)
902 { // Make a super chicken
903 P_GivePower(source->player, pw_weaponlevel2);
904 }
905 }
906 }
907 }
908 else
909 if (target->flags & MF_COUNTKILL) { /* Add to kills tally */
910 if ((compatibility_level < lxdoom_1_compatibility) || !netgame) {
911 if (!netgame)
912 {
913 dsda_WatchKill(&players[0], target);
914 }
915 else
916 {
917 if (!deathmatch) {
918 if (target->lastenemy && target->lastenemy->health > 0 && target->lastenemy->player)
919 {
920 dsda_WatchKill(target->lastenemy->player, target);
921 }
922 else
923 {
924 unsigned int player;
925 for (player = 0; player < g_maxplayers; player++)
926 {
927 if (playeringame[player])
928 {
929 dsda_WatchKill(&players[player], target);
930 break;
931 }
932 }
933 }
934 }
935 }
936 }
937 else
938 if (!deathmatch) {
939 // try and find a player to give the kill to, otherwise give the
940 // kill to a random player. this fixes the missing monsters bug
941 // in coop - rain
942 // CPhipps - not a bug as such, but certainly an inconsistency.
943 if (target->lastenemy && target->lastenemy->health > 0 && target->lastenemy->player) // Fighting a player
944 {
945 dsda_WatchKill(target->lastenemy->player, target);
946 }
947 else {
948 // cph - randomely choose a player in the game to be credited
949 // and do it uniformly between the active players
950 unsigned int activeplayers = 0, player, i;
951
952 for (player = 0; player < g_maxplayers; player++)
953 if (playeringame[player])
954 activeplayers++;
955
956 if (activeplayers) {
957 player = P_Random(pr_friends) % activeplayers;
958
959 for (i = 0; i < g_maxplayers; i++)
960 if (playeringame[i])
961 if (!player--)
962 {
963 dsda_WatchKill(&players[i], target);
964 }
965 }
966 }
967 }
968 }
969
970 if (target->player)
971 {
972 // count environment kills against you
973 if (!source)
974 target->player->frags[target->player-players]++;
975
976 target->flags &= ~MF_SOLID;
977
978 // heretic
979 target->flags2 &= ~MF2_FLY;
980 target->player->powers[pw_flight] = 0;
981 target->player->powers[pw_weaponlevel2] = 0;
982
983 target->player->playerstate = PST_DEAD;
984 P_DropWeapon (target->player);
985
986 // heretic
987 if (target->flags2 & MF2_FIREDAMAGE)
988 { // Player flame death
989 switch (target->player->pclass)
990 {
991 case PCLASS_NULL: // heretic
992 P_SetMobjState(target, HERETIC_S_PLAY_FDTH1);
993 return;
994 case PCLASS_FIGHTER:
995 S_StartMobjSound(target, hexen_sfx_player_fighter_burn_death);
996 P_SetMobjState(target, HEXEN_S_PLAY_F_FDTH1);
997 return;
998 case PCLASS_CLERIC:
999 S_StartMobjSound(target, hexen_sfx_player_cleric_burn_death);
1000 P_SetMobjState(target, HEXEN_S_PLAY_C_FDTH1);
1001 return;
1002 case PCLASS_MAGE:
1003 S_StartMobjSound(target, hexen_sfx_player_mage_burn_death);
1004 P_SetMobjState(target, HEXEN_S_PLAY_M_FDTH1);
1005 return;
1006 default:
1007 break;
1008 }
1009 }
1010
1011 // hexen
1012 if (target->flags2 & MF2_ICEDAMAGE)
1013 { // Player ice death
1014 target->flags &= ~(7 << MF_TRANSSHIFT); //no translation
1015 target->flags |= MF_ICECORPSE;
1016 switch (target->player->pclass)
1017 {
1018 case PCLASS_FIGHTER:
1019 P_SetMobjState(target, HEXEN_S_FPLAY_ICE);
1020 return;
1021 case PCLASS_CLERIC:
1022 P_SetMobjState(target, HEXEN_S_CPLAY_ICE);
1023 return;
1024 case PCLASS_MAGE:
1025 P_SetMobjState(target, HEXEN_S_MPLAY_ICE);
1026 return;
1027 case PCLASS_PIG:
1028 P_SetMobjState(target, HEXEN_S_PIG_ICE);
1029 return;
1030 default:
1031 break;
1032 }
1033 }
1034
1035 if (target->player == &players[consoleplayer] && automap_active)
1036 AM_Stop(true); // don't die in auto map; switch view prior to dying
1037 }
1038
1039 if (hexen)
1040 {
1041 if (target->flags2 & MF2_FIREDAMAGE)
1042 {
1043 if (target->type == HEXEN_MT_FIGHTER_BOSS
1044 || target->type == HEXEN_MT_CLERIC_BOSS
1045 || target->type == HEXEN_MT_MAGE_BOSS)
1046 {
1047 switch (target->type)
1048 {
1049 case HEXEN_MT_FIGHTER_BOSS:
1050 S_StartMobjSound(target, hexen_sfx_player_fighter_burn_death);
1051 P_SetMobjState(target, HEXEN_S_PLAY_F_FDTH1);
1052 return;
1053 case HEXEN_MT_CLERIC_BOSS:
1054 S_StartMobjSound(target, hexen_sfx_player_cleric_burn_death);
1055 P_SetMobjState(target, HEXEN_S_PLAY_C_FDTH1);
1056 return;
1057 case HEXEN_MT_MAGE_BOSS:
1058 S_StartMobjSound(target, hexen_sfx_player_mage_burn_death);
1059 P_SetMobjState(target, HEXEN_S_PLAY_M_FDTH1);
1060 return;
1061 default:
1062 break;
1063 }
1064 }
1065 else if (target->type == HEXEN_MT_TREEDESTRUCTIBLE)
1066 {
1067 P_SetMobjState(target, HEXEN_S_ZTREEDES_X1);
1068 target->height = 24 * FRACUNIT;
1069 S_StartMobjSound(target, hexen_sfx_tree_explode);
1070 return;
1071 }
1072 }
1073 if (target->flags2 & MF2_ICEDAMAGE)
1074 {
1075 target->flags |= MF_ICECORPSE;
1076 switch (target->type)
1077 {
1078 case HEXEN_MT_BISHOP:
1079 P_SetMobjState(target, HEXEN_S_BISHOP_ICE);
1080 return;
1081 case HEXEN_MT_CENTAUR:
1082 case HEXEN_MT_CENTAURLEADER:
1083 P_SetMobjState(target, HEXEN_S_CENTAUR_ICE);
1084 return;
1085 case HEXEN_MT_DEMON:
1086 case HEXEN_MT_DEMON2:
1087 P_SetMobjState(target, HEXEN_S_DEMON_ICE);
1088 return;
1089 case HEXEN_MT_SERPENT:
1090 case HEXEN_MT_SERPENTLEADER:
1091 P_SetMobjState(target, HEXEN_S_SERPENT_ICE);
1092 return;
1093 case HEXEN_MT_WRAITH:
1094 case HEXEN_MT_WRAITHB:
1095 P_SetMobjState(target, HEXEN_S_WRAITH_ICE);
1096 return;
1097 case HEXEN_MT_ETTIN:
1098 P_SetMobjState(target, HEXEN_S_ETTIN_ICE1);
1099 return;
1100 case HEXEN_MT_FIREDEMON:
1101 P_SetMobjState(target, HEXEN_S_FIRED_ICE1);
1102 return;
1103 case HEXEN_MT_FIGHTER_BOSS:
1104 P_SetMobjState(target, HEXEN_S_FIGHTER_ICE);
1105 return;
1106 case HEXEN_MT_CLERIC_BOSS:
1107 P_SetMobjState(target, HEXEN_S_CLERIC_ICE);
1108 return;
1109 case HEXEN_MT_MAGE_BOSS:
1110 P_SetMobjState(target, HEXEN_S_MAGE_ICE);
1111 return;
1112 case HEXEN_MT_PIG:
1113 P_SetMobjState(target, HEXEN_S_PIG_ICE);
1114 return;
1115 default:
1116 target->flags &= ~MF_ICECORPSE;
1117 break;
1118 }
1119 }
1120
1121 if (target->type == HEXEN_MT_MINOTAUR)
1122 {
1123 mobj_t *master = target->special1.m;
1124 if (master->health > 0)
1125 {
1126 if (!ActiveMinotaur(master->player))
1127 {
1128 master->player->powers[pw_minotaur] = 0;
1129 }
1130 }
1131 }
1132 else if (target->type == HEXEN_MT_TREEDESTRUCTIBLE)
1133 {
1134 target->height = 24 * FRACUNIT;
1135 }
1136 if (target->health < -(P_MobjSpawnHealth(target) >> 1)
1137 && target->info->xdeathstate)
1138 { // Extreme death
1139 P_SetMobjState(target, target->info->xdeathstate);
1140 }
1141 else
1142 { // Normal death
1143 if ((target->type == HEXEN_MT_FIREDEMON) &&
1144 (target->z <= target->floorz + 2 * FRACUNIT) &&
1145 (target->info->xdeathstate))
1146 {
1147 // This is to fix the imps' staying in fall state
1148 P_SetMobjState(target, target->info->xdeathstate);
1149 }
1150 else
1151 {
1152 P_SetMobjState(target, target->info->deathstate);
1153 }
1154 }
1155 }
1156 else
1157 {
1158 xdeath_limit = heretic ? (P_MobjSpawnHealth(target) >> 1) : P_MobjSpawnHealth(target);
1159 if (target->health < -xdeath_limit && target->info->xdeathstate)
1160 P_SetMobjState (target, target->info->xdeathstate);
1161 else
1162 P_SetMobjState (target, target->info->deathstate);
1163 }
1164
1165 target->tics -= P_Random(pr_killtics)&3;
1166
1167 if (raven) return;
1168
1169 if (target->tics < 1)
1170 target->tics = 1;
1171
1172 // In Chex Quest, monsters don't drop items.
1173 if (gamemission == tc_chex)
1174 {
1175 return;
1176 }
1177
1178 // Drop stuff.
1179 // This determines the kind of object spawned
1180 // during the death frame of a thing.
1181
1182 if (target->info->droppeditem != MT_NULL)
1183 {
1184 item = target->info->droppeditem;
1185 }
1186 else return;
1187
1188 mo = P_SpawnMobj (target->x,target->y,ONFLOORZ, item);
1189 mo->flags |= MF_DROPPED; // special versions of items
1190
1191 if (target->momx == 0 && target->momy == 0)
1192 {
1193 target->flags |= MF_FOREGROUND;
1194 }
1195 }
1196
1197 //
1198 // P_DamageMobj
1199 // Damages both enemies and players
1200 // "inflictor" is the thing that caused the damage
1201 // creature or missile, can be NULL (slime, etc)
1202 // "source" is the thing to target after taking damage
1203 // creature or NULL
1204 // Source and inflictor are the same for melee attacks.
1205 // Source can be NULL for slime, barrel explosions
1206 // and other environmental stuff.
1207 //
1208
1209 static dboolean P_InfightingImmune(mobj_t *target, mobj_t *source)
1210 {
1211 return // not default behaviour, and same group
1212 mobjinfo[target->type].infighting_group != IG_DEFAULT &&
1213 mobjinfo[target->type].infighting_group == mobjinfo[source->type].infighting_group;
1214 }
1215
1216 static dboolean P_MorphMonster(mobj_t * actor);
1217
1218 void P_DamageMobj(mobj_t *target,mobj_t *inflictor, mobj_t *source, int damage)
1219 {
1220 player_t *player;
1221 dboolean justhit = false; /* killough 11/98 */
1222
1223 /* killough 8/31/98: allow bouncers to take damage */
1224 if (!(target->flags & (MF_SHOOTABLE | MF_BOUNCES)))
1225 return; // shouldn't happen...
1226
1227 if (target->health <= 0)
1228 {
1229 // hexen
1230 if (inflictor && inflictor->flags2 & MF2_ICEDAMAGE)
1231 {
1232 return;
1233 }
1234 else if (target->flags & MF_ICECORPSE) // frozen
1235 {
1236 target->tics = 1;
1237 target->momx = target->momy = 0;
1238 }
1239 return;
1240 }
1241
1242 // hexen has a different order of checks
1243 if (hexen)
1244 {
1245 if ((target->flags2 & MF2_INVULNERABLE) && damage < 10000)
1246 { // mobj is invulnerable
1247 if (target->player)
1248 return; // for player, no exceptions
1249 if (inflictor)
1250 {
1251 switch (inflictor->type)
1252 {
1253 // These inflictors aren't foiled by invulnerability
1254 case HEXEN_MT_HOLY_FX:
1255 case HEXEN_MT_POISONCLOUD:
1256 case HEXEN_MT_FIREBOMB:
1257 break;
1258 default:
1259 return;
1260 }
1261 }
1262 else
1263 {
1264 return;
1265 }
1266 }
1267 if (target->player)
1268 {
1269 if (damage < 1000 && ((target->player->cheats & CF_GODMODE)
1270 || target->player->powers[pw_invulnerability]))
1271 {
1272 return;
1273 }
1274 }
1275 }
1276
1277 if (target->flags & MF_SKULLFLY)
1278 {
1279 if (heretic && target->type == HERETIC_MT_MINOTAUR) return;
1280 target->momx = target->momy = target->momz = 0;
1281 }
1282
1283 if (target->flags2 & MF2_DORMANT)
1284 {
1285 // Invulnerable, and won't wake up
1286 return;
1287 }
1288
1289 player = target->player;
1290 if (player && skill_info.damage_factor)
1291 damage = FixedMul(damage, skill_info.damage_factor);
1292
1293 // Special damage types
1294 if (raven && inflictor)
1295 switch (inflictor->type)
1296 {
1297 case HERETIC_MT_EGGFX:
1298 if (player)
1299 {
1300 P_ChickenMorphPlayer(player);
1301 }
1302 else
1303 {
1304 P_ChickenMorph(target);
1305 }
1306 return; // Always return
1307 case HERETIC_MT_WHIRLWIND:
1308 P_TouchWhirlwind(target);
1309 return;
1310 case HERETIC_MT_MINOTAUR:
1311 if (inflictor->flags & MF_SKULLFLY)
1312 { // Slam only when in charge mode
1313 P_MinotaurSlam(inflictor, target);
1314 return;
1315 }
1316 break;
1317 case HERETIC_MT_MACEFX4: // Death ball
1318 if ((target->flags2 & MF2_BOSS) || target->type == HERETIC_MT_HEAD)
1319 { // Don't allow cheap boss kills
1320 break;
1321 }
1322 else if (target->player)
1323 { // Player specific checks
1324 if (target->player->powers[pw_invulnerability])
1325 { // Can't hurt invulnerable players
1326 break;
1327 }
1328 if (P_AutoUseChaosDevice(target->player))
1329 { // Player was saved using chaos device
1330 return;
1331 }
1332 }
1333 damage = 10000; // Something's gonna die
1334 break;
1335 case HERETIC_MT_PHOENIXFX2: // Flame thrower
1336 if (target->player && P_Random(pr_heretic) < 128)
1337 { // Freeze player for a bit
1338 target->reactiontime += 4;
1339 }
1340 break;
1341 case HERETIC_MT_RAINPLR1: // Rain missiles
1342 case HERETIC_MT_RAINPLR2:
1343 case HERETIC_MT_RAINPLR3:
1344 case HERETIC_MT_RAINPLR4:
1345 if (target->flags2 & MF2_BOSS)
1346 { // Decrease damage for bosses
1347 damage = (P_Random(pr_heretic) & 7) + 1;
1348 }
1349 break;
1350 case HERETIC_MT_HORNRODFX2:
1351 case HERETIC_MT_PHOENIXFX1:
1352 if (target->type == HERETIC_MT_SORCERER2 && P_Random(pr_heretic) < 96)
1353 { // D'Sparil teleports away
1354 P_DSparilTeleport(target);
1355 return;
1356 }
1357 break;
1358 case HERETIC_MT_BLASTERFX1:
1359 case HERETIC_MT_RIPPER:
1360 if (target->type == HERETIC_MT_HEAD)
1361 { // Less damage to Ironlich bosses
1362 damage = P_Random(pr_heretic) & 1;
1363 if (!damage)
1364 {
1365 return;
1366 }
1367 }
1368 break;
1369 case HEXEN_MT_EGGFX:
1370 if (player)
1371 {
1372 P_MorphPlayer(player);
1373 }
1374 else
1375 {
1376 P_MorphMonster(target);
1377 }
1378 return; // Always return
1379 case HEXEN_MT_TELOTHER_FX1:
1380 case HEXEN_MT_TELOTHER_FX2:
1381 case HEXEN_MT_TELOTHER_FX3:
1382 case HEXEN_MT_TELOTHER_FX4:
1383 case HEXEN_MT_TELOTHER_FX5:
1384 if ((target->flags & MF_COUNTKILL) &&
1385 (target->type != HEXEN_MT_SERPENT) &&
1386 (target->type != HEXEN_MT_SERPENTLEADER) &&
1387 (!(target->flags2 & MF2_BOSS)))
1388 {
1389 P_TeleportOther(target);
1390 }
1391 return;
1392 case HEXEN_MT_MINOTAUR:
1393 if (inflictor->flags & MF_SKULLFLY)
1394 { // Slam only when in charge mode
1395 P_MinotaurSlam(inflictor, target);
1396 return;
1397 }
1398 break;
1399 case HEXEN_MT_BISH_FX:
1400 // Bishops are just too nasty
1401 damage >>= 1;
1402 break;
1403 case HEXEN_MT_SHARDFX1:
1404 switch (inflictor->special2.i)
1405 {
1406 case 3:
1407 damage <<= 3;
1408 break;
1409 case 2:
1410 damage <<= 2;
1411 break;
1412 case 1:
1413 damage <<= 1;
1414 break;
1415 default:
1416 break;
1417 }
1418 break;
1419 case HEXEN_MT_CSTAFF_MISSILE:
1420 // Cleric Serpent Staff does poison damage
1421 if (target->player)
1422 {
1423 P_PoisonPlayer(target->player, source, 20);
1424 damage >>= 1;
1425 }
1426 break;
1427 case HEXEN_MT_ICEGUY_FX2:
1428 damage >>= 1;
1429 break;
1430 case HEXEN_MT_POISONDART:
1431 if (target->player)
1432 {
1433 P_PoisonPlayer(target->player, source, 20);
1434 damage >>= 1;
1435 }
1436 break;
1437 case HEXEN_MT_POISONCLOUD:
1438 if (target->player)
1439 {
1440 if (target->player->poisoncount < 4)
1441 {
1442 P_PoisonDamage(target->player, source, 15 + (P_Random(pr_hexen) & 15), false); // Don't play painsound
1443 P_PoisonPlayer(target->player, source, 50);
1444 S_StartMobjSound(target, hexen_sfx_player_poisoncough);
1445 }
1446 return;
1447 }
1448 else if (!(target->flags & MF_COUNTKILL))
1449 { // only damage monsters/players with the poison cloud
1450 return;
1451 }
1452 break;
1453 case HEXEN_MT_FSWORD_MISSILE:
1454 if (target->player)
1455 {
1456 damage -= damage >> 2;
1457 }
1458 break;
1459 default:
1460 break;
1461 }
1462
1463 // Some close combat weapons should not
1464 // inflict thrust and push the victim out of reach,
1465 // thus kick away unless using the chainsaw.
1466
1467 if (
1468 inflictor &&
1469 !(target->flags & MF_NOCLIP) && // hexen_note: not done in hexen, does it matter?
1470 !(
1471 source &&
1472 source->player &&
1473 (hexen || weaponinfo[source->player->readyweapon].flags & WPF_NOTHRUST)
1474 ) &&
1475 !(inflictor->flags2 & MF2_NODMGTHRUST)
1476 )
1477 {
1478 unsigned ang = R_PointToAngle2 (inflictor->x, inflictor->y,
1479 target->x, target->y);
1480
1481 fixed_t thrust = damage * (FRACUNIT >> 3) * g_thrust_factor / target->info->mass;
1482
1483 // make fall forwards sometimes
1484 if ( damage < 40 && damage > target->health
1485 && target->z - inflictor->z > 64*FRACUNIT
1486 && P_Random(pr_damagemobj) & 1)
1487 {
1488 ang += ANG180;
1489 thrust *= 4;
1490 }
1491
1492 ang >>= ANGLETOFINESHIFT;
1493
1494 if (source && source->player && (source == inflictor)
1495 && source->player->powers[pw_weaponlevel2]
1496 && source->player->readyweapon == wp_staff)
1497 {
1498 // Staff power level 2
1499 target->momx += FixedMul(10 * FRACUNIT, finecosine[ang]);
1500 target->momy += FixedMul(10 * FRACUNIT, finesine[ang]);
1501 if (!(target->flags & MF_NOGRAVITY))
1502 {
1503 target->momz += 5 * FRACUNIT;
1504 }
1505 }
1506 else
1507 {
1508 target->momx += FixedMul(thrust, finecosine[ang]);
1509 target->momy += FixedMul(thrust, finesine[ang]);
1510 }
1511
1512 /* killough 11/98: thrust objects hanging off ledges */
1513 if (target->intflags & MIF_FALLING && target->gear >= MAXGEAR)
1514 target->gear = 0;
1515 }
1516
1517 // player specific
1518 if (player)
1519 {
1520 // end of game hell hack
1521 if (!raven && target->subsector->sector->special == 11 && damage >= target->health)
1522 damage = target->health - 1;
1523
1524 // Below certain threshold,
1525 // ignore damage in GOD mode, or with INVUL power.
1526 // killough 3/26/98: make god mode 100% god mode in non-compat mode
1527
1528 if (
1529 !hexen &&
1530 (damage < 1000 || (!comp[comp_god] && (player->cheats & CF_GODMODE))) &&
1531 (player->cheats & CF_GODMODE || player->powers[pw_invulnerability])
1532 )
1533 return;
1534
1535 if (hexen)
1536 {
1537 int i;
1538 int saved;
1539 fixed_t savedPercent = pclass[player->pclass].auto_armor_save
1540 + player->armorpoints[ARMOR_ARMOR]
1541 + player->armorpoints[ARMOR_SHIELD]
1542 + player->armorpoints[ARMOR_HELMET]
1543 + player->armorpoints[ARMOR_AMULET];
1544 if (savedPercent)
1545 { // armor absorbed some damage
1546 if (savedPercent > 100 * FRACUNIT)
1547 {
1548 savedPercent = 100 * FRACUNIT;
1549 }
1550 for (i = 0; i < NUMARMOR; i++)
1551 {
1552 if (player->armorpoints[i])
1553 {
1554 player->armorpoints[i] -= FixedDiv(
1555 FixedMul(damage << FRACBITS, pclass[player->pclass].armor_increment[i]),
1556 300 * FRACUNIT
1557 );
1558 if (player->armorpoints[i] < 2 * FRACUNIT)
1559 {
1560 player->armorpoints[i] = 0;
1561 }
1562 }
1563 }
1564 saved = FixedDiv(
1565 FixedMul(damage << FRACBITS, savedPercent),
1566 100 * FRACUNIT
1567 );
1568 if (saved > savedPercent * 2)
1569 {
1570 saved = savedPercent * 2;
1571 }
1572 damage -= saved >> FRACBITS;
1573 }
1574 }
1575 else
1576 {
1577 if (player->armortype)
1578 {
1579 int saved;
1580
1581 if (heretic)
1582 saved = player->armortype == 1 ? (damage >> 1) : (damage >> 1) + (damage >> 2);
1583 else
1584 saved = player->armortype == 1 ? damage / 3 : damage / 2;
1585
1586 if (player->armorpoints[ARMOR_ARMOR] <= saved)
1587 {
1588 // armor is used up
1589 saved = player->armorpoints[ARMOR_ARMOR];
1590 player->armortype = 0;
1591 }
1592 player->armorpoints[ARMOR_ARMOR] -= saved;
1593 damage -= saved;
1594 }
1595 }
1596
1597 if (
1598 raven &&
1599 damage >= player->health &&
1600 (skill_info.flags & SI_AUTO_USE_HEALTH || deathmatch) &&
1601 !player->chickenTics && !player->morphTics
1602 )
1603 { // Try to use some inventory health
1604 P_AutoUseHealth(player, damage - player->health + 1);
1605 }
1606
1607 player->health -= damage; // mirror mobj health here for Dave
1608 if (player->health < 0)
1609 player->health = 0;
1610
1611 player->attacker = source;
1612 player->damagecount += damage; // add damage after armor / invuln
1613
1614 if (player->damagecount > 100)
1615 player->damagecount = 100; // teleport stomp does 10k points...
1616
1617 if (raven && player == &players[consoleplayer])
1618 {
1619 SB_PaletteFlash(false);
1620 }
1621 }
1622
1623 dsda_WatchDamage(target, inflictor, source, damage);
1624
1625 // do the damage
1626 target->health -= damage;
1627 if (target->health <= 0)
1628 {
1629 if (heretic) {
1630 target->special1.i = damage;
1631 if (target->type == HERETIC_MT_POD && source && source->type != HERETIC_MT_POD)
1632 { // Make sure players get frags for chain-reaction kills
1633 P_SetTarget(&target->target, source);
1634 }
1635 if (player && inflictor && !player->chickenTics)
1636 { // Check for flame death
1637 if ((inflictor->flags2 & MF2_FIREDAMAGE)
1638 || ((inflictor->type == HERETIC_MT_PHOENIXFX1)
1639 && (target->health > -50) && (damage > 25)))
1640 {
1641 target->flags2 |= MF2_FIREDAMAGE;
1642 }
1643 }
1644 }
1645 else if (hexen)
1646 {
1647 if (inflictor)
1648 { // check for special fire damage or ice damage deaths
1649 if (inflictor->flags2 & MF2_FIREDAMAGE)
1650 {
1651 if (player && !player->morphTics)
1652 { // Check for flame death
1653 if (target->health > -50 && damage > 25)
1654 {
1655 target->flags2 |= MF2_FIREDAMAGE;
1656 }
1657 }
1658 else
1659 {
1660 target->flags2 |= MF2_FIREDAMAGE;
1661 }
1662 }
1663 else if (inflictor->flags2 & MF2_ICEDAMAGE)
1664 {
1665 target->flags2 |= MF2_ICEDAMAGE;
1666 }
1667 }
1668 if (source && (source->type == HEXEN_MT_MINOTAUR))
1669 { // Minotaur's kills go to his master
1670 mobj_t *master = source->special1.m;
1671 // Make sure still alive and not a pointer to fighter head
1672 if (master->player && (master->player->mo == master))
1673 {
1674 source = master;
1675 }
1676 }
1677 if (source && (source->player) &&
1678 (source->player->readyweapon == wp_fourth))
1679 {
1680 // Always extreme death from fourth weapon
1681 target->health = -5000;
1682 }
1683 }
1684
1685 P_KillMobj (source, target);
1686 return;
1687 }
1688
1689 // killough 9/7/98: keep track of targets so that friends can help friends
1690 if (mbf_features)
1691 {
1692 /* If target is a player, set player's target to source,
1693 * so that a friend can tell who's hurting a player
1694 */
1695 if (player) P_SetTarget(&target->target, source);
1696
1697 /* killough 9/8/98:
1698 * If target's health is less than 50%, move it to the front of its list.
1699 * This will slightly increase the chances that enemies will choose to
1700 * "finish it off", but its main purpose is to alert friends of danger.
1701 */
1702 if (target->health*2 < P_MobjSpawnHealth(target))
1703 {
1704 thinker_t *cap = &thinkerclasscap[target->flags & MF_FRIEND ?
1705 th_friends : th_enemies];
1706 (target->thinker.cprev->cnext = target->thinker.cnext)->cprev =
1707 target->thinker.cprev;
1708 (target->thinker.cnext = cap->cnext)->cprev = &target->thinker;
1709 (target->thinker.cprev = cap)->cnext = &target->thinker;
1710 }
1711 }
1712
1713 if (!(skill_info.flags & SI_NO_PAIN) &&
1714 P_Random(pr_painchance) < target->info->painchance &&
1715 !(target->flags & MF_SKULLFLY)) //killough 11/98: see below
1716 {
1717 if (hexen && inflictor && inflictor->type >= HEXEN_MT_LIGHTNING_FLOOR &&
1718 inflictor->type <= HEXEN_MT_LIGHTNING_ZAP)
1719 {
1720 if (P_Random(pr_hexen) < 96)
1721 {
1722 target->flags |= MF_JUSTHIT; // fight back!
1723 P_SetMobjState(target, target->info->painstate);
1724 }
1725 else
1726 { // "electrocute" the target
1727 target->frame |= FF_FULLBRIGHT;
1728 if (target->flags & MF_COUNTKILL && P_Random(pr_hexen) < 128
1729 && !S_GetSoundPlayingInfo(target, hexen_sfx_puppybeat))
1730 {
1731 if ((target->type == HEXEN_MT_CENTAUR) ||
1732 (target->type == HEXEN_MT_CENTAURLEADER) ||
1733 (target->type == HEXEN_MT_ETTIN))
1734 {
1735 S_StartMobjSound(target, hexen_sfx_puppybeat);
1736 }
1737 }
1738 }
1739 }
1740 else
1741 {
1742 if (mbf_features)
1743 justhit = true;
1744 else
1745 target->flags |= MF_JUSTHIT; // fight back!
1746
1747 P_SetMobjState(target, target->info->painstate);
1748
1749 if (hexen && inflictor && inflictor->type == HEXEN_MT_POISONCLOUD)
1750 {
1751 if (target->flags & MF_COUNTKILL && P_Random(pr_hexen) < 128
1752 && !S_GetSoundPlayingInfo(target, hexen_sfx_puppybeat))
1753 {
1754 if ((target->type == HEXEN_MT_CENTAUR) ||
1755 (target->type == HEXEN_MT_CENTAURLEADER) ||
1756 (target->type == HEXEN_MT_ETTIN))
1757 {
1758 S_StartMobjSound(target, hexen_sfx_puppybeat);
1759 }
1760 }
1761 }
1762 }
1763 }
1764
1765 target->reactiontime = 0; // we're awake now...
1766
1767 /* killough 9/9/98: cleaned up, made more consistent: */
1768 //e6y: Monsters could commit suicide in Doom v1.2 if they damaged themselves by exploding a barrel
1769 if (
1770 source &&
1771 (source != target || compatibility_level == doom_12_compatibility) &&
1772 !(source->flags2 & MF2_DMGIGNORED) &&
1773 (!target->threshold || target->flags2 & MF2_NOTHRESHOLD) &&
1774 ((source->flags ^ target->flags) & MF_FRIEND || monster_infighting || !mbf_features) &&
1775 !(
1776 raven && (
1777 source->flags2 & MF2_BOSS ||
1778 (target->type == HERETIC_MT_SORCERER2 && source->type == HERETIC_MT_WIZARD) ||
1779 target->type == HEXEN_MT_BISHOP ||
1780 target->type == HEXEN_MT_MINOTAUR ||
1781 (target->type == HEXEN_MT_CENTAUR && source->type == HEXEN_MT_CENTAURLEADER) ||
1782 (target->type == HEXEN_MT_CENTAURLEADER && source->type == HEXEN_MT_CENTAUR)
1783 )
1784 ) &&
1785 !P_InfightingImmune(target, source)
1786 )
1787 {
1788 /* if not intent on another player, chase after this one
1789 *
1790 * killough 2/15/98: remember last enemy, to prevent
1791 * sleeping early; 2/21/98: Place priority on players
1792 * killough 9/9/98: cleaned up, made more consistent:
1793 */
1794
1795 if (
1796 !target->lastenemy ||
1797 target->lastenemy->health <= 0 ||
1798 (
1799 !mbf_features ?
1800 !target->lastenemy->player :
1801 !((target->flags ^ target->lastenemy->flags) & MF_FRIEND) && target->target != source
1802 )
1803 ) // remember last enemy - killough
1804 P_SetTarget(&target->lastenemy, target->target);
1805
1806 P_SetTarget(&target->target, source); // killough 11/98
1807 target->threshold = BASETHRESHOLD;
1808 if (target->state == &states[target->info->spawnstate]
1809 && target->info->seestate != g_s_null)
1810 P_SetMobjState (target, target->info->seestate);
1811 }
1812
1813 /* killough 11/98: Don't attack a friend, unless hit by that friend.
1814 * cph 2006/04/01 - implicitly this is only if mbf_features */
1815 if(!demo_compatibility) //e6y
1816 if (justhit && (target->target == source || !target->target ||
1817 !(target->flags & target->target->flags & MF_FRIEND)))
1818 target->flags |= MF_JUSTHIT; // fight back!
1819 }
1820
1821 // heretic
1822
1823 #include "p_user.h"
1824
1825 #define CHICKENTICS (40*35)
1826
1827 void A_RestoreArtifact(mobj_t * arti)
1828 {
1829 arti->flags |= MF_SPECIAL;
1830 P_SetMobjState(arti, arti->info->spawnstate);
1831 S_StartMobjSound(arti, g_sfx_respawn);
1832 }
1833
1834 void A_RestoreSpecialThing1(mobj_t * thing)
1835 {
1836 if (thing->type == HERETIC_MT_WMACE)
1837 { // Do random mace placement
1838 P_RepositionMace(thing);
1839 }
1840 thing->flags2 &= ~MF2_DONTDRAW;
1841 S_StartMobjSound(thing, g_sfx_respawn);
1842 }
1843
1844 void A_RestoreSpecialThing2(mobj_t * thing)
1845 {
1846 thing->flags |= MF_SPECIAL;
1847 P_SetMobjState(thing, thing->info->spawnstate);
1848 }
1849
1850 // heretic
1851
1852 void P_SetMessage(player_t * player, const char *message, dboolean ultmsg)
1853 {
1854 dsda_AddPlayerMessage(message, player);
1855 player->yellowMessage = false;
1856 }
1857
1858 static void Heretic_P_TouchSpecialThing(mobj_t * special, mobj_t * toucher)
1859 {
1860 int i;
1861 player_t *player;
1862 fixed_t delta;
1863 int sound;
1864
1865 delta = special->z - toucher->z;
1866 if (delta > toucher->height || delta < -32 * FRACUNIT)
1867 { // Out of reach
1868 return;
1869 }
1870 if (toucher->health <= 0)
1871 { // Toucher is dead
1872 return;
1873 }
1874 sound = heretic_sfx_itemup;
1875 player = toucher->player;
1876
1877 switch (special->sprite)
1878 {
1879 // Items
1880 case HERETIC_SPR_PTN1: // Item_HealingPotion
1881 if (!P_GiveBody(player, 10))
1882 {
1883 return;
1884 }
1885 P_SetMessage(player, HERETIC_TXT_ITEMHEALTH, false);
1886 break;
1887 case HERETIC_SPR_SHLD: // Item_Shield1
1888 if (!P_GiveArmor(player, 1))
1889 {
1890 return;
1891 }
1892 P_SetMessage(player, HERETIC_TXT_ITEMSHIELD1, false);
1893 break;
1894 case HERETIC_SPR_SHD2: // Item_Shield2
1895 if (!P_GiveArmor(player, 2))
1896 {
1897 return;
1898 }
1899 P_SetMessage(player, HERETIC_TXT_ITEMSHIELD2, false);
1900 break;
1901 case HERETIC_SPR_BAGH: // Item_BagOfHolding
1902 if (!player->backpack)
1903 {
1904 for (i = 0; i < NUMAMMO; i++)
1905 {
1906 player->maxammo[i] *= 2;
1907 }
1908 player->backpack = true;
1909 }
1910 P_GiveAmmo(player, am_goldwand, AMMO_GWND_WIMPY);
1911 P_GiveAmmo(player, am_blaster, AMMO_BLSR_WIMPY);
1912 P_GiveAmmo(player, am_crossbow, AMMO_CBOW_WIMPY);
1913 P_GiveAmmo(player, am_skullrod, AMMO_SKRD_WIMPY);
1914 P_GiveAmmo(player, am_phoenixrod, AMMO_PHRD_WIMPY);
1915 P_SetMessage(player, HERETIC_TXT_ITEMBAGOFHOLDING, false);
1916 break;
1917 case HERETIC_SPR_SPMP: // Item_SuperMap
1918 if (!P_GivePower(player, pw_allmap))
1919 {
1920 return;
1921 }
1922 P_SetMessage(player, HERETIC_TXT_ITEMSUPERMAP, false);
1923 break;
1924
1925 // Keys
1926 case HERETIC_SPR_BKYY: // Key_Blue
1927 if (!player->cards[key_blue])
1928 {
1929 P_SetMessage(player, HERETIC_TXT_GOTBLUEKEY, false);
1930 }
1931 P_GiveCard(player, key_blue);
1932 sound = heretic_sfx_keyup;
1933 if (!netgame)
1934 {
1935 break;
1936 }
1937 return;
1938 case HERETIC_SPR_CKYY: // Key_Yellow
1939 if (!player->cards[key_yellow])
1940 {
1941 P_SetMessage(player, HERETIC_TXT_GOTYELLOWKEY, false);
1942 }
1943 sound = heretic_sfx_keyup;
1944 P_GiveCard(player, key_yellow);
1945 if (!netgame)
1946 {
1947 break;
1948 }
1949 return;
1950 case HERETIC_SPR_AKYY: // Key_Green
1951 if (!player->cards[key_green])
1952 {
1953 P_SetMessage(player, HERETIC_TXT_GOTGREENKEY, false);
1954 }
1955 sound = heretic_sfx_keyup;
1956 P_GiveCard(player, key_green);
1957 if (!netgame)
1958 {
1959 break;
1960 }
1961 return;
1962
1963 // Artifacts
1964 case HERETIC_SPR_PTN2: // Arti_HealingPotion
1965 if (P_GiveArtifact(player, arti_health, special))
1966 {
1967 P_SetMessage(player, HERETIC_TXT_ARTIHEALTH, false);
1968 P_SetDormantArtifact(special);
1969 }
1970 return;
1971 case HERETIC_SPR_SOAR: // Arti_Fly
1972 if (P_GiveArtifact(player, arti_fly, special))
1973 {
1974 P_SetMessage(player, HERETIC_TXT_ARTIFLY, false);
1975 P_SetDormantArtifact(special);
1976 }
1977 return;
1978 case HERETIC_SPR_INVU: // Arti_Invulnerability
1979 if (P_GiveArtifact(player, arti_invulnerability, special))
1980 {
1981 P_SetMessage(player, HERETIC_TXT_ARTIINVULNERABILITY, false);
1982 P_SetDormantArtifact(special);
1983 }
1984 return;
1985 case HERETIC_SPR_PWBK: // Arti_TomeOfPower
1986 if (P_GiveArtifact(player, arti_tomeofpower, special))
1987 {
1988 P_SetMessage(player, HERETIC_TXT_ARTITOMEOFPOWER, false);
1989 P_SetDormantArtifact(special);
1990 }
1991 return;
1992 case HERETIC_SPR_INVS: // Arti_Invisibility
1993 if (P_GiveArtifact(player, arti_invisibility, special))
1994 {
1995 P_SetMessage(player, HERETIC_TXT_ARTIINVISIBILITY, false);
1996 P_SetDormantArtifact(special);
1997 }
1998 return;
1999 case HERETIC_SPR_EGGC: // Arti_Egg
2000 if (P_GiveArtifact(player, arti_egg, special))
2001 {
2002 P_SetMessage(player, HERETIC_TXT_ARTIEGG, false);
2003 P_SetDormantArtifact(special);
2004 }
2005 return;
2006 case HERETIC_SPR_SPHL: // Arti_SuperHealth
2007 if (P_GiveArtifact(player, arti_superhealth, special))
2008 {
2009 P_SetMessage(player, HERETIC_TXT_ARTISUPERHEALTH, false);
2010 P_SetDormantArtifact(special);
2011 }
2012 return;
2013 case HERETIC_SPR_TRCH: // Arti_Torch
2014 if (P_GiveArtifact(player, arti_torch, special))
2015 {
2016 P_SetMessage(player, HERETIC_TXT_ARTITORCH, false);
2017 P_SetDormantArtifact(special);
2018 }
2019 return;
2020 case HERETIC_SPR_FBMB: // Arti_FireBomb
2021 if (P_GiveArtifact(player, arti_firebomb, special))
2022 {
2023 P_SetMessage(player, HERETIC_TXT_ARTIFIREBOMB, false);
2024 P_SetDormantArtifact(special);
2025 }
2026 return;
2027 case HERETIC_SPR_ATLP: // Arti_Teleport
2028 if (P_GiveArtifact(player, arti_teleport, special))
2029 {
2030 P_SetMessage(player, HERETIC_TXT_ARTITELEPORT, false);
2031 P_SetDormantArtifact(special);
2032 }
2033 return;
2034
2035 // Ammo
2036 case HERETIC_SPR_AMG1: // Ammo_GoldWandWimpy
2037 if (!P_GiveAmmo(player, am_goldwand, special->health))
2038 {
2039 return;
2040 }
2041 P_SetMessage(player, HERETIC_TXT_AMMOGOLDWAND1, false);
2042 break;
2043 case HERETIC_SPR_AMG2: // Ammo_GoldWandHefty
2044 if (!P_GiveAmmo(player, am_goldwand, special->health))
2045 {
2046 return;
2047 }
2048 P_SetMessage(player, HERETIC_TXT_AMMOGOLDWAND2, false);
2049 break;
2050 case HERETIC_SPR_AMM1: // Ammo_MaceWimpy
2051 if (!P_GiveAmmo(player, am_mace, special->health))
2052 {
2053 return;
2054 }
2055 P_SetMessage(player, HERETIC_TXT_AMMOMACE1, false);
2056 break;
2057 case HERETIC_SPR_AMM2: // Ammo_MaceHefty
2058 if (!P_GiveAmmo(player, am_mace, special->health))
2059 {
2060 return;
2061 }
2062 P_SetMessage(player, HERETIC_TXT_AMMOMACE2, false);
2063 break;
2064 case HERETIC_SPR_AMC1: // Ammo_CrossbowWimpy
2065 if (!P_GiveAmmo(player, am_crossbow, special->health))
2066 {
2067 return;
2068 }
2069 P_SetMessage(player, HERETIC_TXT_AMMOCROSSBOW1, false);
2070 break;
2071 case HERETIC_SPR_AMC2: // Ammo_CrossbowHefty
2072 if (!P_GiveAmmo(player, am_crossbow, special->health))
2073 {
2074 return;
2075 }
2076 P_SetMessage(player, HERETIC_TXT_AMMOCROSSBOW2, false);
2077 break;
2078 case HERETIC_SPR_AMB1: // Ammo_BlasterWimpy
2079 if (!P_GiveAmmo(player, am_blaster, special->health))
2080 {
2081 return;
2082 }
2083 P_SetMessage(player, HERETIC_TXT_AMMOBLASTER1, false);
2084 break;
2085 case HERETIC_SPR_AMB2: // Ammo_BlasterHefty
2086 if (!P_GiveAmmo(player, am_blaster, special->health))
2087 {
2088 return;
2089 }
2090 P_SetMessage(player, HERETIC_TXT_AMMOBLASTER2, false);
2091 break;
2092 case HERETIC_SPR_AMS1: // Ammo_SkullRodWimpy
2093 if (!P_GiveAmmo(player, am_skullrod, special->health))
2094 {
2095 return;
2096 }
2097 P_SetMessage(player, HERETIC_TXT_AMMOSKULLROD1, false);
2098 break;
2099 case HERETIC_SPR_AMS2: // Ammo_SkullRodHefty
2100 if (!P_GiveAmmo(player, am_skullrod, special->health))
2101 {
2102 return;
2103 }
2104 P_SetMessage(player, HERETIC_TXT_AMMOSKULLROD2, false);
2105 break;
2106 case HERETIC_SPR_AMP1: // Ammo_PhoenixRodWimpy
2107 if (!P_GiveAmmo(player, am_phoenixrod, special->health))
2108 {
2109 return;
2110 }
2111 P_SetMessage(player, HERETIC_TXT_AMMOPHOENIXROD1, false);
2112 break;
2113 case HERETIC_SPR_AMP2: // Ammo_PhoenixRodHefty
2114 if (!P_GiveAmmo(player, am_phoenixrod, special->health))
2115 {
2116 return;
2117 }
2118 P_SetMessage(player, HERETIC_TXT_AMMOPHOENIXROD2, false);
2119 break;
2120
2121 // Weapons
2122 case HERETIC_SPR_WMCE: // Weapon_Mace
2123 if (!P_GiveWeapon(player, wp_mace, false))
2124 {
2125 return;
2126 }
2127 P_SetMessage(player, HERETIC_TXT_WPNMACE, false);
2128 sound = heretic_sfx_wpnup;
2129 break;
2130 case HERETIC_SPR_WBOW: // Weapon_Crossbow
2131 if (!P_GiveWeapon(player, wp_crossbow, false))
2132 {
2133 return;
2134 }
2135 P_SetMessage(player, HERETIC_TXT_WPNCROSSBOW, false);
2136 sound = heretic_sfx_wpnup;
2137 break;
2138 case HERETIC_SPR_WBLS: // Weapon_Blaster
2139 if (!P_GiveWeapon(player, wp_blaster, false))
2140 {
2141 return;
2142 }
2143 P_SetMessage(player, HERETIC_TXT_WPNBLASTER, false);
2144 sound = heretic_sfx_wpnup;
2145 break;
2146 case HERETIC_SPR_WSKL: // Weapon_SkullRod
2147 if (!P_GiveWeapon(player, wp_skullrod, false))
2148 {
2149 return;
2150 }
2151 P_SetMessage(player, HERETIC_TXT_WPNSKULLROD, false);
2152 sound = heretic_sfx_wpnup;
2153 break;
2154 case HERETIC_SPR_WPHX: // Weapon_PhoenixRod
2155 if (!P_GiveWeapon(player, wp_phoenixrod, false))
2156 {
2157 return;
2158 }
2159 P_SetMessage(player, HERETIC_TXT_WPNPHOENIXROD, false);
2160 sound = heretic_sfx_wpnup;
2161 break;
2162 case HERETIC_SPR_WGNT: // Weapon_Gauntlets
2163 if (!P_GiveWeapon(player, wp_gauntlets, false))
2164 {
2165 return;
2166 }
2167 P_SetMessage(player, HERETIC_TXT_WPNGAUNTLETS, false);
2168 sound = heretic_sfx_wpnup;
2169 break;
2170 default:
2171 I_Error("Heretic_P_TouchSpecialThing: Unknown gettable thing");
2172 }
2173 if (special->flags & MF_COUNTITEM)
2174 {
2175 player->itemcount++;
2176 }
2177 if (deathmatch && !(special->flags & MF_DROPPED))
2178 {
2179 P_HideSpecialThing(special);
2180 }
2181 else
2182 {
2183 P_RemoveMobj(special);
2184 }
2185 player->bonuscount += BONUSADD;
2186 if (player == &players[consoleplayer])
2187 {
2188 S_StartVoidSound(sound);
2189 SB_PaletteFlash(false);
2190 }
2191 }
2192
2193 dboolean P_GiveArtifact(player_t * player, artitype_t arti, mobj_t * mo)
2194 {
2195 int i;
2196 dboolean slidePointer;
2197
2198 slidePointer = false;
2199 i = 0;
2200 while (player->inventory[i].type != arti && i < player->inventorySlotNum)
2201 {
2202 i++;
2203 }
2204 if (i == player->inventorySlotNum)
2205 {
2206 if (hexen && arti < hexen_arti_firstpuzzitem)
2207 {
2208 i = 0;
2209 while (player->inventory[i].type < hexen_arti_firstpuzzitem
2210 && i < player->inventorySlotNum)
2211 {
2212 i++;
2213 }
2214 if (i != player->inventorySlotNum)
2215 {
2216 int j;
2217 for (j = player->inventorySlotNum; j > i; j--)
2218 {
2219 player->inventory[j].count =
2220 player->inventory[j - 1].count;
2221 player->inventory[j].type = player->inventory[j - 1].type;
2222 slidePointer = true;
2223 }
2224 }
2225 }
2226 player->inventory[i].count = 1;
2227 player->inventory[i].type = arti;
2228 player->inventorySlotNum++;
2229 }
2230 else
2231 {
2232 if (hexen && arti >= hexen_arti_firstpuzzitem && netgame && !deathmatch)
2233 { // Can't carry more than 1 puzzle item in coop netplay
2234 return false;
2235 }
2236 if (player->inventory[i].count >= g_arti_limit)
2237 { // Player already has 16 of this item
2238 return (false);
2239 }
2240 player->inventory[i].count++;
2241 }
2242 if (player->artifactCount == 0)
2243 {
2244 player->readyArtifact = arti;
2245 }
2246 else if (player == &players[consoleplayer] && slidePointer && i <= inv_ptr)
2247 {
2248 inv_ptr++;
2249 curpos++;
2250 if (curpos > 6)
2251 {
2252 curpos = 6;
2253 }
2254 }
2255 player->artifactCount++;
2256 if (mo && (mo->flags & MF_COUNTITEM))
2257 {
2258 player->itemcount++;
2259 }
2260 return (true);
2261 }
2262
2263 void P_SetDormantArtifact(mobj_t * arti)
2264 {
2265 arti->flags &= ~MF_SPECIAL;
2266 if (deathmatch && (arti->type != HERETIC_MT_ARTIINVULNERABILITY)
2267 && (arti->type != HERETIC_MT_ARTIINVISIBILITY))
2268 {
2269 P_SetMobjState(arti, HERETIC_S_DORMANTARTI1);
2270 }
2271 else
2272 { // Don't respawn
2273 P_SetMobjState(arti, HERETIC_S_DEADARTI1);
2274 }
2275 S_StartMobjSound(arti, heretic_sfx_artiup);
2276 }
2277
2278 int GetWeaponAmmo[NUMWEAPONS] = {
2279 0, // staff
2280 25, // gold wand
2281 10, // crossbow
2282 30, // blaster
2283 50, // skull rod
2284 2, // phoenix rod
2285 50, // mace
2286 0, // gauntlets
2287 0 // beak
2288 };
2289
2290 int WeaponValue[] = {
2291 1, // staff
2292 3, // goldwand
2293 4, // crossbow
2294 5, // blaster
2295 6, // skullrod
2296 7, // phoenixrod
2297 8, // mace
2298 2, // gauntlets
2299 0 // beak
2300 };
2301
2302 dboolean Heretic_P_GiveWeapon(player_t * player, weapontype_t weapon)
2303 {
2304 dboolean gaveAmmo;
2305 dboolean gaveWeapon;
2306
2307 if (netgame && !deathmatch)
2308 { // Cooperative net-game
2309 if (player->weaponowned[weapon])
2310 {
2311 return (false);
2312 }
2313 player->bonuscount += BONUSADD;
2314 player->weaponowned[weapon] = true;
2315 P_GiveAmmo(player, wpnlev1info[weapon].ammo, GetWeaponAmmo[weapon]);
2316 P_AutoSwitchWeapon(player, weapon);
2317 if (player == &players[consoleplayer])
2318 {
2319 S_StartVoidSound(heretic_sfx_wpnup);
2320 }
2321 return (false);
2322 }
2323 gaveAmmo = P_GiveAmmo(player, wpnlev1info[weapon].ammo,
2324 GetWeaponAmmo[weapon]);
2325 if (player->weaponowned[weapon])
2326 {
2327 gaveWeapon = false;
2328 }
2329 else
2330 {
2331 gaveWeapon = true;
2332 player->weaponowned[weapon] = true;
2333 if (WeaponValue[weapon] > WeaponValue[player->readyweapon])
2334 { // Only switch to more powerful weapons
2335 P_AutoSwitchWeapon(player, weapon);
2336 }
2337 }
2338 return (gaveWeapon || gaveAmmo);
2339 }
2340
2341 void P_HideSpecialThing(mobj_t * thing)
2342 {
2343 thing->flags &= ~MF_SPECIAL;
2344 thing->flags2 |= MF2_DONTDRAW;
2345 P_SetMobjState(thing, g_hide_state);
2346 }
2347
2348 void P_MinotaurSlam(mobj_t * source, mobj_t * target)
2349 {
2350 angle_t angle;
2351 fixed_t thrust;
2352
2353 angle = R_PointToAngle2(source->x, source->y, target->x, target->y);
2354 angle >>= ANGLETOFINESHIFT;
2355 thrust = 16 * FRACUNIT + (P_Random(pr_heretic) << 10);
2356 target->momx += FixedMul(thrust, finecosine[angle]);
2357 target->momy += FixedMul(thrust, finesine[angle]);
2358 if (hexen)
2359 {
2360 P_DamageMobj(target, NULL, source, HITDICE(4));
2361 }
2362 else
2363 {
2364 P_DamageMobj(target, NULL, NULL, HITDICE(6));
2365 }
2366 if (target->player)
2367 {
2368 target->reactiontime = 14 + (P_Random(pr_heretic) & 7);
2369 }
2370 source->special_args[0] = 0; // Stop charging
2371 }
2372
2373 void P_TouchWhirlwind(mobj_t * target)
2374 {
2375 int randVal;
2376
2377 target->angle += P_SubRandom() << 20;
2378 target->momx += P_SubRandom() << 10;
2379 target->momy += P_SubRandom() << 10;
2380 if (leveltime & 16 && !(target->flags2 & MF2_BOSS))
2381 {
2382 randVal = P_Random(pr_heretic);
2383 if (randVal > 160)
2384 {
2385 randVal = 160;
2386 }
2387 target->momz += randVal << 10;
2388 if (target->momz > 12 * FRACUNIT)
2389 {
2390 target->momz = 12 * FRACUNIT;
2391 }
2392 }
2393 if (!(leveltime & 7))
2394 {
2395 P_DamageMobj(target, NULL, NULL, 3);
2396 }
2397
2398 if (target->player) R_SmoothPlaying_Reset(target->player); // e6y
2399 }
2400
2401 dboolean P_ChickenMorphPlayer(player_t * player)
2402 {
2403 mobj_t *pmo;
2404 mobj_t *fog;
2405 mobj_t *chicken;
2406 fixed_t x;
2407 fixed_t y;
2408 fixed_t z;
2409 angle_t angle;
2410 int oldFlags2;
2411
2412 if (player->chickenTics)
2413 {
2414 if ((player->chickenTics < CHICKENTICS - TICRATE)
2415 && !player->powers[pw_weaponlevel2])
2416 { // Make a super chicken
2417 P_GivePower(player, pw_weaponlevel2);
2418 }
2419 return (false);
2420 }
2421 if (player->powers[pw_invulnerability])
2422 { // Immune when invulnerable
2423 return (false);
2424 }
2425 pmo = player->mo;
2426 x = pmo->x;
2427 y = pmo->y;
2428 z = pmo->z;
2429 angle = pmo->angle;
2430 oldFlags2 = pmo->flags2;
2431 P_SetMobjState(pmo, HERETIC_S_FREETARGMOBJ);
2432 fog = P_SpawnMobj(x, y, z + TELEFOGHEIGHT, HERETIC_MT_TFOG);
2433 S_StartMobjSound(fog, heretic_sfx_telept);
2434 chicken = P_SpawnMobj(x, y, z, HERETIC_MT_CHICPLAYER);
2435 chicken->special1.i = player->readyweapon;
2436 chicken->angle = angle;
2437 chicken->player = player;
2438 player->health = chicken->health = MAXCHICKENHEALTH;
2439 player->mo = chicken;
2440 player->armorpoints[ARMOR_ARMOR] = player->armortype = 0;
2441 player->powers[pw_invisibility] = 0;
2442 player->powers[pw_weaponlevel2] = 0;
2443 if (oldFlags2 & MF2_FLY)
2444 {
2445 chicken->flags2 |= MF2_FLY;
2446 }
2447 player->chickenTics = CHICKENTICS;
2448 P_ActivateBeak(player);
2449 return (true);
2450 }
2451
2452 dboolean P_ChickenMorph(mobj_t * actor)
2453 {
2454 mobj_t *fog;
2455 mobj_t *chicken;
2456 mobj_t *target;
2457 mobjtype_t moType;
2458 fixed_t x;
2459 fixed_t y;
2460 fixed_t z;
2461 angle_t angle;
2462 int ghost;
2463
2464 if (actor->player)
2465 {
2466 return (false);
2467 }
2468 moType = actor->type;
2469 switch (moType)
2470 {
2471 case HERETIC_MT_POD:
2472 case HERETIC_MT_CHICKEN:
2473 case HERETIC_MT_HEAD:
2474 case HERETIC_MT_MINOTAUR:
2475 case HERETIC_MT_SORCERER1:
2476 case HERETIC_MT_SORCERER2:
2477 return (false);
2478 default:
2479 break;
2480 }
2481 x = actor->x;
2482 y = actor->y;
2483 z = actor->z;
2484 angle = actor->angle;
2485 ghost = actor->flags & MF_SHADOW;
2486 target = actor->target;
2487 P_SetMobjState(actor, HERETIC_S_FREETARGMOBJ);
2488 fog = P_SpawnMobj(x, y, z + TELEFOGHEIGHT, HERETIC_MT_TFOG);
2489 S_StartMobjSound(fog, heretic_sfx_telept);
2490 chicken = P_SpawnMobj(x, y, z, HERETIC_MT_CHICKEN);
2491 chicken->special2.i = moType;
2492 chicken->special1.i = CHICKENTICS + P_Random(pr_heretic);
2493 chicken->flags |= ghost;
2494 P_SetTarget(&chicken->target, target);
2495 chicken->angle = angle;
2496 dsda_WatchMorph(chicken);
2497 return (true);
2498 }
2499
2500 dboolean P_AutoUseChaosDevice(player_t * player)
2501 {
2502 int i;
2503
2504 for (i = 0; i < player->inventorySlotNum; i++)
2505 {
2506 if (player->inventory[i].type == arti_teleport)
2507 {
2508 P_PlayerUseArtifact(player, arti_teleport);
2509 player->health = player->mo->health = (player->health + 1) / 2;
2510 return (true);
2511 }
2512 }
2513 return (false);
2514 }
2515
2516 void P_AutoUseHealth(player_t * player, int saveHealth)
2517 {
2518 int i;
2519 int count;
2520 int normalCount = 0;
2521 int normalSlot = 0;
2522 int superCount = 0;
2523 int superSlot = 0;
2524
2525 for (i = 0; i < player->inventorySlotNum; i++)
2526 {
2527 if (player->inventory[i].type == g_arti_health)
2528 {
2529 normalSlot = i;
2530 normalCount = player->inventory[i].count;
2531 }
2532 else if (player->inventory[i].type == g_arti_superhealth)
2533 {
2534 superSlot = i;
2535 superCount = player->inventory[i].count;
2536 }
2537 }
2538 if (skill_info.flags & SI_AUTO_USE_HEALTH && (normalCount * 25 >= saveHealth))
2539 { // Use quartz flasks
2540 count = (saveHealth + 24) / 25;
2541 for (i = 0; i < count; i++)
2542 {
2543 player->health += P_PlayerHealthIncrease(25);
2544 P_PlayerRemoveArtifact(player, normalSlot);
2545 }
2546 }
2547 else if (superCount * 100 >= saveHealth)
2548 { // Use mystic urns
2549 count = (saveHealth + 99) / 100;
2550 for (i = 0; i < count; i++)
2551 {
2552 player->health += P_PlayerHealthIncrease(100);
2553 P_PlayerRemoveArtifact(player, superSlot);
2554 }
2555 }
2556 else if (skill_info.flags & SI_AUTO_USE_HEALTH
2557 && (superCount * 100 + normalCount * 25 >= saveHealth))
2558 { // Use mystic urns and quartz flasks
2559 count = (saveHealth + 24) / 25;
2560 saveHealth -= count * 25;
2561 for (i = 0; i < count; i++)
2562 {
2563 player->health += P_PlayerHealthIncrease(25);
2564 P_PlayerRemoveArtifact(player, normalSlot);
2565 }
2566 count = (saveHealth + 99) / 100;
2567 for (i = 0; i < count; i++)
2568 {
2569 player->health += P_PlayerHealthIncrease(100);
2570 P_PlayerRemoveArtifact(player, normalSlot);
2571 }
2572 }
2573 player->mo->health = player->health;
2574 }
2575
2576 // hexen
2577
2578 #define TXT_MANA_1 "BLUE MANA"
2579 #define TXT_MANA_2 "GREEN MANA"
2580 #define TXT_MANA_BOTH "COMBINED MANA"
2581
2582 #define TXT_KEY_STEEL "STEEL KEY"
2583 #define TXT_KEY_CAVE "CAVE KEY"
2584 #define TXT_KEY_AXE "AXE KEY"
2585 #define TXT_KEY_FIRE "FIRE KEY"
2586 #define TXT_KEY_EMERALD "EMERALD KEY"
2587 #define TXT_KEY_DUNGEON "DUNGEON KEY"
2588 #define TXT_KEY_SILVER "SILVER KEY"
2589 #define TXT_KEY_RUSTED "RUSTED KEY"
2590 #define TXT_KEY_HORN "HORN KEY"
2591 #define TXT_KEY_SWAMP "SWAMP KEY"
2592 #define TXT_KEY_CASTLE "CASTLE KEY"
2593
2594 #define TXT_ARTIINVULNERABILITY "ICON OF THE DEFENDER"
2595 #define TXT_ARTIHEALTH "QUARTZ FLASK"
2596 #define TXT_ARTISUPERHEALTH "MYSTIC URN"
2597 #define TXT_ARTIHEALINGRADIUS "MYSTIC AMBIT INCANT"
2598 #define TXT_ARTISUMMON "DARK SERVANT"
2599 #define TXT_ARTITORCH "TORCH"
2600 #define TXT_ARTIEGG "PORKALATOR"
2601 #define TXT_ARTIFLY "WINGS OF WRATH"
2602 #define TXT_ARTIBLASTRADIUS "DISC OF REPULSION"
2603 #define TXT_ARTIPOISONBAG "FLECHETTE"
2604 #define TXT_ARTITELEPORTOTHER "BANISHMENT DEVICE"
2605 #define TXT_ARTISPEED "BOOTS OF SPEED"
2606 #define TXT_ARTIBOOSTMANA "KRATER OF MIGHT"
2607 #define TXT_ARTIBOOSTARMOR "DRAGONSKIN BRACERS"
2608 #define TXT_ARTITELEPORT "CHAOS DEVICE"
2609
2610 #define TXT_ITEMHEALTH "CRYSTAL VIAL"
2611 #define TXT_ITEMBAGOFHOLDING "BAG OF HOLDING"
2612 #define TXT_ITEMSHIELD1 "SILVER SHIELD"
2613 #define TXT_ITEMSHIELD2 "ENCHANTED SHIELD"
2614 #define TXT_ITEMSUPERMAP "MAP SCROLL"
2615
2616 #define TXT_ARMOR1 "MESH ARMOR"
2617 #define TXT_ARMOR2 "FALCON SHIELD"
2618 #define TXT_ARMOR3 "PLATINUM HELMET"
2619 #define TXT_ARMOR4 "AMULET OF WARDING"
2620
2621 #define TXT_WEAPON_F2 "TIMON'S AXE"
2622 #define TXT_WEAPON_F3 "HAMMER OF RETRIBUTION"
2623 #define TXT_WEAPON_F4 "QUIETUS ASSEMBLED"
2624 #define TXT_WEAPON_C2 "SERPENT STAFF"
2625 #define TXT_WEAPON_C3 "FIRESTORM"
2626 #define TXT_WEAPON_C4 "WRAITHVERGE ASSEMBLED"
2627 #define TXT_WEAPON_M2 "FROST SHARDS"
2628 #define TXT_WEAPON_M3 "ARC OF DEATH"
2629 #define TXT_WEAPON_M4 "BLOODSCOURGE ASSEMBLED"
2630
2631 #define TXT_QUIETUS_PIECE "SEGMENT OF QUIETUS"
2632 #define TXT_WRAITHVERGE_PIECE "SEGMENT OF WRAITHVERGE"
2633 #define TXT_BLOODSCOURGE_PIECE "SEGMENT OF BLOODSCOURGE"
2634
2635 const char *TextKeyMessages[] = {
2636 TXT_KEY_STEEL,
2637 TXT_KEY_CAVE,
2638 TXT_KEY_AXE,
2639 TXT_KEY_FIRE,
2640 TXT_KEY_EMERALD,
2641 TXT_KEY_DUNGEON,
2642 TXT_KEY_SILVER,
2643 TXT_KEY_RUSTED,
2644 TXT_KEY_HORN,
2645 TXT_KEY_SWAMP,
2646 TXT_KEY_CASTLE
2647 };
2648
2649 void P_FallingDamage(player_t * player)
2650 {
2651 int damage;
2652 int mom;
2653 int dist;
2654
2655 mom = abs(player->mo->momz);
2656 dist = FixedMul(mom, 16 * FRACUNIT / 23);
2657
2658 if (mom >= 63 * FRACUNIT)
2659 { // automatic death
2660 P_DamageMobj(player->mo, NULL, NULL, 10000);
2661 return;
2662 }
2663 damage = ((FixedMul(dist, dist) / 10) >> FRACBITS) - 24;
2664 if (player->mo->momz > -39 * FRACUNIT && damage > player->mo->health
2665 && player->mo->health != 1)
2666 { // No-death threshold
2667 damage = player->mo->health - 1;
2668 }
2669 S_StartMobjSound(player->mo, hexen_sfx_player_land);
2670 P_DamageMobj(player->mo, NULL, NULL, damage);
2671 }
2672
2673 void P_PoisonDamage(player_t * player, mobj_t * source, int damage,
2674 dboolean playPainSound)
2675 {
2676 mobj_t *target;
2677 mobj_t *inflictor;
2678
2679 target = player->mo;
2680 inflictor = source;
2681 if (target->health <= 0)
2682 {
2683 return;
2684 }
2685 if (target->flags2 & MF2_INVULNERABLE && damage < 10000)
2686 { // mobj is invulnerable
2687 return;
2688 }
2689 if (skill_info.damage_factor)
2690 {
2691 damage = FixedMul(damage, skill_info.damage_factor);
2692 }
2693 if (damage < 1000 && ((player->cheats & CF_GODMODE)
2694 || player->powers[pw_invulnerability]))
2695 {
2696 return;
2697 }
2698 if (damage >= player->health
2699 && (skill_info.flags & SI_AUTO_USE_HEALTH || deathmatch) && !player->morphTics)
2700 { // Try to use some inventory health
2701 P_AutoUseHealth(player, damage - player->health + 1);
2702 }
2703 player->health -= damage; // mirror mobj health here for Dave
2704 if (player->health < 0)
2705 {
2706 player->health = 0;
2707 }
2708 player->attacker = source;
2709
2710 //
2711 // do the damage
2712 //
2713 target->health -= damage;
2714 if (target->health <= 0)
2715 { // Death
2716 target->special1.i = damage;
2717 if (inflictor && !player->morphTics)
2718 { // Check for flame death
2719 if ((inflictor->flags2 & MF2_FIREDAMAGE)
2720 && (target->health > -50) && (damage > 25))
2721 {
2722 target->flags2 |= MF2_FIREDAMAGE;
2723 }
2724 if (inflictor->flags2 & MF2_ICEDAMAGE)
2725 {
2726 target->flags2 |= MF2_ICEDAMAGE;
2727 }
2728 }
2729 P_KillMobj(source, target);
2730 return;
2731 }
2732 if (!(leveltime & 63) && playPainSound)
2733 {
2734 P_SetMobjState(target, target->info->painstate);
2735 }
2736 }
2737
2738 dboolean P_GiveMana(player_t * player, manatype_t mana, int count)
2739 {
2740 int prevMana;
2741
2742 if (mana == MANA_NONE || mana == MANA_BOTH)
2743 {
2744 return (false);
2745 }
2746 if ((unsigned int) mana > NUMMANA)
2747 {
2748 I_Error("P_GiveMana: bad type %i", mana);
2749 }
2750 if (player->ammo[mana] == MAX_MANA)
2751 {
2752 return (false);
2753 }
2754 if (skill_info.ammo_factor)
2755 {
2756 count = FixedMul(count, skill_info.ammo_factor);
2757 }
2758 prevMana = player->ammo[mana];
2759
2760 player->ammo[mana] += count;
2761 if (player->ammo[mana] > MAX_MANA)
2762 {
2763 player->ammo[mana] = MAX_MANA;
2764 }
2765 if (player->pclass == PCLASS_FIGHTER && player->readyweapon == wp_second
2766 && mana == MANA_1 && prevMana <= 0)
2767 {
2768 P_SetPsprite(player, ps_weapon, HEXEN_S_FAXEREADY_G);
2769 }
2770 return (true);
2771 }
2772
2773 dboolean Hexen_P_GiveArmor(player_t * player, armortype_t armortype, int amount)
2774 {
2775 int hits;
2776 int totalArmor;
2777
2778 if (amount == -1)
2779 {
2780 hits = pclass[player->pclass].armor_increment[armortype];
2781 if (player->armorpoints[armortype] >= hits)
2782 {
2783 return false;
2784 }
2785 else
2786 {
2787 player->armorpoints[armortype] = hits;
2788 }
2789 }
2790 else
2791 {
2792 hits = amount * 5 * FRACUNIT;
2793 totalArmor = player->armorpoints[ARMOR_ARMOR]
2794 + player->armorpoints[ARMOR_SHIELD]
2795 + player->armorpoints[ARMOR_HELMET]
2796 + player->armorpoints[ARMOR_AMULET]
2797 + pclass[player->pclass].auto_armor_save;
2798 if (totalArmor < pclass[player->pclass].armor_max)
2799 {
2800 player->armorpoints[armortype] += hits;
2801 }
2802 else
2803 {
2804 return false;
2805 }
2806 }
2807 return true;
2808 }
2809
2810 void P_SetYellowMessage(player_t * player, const char *message, dboolean ultmsg)
2811 {
2812 dsda_AddPlayerMessage(message, player);
2813 player->yellowMessage = true;
2814 }
2815
2816 void TryPickupWeapon(player_t * player, pclass_t weaponClass,
2817 weapontype_t weaponType, mobj_t * weapon,
2818 const char *message)
2819 {
2820 dboolean remove;
2821 dboolean gaveMana;
2822 dboolean gaveWeapon;
2823
2824 remove = true;
2825 if (player->pclass != weaponClass)
2826 { // Wrong class, but try to pick up for mana
2827 if (netgame && !deathmatch)
2828 { // Can't pick up weapons for other classes in coop netplay
2829 return;
2830 }
2831 if (weaponType == wp_second)
2832 {
2833 if (!P_GiveMana(player, MANA_1, 25))
2834 {
2835 return;
2836 }
2837 }
2838 else
2839 {
2840 if (!P_GiveMana(player, MANA_2, 25))
2841 {
2842 return;
2843 }
2844 }
2845 }
2846 else if (netgame && !deathmatch)
2847 { // Cooperative net-game
2848 if (player->weaponowned[weaponType])
2849 {
2850 return;
2851 }
2852 player->weaponowned[weaponType] = true;
2853 if (weaponType == wp_second)
2854 {
2855 P_GiveMana(player, MANA_1, 25);
2856 }
2857 else
2858 {
2859 P_GiveMana(player, MANA_2, 25);
2860 }
2861 P_AutoSwitchWeapon(player, weaponType);
2862 remove = false;
2863 }
2864 else
2865 { // Deathmatch or single player game
2866 if (weaponType == wp_second)
2867 {
2868 gaveMana = P_GiveMana(player, MANA_1, 25);
2869 }
2870 else
2871 {
2872 gaveMana = P_GiveMana(player, MANA_2, 25);
2873 }
2874 if (player->weaponowned[weaponType])
2875 {
2876 gaveWeapon = false;
2877 }
2878 else
2879 {
2880 gaveWeapon = true;
2881 player->weaponowned[weaponType] = true;
2882 if (weaponType > player->readyweapon)
2883 { // Only switch to more powerful weapons
2884 P_AutoSwitchWeapon(player, weaponType);
2885 }
2886 }
2887 if (!(gaveWeapon || gaveMana))
2888 { // Player didn't need the weapon or any mana
2889 return;
2890 }
2891 }
2892
2893 P_SetMessage(player, message, false);
2894 if (weapon->special)
2895 {
2896 map_format.execute_line_special(weapon->special, weapon->special_args, NULL, 0, player->mo);
2897 weapon->special = 0;
2898 }
2899
2900 if (remove && !(weapon->intflags & MIF_FAKE))
2901 {
2902 if (deathmatch && !(weapon->flags & MF_DROPPED))
2903 {
2904 P_HideSpecialThing(weapon);
2905 }
2906 else
2907 {
2908 P_RemoveMobj(weapon);
2909 }
2910 }
2911
2912 player->bonuscount += BONUSADD;
2913 if (player == &players[consoleplayer])
2914 {
2915 S_StartVoidSound(hexen_sfx_pickup_weapon);
2916 SB_PaletteFlash(false);
2917 }
2918 }
2919
2920 static void TryPickupWeaponPiece(player_t * player, pclass_t matchClass,
2921 int pieceValue, mobj_t * pieceMobj)
2922 {
2923 dboolean remove;
2924 dboolean checkAssembled;
2925 dboolean gaveWeapon;
2926 int gaveMana;
2927 static const char *fourthWeaponText[] = {
2928 0,
2929 TXT_WEAPON_F4,
2930 TXT_WEAPON_C4,
2931 TXT_WEAPON_M4
2932 };
2933 static const char *weaponPieceText[] = {
2934 0,
2935 TXT_QUIETUS_PIECE,
2936 TXT_WRAITHVERGE_PIECE,
2937 TXT_BLOODSCOURGE_PIECE
2938 };
2939 static int pieceValueTrans[] = {
2940 0, // 0: never
2941 WPIECE1 | WPIECE2 | WPIECE3, // WPIECE1 (1)
2942 WPIECE2 | WPIECE3, // WPIECE2 (2)
2943 0, // 3: never
2944 WPIECE3 // WPIECE3 (4)
2945 };
2946
2947 remove = true;
2948 checkAssembled = true;
2949 gaveWeapon = false;
2950 if (player->pclass != matchClass)
2951 { // Wrong class, but try to pick up for mana
2952 if (netgame && !deathmatch)
2953 { // Can't pick up wrong-class weapons in coop netplay
2954 return;
2955 }
2956 checkAssembled = false;
2957 gaveMana = P_GiveMana(player, MANA_1, 20) +
2958 P_GiveMana(player, MANA_2, 20);
2959 if (!gaveMana)
2960 { // Didn't need the mana, so don't pick it up
2961 return;
2962 }
2963 }
2964 else if (netgame && !deathmatch)
2965 { // Cooperative net-game
2966 if (player->pieces & pieceValue)
2967 { // Already has the piece
2968 return;
2969 }
2970 pieceValue = pieceValueTrans[pieceValue];
2971 P_GiveMana(player, MANA_1, 20);
2972 P_GiveMana(player, MANA_2, 20);
2973 remove = false;
2974 }
2975 else
2976 { // Deathmatch or single player game
2977 gaveMana = P_GiveMana(player, MANA_1, 20) +
2978 P_GiveMana(player, MANA_2, 20);
2979 if (player->pieces & pieceValue)
2980 { // Already has the piece, check if mana needed
2981 if (!gaveMana)
2982 { // Didn't need the mana, so don't pick it up
2983 return;
2984 }
2985 checkAssembled = false;
2986 }
2987 }
2988
2989 // Pick up the weapon piece
2990 if (pieceMobj->special)
2991 {
2992 map_format.execute_line_special(pieceMobj->special, pieceMobj->special_args, NULL, 0, player->mo);
2993 pieceMobj->special = 0;
2994 }
2995 if (remove)
2996 {
2997 if (deathmatch && !(pieceMobj->flags & MF_DROPPED))
2998 {
2999 P_HideSpecialThing(pieceMobj);
3000 }
3001 else
3002 {
3003 P_RemoveMobj(pieceMobj);
3004 }
3005 }
3006 player->bonuscount += BONUSADD;
3007 if (player == &players[consoleplayer])
3008 {
3009 SB_PaletteFlash(false);
3010 }
3011
3012 // Check if fourth weapon assembled
3013 if (checkAssembled)
3014 {
3015 player->pieces |= pieceValue;
3016 if (player->pieces == (WPIECE1 | WPIECE2 | WPIECE3))
3017 {
3018 gaveWeapon = true;
3019 player->weaponowned[wp_fourth] = true;
3020 P_AutoSwitchWeapon(player, wp_fourth);
3021 }
3022 }
3023
3024 if (gaveWeapon)
3025 {
3026 P_SetMessage(player, fourthWeaponText[matchClass], false);
3027 // Play the build-sound full volume for all players
3028 S_StartVoidSound(hexen_sfx_weapon_build);
3029 }
3030 else
3031 {
3032 P_SetMessage(player, weaponPieceText[matchClass], false);
3033 if (player == &players[consoleplayer])
3034 {
3035 S_StartVoidSound(hexen_sfx_pickup_weapon);
3036 }
3037 }
3038 }
3039
3040 int P_GiveKey(player_t * player, card_t key)
3041 {
3042 if (player->cards[key])
3043 {
3044 return false;
3045 }
3046 player->bonuscount += BONUSADD;
3047 player->cards[key] = true;
3048
3049 if (player == &players[consoleplayer])
3050 player->ravenkeys |= 1 << key;
3051
3052 return true;
3053 }
3054
3055 static void SetDormantArtifact(mobj_t * arti)
3056 {
3057 arti->flags &= ~MF_SPECIAL;
3058 if (deathmatch && !(arti->flags & MF_DROPPED))
3059 {
3060 if (arti->type == HEXEN_MT_ARTIINVULNERABILITY)
3061 {
3062 P_SetMobjState(arti, HEXEN_S_DORMANTARTI3_1);
3063 }
3064 else if (arti->type == HEXEN_MT_SUMMONMAULATOR || arti->type == HEXEN_MT_ARTIFLY)
3065 {
3066 P_SetMobjState(arti, HEXEN_S_DORMANTARTI2_1);
3067 }
3068 else
3069 {
3070 P_SetMobjState(arti, HEXEN_S_DORMANTARTI1_1);
3071 }
3072 }
3073 else
3074 { // Don't respawn
3075 P_SetMobjState(arti, HEXEN_S_DEADARTI1);
3076 }
3077 }
3078
3079 static void TryPickupArtifact(player_t * player, artitype_t artifactType, mobj_t * artifact)
3080 {
3081 static const char *artifactMessages[HEXEN_NUMARTIFACTS] = {
3082 NULL,
3083 TXT_ARTIINVULNERABILITY,
3084 TXT_ARTIHEALTH,
3085 TXT_ARTISUPERHEALTH,
3086 TXT_ARTIHEALINGRADIUS,
3087 TXT_ARTISUMMON,
3088 TXT_ARTITORCH,
3089 TXT_ARTIEGG,
3090 TXT_ARTIFLY,
3091 TXT_ARTIBLASTRADIUS,
3092 TXT_ARTIPOISONBAG,
3093 TXT_ARTITELEPORTOTHER,
3094 TXT_ARTISPEED,
3095 TXT_ARTIBOOSTMANA,
3096 TXT_ARTIBOOSTARMOR,
3097 TXT_ARTITELEPORT,
3098 TXT_ARTIPUZZSKULL,
3099 TXT_ARTIPUZZGEMBIG,
3100 TXT_ARTIPUZZGEMRED,
3101 TXT_ARTIPUZZGEMGREEN1,
3102 TXT_ARTIPUZZGEMGREEN2,
3103 TXT_ARTIPUZZGEMBLUE1,
3104 TXT_ARTIPUZZGEMBLUE2,
3105 TXT_ARTIPUZZBOOK1,
3106 TXT_ARTIPUZZBOOK2,
3107 TXT_ARTIPUZZSKULL2,
3108 TXT_ARTIPUZZFWEAPON,
3109 TXT_ARTIPUZZCWEAPON,
3110 TXT_ARTIPUZZMWEAPON,
3111 TXT_ARTIPUZZGEAR, // All gear pickups use the same text
3112 TXT_ARTIPUZZGEAR,
3113 TXT_ARTIPUZZGEAR,
3114 TXT_ARTIPUZZGEAR
3115 };
3116
3117 if (gamemode == shareware)
3118 {
3119 artifactMessages[hexen_arti_blastradius] = TXT_ARTITELEPORT;
3120 artifactMessages[hexen_arti_teleport] = TXT_ARTIBLASTRADIUS;
3121 }
3122
3123 if (P_GiveArtifact(player, artifactType, artifact))
3124 {
3125 if (artifact->special)
3126 {
3127 map_format.execute_line_special(artifact->special, artifact->special_args, NULL, 0, NULL);
3128 artifact->special = 0;
3129 }
3130 player->bonuscount += BONUSADD;
3131 if (artifactType < hexen_arti_firstpuzzitem)
3132 {
3133 SetDormantArtifact(artifact);
3134 S_StartMobjSound(artifact, hexen_sfx_pickup_artifact);
3135 P_SetMessage(player, artifactMessages[artifactType], false);
3136 }
3137 else
3138 { // Puzzle item
3139 S_StartVoidSound(hexen_sfx_pickup_item);
3140 P_SetMessage(player, artifactMessages[artifactType], true);
3141 if (!netgame || deathmatch)
3142 { // Remove puzzle items if not cooperative netplay
3143 P_RemoveMobj(artifact);
3144 }
3145 }
3146 }
3147 }
3148
3149 static void Hexen_P_TouchSpecialThing(mobj_t * special, mobj_t * toucher)
3150 {
3151 player_t *player;
3152 fixed_t delta;
3153 int sound;
3154 dboolean respawn;
3155
3156 delta = special->z - toucher->z;
3157 if (delta > toucher->height || delta < -32 * FRACUNIT)
3158 { // Out of reach
3159 return;
3160 }
3161 if (toucher->health <= 0)
3162 { // Toucher is dead
3163 return;
3164 }
3165 sound = hexen_sfx_pickup_item;
3166 player = toucher->player;
3167 respawn = true;
3168 switch (special->sprite)
3169 {
3170 // Items
3171 case HEXEN_SPR_PTN1: // Item_HealingPotion
3172 if (!P_GiveBody(player, 10))
3173 {
3174 return;
3175 }
3176 P_SetMessage(player, TXT_ITEMHEALTH, false);
3177 break;
3178 case HEXEN_SPR_ARM1:
3179 if (!Hexen_P_GiveArmor(player, ARMOR_ARMOR, -1))
3180 {
3181 return;
3182 }
3183 P_SetMessage(player, TXT_ARMOR1, false);
3184 break;
3185 case HEXEN_SPR_ARM2:
3186 if (!Hexen_P_GiveArmor(player, ARMOR_SHIELD, -1))
3187 {
3188 return;
3189 }
3190 P_SetMessage(player, TXT_ARMOR2, false);
3191 break;
3192 case HEXEN_SPR_ARM3:
3193 if (!Hexen_P_GiveArmor(player, ARMOR_HELMET, -1))
3194 {
3195 return;
3196 }
3197 P_SetMessage(player, TXT_ARMOR3, false);
3198 break;
3199 case HEXEN_SPR_ARM4:
3200 if (!Hexen_P_GiveArmor(player, ARMOR_AMULET, -1))
3201 {
3202 return;
3203 }
3204 P_SetMessage(player, TXT_ARMOR4, false);
3205 break;
3206
3207 // Keys
3208 case HEXEN_SPR_KEY1:
3209 case HEXEN_SPR_KEY2:
3210 case HEXEN_SPR_KEY3:
3211 case HEXEN_SPR_KEY4:
3212 case HEXEN_SPR_KEY5:
3213 case HEXEN_SPR_KEY6:
3214 case HEXEN_SPR_KEY7:
3215 case HEXEN_SPR_KEY8:
3216 case HEXEN_SPR_KEY9:
3217 case HEXEN_SPR_KEYA:
3218 case HEXEN_SPR_KEYB:
3219 if (!P_GiveKey(player, special->sprite - HEXEN_SPR_KEY1))
3220 {
3221 return;
3222 }
3223 P_SetMessage(player, TextKeyMessages[special->sprite - HEXEN_SPR_KEY1],
3224 true);
3225 sound = hexen_sfx_pickup_key;
3226
3227 // Check and process the special now in case the key doesn't
3228 // get removed for coop netplay
3229 if (special->special)
3230 {
3231 map_format.execute_line_special(special->special, special->special_args, NULL, 0, toucher);
3232 special->special = 0;
3233 }
3234
3235 if (!netgame)
3236 { // Only remove keys in single player game
3237 break;
3238 }
3239 player->bonuscount += BONUSADD;
3240 if (player == &players[consoleplayer])
3241 {
3242 S_StartVoidSound(sound);
3243 SB_PaletteFlash(false);
3244 }
3245 return;
3246
3247 // Artifacts
3248 case HEXEN_SPR_PTN2:
3249 TryPickupArtifact(player, hexen_arti_health, special);
3250 return;
3251 case HEXEN_SPR_SOAR:
3252 TryPickupArtifact(player, hexen_arti_fly, special);
3253 return;
3254 case HEXEN_SPR_INVU:
3255 TryPickupArtifact(player, hexen_arti_invulnerability, special);
3256 return;
3257 case HEXEN_SPR_SUMN:
3258 TryPickupArtifact(player, hexen_arti_summon, special);
3259 return;
3260 case HEXEN_SPR_PORK:
3261 TryPickupArtifact(player, hexen_arti_egg, special);
3262 return;
3263 case HEXEN_SPR_SPHL:
3264 TryPickupArtifact(player, hexen_arti_superhealth, special);
3265 return;
3266 case HEXEN_SPR_HRAD:
3267 TryPickupArtifact(player, hexen_arti_healingradius, special);
3268 return;
3269 case HEXEN_SPR_TRCH:
3270 TryPickupArtifact(player, hexen_arti_torch, special);
3271 return;
3272 case HEXEN_SPR_ATLP:
3273 TryPickupArtifact(player, hexen_arti_teleport, special);
3274 return;
3275 case HEXEN_SPR_TELO:
3276 TryPickupArtifact(player, hexen_arti_teleportother, special);
3277 return;
3278 case HEXEN_SPR_PSBG:
3279 TryPickupArtifact(player, hexen_arti_poisonbag, special);
3280 return;
3281 case HEXEN_SPR_SPED:
3282 TryPickupArtifact(player, hexen_arti_speed, special);
3283 return;
3284 case HEXEN_SPR_BMAN:
3285 TryPickupArtifact(player, hexen_arti_boostmana, special);
3286 return;
3287 case HEXEN_SPR_BRAC:
3288 TryPickupArtifact(player, hexen_arti_boostarmor, special);
3289 return;
3290 case HEXEN_SPR_BLST:
3291 TryPickupArtifact(player, hexen_arti_blastradius, special);
3292 return;
3293
3294 // Puzzle artifacts
3295 case HEXEN_SPR_ASKU:
3296 TryPickupArtifact(player, hexen_arti_puzzskull, special);
3297 return;
3298 case HEXEN_SPR_ABGM:
3299 TryPickupArtifact(player, hexen_arti_puzzgembig, special);
3300 return;
3301 case HEXEN_SPR_AGMR:
3302 TryPickupArtifact(player, hexen_arti_puzzgemred, special);
3303 return;
3304 case HEXEN_SPR_AGMG:
3305 TryPickupArtifact(player, hexen_arti_puzzgemgreen1, special);
3306 return;
3307 case HEXEN_SPR_AGG2:
3308 TryPickupArtifact(player, hexen_arti_puzzgemgreen2, special);
3309 return;
3310 case HEXEN_SPR_AGMB:
3311 TryPickupArtifact(player, hexen_arti_puzzgemblue1, special);
3312 return;
3313 case HEXEN_SPR_AGB2:
3314 TryPickupArtifact(player, hexen_arti_puzzgemblue2, special);
3315 return;
3316 case HEXEN_SPR_ABK1:
3317 TryPickupArtifact(player, hexen_arti_puzzbook1, special);
3318 return;
3319 case HEXEN_SPR_ABK2:
3320 TryPickupArtifact(player, hexen_arti_puzzbook2, special);
3321 return;
3322 case HEXEN_SPR_ASK2:
3323 TryPickupArtifact(player, hexen_arti_puzzskull2, special);
3324 return;
3325 case HEXEN_SPR_AFWP:
3326 TryPickupArtifact(player, hexen_arti_puzzfweapon, special);
3327 return;
3328 case HEXEN_SPR_ACWP:
3329 TryPickupArtifact(player, hexen_arti_puzzcweapon, special);
3330 return;
3331 case HEXEN_SPR_AMWP:
3332 TryPickupArtifact(player, hexen_arti_puzzmweapon, special);
3333 return;
3334 case HEXEN_SPR_AGER:
3335 TryPickupArtifact(player, hexen_arti_puzzgear1, special);
3336 return;
3337 case HEXEN_SPR_AGR2:
3338 TryPickupArtifact(player, hexen_arti_puzzgear2, special);
3339 return;
3340 case HEXEN_SPR_AGR3:
3341 TryPickupArtifact(player, hexen_arti_puzzgear3, special);
3342 return;
3343 case HEXEN_SPR_AGR4:
3344 TryPickupArtifact(player, hexen_arti_puzzgear4, special);
3345 return;
3346
3347 // Mana
3348 case HEXEN_SPR_MAN1:
3349 if (!P_GiveMana(player, MANA_1, 15))
3350 {
3351 return;
3352 }
3353 P_SetMessage(player, TXT_MANA_1, false);
3354 break;
3355 case HEXEN_SPR_MAN2:
3356 if (!P_GiveMana(player, MANA_2, 15))
3357 {
3358 return;
3359 }
3360 P_SetMessage(player, TXT_MANA_2, false);
3361 break;
3362 case HEXEN_SPR_MAN3: // Double Mana Dodecahedron
3363 if (!P_GiveMana(player, MANA_1, 20))
3364 {
3365 if (!P_GiveMana(player, MANA_2, 20))
3366 {
3367 return;
3368 }
3369 }
3370 else
3371 {
3372 P_GiveMana(player, MANA_2, 20);
3373 }
3374 P_SetMessage(player, TXT_MANA_BOTH, false);
3375 break;
3376
3377 // 2nd and 3rd Mage Weapons
3378 case HEXEN_SPR_WMCS: // Frost Shards
3379 TryPickupWeapon(player, PCLASS_MAGE, wp_second,
3380 special, TXT_WEAPON_M2);
3381 return;
3382 case HEXEN_SPR_WMLG: // Arc of Death
3383 TryPickupWeapon(player, PCLASS_MAGE, wp_third,
3384 special, TXT_WEAPON_M3);
3385 return;
3386
3387 // 2nd and 3rd Fighter Weapons
3388 case HEXEN_SPR_WFAX: // Timon's Axe
3389 TryPickupWeapon(player, PCLASS_FIGHTER, wp_second,
3390 special, TXT_WEAPON_F2);
3391 return;
3392 case HEXEN_SPR_WFHM: // Hammer of Retribution
3393 TryPickupWeapon(player, PCLASS_FIGHTER, wp_third,
3394 special, TXT_WEAPON_F3);
3395 return;
3396
3397 // 2nd and 3rd Cleric Weapons
3398 case HEXEN_SPR_WCSS: // Serpent Staff
3399 TryPickupWeapon(player, PCLASS_CLERIC, wp_second,
3400 special, TXT_WEAPON_C2);
3401 return;
3402 case HEXEN_SPR_WCFM: // Firestorm
3403 TryPickupWeapon(player, PCLASS_CLERIC, wp_third,
3404 special, TXT_WEAPON_C3);
3405 return;
3406
3407 // Fourth Weapon Pieces
3408 case HEXEN_SPR_WFR1:
3409 TryPickupWeaponPiece(player, PCLASS_FIGHTER, WPIECE1, special);
3410 return;
3411 case HEXEN_SPR_WFR2:
3412 TryPickupWeaponPiece(player, PCLASS_FIGHTER, WPIECE2, special);
3413 return;
3414 case HEXEN_SPR_WFR3:
3415 TryPickupWeaponPiece(player, PCLASS_FIGHTER, WPIECE3, special);
3416 return;
3417 case HEXEN_SPR_WCH1:
3418 TryPickupWeaponPiece(player, PCLASS_CLERIC, WPIECE1, special);
3419 return;
3420 case HEXEN_SPR_WCH2:
3421 TryPickupWeaponPiece(player, PCLASS_CLERIC, WPIECE2, special);
3422 return;
3423 case HEXEN_SPR_WCH3:
3424 TryPickupWeaponPiece(player, PCLASS_CLERIC, WPIECE3, special);
3425 return;
3426 case HEXEN_SPR_WMS1:
3427 TryPickupWeaponPiece(player, PCLASS_MAGE, WPIECE1, special);
3428 return;
3429 case HEXEN_SPR_WMS2:
3430 TryPickupWeaponPiece(player, PCLASS_MAGE, WPIECE2, special);
3431 return;
3432 case HEXEN_SPR_WMS3:
3433 TryPickupWeaponPiece(player, PCLASS_MAGE, WPIECE3, special);
3434 return;
3435
3436 default:
3437 I_Error("P_SpecialThing: Unknown gettable thing");
3438 }
3439 if (special->special)
3440 {
3441 map_format.execute_line_special(special->special, special->special_args, NULL, 0, toucher);
3442 special->special = 0;
3443 }
3444 if (deathmatch && respawn && !(special->flags & MF_DROPPED))
3445 {
3446 P_HideSpecialThing(special);
3447 }
3448 else
3449 {
3450 P_RemoveMobj(special);
3451 }
3452 player->bonuscount += BONUSADD;
3453 if (player == &players[consoleplayer])
3454 {
3455 S_StartVoidSound(sound);
3456 SB_PaletteFlash(false);
3457 }
3458 }
3459
3460 // Search thinker list for minotaur
3461 static mobj_t *ActiveMinotaur(player_t * master)
3462 {
3463 byte args[5];
3464 mobj_t *mo;
3465 player_t *plr;
3466 thinker_t *think;
3467 unsigned int starttime;
3468
3469 for (think = thinkercap.next; think != &thinkercap; think = think->next)
3470 {
3471 if (think->function != P_MobjThinker)
3472 continue;
3473 mo = (mobj_t *) think;
3474 if (mo->type != HEXEN_MT_MINOTAUR)
3475 continue;
3476 if (mo->health <= 0)
3477 continue;
3478 if (!(mo->flags & MF_COUNTKILL))
3479 continue; // for morphed minotaurs
3480 if (mo->flags & MF_CORPSE)
3481 continue;
3482
3483 COLLAPSE_SPECIAL_ARGS(args, mo->special_args);
3484 memcpy(&starttime, args, sizeof(unsigned int));
3485 if (leveltime - LittleLong(starttime) >= MAULATORTICS)
3486 continue;
3487
3488 plr = mo->special1.m->player;
3489 if (plr == master)
3490 return (mo);
3491 }
3492 return (NULL);
3493 }
3494
3495 dboolean P_MorphPlayer(player_t * player)
3496 {
3497 mobj_t *pmo;
3498 mobj_t *fog;
3499 mobj_t *beastMo;
3500 fixed_t x;
3501 fixed_t y;
3502 fixed_t z;
3503 angle_t angle;
3504 int oldFlags2;
3505
3506 if (player->powers[pw_invulnerability])
3507 { // Immune when invulnerable
3508 return (false);
3509 }
3510 if (player->morphTics)
3511 { // Player is already a beast
3512 return false;
3513 }
3514 pmo = player->mo;
3515 x = pmo->x;
3516 y = pmo->y;
3517 z = pmo->z;
3518 angle = pmo->angle;
3519 oldFlags2 = pmo->flags2;
3520 P_SetMobjState(pmo, HEXEN_S_FREETARGMOBJ);
3521 fog = P_SpawnMobj(x, y, z + TELEFOGHEIGHT, HEXEN_MT_TFOG);
3522 S_StartMobjSound(fog, hexen_sfx_teleport);
3523 beastMo = P_SpawnMobj(x, y, z, HEXEN_MT_PIGPLAYER);
3524 beastMo->special1.i = player->readyweapon;
3525 beastMo->angle = angle;
3526 beastMo->player = player;
3527 player->health = beastMo->health = MAXMORPHHEALTH;
3528 player->mo = beastMo;
3529 memset(&player->armorpoints[0], 0, NUMARMOR * sizeof(int));
3530 player->pclass = PCLASS_PIG;
3531 if (oldFlags2 & MF2_FLY)
3532 {
3533 beastMo->flags2 |= MF2_FLY;
3534 }
3535 player->morphTics = MORPHTICS;
3536 P_ActivateMorphWeapon(player);
3537 return (true);
3538 }
3539
3540 static dboolean P_MorphMonster(mobj_t * actor)
3541 {
3542 mobj_t *master, *monster, *fog;
3543 mobjtype_t moType;
3544 fixed_t x;
3545 fixed_t y;
3546 fixed_t z;
3547 mobj_t oldMonster;
3548
3549 if (actor->player)
3550 return (false);
3551 if (!(actor->flags & MF_COUNTKILL))
3552 return false;
3553 if (actor->flags2 & MF2_BOSS)
3554 return false;
3555 moType = actor->type;
3556 switch (moType)
3557 {
3558 case HEXEN_MT_PIG:
3559 return (false);
3560 case HEXEN_MT_FIGHTER_BOSS:
3561 case HEXEN_MT_CLERIC_BOSS:
3562 case HEXEN_MT_MAGE_BOSS:
3563 return (false);
3564 default:
3565 break;
3566 }
3567
3568 oldMonster = *actor;
3569 x = oldMonster.x;
3570 y = oldMonster.y;
3571 z = oldMonster.z;
3572 map_format.remove_mobj_thing_id(actor);
3573 P_SetMobjState(actor, HEXEN_S_FREETARGMOBJ);
3574 fog = P_SpawnMobj(x, y, z + TELEFOGHEIGHT, HEXEN_MT_TFOG);
3575 S_StartMobjSound(fog, hexen_sfx_teleport);
3576 monster = P_SpawnMobj(x, y, z, HEXEN_MT_PIG);
3577 monster->special2.i = moType;
3578 monster->special1.i = MORPHTICS + P_Random(pr_hexen);
3579 monster->flags |= (oldMonster.flags & MF_SHADOW);
3580 P_SetTarget(&monster->target, oldMonster.target);
3581 monster->angle = oldMonster.angle;
3582 monster->tid = oldMonster.tid;
3583 monster->special = oldMonster.special;
3584 map_format.add_mobj_thing_id(monster, oldMonster.tid);
3585 memcpy(monster->special_args, oldMonster.special_args, SPECIAL_ARGS_SIZE);
3586 dsda_WatchMorph(monster);
3587
3588 // check for turning off minotaur power for active icon
3589 if (moType == HEXEN_MT_MINOTAUR)
3590 {
3591 master = oldMonster.special1.m;
3592 if (master->health > 0)
3593 {
3594 if (!ActiveMinotaur(master->player))
3595 {
3596 master->player->powers[pw_minotaur] = 0;
3597 }
3598 }
3599 }
3600 return (true);
3601 }
3602
3603 void P_PoisonPlayer(player_t * player, mobj_t * poisoner, int poison)
3604 {
3605 if ((player->cheats & CF_GODMODE) || player->powers[pw_invulnerability])
3606 {
3607 return;
3608 }
3609 player->poisoncount += poison;
3610 player->poisoner = poisoner;
3611 if (player->poisoncount > 100)
3612 {
3613 player->poisoncount = 100;
3614 }
3615 }