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