]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/g_damage.c
fix a bug with firstblood not playing except in minstagib (the
[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         // midair gamemode: damage only while in the air
298         if (cvar("g_midair")
299             && self.classname == "player" // e.g. grenades take damage
300             && self.flags & FL_ONGROUND) {
301                 damage = 0;
302         }
303
304         // apply strength multiplier
305         if (attacker.items & IT_STRENGTH && !cvar("g_minstagib"))
306         {
307                 damage = damage * cvar("g_balance_powerup_strength_damage");
308                 force = force * cvar("g_balance_powerup_strength_force");
309         }
310         // apply invincibility multiplier
311         if (targ.items & IT_INVINCIBLE && !cvar("g_minstagib"))
312                 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
313
314
315         if(cvar("g_runematch"))
316         {
317                 // apply strength rune
318                 if (attacker.runes & RUNE_STRENGTH)
319                 {
320                         if(attacker.runes & CURSE_WEAK) // have both curse & rune
321                         {
322                                 damage = damage * cvar("g_balance_rune_strength_combo_damage");
323                                 force = force * cvar("g_balance_rune_strength_combo_force");
324                         }
325                         else
326                         {
327                                 damage = damage * cvar("g_balance_rune_strength_damage");
328                                 force = force * cvar("g_balance_rune_strength_force");
329                         }
330                 }
331                 else if (attacker.runes & CURSE_WEAK)
332                 {
333                         damage = damage * cvar("g_balance_curse_weak_damage");
334                         force = force * cvar("g_balance_curse_weak_force");
335                 }
336
337                 // apply defense rune
338                 if (targ.runes & RUNE_DEFENSE)
339                 {
340                         if (targ.runes & CURSE_VULNER) // have both curse & rune
341                                 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
342                         else
343                                 damage = damage * cvar("g_balance_rune_defense_takedamage");
344                 }
345                 else if (targ.runes & CURSE_VULNER)
346                         damage = damage * cvar("g_balance_curse_vulner_takedamage");
347         }
348
349         // apply push
350         if (self.damageforcescale)
351         {
352                 self.velocity = self.velocity + self.damageforcescale * force;
353                 self.flags = self.flags - (self.flags & FL_ONGROUND);
354         }
355         // apply damage
356         if (self.event_damage)
357                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
358         self = oldself;
359
360         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
361         {
362                 // Savage: vampire mode
363                 if(cvar("g_vampire") && !cvar("g_minstagib"))
364                 {
365                         attacker.health += damage;
366                 }
367                 if(cvar("g_runematch"))
368                 {
369                         if (attacker.runes & RUNE_VAMPIRE)
370                         {
371                         // apply vampire rune
372                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
373                                 {
374                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
375                                         attacker.health = bound(
376                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
377                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
378                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
379                                 }
380                                 else
381                                 {
382                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
383                                         attacker.health = bound(
384                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
385                                                                                         // empathy won't let you gain health in the same way...
386                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
387                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
388                                         }
389                         }
390                         // apply empathy curse
391                         else if (attacker.runes & CURSE_EMPATHY)
392                         {
393                                 attacker.health = bound(
394                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
395                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
396                                         attacker.health);
397                         }
398                 }
399         }
400 }
401
402 void RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
403 {
404         entity  targ;
405         float   finaldmg;
406         float   power;
407         vector  blastorigin;
408         vector  force;
409         vector  m1;
410         vector  m2;
411         vector  nearest;
412         vector  diff;
413
414         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
415
416         targ = findradius (blastorigin, rad);
417         while (targ)
418         {
419                 if (targ != inflictor)
420                         if (ignore != targ)
421                         {
422                                 // LordHavoc: measure distance to nearest point on target (not origin)
423                                 // (this guarentees 100% damage on a touch impact)
424                                 nearest = blastorigin;
425                                 m1 = targ.origin + targ.mins;
426                                 m2 = targ.origin + targ.maxs;
427                                 if (nearest_x < m1_x) nearest_x = m1_x;
428                                 if (nearest_y < m1_y) nearest_y = m1_y;
429                                 if (nearest_z < m1_z) nearest_z = m1_z;
430                                 if (nearest_x > m2_x) nearest_x = m2_x;
431                                 if (nearest_y > m2_y) nearest_y = m2_y;
432                                 if (nearest_z > m2_z) nearest_z = m2_z;
433                                 diff = nearest - blastorigin;
434                                 // round up a little on the damage to ensure full damage on impacts
435                                 // and turn the distance into a fraction of the radius
436                                 power = 1 - ((vlen (diff) - 2) / rad);
437                                 //bprint(" ");
438                                 //bprint(ftos(power));
439                                 if (power > 0)
440                                 {
441                                         if (power > 1)
442                                                 power = 1;
443                                         finaldmg = coredamage * power + edgedamage * (1 - power);
444                                         if (finaldmg > 0)
445                                         {
446                                                 force = normalize((m1 + m2) * 0.5 - blastorigin) * (finaldmg / coredamage) * forceintensity;
447                                                 if (targ == attacker)
448                                                         finaldmg = finaldmg * cvar("g_balance_selfdamagepercent");      // Partial damage if the attacker hits himself
449                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, inflictor.origin, force);
450                                         }
451                                 }
452                         }
453                 targ = targ.chain;
454         }
455 }
456
457 /*
458 entity  multi_ent;
459 float   multi_damage;
460 vector  multi_force;
461
462 void ClearMultiDamage (void)
463 {
464         multi_ent = world;
465         multi_damage = 0;
466         multi_force = '0 0 0';
467 }
468
469 void ApplyMultiDamage (void)
470 {
471         if (!multi_ent)
472                 return;
473
474         Damage (self, multi_ent.origin, multi_ent, 0, multi_damage, multi_force);
475 }
476
477 void AddMultiDamage (entity hit, float damage, vector force)
478 {
479         if (!hit)
480                 return;
481
482         if (hit != multi_ent)
483         {
484                 ApplyMultiDamage ();
485                 ClearMultiDamage ();
486                 multi_ent = hit;
487         }
488         multi_damage = multi_damage + damage;
489         multi_force = multi_force + force;
490 }
491
492 void FireBullets (float shotcount, vector dir, vector spread, float deathtype)
493 {
494         vector  direction;
495         vector  source;
496         vector  vel;
497         vector  org;
498
499         makevectors (self.v_angle);
500
501         source = self.origin + v_forward * 10;  // FIXME
502         source_x = self.absmin_z + self.size_z * 0.7;   // ??? whaddabout view_ofs
503
504         // LordHavoc: better to use normal damage
505         //ClearMultiDamage ();
506         while (shotcount > 0)
507         {
508                 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
509
510                 traceline (source, source + direction * 2048, FALSE, self);
511                 if (trace_fraction != 1.0)
512                 {
513                         vel = normalize (direction + v_up * crandom () + v_right * crandom ());
514                         vel = vel + 2 * trace_plane_normal;
515                         vel = vel * 200;
516
517                         org = trace_endpos - direction * 4;
518
519                         if (!trace_ent.takedamage)
520                                 te_gunshot (org);
521                         // LordHavoc: better to use normal damage
522                         //AddMultiDamage (trace_ent, 4, direction * 4);
523                         Damage (trace_ent, self, self, 4, deathtype, trace_endpos, direction * 4);
524                 }
525
526                 shotcount = shotcount + 1;
527         }
528
529         // LordHavoc: better to use normal damage
530         //ApplyMultiDamage ();
531 }
532 */
533
534
535