forked from nzp-team/quakec
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdamage.qc
More file actions
619 lines (518 loc) · 16.1 KB
/
damage.qc
File metadata and controls
619 lines (518 loc) · 16.1 KB
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
/*
server/clientfuncs.qc
used for any sort of down, hit, etc that the player or entity
experiences
Copyright (C) 2021-2024 NZ:P Team
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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
void (float achievement_id, optional entity who) GiveAchievement;
void(entity client) LastStand_Begin;
void() Gamemode_GetUp;
void(entity attacker, float death_style) Gamemode_DieHandler;
float(float current_earned_score, float damage_style) Gamemode_ScoreForDamage;
float(float current_health_delay, float current_perks) Gamemode_GetHealthRegenDelayForPlayer;
#define DMG_SCORE_HEADSHOT 100 // Death by Headshot
#define DMG_SCORE_MELEE 130 // Death by Melee
#define DMG_SCORE_UPPERTORSO 60 // Death by gunshot, upper torso.
#define DMG_SCORE_LOWERTORSO 50 // Death by gunshot, lower torso.
#define DMG_SCORE_GRENADE 50 // Death by Grenade.
#define DMG_SCORE_EXPLOSIVE 60 // Death by Explosive Weapon.
#define DMG_SCORE_TESLA 50 // Death by Tesla.
#define DMG_SCORE_FLOPPER 50 // Death by PhD Flopper
#define DMG_SCORE_STDDAMAGE 10 // Standard Damage reward.
void() Barrel_Hit;
void() teddy_react;
// Fade to black function, creates another think for restart
void() EndGame_FadePrompt =
{
entity players = find(world, classname, "player");
while(players != world) {
nzp_screenflash(players, SCREENFLASH_COLOR_BLACK, 5, SCREENFLASH_FADE_IN);
players = find(players, classname, "player");
}
#ifdef FTE
self.think = MapRotation_Decide;
#else
self.think = Soft_Restart;
#endif // FTE
self.nextthink = time + 5;
}
//Actual endgame function, all zombies die, music plays
void() EndGame =
{
entity old_self;
entity who = find(world,classname,"ai_zombie");
while(who != world)
{
if(who.health)
{
old_self = self;
self = who;
self.th_die();
self = old_self;
}
who = find(who,classname,"ai_zombie");
}
self.think = EndGame_FadePrompt;
self.nextthink = time + 28;
}
// when dead and other players exist and are alive, throw user into spectate mode
void() startspectate =
{
if (!self.downed)
return;
if (self.beingrevived)
{
self.think = startspectate;
self.nextthink = time + 0.1;
return;
}
self.downedloop = 0;
self.beingrevived = false;
self.health = 100;
self.weaponmodel = "";
self.weapon2model = "";
self.downed = 0;
self.frame = 0;
if (player_count > 1)
SpectatorSpawn();
}
// searches for players that are alive given which clients have which playernumbers
// Returns 1 if there IS someone in the world that's not downed
float() PollPlayersAlive =
{
entity players = find(world, classname, "player");
while(players != world) {
if (!players.downed)
return 1;
players = find(players, classname, "player");
}
return 0;
}
// Endgamesetup -- think function for setting up the death of everyone
void() EndGameSetup =
{
entity gameover_watcher = spawn();
gameover_watcher.think = EndGame;
gameover_watcher.nextthink = time + 4;
gameover_watcher.classname = "gameover_watcher";
entity players = find(world, classname, "player");
while(players != world) {
players.health = 0;
players.weapon = 0;
players.currentammo = 0;
players.currentmag = 0;
players.weaponmodel = "";
players.weapon2model = "";
players.animend = SUB_Null;
players.perks = 0;
players.movetype = MOVETYPE_TOSS;
players.velocity = '0 0 0';
Player_RemoveScore(players, players.points);
Player_AddScore(players, players.score, false);
players = find(players, classname, "player");
}
if (in_endgame_sequence == false) {
Rounds_PlayTransition("sounds/music/end.wav");
NotifyGameEnd();
}
in_endgame_sequence = true;
Player_RemoveScore(self, self.points);
Player_AddScore(self, self.score, false);
for (float i = 0; i < MAX_PLAYER_WEAPONS; ++i)
{
Weapon_RemoveWeapon(0);
}
return;
}
float() push_away_zombies;
void () GetUp =
{
// Play Getting Up Animation
PAnim_GetUp();
Player_SetStance(self, PLAYER_STANCE_STAND, false);
// Bad hack: if we're crouching, just play some dummy crouchwalk frames.
if (self.stance == PLAYER_STANCE_CROUCH)
PAnim_CrouchWalk7();
self.health = 100;
self.downedloop = 0; // used for death timing vs endgame
self.downed = 0;
self.classname = "player";
// Take away the ammo that was fired while in last stand.
if (self.weapon != W_COLT) {
if (self.weapon == self.weaponbk) {
self.currentammobk -= self.teslacount;
// Take from the mag if the reserve is empty now
if (self.currentammobk < 0) {
self.currentmagbk += self.currentammobk;
self.currentammobk = 0;
}
} else if (self.weapon == self.weapons[1].weapon_id) {
self.weapons[1].weapon_reserve -= self.teslacount;
// Take from the mag if the reserve is empty now
if (self.weapons[1].weapon_reserve < 0) {
self.weapons[0].weapon_magazine += self.weapons[1].weapon_reserve;
self.weapons[1].weapon_reserve = 0;
}
}
}
self.teslacount = 0;
Weapon_AssignWeapon(0, self.weaponbk, self.currentmagbk, self.currentammobk, self.tierbk);
Gamemode_GetUp();
};
// poll checking whether to see if our revive invoke is active
void(entity ent) CheckRevive =
{
if (self.invoke_revive) {
GetUp();
DisableReviveIcon(self.playernum);
self.invoke_revive = 0;
self.firer = world;
}
}
void(entity attacker, float d_style) DieHandler =
{
if (cvar("sv_headshotonly") == 1 && d_style != DMG_TYPE_HEADSHOT && self.classname == "ai_zombie")
return;
float t;
t = random();
if (self.classname == "ai_zombie" || self.classname == "ai_dog") {
self.th_die();
}
if (attacker.classname == "player") {
attacker.kills++;
nzp_hitmarker(attacker, true);
float points_earned = 0;
switch(d_style) {
case DMG_TYPE_HEADSHOT:
points_earned = DMG_SCORE_HEADSHOT;
attacker.headshots++;
break;
case DMG_TYPE_MELEE:
points_earned = DMG_SCORE_MELEE;
break;
case DMG_TYPE_TESLA:
points_earned = DMG_SCORE_GRENADE;
break;
case DMG_TYPE_FLAMETHROWER:
points_earned = DMG_SCORE_GRENADE;
// override their death sound (FIXME: make a new sound..)
Sound_PlaySound(self, "sounds/pu/drop.wav", SOUND_TYPE_ZOMBIE_LOUD, SOUND_PRIORITY_PLAYALWAYS);
break;
case DMG_TYPE_GRENADE:
points_earned = DMG_SCORE_GRENADE;
break;
case DMG_TYPE_EXPLOSIVE:
points_earned = DMG_SCORE_EXPLOSIVE;
break;
case DMG_TYPE_LOWERTORSO:
points_earned = DMG_SCORE_LOWERTORSO;
break;
case DMG_TYPE_UPPERTORSO:
points_earned = DMG_SCORE_UPPERTORSO;
break;
case DMG_TYPE_FLOPPER:
points_earned = DMG_SCORE_FLOPPER;
break;
default:
if (cvar("developer"))
bprint(PRINT_HIGH, "DieHandler: Received invalid style\n");
break;
}
if (cvar("sv_difficulty") == 3)
points_earned = floor((points_earned/10) * 0.75) * 10;
Player_AddScore(attacker, Gamemode_ScoreForDamage(points_earned, d_style), true);
Gamemode_DieHandler(attacker, d_style);
}
}
void(entity victim, entity attacker, float damage, float d_style) DamageHandler = {
if (cvar("sv_headshotonly") == 1 && d_style != DMG_TYPE_HEADSHOT && victim.classname == "ai_zombie")
return;
// don't do any attacking during nuke delay
if (d_style == DMG_TYPE_ZOMBIESWIPE && nuke_powerup_active > time)
return;
entity old_self;
if (victim.classname == "ai_zombie" || victim.classname == "ai_dog") {
if (attacker.classname == "player" && (victim.health - damage) > 0 && d_style != DMG_TYPE_OTHER) {
Player_AddScore(attacker, Gamemode_ScoreForDamage(DMG_SCORE_STDDAMAGE, d_style), true);
nzp_hitmarker(attacker, false);
}
victim.health = victim.health - damage;
if (d_style == DMG_TYPE_EXPLOSIVE && damage != 0) {
if (victim.health > 0 && victim.crawling == 2) {
makeCrawler(victim);
GiveAchievement(3, attacker);
}
}
if (victim.health <= 0 || instakill_finished > time) {
old_self = self;
self = victim;
DieHandler(attacker, d_style);
self = old_self;
}
} else if (victim.classname == "player" && !victim.downed) {
if (victim.flags & FL_GODMODE) {
return;
}
// Abstinence Program
victim.ach_tracker_abst = 1;
victim.health -= damage;
// Determine how long to wait before regenerating based on our Health ratio
float ratio = victim.health / victim.max_health;
float health_delay_s = 0;
// Badly hurt = longer delay.
if (ratio <= 0.2) {
health_delay_s = 5;
// We're really low, so let's regen REALLY slow.
victim.health_was_very_low = true;
} else {
health_delay_s = 2.4;
}
health_delay_s = Gamemode_GetHealthRegenDelayForPlayer(health_delay_s, victim.perks);
victim.health_delay = time + health_delay_s;
// shake the camera on impact
vector distance;
distance = attacker.angles - victim.angles;
// just to prevent radical punchangles
while(distance_x > 10 || distance_x < -10) {
distance_x /= 2;
}
while(distance_y > 10 || distance_y < -10) {
distance_y /= 2;
}
// apply
victim.punchangle_x = distance_x;
victim.punchangle_y = distance_y;
// Play pain noise if this isn't done by an electric barrier.
if (d_style != DMG_TYPE_ELECTRICTRAP) {
Sound_PlaySound(victim, "sounds/player/pain4.wav", SOUND_TYPE_PLAYER_VOICE, SOUND_PRIORITY_PLAYALWAYS);
} else {
Sound_PlaySound(victim, "sounds/machines/elec_shock.wav", SOUND_TYPE_PLAYER_VOICE, SOUND_PRIORITY_PLAYALWAYS);
}
if (victim.sprinting) {
old_self = self;
self = victim;
W_SprintStop();
self = old_self;
}
victim.sprint_delay = time + 0.75;
// Was 20 for.. some reason.
if (victim.health <= 1)
{
LastStand_Begin(victim);
}
}
}
/*
============
CanDamage
Returns true if the inflictor can directly damage the target. Used for
explosions and melee attacks.
============
*/
float(entity targ, entity inflictor) CanDamage =
{
if (targ.flags == FL_GODMODE)
return FALSE;
// bmodels need special checking because their origin is 0,0,0
if (targ.movetype == MOVETYPE_PUSH)
{
traceline(inflictor.origin, 0.5 * (targ.absmin + targ.absmax), TRUE, self);
if (trace_fraction == 1)
return TRUE;
if (trace_ent == targ)
return TRUE;
return FALSE;
}
traceline(inflictor.origin, targ.origin, TRUE, self);
if (trace_fraction == 1)
return TRUE;
traceline(inflictor.origin, targ.origin + '15 15 0', TRUE, self);
if (trace_fraction == 1)
return TRUE;
traceline(inflictor.origin, targ.origin + '-15 -15 0', TRUE, self);
if (trace_fraction == 1)
return TRUE;
traceline(inflictor.origin, targ.origin + '-15 15 0', TRUE, self);
if (trace_fraction == 1)
return TRUE;
traceline(inflictor.origin, targ.origin + '15 -15 0', TRUE, self);
if (trace_fraction == 1)
return TRUE;
return FALSE;
};
float(float min, float max, vector org1, vector org2, float radius) calculate_proximity_value =
{
float proximity_value;
float distance = fabs(vlen(org1 - org2));
if (distance <= radius) {
float normalized_distance = distance / radius;
proximity_value = min + (max - min) * (1 - normalized_distance);
} else {
proximity_value = min;
}
return proximity_value;
};
void(entity inflictor, entity attacker, float damage2, float mindamage, float radius) DamgageExplode =
{
float final_damage = 0;
float damage_style = 0;
entity ent;
float multi, r;
ent = findradius(inflictor.origin, radius);
while (ent != world)
{
if(ent.classname == "player")
{
if (ent.perks & P_FLOP) // PhD Flopper makes us immune to any explosive damage
final_damage = 0;
else if (inflictor.classname == "betty") // Self-inflicted betties don't do damage either.
final_damage = 0;
else if (inflictor.owner != ent) // we don't want OUR explosives to harm other players..
final_damage = 0;
else
{
final_damage = (radius - vlen(inflictor.origin - ent.origin))*1.5;
if(final_damage < 0)
{
ent = ent.chain;
continue;
}
if (final_damage > radius * 0.75)
final_damage = 100;
if (final_damage < other.health)
{
Player_AddScore(self, Gamemode_ScoreForDamage(DMG_SCORE_STDDAMAGE, 0), false);
}
else if (final_damage > other.health)
{
Player_AddScore(self, Gamemode_ScoreForDamage(DMG_SCORE_STDDAMAGE, 0), false);
}
else
{
final_damage /= radius;
final_damage *= 60;
}
// inflicting damage from an explosive introduces a delay before
// player can sprint again.
ent.sprint_delay = time + 3;
}
// shake the camera on impact
vector distance;
distance = inflictor.angles - ent.angles;
// just to prevent radical punchangles
while(distance_x > 10 || distance_x < -10) {
distance_x /= 2;
}
while(distance_y > 10 || distance_y < -10) {
distance_y /= 2;
}
// Give a heavy rumble for feedback of being in explosion vicinity.
nzp_rumble(ent, 1400, 2000, 200);
// apply
ent.punchangle_x = distance_x;
ent.punchangle_y = distance_y;
}
else if (ent.classname == "explosive_barrel")
{
final_damage = radius - vlen(inflictor.origin - ent.origin);
final_damage *= 4;
if (final_damage < 0)
{
ent = ent.chain;
continue;
}
ent.health -= final_damage;
entity oldself;
oldself = self;
self = ent;
Barrel_Hit();
self = oldself;
}
else if (ent.classname == "teddy_spawn")
{
entity oldself2;
oldself2 = self;
self = ent;
teddy_react();
self = oldself2;
}
else if (ent.takedamage && ent.classname != "ai_zombie_head" && ent.classname != "ai_zombie_larm" && ent.classname != "ai_zombie_rarm")
{
if (mapname == "ndu" && ent.classname == "ai_zombie" && inflictor.classname == "explosive_barrel") {
ach_tracker_barr++;
if (ach_tracker_barr >= 15)
{
GiveAchievement(13);
}
}
// cypress -- accurate explosive damage
// cod likes to override the damage to ai with
// explosives (yay!).
if (inflictor.classname == "grenade") {
// grenades follow the logic of (rounds + (rand 150-500))
// rounds is basically meaningless though.. wtf?
final_damage = rounds + rint(random() * 350) + 150;
damage_style = DMG_TYPE_GRENADE;
} else if (inflictor.classname == "projectile_grenade") {
// projectile-based grenades (mustang & sally) seem to do
// more damage than standard grenades.
// (rounds + (rand 1200-5000))
final_damage = rounds + rint(random() * 3800) + 1200;
damage_style = DMG_TYPE_EXPLOSIVE;
} else if (inflictor.classname == "rocket") {
// rockets were kinda tricky to figure out, this is as close
// as i can get and i'm not super confident..
// (rounds * (rand 0-100) * weapon_damage/500).
final_damage = (rounds * rint(random() * 100)) * damage2/500;
damage_style = DMG_TYPE_EXPLOSIVE;
} else if (inflictor.classname == "projectile_raybeam") {
//final_damage = calculate_proximity_value(mindamage, damage2, inflictor.origin, ent.origin, radius);
//bprint(PRINT_HIGH, strcat("damage: ", ftos(final_damage), "\n"));
final_damage = damage2;
damage_style = DMG_TYPE_GRENADE;
} else if (inflictor.classname == "player") {
// phd flopper.
final_damage = calculate_proximity_value(mindamage, damage2, inflictor.origin, ent.origin, radius);
damage_style = DMG_TYPE_FLOPPER;
} else {
r = rounds;
multi = 1.07;
while(r > 0)
{
multi *= 1.05;
r --;
}
if (mindamage == 75)
{
final_damage = (200 * multi) + 185;
}
else
{
final_damage = (mindamage + damage2)/2;
}
}
// to decide if this should make a crawler, check if we've done 10% or more damage
if (final_damage / ent.health > 0.10 && ent.crawling != true && ent.classname != "ai_dog") {
ent.crawling = 2;
}
}
if (final_damage > 0) {
if (CanDamage (ent, inflictor))
DamageHandler (ent, attacker, final_damage, damage_style);
}
ent = ent.chain;
}
};