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;
59 .float taunt_soundtime;
62 float IsDifferentTeam(entity a, entity b)
77 float IsFlying(entity a)
79 if(a.flags & FL_ONGROUND)
81 if(a.waterlevel >= WATERLEVEL_SWIMMING)
83 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
84 if(trace_fraction < 1)
89 vector GetHeadshotMins(entity targ)
91 return '-0.5 0 0' * PL_HEAD_x + '0 -0.5 0' * PL_HEAD_y + '0 0 1' * (targ.maxs_z - PL_HEAD_z);
93 vector GetHeadshotMaxs(entity targ)
95 return '0.5 0 0' * PL_HEAD_x + '0 0.5 0' * PL_HEAD_y + '0 0 1' * targ.maxs_z;
98 void UpdateFrags(entity player, float f)
100 PlayerTeamScore_AddScore(player, f);
103 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
104 void W_SwitchWeapon_Force(entity e, float w);
105 entity GiveFrags_randomweapons;
106 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);
145 culprit = attacker.weapon;
146 else if(!WEPSET_CONTAINS_EW(attacker, culprit))
147 culprit = attacker.weapon;
149 if(g_weaponarena_random_with_laser && culprit == WEP_LASER)
155 if(!GiveFrags_randomweapons)
157 GiveFrags_randomweapons = spawn();
158 GiveFrags_randomweapons.classname = "GiveFrags_randomweapons";
162 WEPSET_COPY_EA(GiveFrags_randomweapons, warmup_start_weapons);
164 WEPSET_COPY_EA(GiveFrags_randomweapons, start_weapons);
166 // all others (including the culprit): remove
167 WEPSET_ANDNOT_EE(GiveFrags_randomweapons, attacker);
168 WEPSET_ANDNOT_EW(GiveFrags_randomweapons, culprit);
170 // among the remaining ones, choose one by random
171 W_RandomWeapons(GiveFrags_randomweapons, 1);
173 if(!WEPSET_EMPTY_E(GiveFrags_randomweapons))
175 WEPSET_OR_EE(attacker, GiveFrags_randomweapons);
176 WEPSET_ANDNOT_EW(attacker, culprit);
180 // after a frag, choose another random weapon set
181 if not(WEPSET_CONTAINS_EW(attacker, attacker.weapon))
182 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
185 // FIXME fix the mess this is (we have REAL points now!)
189 frag_attacker = attacker;
192 if(MUTATOR_CALLHOOK(GiveFragsForKill))
202 f = RunematchHandleFrags(attacker, targ, f);
208 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
209 if(tl < lms_lowest_lives)
210 lms_lowest_lives = tl;
214 lms_next_place = player_count;
216 lms_next_place = min(lms_next_place, player_count);
217 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
224 if(g_ctf_ignore_frags)
229 attacker.totalfrags += f;
232 UpdateFrags(attacker, f);
235 string Obituary_ExtraFragInfo(entity player) // Extra fragmessage information
237 string health_output = string_null;
238 string ping_output = string_null;
239 string handicap_output = string_null;
240 string output = string_null;
242 if(autocvar_sv_fraginfo && ((autocvar_sv_fraginfo == 2) || inWarmupStage))
244 // health/armor of attacker (person who killed you)
245 if(autocvar_sv_fraginfo_stats && (player.health >= 1))
246 health_output = strcat("^7(Health ^1", ftos(rint(player.health)), "^7 / Armor ^2", ftos(rint(player.armorvalue)), "^7)");
249 if(autocvar_sv_fraginfo_ping)
250 ping_output = ((clienttype(player) == CLIENTTYPE_BOT) ? "^2Bot" : strcat("Ping ", ((player.ping >= 150) ? "^1" : "^2"), ftos(rint(player.ping)), "ms"));
253 if(autocvar_sv_fraginfo_handicap)
255 if(autocvar_sv_fraginfo_handicap == 2)
256 handicap_output = strcat(output, strcat("Handicap ^2", ((player.cvar_cl_handicap <= 1) ? "Off" : ftos(rint(player.cvar_cl_handicap)))));
257 else if(player.cvar_cl_handicap) // with _handicap 1, only show this if there actually is a handicap enabled.
258 handicap_output = strcat("Handicap ^2", ftos(rint(player.cvar_cl_handicap)));
262 output = strcat(health_output, (health_output ? ((ping_output || handicap_output) ? " ^7(" : "") : ((ping_output || handicap_output) ? "^7(" : "")),
263 ping_output, (handicap_output ? "^7 / " : ""),
264 handicap_output, ((ping_output || handicap_output) ? "^7)" : ""));
266 // add new line to the beginning if there is a message
267 if(output) { output = strcat("\n", output); }
273 string AppendItemcodes(string s, entity player)
278 // w = player.switchweapon;
280 w = player.cnt; // previous weapon!
281 s = strcat(s, ftos(w));
282 if(time < player.strength_finished)
284 if(time < player.invincible_finished)
286 if(player.flagcarried != world)
288 if(player.BUTTON_CHAT)
293 s = strcat(s, "|", ftos(player.runes));
297 void LogDeath(string mode, float deathtype, entity killer, entity killed)
300 if(!autocvar_sv_eventlog)
302 s = strcat(":kill:", mode);
303 s = strcat(s, ":", ftos(killer.playerid));
304 s = strcat(s, ":", ftos(killed.playerid));
305 s = strcat(s, ":type=", ftos(deathtype));
306 s = strcat(s, ":items=");
307 s = AppendItemcodes(s, killer);
310 s = strcat(s, ":victimitems=");
311 s = AppendItemcodes(s, killed);
316 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
318 WriteByte(MSG_ALL, SVC_TEMPENTITY);
319 WriteByte(MSG_ALL, TE_CSQC_KILLNOTIFY);
320 WriteString(MSG_ALL, s1);
321 WriteString(MSG_ALL, s2);
322 WriteString(MSG_ALL, s3);
323 WriteShort(MSG_ALL, msg);
324 WriteByte(MSG_ALL, type);
327 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
328 void Send_CSQC_KillCenterprint(entity e, string s1, string s2, float msg, float type)
330 if (clienttype(e) == CLIENTTYPE_REAL)
333 WRITESPECTATABLE_MSG_ONE({
334 WriteByte(MSG_ONE, SVC_TEMPENTITY);
335 WriteByte(MSG_ONE, TE_CSQC_KILLCENTERPRINT);
336 WriteString(MSG_ONE, s1);
337 WriteString(MSG_ONE, s2);
338 WriteShort(MSG_ONE, msg);
339 WriteByte(MSG_ONE, type);
344 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
349 if (targ.classname == "player")
352 a = attacker.netname;
354 if (targ == attacker) // suicides
356 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
357 msg = ColoredTeamName(targ.team); // TODO: check if needed?
360 if(!g_cts) // no "killed your own dumb self" message in CTS
361 Send_CSQC_KillCenterprint(targ, msg, "", deathtype, MSG_SUICIDE);
363 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
365 LogDeath("suicide", deathtype, targ, targ);
366 GiveFrags(attacker, targ, -1, deathtype);
369 if (targ.killcount > 2)
370 msg = ftos(targ.killcount);
373 if(teamplay && deathtype == DEATH_MIRRORDAMAGE)
375 if(attacker.team == COLOR_TEAM1)
376 deathtype = KILL_TEAM_RED;
378 deathtype = KILL_TEAM_BLUE;
381 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
383 else if (attacker.classname == "player")
385 if(!IsDifferentTeam(attacker, targ))
387 if(attacker.team == COLOR_TEAM1)
388 type = KILL_TEAM_RED;
390 type = KILL_TEAM_BLUE;
392 GiveFrags(attacker, targ, -1, deathtype);
394 Send_CSQC_KillCenterprint(attacker, s, "", type, MSG_KILL);
396 if (targ.killcount > 2)
397 msg = ftos(targ.killcount);
401 if (attacker.killcount > 2) {
402 msg = ftos(attacker.killcount);
403 type = KILL_TEAM_SPREE;
405 Send_KillNotification(a, s, msg, type, MSG_KILL);
407 attacker.killcount = 0;
409 LogDeath("tk", deathtype, attacker, targ);
413 if (!checkrules_firstblood)
415 checkrules_firstblood = TRUE;
416 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
417 // TODO: make these print a newline if they dont
418 Send_CSQC_KillCenterprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
419 Send_CSQC_KillCenterprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
420 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
421 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
424 if(targ.istypefrag) {
425 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_TYPEFRAG, MSG_KILL);
426 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_TYPEFRAGGED, MSG_KILL);
428 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_FRAG, MSG_KILL);
429 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_FRAGGED, MSG_KILL);
432 attacker.taunt_soundtime = time + 1;
434 if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
435 msg = inflictor.message2;
436 else if (deathtype == DEATH_CUSTOM)
441 if(strstrofs(msg, "%", 0) < 0)
442 msg = strcat("%s ", msg, " by %s");
444 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
446 if(g_ctf && targ.flagcarried)
448 UpdateFrags(attacker, ctf_score_value("score_kill"));
449 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
450 GiveFrags(attacker, targ, 0, deathtype); // for logging
453 GiveFrags(attacker, targ, 1, deathtype);
455 if (targ.killcount > 2) {
456 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
459 attacker.killcount = attacker.killcount + 1;
461 if (attacker.killcount > 2) {
462 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
464 else if (attacker.killcount == 3)
466 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
467 AnnounceTo(attacker, "03kills");
468 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
470 else if (attacker.killcount == 5)
472 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
473 AnnounceTo(attacker, "05kills");
474 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
476 else if (attacker.killcount == 10)
478 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
479 AnnounceTo(attacker, "10kills");
480 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
482 else if (attacker.killcount == 15)
484 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
485 AnnounceTo(attacker, "15kills");
486 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
488 else if (attacker.killcount == 20)
490 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
491 AnnounceTo(attacker, "20kills");
492 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
494 else if (attacker.killcount == 25)
496 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
497 AnnounceTo(attacker, "25kills");
498 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
500 else if (attacker.killcount == 30)
502 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
503 AnnounceTo(attacker, "30kills");
504 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
506 LogDeath("frag", deathtype, attacker, targ);
511 Send_CSQC_KillCenterprint(targ, "", "", deathtype, MSG_KILL_ACTION);
512 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
513 msg = inflictor.message;
514 else if (deathtype == DEATH_CUSTOM)
518 if(strstrofs(msg, "%", 0) < 0)
519 msg = strcat("%s ", msg);
521 GiveFrags(targ, targ, -1, deathtype);
522 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
523 AnnounceTo(targ, "botlike");
524 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
526 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
528 if (targ.killcount > 2)
529 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
531 LogDeath("accident", deathtype, targ, targ);
534 targ.death_origin = targ.origin;
536 targ.killer_origin = attacker.origin;
538 // FIXME: this should go in PutClientInServer
544 // these are updated by each Damage call for use in button triggering and such
546 entity damage_inflictor;
547 entity damage_attacker;
549 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
554 entity attacker_save;
558 if (gameover || targ.killcount == -666)
565 damage_inflictor = inflictor;
566 damage_attacker = attacker;
567 attacker_save = attacker;
569 if(targ.classname == "player")
572 if(targ.hook.aiment == attacker)
573 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
575 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
576 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
578 if(targ.classname == "player")
579 if not(IsDifferentTeam(targ, attacker))
586 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
588 // These are ALWAYS lethal
589 // No damage modification here
590 // Instead, prepare the victim for his death...
592 targ.spawnshieldtime = 0;
593 targ.health = 0.9; // this is < 1
594 targ.flags -= targ.flags & FL_GODMODE;
597 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
604 skill based bot damage? gtfo. (tZork)
605 if (targ.classname == "player")
606 if (attacker.classname == "player")
609 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
612 // nullify damage if teamplay is on
613 if(deathtype != DEATH_TELEFRAG)
614 if(attacker.classname == "player")
616 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
621 else if(!IsDifferentTeam(attacker, targ))
623 if(autocvar_teamplay_mode == 1)
625 else if(attacker != targ)
627 if(autocvar_teamplay_mode == 3)
629 else if(autocvar_teamplay_mode == 4)
631 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
633 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
634 attacker.dmg_team = attacker.dmg_team + damage;
635 if(attacker.dmg_team > teamdamage0 && !g_ca)
636 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
637 mirrorforce = autocvar_g_mirrordamage * vlen(force);
640 if(autocvar_g_friendlyfire == 0)
646 damage = autocvar_g_friendlyfire * damage;
647 // mirrordamage will be used LATER
649 if(autocvar_g_mirrordamage_virtual)
651 vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
652 attacker.dmg_take += v_x;
653 attacker.dmg_save += v_y;
654 attacker.dmg_inflictor = inflictor;
659 if(autocvar_g_friendlyfire_virtual)
661 vector v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
662 targ.dmg_take += v_x;
663 targ.dmg_save += v_y;
664 targ.dmg_inflictor = inflictor;
666 if(!autocvar_g_friendlyfire_virtual_force)
677 if(targ.classname == "player")
678 if(attacker.classname == "player")
681 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
682 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
685 if(targ.classname == "player")
688 if ((deathtype == DEATH_FALL) ||
689 (deathtype == DEATH_DROWN) ||
690 (deathtype == DEATH_SLIME) ||
691 (deathtype == DEATH_LAVA) ||
692 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
699 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
701 targ.armorvalue -= 1;
702 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
705 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
707 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
711 if (targ != attacker)
713 if ((targ.health >= 1) && (targ.classname == "player"))
714 centerprint(attacker, "Secondary fire inflicts no damage!");
722 if not(DEATH_ISSPECIAL(deathtype))
724 damage *= g_weapondamagefactor;
725 mirrordamage *= g_weapondamagefactor;
726 force = force * g_weaponforcefactor;
727 mirrorforce *= g_weaponforcefactor;
730 // should this be changed at all? If so, in what way?
731 frag_attacker = attacker;
733 frag_damage = damage;
735 frag_deathtype = deathtype;
736 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
737 damage = frag_damage;
740 // apply strength multiplier
741 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
745 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
746 force = force * autocvar_g_balance_powerup_strength_selfforce;
750 damage = damage * autocvar_g_balance_powerup_strength_damage;
751 force = force * autocvar_g_balance_powerup_strength_force;
755 // apply invincibility multiplier
756 if (targ.items & IT_INVINCIBLE && !g_minstagib)
757 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
759 if (targ == attacker)
761 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
764 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
767 // CTF: reduce damage/force
772 damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
773 force = force * autocvar_g_ctf_flagcarrier_selfforce;
778 // apply strength rune
779 if (attacker.runes & RUNE_STRENGTH)
781 if(attacker.runes & CURSE_WEAK) // have both curse & rune
783 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
784 force = force * autocvar_g_balance_rune_strength_combo_force;
788 damage = damage * autocvar_g_balance_rune_strength_damage;
789 force = force * autocvar_g_balance_rune_strength_force;
792 else if (attacker.runes & CURSE_WEAK)
794 damage = damage * autocvar_g_balance_curse_weak_damage;
795 force = force * autocvar_g_balance_curse_weak_force;
798 // apply defense rune
799 if (targ.runes & RUNE_DEFENSE)
801 if (targ.runes & CURSE_VULNER) // have both curse & rune
802 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
804 damage = damage * autocvar_g_balance_rune_defense_takedamage;
806 else if (targ.runes & CURSE_VULNER)
807 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
813 if(targ.takedamage == DAMAGE_AIM)
816 if(damage_headshotbonus)
818 if(targ.classname == "player")
821 // find height of hit on player axis
822 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
823 vector headmins, headmaxs, org;
824 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
825 headmins = org + GetHeadshotMins(targ);
826 headmaxs = org + GetHeadshotMaxs(targ);
827 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
829 deathtype |= HITTYPE_HEADSHOT;
832 else if(targ.classname == "turret_head")
834 deathtype |= HITTYPE_HEADSHOT;
836 if(deathtype & HITTYPE_HEADSHOT)
837 if(damage_headshotbonus > 0)
838 damage *= 1 + damage_headshotbonus;
842 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
847 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
849 if(IsDifferentTeam(victim, attacker))
853 if(deathtype != DEATH_FIRE)
855 if(victim.BUTTON_CHAT)
856 attacker.typehitsound += 1;
858 attacker.hitsound += 1;
861 damage_goodhits += 1;
862 damage_gooddamage += damage;
864 if not(DEATH_ISSPECIAL(deathtype))
866 if(targ.classname == "player") // don't do this for vehicles
872 if(victim.items & IT_STRENGTH)
875 if(deathtype & HITTYPE_HEADSHOT)
879 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
884 if(deathtype != DEATH_FIRE)
886 attacker.typehitsound += 1;
889 if(time > attacker.teamkill_complain)
891 attacker.teamkill_complain = time + 5;
892 attacker.teamkill_soundtime = time + 0.4;
893 attacker.teamkill_soundsource = targ;
901 if (self.damageforcescale)
903 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
905 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
906 if(self.movetype == MOVETYPE_PHYSICS)
910 farcent.classname = "farce";
911 farcent.enemy = self;
912 farcent.movedir = farce * 10;
914 farcent.movedir = farcent.movedir * self.mass;
915 farcent.origin = hitloc;
916 farcent.forcetype = FORCETYPE_FORCEATPOS;
917 farcent.nextthink = time + 0.1;
918 farcent.think = SUB_Remove;
921 self.velocity = self.velocity + farce;
922 self.flags &~= FL_ONGROUND;
923 UpdateCSQCProjectile(self);
926 if (damage != 0 || (self.damageforcescale && vlen(force)))
927 if (self.event_damage)
928 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
931 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
935 if (attacker.runes & RUNE_VAMPIRE)
937 // apply vampire rune
938 if (attacker.runes & CURSE_EMPATHY) // have the curse too
940 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
941 attacker.health = bound(
942 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
943 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
944 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
948 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
949 attacker.health = bound(
950 attacker.health, // LA: was 3, but changed so that you can't lose health
951 // empathy won't let you gain health in the same way...
952 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
953 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
956 // apply empathy curse
957 else if (attacker.runes & CURSE_EMPATHY)
959 attacker.health = bound(
960 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
961 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
967 // apply mirror damage if any
968 if(mirrordamage > 0 || mirrorforce > 0)
970 attacker = attacker_save;
974 // just lose extra LIVES, don't kill the player for mirror damage
975 if(attacker.armorvalue > 0)
977 attacker.armorvalue = attacker.armorvalue - 1;
978 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
979 attacker.hitsound += 1;
984 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
985 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
989 float RadiusDamage_running;
990 float RadiusDamageForSource (entity inflictor, vector inflictororigin, vector inflictorvelocity, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float inflictorselfdamage, float forceintensity, float deathtype, entity directhitentity)
991 // Returns total damage applies to creatures
995 float total_damage_to_creatures;
1000 float stat_damagedone;
1002 if(RadiusDamage_running)
1004 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
1008 RadiusDamage_running = 1;
1010 tfloordmg = autocvar_g_throughfloor_damage;
1011 tfloorforce = autocvar_g_throughfloor_force;
1013 total_damage_to_creatures = 0;
1015 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1016 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
1018 force = inflictorvelocity;
1019 if(vlen(force) == 0)
1022 force = normalize(force);
1023 if(forceintensity >= 0)
1024 Damage_DamageInfo(inflictororigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
1026 Damage_DamageInfo(inflictororigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
1029 stat_damagedone = 0;
1031 targ = WarpZone_FindRadius (inflictororigin, rad + MAX_DAMAGEEXTRARADIUS, FALSE);
1035 if ((targ != inflictor) || inflictorselfdamage)
1036 if (((cantbe != targ) && !mustbe) || (mustbe == targ))
1037 if (targ.takedamage)
1043 // LordHavoc: measure distance to nearest point on target (not origin)
1044 // (this guarentees 100% damage on a touch impact)
1045 nearest = targ.WarpZone_findradius_nearest;
1046 diff = targ.WarpZone_findradius_dist;
1047 // round up a little on the damage to ensure full damage on impacts
1048 // and turn the distance into a fraction of the radius
1049 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
1051 //bprint(ftos(power));
1052 //if (targ == attacker)
1053 // print(ftos(power), "\n");
1059 finaldmg = coredamage * power + edgedamage * (1 - power);
1065 vector myblastorigin;
1068 myblastorigin = WarpZone_TransformOrigin(targ, inflictororigin);
1070 // if it's a player, use the view origin as reference
1071 if (targ.classname == "player")
1072 center = targ.origin + targ.view_ofs;
1074 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1076 force = normalize(center - myblastorigin);
1077 force = force * (finaldmg / coredamage) * forceintensity;
1080 if(targ != directhitentity)
1085 float mininv_f, mininv_d;
1087 // test line of sight to multiple positions on box,
1088 // and do damage if any of them hit
1091 // we know: max stddev of hitratio = 1 / (2 * sqrt(n))
1092 // so for a given max stddev:
1093 // n = (1 / (2 * max stddev of hitratio))^2
1095 mininv_d = (finaldmg * (1-tfloordmg)) / autocvar_g_throughfloor_damage_max_stddev;
1096 mininv_f = (vlen(force) * (1-tfloorforce)) / autocvar_g_throughfloor_force_max_stddev;
1098 if(autocvar_g_throughfloor_debug)
1099 print(sprintf("THROUGHFLOOR: D=%f F=%f max(dD)=1/%f max(dF)=1/%f", finaldmg, vlen(force), mininv_d, mininv_f));
1101 total = 0.25 * pow(max(mininv_f, mininv_d), 2);
1103 if(autocvar_g_throughfloor_debug)
1104 print(sprintf(" steps=%f", total));
1106 if (targ.classname == "player")
1107 total = ceil(bound(autocvar_g_throughfloor_min_steps_player, total, autocvar_g_throughfloor_max_steps_player));
1109 total = ceil(bound(autocvar_g_throughfloor_min_steps_other, total, autocvar_g_throughfloor_max_steps_other));
1111 if(autocvar_g_throughfloor_debug)
1112 print(sprintf(" steps=%f dD=%f dF=%f", total, finaldmg * (1-tfloordmg) / (2 * sqrt(total)), vlen(force) * (1-tfloorforce) / (2 * sqrt(total))));
1114 for(c = 0; c < total; ++c)
1116 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1117 WarpZone_TraceLine(inflictororigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1118 if (trace_fraction == 1 || trace_ent == targ)
1122 hitloc = hitloc + nearest;
1126 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1127 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1128 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1131 nearest = hitloc * (1 / max(1, hits));
1132 hitratio = (hits / total);
1133 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1134 finaldmg = finaldmg * a;
1135 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1138 if(autocvar_g_throughfloor_debug)
1139 print(sprintf(" D=%f F=%f\n", finaldmg, vlen(force)));
1142 //if (targ == attacker)
1144 // print("hits ", ftos(hits), " / ", ftos(total));
1145 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1146 // print(" (", ftos(a), ")\n");
1148 if(finaldmg || vlen(force))
1152 total_damage_to_creatures += finaldmg;
1154 if(accuracy_isgooddamage(attacker, targ))
1155 stat_damagedone += finaldmg;
1158 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1159 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1161 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1169 RadiusDamage_running = 0;
1171 if(!DEATH_ISSPECIAL(deathtype))
1172 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1174 return total_damage_to_creatures;
1177 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, float deathtype, entity directhitentity)
1179 return RadiusDamageForSource (inflictor, (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5), inflictor.velocity, attacker, coredamage, edgedamage, rad, cantbe, mustbe, FALSE, forceintensity, deathtype, directhitentity);
1182 .float fire_damagepersec;
1183 .float fire_endtime;
1184 .float fire_deathtype;
1186 .float fire_hitsound;
1187 .entity fire_burner;
1189 void fireburner_think();
1191 float Fire_IsBurning(entity e)
1193 return (time < e.fire_endtime);
1196 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1199 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1201 if(e.classname == "player")
1210 // print("adding a fire burner to ", e.classname, "\n");
1211 e.fire_burner = spawn();
1212 e.fire_burner.classname = "fireburner";
1213 e.fire_burner.think = fireburner_think;
1214 e.fire_burner.nextthink = time;
1215 e.fire_burner.owner = e;
1221 if(Fire_IsBurning(e))
1223 mintime = e.fire_endtime - time;
1224 maxtime = max(mintime, t);
1226 mindps = e.fire_damagepersec;
1227 maxdps = max(mindps, dps);
1229 if(maxtime > mintime || maxdps > mindps)
1233 // damage we have right now
1234 mindamage = mindps * mintime;
1236 // damage we want to get
1237 maxdamage = mindamage + d;
1239 // but we can't exceed maxtime * maxdps!
1240 totaldamage = min(maxdamage, maxtime * maxdps);
1244 // totaldamage = min(mindamage + d, maxtime * maxdps)
1246 // totaldamage <= maxtime * maxdps
1247 // ==> totaldamage / maxdps <= maxtime.
1249 // totaldamage / mindps = min(mindamage / mindps + d, maxtime * maxdps / mindps)
1250 // >= min(mintime, maxtime)
1251 // ==> totaldamage / maxdps >= mintime.
1254 // how long do we damage then?
1255 // at least as long as before
1256 // but, never exceed maxdps
1257 totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime due to lemma
1261 // at most as long as maximum allowed
1262 // but, never below mindps
1263 totaltime = min(maxtime, totaldamage / mindps); // always >= mintime due to lemma
1265 // assuming t > mintime, dps > mindps:
1266 // we get d = t * dps = maxtime * maxdps
1267 // totaldamage = min(maxdamage, maxtime * maxdps) = min(... + d, maxtime * maxdps) = maxtime * maxdps
1268 // totaldamage / maxdps = maxtime
1269 // totaldamage / mindps > totaldamage / maxdps = maxtime
1271 // a) totaltime = max(mintime, maxtime) = maxtime
1272 // b) totaltime = min(maxtime, totaldamage / maxdps) = maxtime
1274 // assuming t <= mintime:
1275 // we get maxtime = mintime
1276 // a) totaltime = max(mintime, ...) >= mintime, also totaltime <= maxtime by the lemma, therefore totaltime = mintime = maxtime
1277 // b) totaltime = min(maxtime, ...) <= maxtime, also totaltime >= mintime by the lemma, therefore totaltime = mintime = maxtime
1279 // assuming dps <= mindps:
1280 // we get mindps = maxdps.
1281 // With this, the lemma says that mintime <= totaldamage / mindps = totaldamage / maxdps <= maxtime.
1282 // a) totaltime = max(mintime, totaldamage / maxdps) = totaldamage / maxdps
1283 // b) totaltime = min(maxtime, totaldamage / mindps) = totaldamage / maxdps
1285 e.fire_damagepersec = totaldamage / totaltime;
1286 e.fire_endtime = time + totaltime;
1287 if(totaldamage > 1.2 * mindamage)
1289 e.fire_deathtype = dt;
1290 if(e.fire_owner != o)
1293 e.fire_hitsound = FALSE;
1296 if(accuracy_isgooddamage(o, e))
1297 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1298 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1305 e.fire_damagepersec = dps;
1306 e.fire_endtime = time + t;
1307 e.fire_deathtype = dt;
1309 e.fire_hitsound = FALSE;
1310 if(accuracy_isgooddamage(o, e))
1311 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1316 void Fire_ApplyDamage(entity e)
1321 if not(Fire_IsBurning(e))
1324 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1325 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1328 // water and slime stop fire
1330 if(e.watertype != CONTENT_LAVA)
1334 if(e.freezetag_frozen)
1337 t = min(frametime, e.fire_endtime - time);
1338 d = e.fire_damagepersec * t;
1340 hi = e.fire_owner.hitsound;
1341 ty = e.fire_owner.typehitsound;
1342 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1343 if(e.fire_hitsound && e.fire_owner)
1345 e.fire_owner.hitsound = hi;
1346 e.fire_owner.typehitsound = ty;
1348 e.fire_hitsound = TRUE;
1350 if not(IS_INDEPENDENT_PLAYER(e))
1351 FOR_EACH_PLAYER(other) if(e != other)
1353 if(other.classname == "player")
1354 if(other.deadflag == DEAD_NO)
1355 if not(IS_INDEPENDENT_PLAYER(other))
1356 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1358 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1359 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1360 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1365 void Fire_ApplyEffect(entity e)
1367 if(Fire_IsBurning(e))
1368 e.effects |= EF_FLAME;
1370 e.effects &~= EF_FLAME;
1373 void fireburner_think()
1375 // for players, this is done in the regular loop
1376 if(wasfreed(self.owner))
1381 Fire_ApplyEffect(self.owner);
1382 if(!Fire_IsBurning(self.owner))
1384 self.owner.fire_burner = world;
1388 Fire_ApplyDamage(self.owner);
1389 self.nextthink = time;