6 float Damage_DamageInfo_SendEntity(entity to, float sf)
8 WriteByte(MSG_ENTITY, ENT_CLIENT_DAMAGEINFO);
9 WriteShort(MSG_ENTITY, self.projectiledeathtype);
10 WriteCoord(MSG_ENTITY, floor(self.origin_x));
11 WriteCoord(MSG_ENTITY, floor(self.origin_y));
12 WriteCoord(MSG_ENTITY, floor(self.origin_z));
13 WriteByte(MSG_ENTITY, bound(1, self.dmg, 255));
14 WriteByte(MSG_ENTITY, bound(0, self.dmg_radius, 255));
15 WriteByte(MSG_ENTITY, bound(1, self.dmg_edge, 255));
16 WriteShort(MSG_ENTITY, self.oldorigin_x);
17 WriteByte(MSG_ENTITY, self.species);
21 void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, float deathtype, float bloodtype, entity dmgowner)
23 // TODO maybe call this from non-edgedamage too?
24 // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
28 if(!sound_allowed(MSG_BROADCAST, dmgowner))
33 e.projectiledeathtype = deathtype;
35 e.dmg_edge = edgedamage;
37 e.dmg_force = vlen(force);
39 e.oldorigin_x = compressShortVector(e.velocity);
40 e.species = bloodtype;
42 Net_LinkEntity(e, FALSE, 0.2, Damage_DamageInfo_SendEntity);
45 float checkrules_firstblood;
48 float damage_goodhits;
49 float damage_gooddamage;
51 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
54 .float teamkill_complain;
55 .float teamkill_soundtime;
56 .entity teamkill_soundsource;
58 .float taunt_soundtime;
61 float IsDifferentTeam(entity a, entity b)
76 float IsFlying(entity a)
78 if(a.flags & FL_ONGROUND)
80 if(a.waterlevel >= WATERLEVEL_SWIMMING)
82 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
83 if(trace_fraction < 1)
88 vector GetHeadshotMins(entity targ)
90 return '-0.5 0 0' * PL_HEAD_x + '0 -0.5 0' * PL_HEAD_y + '0 0 1' * (targ.maxs_z - PL_HEAD_z);
92 vector GetHeadshotMaxs(entity targ)
94 return '0.5 0 0' * PL_HEAD_x + '0 0.5 0' * PL_HEAD_y + '0 0 1' * targ.maxs_z;
97 void UpdateFrags(entity player, float f)
99 PlayerTeamScore_AddScore(player, f);
102 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
103 void W_SwitchWeapon_Force(entity e, float w);
104 void GiveFrags (entity attacker, entity targ, float f, float deathtype)
108 // TODO route through PlayerScores instead
116 PlayerScore_Add(attacker, SP_SUICIDES, 1);
121 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
127 PlayerScore_Add(attacker, SP_KILLS, 1);
129 PlayerStats_Event(attacker, sprintf("kills-%d", targ.playerid), 1);
132 PlayerScore_Add(targ, SP_DEATHS, 1);
135 if(autocvar_g_arena_roundbased)
138 if(targ != attacker) // not for suicides
139 if(g_weaponarena_random)
141 // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
143 culprit = DEATH_WEAPONOF(deathtype);
144 if(!culprit || !(attacker.weapons & W_WeaponBit(culprit)))
145 culprit = attacker.weapon;
147 if(g_weaponarena_random_with_laser && culprit == WEPBIT_LASER)
154 w = warmup_start_weapons;
158 // all others (including the culprit): remove
159 w &~= attacker.weapons;
161 // among the remaining ones, choose one by random
162 w = randombits(w, 1, FALSE);
165 attacker.weapons |= w;
166 attacker.weapons &~= W_WeaponBit(culprit);
170 // after a frag, choose another random weapon set
171 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
172 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
175 // FIXME fix the mess this is (we have REAL points now!)
179 frag_attacker = attacker;
182 if(MUTATOR_CALLHOOK(GiveFragsForKill))
192 f = RunematchHandleFrags(attacker, targ, f);
198 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
199 if(tl < lms_lowest_lives)
200 lms_lowest_lives = tl;
204 lms_next_place = player_count;
206 lms_next_place = min(lms_next_place, player_count);
207 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
214 attacker.totalfrags += f;
217 UpdateFrags(attacker, f);
220 string Obituary_ExtraFragInfo(entity player) // Extra fragmessage information
222 string health_output;
224 string handicap_output;
227 if(autocvar_sv_fraginfo && ((autocvar_sv_fraginfo == 2) || inWarmupStage))
229 // health/armor of attacker (person who killed you)
230 if(autocvar_sv_fraginfo_stats && (player.health >= 1))
231 health_output = strcat("^7(Health ^1", ftos(rint(player.health)), "^7 / Armor ^2", ftos(rint(player.armorvalue)), "^7)");
234 if(autocvar_sv_fraginfo_ping)
235 ping_output = ((clienttype(player) == CLIENTTYPE_BOT) ? "^2Bot" : strcat("Ping ", ((player.ping >= 150) ? "^1" : "^2"), ftos(rint(player.ping)), "ms"));
238 if(autocvar_sv_fraginfo_handicap)
240 if(autocvar_sv_fraginfo_handicap == 2)
241 handicap_output = strcat(output, strcat("Handicap ^2", ((player.cvar_cl_handicap <= 1) ? "Off" : ftos(rint(player.cvar_cl_handicap)))));
242 else if(player.cvar_cl_handicap) // with _handicap 1, only show this if there actually is a handicap enabled.
243 handicap_output = strcat("Handicap ^2", ftos(rint(player.cvar_cl_handicap)));
247 output = strcat(health_output, (health_output ? ((ping_output || handicap_output) ? " ^7(" : "") : ((ping_output || handicap_output) ? "^7(" : "")),
248 ping_output, (handicap_output ? "^7 / " : ""),
249 handicap_output, ((ping_output || handicap_output) ? "^7)" : ""));
251 // add new line to the beginning if there is a message
252 if(output) { output = strcat("\n", output); }
258 string AppendItemcodes(string s, entity player)
263 // w = player.switchweapon;
265 w = player.cnt; // previous weapon!
266 s = strcat(s, ftos(w));
267 if(time < player.strength_finished)
269 if(time < player.invincible_finished)
271 if(player.flagcarried != world)
273 if(player.BUTTON_CHAT)
278 s = strcat(s, "|", ftos(player.runes));
282 void LogDeath(string mode, float deathtype, entity killer, entity killed)
285 if(!autocvar_sv_eventlog)
287 s = strcat(":kill:", mode);
288 s = strcat(s, ":", ftos(killer.playerid));
289 s = strcat(s, ":", ftos(killed.playerid));
290 s = strcat(s, ":type=", ftos(deathtype));
291 s = strcat(s, ":items=");
292 s = AppendItemcodes(s, killer);
295 s = strcat(s, ":victimitems=");
296 s = AppendItemcodes(s, killed);
301 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
303 WriteByte(MSG_ALL, SVC_TEMPENTITY);
304 WriteByte(MSG_ALL, TE_CSQC_KILLNOTIFY);
305 WriteString(MSG_ALL, s1);
306 WriteString(MSG_ALL, s2);
307 WriteString(MSG_ALL, s3);
308 WriteShort(MSG_ALL, msg);
309 WriteByte(MSG_ALL, type);
312 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
313 void Send_CSQC_KillCenterprint(entity e, string s1, string s2, float msg, float type)
315 if (clienttype(e) == CLIENTTYPE_REAL)
318 WRITESPECTATABLE_MSG_ONE({
319 WriteByte(MSG_ONE, SVC_TEMPENTITY);
320 WriteByte(MSG_ONE, TE_CSQC_KILLCENTERPRINT);
321 WriteString(MSG_ONE, s1);
322 WriteString(MSG_ONE, s2);
323 WriteShort(MSG_ONE, msg);
324 WriteByte(MSG_ONE, type);
329 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
334 if (targ.classname == "player")
337 a = attacker.netname;
339 if (targ == attacker) // suicides
341 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
342 msg = ColoredTeamName(targ.team); // TODO: check if needed?
343 if(!g_cts) // no "killed your own dumb self" message in CTS
344 Send_CSQC_KillCenterprint(targ, msg, "", deathtype, MSG_SUICIDE);
346 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
348 LogDeath("suicide", deathtype, targ, targ);
349 GiveFrags(attacker, targ, -1, deathtype);
352 if (targ.killcount > 2)
353 msg = ftos(targ.killcount);
354 if(teamplay && deathtype == DEATH_MIRRORDAMAGE)
356 if(attacker.team == COLOR_TEAM1)
357 deathtype = KILL_TEAM_RED;
359 deathtype = KILL_TEAM_BLUE;
362 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
364 else if (attacker.classname == "player")
366 if(!IsDifferentTeam(attacker, targ))
368 if(attacker.team == COLOR_TEAM1)
369 type = KILL_TEAM_RED;
371 type = KILL_TEAM_BLUE;
373 GiveFrags(attacker, targ, -1, deathtype);
375 Send_CSQC_KillCenterprint(attacker, s, "", type, MSG_KILL);
377 if (targ.killcount > 2) {
378 msg = ftos(targ.killcount);
381 if (attacker.killcount > 2) {
382 msg = ftos(attacker.killcount);
383 type = KILL_TEAM_SPREE;
385 Send_KillNotification(a, s, msg, type, MSG_KILL);
387 attacker.killcount = 0;
389 LogDeath("tk", deathtype, attacker, targ);
393 if (!checkrules_firstblood)
395 checkrules_firstblood = TRUE;
396 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
397 // TODO: make these print a newline if they dont
398 Send_CSQC_KillCenterprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
399 Send_CSQC_KillCenterprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
400 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
401 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
404 if(targ.BUTTON_CHAT) {
405 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_TYPEFRAG, MSG_KILL);
406 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_TYPEFRAGGED, MSG_KILL);
408 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_FRAG, MSG_KILL);
409 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_FRAGGED, MSG_KILL);
412 attacker.taunt_soundtime = time + 1;
415 if (deathtype == DEATH_CUSTOM)
418 msg = inflictor.message2;
420 if(strstrofs(msg, "%", 0) < 0)
421 msg = strcat("%s ", msg, " by %s");
423 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
425 if(g_ctf && targ.flagcarried)
427 UpdateFrags(attacker, ctf_ReadScore("score_kill")); // FIXCTF
428 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
429 GiveFrags(attacker, targ, 0, deathtype); // for logging
432 GiveFrags(attacker, targ, 1, deathtype);
434 if (targ.killcount > 2) {
435 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
438 attacker.killcount = attacker.killcount + 1;
440 if (attacker.killcount > 2) {
441 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
443 else if (attacker.killcount == 3)
445 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
446 AnnounceTo(attacker, "03kills");
447 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
449 else if (attacker.killcount == 5)
451 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
452 AnnounceTo(attacker, "05kills");
453 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
455 else if (attacker.killcount == 10)
457 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
458 AnnounceTo(attacker, "10kills");
459 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
461 else if (attacker.killcount == 15)
463 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
464 AnnounceTo(attacker, "15kills");
465 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
467 else if (attacker.killcount == 20)
469 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
470 AnnounceTo(attacker, "20kills");
471 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
473 else if (attacker.killcount == 25)
475 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
476 AnnounceTo(attacker, "25kills");
477 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
479 else if (attacker.killcount == 30)
481 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
482 AnnounceTo(attacker, "30kills");
483 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
485 LogDeath("frag", deathtype, attacker, targ);
490 Send_CSQC_KillCenterprint(targ, "", "", deathtype, MSG_KILL_ACTION);
491 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
492 msg = inflictor.message;
493 else if (deathtype == DEATH_CUSTOM)
495 if(strstrofs(msg, "%", 0) < 0)
496 msg = strcat("%s ", msg);
498 GiveFrags(targ, targ, -1, deathtype);
499 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
500 AnnounceTo(targ, "botlike");
501 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
503 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
505 if (targ.killcount > 2)
506 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
508 LogDeath("accident", deathtype, targ, targ);
511 targ.death_origin = targ.origin;
513 targ.killer_origin = attacker.origin;
515 // FIXME: this should go in PutClientInServer
521 // these are updated by each Damage call for use in button triggering and such
523 entity damage_inflictor;
524 entity damage_attacker;
526 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
531 entity attacker_save;
535 if (gameover || targ.killcount == -666)
542 damage_inflictor = inflictor;
543 damage_attacker = attacker;
544 attacker_save = attacker;
546 if(targ.classname == "player")
549 if(targ.hook.aiment == attacker)
550 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
552 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
553 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
555 if(targ.classname == "player")
556 if not(IsDifferentTeam(targ, attacker))
563 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
565 // These are ALWAYS lethal
566 // No damage modification here
567 // Instead, prepare the victim for his death...
569 targ.spawnshieldtime = 0;
570 targ.health = 0.9; // this is < 1
571 targ.flags -= targ.flags & FL_GODMODE;
574 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
581 skill based bot damage? gtfo. (tZork)
582 if (targ.classname == "player")
583 if (attacker.classname == "player")
586 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
589 // nullify damage if teamplay is on
590 if(deathtype != DEATH_TELEFRAG)
591 if(attacker.classname == "player")
593 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
598 else if(!IsDifferentTeam(attacker, targ))
600 if(autocvar_teamplay_mode == 1)
602 else if(attacker != targ)
604 if(autocvar_teamplay_mode == 3)
606 else if(autocvar_teamplay_mode == 4)
608 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
610 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
611 attacker.dmg_team = attacker.dmg_team + damage;
612 if(attacker.dmg_team > teamdamage0 && !g_ca)
613 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
614 mirrorforce = autocvar_g_mirrordamage * vlen(force);
617 if(autocvar_g_friendlyfire == 0)
623 damage = autocvar_g_friendlyfire * damage;
624 // mirrordamage will be used LATER
626 if(autocvar_g_mirrordamage_virtual)
629 v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
630 v_z = 0; // fteqcc sucks
631 attacker.dmg_take += v_x;
632 attacker.dmg_save += v_y;
633 attacker.dmg_inflictor = inflictor;
638 if(autocvar_g_friendlyfire_virtual)
641 v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
642 v_z = 0; // fteqcc sucks
643 targ.dmg_take += v_x;
644 targ.dmg_save += v_y;
645 targ.dmg_inflictor = inflictor;
647 if(!autocvar_g_friendlyfire_virtual_force)
658 if(targ.classname == "player")
659 if(attacker.classname == "player")
662 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
663 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
666 if(targ.classname == "player")
669 if ((deathtype == DEATH_FALL) ||
670 (deathtype == DEATH_DROWN) ||
671 (deathtype == DEATH_SLIME) ||
672 (deathtype == DEATH_LAVA) ||
673 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
680 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
682 targ.armorvalue -= 1;
683 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
686 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
688 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
692 if (targ != attacker)
694 if ((targ.health >= 1) && (targ.classname == "player"))
695 centerprint(attacker, "Secondary fire inflicts no damage!");
703 if not(DEATH_ISSPECIAL(deathtype))
705 damage *= g_weapondamagefactor;
706 mirrordamage *= g_weapondamagefactor;
707 force = force * g_weaponforcefactor;
708 mirrorforce *= g_weaponforcefactor;
711 // should this be changed at all? If so, in what way?
712 frag_attacker = attacker;
714 frag_damage = damage;
716 frag_deathtype = deathtype;
717 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
718 damage = frag_damage;
721 // apply strength multiplier
722 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
726 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
727 force = force * autocvar_g_balance_powerup_strength_selfforce;
731 damage = damage * autocvar_g_balance_powerup_strength_damage;
732 force = force * autocvar_g_balance_powerup_strength_force;
736 // apply invincibility multiplier
737 if (targ.items & IT_INVINCIBLE && !g_minstagib)
738 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
740 if (targ == attacker)
742 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
745 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
750 // apply strength rune
751 if (attacker.runes & RUNE_STRENGTH)
753 if(attacker.runes & CURSE_WEAK) // have both curse & rune
755 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
756 force = force * autocvar_g_balance_rune_strength_combo_force;
760 damage = damage * autocvar_g_balance_rune_strength_damage;
761 force = force * autocvar_g_balance_rune_strength_force;
764 else if (attacker.runes & CURSE_WEAK)
766 damage = damage * autocvar_g_balance_curse_weak_damage;
767 force = force * autocvar_g_balance_curse_weak_force;
770 // apply defense rune
771 if (targ.runes & RUNE_DEFENSE)
773 if (targ.runes & CURSE_VULNER) // have both curse & rune
774 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
776 damage = damage * autocvar_g_balance_rune_defense_takedamage;
778 else if (targ.runes & CURSE_VULNER)
779 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
785 if(targ.takedamage == DAMAGE_AIM)
788 if(damage_headshotbonus > 0)
790 if(targ.classname == "player")
793 // find height of hit on player axis
794 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
795 vector headmins, headmaxs, org;
796 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
797 headmins = org + GetHeadshotMins(targ);
798 headmaxs = org + GetHeadshotMaxs(targ);
799 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
801 deathtype |= HITTYPE_HEADSHOT;
804 else if(targ.classname == "turret_head")
806 deathtype |= HITTYPE_HEADSHOT;
808 if(deathtype & HITTYPE_HEADSHOT)
809 damage *= 1 + damage_headshotbonus;
813 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
818 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
820 if(IsDifferentTeam(victim, attacker))
824 if(deathtype != DEATH_FIRE)
826 if(victim.BUTTON_CHAT)
827 attacker.typehitsound += 1;
829 attacker.hitsound += 1;
832 damage_goodhits += 1;
833 damage_gooddamage += damage;
835 if not(DEATH_ISSPECIAL(deathtype))
837 if(targ.classname == "player") // don't do this for vehicles
843 if(victim.items & IT_STRENGTH)
846 if(deathtype & HITTYPE_HEADSHOT)
850 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
855 if(deathtype != DEATH_FIRE)
857 attacker.typehitsound += 1;
860 if(time > attacker.teamkill_complain)
862 attacker.teamkill_complain = time + 5;
863 attacker.teamkill_soundtime = time + 0.4;
864 attacker.teamkill_soundsource = targ;
872 if (self.damageforcescale)
874 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
876 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
877 if(self.movetype == MOVETYPE_PHYSICS)
881 farcent.classname = "farce";
882 farcent.enemy = self;
883 farcent.movedir = farce * 10;
885 farcent.movedir = farcent.movedir * self.mass;
886 farcent.origin = hitloc;
887 farcent.forcetype = FORCETYPE_FORCEATPOS;
888 farcent.nextthink = time + 0.1;
889 farcent.think = SUB_Remove;
892 self.velocity = self.velocity + farce;
893 self.flags &~= FL_ONGROUND;
894 UpdateCSQCProjectile(self);
897 if (damage != 0 || (self.damageforcescale && vlen(force)))
898 if (self.event_damage)
899 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
902 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
906 if (attacker.runes & RUNE_VAMPIRE)
908 // apply vampire rune
909 if (attacker.runes & CURSE_EMPATHY) // have the curse too
911 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
912 attacker.health = bound(
913 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
914 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
915 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
919 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
920 attacker.health = bound(
921 attacker.health, // LA: was 3, but changed so that you can't lose health
922 // empathy won't let you gain health in the same way...
923 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
924 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
927 // apply empathy curse
928 else if (attacker.runes & CURSE_EMPATHY)
930 attacker.health = bound(
931 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
932 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
938 // apply mirror damage if any
939 if(mirrordamage > 0 || mirrorforce > 0)
941 attacker = attacker_save;
945 // just lose extra LIVES, don't kill the player for mirror damage
946 if(attacker.armorvalue > 0)
948 attacker.armorvalue = attacker.armorvalue - 1;
949 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
950 attacker.hitsound += 1;
955 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
956 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
960 float RadiusDamage_running;
961 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
962 // Returns total damage applies to creatures
972 float total_damage_to_creatures;
977 float stat_damagedone;
979 if(RadiusDamage_running)
981 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
985 RadiusDamage_running = 1;
987 tfloordmg = autocvar_g_throughfloor_damage;
988 tfloorforce = autocvar_g_throughfloor_force;
990 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
991 total_damage_to_creatures = 0;
993 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
994 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
996 force = inflictor.velocity;
1000 force = normalize(force);
1001 if(forceintensity >= 0)
1002 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
1004 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
1007 stat_damagedone = 0;
1009 targ = WarpZone_FindRadius (blastorigin, rad + MAX_DAMAGEEXTRARADIUS, FALSE);
1013 if (targ != inflictor)
1014 if (ignore != targ) if(targ.takedamage)
1016 // LordHavoc: measure distance to nearest point on target (not origin)
1017 // (this guarentees 100% damage on a touch impact)
1018 nearest = targ.WarpZone_findradius_nearest;
1019 diff = targ.WarpZone_findradius_dist;
1020 // round up a little on the damage to ensure full damage on impacts
1021 // and turn the distance into a fraction of the radius
1022 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
1024 //bprint(ftos(power));
1025 //if (targ == attacker)
1026 // print(ftos(power), "\n");
1031 finaldmg = coredamage * power + edgedamage * (1 - power);
1040 vector myblastorigin;
1041 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1042 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1043 // if it's a player, use the view origin as reference
1044 if (targ.classname == "player")
1045 center = targ.origin + targ.view_ofs;
1046 force = normalize(center - myblastorigin);
1047 force = force * (finaldmg / coredamage) * forceintensity;
1048 // test line of sight to multiple positions on box,
1049 // and do damage if any of them hit
1051 if (targ.classname == "player")
1052 total = ceil(bound(1, finaldmg, 50));
1054 total = ceil(bound(1, finaldmg/10, 5));
1059 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1060 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1061 if (trace_fraction == 1 || trace_ent == targ)
1065 hitloc = hitloc + nearest;
1069 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1070 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1071 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1074 nearest = hitloc * (1 / max(1, hits));
1075 hitratio = (hits / total);
1076 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1077 finaldmg = finaldmg * a;
1078 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1081 // laser force adjustments :P
1082 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1084 if (targ == attacker)
1089 float force_velocitybiasramp;
1090 float force_velocitybias;
1092 force_velocitybiasramp = autocvar_sv_maxspeed;
1093 if(deathtype & HITTYPE_SECONDARY)
1095 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1096 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1100 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1101 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1104 vel = targ.velocity;
1106 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1110 normalize(normalize(force) + vel);
1112 force_z *= force_zscale;
1116 if(deathtype & HITTYPE_SECONDARY)
1118 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1122 force *= autocvar_g_balance_laser_primary_force_other_scale;
1127 //if (targ == attacker)
1129 // print("hits ", ftos(hits), " / ", ftos(total));
1130 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1131 // print(" (", ftos(a), ")\n");
1133 if(hits || tfloordmg || tfloorforce)
1137 total_damage_to_creatures += finaldmg;
1139 if(accuracy_isgooddamage(attacker, targ))
1140 stat_damagedone += finaldmg;
1143 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1144 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1146 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1154 RadiusDamage_running = 0;
1156 if(!DEATH_ISSPECIAL(deathtype))
1157 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1159 return total_damage_to_creatures;
1162 .float fire_damagepersec;
1163 .float fire_endtime;
1164 .float fire_deathtype;
1166 .float fire_hitsound;
1167 .entity fire_burner;
1169 void fireburner_think();
1171 float Fire_IsBurning(entity e)
1173 return (time < e.fire_endtime);
1176 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1179 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1181 if(e.classname == "player")
1190 // print("adding a fire burner to ", e.classname, "\n");
1191 e.fire_burner = spawn();
1192 e.fire_burner.classname = "fireburner";
1193 e.fire_burner.think = fireburner_think;
1194 e.fire_burner.nextthink = time;
1195 e.fire_burner.owner = e;
1201 if(Fire_IsBurning(e))
1203 mintime = e.fire_endtime - time;
1204 maxtime = max(mintime, t);
1206 mindps = e.fire_damagepersec;
1207 maxdps = max(mindps, dps);
1209 if(maxtime > mintime || maxdps > mindps)
1211 mindamage = mindps * mintime;
1212 maxdamage = mindamage + d;
1214 // interval [mintime, maxtime] * [mindps, maxdps]
1216 // [mindamage, maxdamage]
1219 if(maxdamage >= maxtime * maxdps)
1221 totaltime = maxtime;
1222 totaldamage = maxtime * maxdps;
1224 // this branch increases totaldamage if either t > mintime, or dps > mindps
1228 // maxdamage is inside the interval!
1229 // first, try to use mindps; only if this fails, increase dps as needed
1230 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1231 totaldamage = maxdamage;
1232 // can totaldamage / totaltime be >= maxdps?
1233 // max(mindps, maxdamage / maxtime) >= maxdps?
1234 // we know maxdamage < maxtime * maxdps
1237 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1240 // total conditions for increasing:
1241 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1243 // if maxtime = mintime, maxdps = mindps
1245 // maxdamage = mindamage + d
1246 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1247 // so the last condition is not needed
1249 e.fire_damagepersec = totaldamage / totaltime;
1250 e.fire_endtime = time + totaltime;
1251 if(totaldamage > 1.2 * mindamage)
1253 e.fire_deathtype = dt;
1254 if(e.fire_owner != o)
1257 e.fire_hitsound = FALSE;
1260 if(accuracy_isgooddamage(o, e))
1261 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1262 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1269 e.fire_damagepersec = dps;
1270 e.fire_endtime = time + t;
1271 e.fire_deathtype = dt;
1273 e.fire_hitsound = FALSE;
1274 if(accuracy_isgooddamage(o, e))
1275 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1280 void Fire_ApplyDamage(entity e)
1285 if not(Fire_IsBurning(e))
1288 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1289 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1292 // water and slime stop fire
1294 if(e.watertype != CONTENT_LAVA)
1298 if(e.freezetag_frozen)
1301 t = min(frametime, e.fire_endtime - time);
1302 d = e.fire_damagepersec * t;
1304 hi = e.fire_owner.hitsound;
1305 ty = e.fire_owner.typehitsound;
1306 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1307 if(e.fire_hitsound && e.fire_owner)
1309 e.fire_owner.hitsound = hi;
1310 e.fire_owner.typehitsound = ty;
1312 e.fire_hitsound = TRUE;
1314 if not(IS_INDEPENDENT_PLAYER(e))
1315 FOR_EACH_PLAYER(other) if(e != other)
1317 if(other.classname == "player")
1318 if(other.deadflag == DEAD_NO)
1319 if not(IS_INDEPENDENT_PLAYER(other))
1320 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1322 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1323 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1324 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1329 void Fire_ApplyEffect(entity e)
1331 if(Fire_IsBurning(e))
1332 e.effects |= EF_FLAME;
1334 e.effects &~= EF_FLAME;
1337 void fireburner_think()
1339 // for players, this is done in the regular loop
1340 if(wasfreed(self.owner))
1345 Fire_ApplyEffect(self.owner);
1346 if(!Fire_IsBurning(self.owner))
1348 self.owner.fire_burner = world;
1352 Fire_ApplyDamage(self.owner);
1353 self.nextthink = time;