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