-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcombat.qc
526 lines (432 loc) · 12.6 KB
/
combat.qc
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
/*
============
CanDamage
Returns true if the inflictor can directly damage the target. Used for
explosions and melee attacks.
============
*/
float(entity targ, vector org) CanDamage =
{
// bmodels need special checking because their origin is 0,0,0
if (targ.movetype == MOVETYPE_PUSH)
{
traceline(org, 0.5 * (targ.absmin + targ.absmax), TRUE, self);
if (trace_fraction == 1)
return TRUE;
if (trace_ent == targ)
return TRUE;
return FALSE;
}
traceline(org, targ.origin, TRUE, self);
if (trace_fraction == 1)
return TRUE;
traceline(org, targ.origin + '15 15 0', TRUE, self);
if (trace_fraction == 1)
return TRUE;
traceline(org, targ.origin + '-15 -15 0', TRUE, self);
if (trace_fraction == 1)
return TRUE;
traceline(org, targ.origin + '-15 15 0', TRUE, self);
if (trace_fraction == 1)
return TRUE;
traceline(org, targ.origin + '15 -15 0', TRUE, self);
if (trace_fraction == 1)
return TRUE;
return FALSE;
};
/*
============
Killed
============
*/
void(entity targ, entity attacker, entity inflictor) Killed =
{
local entity oself;
oself = self;
self = targ;
if ((self.health < -99) && (self.classname == "player"))
//if (self.health < -99)
self.health = -99; // don't let sbar look bad if a player
if (self.movetype == MOVETYPE_PUSH || self.movetype == MOVETYPE_NONE)
{ // doors, triggers, etc
self.th_die ();
self = oself;
return;
}
self.enemy = attacker;
// bump the monster counter
if ((self.flags & FL_MONSTER && !(self.flags & FL_PACIFIST))
|| (self.flags & FL_PACIFIST && self.spawnflags & MONSTER_COUNTONSPAWN)
) {
// if it's a monster generated by a spawner, update the generator's alive count
if (self.spawnflags & MONSTER_SPAWNER) {
// just to be sure the spawner wasn't removed or if the "owner" field has been manipulated somehow
if (self.owner.classname == self.classname) {
self.owner.cnt--;
}
}
killed_monsters = killed_monsters + 1;
WriteByte (MSG_ALL, SVC_KILLEDMONSTER);
}
ClientObituary(self, attacker);
self.takedamage = DAMAGE_NO;
self.touch = SUB_Null;
// This check didn't exist before, but running this block on non-monsters didn't make sense.
// Will it cause issues?
// -bmFbr
if (self.flags & FL_MONSTER) {
// fall to ground
self.movetype = MOVETYPE_STEP;
self.flags &~= FL_FLY | FL_SWIM | FL_SWIM2;
// monster_death_use() inlined below
// makes sure wake trigger monsters won't fire target4 upon death
if (self.spawnflags & MONSTER_WAKETRIGGER) self.target4 = "";
activator = self.enemy;
SUB_UseTargets ();
self.deadflag = DEAD_DYING;
}
if (attacker.classname == "trigger_void") {
if (self.flags & FL_MONSTER) {
entity_hide(self);
self = oself;
return;
}
else if (self.classname == "player") {
PlayerDieGo(TRUE);
self = oself;
return;
}
}
self.th_die ();
self = oself;
};
/*
============
T_Damage
The damage is coming from inflictor, but get mad at attacker
This should be the only function that ever reduces health.
============
*/
void(entity targ, entity inflictor, entity attacker, float damage, float dmgtype) T_Damage =
{
local vector dir;
local entity oldself;
local float save;
local float take;
local float blocked_by_biosuit; //johnfitz
local float ignore_armor; //johnfitz
float filtered;
entity filter;
if (!targ.takedamage)
return;
// used by buttons and triggers to set activator for target firing
damage_attacker = attacker;
// check for quad damage powerup on the attacker
if ((attacker.super_damage_finished > time) || (attacker.trif_finished > time))
damage = damage * 4;
//johnfitz -- special rules for some damage types
//biosuit protects against burning and steam
if (targ.radsuit_finished > time && dmgtype & DMGTYPE_BURN)
blocked_by_biosuit = TRUE;
else
blocked_by_biosuit = FALSE;
//don't deplete armor if drowning/burning, or protected by biosuit/pentagram/godmode (note: in ID1 pentagram/godmode doesn't actually protect your armor)
if (dmgtype & DMGTYPE_BURN || dmgtype & DMGTYPE_DROWN || blocked_by_biosuit || targ.invincible_finished >= time || targ.trif_finished >= time || targ.flags & FL_GODMODE)
ignore_armor = TRUE;
else
ignore_armor = FALSE;
//johnfitz
if (targ.attackerfilter != "") {
filtered = TRUE;
filter = find(world, targetname, targ.attackerfilter);
while (filter && filtered) {
filtered = filter_entity(attacker, filter);
if (filter.target)
filter = find(world, targetname, filter.target);
else
filter = world;
}
if (!filtered)
return;
}
if (targ.inflictorfilter != "") {
filtered = TRUE;
filter = find(world, targetname, targ.inflictorfilter);
while (filter && filtered) {
filtered = filter_entity(inflictor, filter);
if (filter.target)
filter = find(world, targetname, filter.target);
else
filter = world;
}
if (!filtered)
return;
}
if (targ.damagedby) {
if (!(dmgtype & targ.damagedby))
return;
}
take = damage;
// save damage based on the target's armor level
if (targ.armortype && !ignore_armor){
save = ceil(targ.armortype*damage);
if (save >= targ.armorvalue)
{
save = targ.armorvalue;
targ.armortype = 0; // lost all armor
targ.items = targ.items - (targ.items & (IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3));
}
targ.armorvalue = targ.armorvalue - save;
take = ceil(damage-save);
}
// checks if entity has a custom damage calculation function
if (targ.th_damage) {
oldself = self;
self = targ;
take = self.th_damage(inflictor, attacker, take, damage, dmgtype);
self = oldself;
if (take <= 0) return;
}
// figure momentum add
if ( (inflictor != world) && (targ.movetype == MOVETYPE_WALK) && (inflictor.classname != "trigger_void")) {
dir = targ.origin - (inflictor.absmin + inflictor.absmax) * 0.5;
dir = normalize(dir);
targ.velocity = targ.velocity + dir*damage*8;
}
// check for godmode or invincibility
if (targ.flags & FL_GODMODE)
return;
if ((targ.invincible_finished >= time) || (targ.trif_finished >= time)) {
if (targ.invincible_sound < time && targ.invincible_finished >= time) {
sound (self, CHAN_ITEM, "items/protect3.wav", 1, ATTN_NORM);
self.invincible_sound = time + 2;
}
return;
}
//johnfitz -- momentum added, can return now
if (blocked_by_biosuit)
return;
//johnfitz
// team play damage avoidance
if (teamplay == 1 && targ.team > 0 && targ.team == attacker.team)
return;
take = floor(take); // don't deal float damage
// do the damage
targ.health = targ.health - take;
// Add to the damage total for clients, which will be sent as a single
// message at the end of the frame.
// dmg_take having a value is what triggers the engine to tint the screen,
// twitch the view, and show the pain face in the HUD.
// Both fields at cleared at each frame for clients
if (targ.flags & FL_CLIENT) {
targ.dmg_take = targ.dmg_take + take;
targ.dmg_take_hud = self.dmg_take;
targ.dmg_save = targ.dmg_save + save;
}
// store inflictor info
targ.dmg_inflictor = inflictor;
targ.inflictor_origin = inflictor.origin;
targ.inflictor_movetype = inflictor.movetype;
targ.inflictor_vel = inflictor.velocity;
// health-based triggering
if (targ.flags & FL_MONSTER && targ.spawnflags & MONSTER_HEALTHTRIGGER) {
if (targ.health <= targ.max_health * 0.75 && targ.target2 != "") {
activator = targ.enemy;
SUB_UseSpecificTarget(targ.target2, targetname);
targ.target2 = "";
}
if (targ.health <= targ.max_health * 0.50 && targ.target3 != "") {
activator = targ.enemy;
SUB_UseSpecificTarget(targ.target3, targetname);
targ.target3 = "";
}
if (targ.health <= targ.max_health * 0.25 && targ.target4 != "") {
activator = targ.enemy;
SUB_UseSpecificTarget(targ.target4, targetname);
targ.target4 = "";
}
}
if (targ.health <= 0) {
targ.deathtype = dmgtype;
Killed(targ, attacker, inflictor);
return;
}
// react to the damage
oldself = self;
self = targ;
if ( (self.flags & FL_MONSTER) && attacker != world && !(attacker.flags & FL_IGNOREDATTACK)) {
// get mad unless of the same class (except for soldiers)
if (self != attacker && attacker != SUB_entEnemyTarget() )
{
if (
(self.classname != attacker.classname || self.classname == "monster_army") &&
!(attacker.flags & FL_MONSTER && self.spawnflags & MONSTER_NOINFIGHT)
) {
if (SUB_entEnemyTarget().classname == "player")
self.oldenemy = SUB_entEnemyTarget();
if (self.enemy.type == "enemytarget") SUB_switchEnemyTarget();
self.enemy = attacker;
FoundTarget();
}
}
}
if (self.flags & FL_CLIENT) {
player_pain(attacker, take, dmgtype);
}
else if (self.th_pain) {
self.th_pain (attacker, take);
// nightmare mode monsters don't go into pain frames often
if (startskill == 3 && self.flags & FL_MONSTER)
self.pain_finished = time + 5;
}
if (dmgtype == DMGTYPE_BURN_LONG && self.flags & FL_CLIENT)
StartBurning(self, attacker, 5*startskill + 4 + 2*random());
self = oldself;
};
/*
============
T_EELZap
============
*/
void(entity inflictor, entity attacker, float damage) T_EELZap =
{
local float points;
local float radius;
local entity head, next;
local vector org;
local vector dir;
radius = damage + 128;
head = findradius(inflictor.origin, radius);
while (head)
{
next = head.chain;
if (head.takedamage)
{
org = head.origin + (head.mins + head.maxs)*0.5;
points = damage - (vlen(inflictor.origin - org) * damage / radius);
/*
points = 0.5*vlen (inflictor.origin - org);
if (points < 0)
points = 0;
points = damage - points;
if (head == attacker)
points = points * 0.5;
*/
if (points > 0)
{
if (CanDamage (head, inflictor.origin))
{ // eels take no damage from this attack
if (head.classname != "monster_eel" &&
(head.flags & FL_INWATER))
{
dir = org - inflictor.origin;
dir = normalize (dir);
traceline (inflictor.origin, inflictor.origin + dir*radius, TRUE, self);
fx_beam(inflictor.origin, trace_endpos, self);
T_Damage(head, inflictor, attacker, points, DMGTYPE_ENERGY);
}
}
}
}
head = next;
}
};
/*
============
T_RadiusDamage
============
*/
void(entity inflictor, entity attacker, float damage, float radiusscale, entity ignore, float dmgtype) T_RadiusDamage =
{
if (dmgtype == DMGTYPE_EXPLOSION) T_GibDownedZombies(inflictor, attacker, damage+10);
local float points;
local entity head, next;
local vector org;
head = findradius(inflictor.origin, (damage+40)*radiusscale);
while (head)
{
next = head.chain;
if (head != ignore)
{
if (head.takedamage)
{
org = head.origin + (head.mins + head.maxs)*0.5; // target's origin is its geometrical center
points = (0.5 * vlen(inflictor.origin - org)) / radiusscale;
if (points < 0)
points = 0;
points = damage - points;
if (head == attacker)
points = points * 0.5;
//johnfitz -- make floyd death less dangerous without shrinking the range of it
/*
if (attacker.classname == "monster_floyd")
points = points * 0.5;
else if (attacker.classname == "monster_drone")
points = points * 0.625;
*/
//johnfitz
if (points > 0)
{
if (CanDamage (head, inflictor.origin)) {
T_Damage(head, inflictor, attacker, points, dmgtype);
}
}
}
}
head = next;
}
};
// adapted from Copper
void(entity inflictor, entity attacker, float rad) T_GibDownedZombies = {
if (rad < 72) return; // not a big enough blast
entity head;
head = findradiusplus(inflictor.origin + '0 0 16', rad, type, "downedzombie");
// look a little too high since we'll assume zombies are lower than their
// actual origin, which is 24u off the ground
while (head) {
if (head.solid == SOLID_NOT && // can't be hurt otherwise
CanDamage(head, inflictor.origin) && // in sight
rad - vlen(head.origin - inflictor.origin) > 0.5 * head.health // close enough to hurt
) {
T_Damage(head, inflictor, attacker, head.health + 10, DMGTYPE_EXPLOSION);
}
head = head.chain;
}
};
/*
Unused?
============
T_BeamDamage
============
*/
/*
void(entity attacker, float damage) T_BeamDamage =
{
local float points;
local entity head;
head = findradius(attacker.origin, damage+40);
while (head)
{
if (head.takedamage)
{
points = 0.5*vlen (attacker.origin - head.origin);
if (points < 0)
points = 0;
points = damage - points;
if (head == attacker)
points = points * 0.5;
if (points > 0)
{
if (CanDamage (head, attacker.origin))
{
if (head.classname == "monster_shambler")
T_Damage(head, attacker, attacker, points*0.5);
else
T_Damage(head, attacker, attacker, points);
}
}
}
head = head.chain;
}
};
*/