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);
20 void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, float deathtype, entity dmgowner)
22 // TODO maybe call this from non-edgedamage too?
23 // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
27 if(!sound_allowed(MSG_BROADCAST, dmgowner))
32 e.projectiledeathtype = deathtype;
34 e.dmg_edge = edgedamage;
36 e.dmg_force = vlen(force);
39 e.oldorigin_x = compressShortVector(e.velocity);
41 Net_LinkEntity(e, FALSE, 0.2, Damage_DamageInfo_SendEntity);
44 float checkrules_firstblood;
47 float damage_goodhits;
48 float damage_gooddamage;
50 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
53 .float teamkill_complain;
54 .float teamkill_soundtime;
55 .entity teamkill_soundsource;
57 .float taunt_soundtime;
60 float IsDifferentTeam(entity a, entity b)
75 float IsFlying(entity a)
77 if(a.flags & FL_ONGROUND)
79 if(a.waterlevel >= WATERLEVEL_SWIMMING)
81 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
82 if(trace_fraction < 1)
87 vector GetHeadshotMins(entity targ)
89 return '-0.5 0 0' * PL_HEAD_x + '0 -0.5 0' * PL_HEAD_y + '0 0 1' * (targ.maxs_z - PL_HEAD_z);
91 vector GetHeadshotMaxs(entity targ)
93 return '0.5 0 0' * PL_HEAD_x + '0 0.5 0' * PL_HEAD_y + '0 0 1' * targ.maxs_z;
96 void UpdateFrags(entity player, float f)
98 PlayerTeamScore_AddScore(player, f);
101 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
102 void W_SwitchWeapon_Force(entity e, float w);
103 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);
143 if(!culprit || !(attacker.weapons & W_WeaponBit(culprit)))
144 culprit = attacker.weapon;
146 if(g_weaponarena_random_with_laser && culprit == WEPBIT_LASER)
153 w = warmup_start_weapons;
157 // all others (including the culprit): remove
158 w &~= attacker.weapons;
160 // among the remaining ones, choose one by random
161 w = randombits(w, 1, FALSE);
164 attacker.weapons |= w;
165 attacker.weapons &~= W_WeaponBit(culprit);
169 // after a frag, choose another random weapon set
170 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
171 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
174 // FIXME fix the mess this is (we have REAL points now!)
178 frag_attacker = attacker;
181 if(MUTATOR_CALLHOOK(GiveFragsForKill))
191 f = RunematchHandleFrags(attacker, targ, f);
197 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
198 if(tl < lms_lowest_lives)
199 lms_lowest_lives = tl;
203 lms_next_place = player_count;
205 lms_next_place = min(lms_next_place, player_count);
206 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
213 if(g_ctf_ignore_frags)
218 attacker.totalfrags += f;
221 UpdateFrags(attacker, f);
224 string Obituary_ExtraFragInfo(entity player) // Extra fragmessage information
226 string health_output;
228 string handicap_output;
231 // health/armor of attacker (person who killed you)
232 if(autocvar_sv_fraginfo_stats && (player.health >= 1))
233 if((autocvar_sv_fraginfo_stats == 2) || !inWarmupStage)
234 health_output = strcat("^7(Health ^1", ftos(rint(player.health)), "^7 / Armor ^2", ftos(rint(player.armorvalue)), "^7)");
237 if(autocvar_sv_fraginfo_ping)
238 ping_output = ((clienttype(player) == CLIENTTYPE_BOT) ? "^2Bot" : strcat("Ping ", ((player.ping >= 150) ? "^1" : "^2"), ftos(player.ping), "ms"));
241 if(autocvar_sv_fraginfo_handicap)
243 if(autocvar_sv_fraginfo_handicap == 2)
244 handicap_output = strcat(output, strcat("Handicap ^2", ((player.cvar_cl_handicap <= 1) ? "Off" : ftos(player.cvar_cl_handicap))));
245 else if(player.cvar_cl_handicap) // with _handicap 1, only show this if there actually is a handicap enabled.
246 handicap_output = strcat("Handicap ^2", ftos(player.cvar_cl_handicap));
250 output = strcat(health_output, (health_output ? " ^7(" : ((ping_output || handicap_output) ? "^7(" : "")),
251 ping_output, ((ping_output && handicap_output) ? "^7 / " : ""),
252 handicap_output, ((ping_output || handicap_output) ? "^7)" : ""));
254 // add new line to the beginning if there is a message
255 if(output) { output = strcat("\n", output); }
260 string AppendItemcodes(string s, entity player)
265 // w = player.switchweapon;
267 w = player.cnt; // previous weapon!
268 s = strcat(s, ftos(w));
269 if(time < player.strength_finished)
271 if(time < player.invincible_finished)
273 if(player.flagcarried != world)
275 if(player.BUTTON_CHAT)
280 s = strcat(s, "|", ftos(player.runes));
284 void LogDeath(string mode, float deathtype, entity killer, entity killed)
287 if(!autocvar_sv_eventlog)
289 s = strcat(":kill:", mode);
290 s = strcat(s, ":", ftos(killer.playerid));
291 s = strcat(s, ":", ftos(killed.playerid));
292 s = strcat(s, ":type=", ftos(deathtype));
293 s = strcat(s, ":items=");
294 s = AppendItemcodes(s, killer);
297 s = strcat(s, ":victimitems=");
298 s = AppendItemcodes(s, killed);
303 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
305 WriteByte(MSG_ALL, SVC_TEMPENTITY);
306 WriteByte(MSG_ALL, TE_CSQC_KILLNOTIFY);
307 WriteString(MSG_ALL, s1);
308 WriteString(MSG_ALL, s2);
309 WriteString(MSG_ALL, s3);
310 WriteShort(MSG_ALL, msg);
311 WriteByte(MSG_ALL, type);
314 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
315 void Send_CSQC_KillCenterprint(entity e, string s1, string s2, float msg, float type)
317 if (clienttype(e) == CLIENTTYPE_REAL)
320 WRITESPECTATABLE_MSG_ONE({
321 WriteByte(MSG_ONE, SVC_TEMPENTITY);
322 WriteByte(MSG_ONE, TE_CSQC_KILLCENTERPRINT);
323 WriteString(MSG_ONE, s1);
324 WriteString(MSG_ONE, s2);
325 WriteShort(MSG_ONE, msg);
326 WriteByte(MSG_ONE, type);
331 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
336 if (targ.classname == "player")
339 a = attacker.netname;
341 if (targ == attacker) // suicides
343 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
344 msg = ColoredTeamName(targ.team); // TODO: check if needed?
345 if(!g_cts) // no "killed your own dumb self" message in CTS
346 Send_CSQC_KillCenterprint(targ, msg, "", deathtype, MSG_SUICIDE);
348 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
350 LogDeath("suicide", deathtype, targ, targ);
351 GiveFrags(attacker, targ, -1, deathtype);
354 if (targ.killcount > 2)
355 msg = ftos(targ.killcount);
356 if(teamplay && deathtype == DEATH_MIRRORDAMAGE)
358 if(attacker.team == COLOR_TEAM1)
359 deathtype = KILL_TEAM_RED;
361 deathtype = KILL_TEAM_BLUE;
364 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
366 else if (attacker.classname == "player")
368 if(!IsDifferentTeam(attacker, targ))
370 if(attacker.team == COLOR_TEAM1)
371 type = KILL_TEAM_RED;
373 type = KILL_TEAM_BLUE;
375 GiveFrags(attacker, targ, -1, deathtype);
377 Send_CSQC_KillCenterprint(attacker, s, "", type, MSG_KILL);
379 if (targ.killcount > 2) {
380 msg = ftos(targ.killcount);
383 if (attacker.killcount > 2) {
384 msg = ftos(attacker.killcount);
385 type = KILL_TEAM_SPREE;
387 Send_KillNotification(a, s, msg, type, MSG_KILL);
389 attacker.killcount = 0;
391 LogDeath("tk", deathtype, attacker, targ);
395 if (!checkrules_firstblood)
397 checkrules_firstblood = TRUE;
398 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
399 // TODO: make these print a newline if they dont
400 Send_CSQC_KillCenterprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
401 Send_CSQC_KillCenterprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
402 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
403 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
406 if((autocvar_sv_fraginfo_typefrag) && (targ.BUTTON_CHAT)) {
407 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_TYPEFRAG, MSG_KILL);
408 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_TYPEFRAGGED, MSG_KILL);
410 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_FRAG, MSG_KILL);
411 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_FRAGGED, MSG_KILL);
414 attacker.taunt_soundtime = time + 1;
417 if (deathtype == DEATH_CUSTOM)
420 msg = inflictor.message2;
422 if(strstrofs(msg, "%", 0) < 0)
423 msg = strcat("%s ", msg, " by %s");
425 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
427 if(g_ctf && targ.flagcarried)
429 UpdateFrags(attacker, ctf_score_value("score_kill"));
430 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
431 GiveFrags(attacker, targ, 0, deathtype); // for logging
434 GiveFrags(attacker, targ, 1, deathtype);
436 if (targ.killcount > 2) {
437 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
440 attacker.killcount = attacker.killcount + 1;
442 if (attacker.killcount > 2) {
443 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
445 else if (attacker.killcount == 3)
447 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
448 AnnounceTo(attacker, "03kills");
449 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
451 else if (attacker.killcount == 5)
453 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
454 AnnounceTo(attacker, "05kills");
455 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
457 else if (attacker.killcount == 10)
459 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
460 AnnounceTo(attacker, "10kills");
461 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
463 else if (attacker.killcount == 15)
465 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
466 AnnounceTo(attacker, "15kills");
467 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
469 else if (attacker.killcount == 20)
471 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
472 AnnounceTo(attacker, "20kills");
473 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
475 else if (attacker.killcount == 25)
477 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
478 AnnounceTo(attacker, "25kills");
479 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
481 else if (attacker.killcount == 30)
483 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
484 AnnounceTo(attacker, "30kills");
485 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
487 LogDeath("frag", deathtype, attacker, targ);
492 Send_CSQC_KillCenterprint(targ, "", "", deathtype, MSG_KILL_ACTION);
493 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
494 msg = inflictor.message;
495 else if (deathtype == DEATH_CUSTOM)
497 if(strstrofs(msg, "%", 0) < 0)
498 msg = strcat("%s ", msg);
500 GiveFrags(targ, targ, -1, deathtype);
501 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
502 AnnounceTo(targ, "botlike");
503 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
505 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
507 if (targ.killcount > 2)
508 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
510 LogDeath("accident", deathtype, targ, targ);
513 targ.death_origin = targ.origin;
515 targ.killer_origin = attacker.origin;
517 // FIXME: this should go in PutClientInServer
523 // these are updated by each Damage call for use in button triggering and such
525 entity damage_inflictor;
526 entity damage_attacker;
528 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
533 entity attacker_save;
537 if (gameover || targ.killcount == -666)
544 damage_inflictor = inflictor;
545 damage_attacker = attacker;
546 attacker_save = attacker;
548 if(targ.classname == "player")
551 if(targ.hook.aiment == attacker)
552 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
554 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
555 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
557 if(targ.classname == "player")
558 if not(IsDifferentTeam(targ, attacker))
565 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
567 // These are ALWAYS lethal
568 // No damage modification here
569 // Instead, prepare the victim for his death...
571 targ.spawnshieldtime = 0;
572 targ.health = 0.9; // this is < 1
573 targ.flags -= targ.flags & FL_GODMODE;
576 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
583 skill based bot damage? gtfo. (tZork)
584 if (targ.classname == "player")
585 if (attacker.classname == "player")
588 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
591 // nullify damage if teamplay is on
592 if(deathtype != DEATH_TELEFRAG)
593 if(attacker.classname == "player")
595 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
600 else if(!IsDifferentTeam(attacker, targ))
602 if(autocvar_teamplay_mode == 1)
604 else if(attacker != targ)
606 if(autocvar_teamplay_mode == 3)
608 else if(autocvar_teamplay_mode == 4)
610 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
612 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
613 attacker.dmg_team = attacker.dmg_team + damage;
614 if(attacker.dmg_team > teamdamage0 && !g_ca)
615 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
616 mirrorforce = autocvar_g_mirrordamage * vlen(force);
619 if(autocvar_g_friendlyfire == 0)
625 damage = autocvar_g_friendlyfire * damage;
626 // mirrordamage will be used LATER
628 if(autocvar_g_mirrordamage_virtual)
631 v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
632 attacker.dmg_take += v_x;
633 attacker.dmg_save += v_y;
634 attacker.dmg_inflictor = inflictor;
639 if(autocvar_g_friendlyfire_virtual)
642 v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
643 targ.dmg_take += v_x;
644 targ.dmg_save += v_y;
645 targ.dmg_inflictor = inflictor;
647 if(!autocvar_g_friendlyfire_virtual_force)
658 if(targ.classname == "player")
659 if(attacker.classname == "player")
662 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
663 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
666 if(targ.classname == "player")
669 if ((deathtype == DEATH_FALL) ||
670 (deathtype == DEATH_DROWN) ||
671 (deathtype == DEATH_SLIME) ||
672 (deathtype == DEATH_LAVA) ||
673 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
680 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
682 targ.armorvalue -= 1;
683 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
686 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
688 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
692 if (targ != attacker)
694 if ((targ.health >= 1) && (targ.classname == "player"))
695 centerprint(attacker, "Secondary fire inflicts no damage!");
703 if not(DEATH_ISSPECIAL(deathtype))
705 damage *= g_weapondamagefactor;
706 mirrordamage *= g_weapondamagefactor;
707 force = force * g_weaponforcefactor;
708 mirrorforce *= g_weaponforcefactor;
711 // should this be changed at all? If so, in what way?
712 frag_attacker = attacker;
714 frag_damage = damage;
716 frag_deathtype = deathtype;
717 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
718 damage = frag_damage;
721 // apply strength multiplier
722 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
726 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
727 force = force * autocvar_g_balance_powerup_strength_selfforce;
731 damage = damage * autocvar_g_balance_powerup_strength_damage;
732 force = force * autocvar_g_balance_powerup_strength_force;
736 // apply invincibility multiplier
737 if (targ.items & IT_INVINCIBLE && !g_minstagib)
738 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
740 if (targ == attacker)
742 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
745 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
748 // CTF: reduce damage/force
753 damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
754 force = force * autocvar_g_ctf_flagcarrier_selfforce;
759 // apply strength rune
760 if (attacker.runes & RUNE_STRENGTH)
762 if(attacker.runes & CURSE_WEAK) // have both curse & rune
764 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
765 force = force * autocvar_g_balance_rune_strength_combo_force;
769 damage = damage * autocvar_g_balance_rune_strength_damage;
770 force = force * autocvar_g_balance_rune_strength_force;
773 else if (attacker.runes & CURSE_WEAK)
775 damage = damage * autocvar_g_balance_curse_weak_damage;
776 force = force * autocvar_g_balance_curse_weak_force;
779 // apply defense rune
780 if (targ.runes & RUNE_DEFENSE)
782 if (targ.runes & CURSE_VULNER) // have both curse & rune
783 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
785 damage = damage * autocvar_g_balance_rune_defense_takedamage;
787 else if (targ.runes & CURSE_VULNER)
788 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
794 if(targ.takedamage == DAMAGE_AIM)
797 if(damage_headshotbonus > 0)
799 if(targ.classname == "player")
802 // find height of hit on player axis
803 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
804 vector headmins, headmaxs, org;
805 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
806 headmins = org + GetHeadshotMins(targ);
807 headmaxs = org + GetHeadshotMaxs(targ);
808 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
810 deathtype |= HITTYPE_HEADSHOT;
813 else if(targ.classname == "turret_head")
815 deathtype |= HITTYPE_HEADSHOT;
817 if(deathtype & HITTYPE_HEADSHOT)
818 damage *= 1 + damage_headshotbonus;
822 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
827 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
829 if(IsDifferentTeam(victim, attacker))
833 if(deathtype != DEATH_FIRE)
835 if(victim.BUTTON_CHAT)
836 attacker.typehitsound += 1;
838 attacker.hitsound += 1;
841 damage_goodhits += 1;
842 damage_gooddamage += damage;
844 if not(DEATH_ISSPECIAL(deathtype))
846 if(targ.classname == "player") // don't do this for vehicles
852 if(victim.items & IT_STRENGTH)
855 if(deathtype & HITTYPE_HEADSHOT)
859 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
864 if(deathtype != DEATH_FIRE)
866 attacker.typehitsound += 1;
869 if(time > attacker.teamkill_complain)
871 attacker.teamkill_complain = time + 5;
872 attacker.teamkill_soundtime = time + 0.4;
873 attacker.teamkill_soundsource = targ;
881 if (self.damageforcescale)
883 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
885 self.velocity = self.velocity + damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
886 self.flags &~= FL_ONGROUND;
887 UpdateCSQCProjectile(self);
890 if (damage != 0 || (self.damageforcescale && vlen(force)))
891 if (self.event_damage)
892 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
895 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
899 if (attacker.runes & RUNE_VAMPIRE)
901 // apply vampire rune
902 if (attacker.runes & CURSE_EMPATHY) // have the curse too
904 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
905 attacker.health = bound(
906 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
907 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
908 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
912 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
913 attacker.health = bound(
914 attacker.health, // LA: was 3, but changed so that you can't lose health
915 // empathy won't let you gain health in the same way...
916 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
917 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
920 // apply empathy curse
921 else if (attacker.runes & CURSE_EMPATHY)
923 attacker.health = bound(
924 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
925 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
931 // apply mirror damage if any
932 if(mirrordamage > 0 || mirrorforce > 0)
934 attacker = attacker_save;
938 // just lose extra LIVES, don't kill the player for mirror damage
939 if(attacker.armorvalue > 0)
941 attacker.armorvalue = attacker.armorvalue - 1;
942 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
943 attacker.hitsound += 1;
948 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
949 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
953 float RadiusDamage_running;
954 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
955 // Returns total damage applies to creatures
965 float total_damage_to_creatures;
970 float stat_damagedone;
972 if(RadiusDamage_running)
974 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
978 RadiusDamage_running = 1;
980 tfloordmg = autocvar_g_throughfloor_damage;
981 tfloorforce = autocvar_g_throughfloor_force;
983 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
984 total_damage_to_creatures = 0;
986 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
987 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
989 force = inflictor.velocity;
993 force = normalize(force);
994 if(forceintensity >= 0)
995 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
997 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1000 stat_damagedone = 0;
1002 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
1006 if (targ != inflictor)
1007 if (ignore != targ) if(targ.takedamage)
1009 // LordHavoc: measure distance to nearest point on target (not origin)
1010 // (this guarentees 100% damage on a touch impact)
1011 nearest = targ.WarpZone_findradius_nearest;
1012 diff = targ.WarpZone_findradius_dist;
1013 // round up a little on the damage to ensure full damage on impacts
1014 // and turn the distance into a fraction of the radius
1015 power = 1 - ((vlen (diff) - 2) / rad);
1017 //bprint(ftos(power));
1018 //if (targ == attacker)
1019 // print(ftos(power), "\n");
1024 finaldmg = coredamage * power + edgedamage * (1 - power);
1033 vector myblastorigin;
1034 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1035 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1036 // if it's a player, use the view origin as reference
1037 if (targ.classname == "player")
1038 center = targ.origin + targ.view_ofs;
1039 force = normalize(center - myblastorigin);
1040 force = force * (finaldmg / coredamage) * forceintensity;
1041 // test line of sight to multiple positions on box,
1042 // and do damage if any of them hit
1044 if (targ.classname == "player")
1045 total = ceil(bound(1, finaldmg, 50));
1047 total = ceil(bound(1, finaldmg/10, 5));
1052 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1053 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1054 if (trace_fraction == 1 || trace_ent == targ)
1058 hitloc = hitloc + nearest;
1062 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1063 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1064 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1067 nearest = hitloc * (1 / max(1, hits));
1068 hitratio = (hits / total);
1069 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1070 finaldmg = finaldmg * a;
1071 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1074 // laser force adjustments :P
1075 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1077 if (targ == attacker)
1082 float force_velocitybiasramp;
1083 float force_velocitybias;
1085 force_velocitybiasramp = autocvar_sv_maxspeed;
1086 if(deathtype & HITTYPE_SECONDARY)
1088 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1089 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1093 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1094 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1097 vel = targ.velocity;
1099 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1103 normalize(normalize(force) + vel);
1105 force_z *= force_zscale;
1109 if(deathtype & HITTYPE_SECONDARY)
1111 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1115 force *= autocvar_g_balance_laser_primary_force_other_scale;
1120 //if (targ == attacker)
1122 // print("hits ", ftos(hits), " / ", ftos(total));
1123 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1124 // print(" (", ftos(a), ")\n");
1126 if(hits || tfloordmg || tfloorforce)
1130 total_damage_to_creatures += finaldmg;
1132 if(accuracy_isgooddamage(attacker, targ))
1133 stat_damagedone += finaldmg;
1136 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1137 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1139 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1147 RadiusDamage_running = 0;
1149 if(!DEATH_ISSPECIAL(deathtype))
1150 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1152 return total_damage_to_creatures;
1155 .float fire_damagepersec;
1156 .float fire_endtime;
1157 .float fire_deathtype;
1159 .float fire_hitsound;
1160 .entity fire_burner;
1162 void fireburner_think();
1164 float Fire_IsBurning(entity e)
1166 return (time < e.fire_endtime);
1169 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1172 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1174 if(e.classname == "player")
1183 // print("adding a fire burner to ", e.classname, "\n");
1184 e.fire_burner = spawn();
1185 e.fire_burner.classname = "fireburner";
1186 e.fire_burner.think = fireburner_think;
1187 e.fire_burner.nextthink = time;
1188 e.fire_burner.owner = e;
1194 if(Fire_IsBurning(e))
1196 mintime = e.fire_endtime - time;
1197 maxtime = max(mintime, t);
1199 mindps = e.fire_damagepersec;
1200 maxdps = max(mindps, dps);
1202 if(maxtime > mintime || maxdps > mindps)
1204 mindamage = mindps * mintime;
1205 maxdamage = mindamage + d;
1207 // interval [mintime, maxtime] * [mindps, maxdps]
1209 // [mindamage, maxdamage]
1212 if(maxdamage >= maxtime * maxdps)
1214 totaltime = maxtime;
1215 totaldamage = maxtime * maxdps;
1217 // this branch increases totaldamage if either t > mintime, or dps > mindps
1221 // maxdamage is inside the interval!
1222 // first, try to use mindps; only if this fails, increase dps as needed
1223 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1224 totaldamage = maxdamage;
1225 // can totaldamage / totaltime be >= maxdps?
1226 // max(mindps, maxdamage / maxtime) >= maxdps?
1227 // we know maxdamage < maxtime * maxdps
1230 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1233 // total conditions for increasing:
1234 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1236 // if maxtime = mintime, maxdps = mindps
1238 // maxdamage = mindamage + d
1239 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1240 // so the last condition is not needed
1242 e.fire_damagepersec = totaldamage / totaltime;
1243 e.fire_endtime = time + totaltime;
1244 if(totaldamage > 1.2 * mindamage)
1246 e.fire_deathtype = dt;
1247 if(e.fire_owner != o)
1250 e.fire_hitsound = FALSE;
1253 if(accuracy_isgooddamage(o, e))
1254 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1255 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1262 e.fire_damagepersec = dps;
1263 e.fire_endtime = time + t;
1264 e.fire_deathtype = dt;
1266 e.fire_hitsound = FALSE;
1267 if(accuracy_isgooddamage(o, e))
1268 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1273 void Fire_ApplyDamage(entity e)
1278 if not(Fire_IsBurning(e))
1281 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1282 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1285 // water and slime stop fire
1287 if(e.watertype != CONTENT_LAVA)
1291 if(e.freezetag_frozen)
1294 t = min(frametime, e.fire_endtime - time);
1295 d = e.fire_damagepersec * t;
1297 hi = e.fire_owner.hitsound;
1298 ty = e.fire_owner.typehitsound;
1299 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1300 if(e.fire_hitsound && e.fire_owner)
1302 e.fire_owner.hitsound = hi;
1303 e.fire_owner.typehitsound = ty;
1305 e.fire_hitsound = TRUE;
1307 if not(IS_INDEPENDENT_PLAYER(e))
1308 FOR_EACH_PLAYER(other) if(e != other)
1310 if(other.classname == "player")
1311 if(other.deadflag == DEAD_NO)
1312 if not(IS_INDEPENDENT_PLAYER(other))
1313 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1315 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1316 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1317 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1322 void Fire_ApplyEffect(entity e)
1324 if(Fire_IsBurning(e))
1325 e.effects |= EF_FLAME;
1327 e.effects &~= EF_FLAME;
1330 void fireburner_think()
1332 // for players, this is done in the regular loop
1333 if(wasfreed(self.owner))
1338 Fire_ApplyEffect(self.owner);
1339 if(!Fire_IsBurning(self.owner))
1341 self.owner.fire_burner = world;
1345 Fire_ApplyDamage(self.owner);
1346 self.nextthink = time;