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