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