]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/g_damage.qc
removed .extralives
[divverent/nexuiz.git] / data / qcsrc / server / g_damage.qc
1
2 float checkrules_firstblood;
3
4 void GiveFrags (entity attacker, entity targ, float f)
5 {
6         if(gameover) return;
7
8         if(cvar("g_arena"))
9                 if(cvar("g_arena_roundbased"))
10                         return;
11
12         if(cvar("g_domination"))
13         {
14                 if(cvar("g_domination_disable_frags"))
15                         if(f > 0)
16                                 return;
17         }
18         else if(cvar("g_runematch"))
19         {
20                 if(f > 0)
21                         f = RunematchHandleFrags(attacker, targ, f);
22         }
23         else if(cvar("g_lms"))
24         {
25                 // count remaining lives, not frags in lms
26                 targ.frags -= 1;
27                 // keep track of the worst players lives
28                 if(targ.frags < lms_lowest_lives)
29                         lms_lowest_lives = targ.frags;
30                 // player has no more lives left
31                 if (!targ.frags)
32                 {
33                         lms_dead_count += 1;
34                         if(!lms_next_place)
35                                 lms_next_place = player_count;
36                         targ.frags = -lms_next_place;
37                         lms_next_place -= 1;
38                 }
39                 return;
40         }
41
42         if(f)
43                 attacker.frags = attacker.frags + f;
44 }
45
46 string AppendItemcodes(string s, entity player)
47 {
48         float w;
49         w = player.weapon;
50         //if(w == 0)
51         //      w = player.switchweapon;
52         if(w == 0)
53                 w = player.cnt; // previous weapon!
54         s = strcat(s, ftos(W_ItemCode(w)));
55         if(time < player.strength_finished)
56                 s = strcat(s, "S");
57         if(time < player.invincible_finished)
58                 s = strcat(s, "I");
59         if(player.flagcarried != world)
60                 s = strcat(s, "F");
61         if(player.runes)
62                 s = strcat(s, "|", ftos(player.runes));
63         return s;
64 }
65
66 void LogDeath(string mode, float deathtype, entity killer, entity killed)
67 {
68         string s;
69         if(!cvar("sv_eventlog"))
70                 return;
71         s = strcat(":kill:", mode);
72         s = strcat(s, ":", ftos(killer.playerid));
73         s = strcat(s, ":", ftos(killed.playerid));
74         s = strcat(s, ":type=", ftos(deathtype));
75         s = strcat(s, ":items=");
76         s = AppendItemcodes(s, killer);
77         if(killed != killer)
78         {
79                 s = strcat(s, ":victimitems=");
80                 s = AppendItemcodes(s, killed);
81         }
82         GameLogEcho(s, FALSE);
83 }
84
85 void Obituary (entity attacker, entity targ, float deathtype)
86 {
87         string  s, m;
88
89         if (targ.classname == "player" || targ.classname == "corpse")
90         {
91                 if (targ.classname == "corpse")
92                         s = "A corpse";
93                 else
94                         s = targ.netname;
95
96                 if (targ == attacker)
97                 {
98                         if (deathtype == DEATH_TEAMCHANGE)
99                         {
100                                 m = "You are now on: ";
101                                 if (targ.team == 5)
102                                         m = strcat(m, "^1Red Team");
103                                 else if (targ.team == 14)
104                                         m = strcat(m, "^4Blue Team");
105                                 else if (targ.team == 10)
106                                         m = strcat(m, "^6Pink Team");
107                                 else if (targ.team == 13)
108                                         m = strcat(m, "^3Yellow Team");
109                                 centermsg_setfor(targ, CENTERMSG_TEAMCHANGE, m);
110                         }
111                         else if (deathtype == DEATH_AUTOTEAMCHANGE)
112                         {
113                                 centermsg_setfor(targ, CENTERMSG_TEAMCHANGE, "You have been moved into a different team to improve team balance");
114                                 m = "You are now on: ";
115                                 if (targ.team == 5)
116                                         m = strcat(m, "^1Red Team");
117                                 else if (targ.team == 14)
118                                         m = strcat(m, "^4Blue Team");
119                                 else if (targ.team == 10)
120                                         m = strcat(m, "^6Pink Team");
121                                 else if (targ.team == 13)
122                                         m = strcat(m, "^3Yellow Team");
123                                 centermsg_setfor(targ, CENTERMSG_TEAMCHANGE2, m);
124                                 return;
125                         }
126                         else if (deathtype == DEATH_CAMP)
127                                 centermsg_setfor(targ, CENTERMSG_DEATH, "^1Die camper!");
128                         else if (deathtype == DEATH_NOAMMO)
129                                 centermsg_setfor(targ, CENTERMSG_DEATH, "^1You were killed for running out of ammo...");
130                         else if (deathtype == DEATH_ROT)
131                                 centermsg_setfor(targ, CENTERMSG_DEATH, "^1You grew too old without taking your medcine");
132                         else if (deathtype == DEATH_MIRRORDAMAGE)
133                                 centermsg_setfor(targ, CENTERMSG_DEATH, "^1Don't shoot your team mates!");
134                         else
135                                 centermsg_setfor(targ, CENTERMSG_DEATH, "^1You killed your own dumb self!");
136
137                         if (deathtype == IT_GRENADE_LAUNCHER)
138                                 bprint ("^1",s, "^1 detonated\n");
139                         else if (deathtype == IT_ELECTRO)
140                                 bprint ("^1",s, "^1 played with plasma\n");
141                         else if (deathtype == IT_ROCKET_LAUNCHER)
142                                 bprint ("^1",s, "^1 exploded\n");
143                         else if (deathtype == DEATH_KILL)
144                                 bprint ("^1",s, "^1 couldn't take it anymore\n");
145                         else if (deathtype == DEATH_ROT)
146                                 bprint ("^1",s, "^1 died\n");
147                         else if (deathtype == DEATH_NOAMMO)
148                         {
149                                 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
150                                 //sound (self, CHAN_BODY, "minstagib/mockery.ogg", 1, ATTN_NONE);
151                         }
152                         else if (deathtype == DEATH_CAMP)
153                                 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
154                         else if (deathtype == DEATH_MIRRORDAMAGE)
155                                 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
156                         else if (deathtype != DEATH_TEAMCHANGE)
157                                 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
158
159                         if(deathtype != DEATH_TEAMCHANGE)
160                                 LogDeath("suicide", deathtype, targ, targ);
161
162                         GiveFrags(attacker, targ, -1);
163                         //targ.frags = targ.frags - 1;
164                         if (targ.killcount > 2)
165                                 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
166                 }
167                 else if (teamplay && attacker.team == targ.team)
168                 {
169                         centermsg_setfor(attacker, CENTERMSG_DEATH, "^1Moron! You fragged a teammate!");
170                         bprint ("^1", attacker.netname, "^1 mows down a teammate\n");
171                         GiveFrags(attacker, targ, -1);
172                         //attacker.frags = attacker.frags - 1;
173                         if (targ.killcount > 2)
174                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was endeded by a teammate!\n");
175                         if (attacker.killcount > 2)
176                                 bprint ("^1",attacker.netname,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
177                         attacker.killcount = 0;
178
179                         LogDeath("tk", deathtype, attacker, targ);
180                 }
181                 else if (attacker.classname == "player" || attacker.classname == "gib")
182                 {
183                         if (!checkrules_firstblood)
184                         {
185                                 checkrules_firstblood = TRUE;
186                                 //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
187                                 //if (cvar("g_minstagib"))
188                                         //sound(world, CHAN_AUTO, "announce/male/mapkill1.ogg", 1, ATTN_NONE);
189                                 bprint("^1",attacker.netname, "^1 drew first blood", "\n");
190                         }
191
192                         centermsg_setfor(attacker, CENTERMSG_KILL, strcat("^4You fragged ^7", s));
193                         centermsg_setfor(targ, CENTERMSG_DEATH, strcat("^1You were fragged by ^7", attacker.netname));
194
195                         if (deathtype == IT_LASER)
196                                 bprint ("^1",s, "^1 was blasted by ", attacker.netname, "\n");
197                         else if (deathtype == IT_UZI)
198                                 bprint ("^1",s, "^1 was riddled full of holes by ", attacker.netname, "\n");
199                         else if (deathtype == IT_SHOTGUN)
200                                 bprint ("^1",s, "^1 was gunned by ", attacker.netname, "\n");
201                         else if (deathtype == IT_GRENADE_LAUNCHER)
202                                 bprint ("^1", s, "^1 was blasted by ", attacker.netname, "\n");
203                         else if (deathtype == IT_ELECTRO)
204                                 bprint ("^1",s, "^1 was blasted by ", attacker.netname, "\n");
205                         else if (deathtype == IT_CRYLINK)
206                                 bprint ("^1",s, "^1 was blasted by ", attacker.netname, "\n");
207                         else if (deathtype == IT_NEX)
208                                 bprint ("^1",s, "^1 has been vaporized by ", attacker.netname, "\n");
209                         else if (deathtype == IT_HAGAR)
210                                 bprint ("^1",s, "^1 was pummeled by ", attacker.netname, "\n");
211                         else if (deathtype == IT_ROCKET_LAUNCHER)
212                                 bprint ("^1",s, "^1 was blasted by ", attacker.netname, "\n");
213                         else if (deathtype == DEATH_TELEFRAG)
214                                 bprint ("^1",s, "^1 was telefragged by ", attacker.netname, "\n");
215                         else if (deathtype == DEATH_DROWN)
216                                 bprint ("^1",s, "^1 was drowned by ", attacker.netname, "\n");
217                         else if (deathtype == DEATH_SLIME)
218                                 bprint ("^1",s, "^1 was slimed by ", attacker.netname, "\n");
219                         else if (deathtype == DEATH_LAVA)
220                                 bprint ("^1",s, "^1 was cooked by ", attacker.netname, "\n");
221                         else if (deathtype == DEATH_FALL)
222                                 bprint ("^1",s, "^1 was grounded by ", attacker.netname, "\n");
223                         else if (deathtype == DEATH_SHOOTING_STAR)
224                                 bprint ("^1",s, "^1 was shot into space by ", attacker.netname, "\n");
225                         else if (deathtype == DEATH_SWAMP)
226                                 bprint ("^1",s, "^1 was conserved by ", attacker.netname, "\n");
227                         else if (deathtype == DEATH_HURTTRIGGER)
228                                 bprint ("^1",s, "^1 was thrown into a world of hurt by ", attacker.netname, "\n");
229                         else
230                                 bprint ("^1",s, "^1 was fragged by ", attacker.netname, "\n");
231
232                         GiveFrags(attacker, targ, 1);
233                         //attacker.frags = attacker.frags + 1;
234                         if (targ.killcount > 2)
235                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", attacker.netname, "\n");
236                         attacker.killcount = attacker.killcount + 1;
237                         if (attacker.killcount > 2)
238                                 bprint ("^1",attacker.netname,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
239
240                         LogDeath("frag", deathtype, attacker, targ);
241
242                         if (attacker.killcount == 3)
243                         {
244                                 bprint (attacker.netname,"^7 made a ^1TRIPLE FRAG\n");
245                                 stuffcmd(attacker, "play2 announcer/male/03kills.ogg\n");
246                         }
247                         else if (attacker.killcount == 5)
248                         {
249                                 bprint (attacker.netname,"^7 made a ^1FIVE FRAG COMBO\n");
250                                 stuffcmd(attacker, "play2 announcer/male/05kills.ogg\n");
251                         }
252                         else if (attacker.killcount == 10)
253                         {
254                                 bprint (attacker.netname,"^7 is on a ^1RAGE\n");
255                                 stuffcmd(attacker, "play2 announcer/male/10kills.ogg\n");
256                         }
257                         else if (attacker.killcount == 15)
258                         {
259                                 bprint (attacker.netname,"^7 has done a ^1MASSACRE!\n");
260                                 stuffcmd(attacker, "play2 announcer/male/15kills.ogg\n");
261                         }
262                         else if (attacker.killcount == 20)
263                         {
264                                 bprint (attacker.netname,"^7 is ^1UNHUMAN!\n");
265                                 stuffcmd(attacker, "play2 announcer/male/20kills.ogg\n");
266                         }
267                         else if (attacker.killcount == 25)
268                         {
269                                 bprint (attacker.netname,"^7 is a ^1DEATH INCARNATION!\n");
270                                 stuffcmd(attacker, "play2 announcer/male/25kills.ogg\n");
271                         }
272                         else if (attacker.killcount == 30)
273                         {
274                                 bprint (attacker.netname,"^7 is maybe a ^1AIMBOTTER?!\n");
275                                 stuffcmd(attacker, "play2 announcer/male/30kills.ogg\n");
276                         }
277                 }
278                 else
279                 {
280                         centermsg_setfor(targ, CENTERMSG_DEATH, "^1Watch your step!");
281                         if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
282                                 bprint ("^1",s, "^1 ", attacker.message, "\n");
283                         else if (deathtype == DEATH_DROWN)
284                                 bprint ("^1",s, "^1 drowned\n");
285                         else if (deathtype == DEATH_SLIME)
286                                 bprint ("^1",s, "^1 was slimed\n");
287                         else if (deathtype == DEATH_LAVA)
288                                 bprint ("^1",s, "^1 turned into hot slag\n");
289                         else if (deathtype == DEATH_FALL)
290                                 bprint ("^1",s, "^1 hit the ground with a crunch\n");
291                         else if (deathtype == DEATH_SHOOTING_STAR)
292                                 bprint ("^1",s, "^1 became a shooting star\n");
293                         else if (deathtype == DEATH_SWAMP)
294                                 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
295                         else
296                                 bprint ("^1",s, "^1 died\n");
297                         GiveFrags(targ, targ, -1);
298                         if(targ.frags == -5) {
299                                 stuffcmd(targ, "play2 announcer/male/botlike.ogg\n");
300                         }
301
302                         //targ.frags = targ.frags - 1;
303                         if (targ.killcount > 2)
304                                 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
305
306                         LogDeath("accident", deathtype, targ, targ);
307                 }
308                 targ.death_origin = targ.origin;
309                 if(targ != attacker)
310                         targ.killer_origin = attacker.origin;
311                 // FIXME: this should go in PutClientInServer
312                 if (targ.killcount)
313                         targ.killcount = 0;
314         }
315 }
316
317 // these are updated by each Damage call for use in button triggering and such
318 entity damage_targ;
319 entity damage_inflictor;
320 entity damage_attacker;
321
322 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
323 {
324         float mirrordamage;
325         float mirrorforce;
326         entity attacker_save;
327         mirrordamage = 0;
328         mirrorforce = 0;
329
330         if (gameover || targ.killcount == -666)
331                 return;
332
333         local entity oldself;
334         oldself = self;
335         self = targ;
336         damage_targ = targ;
337         damage_inflictor = inflictor;
338         damage_attacker = attacker;
339                 attacker_save = attacker;
340
341         if (targ.classname == "player")
342         if (attacker.classname == "player")
343         if (!targ.isbot)
344         if (attacker.isbot)
345                 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
346
347         // nullify damage if teamplay is on
348         if(teamplay == 1)
349                 if(attacker.team)
350                         if(attacker.team == targ.team)
351                                 damage = 0;
352         if(teamplay == 3)
353                 if(attacker != targ)
354                         if(attacker.team)
355                                 if(attacker.team == targ.team)
356                                         damage = 0;
357         if(teamplay == 4)
358                 if(attacker != targ)
359                         if(attacker.team == targ.team)
360                                 if(attacker.classname == "player")
361                                         if(targ.classname == "player")
362                                         {
363                                                 mirrordamage = cvar("g_mirrordamage") * damage;
364                                                 mirrorforce = cvar("g_mirrordamage") * vlen(force);
365                                                 if(cvar("g_minstagib"))
366                                                 {
367                                                         if(cvar("g_friendlyfire") == 0)
368                                                                 damage = 0;
369                                                 }
370                                                 else
371                                                         damage = cvar("g_friendlyfire") * damage;
372                                                 // mirrordamage will be used LATER
373                                         }
374
375         if(cvar("g_lms"))
376         if(targ.classname == "player")
377         if(attacker.classname == "player")
378         if(attacker != targ)
379         {
380                 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
381                 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
382         }
383
384         if(targ != attacker)
385         if(!targ.deadflag)
386         if(damage > 0)
387         if(clienttype(attacker) == CLIENTTYPE_REAL)
388         if(targ.classname == "player")
389                 stuffcmd(attacker, "play2 misc/hit.wav\n");
390
391         if (cvar("g_minstagib"))
392         {
393                 if ((deathtype == DEATH_FALL)  ||
394                     (deathtype == DEATH_DROWN) ||
395                     (deathtype == DEATH_SLIME) ||
396                     (deathtype == DEATH_LAVA))
397                         return;
398                 if (targ.armorvalue && (deathtype == IT_NEX) && damage)
399                 {
400                         targ.armorvalue -= 1;
401                         centermsg_setfor(targ, CENTERMSG_MINSTAGIB, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
402                         damage = 0;
403                         if(clienttype(targ) == CLIENTTYPE_REAL) stuffcmd(targ, "play2 misc/hit.wav\n");
404                         //stuffcmd(attacker, "play2 misc/hit.wav\n");
405                 }
406                 else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
407                 {
408                         if(clienttype(attacker) == CLIENTTYPE_REAL) stuffcmd(attacker, "play2 announcer/male/yoda.ogg\n");
409                 }
410                 if (deathtype == IT_LASER)
411                 {
412                         damage = 0;
413                         if (targ != attacker)
414                         {
415                                 if (targ.classname == "player")
416                                         centermsg_setfor(attacker, CENTERMSG_MINSTAGIB, "Secondary fire inflicts no damage!\n");
417                                 damage = 0;
418                                 mirrordamage = 0;
419                                 force = '0 0 0';
420                                 // keep mirrorforce
421                                 attacker = targ;
422                         }
423                 }
424         } else {
425                 if (deathtype == IT_NEX && !targ.deadflag && !(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)
426                 {
427                         if(clienttype(attacker) == CLIENTTYPE_REAL)  stuffcmd(attacker, "play2 announcer/male/yoda.ogg\n");
428                 }
429         }
430
431         // apply strength multiplier
432         if (attacker.items & IT_STRENGTH && !cvar("g_minstagib"))
433         {
434                 damage = damage * cvar("g_balance_powerup_strength_damage");
435                 force = force * cvar("g_balance_powerup_strength_force");
436         }
437         // apply invincibility multiplier
438         if (targ.items & IT_INVINCIBLE && !cvar("g_minstagib"))
439                 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
440
441
442         if(cvar("g_runematch"))
443         {
444                 // apply strength rune
445                 if (attacker.runes & RUNE_STRENGTH)
446                 {
447                         if(attacker.runes & CURSE_WEAK) // have both curse & rune
448                         {
449                                 damage = damage * cvar("g_balance_rune_strength_combo_damage");
450                                 force = force * cvar("g_balance_rune_strength_combo_force");
451                         }
452                         else
453                         {
454                                 damage = damage * cvar("g_balance_rune_strength_damage");
455                                 force = force * cvar("g_balance_rune_strength_force");
456                         }
457                 }
458                 else if (attacker.runes & CURSE_WEAK)
459                 {
460                         damage = damage * cvar("g_balance_curse_weak_damage");
461                         force = force * cvar("g_balance_curse_weak_force");
462                 }
463
464                 // apply defense rune
465                 if (targ.runes & RUNE_DEFENSE)
466                 {
467                         if (targ.runes & CURSE_VULNER) // have both curse & rune
468                                 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
469                         else
470                                 damage = damage * cvar("g_balance_rune_defense_takedamage");
471                 }
472                 else if (targ.runes & CURSE_VULNER)
473                         damage = damage * cvar("g_balance_curse_vulner_takedamage");
474         }
475
476         // apply push
477         if (self.damageforcescale)
478         {
479                 self.velocity = self.velocity + self.damageforcescale * force;
480                 self.flags = self.flags - (self.flags & FL_ONGROUND);
481         }
482         // apply damage
483         if (self.event_damage)
484                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
485         self = oldself;
486
487         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
488         {
489                 // Savage: vampire mode
490                 if(cvar("g_vampire") && !cvar("g_minstagib"))
491                 {
492                         attacker.health += damage;
493                 }
494                 if(cvar("g_runematch"))
495                 {
496                         if (attacker.runes & RUNE_VAMPIRE)
497                         {
498                         // apply vampire rune
499                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
500                                 {
501                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
502                                         attacker.health = bound(
503                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
504                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
505                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
506                                 }
507                                 else
508                                 {
509                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
510                                         attacker.health = bound(
511                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
512                                                                                         // empathy won't let you gain health in the same way...
513                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
514                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
515                                         }
516                         }
517                         // apply empathy curse
518                         else if (attacker.runes & CURSE_EMPATHY)
519                         {
520                                 attacker.health = bound(
521                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
522                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
523                                         attacker.health);
524                         }
525                 }
526         }
527
528         // apply mirror damage if any
529         if(mirrordamage > 0 || mirrorforce > 0)
530         {
531                 attacker = attacker_save;
532                 if(cvar("g_minstagib"))
533                         if(mirrordamage > 0)
534                         {
535                                 // just lose extra LIVES, don't kill the player for mirror damage
536                                 if(attacker.armorvalue > 0)
537                                 {
538                                         attacker.armorvalue = attacker.armorvalue - 1;
539                                         centermsg_setfor(attacker, CENTERMSG_MINSTAGIB, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
540                                         if(clienttype(attacker) == CLIENTTYPE_REAL) stuffcmd(attacker, "play2 misc/hit.wav\n");
541                                 }
542                                 mirrordamage = 0;
543                         }
544                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
545                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
546         }
547 }
548
549 void RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
550 {
551         entity  targ;
552         float   finaldmg;
553         float   power;
554         vector  blastorigin;
555         vector  force;
556         vector  m1;
557         vector  m2;
558         vector  nearest;
559         vector  diff;
560
561         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
562
563         targ = findradius (blastorigin, rad);
564         while (targ)
565         {
566                 if (targ != inflictor)
567                         if (ignore != targ)
568                         {
569                                 // LordHavoc: measure distance to nearest point on target (not origin)
570                                 // (this guarentees 100% damage on a touch impact)
571                                 nearest = blastorigin;
572                                 m1 = targ.origin + targ.mins;
573                                 m2 = targ.origin + targ.maxs;
574                                 if (nearest_x < m1_x) nearest_x = m1_x;
575                                 if (nearest_y < m1_y) nearest_y = m1_y;
576                                 if (nearest_z < m1_z) nearest_z = m1_z;
577                                 if (nearest_x > m2_x) nearest_x = m2_x;
578                                 if (nearest_y > m2_y) nearest_y = m2_y;
579                                 if (nearest_z > m2_z) nearest_z = m2_z;
580                                 diff = nearest - blastorigin;
581                                 // round up a little on the damage to ensure full damage on impacts
582                                 // and turn the distance into a fraction of the radius
583                                 power = 1 - ((vlen (diff) - 2) / rad);
584                                 //bprint(" ");
585                                 //bprint(ftos(power));
586                                 if (power > 0)
587                                 {
588                                         if (power > 1)
589                                                 power = 1;
590                                         finaldmg = coredamage * power + edgedamage * (1 - power);
591                                         if (finaldmg > 0)
592                                         {
593                                                 force = normalize((m1 + m2) * 0.5 - blastorigin) * (finaldmg / coredamage) * forceintensity;
594                                                 if (targ == attacker)
595                                                         finaldmg = finaldmg * cvar("g_balance_selfdamagepercent");      // Partial damage if the attacker hits himself
596                                                 // test line of sight to multiple positions on box,
597                                                 // and do damage if any of them hit
598                                                 local float c;
599                                                 c = ceil(finaldmg / 10);
600                                                 if (c > 20)
601                                                         c = 20;
602                                                 while (c > 0)
603                                                 {
604                                                         c = c - 1;
605                                                         traceline(blastorigin, nearest, TRUE, inflictor);
606                                                         if (trace_fraction == 1 || trace_ent == targ
607                                                             || cvar("g_throughfloor"))
608                                                         {
609                                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
610                                                                 break;
611                                                         }
612                                                         nearest_x = m1_x + random() * targ.size_x;
613                                                         nearest_y = m1_y + random() * targ.size_y;
614                                                         nearest_z = m1_z + random() * targ.size_z;
615                                                 }
616                                         }
617                                 }
618                         }
619                 targ = targ.chain;
620         }
621 }
622
623 /*
624 entity  multi_ent;
625 float   multi_damage;
626 vector  multi_force;
627
628 void ClearMultiDamage (void)
629 {
630         multi_ent = world;
631         multi_damage = 0;
632         multi_force = '0 0 0';
633 }
634
635 void ApplyMultiDamage (void)
636 {
637         if (!multi_ent)
638                 return;
639
640         Damage (self, multi_ent.origin, multi_ent, 0, multi_damage, multi_force);
641 }
642
643 void AddMultiDamage (entity hit, float damage, vector force)
644 {
645         if (!hit)
646                 return;
647
648         if (hit != multi_ent)
649         {
650                 ApplyMultiDamage ();
651                 ClearMultiDamage ();
652                 multi_ent = hit;
653         }
654         multi_damage = multi_damage + damage;
655         multi_force = multi_force + force;
656 }
657
658 void FireBullets (float shotcount, vector dir, vector spread, float deathtype)
659 {
660         vector  direction;
661         vector  source;
662         vector  vel;
663         vector  org;
664
665         makevectors (self.v_angle);
666
667         source = self.origin + v_forward * 10;  // FIXME
668         source_x = self.absmin_z + self.size_z * 0.7;   // ??? whaddabout view_ofs
669
670         // LordHavoc: better to use normal damage
671         //ClearMultiDamage ();
672         while (shotcount > 0)
673         {
674                 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
675
676                 traceline (source, source + direction * 2048, FALSE, self);
677                 if (trace_fraction != 1.0)
678                 {
679                         vel = normalize (direction + v_up * crandom () + v_right * crandom ());
680                         vel = vel + 2 * trace_plane_normal;
681                         vel = vel * 200;
682
683                         org = trace_endpos - direction * 4;
684
685                         if (!trace_ent.takedamage)
686                                 te_gunshot (org);
687                         // LordHavoc: better to use normal damage
688                         //AddMultiDamage (trace_ent, 4, direction * 4);
689                         Damage (trace_ent, self, self, 4, deathtype, trace_endpos, direction * 4);
690                 }
691
692                 shotcount = shotcount + 1;
693         }
694
695         // LordHavoc: better to use normal damage
696         //ApplyMultiDamage ();
697 }
698 */
699
700
701