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 if(g_ctf_ignore_frags)
219 attacker.totalfrags += f;
222 UpdateFrags(attacker, f);
225 string Obituary_ExtraFragInfo(entity player) // Extra fragmessage information
227 string health_output;
229 string handicap_output;
232 // health/armor of attacker (person who killed you)
233 if(autocvar_sv_fraginfo_stats && (player.health >= 1))
234 if((autocvar_sv_fraginfo_stats == 2) || inWarmupStage)
235 health_output = strcat("^7(Health ^1", ftos(rint(player.health)), "^7 / Armor ^2", ftos(rint(player.armorvalue)), "^7)");
238 if(autocvar_sv_fraginfo_ping)
239 ping_output = ((clienttype(player) == CLIENTTYPE_BOT) ? "^2Bot" : strcat("Ping ", ((player.ping >= 150) ? "^1" : "^2"), ftos(rint(player.ping)), "ms"));
242 if(autocvar_sv_fraginfo_handicap)
244 if(autocvar_sv_fraginfo_handicap == 2)
245 handicap_output = strcat(output, strcat("Handicap ^2", ((player.cvar_cl_handicap <= 1) ? "Off" : ftos(rint(player.cvar_cl_handicap)))));
246 else if(player.cvar_cl_handicap) // with _handicap 1, only show this if there actually is a handicap enabled.
247 handicap_output = strcat("Handicap ^2", ftos(rint(player.cvar_cl_handicap)));
251 output = strcat(health_output, (health_output ? ((ping_output || handicap_output) ? " ^7(" : "") : ((ping_output || handicap_output) ? "^7(" : "")),
252 ping_output, (handicap_output ? "^7 / " : ""),
253 handicap_output, ((ping_output || handicap_output) ? "^7)" : ""));
255 // add new line to the beginning if there is a message
256 if(output) { output = strcat("\n", output); }
261 string AppendItemcodes(string s, entity player)
266 // w = player.switchweapon;
268 w = player.cnt; // previous weapon!
269 s = strcat(s, ftos(w));
270 if(time < player.strength_finished)
272 if(time < player.invincible_finished)
274 if(player.flagcarried != world)
276 if(player.BUTTON_CHAT)
281 s = strcat(s, "|", ftos(player.runes));
285 void LogDeath(string mode, float deathtype, entity killer, entity killed)
288 if(!autocvar_sv_eventlog)
290 s = strcat(":kill:", mode);
291 s = strcat(s, ":", ftos(killer.playerid));
292 s = strcat(s, ":", ftos(killed.playerid));
293 s = strcat(s, ":type=", ftos(deathtype));
294 s = strcat(s, ":items=");
295 s = AppendItemcodes(s, killer);
298 s = strcat(s, ":victimitems=");
299 s = AppendItemcodes(s, killed);
304 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
306 WriteByte(MSG_ALL, SVC_TEMPENTITY);
307 WriteByte(MSG_ALL, TE_CSQC_KILLNOTIFY);
308 WriteString(MSG_ALL, s1);
309 WriteString(MSG_ALL, s2);
310 WriteString(MSG_ALL, s3);
311 WriteShort(MSG_ALL, msg);
312 WriteByte(MSG_ALL, type);
315 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
316 void Send_CSQC_KillCenterprint(entity e, string s1, string s2, float msg, float type)
318 if (clienttype(e) == CLIENTTYPE_REAL)
321 WRITESPECTATABLE_MSG_ONE({
322 WriteByte(MSG_ONE, SVC_TEMPENTITY);
323 WriteByte(MSG_ONE, TE_CSQC_KILLCENTERPRINT);
324 WriteString(MSG_ONE, s1);
325 WriteString(MSG_ONE, s2);
326 WriteShort(MSG_ONE, msg);
327 WriteByte(MSG_ONE, type);
332 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
337 if (targ.classname == "player")
340 a = attacker.netname;
342 if (targ == attacker) // suicides
344 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
345 msg = ColoredTeamName(targ.team); // TODO: check if needed?
346 if(!g_cts) // no "killed your own dumb self" message in CTS
347 Send_CSQC_KillCenterprint(targ, msg, "", deathtype, MSG_SUICIDE);
349 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
351 LogDeath("suicide", deathtype, targ, targ);
352 GiveFrags(attacker, targ, -1, deathtype);
355 if (targ.killcount > 2)
356 msg = ftos(targ.killcount);
357 if(teamplay && deathtype == DEATH_MIRRORDAMAGE)
359 if(attacker.team == COLOR_TEAM1)
360 deathtype = KILL_TEAM_RED;
362 deathtype = KILL_TEAM_BLUE;
365 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
367 else if (attacker.classname == "player")
369 if(!IsDifferentTeam(attacker, targ))
371 if(attacker.team == COLOR_TEAM1)
372 type = KILL_TEAM_RED;
374 type = KILL_TEAM_BLUE;
376 GiveFrags(attacker, targ, -1, deathtype);
378 Send_CSQC_KillCenterprint(attacker, s, "", type, MSG_KILL);
380 if (targ.killcount > 2) {
381 msg = ftos(targ.killcount);
384 if (attacker.killcount > 2) {
385 msg = ftos(attacker.killcount);
386 type = KILL_TEAM_SPREE;
388 Send_KillNotification(a, s, msg, type, MSG_KILL);
390 attacker.killcount = 0;
392 LogDeath("tk", deathtype, attacker, targ);
396 if (!checkrules_firstblood)
398 checkrules_firstblood = TRUE;
399 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
400 // TODO: make these print a newline if they dont
401 Send_CSQC_KillCenterprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
402 Send_CSQC_KillCenterprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
403 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
404 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
407 if((autocvar_sv_fraginfo_typefrag) && (targ.BUTTON_CHAT)) {
408 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_TYPEFRAG, MSG_KILL);
409 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_TYPEFRAGGED, MSG_KILL);
411 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_FRAG, MSG_KILL);
412 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_FRAGGED, MSG_KILL);
415 attacker.taunt_soundtime = time + 1;
418 if (deathtype == DEATH_CUSTOM)
421 msg = inflictor.message2;
423 if(strstrofs(msg, "%", 0) < 0)
424 msg = strcat("%s ", msg, " by %s");
426 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
428 if(g_ctf && targ.flagcarried)
430 UpdateFrags(attacker, ctf_score_value("score_kill"));
431 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
432 GiveFrags(attacker, targ, 0, deathtype); // for logging
435 GiveFrags(attacker, targ, 1, deathtype);
437 if (targ.killcount > 2) {
438 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
441 attacker.killcount = attacker.killcount + 1;
443 if (attacker.killcount > 2) {
444 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
446 else if (attacker.killcount == 3)
448 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
449 AnnounceTo(attacker, "03kills");
450 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
452 else if (attacker.killcount == 5)
454 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
455 AnnounceTo(attacker, "05kills");
456 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
458 else if (attacker.killcount == 10)
460 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
461 AnnounceTo(attacker, "10kills");
462 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
464 else if (attacker.killcount == 15)
466 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
467 AnnounceTo(attacker, "15kills");
468 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
470 else if (attacker.killcount == 20)
472 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
473 AnnounceTo(attacker, "20kills");
474 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
476 else if (attacker.killcount == 25)
478 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
479 AnnounceTo(attacker, "25kills");
480 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
482 else if (attacker.killcount == 30)
484 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
485 AnnounceTo(attacker, "30kills");
486 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
488 LogDeath("frag", deathtype, attacker, targ);
493 Send_CSQC_KillCenterprint(targ, "", "", deathtype, MSG_KILL_ACTION);
494 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
495 msg = inflictor.message;
496 else if (deathtype == DEATH_CUSTOM)
498 if(strstrofs(msg, "%", 0) < 0)
499 msg = strcat("%s ", msg);
501 GiveFrags(targ, targ, -1, deathtype);
502 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
503 AnnounceTo(targ, "botlike");
504 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
506 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
508 if (targ.killcount > 2)
509 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
511 LogDeath("accident", deathtype, targ, targ);
514 targ.death_origin = targ.origin;
516 targ.killer_origin = attacker.origin;
518 // FIXME: this should go in PutClientInServer
524 // these are updated by each Damage call for use in button triggering and such
526 entity damage_inflictor;
527 entity damage_attacker;
529 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
534 entity attacker_save;
538 if (gameover || targ.killcount == -666)
545 damage_inflictor = inflictor;
546 damage_attacker = attacker;
547 attacker_save = attacker;
549 if(targ.classname == "player")
552 if(targ.hook.aiment == attacker)
553 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
555 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
556 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
558 if(targ.classname == "player")
559 if not(IsDifferentTeam(targ, attacker))
566 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
568 // These are ALWAYS lethal
569 // No damage modification here
570 // Instead, prepare the victim for his death...
572 targ.spawnshieldtime = 0;
573 targ.health = 0.9; // this is < 1
574 targ.flags -= targ.flags & FL_GODMODE;
577 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
584 skill based bot damage? gtfo. (tZork)
585 if (targ.classname == "player")
586 if (attacker.classname == "player")
589 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
592 // nullify damage if teamplay is on
593 if(deathtype != DEATH_TELEFRAG)
594 if(attacker.classname == "player")
596 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
601 else if(!IsDifferentTeam(attacker, targ))
603 if(autocvar_teamplay_mode == 1)
605 else if(attacker != targ)
607 if(autocvar_teamplay_mode == 3)
609 else if(autocvar_teamplay_mode == 4)
611 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
613 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
614 attacker.dmg_team = attacker.dmg_team + damage;
615 if(attacker.dmg_team > teamdamage0 && !g_ca)
616 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
617 mirrorforce = autocvar_g_mirrordamage * vlen(force);
620 if(autocvar_g_friendlyfire == 0)
626 damage = autocvar_g_friendlyfire * damage;
627 // mirrordamage will be used LATER
629 if(autocvar_g_mirrordamage_virtual)
632 v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
633 v_z = 0; // fteqcc sucks
634 attacker.dmg_take += v_x;
635 attacker.dmg_save += v_y;
636 attacker.dmg_inflictor = inflictor;
641 if(autocvar_g_friendlyfire_virtual)
644 v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
645 v_z = 0; // fteqcc sucks
646 targ.dmg_take += v_x;
647 targ.dmg_save += v_y;
648 targ.dmg_inflictor = inflictor;
650 if(!autocvar_g_friendlyfire_virtual_force)
661 if(targ.classname == "player")
662 if(attacker.classname == "player")
665 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
666 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
669 if(targ.classname == "player")
672 if ((deathtype == DEATH_FALL) ||
673 (deathtype == DEATH_DROWN) ||
674 (deathtype == DEATH_SLIME) ||
675 (deathtype == DEATH_LAVA) ||
676 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
683 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
685 targ.armorvalue -= 1;
686 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
689 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
691 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
695 if (targ != attacker)
697 if ((targ.health >= 1) && (targ.classname == "player"))
698 centerprint(attacker, "Secondary fire inflicts no damage!");
706 if not(DEATH_ISSPECIAL(deathtype))
708 damage *= g_weapondamagefactor;
709 mirrordamage *= g_weapondamagefactor;
710 force = force * g_weaponforcefactor;
711 mirrorforce *= g_weaponforcefactor;
714 // should this be changed at all? If so, in what way?
715 frag_attacker = attacker;
717 frag_damage = damage;
719 frag_deathtype = deathtype;
720 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
721 damage = frag_damage;
724 // apply strength multiplier
725 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
729 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
730 force = force * autocvar_g_balance_powerup_strength_selfforce;
734 damage = damage * autocvar_g_balance_powerup_strength_damage;
735 force = force * autocvar_g_balance_powerup_strength_force;
739 // apply invincibility multiplier
740 if (targ.items & IT_INVINCIBLE && !g_minstagib)
741 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
743 if (targ == attacker)
745 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
748 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
751 // CTF: reduce damage/force
756 damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
757 force = force * autocvar_g_ctf_flagcarrier_selfforce;
762 // apply strength rune
763 if (attacker.runes & RUNE_STRENGTH)
765 if(attacker.runes & CURSE_WEAK) // have both curse & rune
767 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
768 force = force * autocvar_g_balance_rune_strength_combo_force;
772 damage = damage * autocvar_g_balance_rune_strength_damage;
773 force = force * autocvar_g_balance_rune_strength_force;
776 else if (attacker.runes & CURSE_WEAK)
778 damage = damage * autocvar_g_balance_curse_weak_damage;
779 force = force * autocvar_g_balance_curse_weak_force;
782 // apply defense rune
783 if (targ.runes & RUNE_DEFENSE)
785 if (targ.runes & CURSE_VULNER) // have both curse & rune
786 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
788 damage = damage * autocvar_g_balance_rune_defense_takedamage;
790 else if (targ.runes & CURSE_VULNER)
791 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
797 if(targ.takedamage == DAMAGE_AIM)
800 if(damage_headshotbonus > 0)
802 if(targ.classname == "player")
805 // find height of hit on player axis
806 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
807 vector headmins, headmaxs, org;
808 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
809 headmins = org + GetHeadshotMins(targ);
810 headmaxs = org + GetHeadshotMaxs(targ);
811 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
813 deathtype |= HITTYPE_HEADSHOT;
816 else if(targ.classname == "turret_head")
818 deathtype |= HITTYPE_HEADSHOT;
820 if(deathtype & HITTYPE_HEADSHOT)
821 damage *= 1 + damage_headshotbonus;
825 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
830 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
832 if(IsDifferentTeam(victim, attacker))
836 if(deathtype != DEATH_FIRE)
838 if(victim.BUTTON_CHAT)
839 attacker.typehitsound += 1;
841 attacker.hitsound += 1;
844 damage_goodhits += 1;
845 damage_gooddamage += damage;
847 if not(DEATH_ISSPECIAL(deathtype))
849 if(targ.classname == "player") // don't do this for vehicles
855 if(victim.items & IT_STRENGTH)
858 if(deathtype & HITTYPE_HEADSHOT)
862 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
867 if(deathtype != DEATH_FIRE)
869 attacker.typehitsound += 1;
872 if(time > attacker.teamkill_complain)
874 attacker.teamkill_complain = time + 5;
875 attacker.teamkill_soundtime = time + 0.4;
876 attacker.teamkill_soundsource = targ;
884 if (self.damageforcescale)
886 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
888 self.velocity = self.velocity + damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
889 self.flags &~= FL_ONGROUND;
890 UpdateCSQCProjectile(self);
893 if (damage != 0 || (self.damageforcescale && vlen(force)))
894 if (self.event_damage)
895 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
898 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
902 if (attacker.runes & RUNE_VAMPIRE)
904 // apply vampire rune
905 if (attacker.runes & CURSE_EMPATHY) // have the curse too
907 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
908 attacker.health = bound(
909 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
910 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
911 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
915 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
916 attacker.health = bound(
917 attacker.health, // LA: was 3, but changed so that you can't lose health
918 // empathy won't let you gain health in the same way...
919 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
920 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
923 // apply empathy curse
924 else if (attacker.runes & CURSE_EMPATHY)
926 attacker.health = bound(
927 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
928 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
934 // apply mirror damage if any
935 if(mirrordamage > 0 || mirrorforce > 0)
937 attacker = attacker_save;
941 // just lose extra LIVES, don't kill the player for mirror damage
942 if(attacker.armorvalue > 0)
944 attacker.armorvalue = attacker.armorvalue - 1;
945 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
946 attacker.hitsound += 1;
951 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
952 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
956 float RadiusDamage_running;
957 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
958 // Returns total damage applies to creatures
968 float total_damage_to_creatures;
973 float stat_damagedone;
975 if(RadiusDamage_running)
977 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
981 RadiusDamage_running = 1;
983 tfloordmg = autocvar_g_throughfloor_damage;
984 tfloorforce = autocvar_g_throughfloor_force;
986 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
987 total_damage_to_creatures = 0;
989 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
990 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
992 force = inflictor.velocity;
996 force = normalize(force);
997 if(forceintensity >= 0)
998 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
1000 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
1003 stat_damagedone = 0;
1005 targ = WarpZone_FindRadius (blastorigin, rad + MAX_DAMAGEEXTRARADIUS, FALSE);
1009 if (targ != inflictor)
1010 if (ignore != targ) if(targ.takedamage)
1012 // LordHavoc: measure distance to nearest point on target (not origin)
1013 // (this guarentees 100% damage on a touch impact)
1014 nearest = targ.WarpZone_findradius_nearest;
1015 diff = targ.WarpZone_findradius_dist;
1016 // round up a little on the damage to ensure full damage on impacts
1017 // and turn the distance into a fraction of the radius
1018 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
1020 //bprint(ftos(power));
1021 //if (targ == attacker)
1022 // print(ftos(power), "\n");
1027 finaldmg = coredamage * power + edgedamage * (1 - power);
1036 vector myblastorigin;
1037 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1038 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1039 // if it's a player, use the view origin as reference
1040 if (targ.classname == "player")
1041 center = targ.origin + targ.view_ofs;
1042 force = normalize(center - myblastorigin);
1043 force = force * (finaldmg / coredamage) * forceintensity;
1044 // test line of sight to multiple positions on box,
1045 // and do damage if any of them hit
1047 if (targ.classname == "player")
1048 total = ceil(bound(1, finaldmg, 50));
1050 total = ceil(bound(1, finaldmg/10, 5));
1055 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1056 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1057 if (trace_fraction == 1 || trace_ent == targ)
1061 hitloc = hitloc + nearest;
1065 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1066 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1067 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1070 nearest = hitloc * (1 / max(1, hits));
1071 hitratio = (hits / total);
1072 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1073 finaldmg = finaldmg * a;
1074 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1077 // laser force adjustments :P
1078 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1080 if (targ == attacker)
1085 float force_velocitybiasramp;
1086 float force_velocitybias;
1088 force_velocitybiasramp = autocvar_sv_maxspeed;
1089 if(deathtype & HITTYPE_SECONDARY)
1091 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1092 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1096 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1097 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1100 vel = targ.velocity;
1102 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1106 normalize(normalize(force) + vel);
1108 force_z *= force_zscale;
1112 if(deathtype & HITTYPE_SECONDARY)
1114 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1118 force *= autocvar_g_balance_laser_primary_force_other_scale;
1123 //if (targ == attacker)
1125 // print("hits ", ftos(hits), " / ", ftos(total));
1126 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1127 // print(" (", ftos(a), ")\n");
1129 if(hits || tfloordmg || tfloorforce)
1133 total_damage_to_creatures += finaldmg;
1135 if(accuracy_isgooddamage(attacker, targ))
1136 stat_damagedone += finaldmg;
1139 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1140 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1142 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1150 RadiusDamage_running = 0;
1152 if(!DEATH_ISSPECIAL(deathtype))
1153 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1155 return total_damage_to_creatures;
1158 .float fire_damagepersec;
1159 .float fire_endtime;
1160 .float fire_deathtype;
1162 .float fire_hitsound;
1163 .entity fire_burner;
1165 void fireburner_think();
1167 float Fire_IsBurning(entity e)
1169 return (time < e.fire_endtime);
1172 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1175 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1177 if(e.classname == "player")
1186 // print("adding a fire burner to ", e.classname, "\n");
1187 e.fire_burner = spawn();
1188 e.fire_burner.classname = "fireburner";
1189 e.fire_burner.think = fireburner_think;
1190 e.fire_burner.nextthink = time;
1191 e.fire_burner.owner = e;
1197 if(Fire_IsBurning(e))
1199 mintime = e.fire_endtime - time;
1200 maxtime = max(mintime, t);
1202 mindps = e.fire_damagepersec;
1203 maxdps = max(mindps, dps);
1205 if(maxtime > mintime || maxdps > mindps)
1207 mindamage = mindps * mintime;
1208 maxdamage = mindamage + d;
1210 // interval [mintime, maxtime] * [mindps, maxdps]
1212 // [mindamage, maxdamage]
1215 if(maxdamage >= maxtime * maxdps)
1217 totaltime = maxtime;
1218 totaldamage = maxtime * maxdps;
1220 // this branch increases totaldamage if either t > mintime, or dps > mindps
1224 // maxdamage is inside the interval!
1225 // first, try to use mindps; only if this fails, increase dps as needed
1226 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1227 totaldamage = maxdamage;
1228 // can totaldamage / totaltime be >= maxdps?
1229 // max(mindps, maxdamage / maxtime) >= maxdps?
1230 // we know maxdamage < maxtime * maxdps
1233 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1236 // total conditions for increasing:
1237 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1239 // if maxtime = mintime, maxdps = mindps
1241 // maxdamage = mindamage + d
1242 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1243 // so the last condition is not needed
1245 e.fire_damagepersec = totaldamage / totaltime;
1246 e.fire_endtime = time + totaltime;
1247 if(totaldamage > 1.2 * mindamage)
1249 e.fire_deathtype = dt;
1250 if(e.fire_owner != o)
1253 e.fire_hitsound = FALSE;
1256 if(accuracy_isgooddamage(o, e))
1257 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1258 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1265 e.fire_damagepersec = dps;
1266 e.fire_endtime = time + t;
1267 e.fire_deathtype = dt;
1269 e.fire_hitsound = FALSE;
1270 if(accuracy_isgooddamage(o, e))
1271 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1276 void Fire_ApplyDamage(entity e)
1281 if not(Fire_IsBurning(e))
1284 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1285 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1288 // water and slime stop fire
1290 if(e.watertype != CONTENT_LAVA)
1294 if(e.freezetag_frozen)
1297 t = min(frametime, e.fire_endtime - time);
1298 d = e.fire_damagepersec * t;
1300 hi = e.fire_owner.hitsound;
1301 ty = e.fire_owner.typehitsound;
1302 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1303 if(e.fire_hitsound && e.fire_owner)
1305 e.fire_owner.hitsound = hi;
1306 e.fire_owner.typehitsound = ty;
1308 e.fire_hitsound = TRUE;
1310 if not(IS_INDEPENDENT_PLAYER(e))
1311 FOR_EACH_PLAYER(other) if(e != other)
1313 if(other.classname == "player")
1314 if(other.deadflag == DEAD_NO)
1315 if not(IS_INDEPENDENT_PLAYER(other))
1316 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1318 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1319 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1320 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1325 void Fire_ApplyEffect(entity e)
1327 if(Fire_IsBurning(e))
1328 e.effects |= EF_FLAME;
1330 e.effects &~= EF_FLAME;
1333 void fireburner_think()
1335 // for players, this is done in the regular loop
1336 if(wasfreed(self.owner))
1341 Fire_ApplyEffect(self.owner);
1342 if(!Fire_IsBurning(self.owner))
1344 self.owner.fire_burner = world;
1348 Fire_ApplyDamage(self.owner);
1349 self.nextthink = time;