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