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;
52 .float teamkill_complain;
53 .float teamkill_soundtime;
54 .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 void UpdateFrags(entity player, float f)
89 PlayerTeamScore_AddScore(player, f);
92 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
93 void W_SwitchWeapon_Force(entity e, float w);
94 entity GiveFrags_randomweapons;
95 void GiveFrags (entity attacker, entity targ, float f, float deathtype)
97 // TODO route through PlayerScores instead
105 PlayerScore_Add(attacker, SP_SUICIDES, 1);
110 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
116 PlayerScore_Add(attacker, SP_KILLS, 1);
118 PlayerStats_Event(attacker, sprintf("kills-%d", targ.playerid), 1);
121 PlayerScore_Add(targ, SP_DEATHS, 1);
124 if(autocvar_g_arena_roundbased)
127 if(targ != attacker) // not for suicides
128 if(g_weaponarena_random)
130 // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
132 culprit = DEATH_WEAPONOF(deathtype);
134 culprit = attacker.weapon;
135 else if(!WEPSET_CONTAINS_EW(attacker, culprit))
136 culprit = attacker.weapon;
138 if(g_weaponarena_random_with_laser && culprit == WEP_LASER)
144 if(!GiveFrags_randomweapons)
146 GiveFrags_randomweapons = spawn();
147 GiveFrags_randomweapons.classname = "GiveFrags_randomweapons";
151 WEPSET_COPY_EA(GiveFrags_randomweapons, warmup_start_weapons);
153 WEPSET_COPY_EA(GiveFrags_randomweapons, start_weapons);
155 // all others (including the culprit): remove
156 WEPSET_ANDNOT_EE(GiveFrags_randomweapons, attacker);
157 WEPSET_ANDNOT_EW(GiveFrags_randomweapons, culprit);
159 // among the remaining ones, choose one by random
160 W_RandomWeapons(GiveFrags_randomweapons, 1);
162 if(!WEPSET_EMPTY_E(GiveFrags_randomweapons))
164 WEPSET_OR_EE(attacker, GiveFrags_randomweapons);
165 WEPSET_ANDNOT_EW(attacker, culprit);
169 // after a frag, choose another random weapon set
170 if not(WEPSET_CONTAINS_EW(attacker, 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 attacker.totalfrags += f;
216 UpdateFrags(attacker, f);
219 string AppendItemcodes(string s, entity player)
224 // w = player.switchweapon;
226 w = player.cnt; // previous weapon!
227 s = strcat(s, ftos(w));
228 if(time < player.strength_finished)
230 if(time < player.invincible_finished)
232 if(player.flagcarried != world)
234 if(player.BUTTON_CHAT)
239 s = strcat(s, "|", ftos(player.runes));
243 void LogDeath(string mode, float deathtype, entity killer, entity killed)
246 if(!autocvar_sv_eventlog)
248 s = strcat(":kill:", mode);
249 s = strcat(s, ":", ftos(killer.playerid));
250 s = strcat(s, ":", ftos(killed.playerid));
251 s = strcat(s, ":type=", Deathtype_Name(deathtype));
252 s = strcat(s, ":items=");
253 s = AppendItemcodes(s, killer);
256 s = strcat(s, ":victimitems=");
257 s = AppendItemcodes(s, killed);
262 void Obituary_SpecialDeath(entity notif_target, float murder, float deathtype, string s1, string s2, string s3, float f1, float f2, float f3)
264 if(DEATH_ISSPECIAL(deathtype))
266 entity deathent = deathtypes[(deathtype - DT_FIRST) - 1];
267 if not(deathent) { backtrace("Obituary_SpecialDeath: Could not find deathtype entity!\n"); return; }
271 if(deathent.death_msgmurder)
273 Send_Notification_WOVA(NOTIF_ONE, notif_target, MSG_MULTI, deathent.death_msgmurder.nent_id, s1, s2, s3, "", f1, f2, f3, 0);
274 Send_Notification_WOVA(NOTIF_ALL_EXCEPT, notif_target, MSG_INFO, deathent.death_msgmurder.nent_msginfo.nent_id, s1, s2, s3, "", f1, f2, f3, 0);
279 if(deathent.death_msgself)
281 Send_Notification_WOVA(NOTIF_ONE, notif_target, MSG_MULTI, deathent.death_msgself.nent_id, s1, s2, s3, "", f1, f2, f3, 0);
282 Send_Notification_WOVA(NOTIF_ALL_EXCEPT, notif_target, MSG_INFO, deathent.death_msgself.nent_msginfo.nent_id, s1, s2, s3, "", f1, f2, f3, 0);
286 else { backtrace("Obituary_SpecialDeath called without a special deathtype?\n"); return; }
290 float Obituary_WeaponDeath(entity notif_target, float murder, float deathtype, string s1, string s2, string s3, float f1, float f2)
292 float death_weapon = DEATH_WEAPONOF(deathtype);
295 w_deathtype = deathtype;
296 float death_message = weapon_action(death_weapon, ((murder) ? WR_KILLMESSAGE : WR_SUICIDEMESSAGE));
301 Send_Notification_WOVA(NOTIF_ONE, notif_target, MSG_MULTI, death_message, s1, s2, s3, "", f1, f2, 0, 0);
302 Send_Notification_WOVA(NOTIF_ALL_EXCEPT, notif_target, MSG_INFO, msg_multi_notifs[death_message - 1].nent_msginfo.nent_id, s1, s2, s3, "", f1, f2, 0, 0);
307 "Obituary_WeaponDeath(): ^1Deathtype ^7(%d)^1 has no notification for weapon %d!\n",
318 void Obituary(entity attacker, entity inflictor, entity targ, float deathtype)
321 if not(IS_PLAYER(targ)) { backtrace("Obituary called on non-player?!\n"); return; }
324 float notif_firstblood = FALSE;
325 float kill_count_to_attacker, kill_count_to_target;
327 // Set final information for the death
328 targ.death_origin = targ.origin;
329 if(targ != attacker) { targ.killer_origin = attacker.origin; }
330 string deathlocation = NearestLocation(targ.death_origin);
332 #ifdef NOTIFICATIONS_DEBUG
335 "Obituary(%s, %s, %s, %s = %d);\n",
339 Deathtype_Name(deathtype),
350 if(DEATH_ISSPECIAL(deathtype))
352 if(deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
354 Obituary_SpecialDeath(targ, FALSE, deathtype, targ.netname, deathlocation, "", targ.team, 0, 0);
360 case DEATH_MIRRORDAMAGE:
362 Obituary_SpecialDeath(targ, FALSE, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
368 Obituary_SpecialDeath(targ, FALSE, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
374 else if not(Obituary_WeaponDeath(targ, FALSE, deathtype, targ.netname, deathlocation, "", targ.killcount, 0))
376 backtrace("SUICIDE: what the hell happened here?\n");
379 LogDeath("suicide", deathtype, targ, targ);
380 GiveFrags(attacker, targ, -1, deathtype);
386 else if(attacker.classname == "player")
388 if(!IsDifferentTeam(attacker, targ))
390 LogDeath("tk", deathtype, attacker, targ);
391 GiveFrags(attacker, targ, -1, deathtype);
393 attacker.killcount = 0;
395 Send_Notification(NOTIF_ONE, attacker, MSG_CENTER, CENTER_DEATH_TEAMKILL_FRAG, targ.netname);
396 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_DEATH_TEAMKILL_FRAGGED, attacker.netname);
397 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(targ.team, INFO_DEATH_TEAMKILL_), targ.netname, attacker.netname, targ.killcount);
399 // In this case, the death message will ALWAYS be "foo was betrayed by bar"
400 // No need for specific death/weapon messages...
404 LogDeath("frag", deathtype, attacker, targ);
405 GiveFrags(attacker, targ, 1, deathtype);
407 attacker.taunt_soundtime = time + 1;
408 attacker.killcount = attacker.killcount + 1;
410 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
413 AnnounceTo(attacker, strcat(#countb, "kills")); \
414 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_##counta, 1); \
417 switch(attacker.killcount)
424 if(!checkrules_firstblood)
426 checkrules_firstblood = TRUE;
427 notif_firstblood = TRUE; // modify the current messages so that they too show firstblood information
428 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
429 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
431 // tell spree_inf and spree_cen that this is a first-blood and first-victim event
432 kill_count_to_attacker = -1;
433 kill_count_to_target = -2;
437 kill_count_to_attacker = attacker.killcount;
438 kill_count_to_target = 0;
443 if(attacker.FRAG_VERBOSE)
444 Send_Notification(NOTIF_ONE, attacker, MSG_CENTER, CENTER_DEATH_MURDER_TYPEFRAG_VERBOSE, targ.netname, kill_count_to_attacker, (IS_BOT_CLIENT(targ) ? NO_MSG : targ.ping));
446 Send_Notification(NOTIF_ONE, attacker, MSG_CENTER, CENTER_DEATH_MURDER_TYPEFRAG, targ.netname, kill_count_to_attacker);
448 if(targ.FRAG_VERBOSE)
449 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_DEATH_MURDER_TYPEFRAGGED_VERBOSE, attacker.netname, kill_count_to_target, attacker.health, attacker.armorvalue, (IS_BOT_CLIENT(attacker) ? NO_MSG : attacker.ping));
451 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_DEATH_MURDER_TYPEFRAGGED, attacker.netname, kill_count_to_target);
455 if(attacker.FRAG_VERBOSE)
456 Send_Notification(NOTIF_ONE, attacker, MSG_CENTER, CENTER_DEATH_MURDER_FRAG_VERBOSE, targ.netname, kill_count_to_attacker, (IS_BOT_CLIENT(targ) ? NO_MSG : targ.ping));
458 Send_Notification(NOTIF_ONE, attacker, MSG_CENTER, CENTER_DEATH_MURDER_FRAG, targ.netname, kill_count_to_attacker);
460 if(targ.FRAG_VERBOSE)
461 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_DEATH_MURDER_FRAGGED_VERBOSE, attacker.netname, kill_count_to_target, attacker.health, attacker.armorvalue, (IS_BOT_CLIENT(attacker) ? NO_MSG : attacker.ping));
463 Send_Notification(NOTIF_ONE, targ, MSG_CENTER, CENTER_DEATH_MURDER_FRAGGED, attacker.netname, kill_count_to_target);
466 if not(Obituary_WeaponDeath(targ, TRUE, deathtype, targ.netname, attacker.netname, deathlocation, targ.killcount, kill_count_to_attacker))
467 Obituary_SpecialDeath(targ, TRUE, deathtype, targ.netname, attacker.netname, deathlocation, targ.killcount, kill_count_to_attacker, 0);
478 // For now, we're just forcing HURTTRIGGER to behave as "DEATH_VOID" and giving it no special options...
479 // Later on you will only be able to make custom messages using DEATH_CUSTOM,
480 // and there will be a REAL DEATH_VOID implementation which mappers will use.
481 /*case DEATH_HURTTRIGGER:
484 s2 = inflictor.message;
485 if(strstrofs(s2, "%", 0) < 0) { s2 = strcat("%s ", s2); }
491 Obituary_SpecialDeath(targ, FALSE, deathtype,
493 ((strstrofs(deathmessage, "%", 0) < 0) ? strcat("%s ", deathmessage) : deathmessage),
503 Obituary_SpecialDeath(targ, FALSE, deathtype, targ.netname, deathlocation, "", targ.killcount, 0, 0);
508 LogDeath("accident", deathtype, targ, targ);
509 GiveFrags(targ, targ, -1, deathtype);
511 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5)
513 AnnounceTo(targ, "botlike");
514 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
518 // reset target kill count
519 if(targ.killcount) { targ.killcount = 0; }
522 // these are updated by each Damage call for use in button triggering and such
524 entity damage_inflictor;
525 entity damage_attacker;
527 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
531 float complainteamdamage = 0;
532 entity attacker_save;
536 if (gameover || targ.killcount == -666)
543 damage_inflictor = inflictor;
544 damage_attacker = attacker;
545 attacker_save = attacker;
547 if(targ.classname == "player")
550 if(targ.hook.aiment == attacker)
551 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
553 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
554 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
556 if(targ.classname == "player")
557 if not(IsDifferentTeam(targ, attacker))
564 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
566 // These are ALWAYS lethal
567 // No damage modification here
568 // Instead, prepare the victim for his death...
570 targ.spawnshieldtime = 0;
571 targ.health = 0.9; // this is < 1
572 targ.flags -= targ.flags & FL_GODMODE;
575 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
582 skill based bot damage? gtfo. (tZork)
583 if (targ.classname == "player")
584 if (attacker.classname == "player")
587 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
590 // nullify damage if teamplay is on
591 if(deathtype != DEATH_TELEFRAG)
592 if(attacker.classname == "player")
594 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
599 else if(!IsDifferentTeam(attacker, targ))
601 if(autocvar_teamplay_mode == 1)
603 else if(attacker != targ)
605 if(autocvar_teamplay_mode == 3)
607 else if(autocvar_teamplay_mode == 4)
609 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
611 attacker.dmg_team = attacker.dmg_team + damage;
612 complainteamdamage = attacker.dmg_team - autocvar_g_teamdamage_threshold;
613 if(complainteamdamage > 0 && !g_ca) // FIXME why is g_ca ruled out here? Why not just g_mirrordamage 0 on CA servers?
614 mirrordamage = autocvar_g_mirrordamage * complainteamdamage;
615 mirrorforce = autocvar_g_mirrordamage * vlen(force);
618 if(autocvar_g_friendlyfire == 0)
624 damage = autocvar_g_friendlyfire * damage;
625 // mirrordamage will be used LATER
627 if(autocvar_g_mirrordamage_virtual)
629 vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
630 attacker.dmg_take += v_x;
631 attacker.dmg_save += v_y;
632 attacker.dmg_inflictor = inflictor;
633 mirrordamage = v_z; // = 0, to make fteqcc stfu
637 if(autocvar_g_friendlyfire_virtual)
639 vector v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
640 targ.dmg_take += v_x;
641 targ.dmg_save += v_y;
642 targ.dmg_inflictor = inflictor;
644 if(!autocvar_g_friendlyfire_virtual_force)
655 if(targ.classname == "player")
656 if(attacker.classname == "player")
659 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
660 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
663 if(targ.classname == "player")
666 if ((deathtype == DEATH_FALL) ||
667 (deathtype == DEATH_DROWN) ||
668 (deathtype == DEATH_SLIME) ||
669 (deathtype == DEATH_LAVA) ||
670 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
677 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
679 targ.armorvalue -= 1;
680 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
683 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
685 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
689 complainteamdamage = 0;
690 if (targ != attacker)
692 if ((targ.health >= 1) && (targ.classname == "player"))
693 centerprint(attacker, "Secondary fire inflicts no damage!");
701 if not(DEATH_ISSPECIAL(deathtype))
703 damage *= g_weapondamagefactor;
704 mirrordamage *= g_weapondamagefactor;
705 complainteamdamage *= g_weapondamagefactor;
706 force = force * g_weaponforcefactor;
707 mirrorforce *= g_weaponforcefactor;
710 // should this be changed at all? If so, in what way?
711 frag_attacker = attacker;
713 frag_damage = damage;
715 frag_deathtype = deathtype;
716 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
717 damage = frag_damage;
720 // apply strength multiplier
721 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
725 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
726 force = force * autocvar_g_balance_powerup_strength_selfforce;
730 damage = damage * autocvar_g_balance_powerup_strength_damage;
731 force = force * autocvar_g_balance_powerup_strength_force;
735 // apply invincibility multiplier
736 if (targ.items & IT_INVINCIBLE && !g_minstagib)
737 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
739 if (targ == attacker)
741 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
744 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
749 // apply strength rune
750 if (attacker.runes & RUNE_STRENGTH)
752 if(attacker.runes & CURSE_WEAK) // have both curse & rune
754 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
755 force = force * autocvar_g_balance_rune_strength_combo_force;
759 damage = damage * autocvar_g_balance_rune_strength_damage;
760 force = force * autocvar_g_balance_rune_strength_force;
763 else if (attacker.runes & CURSE_WEAK)
765 damage = damage * autocvar_g_balance_curse_weak_damage;
766 force = force * autocvar_g_balance_curse_weak_force;
769 // apply defense rune
770 if (targ.runes & RUNE_DEFENSE)
772 if (targ.runes & CURSE_VULNER) // have both curse & rune
773 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
775 damage = damage * autocvar_g_balance_rune_defense_takedamage;
777 else if (targ.runes & CURSE_VULNER)
778 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
784 if(targ.takedamage == DAMAGE_AIM)
788 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
793 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
795 if(IsDifferentTeam(victim, attacker))
799 if(deathtype != DEATH_FIRE)
801 if(victim.BUTTON_CHAT)
802 attacker.typehitsound += 1;
804 attacker.hitsound += 1;
807 damage_goodhits += 1;
808 damage_gooddamage += damage;
810 if not(DEATH_ISSPECIAL(deathtype))
812 if(targ.classname == "player") // don't do this for vehicles
818 if(victim.items & IT_STRENGTH)
825 if(deathtype != DEATH_FIRE)
827 attacker.typehitsound += 1;
829 if(complainteamdamage > 0)
830 if(time > attacker.teamkill_complain)
832 attacker.teamkill_complain = time + 5;
833 attacker.teamkill_soundtime = time + 0.4;
834 attacker.teamkill_soundsource = targ;
842 if (self.damageforcescale)
844 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
846 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
847 if(self.movetype == MOVETYPE_PHYSICS)
851 farcent.classname = "farce";
852 farcent.enemy = self;
853 farcent.movedir = farce * 10;
855 farcent.movedir = farcent.movedir * self.mass;
856 farcent.origin = hitloc;
857 farcent.forcetype = FORCETYPE_FORCEATPOS;
858 farcent.nextthink = time + 0.1;
859 farcent.think = SUB_Remove;
862 self.velocity = self.velocity + farce;
863 self.flags &~= FL_ONGROUND;
864 UpdateCSQCProjectile(self);
867 if (damage != 0 || (self.damageforcescale && vlen(force)))
868 if (self.event_damage)
869 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
872 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
876 if (attacker.runes & RUNE_VAMPIRE)
878 // apply vampire rune
879 if (attacker.runes & CURSE_EMPATHY) // have the curse too
881 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
882 attacker.health = bound(
883 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
884 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
885 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
889 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
890 attacker.health = bound(
891 attacker.health, // LA: was 3, but changed so that you can't lose health
892 // empathy won't let you gain health in the same way...
893 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
894 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
897 // apply empathy curse
898 else if (attacker.runes & CURSE_EMPATHY)
900 attacker.health = bound(
901 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
902 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
908 // apply mirror damage if any
909 if(mirrordamage > 0 || mirrorforce > 0)
911 attacker = attacker_save;
915 // just lose extra LIVES, don't kill the player for mirror damage
916 if(attacker.armorvalue > 0)
918 attacker.armorvalue = attacker.armorvalue - 1;
919 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
920 attacker.hitsound += 1;
925 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
926 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
930 float RadiusDamage_running;
931 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
932 // Returns total damage applies to creatures
937 float total_damage_to_creatures;
942 float stat_damagedone;
944 if(RadiusDamage_running)
946 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
950 RadiusDamage_running = 1;
952 tfloordmg = autocvar_g_throughfloor_damage;
953 tfloorforce = autocvar_g_throughfloor_force;
955 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
956 total_damage_to_creatures = 0;
958 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
959 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
961 force = inflictor.velocity;
965 force = normalize(force);
966 if(forceintensity >= 0)
967 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
969 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
974 targ = WarpZone_FindRadius (blastorigin, rad + MAX_DAMAGEEXTRARADIUS, FALSE);
978 if (targ != inflictor)
979 if (ignore != targ) if(targ.takedamage)
985 // LordHavoc: measure distance to nearest point on target (not origin)
986 // (this guarentees 100% damage on a touch impact)
987 nearest = targ.WarpZone_findradius_nearest;
988 diff = targ.WarpZone_findradius_dist;
989 // round up a little on the damage to ensure full damage on impacts
990 // and turn the distance into a fraction of the radius
991 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
993 //bprint(ftos(power));
994 //if (targ == attacker)
995 // print(ftos(power), "\n");
1001 finaldmg = coredamage * power + edgedamage * (1 - power);
1007 vector myblastorigin;
1010 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1012 // if it's a player, use the view origin as reference
1013 center = CENTER_OR_VIEWOFS(targ);
1015 force = normalize(center - myblastorigin);
1016 force = force * (finaldmg / coredamage) * forceintensity;
1019 if(targ != directhitentity)
1024 float mininv_f, mininv_d;
1026 // test line of sight to multiple positions on box,
1027 // and do damage if any of them hit
1030 // we know: max stddev of hitratio = 1 / (2 * sqrt(n))
1031 // so for a given max stddev:
1032 // n = (1 / (2 * max stddev of hitratio))^2
1034 mininv_d = (finaldmg * (1-tfloordmg)) / autocvar_g_throughfloor_damage_max_stddev;
1035 mininv_f = (vlen(force) * (1-tfloorforce)) / autocvar_g_throughfloor_force_max_stddev;
1037 if(autocvar_g_throughfloor_debug)
1038 print(sprintf("THROUGHFLOOR: D=%f F=%f max(dD)=1/%f max(dF)=1/%f", finaldmg, vlen(force), mininv_d, mininv_f));
1040 total = 0.25 * pow(max(mininv_f, mininv_d), 2);
1042 if(autocvar_g_throughfloor_debug)
1043 print(sprintf(" steps=%f", total));
1045 if (targ.classname == "player")
1046 total = ceil(bound(autocvar_g_throughfloor_min_steps_player, total, autocvar_g_throughfloor_max_steps_player));
1048 total = ceil(bound(autocvar_g_throughfloor_min_steps_other, total, autocvar_g_throughfloor_max_steps_other));
1050 if(autocvar_g_throughfloor_debug)
1051 print(sprintf(" steps=%f dD=%f dF=%f", total, finaldmg * (1-tfloordmg) / (2 * sqrt(total)), vlen(force) * (1-tfloorforce) / (2 * sqrt(total))));
1053 for(c = 0; c < total; ++c)
1055 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1056 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1057 if (trace_fraction == 1 || trace_ent == targ)
1061 hitloc = hitloc + nearest;
1065 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1066 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1067 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1070 nearest = hitloc * (1 / max(1, hits));
1071 hitratio = (hits / total);
1072 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1073 finaldmg = finaldmg * a;
1074 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1077 if(autocvar_g_throughfloor_debug)
1078 print(sprintf(" D=%f F=%f\n", finaldmg, vlen(force)));
1081 // laser force adjustments :P
1082 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1084 if (targ == attacker)
1089 float force_velocitybiasramp;
1090 float force_velocitybias;
1092 force_velocitybiasramp = autocvar_sv_maxspeed;
1093 if(deathtype & HITTYPE_SECONDARY)
1095 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1096 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1100 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1101 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1104 vel = targ.velocity;
1106 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1110 normalize(normalize(force) + vel);
1112 force_z *= force_zscale;
1116 if(deathtype & HITTYPE_SECONDARY)
1118 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1122 force *= autocvar_g_balance_laser_primary_force_other_scale;
1127 //if (targ == attacker)
1129 // print("hits ", ftos(hits), " / ", ftos(total));
1130 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1131 // print(" (", ftos(a), ")\n");
1133 if(finaldmg || vlen(force))
1137 total_damage_to_creatures += finaldmg;
1139 if(accuracy_isgooddamage(attacker, targ))
1140 stat_damagedone += finaldmg;
1143 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1144 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1146 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1154 RadiusDamage_running = 0;
1156 if(!DEATH_ISSPECIAL(deathtype))
1157 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1159 return total_damage_to_creatures;
1162 .float fire_damagepersec;
1163 .float fire_endtime;
1164 .float fire_deathtype;
1166 .float fire_hitsound;
1167 .entity fire_burner;
1169 void fireburner_think();
1171 float Fire_IsBurning(entity e)
1173 return (time < e.fire_endtime);
1176 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1179 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1181 if(e.classname == "player")
1190 // print("adding a fire burner to ", e.classname, "\n");
1191 e.fire_burner = spawn();
1192 e.fire_burner.classname = "fireburner";
1193 e.fire_burner.think = fireburner_think;
1194 e.fire_burner.nextthink = time;
1195 e.fire_burner.owner = e;
1201 if(Fire_IsBurning(e))
1203 mintime = e.fire_endtime - time;
1204 maxtime = max(mintime, t);
1206 mindps = e.fire_damagepersec;
1207 maxdps = max(mindps, dps);
1209 if(maxtime > mintime || maxdps > mindps)
1213 // damage we have right now
1214 mindamage = mindps * mintime;
1216 // damage we want to get
1217 maxdamage = mindamage + d;
1219 // but we can't exceed maxtime * maxdps!
1220 totaldamage = min(maxdamage, maxtime * maxdps);
1224 // totaldamage = min(mindamage + d, maxtime * maxdps)
1226 // totaldamage <= maxtime * maxdps
1227 // ==> totaldamage / maxdps <= maxtime.
1229 // totaldamage / mindps = min(mindamage / mindps + d, maxtime * maxdps / mindps)
1230 // >= min(mintime, maxtime)
1231 // ==> totaldamage / maxdps >= mintime.
1234 // how long do we damage then?
1235 // at least as long as before
1236 // but, never exceed maxdps
1237 totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime due to lemma
1241 // at most as long as maximum allowed
1242 // but, never below mindps
1243 totaltime = min(maxtime, totaldamage / mindps); // always >= mintime due to lemma
1245 // assuming t > mintime, dps > mindps:
1246 // we get d = t * dps = maxtime * maxdps
1247 // totaldamage = min(maxdamage, maxtime * maxdps) = min(... + d, maxtime * maxdps) = maxtime * maxdps
1248 // totaldamage / maxdps = maxtime
1249 // totaldamage / mindps > totaldamage / maxdps = maxtime
1251 // a) totaltime = max(mintime, maxtime) = maxtime
1252 // b) totaltime = min(maxtime, totaldamage / maxdps) = maxtime
1254 // assuming t <= mintime:
1255 // we get maxtime = mintime
1256 // a) totaltime = max(mintime, ...) >= mintime, also totaltime <= maxtime by the lemma, therefore totaltime = mintime = maxtime
1257 // b) totaltime = min(maxtime, ...) <= maxtime, also totaltime >= mintime by the lemma, therefore totaltime = mintime = maxtime
1259 // assuming dps <= mindps:
1260 // we get mindps = maxdps.
1261 // With this, the lemma says that mintime <= totaldamage / mindps = totaldamage / maxdps <= maxtime.
1262 // a) totaltime = max(mintime, totaldamage / maxdps) = totaldamage / maxdps
1263 // b) totaltime = min(maxtime, totaldamage / mindps) = totaldamage / maxdps
1265 e.fire_damagepersec = totaldamage / totaltime;
1266 e.fire_endtime = time + totaltime;
1267 if(totaldamage > 1.2 * mindamage)
1269 e.fire_deathtype = dt;
1270 if(e.fire_owner != o)
1273 e.fire_hitsound = FALSE;
1276 if(accuracy_isgooddamage(o, e))
1277 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1278 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1285 e.fire_damagepersec = dps;
1286 e.fire_endtime = time + t;
1287 e.fire_deathtype = dt;
1289 e.fire_hitsound = FALSE;
1290 if(accuracy_isgooddamage(o, e))
1291 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1296 void Fire_ApplyDamage(entity e)
1301 if not(Fire_IsBurning(e))
1304 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1305 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1308 // water and slime stop fire
1310 if(e.watertype != CONTENT_LAVA)
1314 if(e.freezetag_frozen)
1317 t = min(frametime, e.fire_endtime - time);
1318 d = e.fire_damagepersec * t;
1320 hi = e.fire_owner.hitsound;
1321 ty = e.fire_owner.typehitsound;
1322 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1323 if(e.fire_hitsound && e.fire_owner)
1325 e.fire_owner.hitsound = hi;
1326 e.fire_owner.typehitsound = ty;
1328 e.fire_hitsound = TRUE;
1330 if not(IS_INDEPENDENT_PLAYER(e))
1331 FOR_EACH_PLAYER(other) if(e != other)
1333 if(other.classname == "player")
1334 if(other.deadflag == DEAD_NO)
1335 if not(IS_INDEPENDENT_PLAYER(other))
1336 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1338 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1339 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1340 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1345 void Fire_ApplyEffect(entity e)
1347 if(Fire_IsBurning(e))
1348 e.effects |= EF_FLAME;
1350 e.effects &~= EF_FLAME;
1353 void fireburner_think()
1355 // for players, this is done in the regular loop
1356 if(wasfreed(self.owner))
1361 Fire_ApplyEffect(self.owner);
1362 if(!Fire_IsBurning(self.owner))
1364 self.owner.fire_burner = world;
1368 Fire_ApplyDamage(self.owner);
1369 self.nextthink = time;