6 float Damage_DamageInfo_SendEntity(entity to, float sf)
8 WriteByte(MSG_ENTITY, ENT_CLIENT_DAMAGEINFO);
9 WriteShort(MSG_ENTITY, self.projectiledeathtype);
10 WriteCoord(MSG_ENTITY, floor(self.origin_x));
11 WriteCoord(MSG_ENTITY, floor(self.origin_y));
12 WriteCoord(MSG_ENTITY, floor(self.origin_z));
13 WriteByte(MSG_ENTITY, bound(1, self.dmg, 255));
14 WriteByte(MSG_ENTITY, bound(0, self.dmg_radius, 255));
15 WriteByte(MSG_ENTITY, bound(1, self.dmg_edge, 255));
16 WriteShort(MSG_ENTITY, self.oldorigin_x);
17 WriteByte(MSG_ENTITY, self.species);
21 void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, float deathtype, float bloodtype, entity dmgowner)
23 // TODO maybe call this from non-edgedamage too?
24 // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
28 if(!sound_allowed(MSG_BROADCAST, dmgowner))
33 e.projectiledeathtype = deathtype;
35 e.dmg_edge = edgedamage;
37 e.dmg_force = vlen(force);
39 e.oldorigin_x = compressShortVector(e.velocity);
40 e.species = bloodtype;
42 Net_LinkEntity(e, FALSE, 0.2, Damage_DamageInfo_SendEntity);
45 float checkrules_firstblood;
48 float damage_goodhits;
49 float damage_gooddamage;
51 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
54 .float teamkill_complain;
55 .float teamkill_soundtime;
56 .entity teamkill_soundsource;
59 .float taunt_soundtime;
62 float IsDifferentTeam(entity a, entity b)
77 float IsFlying(entity a)
79 if(a.flags & FL_ONGROUND)
81 if(a.waterlevel >= WATERLEVEL_SWIMMING)
83 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
84 if(trace_fraction < 1)
89 vector GetHeadshotMins(entity targ)
91 return '-0.5 0 0' * PL_HEAD_x + '0 -0.5 0' * PL_HEAD_y + '0 0 1' * (targ.maxs_z - PL_HEAD_z);
93 vector GetHeadshotMaxs(entity targ)
95 return '0.5 0 0' * PL_HEAD_x + '0 0.5 0' * PL_HEAD_y + '0 0 1' * targ.maxs_z;
98 void UpdateFrags(entity player, float f)
100 PlayerTeamScore_AddScore(player, f);
103 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
104 void W_SwitchWeapon_Force(entity e, float w);
105 entity GiveFrags_randomweapons;
106 void GiveFrags (entity attacker, entity targ, float f, float deathtype)
108 // TODO route through PlayerScores instead
116 PlayerScore_Add(attacker, SP_SUICIDES, 1);
121 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
127 PlayerScore_Add(attacker, SP_KILLS, 1);
129 PlayerStats_Event(attacker, sprintf("kills-%d", targ.playerid), 1);
132 PlayerScore_Add(targ, SP_DEATHS, 1);
135 if(autocvar_g_arena_roundbased)
138 if(targ != attacker) // not for suicides
139 if(g_weaponarena_random)
141 // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
143 culprit = DEATH_WEAPONOF(deathtype);
145 culprit = attacker.weapon;
146 else if(!WEPSET_CONTAINS_EW(attacker, culprit))
147 culprit = attacker.weapon;
149 if(g_weaponarena_random_with_laser && culprit == WEP_LASER)
155 if(!GiveFrags_randomweapons)
157 GiveFrags_randomweapons = spawn();
158 GiveFrags_randomweapons.classname = "GiveFrags_randomweapons";
162 WEPSET_COPY_EA(GiveFrags_randomweapons, warmup_start_weapons);
164 WEPSET_COPY_EA(GiveFrags_randomweapons, start_weapons);
166 // all others (including the culprit): remove
167 WEPSET_ANDNOT_EE(GiveFrags_randomweapons, attacker);
168 WEPSET_ANDNOT_EW(GiveFrags_randomweapons, culprit);
170 // among the remaining ones, choose one by random
171 W_RandomWeapons(GiveFrags_randomweapons, 1);
173 if(!WEPSET_EMPTY_E(GiveFrags_randomweapons))
175 WEPSET_OR_EE(attacker, GiveFrags_randomweapons);
176 WEPSET_ANDNOT_EW(attacker, culprit);
180 // after a frag, choose another random weapon set
181 if not(WEPSET_CONTAINS_EW(attacker, attacker.weapon))
182 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
185 // FIXME fix the mess this is (we have REAL points now!)
189 frag_attacker = attacker;
192 if(MUTATOR_CALLHOOK(GiveFragsForKill))
202 f = RunematchHandleFrags(attacker, targ, f);
208 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
209 if(tl < lms_lowest_lives)
210 lms_lowest_lives = tl;
214 lms_next_place = player_count;
216 lms_next_place = min(lms_next_place, player_count);
217 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
224 attacker.totalfrags += f;
227 UpdateFrags(attacker, f);
230 string Obituary_ExtraFragInfo(entity player) // Extra fragmessage information
232 string health_output = string_null;
233 string ping_output = string_null;
234 string handicap_output = string_null;
235 string output = string_null;
237 if(autocvar_sv_fraginfo && ((autocvar_sv_fraginfo == 2) || inWarmupStage))
239 // health/armor of attacker (person who killed you)
240 if(autocvar_sv_fraginfo_stats && (player.health >= 1))
241 health_output = strcat("^7(Health ^1", ftos(rint(player.health)), "^7 / Armor ^2", ftos(rint(player.armorvalue)), "^7)");
244 if(autocvar_sv_fraginfo_ping)
245 ping_output = ((clienttype(player) == CLIENTTYPE_BOT) ? "^2Bot" : strcat("Ping ", ((player.ping >= 150) ? "^1" : "^2"), ftos(rint(player.ping)), "ms"));
248 if(autocvar_sv_fraginfo_handicap)
250 if(autocvar_sv_fraginfo_handicap == 2)
251 handicap_output = strcat(output, strcat("Handicap ^2", ((player.cvar_cl_handicap <= 1) ? "Off" : ftos(rint(player.cvar_cl_handicap)))));
252 else if(player.cvar_cl_handicap) // with _handicap 1, only show this if there actually is a handicap enabled.
253 handicap_output = strcat("Handicap ^2", ftos(rint(player.cvar_cl_handicap)));
257 output = strcat(health_output, (health_output ? ((ping_output || handicap_output) ? " ^7(" : "") : ((ping_output || handicap_output) ? "^7(" : "")),
258 ping_output, (handicap_output ? "^7 / " : ""),
259 handicap_output, ((ping_output || handicap_output) ? "^7)" : ""));
261 // add new line to the beginning if there is a message
262 if(output) { output = strcat("\n", output); }
268 string AppendItemcodes(string s, entity player)
273 // w = player.switchweapon;
275 w = player.cnt; // previous weapon!
276 s = strcat(s, ftos(w));
277 if(time < player.strength_finished)
279 if(time < player.invincible_finished)
281 if(player.flagcarried != world)
283 if(player.BUTTON_CHAT)
288 s = strcat(s, "|", ftos(player.runes));
292 void LogDeath(string mode, float deathtype, entity killer, entity killed)
295 if(!autocvar_sv_eventlog)
297 s = strcat(":kill:", mode);
298 s = strcat(s, ":", ftos(killer.playerid));
299 s = strcat(s, ":", ftos(killed.playerid));
300 s = strcat(s, ":type=", ftos(deathtype));
301 s = strcat(s, ":items=");
302 s = AppendItemcodes(s, killer);
305 s = strcat(s, ":victimitems=");
306 s = AppendItemcodes(s, killed);
311 void Obituary_Notification(entity notif_target, string s1, string s2, string s3, float deathtype)
315 #define DEATHTYPE(name,type,notification,first,last) \
316 { if((deathtype == max(0, name)) && max(0, type) && max(0, notification)) { Send_Notification(type, notif_target, notification, s1, s2, s3); return; } }
319 backtrace("Unhandled deathtype. Please notify Samual!\n");
323 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
330 if (targ.classname == "player")
333 a = attacker.netname;
335 if (targ == attacker) // suicides
337 s1 = ((deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE) ? ColoredTeamName(targ.team) : "");
339 // no "killed your own dumb self" message in CTS
340 if(!g_cts) { Obituary_Notification(targ, s1, "", "", deathtype); }
342 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
344 LogDeath("suicide", deathtype, targ, targ);
345 GiveFrags(attacker, targ, -1, deathtype);
349 s2 = ((targ.killcount > 2) ? ftos(targ.killcount) : "");
351 //if(teamplay && deathtype == DEATH_MIRRORDAMAGE)
352 // { deathtype = ((attacker.team == COLOR_TEAM1) ? KILL_TEAM_SUICIDE_RED : KILL_TEAM_SUICIDE_BLUE); }
354 Obituary_Notification(world, s1, s2, "", deathtype);
355 //Send_KillNotification(s, s2, ftos(w), deathtype, MSG_SUICIDE);
357 else if (attacker.classname == "player")
359 if(!IsDifferentTeam(attacker, targ))
361 //type = ((attacker.team == COLOR_TEAM1) ? KILL_TEAM_FRAG_RED : KILL_TEAM_FRAG_BLUE);
363 GiveFrags(attacker, targ, -1, deathtype);
365 //Send_CSQC_KillCenterprint(attacker, s, "", type);
367 if (targ.killcount > 2)
368 msg = ftos(targ.killcount);
372 if (attacker.killcount > 2) {
373 msg = ftos(attacker.killcount);
374 type = KILL_TEAM_SPREE;
376 Send_KillNotification(a, s, msg, type, MSG_KILL);
378 attacker.killcount = 0;
380 LogDeath("tk", deathtype, attacker, targ);
384 if (!checkrules_firstblood)
386 checkrules_firstblood = TRUE;
387 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
388 // TODO: make these print a newline if they dont
389 Send_CSQC_KillCenterprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
390 Send_CSQC_KillCenterprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
391 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
392 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
395 if(targ.istypefrag) {
396 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_TYPEFRAG, MSG_KILL);
397 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_TYPEFRAGGED, MSG_KILL);
399 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_FRAG, MSG_KILL);
400 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_FRAGGED, MSG_KILL);
403 attacker.taunt_soundtime = time + 1;
405 if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
406 msg = inflictor.message2;
407 else if (deathtype == DEATH_CUSTOM)
412 if(strstrofs(msg, "%", 0) < 0)
413 msg = strcat("%s ", msg, " by %s");
415 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
417 GiveFrags(attacker, targ, 1, deathtype);
419 if (targ.killcount > 2) {
420 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
423 attacker.killcount = attacker.killcount + 1;
425 if (attacker.killcount == 3)
427 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
428 AnnounceTo(attacker, "03kills");
429 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
431 else if (attacker.killcount == 5)
433 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
434 AnnounceTo(attacker, "05kills");
435 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
437 else if (attacker.killcount == 10)
439 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
440 AnnounceTo(attacker, "10kills");
441 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
443 else if (attacker.killcount == 15)
445 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
446 AnnounceTo(attacker, "15kills");
447 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
449 else if (attacker.killcount == 20)
451 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
452 AnnounceTo(attacker, "20kills");
453 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
455 else if (attacker.killcount == 25)
457 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
458 AnnounceTo(attacker, "25kills");
459 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
461 else if (attacker.killcount == 30)
463 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
464 AnnounceTo(attacker, "30kills");
465 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
467 else if (attacker.killcount > 2) {
468 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
470 LogDeath("frag", deathtype, attacker, targ);
475 Send_CSQC_KillCenterprint(targ, "", "", deathtype, MSG_KILL_ACTION);
476 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
477 msg = inflictor.message;
478 else if (deathtype == DEATH_CUSTOM)
482 if(strstrofs(msg, "%", 0) < 0)
483 msg = strcat("%s ", msg);
485 GiveFrags(targ, targ, -1, deathtype);
486 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
487 AnnounceTo(targ, "botlike");
488 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
490 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
492 if (targ.killcount > 2)
493 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
495 LogDeath("accident", deathtype, targ, targ);
498 targ.death_origin = targ.origin;
500 targ.killer_origin = attacker.origin;
502 // FIXME: this should go in PutClientInServer
508 // these are updated by each Damage call for use in button triggering and such
510 entity damage_inflictor;
511 entity damage_attacker;
513 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
518 entity attacker_save;
522 if (gameover || targ.killcount == -666)
529 damage_inflictor = inflictor;
530 damage_attacker = attacker;
531 attacker_save = attacker;
533 if(targ.classname == "player")
536 if(targ.hook.aiment == attacker)
537 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
539 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
540 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
542 if(targ.classname == "player")
543 if not(IsDifferentTeam(targ, attacker))
550 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
552 // These are ALWAYS lethal
553 // No damage modification here
554 // Instead, prepare the victim for his death...
556 targ.spawnshieldtime = 0;
557 targ.health = 0.9; // this is < 1
558 targ.flags -= targ.flags & FL_GODMODE;
561 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
568 skill based bot damage? gtfo. (tZork)
569 if (targ.classname == "player")
570 if (attacker.classname == "player")
573 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
576 // nullify damage if teamplay is on
577 if(deathtype != DEATH_TELEFRAG)
578 if(attacker.classname == "player")
580 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
585 else if(!IsDifferentTeam(attacker, targ))
587 if(autocvar_teamplay_mode == 1)
589 else if(attacker != targ)
591 if(autocvar_teamplay_mode == 3)
593 else if(autocvar_teamplay_mode == 4)
595 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
597 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
598 attacker.dmg_team = attacker.dmg_team + damage;
599 if(attacker.dmg_team > teamdamage0 && !g_ca)
600 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
601 mirrorforce = autocvar_g_mirrordamage * vlen(force);
604 if(autocvar_g_friendlyfire == 0)
610 damage = autocvar_g_friendlyfire * damage;
611 // mirrordamage will be used LATER
613 if(autocvar_g_mirrordamage_virtual)
615 vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
616 attacker.dmg_take += v_x;
617 attacker.dmg_save += v_y;
618 attacker.dmg_inflictor = inflictor;
619 mirrordamage = v_z; // = 0, to make fteqcc stfu
623 if(autocvar_g_friendlyfire_virtual)
625 vector v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
626 targ.dmg_take += v_x;
627 targ.dmg_save += v_y;
628 targ.dmg_inflictor = inflictor;
630 if(!autocvar_g_friendlyfire_virtual_force)
641 if(targ.classname == "player")
642 if(attacker.classname == "player")
645 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
646 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
649 if(targ.classname == "player")
652 if ((deathtype == DEATH_FALL) ||
653 (deathtype == DEATH_DROWN) ||
654 (deathtype == DEATH_SLIME) ||
655 (deathtype == DEATH_LAVA) ||
656 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
663 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
665 targ.armorvalue -= 1;
666 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
669 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
671 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
675 if (targ != attacker)
677 if ((targ.health >= 1) && (targ.classname == "player"))
678 centerprint(attacker, "Secondary fire inflicts no damage!");
686 if not(DEATH_ISSPECIAL(deathtype))
688 damage *= g_weapondamagefactor;
689 mirrordamage *= g_weapondamagefactor;
690 force = force * g_weaponforcefactor;
691 mirrorforce *= g_weaponforcefactor;
694 // should this be changed at all? If so, in what way?
695 frag_attacker = attacker;
697 frag_damage = damage;
699 frag_deathtype = deathtype;
700 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
701 damage = frag_damage;
704 // apply strength multiplier
705 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
709 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
710 force = force * autocvar_g_balance_powerup_strength_selfforce;
714 damage = damage * autocvar_g_balance_powerup_strength_damage;
715 force = force * autocvar_g_balance_powerup_strength_force;
719 // apply invincibility multiplier
720 if (targ.items & IT_INVINCIBLE && !g_minstagib)
721 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
723 if (targ == attacker)
725 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
728 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
733 // apply strength rune
734 if (attacker.runes & RUNE_STRENGTH)
736 if(attacker.runes & CURSE_WEAK) // have both curse & rune
738 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
739 force = force * autocvar_g_balance_rune_strength_combo_force;
743 damage = damage * autocvar_g_balance_rune_strength_damage;
744 force = force * autocvar_g_balance_rune_strength_force;
747 else if (attacker.runes & CURSE_WEAK)
749 damage = damage * autocvar_g_balance_curse_weak_damage;
750 force = force * autocvar_g_balance_curse_weak_force;
753 // apply defense rune
754 if (targ.runes & RUNE_DEFENSE)
756 if (targ.runes & CURSE_VULNER) // have both curse & rune
757 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
759 damage = damage * autocvar_g_balance_rune_defense_takedamage;
761 else if (targ.runes & CURSE_VULNER)
762 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
768 if(targ.takedamage == DAMAGE_AIM)
771 if(damage_headshotbonus)
773 if(targ.classname == "player")
776 // find height of hit on player axis
777 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
778 vector headmins, headmaxs, org;
779 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
780 headmins = org + GetHeadshotMins(targ);
781 headmaxs = org + GetHeadshotMaxs(targ);
782 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
784 deathtype |= HITTYPE_HEADSHOT;
787 else if(targ.classname == "turret_head")
789 deathtype |= HITTYPE_HEADSHOT;
791 if(deathtype & HITTYPE_HEADSHOT)
792 if(damage_headshotbonus > 0)
793 damage *= 1 + damage_headshotbonus;
797 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
802 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
804 if(IsDifferentTeam(victim, attacker))
808 if(deathtype != DEATH_FIRE)
810 if(victim.BUTTON_CHAT)
811 attacker.typehitsound += 1;
813 attacker.hitsound += 1;
816 damage_goodhits += 1;
817 damage_gooddamage += damage;
819 if not(DEATH_ISSPECIAL(deathtype))
821 if(targ.classname == "player") // don't do this for vehicles
827 if(victim.items & IT_STRENGTH)
830 if(deathtype & HITTYPE_HEADSHOT)
834 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
839 if(deathtype != DEATH_FIRE)
841 attacker.typehitsound += 1;
844 if(time > attacker.teamkill_complain)
846 attacker.teamkill_complain = time + 5;
847 attacker.teamkill_soundtime = time + 0.4;
848 attacker.teamkill_soundsource = targ;
856 if (self.damageforcescale)
858 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
860 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
861 if(self.movetype == MOVETYPE_PHYSICS)
865 farcent.classname = "farce";
866 farcent.enemy = self;
867 farcent.movedir = farce * 10;
869 farcent.movedir = farcent.movedir * self.mass;
870 farcent.origin = hitloc;
871 farcent.forcetype = FORCETYPE_FORCEATPOS;
872 farcent.nextthink = time + 0.1;
873 farcent.think = SUB_Remove;
876 self.velocity = self.velocity + farce;
877 self.flags &~= FL_ONGROUND;
878 UpdateCSQCProjectile(self);
881 if (damage != 0 || (self.damageforcescale && vlen(force)))
882 if (self.event_damage)
883 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
886 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
890 if (attacker.runes & RUNE_VAMPIRE)
892 // apply vampire rune
893 if (attacker.runes & CURSE_EMPATHY) // have the curse too
895 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
896 attacker.health = bound(
897 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
898 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
899 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
903 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
904 attacker.health = bound(
905 attacker.health, // LA: was 3, but changed so that you can't lose health
906 // empathy won't let you gain health in the same way...
907 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
908 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
911 // apply empathy curse
912 else if (attacker.runes & CURSE_EMPATHY)
914 attacker.health = bound(
915 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
916 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
922 // apply mirror damage if any
923 if(mirrordamage > 0 || mirrorforce > 0)
925 attacker = attacker_save;
929 // just lose extra LIVES, don't kill the player for mirror damage
930 if(attacker.armorvalue > 0)
932 attacker.armorvalue = attacker.armorvalue - 1;
933 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
934 attacker.hitsound += 1;
939 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
940 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
944 float RadiusDamage_running;
945 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
946 // Returns total damage applies to creatures
951 float total_damage_to_creatures;
956 float stat_damagedone;
958 if(RadiusDamage_running)
960 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
964 RadiusDamage_running = 1;
966 tfloordmg = autocvar_g_throughfloor_damage;
967 tfloorforce = autocvar_g_throughfloor_force;
969 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
970 total_damage_to_creatures = 0;
972 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
973 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
975 force = inflictor.velocity;
979 force = normalize(force);
980 if(forceintensity >= 0)
981 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
983 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
988 targ = WarpZone_FindRadius (blastorigin, rad + MAX_DAMAGEEXTRARADIUS, FALSE);
992 if (targ != inflictor)
993 if (ignore != targ) if(targ.takedamage)
999 // LordHavoc: measure distance to nearest point on target (not origin)
1000 // (this guarentees 100% damage on a touch impact)
1001 nearest = targ.WarpZone_findradius_nearest;
1002 diff = targ.WarpZone_findradius_dist;
1003 // round up a little on the damage to ensure full damage on impacts
1004 // and turn the distance into a fraction of the radius
1005 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
1007 //bprint(ftos(power));
1008 //if (targ == attacker)
1009 // print(ftos(power), "\n");
1015 finaldmg = coredamage * power + edgedamage * (1 - power);
1021 vector myblastorigin;
1024 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1026 // if it's a player, use the view origin as reference
1027 center = CENTER_OR_VIEWOFS(targ);
1029 force = normalize(center - myblastorigin);
1030 force = force * (finaldmg / coredamage) * forceintensity;
1033 if(targ != directhitentity)
1038 float mininv_f, mininv_d;
1040 // test line of sight to multiple positions on box,
1041 // and do damage if any of them hit
1044 // we know: max stddev of hitratio = 1 / (2 * sqrt(n))
1045 // so for a given max stddev:
1046 // n = (1 / (2 * max stddev of hitratio))^2
1048 mininv_d = (finaldmg * (1-tfloordmg)) / autocvar_g_throughfloor_damage_max_stddev;
1049 mininv_f = (vlen(force) * (1-tfloorforce)) / autocvar_g_throughfloor_force_max_stddev;
1051 if(autocvar_g_throughfloor_debug)
1052 print(sprintf("THROUGHFLOOR: D=%f F=%f max(dD)=1/%f max(dF)=1/%f", finaldmg, vlen(force), mininv_d, mininv_f));
1054 total = 0.25 * pow(max(mininv_f, mininv_d), 2);
1056 if(autocvar_g_throughfloor_debug)
1057 print(sprintf(" steps=%f", total));
1059 if (targ.classname == "player")
1060 total = ceil(bound(autocvar_g_throughfloor_min_steps_player, total, autocvar_g_throughfloor_max_steps_player));
1062 total = ceil(bound(autocvar_g_throughfloor_min_steps_other, total, autocvar_g_throughfloor_max_steps_other));
1064 if(autocvar_g_throughfloor_debug)
1065 print(sprintf(" steps=%f dD=%f dF=%f", total, finaldmg * (1-tfloordmg) / (2 * sqrt(total)), vlen(force) * (1-tfloorforce) / (2 * sqrt(total))));
1067 for(c = 0; c < total; ++c)
1069 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1070 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1071 if (trace_fraction == 1 || trace_ent == targ)
1075 hitloc = hitloc + nearest;
1079 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1080 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1081 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1084 nearest = hitloc * (1 / max(1, hits));
1085 hitratio = (hits / total);
1086 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1087 finaldmg = finaldmg * a;
1088 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1091 if(autocvar_g_throughfloor_debug)
1092 print(sprintf(" D=%f F=%f\n", finaldmg, vlen(force)));
1095 // laser force adjustments :P
1096 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1098 if (targ == attacker)
1103 float force_velocitybiasramp;
1104 float force_velocitybias;
1106 force_velocitybiasramp = autocvar_sv_maxspeed;
1107 if(deathtype & HITTYPE_SECONDARY)
1109 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1110 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1114 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1115 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1118 vel = targ.velocity;
1120 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1124 normalize(normalize(force) + vel);
1126 force_z *= force_zscale;
1130 if(deathtype & HITTYPE_SECONDARY)
1132 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1136 force *= autocvar_g_balance_laser_primary_force_other_scale;
1141 //if (targ == attacker)
1143 // print("hits ", ftos(hits), " / ", ftos(total));
1144 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1145 // print(" (", ftos(a), ")\n");
1147 if(finaldmg || vlen(force))
1151 total_damage_to_creatures += finaldmg;
1153 if(accuracy_isgooddamage(attacker, targ))
1154 stat_damagedone += finaldmg;
1157 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1158 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1160 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1168 RadiusDamage_running = 0;
1170 if(!DEATH_ISSPECIAL(deathtype))
1171 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1173 return total_damage_to_creatures;
1176 .float fire_damagepersec;
1177 .float fire_endtime;
1178 .float fire_deathtype;
1180 .float fire_hitsound;
1181 .entity fire_burner;
1183 void fireburner_think();
1185 float Fire_IsBurning(entity e)
1187 return (time < e.fire_endtime);
1190 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1193 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1195 if(e.classname == "player")
1204 // print("adding a fire burner to ", e.classname, "\n");
1205 e.fire_burner = spawn();
1206 e.fire_burner.classname = "fireburner";
1207 e.fire_burner.think = fireburner_think;
1208 e.fire_burner.nextthink = time;
1209 e.fire_burner.owner = e;
1215 if(Fire_IsBurning(e))
1217 mintime = e.fire_endtime - time;
1218 maxtime = max(mintime, t);
1220 mindps = e.fire_damagepersec;
1221 maxdps = max(mindps, dps);
1223 if(maxtime > mintime || maxdps > mindps)
1227 // damage we have right now
1228 mindamage = mindps * mintime;
1230 // damage we want to get
1231 maxdamage = mindamage + d;
1233 // but we can't exceed maxtime * maxdps!
1234 totaldamage = min(maxdamage, maxtime * maxdps);
1238 // totaldamage = min(mindamage + d, maxtime * maxdps)
1240 // totaldamage <= maxtime * maxdps
1241 // ==> totaldamage / maxdps <= maxtime.
1243 // totaldamage / mindps = min(mindamage / mindps + d, maxtime * maxdps / mindps)
1244 // >= min(mintime, maxtime)
1245 // ==> totaldamage / maxdps >= mintime.
1248 // how long do we damage then?
1249 // at least as long as before
1250 // but, never exceed maxdps
1251 totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime due to lemma
1255 // at most as long as maximum allowed
1256 // but, never below mindps
1257 totaltime = min(maxtime, totaldamage / mindps); // always >= mintime due to lemma
1259 // assuming t > mintime, dps > mindps:
1260 // we get d = t * dps = maxtime * maxdps
1261 // totaldamage = min(maxdamage, maxtime * maxdps) = min(... + d, maxtime * maxdps) = maxtime * maxdps
1262 // totaldamage / maxdps = maxtime
1263 // totaldamage / mindps > totaldamage / maxdps = maxtime
1265 // a) totaltime = max(mintime, maxtime) = maxtime
1266 // b) totaltime = min(maxtime, totaldamage / maxdps) = maxtime
1268 // assuming t <= mintime:
1269 // we get maxtime = mintime
1270 // a) totaltime = max(mintime, ...) >= mintime, also totaltime <= maxtime by the lemma, therefore totaltime = mintime = maxtime
1271 // b) totaltime = min(maxtime, ...) <= maxtime, also totaltime >= mintime by the lemma, therefore totaltime = mintime = maxtime
1273 // assuming dps <= mindps:
1274 // we get mindps = maxdps.
1275 // With this, the lemma says that mintime <= totaldamage / mindps = totaldamage / maxdps <= maxtime.
1276 // a) totaltime = max(mintime, totaldamage / maxdps) = totaldamage / maxdps
1277 // b) totaltime = min(maxtime, totaldamage / mindps) = totaldamage / maxdps
1279 e.fire_damagepersec = totaldamage / totaltime;
1280 e.fire_endtime = time + totaltime;
1281 if(totaldamage > 1.2 * mindamage)
1283 e.fire_deathtype = dt;
1284 if(e.fire_owner != o)
1287 e.fire_hitsound = FALSE;
1290 if(accuracy_isgooddamage(o, e))
1291 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1292 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1299 e.fire_damagepersec = dps;
1300 e.fire_endtime = time + t;
1301 e.fire_deathtype = dt;
1303 e.fire_hitsound = FALSE;
1304 if(accuracy_isgooddamage(o, e))
1305 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1310 void Fire_ApplyDamage(entity e)
1315 if not(Fire_IsBurning(e))
1318 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1319 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1322 // water and slime stop fire
1324 if(e.watertype != CONTENT_LAVA)
1328 if(e.freezetag_frozen)
1331 t = min(frametime, e.fire_endtime - time);
1332 d = e.fire_damagepersec * t;
1334 hi = e.fire_owner.hitsound;
1335 ty = e.fire_owner.typehitsound;
1336 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1337 if(e.fire_hitsound && e.fire_owner)
1339 e.fire_owner.hitsound = hi;
1340 e.fire_owner.typehitsound = ty;
1342 e.fire_hitsound = TRUE;
1344 if not(IS_INDEPENDENT_PLAYER(e))
1345 FOR_EACH_PLAYER(other) if(e != other)
1347 if(other.classname == "player")
1348 if(other.deadflag == DEAD_NO)
1349 if not(IS_INDEPENDENT_PLAYER(other))
1350 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1352 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1353 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1354 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1359 void Fire_ApplyEffect(entity e)
1361 if(Fire_IsBurning(e))
1362 e.effects |= EF_FLAME;
1364 e.effects &~= EF_FLAME;
1367 void fireburner_think()
1369 // for players, this is done in the regular loop
1370 if(wasfreed(self.owner))
1375 Fire_ApplyEffect(self.owner);
1376 if(!Fire_IsBurning(self.owner))
1378 self.owner.fire_burner = world;
1382 Fire_ApplyDamage(self.owner);
1383 self.nextthink = time;