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 entity GiveFrags_randomweapons;
105 void GiveFrags (entity attacker, entity targ, float f, float deathtype)
107 // TODO route through PlayerScores instead
115 PlayerScore_Add(attacker, SP_SUICIDES, 1);
120 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
126 PlayerScore_Add(attacker, SP_KILLS, 1);
128 PlayerStats_Event(attacker, sprintf("kills-%d", targ.playerid), 1);
131 PlayerScore_Add(targ, SP_DEATHS, 1);
134 if(autocvar_g_arena_roundbased)
137 if(targ != attacker) // not for suicides
138 if(g_weaponarena_random)
140 // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
142 culprit = DEATH_WEAPONOF(deathtype);
144 culprit = attacker.weapon;
145 else if(!WEPSET_CONTAINS_EW(attacker, culprit))
146 culprit = attacker.weapon;
148 if(g_weaponarena_random_with_laser && culprit == WEP_LASER)
154 if(!GiveFrags_randomweapons)
156 GiveFrags_randomweapons = spawn();
157 GiveFrags_randomweapons.classname = "GiveFrags_randomweapons";
161 WEPSET_COPY_EA(GiveFrags_randomweapons, warmup_start_weapons);
163 WEPSET_COPY_EA(GiveFrags_randomweapons, start_weapons);
165 // all others (including the culprit): remove
166 WEPSET_ANDNOT_EE(GiveFrags_randomweapons, attacker);
167 WEPSET_ANDNOT_EW(GiveFrags_randomweapons, culprit);
169 // among the remaining ones, choose one by random
170 W_RandomWeapons(GiveFrags_randomweapons, 1);
172 if(!WEPSET_EMPTY_E(GiveFrags_randomweapons))
174 WEPSET_OR_EE(attacker, GiveFrags_randomweapons);
175 WEPSET_ANDNOT_EW(attacker, culprit);
179 // after a frag, choose another random weapon set
180 if not(WEPSET_CONTAINS_EW(attacker, attacker.weapon))
181 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
184 // FIXME fix the mess this is (we have REAL points now!)
188 frag_attacker = attacker;
191 if(MUTATOR_CALLHOOK(GiveFragsForKill))
201 f = RunematchHandleFrags(attacker, targ, f);
207 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
208 if(tl < lms_lowest_lives)
209 lms_lowest_lives = tl;
213 lms_next_place = player_count;
215 lms_next_place = min(lms_next_place, player_count);
216 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
223 if(g_ctf_ignore_frags)
228 attacker.totalfrags += f;
231 UpdateFrags(attacker, f);
234 string Obituary_ExtraFragInfo(entity player) // Extra fragmessage information
236 string health_output = string_null;
237 string ping_output = string_null;
238 string handicap_output = string_null;
239 string output = string_null;
241 if(autocvar_sv_fraginfo && ((autocvar_sv_fraginfo == 2) || inWarmupStage))
243 // health/armor of attacker (person who killed you)
244 if(autocvar_sv_fraginfo_stats && (player.health >= 1))
245 health_output = strcat("^7(Health ^1", ftos(rint(player.health)), "^7 / Armor ^2", ftos(rint(player.armorvalue)), "^7)");
248 if(autocvar_sv_fraginfo_ping)
249 ping_output = ((clienttype(player) == CLIENTTYPE_BOT) ? "^2Bot" : strcat("Ping ", ((player.ping >= 150) ? "^1" : "^2"), ftos(rint(player.ping)), "ms"));
252 if(autocvar_sv_fraginfo_handicap)
254 if(autocvar_sv_fraginfo_handicap == 2)
255 handicap_output = strcat(output, strcat("Handicap ^2", ((player.cvar_cl_handicap <= 1) ? "Off" : ftos(rint(player.cvar_cl_handicap)))));
256 else if(player.cvar_cl_handicap) // with _handicap 1, only show this if there actually is a handicap enabled.
257 handicap_output = strcat("Handicap ^2", ftos(rint(player.cvar_cl_handicap)));
261 output = strcat(health_output, (health_output ? ((ping_output || handicap_output) ? " ^7(" : "") : ((ping_output || handicap_output) ? "^7(" : "")),
262 ping_output, (handicap_output ? "^7 / " : ""),
263 handicap_output, ((ping_output || handicap_output) ? "^7)" : ""));
265 // add new line to the beginning if there is a message
266 if(output) { output = strcat("\n", output); }
272 string AppendItemcodes(string s, entity player)
277 // w = player.switchweapon;
279 w = player.cnt; // previous weapon!
280 s = strcat(s, ftos(w));
281 if(time < player.strength_finished)
283 if(time < player.invincible_finished)
285 if(player.flagcarried != world)
287 if(player.BUTTON_CHAT)
292 s = strcat(s, "|", ftos(player.runes));
296 void LogDeath(string mode, float deathtype, entity killer, entity killed)
299 if(!autocvar_sv_eventlog)
301 s = strcat(":kill:", mode);
302 s = strcat(s, ":", ftos(killer.playerid));
303 s = strcat(s, ":", ftos(killed.playerid));
304 s = strcat(s, ":type=", ftos(deathtype));
305 s = strcat(s, ":items=");
306 s = AppendItemcodes(s, killer);
309 s = strcat(s, ":victimitems=");
310 s = AppendItemcodes(s, killed);
315 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
317 WriteByte(MSG_ALL, SVC_TEMPENTITY);
318 WriteByte(MSG_ALL, TE_CSQC_KILLNOTIFY);
319 WriteString(MSG_ALL, s1);
320 WriteString(MSG_ALL, s2);
321 WriteString(MSG_ALL, s3);
322 WriteShort(MSG_ALL, msg);
323 WriteByte(MSG_ALL, type);
326 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
327 void Send_CSQC_KillCenterprint(entity e, string s1, string s2, float msg, float type)
329 if (clienttype(e) == CLIENTTYPE_REAL)
332 WRITESPECTATABLE_MSG_ONE({
333 WriteByte(MSG_ONE, SVC_TEMPENTITY);
334 WriteByte(MSG_ONE, TE_CSQC_KILLCENTERPRINT);
335 WriteString(MSG_ONE, s1);
336 WriteString(MSG_ONE, s2);
337 WriteShort(MSG_ONE, msg);
338 WriteByte(MSG_ONE, type);
343 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
348 if (targ.classname == "player")
351 a = attacker.netname;
353 if (targ == attacker) // suicides
355 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
356 msg = ColoredTeamName(targ.team); // TODO: check if needed?
359 if(!g_cts) // no "killed your own dumb self" message in CTS
360 Send_CSQC_KillCenterprint(targ, msg, "", deathtype, MSG_SUICIDE);
362 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
364 LogDeath("suicide", deathtype, targ, targ);
365 GiveFrags(attacker, targ, -1, deathtype);
368 if (targ.killcount > 2)
369 msg = ftos(targ.killcount);
372 if(teamplay && deathtype == DEATH_MIRRORDAMAGE)
374 if(attacker.team == COLOR_TEAM1)
375 deathtype = KILL_TEAM_RED;
377 deathtype = KILL_TEAM_BLUE;
380 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
382 else if (attacker.classname == "player")
384 if(!IsDifferentTeam(attacker, targ))
386 if(attacker.team == COLOR_TEAM1)
387 type = KILL_TEAM_RED;
389 type = KILL_TEAM_BLUE;
391 GiveFrags(attacker, targ, -1, deathtype);
393 Send_CSQC_KillCenterprint(attacker, s, "", type, MSG_KILL);
395 if (targ.killcount > 2)
396 msg = ftos(targ.killcount);
400 if (attacker.killcount > 2) {
401 msg = ftos(attacker.killcount);
402 type = KILL_TEAM_SPREE;
404 Send_KillNotification(a, s, msg, type, MSG_KILL);
406 attacker.killcount = 0;
408 LogDeath("tk", deathtype, attacker, targ);
412 if (!checkrules_firstblood)
414 checkrules_firstblood = TRUE;
415 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
416 // TODO: make these print a newline if they dont
417 Send_CSQC_KillCenterprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
418 Send_CSQC_KillCenterprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
419 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
420 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
423 if(targ.BUTTON_CHAT) {
424 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_TYPEFRAG, MSG_KILL);
425 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_TYPEFRAGGED, MSG_KILL);
427 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_FRAG, MSG_KILL);
428 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_FRAGGED, MSG_KILL);
431 attacker.taunt_soundtime = time + 1;
433 if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
434 msg = inflictor.message2;
435 else if (deathtype == DEATH_CUSTOM)
440 if(strstrofs(msg, "%", 0) < 0)
441 msg = strcat("%s ", msg, " by %s");
443 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
445 if(g_ctf && targ.flagcarried)
447 UpdateFrags(attacker, ctf_score_value("score_kill"));
448 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
449 GiveFrags(attacker, targ, 0, deathtype); // for logging
452 GiveFrags(attacker, targ, 1, deathtype);
454 if (targ.killcount > 2) {
455 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
458 attacker.killcount = attacker.killcount + 1;
460 if (attacker.killcount > 2) {
461 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
463 else if (attacker.killcount == 3)
465 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
466 AnnounceTo(attacker, "03kills");
467 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
469 else if (attacker.killcount == 5)
471 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
472 AnnounceTo(attacker, "05kills");
473 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
475 else if (attacker.killcount == 10)
477 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
478 AnnounceTo(attacker, "10kills");
479 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
481 else if (attacker.killcount == 15)
483 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
484 AnnounceTo(attacker, "15kills");
485 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
487 else if (attacker.killcount == 20)
489 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
490 AnnounceTo(attacker, "20kills");
491 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
493 else if (attacker.killcount == 25)
495 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
496 AnnounceTo(attacker, "25kills");
497 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
499 else if (attacker.killcount == 30)
501 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
502 AnnounceTo(attacker, "30kills");
503 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
505 LogDeath("frag", deathtype, attacker, targ);
510 Send_CSQC_KillCenterprint(targ, "", "", deathtype, MSG_KILL_ACTION);
511 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
512 msg = inflictor.message;
513 else if (deathtype == DEATH_CUSTOM)
517 if(strstrofs(msg, "%", 0) < 0)
518 msg = strcat("%s ", msg);
520 GiveFrags(targ, targ, -1, deathtype);
521 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
522 AnnounceTo(targ, "botlike");
523 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
525 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
527 if (targ.killcount > 2)
528 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
530 LogDeath("accident", deathtype, targ, targ);
533 targ.death_origin = targ.origin;
535 targ.killer_origin = attacker.origin;
537 // FIXME: this should go in PutClientInServer
543 // these are updated by each Damage call for use in button triggering and such
545 entity damage_inflictor;
546 entity damage_attacker;
548 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
553 entity attacker_save;
557 if (gameover || targ.killcount == -666)
564 damage_inflictor = inflictor;
565 damage_attacker = attacker;
566 attacker_save = attacker;
568 if(targ.classname == "player")
571 if(targ.hook.aiment == attacker)
572 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
574 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
575 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
577 if(targ.classname == "player")
578 if not(IsDifferentTeam(targ, attacker))
585 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
587 // These are ALWAYS lethal
588 // No damage modification here
589 // Instead, prepare the victim for his death...
591 targ.spawnshieldtime = 0;
592 targ.health = 0.9; // this is < 1
593 targ.flags -= targ.flags & FL_GODMODE;
596 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
603 skill based bot damage? gtfo. (tZork)
604 if (targ.classname == "player")
605 if (attacker.classname == "player")
608 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
611 // nullify damage if teamplay is on
612 if(deathtype != DEATH_TELEFRAG)
613 if(attacker.classname == "player")
615 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
620 else if(!IsDifferentTeam(attacker, targ))
622 if(autocvar_teamplay_mode == 1)
624 else if(attacker != targ)
626 if(autocvar_teamplay_mode == 3)
628 else if(autocvar_teamplay_mode == 4)
630 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
632 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
633 attacker.dmg_team = attacker.dmg_team + damage;
634 if(attacker.dmg_team > teamdamage0 && !g_ca)
635 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
636 mirrorforce = autocvar_g_mirrordamage * vlen(force);
639 if(autocvar_g_friendlyfire == 0)
645 damage = autocvar_g_friendlyfire * damage;
646 // mirrordamage will be used LATER
648 if(autocvar_g_mirrordamage_virtual)
650 vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
651 attacker.dmg_take += v_x;
652 attacker.dmg_save += v_y;
653 attacker.dmg_inflictor = inflictor;
658 if(autocvar_g_friendlyfire_virtual)
660 vector v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
661 targ.dmg_take += v_x;
662 targ.dmg_save += v_y;
663 targ.dmg_inflictor = inflictor;
665 if(!autocvar_g_friendlyfire_virtual_force)
676 if(targ.classname == "player")
677 if(attacker.classname == "player")
680 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
681 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
684 if(targ.classname == "player")
687 if ((deathtype == DEATH_FALL) ||
688 (deathtype == DEATH_DROWN) ||
689 (deathtype == DEATH_SLIME) ||
690 (deathtype == DEATH_LAVA) ||
691 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
698 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
700 targ.armorvalue -= 1;
701 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
704 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
706 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
710 if (targ != attacker)
712 if ((targ.health >= 1) && (targ.classname == "player"))
713 centerprint(attacker, "Secondary fire inflicts no damage!");
721 if not(DEATH_ISSPECIAL(deathtype))
723 damage *= g_weapondamagefactor;
724 mirrordamage *= g_weapondamagefactor;
725 force = force * g_weaponforcefactor;
726 mirrorforce *= g_weaponforcefactor;
729 // should this be changed at all? If so, in what way?
730 frag_attacker = attacker;
732 frag_damage = damage;
734 frag_deathtype = deathtype;
735 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
736 damage = frag_damage;
739 // apply strength multiplier
740 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
744 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
745 force = force * autocvar_g_balance_powerup_strength_selfforce;
749 damage = damage * autocvar_g_balance_powerup_strength_damage;
750 force = force * autocvar_g_balance_powerup_strength_force;
754 // apply invincibility multiplier
755 if (targ.items & IT_INVINCIBLE && !g_minstagib)
756 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
758 if (targ == attacker)
760 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
763 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
766 // CTF: reduce damage/force
771 damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
772 force = force * autocvar_g_ctf_flagcarrier_selfforce;
777 // apply strength rune
778 if (attacker.runes & RUNE_STRENGTH)
780 if(attacker.runes & CURSE_WEAK) // have both curse & rune
782 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
783 force = force * autocvar_g_balance_rune_strength_combo_force;
787 damage = damage * autocvar_g_balance_rune_strength_damage;
788 force = force * autocvar_g_balance_rune_strength_force;
791 else if (attacker.runes & CURSE_WEAK)
793 damage = damage * autocvar_g_balance_curse_weak_damage;
794 force = force * autocvar_g_balance_curse_weak_force;
797 // apply defense rune
798 if (targ.runes & RUNE_DEFENSE)
800 if (targ.runes & CURSE_VULNER) // have both curse & rune
801 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
803 damage = damage * autocvar_g_balance_rune_defense_takedamage;
805 else if (targ.runes & CURSE_VULNER)
806 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
812 if(targ.takedamage == DAMAGE_AIM)
815 if(damage_headshotbonus)
817 if(targ.classname == "player")
820 // find height of hit on player axis
821 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
822 vector headmins, headmaxs, org;
823 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
824 headmins = org + GetHeadshotMins(targ);
825 headmaxs = org + GetHeadshotMaxs(targ);
826 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
828 deathtype |= HITTYPE_HEADSHOT;
831 else if(targ.classname == "turret_head")
833 deathtype |= HITTYPE_HEADSHOT;
835 if(deathtype & HITTYPE_HEADSHOT)
836 if(damage_headshotbonus > 0)
837 damage *= 1 + damage_headshotbonus;
841 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
846 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
848 if(IsDifferentTeam(victim, attacker))
852 if(deathtype != DEATH_FIRE)
854 if(victim.BUTTON_CHAT)
855 attacker.typehitsound += 1;
857 attacker.hitsound += 1;
860 damage_goodhits += 1;
861 damage_gooddamage += damage;
863 if not(DEATH_ISSPECIAL(deathtype))
865 if(targ.classname == "player") // don't do this for vehicles
871 if(victim.items & IT_STRENGTH)
874 if(deathtype & HITTYPE_HEADSHOT)
878 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
883 if(deathtype != DEATH_FIRE)
885 attacker.typehitsound += 1;
888 if(time > attacker.teamkill_complain)
890 attacker.teamkill_complain = time + 5;
891 attacker.teamkill_soundtime = time + 0.4;
892 attacker.teamkill_soundsource = targ;
900 if (self.damageforcescale)
902 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
904 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
905 if(self.movetype == MOVETYPE_PHYSICS)
909 farcent.classname = "farce";
910 farcent.enemy = self;
911 farcent.movedir = farce * 10;
913 farcent.movedir = farcent.movedir * self.mass;
914 farcent.origin = hitloc;
915 farcent.forcetype = FORCETYPE_FORCEATPOS;
916 farcent.nextthink = time + 0.1;
917 farcent.think = SUB_Remove;
920 self.velocity = self.velocity + farce;
921 self.flags &~= FL_ONGROUND;
922 UpdateCSQCProjectile(self);
925 if (damage != 0 || (self.damageforcescale && vlen(force)))
926 if (self.event_damage)
927 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
930 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
934 if (attacker.runes & RUNE_VAMPIRE)
936 // apply vampire rune
937 if (attacker.runes & CURSE_EMPATHY) // have the curse too
939 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
940 attacker.health = bound(
941 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
942 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
943 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
947 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
948 attacker.health = bound(
949 attacker.health, // LA: was 3, but changed so that you can't lose health
950 // empathy won't let you gain health in the same way...
951 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
952 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
955 // apply empathy curse
956 else if (attacker.runes & CURSE_EMPATHY)
958 attacker.health = bound(
959 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
960 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
966 // apply mirror damage if any
967 if(mirrordamage > 0 || mirrorforce > 0)
969 attacker = attacker_save;
973 // just lose extra LIVES, don't kill the player for mirror damage
974 if(attacker.armorvalue > 0)
976 attacker.armorvalue = attacker.armorvalue - 1;
977 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
978 attacker.hitsound += 1;
983 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
984 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
988 float RadiusDamage_running;
989 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
990 // 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 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1014 total_damage_to_creatures = 0;
1016 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1017 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
1019 force = inflictor.velocity;
1020 if(vlen(force) == 0)
1023 force = normalize(force);
1024 if(forceintensity >= 0)
1025 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
1027 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
1030 stat_damagedone = 0;
1032 targ = WarpZone_FindRadius (blastorigin, rad + MAX_DAMAGEEXTRARADIUS, FALSE);
1036 if (targ != inflictor)
1037 if (ignore != targ) 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, blastorigin);
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(blastorigin, 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 // laser force adjustments :P
1143 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1145 if (targ == attacker)
1150 float force_velocitybiasramp;
1151 float force_velocitybias;
1153 force_velocitybiasramp = autocvar_sv_maxspeed;
1154 if(deathtype & HITTYPE_SECONDARY)
1156 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1157 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1161 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1162 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1165 vel = targ.velocity;
1167 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1171 normalize(normalize(force) + vel);
1173 force_z *= force_zscale;
1177 if(deathtype & HITTYPE_SECONDARY)
1179 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1183 force *= autocvar_g_balance_laser_primary_force_other_scale;
1188 //if (targ == attacker)
1190 // print("hits ", ftos(hits), " / ", ftos(total));
1191 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1192 // print(" (", ftos(a), ")\n");
1194 if(finaldmg || vlen(force))
1198 total_damage_to_creatures += finaldmg;
1200 if(accuracy_isgooddamage(attacker, targ))
1201 stat_damagedone += finaldmg;
1204 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1205 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1207 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1215 RadiusDamage_running = 0;
1217 if(!DEATH_ISSPECIAL(deathtype))
1218 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1220 return total_damage_to_creatures;
1223 .float fire_damagepersec;
1224 .float fire_endtime;
1225 .float fire_deathtype;
1227 .float fire_hitsound;
1228 .entity fire_burner;
1230 void fireburner_think();
1232 float Fire_IsBurning(entity e)
1234 return (time < e.fire_endtime);
1237 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1240 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1242 if(e.classname == "player")
1251 // print("adding a fire burner to ", e.classname, "\n");
1252 e.fire_burner = spawn();
1253 e.fire_burner.classname = "fireburner";
1254 e.fire_burner.think = fireburner_think;
1255 e.fire_burner.nextthink = time;
1256 e.fire_burner.owner = e;
1262 if(Fire_IsBurning(e))
1264 mintime = e.fire_endtime - time;
1265 maxtime = max(mintime, t);
1267 mindps = e.fire_damagepersec;
1268 maxdps = max(mindps, dps);
1270 if(maxtime > mintime || maxdps > mindps)
1274 // damage we have right now
1275 mindamage = mindps * mintime;
1277 // damage we want to get
1278 maxdamage = mindamage + d;
1280 // but we can't exceed maxtime * maxdps!
1281 totaldamage = min(maxdamage, maxtime * maxdps);
1284 // how long do we damage then?
1285 // at least as long as before
1286 // but, never exceed maxdps
1287 totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime
1291 // at most as long as maximum allowed
1293 totaltime = min(maxtime, totaldamage / mindps); // always >= mintime
1296 BOTH SAEM (but lower one is numerically more stable as maxtime has potentially less ops behind)
1298 maxtime = max(mintime, t)
1299 maxdps = max(mindps, d/t)
1300 mindamage = mindps * mintime
1301 maxdamage = mindps * mintime + d
1302 totaldamage = min(mindps * mintime + d, max(mintime, t) * max(mindps, d/t))
1303 totaltime1 = max(mintime, min(mindps * mintime + d, max(mintime, t) * max(mindps, d/t)) / max(mindps, d/t))
1304 totaltime2 = min(max(mintime, t), min(mindps * mintime + d, max(mintime, t) * max(mindps, d/t)) / mindps)
1306 1. max(mintime, t) == t
1307 totaltime1 = max(mintime, min(mindps * mintime + d, t * max(mindps, d/t)) / max(mindps, d/t))
1308 totaltime2 = min(t, min(mindps * mintime + d, t * max(mindps, d/t)) / mindps)
1310 1.1. max(mindps, d/t) == mindps
1312 totaltime1 = max(mintime, min(mindps * mintime + d, t * mindps) / mindps)
1313 totaltime2 = min(t, min(mindps * mintime + d, t * mindps) / mindps)
1315 totaltime1 = max(mintime, min(mintime + d / mindps, t))
1316 totaltime2 = min(t, min(mintime + d / mindps, t))
1318 totaltime1 = max(mintime, min(mintime + d / mindps, t))
1319 totaltime2 = min(t, mintime + d / mindps)
1321 totaltime1 = min(max(mintime, mintime + d / mindps), max(mintime, t))
1322 totaltime2 = min(t, mintime + d / mindps)
1324 totaltime1 = min(mintime + d / mindps, t)
1325 totaltime2 = min(t, mintime + d / mindps)
1329 1.2. max(mindps, d/t) == d/t
1330 totaltime1 = max(mintime, min(mindps * mintime + d, t * d/t) / d/t)
1331 totaltime2 = min(t, min(mindps * mintime + d, t * d/t) / mindps)
1333 totaltime1 = max(mintime, min(mindps * mintime / (d/t) + t, t))
1334 totaltime2 = min(t, min(mintime + d / mindps, d / mindps))
1336 totaltime1 = max(mintime, t) == t
1337 totaltime2 = min(t, d / mindps) == t
1341 2. max(mintime, t) == mintime
1342 totaltime1 = max(mintime, min(mindps * mintime + d, mintime * max(mindps, d/t)) / max(mindps, d/t))
1343 totaltime2 = min(mintime, min(mindps * mintime + d, mintime * max(mindps, d/t)) / mindps)
1345 2.1. max(mindps, d/t) == mindps
1346 totaltime1 = max(mintime, min(mindps * mintime + d, mintime * mindps) / mindps)
1347 totaltime2 = min(mintime, min(mindps * mintime + d, mintime * mindps) / mindps)
1349 totaltime1 = max(mintime, min(mintime + d / mindps, mintime)) = mintime
1350 totaltime2 = min(mintime, min(mintime + d / mindps, mintime)) = mintime
1354 2.2. max(mindps, d/t) == d/t
1355 totaltime1 = max(mintime, min(mindps * mintime + d, mintime * d/t) / d/t)
1356 totaltime2 = min(mintime, min(mindps * mintime + d, mintime * d/t) / mindps)
1358 totaltime1 = max(mintime, min(mindps * mintime / (d/t) + d / (d/t), mintime)) == mintime
1359 totaltime2 = min(mintime, min(mintime + d / mindps, mintime * d/t / mindps))
1365 e.fire_damagepersec = totaldamage / totaltime;
1366 e.fire_endtime = time + totaltime;
1367 if(totaldamage > 1.2 * mindamage)
1369 e.fire_deathtype = dt;
1370 if(e.fire_owner != o)
1373 e.fire_hitsound = FALSE;
1376 if(accuracy_isgooddamage(o, e))
1377 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1378 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1385 e.fire_damagepersec = dps;
1386 e.fire_endtime = time + t;
1387 e.fire_deathtype = dt;
1389 e.fire_hitsound = FALSE;
1390 if(accuracy_isgooddamage(o, e))
1391 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1396 void Fire_ApplyDamage(entity e)
1401 if not(Fire_IsBurning(e))
1404 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1405 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1408 // water and slime stop fire
1410 if(e.watertype != CONTENT_LAVA)
1414 if(e.freezetag_frozen)
1417 t = min(frametime, e.fire_endtime - time);
1418 d = e.fire_damagepersec * t;
1420 hi = e.fire_owner.hitsound;
1421 ty = e.fire_owner.typehitsound;
1422 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1423 if(e.fire_hitsound && e.fire_owner)
1425 e.fire_owner.hitsound = hi;
1426 e.fire_owner.typehitsound = ty;
1428 e.fire_hitsound = TRUE;
1430 if not(IS_INDEPENDENT_PLAYER(e))
1431 FOR_EACH_PLAYER(other) if(e != other)
1433 if(other.classname == "player")
1434 if(other.deadflag == DEAD_NO)
1435 if not(IS_INDEPENDENT_PLAYER(other))
1436 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1438 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1439 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1440 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1445 void Fire_ApplyEffect(entity e)
1447 if(Fire_IsBurning(e))
1448 e.effects |= EF_FLAME;
1450 e.effects &~= EF_FLAME;
1453 void fireburner_think()
1455 // for players, this is done in the regular loop
1456 if(wasfreed(self.owner))
1461 Fire_ApplyEffect(self.owner);
1462 if(!Fire_IsBurning(self.owner))
1464 self.owner.fire_burner = world;
1468 Fire_ApplyDamage(self.owner);
1469 self.nextthink = time;