]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/g_damage.c
added .float spawnshieldtime which is used to grant temporary
[divverent/nexuiz.git] / data / qcsrc / server / gamec / g_damage.c
1
2 float checkrules_firstblood;
3
4 void GiveFrags (entity attacker, entity targ, float f)
5 {
6
7         if(gameover) return;
8
9         if(f > 0 && cvar("g_domination") && cvar("g_domination_disable_frags"))
10                 return;
11         else if(f > 0 && cvar("g_runematch"))
12                 f = RunematchHandleFrags(attacker, targ, f);
13         else if(cvar("g_lms"))
14         {
15                 // count remaining lives, not frags in lms
16                 targ.frags -= 1;
17                 // keep track of the worst players lives
18                 if(targ.frags < lms_lowest_lives)
19                         lms_lowest_lives = targ.frags;
20                 // player has no more lives left
21                 if (!targ.frags)
22                         lms_dead_count += 1;
23                 return;
24         }
25
26         if(f)
27                 attacker.frags = attacker.frags + f;
28 }
29
30 void Obituary (entity attacker, entity targ, float deathtype)
31 {
32         string  s, m;
33
34         if (targ.classname == "player" || targ.classname == "corpse")
35         {
36                 if (targ.classname == "corpse")
37                         s = "A corpse";
38                 else
39                         s = targ.netname;
40
41                 if (targ == attacker)
42                 {
43                         if (deathtype == DEATH_NOAMMO)
44                                 centerprint(targ, strcat("^1You were killed for running out of ammo...\n\n\n"));
45                         if (deathtype == DEATH_TEAMCHANGE)
46                         {
47                                 m = "You are now on: ";
48                                 if (targ.team == 5)
49                                         m = strcat(m, "^1Red Team");
50                                 else if (targ.team == 14)
51                                         m = strcat(m, "^4Blue Team");
52                                 else if (targ.team == 10)
53                                         m = strcat(m, "^6Pink Team");
54                                 else if (targ.team == 13)
55                                         m = strcat(m, "^3Yellow Team");
56                                 centerprint(targ, m);
57                         }
58                         else if (deathtype == DEATH_AUTOTEAMCHANGE)
59                         {
60                                 m = "You have been moved into a different team to improve team balance\nYou are now on: ";
61                                 if (targ.team == 5)
62                                         m = strcat(m, "^1Red Team");
63                                 else if (targ.team == 14)
64                                         m = strcat(m, "^4Blue Team");
65                                 else if (targ.team == 10)
66                                         m = strcat(m, "^6Pink Team");
67                                 else if (targ.team == 13)
68                                         m = strcat(m, "^3Yellow Team");
69                                 centerprint(targ, m);
70                                 return;
71                         }
72                         else
73                                 centerprint(targ, strcat("^1You killed your own dumb self!\n\n\n"));
74
75                         if (deathtype == IT_GRENADE_LAUNCHER)
76                                 bprint ("^1",s, "^1 detonated\n");
77                         else if (deathtype == IT_ELECTRO)
78                                 bprint ("^1",s, "^1 played with plasma\n");
79                         else if (deathtype == IT_ROCKET_LAUNCHER)
80                                 bprint ("^1",s, "^1 exploded\n");
81                         else if (deathtype == DEATH_KILL)
82                                 bprint ("^1",s, "^1 couldn't take it anymore\n");
83                         else if (deathtype == DEATH_NOAMMO)
84                         {
85                                 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
86                                 //sound (self, CHAN_BODY, "minstagib/mockery.ogg", 1, ATTN_NONE);
87                         }
88                         else if (deathtype != DEATH_TEAMCHANGE)
89                                 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
90                         GiveFrags(attacker, targ, -1);
91                         //targ.frags = targ.frags - 1;
92                         if (targ.killcount > 2)
93                                 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
94                 }
95                 else if (teamplay && attacker.team == targ.team)
96                 {
97                         centerprint(attacker, strcat("^1Moron! You fragged a teammate!\n\n\n"));
98                         bprint ("^1", attacker.netname, "^1 mows down a teammate\n");
99                         GiveFrags(attacker, targ, -1);
100                         //attacker.frags = attacker.frags - 1;
101                         if (targ.killcount > 2)
102                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was endeded by a teammate!\n");
103                         if (attacker.killcount > 2)
104                                 bprint ("^1",attacker.netname,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
105                         attacker.killcount = 0;
106                 }
107                 else if (attacker.classname == "player" || attacker.classname == "gib")
108                 {
109                         if (!checkrules_firstblood)
110                         {
111                                 checkrules_firstblood = TRUE;
112                                 //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
113                                 //if (cvar("g_minstagib"))
114                                         //sound(world, CHAN_AUTO, "announce/male/mapkill1.ogg", 1, ATTN_NONE);
115                                 bprint("^1",attacker.netname, "^1 drew first blood", "\n");
116                         }
117
118                         centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
119                         centerprint(targ, strcat("^1You were fragged by ^7", attacker.netname, "\n\n\n"));
120
121                         if (deathtype == IT_LASER)
122                                 bprint ("^1",s, "^1 was blasted by ", attacker.netname, "\n");
123                         else if (deathtype == IT_UZI)
124                                 bprint ("^1",s, "^1 was riddled full of holes by ", attacker.netname, "\n");
125                         else if (deathtype == IT_SHOTGUN)
126                                 bprint ("^1",s, "^1 was gunned by ", attacker.netname, "\n");
127                         else if (deathtype == IT_GRENADE_LAUNCHER)
128                                 bprint ("^1", s, "^1 was blasted by ", attacker.netname, "\n");
129                         else if (deathtype == IT_ELECTRO)
130                                 bprint ("^1",s, "^1 was blasted by ", attacker.netname, "\n");
131                         else if (deathtype == IT_CRYLINK)
132                                 bprint ("^1",s, "^1 was blasted by ", attacker.netname, "\n");
133                         else if (deathtype == IT_NEX)
134                                 bprint ("^1",s, "^1 has been vaporized by ", attacker.netname, "\n");
135                         else if (deathtype == IT_HAGAR)
136                                 bprint ("^1",s, "^1 was pummeled by ", attacker.netname, "\n");
137                         else if (deathtype == IT_ROCKET_LAUNCHER)
138                                 bprint ("^1",s, "^1 was blasted by ", attacker.netname, "\n");
139                         else if (deathtype == DEATH_TELEFRAG)
140                                 bprint ("^1",s, "^1 was telefragged by ", attacker.netname, "\n");
141                         else if (deathtype == DEATH_DROWN)
142                                 bprint ("^1",s, "^1 was drowned by ", attacker.netname, "\n");
143                         else if (deathtype == DEATH_SLIME)
144                                 bprint ("^1",s, "^1 was slimed by ", attacker.netname, "\n");
145                         else if (deathtype == DEATH_LAVA)
146                                 bprint ("^1",s, "^1 was cooked by ", attacker.netname, "\n");
147                         else if (deathtype == DEATH_FALL)
148                                 bprint ("^1",s, "^1 was grounded by ", attacker.netname, "\n");
149                         else if (deathtype == DEATH_SWAMP)
150                                 bprint ("^1",s, "^1 was conserved by ", attacker.netname, "\n");
151                         else if (deathtype == DEATH_HURTTRIGGER)
152                                 bprint ("^1",s, "^1 was thrown into a world of hurt by ", attacker.netname, "\n");
153                         else
154                                 bprint ("^1",s, "^1 was fragged by ", attacker.netname, "\n");
155
156                         GiveFrags(attacker, targ, 1);
157                         //attacker.frags = attacker.frags + 1;
158                         if (targ.killcount > 2)
159                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", attacker.netname, "\n");
160                         attacker.killcount = attacker.killcount + 1;
161                         if (attacker.killcount > 2)
162                                 bprint ("^1",attacker.netname,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
163
164                         if (attacker.killcount == 3)
165                         {
166                                 bprint (attacker.netname,"^7 made a ^1TRIPLE FRAG\n");
167                                 stuffcmd(attacker, "play2 announcer/male/03kills.ogg\n");
168                         }
169                         else if (attacker.killcount == 5)
170                         {
171                                 bprint (attacker.netname,"^7 made a ^1FIVE FRAG COMBO\n");
172                                 stuffcmd(attacker, "play2 announcer/male/05kills.ogg\n");
173                         }
174                         else if (attacker.killcount == 10)
175                         {
176                                 bprint (attacker.netname,"^7 is on a ^1RAGE\n");
177                                 stuffcmd(attacker, "play2 announcer/male/10kills.ogg\n");
178                         }
179                         else if (attacker.killcount == 15)
180                         {
181                                 bprint (attacker.netname,"^7 has done a ^1MASSACRE!\n");
182                                 stuffcmd(attacker, "play2 announcer/male/15kills.ogg\n");
183                         }
184                         else if (attacker.killcount == 20)
185                         {
186                                 bprint (attacker.netname,"^7 is ^1UNHUMAN!\n");
187                                 stuffcmd(attacker, "play2 announcer/male/20kills.ogg\n");
188                         }
189                         else if (attacker.killcount == 25)
190                         {
191                                 bprint (attacker.netname,"^7 is a ^1DEATH INCARNATION!\n");
192                                 stuffcmd(attacker, "play2 announcer/male/25kills.ogg\n");
193                         }
194                         else if (attacker.killcount == 30)
195                         {
196                                 bprint (attacker.netname,"^7 is maybe a ^1AIMBOTTER?!\n");
197                                 stuffcmd(attacker, "play2 announcer/male/30kills.ogg\n");
198                         }
199                 }
200                 else
201                 {
202                         centerprint(targ, strcat("^1Watch your step!\n\n\n"));
203                         if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
204                                 bprint ("^1",s, "^1 ", attacker.message, "\n");
205                         else if (deathtype == DEATH_DROWN)
206                                 bprint ("^1",s, "^1 drowned\n");
207                         else if (deathtype == DEATH_SLIME)
208                                 bprint ("^1",s, "^1 was slimed\n");
209                         else if (deathtype == DEATH_LAVA)
210                                 bprint ("^1",s, "^1 turned into hot slag\n");
211                         else if (deathtype == DEATH_FALL)
212                                 bprint ("^1",s, "^1 hit the ground with a crunch\n");
213                         else if (deathtype == DEATH_SWAMP)
214                                 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
215                         else
216                                 bprint ("^1",s, "^1 died\n");
217                         GiveFrags(targ, targ, -1);
218                         if(targ.frags == -5) {
219                                 stuffcmd(targ, "play2 announcer/male/botlike.ogg\n");
220                         }
221
222                         //targ.frags = targ.frags - 1;
223                         if (targ.killcount > 2)
224                                 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
225                 }
226                 // FIXME: this should go in PutClientInServer
227                 if (targ.killcount)
228                         targ.killcount = 0;
229         }
230 }
231
232 // these are updated by each Damage call for use in button triggering and such
233 entity damage_targ;
234 entity damage_inflictor;
235 entity damage_attacker;
236
237 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
238 {
239         if (gameover || targ.killcount == -666)
240                 return;
241
242         local entity oldself;
243         oldself = self;
244         self = targ;
245         damage_targ = targ;
246         damage_inflictor = inflictor;
247         damage_attacker = attacker;
248         // nullify damage if teamplay is on
249         if (teamplay)
250         if (attacker.team)
251         if (attacker.team == targ.team)
252         if ((teamplay == 1 || teamplay == 3) && attacker != targ)
253                 damage = 0;
254
255         if(damage > 0 && targ != attacker && clienttype(attacker) == CLIENTTYPE_REAL && targ.classname == "player")
256                 stuffcmd(attacker, "play2 misc/hit.wav\n");
257
258         if (cvar("g_minstagib"))
259         {
260                 if ((deathtype == DEATH_FALL)  ||
261                     (deathtype == DEATH_DROWN) ||
262                     (deathtype == DEATH_SLIME) ||
263                     (deathtype == DEATH_LAVA))
264                         return;
265                 if (targ.extralives && (deathtype == IT_NEX) && damage)
266                 {
267                         targ.extralives -= 1;
268                         centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.extralives),"\n"));
269                         damage = 0;
270                         targ.armorvalue = targ.extralives;
271                         if(clienttype(targ) == CLIENTTYPE_REAL) stuffcmd(targ, "play2 misc/hit.wav\n");
272                         //stuffcmd(attacker, "play2 misc/hit.wav\n");
273                 }
274                 else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
275                 {
276                         if(clienttype(attacker) == CLIENTTYPE_REAL) stuffcmd(attacker, "play2 announcer/male/yoda.ogg\n");
277                 }
278                 if (deathtype == IT_LASER)
279                 {
280                         damage = 0;
281                         if (targ != attacker)
282                         {
283                                 if (targ.classname == "player")
284                                         centerprint(attacker, "Secondary fire inflicts no damage!\n");
285                                 damage = 0;
286                                 force = '0 0 0';
287                                 attacker = targ;
288                         }
289                 }
290         } else {
291                 if (deathtype == IT_NEX && !(attacker.flags & FL_ONGROUND) && !(targ.flags & FL_ONGROUND) && attacker.waterlevel < 2 && targ.waterlevel < 2 && attacker.killcount != 3 && attacker.killcount != 5 && attacker.killcount != 10 && attacker.killcount != 15 && attacker.killcount != 20 && attacker.killcount != 25 && attacker.killcount != 30)
292                 {
293                         if(clienttype(attacker) == CLIENTTYPE_REAL)  stuffcmd(attacker, "play2 announcer/male/yoda.ogg\n");
294                 }
295         }
296
297         // apply strength multiplier
298         if (attacker.items & IT_STRENGTH && !cvar("g_minstagib"))
299         {
300                 damage = damage * cvar("g_balance_powerup_strength_damage");
301                 force = force * cvar("g_balance_powerup_strength_force");
302         }
303         // apply invincibility multiplier
304         if (targ.items & IT_INVINCIBLE && !cvar("g_minstagib"))
305                 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
306
307
308         if(cvar("g_runematch"))
309         {
310                 // apply strength rune
311                 if (attacker.runes & RUNE_STRENGTH)
312                 {
313                         if(attacker.runes & CURSE_WEAK) // have both curse & rune
314                         {
315                                 damage = damage * cvar("g_balance_rune_strength_combo_damage");
316                                 force = force * cvar("g_balance_rune_strength_combo_force");
317                         }
318                         else
319                         {
320                                 damage = damage * cvar("g_balance_rune_strength_damage");
321                                 force = force * cvar("g_balance_rune_strength_force");
322                         }
323                 }
324                 else if (attacker.runes & CURSE_WEAK)
325                 {
326                         damage = damage * cvar("g_balance_curse_weak_damage");
327                         force = force * cvar("g_balance_curse_weak_force");
328                 }
329
330                 // apply defense rune
331                 if (targ.runes & RUNE_DEFENSE)
332                 {
333                         if (targ.runes & CURSE_VULNER) // have both curse & rune
334                                 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
335                         else
336                                 damage = damage * cvar("g_balance_rune_defense_takedamage");
337                 }
338                 else if (targ.runes & CURSE_VULNER)
339                         damage = damage * cvar("g_balance_curse_vulner_takedamage");
340         }
341
342         // apply push
343         if (self.damageforcescale)
344         {
345                 self.velocity = self.velocity + self.damageforcescale * force;
346                 self.flags = self.flags - (self.flags & FL_ONGROUND);
347         }
348         // apply damage
349         if (self.event_damage)
350                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
351         self = oldself;
352
353         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
354         {
355                 // Savage: vampire mode
356                 if(cvar("g_vampire") && !cvar("g_minstagib"))
357                 {
358                         attacker.health += damage;
359                 }
360                 if(cvar("g_runematch"))
361                 {
362                         if (attacker.runes & RUNE_VAMPIRE)
363                         {
364                         // apply vampire rune
365                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
366                                 {
367                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
368                                         attacker.health = bound(
369                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
370                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
371                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
372                                 }
373                                 else
374                                 {
375                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
376                                         attacker.health = bound(
377                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
378                                                                                         // empathy won't let you gain health in the same way...
379                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
380                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
381                                         }
382                         }
383                         // apply empathy curse
384                         else if (attacker.runes & CURSE_EMPATHY)
385                         {
386                                 attacker.health = bound(
387                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
388                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
389                                         attacker.health);
390                         }
391                 }
392         }
393 }
394
395 void RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
396 {
397         entity  targ;
398         float   finaldmg;
399         float   power;
400         vector  blastorigin;
401         vector  force;
402         vector  m1;
403         vector  m2;
404         vector  nearest;
405         vector  diff;
406
407         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
408
409         targ = findradius (blastorigin, rad);
410         while (targ)
411         {
412                 if (targ != inflictor)
413                         if (ignore != targ)
414                         {
415                                 // LordHavoc: measure distance to nearest point on target (not origin)
416                                 // (this guarentees 100% damage on a touch impact)
417                                 nearest = blastorigin;
418                                 m1 = targ.origin + targ.mins;
419                                 m2 = targ.origin + targ.maxs;
420                                 if (nearest_x < m1_x) nearest_x = m1_x;
421                                 if (nearest_y < m1_y) nearest_y = m1_y;
422                                 if (nearest_z < m1_z) nearest_z = m1_z;
423                                 if (nearest_x > m2_x) nearest_x = m2_x;
424                                 if (nearest_y > m2_y) nearest_y = m2_y;
425                                 if (nearest_z > m2_z) nearest_z = m2_z;
426                                 diff = nearest - blastorigin;
427                                 // round up a little on the damage to ensure full damage on impacts
428                                 // and turn the distance into a fraction of the radius
429                                 power = 1 - ((vlen (diff) - 2) / rad);
430                                 //bprint(" ");
431                                 //bprint(ftos(power));
432                                 if (power > 0)
433                                 {
434                                         if (power > 1)
435                                                 power = 1;
436                                         finaldmg = coredamage * power + edgedamage * (1 - power);
437                                         if (finaldmg > 0)
438                                         {
439                                                 force = normalize((m1 + m2) * 0.5 - blastorigin) * (finaldmg / coredamage) * forceintensity;
440                                                 if (targ == attacker)
441                                                         finaldmg = finaldmg * cvar("g_balance_selfdamagepercent");      // Partial damage if the attacker hits himself
442                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, inflictor.origin, force);
443                                         }
444                                 }
445                         }
446                 targ = targ.chain;
447         }
448 }
449
450 /*
451 entity  multi_ent;
452 float   multi_damage;
453 vector  multi_force;
454
455 void ClearMultiDamage (void)
456 {
457         multi_ent = world;
458         multi_damage = 0;
459         multi_force = '0 0 0';
460 }
461
462 void ApplyMultiDamage (void)
463 {
464         if (!multi_ent)
465                 return;
466
467         Damage (self, multi_ent.origin, multi_ent, 0, multi_damage, multi_force);
468 }
469
470 void AddMultiDamage (entity hit, float damage, vector force)
471 {
472         if (!hit)
473                 return;
474
475         if (hit != multi_ent)
476         {
477                 ApplyMultiDamage ();
478                 ClearMultiDamage ();
479                 multi_ent = hit;
480         }
481         multi_damage = multi_damage + damage;
482         multi_force = multi_force + force;
483 }
484
485 void FireBullets (float shotcount, vector dir, vector spread, float deathtype)
486 {
487         vector  direction;
488         vector  source;
489         vector  vel;
490         vector  org;
491
492         makevectors (self.v_angle);
493
494         source = self.origin + v_forward * 10;  // FIXME
495         source_x = self.absmin_z + self.size_z * 0.7;   // ??? whaddabout view_ofs
496
497         // LordHavoc: better to use normal damage
498         //ClearMultiDamage ();
499         while (shotcount > 0)
500         {
501                 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
502
503                 traceline (source, source + direction * 2048, FALSE, self);
504                 if (trace_fraction != 1.0)
505                 {
506                         vel = normalize (direction + v_up * crandom () + v_right * crandom ());
507                         vel = vel + 2 * trace_plane_normal;
508                         vel = vel * 200;
509
510                         org = trace_endpos - direction * 4;
511
512                         if (!trace_ent.takedamage)
513                                 te_gunshot (org);
514                         // LordHavoc: better to use normal damage
515                         //AddMultiDamage (trace_ent, 4, direction * 4);
516                         Damage (trace_ent, self, self, 4, deathtype, trace_endpos, direction * 4);
517                 }
518
519                 shotcount = shotcount + 1;
520         }
521
522         // LordHavoc: better to use normal damage
523         //ApplyMultiDamage ();
524 }
525 */
526
527
528