-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathp_inter.c
736 lines (611 loc) · 19.9 KB
/
p_inter.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
/* Emacs style mode select -*- C++ -*-
*-----------------------------------------------------------------------------
*
*
* PrBoom: a Doom port merged with LxDoom and LSDLDoom
* based on BOOM, a modified and improved DOOM engine
* Copyright (C) 1999 by
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
* Copyright (C) 1999-2000 by
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
* Copyright 2005, 2006 by
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
* Copyright 2023, 2024 by
* Frenkel Smeijers
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* DESCRIPTION:
* Handling interactions (i.e., collisions).
*
*-----------------------------------------------------------------------------*/
#include "d_player.h"
#include "d_englsh.h"
#include "m_random.h"
#include "am_map.h"
#include "r_main.h"
#include "s_sound.h"
#include "sounds.h"
#include "p_tick.h"
#include "i_system.h"
#include "p_inter.h"
#include "p_enemy.h"
#include "globdata.h"
#include "p_inter.h"
#define BONUSADD 6
// Ty 03/07/98 - add deh externals
// Maximums and such were hardcoded values. Need to externalize those for
// dehacked support (and future flexibility). Most var names came from the key
// strings used in dehacked.
const int16_t initial_health = 100;
const int16_t initial_bullets = 50;
static const int16_t maxhealth = 100; // was MAXHEALTH as a #define, used only in this module
static const int16_t max_armor = 200;
static const int16_t green_armor_class = 1; // these are involved with armortype below
static const int16_t blue_armor_class = 2;
static const int16_t max_soul = 200;
static const int16_t soul_health = 100;
const int16_t god_health = 100; // these are used in cheats (see st_stuff.c)
const int16_t idfa_armor = 200;
const int16_t idfa_armor_class = 2;
const int16_t bfgcells = 40; // used in p_pspr.c
// Ty 03/07/98 - end deh externals
// a weapon is found with two clip loads,
// a big item has five clip loads
const int16_t maxammo[NUMAMMO] = {200, 50, 300, 50};
static const int8_t clipammo[NUMAMMO] = { 10, 4, 20, 1};
//
// GET STUFF
//
//
// P_GiveAmmo
// Num is the number of clip loads,
// not the individual count (0= 1/2 clip).
// Returns false if the ammo can't be picked up at all
//
static boolean P_GiveAmmo(player_t *player, ammotype_t ammo, int16_t num)
{
int16_t oldammo;
if (ammo == am_noammo)
return false;
#ifdef RANGECHECK
if (ammo < 0 || ammo > NUMAMMO)
I_Error ("P_GiveAmmo: bad type %i", ammo);
#endif
if ( player->ammo[ammo] == player->maxammo[ammo] )
return false;
if (num)
num *= clipammo[ammo];
else
num = clipammo[ammo]/2;
// give double ammo in trainer mode, you'll need in nightmare
if (_g_gameskill == sk_baby || _g_gameskill == sk_nightmare)
num <<= 1;
oldammo = player->ammo[ammo];
player->ammo[ammo] += num;
if (player->ammo[ammo] > player->maxammo[ammo])
player->ammo[ammo] = player->maxammo[ammo];
// If non zero ammo, don't change up weapons, player was lower on purpose.
if (oldammo)
return true;
// We were down to zero, so select a new weapon.
// Preferences are not user selectable.
switch (ammo)
{
case am_clip:
if (player->readyweapon == wp_fist) {
if (player->weaponowned[wp_chaingun])
player->pendingweapon = wp_chaingun;
else
player->pendingweapon = wp_pistol;
}
break;
case am_shell:
if (player->readyweapon == wp_fist || player->readyweapon == wp_pistol)
if (player->weaponowned[wp_shotgun])
player->pendingweapon = wp_shotgun;
break;
case am_cell:
if (player->readyweapon == wp_fist || player->readyweapon == wp_pistol)
if (player->weaponowned[wp_plasma])
player->pendingweapon = wp_plasma;
break;
case am_misl:
if (player->readyweapon == wp_fist)
if (player->weaponowned[wp_missile])
player->pendingweapon = wp_missile;
default:
break;
}
return true;
}
//
// P_GiveWeapon
// The weapon name may have a MF_DROPPED flag ored in.
//
static boolean P_GiveWeapon(player_t *player, weapontype_t weapon, boolean dropped)
{
boolean gaveammo;
boolean gaveweapon;
if (weaponinfo[weapon].ammo != am_noammo)
{
// give one clip with a dropped weapon,
// two clips with a found weapon
gaveammo = P_GiveAmmo (player, weaponinfo[weapon].ammo, dropped ? 1 : 2);
}
else
gaveammo = false;
if (player->weaponowned[weapon])
gaveweapon = false;
else
{
gaveweapon = true;
player->weaponowned[weapon] = true;
player->pendingweapon = weapon;
}
return gaveweapon || gaveammo;
}
//
// P_GiveBody
// Returns false if the body isn't needed at all
//
static boolean P_GiveBody(player_t *player, int16_t num)
{
if (player->health >= maxhealth)
return false; // Ty 03/09/98 externalized MAXHEALTH to maxhealth
player->health += num;
if (player->health > maxhealth)
player->health = maxhealth;
player->mo->health = player->health;
return true;
}
//
// P_GiveArmor
// Returns false if the armor is worse
// than the current armor.
//
static boolean P_GiveArmor(player_t *player, int16_t armortype)
{
int16_t hits = armortype*100;
if (player->armorpoints >= hits)
return false; // don't pick up
player->armortype = armortype;
player->armorpoints = hits;
return true;
}
//
// P_GiveCard
//
static void P_GiveCard(player_t *player, card_t card)
{
if (player->cards[card])
return;
player->bonuscount = BONUSADD;
player->cards[card] = 1;
}
//
// P_GivePower
//
// Rewritten by Lee Killough
//
boolean P_GivePower(player_t *player, powertype_t power)
{
static const int16_t tics[NUMPOWERS] = {
INVULNTICS, 1 /* strength */, INVISTICS,
IRONTICS, 1 /* allmap */, INFRATICS,
};
switch (power)
{
case pw_invisibility:
player->mo->flags |= MF_SHADOW;
break;
case pw_allmap:
if (player->powers[pw_allmap])
return false;
break;
case pw_strength:
P_GiveBody(player,100);
break;
}
// Unless player has infinite duration cheat, set duration (killough)
if (player->powers[power] >= 0)
player->powers[power] = tics[power];
return true;
}
//
// P_TouchSpecialThing
//
void P_TouchSpecialThing(mobj_t __far* special, mobj_t __far* toucher)
{
player_t *player;
int16_t i;
sfxenum_t sound;
fixed_t delta = special->z - toucher->z;
if (delta > toucher->height || delta < -8*FRACUNIT)
return; // out of reach
sound = sfx_itemup;
player = P_MobjIsPlayer(toucher);
// Dead thing touching.
// Can happen with a sliding player corpse.
if (toucher->health <= 0)
return;
// Identify by sprite.
switch (special->sprite)
{
// armor
case SPR_ARM1:
if (!P_GiveArmor (player, green_armor_class))
return;
player->message = GOTARMOR; // Ty 03/22/98 - externalized
break;
case SPR_ARM2:
if (!P_GiveArmor (player, blue_armor_class))
return;
player->message = GOTMEGA; // Ty 03/22/98 - externalized
break;
// bonus items
case SPR_BON1:
player->health++; // can go over 100%
if (player->health > (maxhealth * 2))
player->health = (maxhealth * 2);
player->mo->health = player->health;
player->message = GOTHTHBONUS; // Ty 03/22/98 - externalized
break;
case SPR_BON2:
player->armorpoints++; // can go over 100%
if (player->armorpoints > max_armor)
player->armorpoints = max_armor;
if (!player->armortype)
player->armortype = green_armor_class;
player->message = GOTARMBONUS; // Ty 03/22/98 - externalized
break;
case SPR_SOUL:
player->health += soul_health;
if (player->health > max_soul)
player->health = max_soul;
player->mo->health = player->health;
player->message = GOTSUPER; // Ty 03/22/98 - externalized
sound = sfx_getpow;
break;
// cards
// leave cards for everyone
case SPR_BKEY:
if (!player->cards[it_bluecard])
player->message = GOTBLUECARD; // Ty 03/22/98 - externalized
P_GiveCard (player, it_bluecard);
break;
case SPR_YKEY:
if (!player->cards[it_yellowcard])
player->message = GOTYELWCARD; // Ty 03/22/98 - externalized
P_GiveCard (player, it_yellowcard);
break;
case SPR_RKEY:
if (!player->cards[it_redcard])
player->message = GOTREDCARD; // Ty 03/22/98 - externalized
P_GiveCard (player, it_redcard);
break;
// medikits, heals
case SPR_STIM:
if (!P_GiveBody (player, 10))
return;
player->message = GOTSTIM; // Ty 03/22/98 - externalized
break;
case SPR_MEDI:
if (!P_GiveBody (player, 25))
return;
if (player->health < 50) // cph - 25 + the 25 just added, thanks to Quasar for reporting this bug
player->message = GOTMEDINEED; // Ty 03/22/98 - externalized
else
player->message = GOTMEDIKIT; // Ty 03/22/98 - externalized
break;
// power ups
case SPR_PINS:
if (!P_GivePower (player, pw_invisibility))
return;
player->message = GOTINVIS; // Ty 03/22/98 - externalized
sound = sfx_getpow;
break;
case SPR_SUIT:
if (!P_GivePower (player, pw_ironfeet))
return;
player->message = GOTSUIT; // Ty 03/22/98 - externalized
sound = sfx_getpow;
break;
case SPR_PMAP:
if (!P_GivePower (player, pw_allmap))
return;
player->message = GOTMAP; // Ty 03/22/98 - externalized
sound = sfx_getpow;
break;
case SPR_PVIS:
if (!P_GivePower (player, pw_infrared))
return;
player->message = GOTVISOR; // Ty 03/22/98 - externalized
sound = sfx_getpow;
break;
// ammo
case SPR_CLIP:
if (special->flags & MF_DROPPED)
{
if (!P_GiveAmmo (player,am_clip,0))
return;
}
else
{
if (!P_GiveAmmo (player,am_clip,1))
return;
}
player->message = GOTCLIP; // Ty 03/22/98 - externalized
break;
case SPR_AMMO:
if (!P_GiveAmmo (player, am_clip,5))
return;
player->message = GOTCLIPBOX; // Ty 03/22/98 - externalized
break;
case SPR_ROCK:
if (!P_GiveAmmo (player, am_misl,1))
return;
player->message = GOTROCKET; // Ty 03/22/98 - externalized
break;
case SPR_BROK:
if (!P_GiveAmmo (player, am_misl,5))
return;
player->message = GOTROCKBOX; // Ty 03/22/98 - externalized
break;
case SPR_SHEL:
if (!P_GiveAmmo (player, am_shell,1))
return;
player->message = GOTSHELLS; // Ty 03/22/98 - externalized
break;
case SPR_SBOX:
if (!P_GiveAmmo (player, am_shell,5))
return;
player->message = GOTSHELLBOX; // Ty 03/22/98 - externalized
break;
case SPR_BPAK:
if (!player->backpack)
{
for (i=0 ; i<NUMAMMO ; i++)
player->maxammo[i] *= 2;
player->backpack = true;
}
for (i=0 ; i<NUMAMMO ; i++)
P_GiveAmmo (player, i, 1);
player->message = GOTBACKPACK; // Ty 03/22/98 - externalized
break;
// weapons
case SPR_MGUN:
if (!P_GiveWeapon (player, wp_chaingun, (special->flags&MF_DROPPED)!=0) )
return;
player->message = GOTCHAINGUN; // Ty 03/22/98 - externalized
sound = sfx_wpnup;
break;
case SPR_CSAW:
if (!P_GiveWeapon (player, wp_chainsaw, false) )
return;
player->message = GOTCHAINSAW; // Ty 03/22/98 - externalized
sound = sfx_wpnup;
break;
case SPR_LAUN:
if (!P_GiveWeapon (player, wp_missile, false) )
return;
player->message = GOTLAUNCHER; // Ty 03/22/98 - externalized
sound = sfx_wpnup;
break;
case SPR_SHOT:
if (!P_GiveWeapon (player, wp_shotgun, (special->flags&MF_DROPPED)!=0 ) )
return;
player->message = GOTSHOTGUN; // Ty 03/22/98 - externalized
sound = sfx_wpnup;
break;
default:
I_Error ("P_SpecialThing: Unknown gettable thing");
}
if (special->flags & MF_COUNTITEM)
player->itemcount++;
P_RemoveMobj (special);
player->bonuscount += BONUSADD;
/* cph 20028/10 - for old-school DM addicts, allow old behavior
* where only consoleplayer's pickup sounds are heard */
// displayplayer, not consoleplayer, for viewing multiplayer demos
if (player == &_g_player)
S_StartSound (player->mo, sound | PICKUP_SOUND); // killough 4/25/98
}
//
// KillMobj
//
static void P_KillMobj(mobj_t __far* source, mobj_t __far* target)
{
mobjtype_t item;
mobj_t __far* mo;
target->flags &= ~MF_SHOOTABLE;
target->flags &= ~MF_NOGRAVITY;
target->flags |= MF_CORPSE|MF_DROPOFF;
target->height >>= 2;
if (!((target->flags ^ MF_COUNTKILL) & (MF_FRIEND | MF_COUNTKILL)))
_g_totallive--;
if (source && P_MobjIsPlayer(source))
{
// count for intermission
if (target->flags & MF_COUNTKILL)
P_MobjIsPlayer(source)->killcount++;
}
else if (target->flags & MF_COUNTKILL)
{ /* Add to kills tally */
// count all monster deaths,
// even those caused by other monsters
_g_player.killcount++;
}
if (P_MobjIsPlayer(target))
{
target->flags &= ~MF_SOLID;
_g_player.playerstate = PST_DEAD;
P_DropWeapon (&_g_player);
if (automapmode & am_active)
AM_Stop(); // don't die in auto map; switch view prior to dying
}
if (target->health < -mobjinfo[target->type].spawnhealth && mobjinfo[target->type].xdeathstate)
P_SetMobjState (target, mobjinfo[target->type].xdeathstate);
else
P_SetMobjState (target, mobjinfo[target->type].deathstate);
target->tics -= P_Random()&3;
if (target->tics < 1)
target->tics = 1;
// Drop stuff.
// This determines the kind of object spawned
// during the death frame of a thing.
if( (_g_player.cheats & CF_ENEMY_ROCKETS) && (target->type >= MT_POSSESSED) && (target->type <= MT_BRUISERSHOT) )
{
item = MT_MISC27; //Everyone drops a rocket launcher.
}
else
{
switch (target->type)
{
case MT_POSSESSED:
item = MT_CLIP;
break;
case MT_SHOTGUY:
item = MT_SHOTGUN;
break;
default:
return;
}
}
mo = P_SpawnMobj (target->x,target->y,ONFLOORZ, item);
mo->flags |= MF_DROPPED; // special versions of items
}
//
// P_DamageMobj
// Damages both enemies and players
// "inflictor" is the thing that caused the damage
// creature or missile, can be NULL (slime, etc)
// "source" is the thing to target after taking damage
// creature or NULL
// Source and inflictor are the same for melee attacks.
// Source can be NULL for slime, barrel explosions
// and other environmental stuff.
//
void P_DamageMobj(mobj_t __far* target, mobj_t __far* inflictor, mobj_t __far* source, int16_t damage)
{
player_t *player;
boolean justhit = false; /* killough 11/98 */
/* killough 8/31/98: allow bouncers to take damage */
if (!(target->flags & (MF_SHOOTABLE)))
return; // shouldn't happen...
if (target->health <= 0)
return;
player = P_MobjIsPlayer(target);
if (player && _g_gameskill == sk_baby)
damage >>= 1; // take half damage in trainer mode
// Some close combat weapons should not
// inflict thrust and push the victim out of reach,
// thus kick away unless using the chainsaw.
if (inflictor && !(target->flags & MF_NOCLIP) &&
(!source || !P_MobjIsPlayer(source) ||
P_MobjIsPlayer(source)->readyweapon != wp_chainsaw))
{
angle_t ang = R_PointToAngle2 (inflictor->x, inflictor->y,
target->x, target->y);
fixed_t thrust = damage*(FRACUNIT>>3)*100/mobjinfo[target->type].mass;
// make fall forwards sometimes
if ( target->health < damage && damage < 40
&& target->z - inflictor->z > 64*FRACUNIT
&& P_Random() & 1)
{
ang += ANG180;
thrust *= 4;
}
ang >>= ANGLETOFINESHIFT;
target->momx += FixedMulAngle(thrust, finecosine(ang));
target->momy += FixedMulAngle(thrust, finesine( ang));
}
// player specific
if (player)
{
// end of game hell hack
if (target->subsector->sector->special == 11 && damage >= target->health)
damage = target->health - 1;
// Below certain threshold,
// ignore damage in GOD mode, or with INVUL power.
// killough 3/26/98: make god mode 100% god mode in non-compat mode
if ((damage < 1000 || ((player->cheats&CF_GODMODE))) &&
(player->cheats&CF_GODMODE || player->powers[pw_invulnerability]))
return;
if (player->armortype)
{
int16_t saved = player->armortype == 1 ? damage/3 : damage/2;
if (player->armorpoints <= saved)
{
// armor is used up
saved = player->armorpoints;
player->armortype = 0;
}
player->armorpoints -= saved;
damage -= saved;
}
player->health -= damage; // mirror mobj health here for Dave
if (player->health < 0)
player->health = 0;
player->attacker = source;
player->damagecount += damage; // add damage after armor / invuln
if (player->damagecount > 100)
player->damagecount = 100; // teleport stomp does 10k points...
}
// do the damage
target->health -= damage;
if (target->health <= 0)
{
P_KillMobj (source, target);
return;
}
/* If target is a player, set player's target to source,
* so that a friend can tell who's hurting a player
*/
if (player)
target->target = source;
if (P_Random () < mobjinfo[target->type].painchance)
{
justhit = true;
P_SetMobjState(target, mobjinfo[target->type].painstate);
}
target->reactiontime = 0; // we're awake now...
/* killough 9/9/98: cleaned up, made more consistent: */
if (source && source != target && !target->threshold)
{
/* if not intent on another player, chase after this one
*
* killough 2/15/98: remember last enemy, to prevent
* sleeping early; 2/21/98: Place priority on players
* killough 9/9/98: cleaned up, made more consistent:
*/
if (!target->lastenemy || target->lastenemy->health <= 0 ||
(
!((target->flags ^ target->lastenemy->flags) & MF_FRIEND) &&
target->target != source)) // remember last enemy - killough
target->lastenemy = target->target;
target->target = source;
target->threshold = BASETHRESHOLD;
if (target->state == &states[mobjinfo[target->type].spawnstate]
&& mobjinfo[target->type].seestate != S_NULL)
P_SetMobjState (target, mobjinfo[target->type].seestate);
}
/* killough 11/98: Don't attack a friend, unless hit by that friend.
* cph 2006/04/01 - implicitly this is only if mbf_features */
if (justhit && (target->target == source || !target->target ||
!(target->flags & target->target->flags & MF_FRIEND)))
target->flags |= MF_JUSTHIT; // fight back!
}