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);
206 attacker.totalfrags += f;
209 UpdateFrags(attacker, f);
212 string Obituary_ExtraFragInfo(entity player) // Extra fragmessage information
214 string health_output = string_null;
215 string ping_output = string_null;
216 string handicap_output = string_null;
217 string output = string_null;
219 if(autocvar_sv_fraginfo && ((autocvar_sv_fraginfo == 2) || inWarmupStage))
221 // health/armor of attacker (person who killed you)
222 if(autocvar_sv_fraginfo_stats && (player.health >= 1))
223 health_output = strcat("^7(Health ^1", ftos(rint(player.health)), "^7 / Armor ^2", ftos(rint(player.armorvalue)), "^7)");
226 if(autocvar_sv_fraginfo_ping)
227 ping_output = ((clienttype(player) == CLIENTTYPE_BOT) ? "^2Bot" : strcat("Ping ", ((player.ping >= 150) ? "^1" : "^2"), ftos(rint(player.ping)), "ms"));
230 if(autocvar_sv_fraginfo_handicap)
232 if(autocvar_sv_fraginfo_handicap == 2)
233 handicap_output = strcat(output, strcat("Handicap ^2", ((player.cvar_cl_handicap <= 1) ? "Off" : ftos(rint(player.cvar_cl_handicap)))));
234 else if(player.cvar_cl_handicap) // with _handicap 1, only show this if there actually is a handicap enabled.
235 handicap_output = strcat("Handicap ^2", ftos(rint(player.cvar_cl_handicap)));
239 output = strcat(health_output, (health_output ? ((ping_output || handicap_output) ? " ^7(" : "") : ((ping_output || handicap_output) ? "^7(" : "")),
240 ping_output, (handicap_output ? "^7 / " : ""),
241 handicap_output, ((ping_output || handicap_output) ? "^7)" : ""));
243 // add new line to the beginning if there is a message
244 if(output) { output = strcat("\n", output); }
250 string AppendItemcodes(string s, entity player)
255 // w = player.switchweapon;
257 w = player.cnt; // previous weapon!
258 s = strcat(s, ftos(w));
259 if(time < player.strength_finished)
261 if(time < player.invincible_finished)
263 if(player.flagcarried != world)
265 if(player.BUTTON_CHAT)
270 s = strcat(s, "|", ftos(player.runes));
274 void LogDeath(string mode, float deathtype, entity killer, entity killed)
277 if(!autocvar_sv_eventlog)
279 s = strcat(":kill:", mode);
280 s = strcat(s, ":", ftos(killer.playerid));
281 s = strcat(s, ":", ftos(killed.playerid));
282 s = strcat(s, ":type=", ftos(deathtype));
283 s = strcat(s, ":items=");
284 s = AppendItemcodes(s, killer);
287 s = strcat(s, ":victimitems=");
288 s = AppendItemcodes(s, killed);
293 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
295 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
296 WriteByte(MSG_BROADCAST, TE_CSQC_KILLNOTIFY);
297 WriteString(MSG_BROADCAST, s1);
298 WriteString(MSG_BROADCAST, s2);
299 WriteString(MSG_BROADCAST, s3);
300 WriteShort(MSG_BROADCAST, msg);
301 WriteByte(MSG_BROADCAST, type);
304 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
305 void Send_CSQC_KillCenterprint(entity e, string s1, string s2, float msg, float type)
307 if (clienttype(e) == CLIENTTYPE_REAL)
310 WRITESPECTATABLE_MSG_ONE({
311 WriteByte(MSG_ONE, SVC_TEMPENTITY);
312 WriteByte(MSG_ONE, TE_CSQC_KILLCENTERPRINT);
313 WriteString(MSG_ONE, s1);
314 WriteString(MSG_ONE, s2);
315 WriteShort(MSG_ONE, msg);
316 WriteByte(MSG_ONE, type);
321 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
326 if (targ.classname == "player")
329 a = attacker.netname;
331 if (targ == attacker) // suicides
333 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
334 msg = ColoredTeamName(targ.team); // TODO: check if needed?
337 if(!g_cts) // no "killed your own dumb self" message in CTS
338 Send_CSQC_KillCenterprint(targ, msg, "", deathtype, MSG_SUICIDE);
340 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
342 LogDeath("suicide", deathtype, targ, targ);
343 GiveFrags(attacker, targ, -1, deathtype);
346 if (targ.killcount > 2)
347 msg = ftos(targ.killcount);
350 if(teamplay && deathtype == DEATH_MIRRORDAMAGE)
352 if(attacker.team == COLOR_TEAM1)
353 deathtype = KILL_TEAM_RED;
355 deathtype = KILL_TEAM_BLUE;
358 Send_KillNotification(s, msg, "", deathtype, MSG_SUICIDE);
360 else if (attacker.classname == "player")
362 if(!IsDifferentTeam(attacker, targ))
364 if(attacker.team == COLOR_TEAM1)
365 type = KILL_TEAM_RED;
367 type = KILL_TEAM_BLUE;
369 GiveFrags(attacker, targ, -1, deathtype);
371 Send_CSQC_KillCenterprint(attacker, s, "", type, MSG_KILL);
373 if (targ.killcount > 2)
374 msg = ftos(targ.killcount);
378 if (attacker.killcount > 2) {
379 msg = ftos(attacker.killcount);
380 type = KILL_TEAM_SPREE;
382 Send_KillNotification(a, s, msg, type, MSG_KILL);
384 attacker.killcount = 0;
386 LogDeath("tk", deathtype, attacker, targ);
390 if (!checkrules_firstblood)
392 checkrules_firstblood = TRUE;
393 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
394 // TODO: make these print a newline if they dont
395 Send_CSQC_KillCenterprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
396 Send_CSQC_KillCenterprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
397 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
398 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
401 if(targ.istypefrag) {
402 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_TYPEFRAG, MSG_KILL);
403 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_TYPEFRAGGED, MSG_KILL);
405 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_FRAG, MSG_KILL);
406 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_FRAGGED, MSG_KILL);
409 attacker.taunt_soundtime = time + 1;
411 if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
412 msg = inflictor.message2;
413 else if (deathtype == DEATH_CUSTOM)
418 if(strstrofs(msg, "%", 0) < 0)
419 msg = strcat("%s ", msg, " by %s");
421 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
423 GiveFrags(attacker, targ, 1, deathtype);
425 if (targ.killcount > 2) {
426 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
429 attacker.killcount = attacker.killcount + 1;
431 if (attacker.killcount == 3)
433 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
434 AnnounceTo(attacker, "03kills");
435 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
437 else if (attacker.killcount == 5)
439 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
440 AnnounceTo(attacker, "05kills");
441 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
443 else if (attacker.killcount == 10)
445 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
446 AnnounceTo(attacker, "10kills");
447 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
449 else if (attacker.killcount == 15)
451 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
452 AnnounceTo(attacker, "15kills");
453 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
455 else if (attacker.killcount == 20)
457 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
458 AnnounceTo(attacker, "20kills");
459 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
461 else if (attacker.killcount == 25)
463 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
464 AnnounceTo(attacker, "25kills");
465 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
467 else if (attacker.killcount == 30)
469 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
470 AnnounceTo(attacker, "30kills");
471 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
473 else if (attacker.killcount > 2) {
474 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
476 LogDeath("frag", deathtype, attacker, targ);
481 Send_CSQC_KillCenterprint(targ, "", "", deathtype, MSG_KILL_ACTION);
482 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
483 msg = inflictor.message;
484 else if (deathtype == DEATH_CUSTOM)
488 if(strstrofs(msg, "%", 0) < 0)
489 msg = strcat("%s ", msg);
491 GiveFrags(targ, targ, -1, deathtype);
492 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
493 AnnounceTo(targ, "botlike");
494 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
496 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
498 if (targ.killcount > 2)
499 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
501 LogDeath("accident", deathtype, targ, targ);
504 targ.death_origin = targ.origin;
506 targ.killer_origin = attacker.origin;
508 // FIXME: this should go in PutClientInServer
514 // these are updated by each Damage call for use in button triggering and such
516 entity damage_inflictor;
517 entity damage_attacker;
519 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
524 entity attacker_save;
528 if (gameover || targ.killcount == -666)
535 damage_inflictor = inflictor;
536 damage_attacker = attacker;
537 attacker_save = attacker;
539 if(targ.classname == "player")
542 if(targ.hook.aiment == attacker)
543 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
545 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
546 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
548 if(targ.classname == "player")
549 if not(IsDifferentTeam(targ, attacker))
556 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
558 // These are ALWAYS lethal
559 // No damage modification here
560 // Instead, prepare the victim for his death...
562 targ.spawnshieldtime = 0;
563 targ.health = 0.9; // this is < 1
564 targ.flags -= targ.flags & FL_GODMODE;
567 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
574 skill based bot damage? gtfo. (tZork)
575 if (targ.classname == "player")
576 if (attacker.classname == "player")
579 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
582 // nullify damage if teamplay is on
583 if(deathtype != DEATH_TELEFRAG)
584 if(attacker.classname == "player")
586 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
591 else if(!IsDifferentTeam(attacker, targ))
593 if(autocvar_teamplay_mode == 1)
595 else if(attacker != targ)
597 if(autocvar_teamplay_mode == 3)
599 else if(autocvar_teamplay_mode == 4)
601 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
603 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
604 attacker.dmg_team = attacker.dmg_team + damage;
605 if(attacker.dmg_team > teamdamage0 && !g_ca)
606 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
607 mirrorforce = autocvar_g_mirrordamage * vlen(force);
610 if(autocvar_g_friendlyfire == 0)
616 damage = autocvar_g_friendlyfire * damage;
617 // mirrordamage will be used LATER
619 if(autocvar_g_mirrordamage_virtual)
621 vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
622 attacker.dmg_take += v_x;
623 attacker.dmg_save += v_y;
624 attacker.dmg_inflictor = inflictor;
625 mirrordamage = v_z; // = 0, to make fteqcc stfu
629 if(autocvar_g_friendlyfire_virtual)
631 vector v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
632 targ.dmg_take += v_x;
633 targ.dmg_save += v_y;
634 targ.dmg_inflictor = inflictor;
636 if(!autocvar_g_friendlyfire_virtual_force)
647 if(targ.classname == "player")
648 if(attacker.classname == "player")
651 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
652 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
655 if(targ.classname == "player")
658 if ((deathtype == DEATH_FALL) ||
659 (deathtype == DEATH_DROWN) ||
660 (deathtype == DEATH_SLIME) ||
661 (deathtype == DEATH_LAVA) ||
662 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
669 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
671 targ.armorvalue -= 1;
672 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
675 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
677 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
681 if (targ != attacker)
683 if ((targ.health >= 1) && (targ.classname == "player"))
684 centerprint(attacker, "Secondary fire inflicts no damage!");
692 if not(DEATH_ISSPECIAL(deathtype))
694 damage *= g_weapondamagefactor;
695 mirrordamage *= g_weapondamagefactor;
696 force = force * g_weaponforcefactor;
697 mirrorforce *= g_weaponforcefactor;
700 // should this be changed at all? If so, in what way?
701 frag_attacker = attacker;
703 frag_damage = damage;
705 frag_deathtype = deathtype;
706 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
707 damage = frag_damage;
710 // apply strength multiplier
711 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
715 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
716 force = force * autocvar_g_balance_powerup_strength_selfforce;
720 damage = damage * autocvar_g_balance_powerup_strength_damage;
721 force = force * autocvar_g_balance_powerup_strength_force;
725 // apply invincibility multiplier
726 if (targ.items & IT_INVINCIBLE && !g_minstagib)
727 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
729 if (targ == attacker)
731 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
734 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
739 // apply strength rune
740 if (attacker.runes & RUNE_STRENGTH)
742 if(attacker.runes & CURSE_WEAK) // have both curse & rune
744 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
745 force = force * autocvar_g_balance_rune_strength_combo_force;
749 damage = damage * autocvar_g_balance_rune_strength_damage;
750 force = force * autocvar_g_balance_rune_strength_force;
753 else if (attacker.runes & CURSE_WEAK)
755 damage = damage * autocvar_g_balance_curse_weak_damage;
756 force = force * autocvar_g_balance_curse_weak_force;
759 // apply defense rune
760 if (targ.runes & RUNE_DEFENSE)
762 if (targ.runes & CURSE_VULNER) // have both curse & rune
763 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
765 damage = damage * autocvar_g_balance_rune_defense_takedamage;
767 else if (targ.runes & CURSE_VULNER)
768 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
774 if(targ.takedamage == DAMAGE_AIM)
777 if(damage_headshotbonus)
779 if(targ.classname == "player")
782 // find height of hit on player axis
783 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
784 vector headmins, headmaxs, org;
785 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
786 headmins = org + GetHeadshotMins(targ);
787 headmaxs = org + GetHeadshotMaxs(targ);
788 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
790 deathtype |= HITTYPE_HEADSHOT;
793 else if(targ.classname == "turret_head")
795 deathtype |= HITTYPE_HEADSHOT;
797 if(deathtype & HITTYPE_HEADSHOT)
798 if(damage_headshotbonus > 0)
799 damage *= 1 + damage_headshotbonus;
803 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
808 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
810 if(IsDifferentTeam(victim, attacker))
814 if(deathtype != DEATH_FIRE)
816 if(victim.BUTTON_CHAT)
817 attacker.typehitsound += 1;
819 attacker.hitsound += 1;
822 damage_goodhits += 1;
823 damage_gooddamage += damage;
825 if not(DEATH_ISSPECIAL(deathtype))
827 if(targ.classname == "player") // don't do this for vehicles
833 if(victim.items & IT_STRENGTH)
836 if(deathtype & HITTYPE_HEADSHOT)
843 if(deathtype != DEATH_FIRE)
845 attacker.typehitsound += 1;
848 if(time > attacker.teamkill_complain)
850 attacker.teamkill_complain = time + 5;
851 attacker.teamkill_soundtime = time + 0.4;
852 attacker.teamkill_soundsource = targ;
860 if (self.damageforcescale)
862 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
864 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
865 if(self.movetype == MOVETYPE_PHYSICS)
869 farcent.classname = "farce";
870 farcent.enemy = self;
871 farcent.movedir = farce * 10;
873 farcent.movedir = farcent.movedir * self.mass;
874 farcent.origin = hitloc;
875 farcent.forcetype = FORCETYPE_FORCEATPOS;
876 farcent.nextthink = time + 0.1;
877 farcent.think = SUB_Remove;
880 self.velocity = self.velocity + farce;
881 self.flags &~= FL_ONGROUND;
882 UpdateCSQCProjectile(self);
885 if (damage != 0 || (self.damageforcescale && vlen(force)))
886 if (self.event_damage)
887 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
890 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
894 if (attacker.runes & RUNE_VAMPIRE)
896 // apply vampire rune
897 if (attacker.runes & CURSE_EMPATHY) // have the curse too
899 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
900 attacker.health = bound(
901 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
902 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
903 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
907 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
908 attacker.health = bound(
909 attacker.health, // LA: was 3, but changed so that you can't lose health
910 // empathy won't let you gain health in the same way...
911 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
912 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
915 // apply empathy curse
916 else if (attacker.runes & CURSE_EMPATHY)
918 attacker.health = bound(
919 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
920 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
926 // apply mirror damage if any
927 if(mirrordamage > 0 || mirrorforce > 0)
929 attacker = attacker_save;
933 // just lose extra LIVES, don't kill the player for mirror damage
934 if(attacker.armorvalue > 0)
936 attacker.armorvalue = attacker.armorvalue - 1;
937 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
938 attacker.hitsound += 1;
943 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
944 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
948 float RadiusDamage_running;
949 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
950 // Returns total damage applies to creatures
955 float total_damage_to_creatures;
960 float stat_damagedone;
962 if(RadiusDamage_running)
964 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
968 RadiusDamage_running = 1;
970 tfloordmg = autocvar_g_throughfloor_damage;
971 tfloorforce = autocvar_g_throughfloor_force;
973 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
974 total_damage_to_creatures = 0;
976 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
977 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
979 force = inflictor.velocity;
983 force = normalize(force);
984 if(forceintensity >= 0)
985 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
987 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
992 targ = WarpZone_FindRadius (blastorigin, rad + MAX_DAMAGEEXTRARADIUS, FALSE);
996 if (targ != inflictor)
997 if (ignore != targ) if(targ.takedamage)
1003 // LordHavoc: measure distance to nearest point on target (not origin)
1004 // (this guarentees 100% damage on a touch impact)
1005 nearest = targ.WarpZone_findradius_nearest;
1006 diff = targ.WarpZone_findradius_dist;
1007 // round up a little on the damage to ensure full damage on impacts
1008 // and turn the distance into a fraction of the radius
1009 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
1011 //bprint(ftos(power));
1012 //if (targ == attacker)
1013 // print(ftos(power), "\n");
1019 finaldmg = coredamage * power + edgedamage * (1 - power);
1025 vector myblastorigin;
1028 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1030 // if it's a player, use the view origin as reference
1031 center = CENTER_OR_VIEWOFS(targ);
1033 force = normalize(center - myblastorigin);
1034 force = force * (finaldmg / coredamage) * forceintensity;
1037 if(targ != directhitentity)
1042 float mininv_f, mininv_d;
1044 // test line of sight to multiple positions on box,
1045 // and do damage if any of them hit
1048 // we know: max stddev of hitratio = 1 / (2 * sqrt(n))
1049 // so for a given max stddev:
1050 // n = (1 / (2 * max stddev of hitratio))^2
1052 mininv_d = (finaldmg * (1-tfloordmg)) / autocvar_g_throughfloor_damage_max_stddev;
1053 mininv_f = (vlen(force) * (1-tfloorforce)) / autocvar_g_throughfloor_force_max_stddev;
1055 if(autocvar_g_throughfloor_debug)
1056 print(sprintf("THROUGHFLOOR: D=%f F=%f max(dD)=1/%f max(dF)=1/%f", finaldmg, vlen(force), mininv_d, mininv_f));
1058 total = 0.25 * pow(max(mininv_f, mininv_d), 2);
1060 if(autocvar_g_throughfloor_debug)
1061 print(sprintf(" steps=%f", total));
1063 if (targ.classname == "player")
1064 total = ceil(bound(autocvar_g_throughfloor_min_steps_player, total, autocvar_g_throughfloor_max_steps_player));
1066 total = ceil(bound(autocvar_g_throughfloor_min_steps_other, total, autocvar_g_throughfloor_max_steps_other));
1068 if(autocvar_g_throughfloor_debug)
1069 print(sprintf(" steps=%f dD=%f dF=%f", total, finaldmg * (1-tfloordmg) / (2 * sqrt(total)), vlen(force) * (1-tfloorforce) / (2 * sqrt(total))));
1071 for(c = 0; c < total; ++c)
1073 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1074 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1075 if (trace_fraction == 1 || trace_ent == targ)
1079 hitloc = hitloc + nearest;
1083 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1084 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1085 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1088 nearest = hitloc * (1 / max(1, hits));
1089 hitratio = (hits / total);
1090 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1091 finaldmg = finaldmg * a;
1092 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1095 if(autocvar_g_throughfloor_debug)
1096 print(sprintf(" D=%f F=%f\n", finaldmg, vlen(force)));
1099 // laser force adjustments :P
1100 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1102 if (targ == attacker)
1107 float force_velocitybiasramp;
1108 float force_velocitybias;
1110 force_velocitybiasramp = autocvar_sv_maxspeed;
1111 if(deathtype & HITTYPE_SECONDARY)
1113 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1114 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1118 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1119 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1122 vel = targ.velocity;
1124 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1128 normalize(normalize(force) + vel);
1130 force_z *= force_zscale;
1134 if(deathtype & HITTYPE_SECONDARY)
1136 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1140 force *= autocvar_g_balance_laser_primary_force_other_scale;
1145 //if (targ == attacker)
1147 // print("hits ", ftos(hits), " / ", ftos(total));
1148 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1149 // print(" (", ftos(a), ")\n");
1151 if(finaldmg || vlen(force))
1155 total_damage_to_creatures += finaldmg;
1157 if(accuracy_isgooddamage(attacker, targ))
1158 stat_damagedone += finaldmg;
1161 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1162 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1164 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1172 RadiusDamage_running = 0;
1174 if(!DEATH_ISSPECIAL(deathtype))
1175 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1177 return total_damage_to_creatures;
1180 .float fire_damagepersec;
1181 .float fire_endtime;
1182 .float fire_deathtype;
1184 .float fire_hitsound;
1185 .entity fire_burner;
1187 void fireburner_think();
1189 float Fire_IsBurning(entity e)
1191 return (time < e.fire_endtime);
1194 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1197 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1199 if(e.classname == "player")
1208 // print("adding a fire burner to ", e.classname, "\n");
1209 e.fire_burner = spawn();
1210 e.fire_burner.classname = "fireburner";
1211 e.fire_burner.think = fireburner_think;
1212 e.fire_burner.nextthink = time;
1213 e.fire_burner.owner = e;
1219 if(Fire_IsBurning(e))
1221 mintime = e.fire_endtime - time;
1222 maxtime = max(mintime, t);
1224 mindps = e.fire_damagepersec;
1225 maxdps = max(mindps, dps);
1227 if(maxtime > mintime || maxdps > mindps)
1231 // damage we have right now
1232 mindamage = mindps * mintime;
1234 // damage we want to get
1235 maxdamage = mindamage + d;
1237 // but we can't exceed maxtime * maxdps!
1238 totaldamage = min(maxdamage, maxtime * maxdps);
1242 // totaldamage = min(mindamage + d, maxtime * maxdps)
1244 // totaldamage <= maxtime * maxdps
1245 // ==> totaldamage / maxdps <= maxtime.
1247 // totaldamage / mindps = min(mindamage / mindps + d, maxtime * maxdps / mindps)
1248 // >= min(mintime, maxtime)
1249 // ==> totaldamage / maxdps >= mintime.
1252 // how long do we damage then?
1253 // at least as long as before
1254 // but, never exceed maxdps
1255 totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime due to lemma
1259 // at most as long as maximum allowed
1260 // but, never below mindps
1261 totaltime = min(maxtime, totaldamage / mindps); // always >= mintime due to lemma
1263 // assuming t > mintime, dps > mindps:
1264 // we get d = t * dps = maxtime * maxdps
1265 // totaldamage = min(maxdamage, maxtime * maxdps) = min(... + d, maxtime * maxdps) = maxtime * maxdps
1266 // totaldamage / maxdps = maxtime
1267 // totaldamage / mindps > totaldamage / maxdps = maxtime
1269 // a) totaltime = max(mintime, maxtime) = maxtime
1270 // b) totaltime = min(maxtime, totaldamage / maxdps) = maxtime
1272 // assuming t <= mintime:
1273 // we get maxtime = mintime
1274 // a) totaltime = max(mintime, ...) >= mintime, also totaltime <= maxtime by the lemma, therefore totaltime = mintime = maxtime
1275 // b) totaltime = min(maxtime, ...) <= maxtime, also totaltime >= mintime by the lemma, therefore totaltime = mintime = maxtime
1277 // assuming dps <= mindps:
1278 // we get mindps = maxdps.
1279 // With this, the lemma says that mintime <= totaldamage / mindps = totaldamage / maxdps <= maxtime.
1280 // a) totaltime = max(mintime, totaldamage / maxdps) = totaldamage / maxdps
1281 // b) totaltime = min(maxtime, totaldamage / mindps) = totaldamage / maxdps
1283 e.fire_damagepersec = totaldamage / totaltime;
1284 e.fire_endtime = time + totaltime;
1285 if(totaldamage > 1.2 * mindamage)
1287 e.fire_deathtype = dt;
1288 if(e.fire_owner != o)
1291 e.fire_hitsound = FALSE;
1294 if(accuracy_isgooddamage(o, e))
1295 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1296 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1303 e.fire_damagepersec = dps;
1304 e.fire_endtime = time + t;
1305 e.fire_deathtype = dt;
1307 e.fire_hitsound = FALSE;
1308 if(accuracy_isgooddamage(o, e))
1309 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1314 void Fire_ApplyDamage(entity e)
1319 if not(Fire_IsBurning(e))
1322 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1323 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1326 // water and slime stop fire
1328 if(e.watertype != CONTENT_LAVA)
1332 if(e.freezetag_frozen)
1335 t = min(frametime, e.fire_endtime - time);
1336 d = e.fire_damagepersec * t;
1338 hi = e.fire_owner.hitsound;
1339 ty = e.fire_owner.typehitsound;
1340 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1341 if(e.fire_hitsound && e.fire_owner)
1343 e.fire_owner.hitsound = hi;
1344 e.fire_owner.typehitsound = ty;
1346 e.fire_hitsound = TRUE;
1348 if not(IS_INDEPENDENT_PLAYER(e))
1349 FOR_EACH_PLAYER(other) if(e != other)
1351 if(other.classname == "player")
1352 if(other.deadflag == DEAD_NO)
1353 if not(IS_INDEPENDENT_PLAYER(other))
1354 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1356 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1357 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1358 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1363 void Fire_ApplyEffect(entity e)
1365 if(Fire_IsBurning(e))
1366 e.effects |= EF_FLAME;
1368 e.effects &~= EF_FLAME;
1371 void fireburner_think()
1373 // for players, this is done in the regular loop
1374 if(wasfreed(self.owner))
1379 Fire_ApplyEffect(self.owner);
1380 if(!Fire_IsBurning(self.owner))
1382 self.owner.fire_burner = world;
1386 Fire_ApplyDamage(self.owner);
1387 self.nextthink = time;