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 AppendItemcodes(string s, entity player)
229 // w = player.switchweapon;
231 w = player.cnt; // previous weapon!
232 s = strcat(s, ftos(w));
233 if(time < player.strength_finished)
235 if(time < player.invincible_finished)
237 if(player.flagcarried != world)
239 if(player.BUTTON_CHAT)
244 s = strcat(s, "|", ftos(player.runes));
248 void LogDeath(string mode, float deathtype, entity killer, entity killed)
251 if(!autocvar_sv_eventlog)
253 s = strcat(":kill:", mode);
254 s = strcat(s, ":", ftos(killer.playerid));
255 s = strcat(s, ":", ftos(killed.playerid));
256 s = strcat(s, ":type=", ftos(deathtype));
257 s = strcat(s, ":items=");
258 s = AppendItemcodes(s, killer);
261 s = strcat(s, ":victimitems=");
262 s = AppendItemcodes(s, killed);
267 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
269 WriteByte(MSG_ALL, SVC_TEMPENTITY);
270 WriteByte(MSG_ALL, TE_CSQC_KILLNOTIFY);
271 WriteString(MSG_ALL, s1);
272 WriteString(MSG_ALL, s2);
273 WriteString(MSG_ALL, s3);
274 WriteShort(MSG_ALL, msg);
275 WriteByte(MSG_ALL, type);
278 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
279 void Send_CSQC_KillCenterprint(entity e, string s1, string s2, float msg, float type)
281 if (clienttype(e) == CLIENTTYPE_REAL)
284 WRITESPECTATABLE_MSG_ONE({
285 WriteByte(MSG_ONE, SVC_TEMPENTITY);
286 WriteByte(MSG_ONE, TE_CSQC_KILLCENTERPRINT);
287 WriteString(MSG_ONE, s1);
288 WriteString(MSG_ONE, s2);
289 WriteShort(MSG_ONE, msg);
290 WriteByte(MSG_ONE, type);
295 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
300 if (targ.classname == "player")
303 a = attacker.netname;
305 if (targ == attacker) // suicides
307 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
308 msg = ColoredTeamName(targ.team); // TODO: check if needed?
309 if(!g_cts) // no "killed your own dumb self" message in CTS
310 Send_CSQC_KillCenterprint(targ, msg, "", deathtype, MSG_SUICIDE);
312 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
314 LogDeath("suicide", deathtype, targ, targ);
315 GiveFrags(attacker, targ, -1, deathtype);
318 if (targ.killcount > 2)
319 msg = ftos(targ.killcount);
320 if(teamplay && deathtype == DEATH_MIRRORDAMAGE)
322 if(attacker.team == COLOR_TEAM1)
323 deathtype = KILL_TEAM_RED;
325 deathtype = KILL_TEAM_BLUE;
328 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
330 else if (attacker.classname == "player")
332 if(teamplay && attacker.team == targ.team)
334 if(attacker.team == COLOR_TEAM1)
335 type = KILL_TEAM_RED;
337 type = KILL_TEAM_BLUE;
339 GiveFrags(attacker, targ, -1, deathtype);
341 Send_CSQC_KillCenterprint(attacker, s, "", type, MSG_KILL);
343 if (targ.killcount > 2) {
344 msg = ftos(targ.killcount);
347 if (attacker.killcount > 2) {
348 msg = ftos(attacker.killcount);
349 type = KILL_TEAM_SPREE;
351 Send_KillNotification(a, s, msg, type, MSG_KILL);
353 attacker.killcount = 0;
355 LogDeath("tk", deathtype, attacker, targ);
359 if (!checkrules_firstblood)
361 checkrules_firstblood = TRUE;
362 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
363 // TODO: make these print a newline if they dont
364 Send_CSQC_KillCenterprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
365 Send_CSQC_KillCenterprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
366 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
367 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
370 if((autocvar_sv_fragmessage_information_typefrag) && (targ.BUTTON_CHAT)) {
371 Send_CSQC_KillCenterprint(attacker, s, GetAdvancedDeathReports(targ), KILL_TYPEFRAG, MSG_KILL);
372 Send_CSQC_KillCenterprint(targ, a, GetAdvancedDeathReports(attacker), KILL_TYPEFRAGGED, MSG_KILL);
374 Send_CSQC_KillCenterprint(attacker, s, GetAdvancedDeathReports(targ), KILL_FRAG, MSG_KILL);
375 Send_CSQC_KillCenterprint(targ, a, GetAdvancedDeathReports(attacker), KILL_FRAGGED, MSG_KILL);
378 attacker.taunt_soundtime = time + 1;
381 if (deathtype == DEATH_CUSTOM)
384 msg = inflictor.message2;
386 if(strstrofs(msg, "%", 0) < 0)
387 msg = strcat("%s ", msg, " by %s");
389 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
391 if(g_ctf && targ.flagcarried)
393 UpdateFrags(attacker, ctf_score_value("score_kill"));
394 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
395 GiveFrags(attacker, targ, 0, deathtype); // for logging
398 GiveFrags(attacker, targ, 1, deathtype);
400 if (targ.killcount > 2) {
401 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
404 attacker.killcount = attacker.killcount + 1;
406 if (attacker.killcount > 2) {
407 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
409 else if (attacker.killcount == 3)
411 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
412 AnnounceTo(attacker, "03kills");
413 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
415 else if (attacker.killcount == 5)
417 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
418 AnnounceTo(attacker, "05kills");
419 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
421 else if (attacker.killcount == 10)
423 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
424 AnnounceTo(attacker, "10kills");
425 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
427 else if (attacker.killcount == 15)
429 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
430 AnnounceTo(attacker, "15kills");
431 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
433 else if (attacker.killcount == 20)
435 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
436 AnnounceTo(attacker, "20kills");
437 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
439 else if (attacker.killcount == 25)
441 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
442 AnnounceTo(attacker, "25kills");
443 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
445 else if (attacker.killcount == 30)
447 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
448 AnnounceTo(attacker, "30kills");
449 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
451 LogDeath("frag", deathtype, attacker, targ);
456 Send_CSQC_KillCenterprint(targ, "", "", deathtype, MSG_KILL_ACTION);
457 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
458 msg = inflictor.message;
459 else if (deathtype == DEATH_CUSTOM)
461 if(strstrofs(msg, "%", 0) < 0)
462 msg = strcat("%s ", msg);
464 GiveFrags(targ, targ, -1, deathtype);
465 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
466 AnnounceTo(targ, "botlike");
467 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
469 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
471 if (targ.killcount > 2)
472 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
474 LogDeath("accident", deathtype, targ, targ);
477 targ.death_origin = targ.origin;
479 targ.killer_origin = attacker.origin;
481 // FIXME: this should go in PutClientInServer
487 // these are updated by each Damage call for use in button triggering and such
489 entity damage_inflictor;
490 entity damage_attacker;
492 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
497 entity attacker_save;
501 if (gameover || targ.killcount == -666)
504 local entity oldself;
508 damage_inflictor = inflictor;
509 damage_attacker = attacker;
510 attacker_save = attacker;
512 if(targ.classname == "player")
515 if(targ.hook.aiment == attacker)
516 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
518 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
519 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
521 if(targ.classname == "player")
522 if not(IsDifferentTeam(targ, attacker))
529 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
531 // These are ALWAYS lethal
532 // No damage modification here
533 // Instead, prepare the victim for his death...
535 targ.spawnshieldtime = 0;
536 targ.health = 0.9; // this is < 1
537 targ.flags -= targ.flags & FL_GODMODE;
540 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
546 if (targ.classname == "player")
547 if (attacker.classname == "player")
550 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
552 // nullify damage if teamplay is on
553 if(deathtype != DEATH_TELEFRAG)
554 if(attacker.classname == "player")
556 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
561 else if(teamplay && attacker.team == targ.team)
563 if(autocvar_teamplay_mode == 1)
565 else if(attacker != targ)
567 if(autocvar_teamplay_mode == 3)
569 else if(autocvar_teamplay_mode == 4)
571 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
573 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
574 attacker.dmg_team = attacker.dmg_team + damage;
575 if(attacker.dmg_team > teamdamage0 && !g_ca)
576 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
577 mirrorforce = autocvar_g_mirrordamage * vlen(force);
580 if(autocvar_g_friendlyfire == 0)
586 damage = autocvar_g_friendlyfire * damage;
587 // mirrordamage will be used LATER
589 if(autocvar_g_mirrordamage_virtual)
592 v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
593 attacker.dmg_take += v_x;
594 attacker.dmg_save += v_y;
595 attacker.dmg_inflictor = inflictor;
600 if(autocvar_g_friendlyfire_virtual)
603 v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
604 targ.dmg_take += v_x;
605 targ.dmg_save += v_y;
606 targ.dmg_inflictor = inflictor;
608 if(!autocvar_g_friendlyfire_virtual_force)
619 if(targ.classname == "player")
620 if(attacker.classname == "player")
623 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
624 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
627 if(targ.classname == "player")
630 if ((deathtype == DEATH_FALL) ||
631 (deathtype == DEATH_DROWN) ||
632 (deathtype == DEATH_SLIME) ||
633 (deathtype == DEATH_LAVA) ||
634 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
641 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
643 targ.armorvalue -= 1;
644 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
647 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
649 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
653 if (targ != attacker)
655 if ((targ.health >= 1) && (targ.classname == "player"))
656 centerprint(attacker, "Secondary fire inflicts no damage!");
664 if not(DEATH_ISSPECIAL(deathtype))
666 damage *= g_weapondamagefactor;
667 mirrordamage *= g_weapondamagefactor;
668 force = force * g_weaponforcefactor;
669 mirrorforce *= g_weaponforcefactor;
672 // should this be changed at all? If so, in what way?
673 frag_attacker = attacker;
675 frag_damage = damage;
677 frag_deathtype = deathtype;
678 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
679 damage = frag_damage;
682 // apply strength multiplier
683 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
687 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
688 force = force * autocvar_g_balance_powerup_strength_selfforce;
692 damage = damage * autocvar_g_balance_powerup_strength_damage;
693 force = force * autocvar_g_balance_powerup_strength_force;
697 // apply invincibility multiplier
698 if (targ.items & IT_INVINCIBLE && !g_minstagib)
699 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
701 if (targ == attacker)
703 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
706 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
709 // CTF: reduce damage/force
714 damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
715 force = force * autocvar_g_ctf_flagcarrier_selfforce;
720 // apply strength rune
721 if (attacker.runes & RUNE_STRENGTH)
723 if(attacker.runes & CURSE_WEAK) // have both curse & rune
725 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
726 force = force * autocvar_g_balance_rune_strength_combo_force;
730 damage = damage * autocvar_g_balance_rune_strength_damage;
731 force = force * autocvar_g_balance_rune_strength_force;
734 else if (attacker.runes & CURSE_WEAK)
736 damage = damage * autocvar_g_balance_curse_weak_damage;
737 force = force * autocvar_g_balance_curse_weak_force;
740 // apply defense rune
741 if (targ.runes & RUNE_DEFENSE)
743 if (targ.runes & CURSE_VULNER) // have both curse & rune
744 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
746 damage = damage * autocvar_g_balance_rune_defense_takedamage;
748 else if (targ.runes & CURSE_VULNER)
749 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
755 if(targ.takedamage == DAMAGE_AIM)
758 if(targ.classname == "player")
761 // find height of hit on player axis
762 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
763 vector headmins, headmaxs, org;
764 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
765 headmins = org + GetHeadshotMins(targ);
766 headmaxs = org + GetHeadshotMaxs(targ);
767 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
769 deathtype |= HITTYPE_HEADSHOT;
772 else if(targ.classname == "turret_head")
774 deathtype |= HITTYPE_HEADSHOT;
776 if(deathtype & HITTYPE_HEADSHOT)
777 damage *= 1 + damage_headshotbonus;
780 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
785 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
787 if(IsDifferentTeam(victim, attacker))
791 if(deathtype != DEATH_FIRE)
793 if(victim.BUTTON_CHAT)
794 attacker.typehitsound += 1;
796 attacker.hitsound += 1;
799 damage_goodhits += 1;
800 damage_gooddamage += damage;
802 if not(DEATH_ISSPECIAL(deathtype))
804 if(targ.classname == "player") // don't do this for vehicles
810 if(victim.items & IT_STRENGTH)
813 if(deathtype & HITTYPE_HEADSHOT)
817 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
822 if(deathtype != DEATH_FIRE)
824 attacker.typehitsound += 1;
827 if(time > attacker.teamkill_complain)
829 attacker.teamkill_complain = time + 5;
830 attacker.teamkill_soundtime = time + 0.4;
831 attacker.teamkill_soundsource = targ;
839 if (self.damageforcescale)
841 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
843 self.velocity = self.velocity + damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
844 self.flags &~= FL_ONGROUND;
845 UpdateCSQCProjectile(self);
848 if (damage != 0 || (self.damageforcescale && vlen(force)))
849 if (self.event_damage)
850 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
853 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
857 if (attacker.runes & RUNE_VAMPIRE)
859 // apply vampire rune
860 if (attacker.runes & CURSE_EMPATHY) // have the curse too
862 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
863 attacker.health = bound(
864 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
865 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
866 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
870 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
871 attacker.health = bound(
872 attacker.health, // LA: was 3, but changed so that you can't lose health
873 // empathy won't let you gain health in the same way...
874 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
875 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
878 // apply empathy curse
879 else if (attacker.runes & CURSE_EMPATHY)
881 attacker.health = bound(
882 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
883 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
889 // apply mirror damage if any
890 if(mirrordamage > 0 || mirrorforce > 0)
892 attacker = attacker_save;
896 // just lose extra LIVES, don't kill the player for mirror damage
897 if(attacker.armorvalue > 0)
899 attacker.armorvalue = attacker.armorvalue - 1;
900 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
901 attacker.hitsound += 1;
906 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
907 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
911 float RadiusDamage_running;
912 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
913 // Returns total damage applies to creatures
923 float total_damage_to_creatures;
928 float stat_damagedone;
930 if(RadiusDamage_running)
932 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
936 RadiusDamage_running = 1;
938 tfloordmg = autocvar_g_throughfloor_damage;
939 tfloorforce = autocvar_g_throughfloor_force;
941 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
942 total_damage_to_creatures = 0;
944 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
945 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
947 force = inflictor.velocity;
951 force = normalize(force);
952 if(forceintensity >= 0)
953 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
955 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
960 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
964 if (targ != inflictor)
965 if (ignore != targ) if(targ.takedamage)
967 // LordHavoc: measure distance to nearest point on target (not origin)
968 // (this guarentees 100% damage on a touch impact)
969 nearest = targ.WarpZone_findradius_nearest;
970 diff = targ.WarpZone_findradius_dist;
971 // round up a little on the damage to ensure full damage on impacts
972 // and turn the distance into a fraction of the radius
973 power = 1 - ((vlen (diff) - 2) / rad);
975 //bprint(ftos(power));
976 //if (targ == attacker)
977 // print(ftos(power), "\n");
982 finaldmg = coredamage * power + edgedamage * (1 - power);
989 local float hitratio;
991 local vector myblastorigin;
992 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
993 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
994 // if it's a player, use the view origin as reference
995 if (targ.classname == "player")
996 center = targ.origin + targ.view_ofs;
997 force = normalize(center - myblastorigin);
998 force = force * (finaldmg / coredamage) * forceintensity;
999 // test line of sight to multiple positions on box,
1000 // and do damage if any of them hit
1002 if (targ.classname == "player")
1003 total = ceil(bound(1, finaldmg, 50));
1005 total = ceil(bound(1, finaldmg/10, 5));
1010 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1011 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1012 if (trace_fraction == 1 || trace_ent == targ)
1016 hitloc = hitloc + nearest;
1020 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1021 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1022 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1025 nearest = hitloc * (1 / max(1, hits));
1026 hitratio = (hits / total);
1027 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1028 finaldmg = finaldmg * a;
1029 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1032 // laser force adjustments :P
1033 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1035 if (targ == attacker)
1040 float force_velocitybiasramp;
1041 float force_velocitybias;
1043 force_velocitybiasramp = autocvar_sv_maxspeed;
1044 if(deathtype & HITTYPE_SECONDARY)
1046 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1047 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1051 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1052 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1055 vel = targ.velocity;
1057 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1061 normalize(normalize(force) + vel);
1063 force_z *= force_zscale;
1067 if(deathtype & HITTYPE_SECONDARY)
1069 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1073 force *= autocvar_g_balance_laser_primary_force_other_scale;
1078 //if (targ == attacker)
1080 // print("hits ", ftos(hits), " / ", ftos(total));
1081 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1082 // print(" (", ftos(a), ")\n");
1084 if(hits || tfloordmg || tfloorforce)
1088 total_damage_to_creatures += finaldmg;
1090 if(accuracy_isgooddamage(attacker, targ))
1091 stat_damagedone += finaldmg;
1094 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1095 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1097 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1105 RadiusDamage_running = 0;
1107 if(!DEATH_ISSPECIAL(deathtype))
1108 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1110 return total_damage_to_creatures;
1113 .float fire_damagepersec;
1114 .float fire_endtime;
1115 .float fire_deathtype;
1117 .float fire_hitsound;
1118 .entity fire_burner;
1120 void fireburner_think();
1122 float Fire_IsBurning(entity e)
1124 return (time < e.fire_endtime);
1127 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1130 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1132 if(e.classname == "player")
1141 // print("adding a fire burner to ", e.classname, "\n");
1142 e.fire_burner = spawn();
1143 e.fire_burner.classname = "fireburner";
1144 e.fire_burner.think = fireburner_think;
1145 e.fire_burner.nextthink = time;
1146 e.fire_burner.owner = e;
1152 if(Fire_IsBurning(e))
1154 mintime = e.fire_endtime - time;
1155 maxtime = max(mintime, t);
1157 mindps = e.fire_damagepersec;
1158 maxdps = max(mindps, dps);
1160 if(maxtime > mintime || maxdps > mindps)
1162 mindamage = mindps * mintime;
1163 maxdamage = mindamage + d;
1165 // interval [mintime, maxtime] * [mindps, maxdps]
1167 // [mindamage, maxdamage]
1170 if(maxdamage >= maxtime * maxdps)
1172 totaltime = maxtime;
1173 totaldamage = maxtime * maxdps;
1175 // this branch increases totaldamage if either t > mintime, or dps > mindps
1179 // maxdamage is inside the interval!
1180 // first, try to use mindps; only if this fails, increase dps as needed
1181 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1182 totaldamage = maxdamage;
1183 // can totaldamage / totaltime be >= maxdps?
1184 // max(mindps, maxdamage / maxtime) >= maxdps?
1185 // we know maxdamage < maxtime * maxdps
1188 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1191 // total conditions for increasing:
1192 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1194 // if maxtime = mintime, maxdps = mindps
1196 // maxdamage = mindamage + d
1197 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1198 // so the last condition is not needed
1200 e.fire_damagepersec = totaldamage / totaltime;
1201 e.fire_endtime = time + totaltime;
1202 if(totaldamage > 1.2 * mindamage)
1204 e.fire_deathtype = dt;
1205 if(e.fire_owner != o)
1208 e.fire_hitsound = FALSE;
1211 if(accuracy_isgooddamage(o, e))
1212 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1213 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1220 e.fire_damagepersec = dps;
1221 e.fire_endtime = time + t;
1222 e.fire_deathtype = dt;
1224 e.fire_hitsound = FALSE;
1225 if(accuracy_isgooddamage(o, e))
1226 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1231 void Fire_ApplyDamage(entity e)
1236 if not(Fire_IsBurning(e))
1239 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1240 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1243 // water and slime stop fire
1245 if(e.watertype != CONTENT_LAVA)
1249 if(e.freezetag_frozen)
1252 t = min(frametime, e.fire_endtime - time);
1253 d = e.fire_damagepersec * t;
1255 hi = e.fire_owner.hitsound;
1256 ty = e.fire_owner.typehitsound;
1257 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1258 if(e.fire_hitsound && e.fire_owner)
1260 e.fire_owner.hitsound = hi;
1261 e.fire_owner.typehitsound = ty;
1263 e.fire_hitsound = TRUE;
1265 if not(IS_INDEPENDENT_PLAYER(e))
1266 FOR_EACH_PLAYER(other) if(e != other)
1268 if(other.classname == "player")
1269 if(other.deadflag == DEAD_NO)
1270 if not(IS_INDEPENDENT_PLAYER(other))
1271 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1273 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1274 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1275 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1280 void Fire_ApplyEffect(entity e)
1282 if(Fire_IsBurning(e))
1283 e.effects |= EF_FLAME;
1285 e.effects &~= EF_FLAME;
1288 void fireburner_think()
1290 // for players, this is done in the regular loop
1291 if(wasfreed(self.owner))
1296 Fire_ApplyEffect(self.owner);
1297 if(!Fire_IsBurning(self.owner))
1299 self.owner.fire_burner = world;
1303 Fire_ApplyDamage(self.owner);
1304 self.nextthink = time;