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;
58 .float taunt_soundtime;
61 float IsDifferentTeam(entity a, entity b)
76 float IsFlying(entity a)
78 if(a.flags & FL_ONGROUND)
80 if(a.waterlevel >= WATERLEVEL_SWIMMING)
82 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
83 if(trace_fraction < 1)
88 vector GetHeadshotMins(entity targ)
90 return '-0.5 0 0' * PL_HEAD_x + '0 -0.5 0' * PL_HEAD_y + '0 0 1' * (targ.maxs_z - PL_HEAD_z);
92 vector GetHeadshotMaxs(entity targ)
94 return '0.5 0 0' * PL_HEAD_x + '0 0.5 0' * PL_HEAD_y + '0 0 1' * targ.maxs_z;
97 void UpdateFrags(entity player, float f)
99 PlayerTeamScore_AddScore(player, f);
102 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
103 void W_SwitchWeapon_Force(entity e, float w);
104 entity GiveFrags_randomweapons;
105 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 || !WEPSET_CONTAINS_EW(attacker, culprit))
144 culprit = attacker.weapon;
146 if(g_weaponarena_random_with_laser && culprit == WEP_LASER)
152 if(!GiveFrags_randomweapons)
154 GiveFrags_randomweapons = spawn();
155 GiveFrags_randomweapons.classname = "GiveFrags_randomweapons";
159 WEPSET_COPY_EA(GiveFrags_randomweapons, warmup_start_weapons);
161 WEPSET_COPY_EA(GiveFrags_randomweapons, start_weapons);
163 // all others (including the culprit): remove
164 WEPSET_ANDNOT_EE(GiveFrags_randomweapons, attacker);
165 WEPSET_ANDNOT_EW(GiveFrags_randomweapons, culprit);
167 // among the remaining ones, choose one by random
168 W_RandomWeapons(GiveFrags_randomweapons, 1);
170 if(!WEPSET_EMPTY_E(GiveFrags_randomweapons))
172 WEPSET_OR_EE(attacker, GiveFrags_randomweapons);
173 WEPSET_ANDNOT_EW(attacker, culprit);
177 // after a frag, choose another random weapon set
178 if not(WEPSET_CONTAINS_EW(attacker, attacker.weapon))
179 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
182 // FIXME fix the mess this is (we have REAL points now!)
186 frag_attacker = attacker;
189 if(MUTATOR_CALLHOOK(GiveFragsForKill))
199 f = RunematchHandleFrags(attacker, targ, f);
205 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
206 if(tl < lms_lowest_lives)
207 lms_lowest_lives = tl;
211 lms_next_place = player_count;
213 lms_next_place = min(lms_next_place, player_count);
214 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
221 if(g_ctf_ignore_frags)
226 attacker.totalfrags += f;
229 UpdateFrags(attacker, f);
232 string Obituary_ExtraFragInfo(entity player) // Extra fragmessage information
234 string health_output;
236 string handicap_output;
239 if(autocvar_sv_fraginfo && ((autocvar_sv_fraginfo == 2) || inWarmupStage))
241 // health/armor of attacker (person who killed you)
242 if(autocvar_sv_fraginfo_stats && (player.health >= 1))
243 health_output = strcat("^7(Health ^1", ftos(rint(player.health)), "^7 / Armor ^2", ftos(rint(player.armorvalue)), "^7)");
246 if(autocvar_sv_fraginfo_ping)
247 ping_output = ((clienttype(player) == CLIENTTYPE_BOT) ? "^2Bot" : strcat("Ping ", ((player.ping >= 150) ? "^1" : "^2"), ftos(rint(player.ping)), "ms"));
250 if(autocvar_sv_fraginfo_handicap)
252 if(autocvar_sv_fraginfo_handicap == 2)
253 handicap_output = strcat(output, strcat("Handicap ^2", ((player.cvar_cl_handicap <= 1) ? "Off" : ftos(rint(player.cvar_cl_handicap)))));
254 else if(player.cvar_cl_handicap) // with _handicap 1, only show this if there actually is a handicap enabled.
255 handicap_output = strcat("Handicap ^2", ftos(rint(player.cvar_cl_handicap)));
259 output = strcat(health_output, (health_output ? ((ping_output || handicap_output) ? " ^7(" : "") : ((ping_output || handicap_output) ? "^7(" : "")),
260 ping_output, (handicap_output ? "^7 / " : ""),
261 handicap_output, ((ping_output || handicap_output) ? "^7)" : ""));
263 // add new line to the beginning if there is a message
264 if(output) { output = strcat("\n", output); }
270 string AppendItemcodes(string s, entity player)
275 // w = player.switchweapon;
277 w = player.cnt; // previous weapon!
278 s = strcat(s, ftos(w));
279 if(time < player.strength_finished)
281 if(time < player.invincible_finished)
283 if(player.flagcarried != world)
285 if(player.BUTTON_CHAT)
290 s = strcat(s, "|", ftos(player.runes));
294 void LogDeath(string mode, float deathtype, entity killer, entity killed)
297 if(!autocvar_sv_eventlog)
299 s = strcat(":kill:", mode);
300 s = strcat(s, ":", ftos(killer.playerid));
301 s = strcat(s, ":", ftos(killed.playerid));
302 s = strcat(s, ":type=", ftos(deathtype));
303 s = strcat(s, ":items=");
304 s = AppendItemcodes(s, killer);
307 s = strcat(s, ":victimitems=");
308 s = AppendItemcodes(s, killed);
313 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
315 WriteByte(MSG_ALL, SVC_TEMPENTITY);
316 WriteByte(MSG_ALL, TE_CSQC_KILLNOTIFY);
317 WriteString(MSG_ALL, s1);
318 WriteString(MSG_ALL, s2);
319 WriteString(MSG_ALL, s3);
320 WriteShort(MSG_ALL, msg);
321 WriteByte(MSG_ALL, type);
324 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
325 void Send_CSQC_KillCenterprint(entity e, string s1, string s2, float msg, float type)
327 if (clienttype(e) == CLIENTTYPE_REAL)
330 WRITESPECTATABLE_MSG_ONE({
331 WriteByte(MSG_ONE, SVC_TEMPENTITY);
332 WriteByte(MSG_ONE, TE_CSQC_KILLCENTERPRINT);
333 WriteString(MSG_ONE, s1);
334 WriteString(MSG_ONE, s2);
335 WriteShort(MSG_ONE, msg);
336 WriteByte(MSG_ONE, type);
341 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
346 if (targ.classname == "player")
349 a = attacker.netname;
351 if (targ == attacker) // suicides
353 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
354 msg = ColoredTeamName(targ.team); // TODO: check if needed?
355 if(!g_cts) // no "killed your own dumb self" message in CTS
356 Send_CSQC_KillCenterprint(targ, msg, "", deathtype, MSG_SUICIDE);
358 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
360 LogDeath("suicide", deathtype, targ, targ);
361 GiveFrags(attacker, targ, -1, deathtype);
364 if (targ.killcount > 2)
365 msg = ftos(targ.killcount);
366 if(teamplay && deathtype == DEATH_MIRRORDAMAGE)
368 if(attacker.team == COLOR_TEAM1)
369 deathtype = KILL_TEAM_RED;
371 deathtype = KILL_TEAM_BLUE;
374 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
376 else if (attacker.classname == "player")
378 if(!IsDifferentTeam(attacker, targ))
380 if(attacker.team == COLOR_TEAM1)
381 type = KILL_TEAM_RED;
383 type = KILL_TEAM_BLUE;
385 GiveFrags(attacker, targ, -1, deathtype);
387 Send_CSQC_KillCenterprint(attacker, s, "", type, MSG_KILL);
389 if (targ.killcount > 2) {
390 msg = ftos(targ.killcount);
393 if (attacker.killcount > 2) {
394 msg = ftos(attacker.killcount);
395 type = KILL_TEAM_SPREE;
397 Send_KillNotification(a, s, msg, type, MSG_KILL);
399 attacker.killcount = 0;
401 LogDeath("tk", deathtype, attacker, targ);
405 if (!checkrules_firstblood)
407 checkrules_firstblood = TRUE;
408 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
409 // TODO: make these print a newline if they dont
410 Send_CSQC_KillCenterprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
411 Send_CSQC_KillCenterprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
412 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
413 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
416 if(targ.BUTTON_CHAT) {
417 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_TYPEFRAG, MSG_KILL);
418 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_TYPEFRAGGED, MSG_KILL);
420 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_FRAG, MSG_KILL);
421 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_FRAGGED, MSG_KILL);
424 attacker.taunt_soundtime = time + 1;
427 if (deathtype == DEATH_CUSTOM)
430 msg = inflictor.message2;
432 if(strstrofs(msg, "%", 0) < 0)
433 msg = strcat("%s ", msg, " by %s");
435 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
437 if(g_ctf && targ.flagcarried)
439 UpdateFrags(attacker, ctf_score_value("score_kill"));
440 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
441 GiveFrags(attacker, targ, 0, deathtype); // for logging
444 GiveFrags(attacker, targ, 1, deathtype);
446 if (targ.killcount > 2) {
447 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
450 attacker.killcount = attacker.killcount + 1;
452 if (attacker.killcount > 2) {
453 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
455 else if (attacker.killcount == 3)
457 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
458 AnnounceTo(attacker, "03kills");
459 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
461 else if (attacker.killcount == 5)
463 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
464 AnnounceTo(attacker, "05kills");
465 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
467 else if (attacker.killcount == 10)
469 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
470 AnnounceTo(attacker, "10kills");
471 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
473 else if (attacker.killcount == 15)
475 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
476 AnnounceTo(attacker, "15kills");
477 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
479 else if (attacker.killcount == 20)
481 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
482 AnnounceTo(attacker, "20kills");
483 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
485 else if (attacker.killcount == 25)
487 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
488 AnnounceTo(attacker, "25kills");
489 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
491 else if (attacker.killcount == 30)
493 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
494 AnnounceTo(attacker, "30kills");
495 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
497 LogDeath("frag", deathtype, attacker, targ);
502 Send_CSQC_KillCenterprint(targ, "", "", deathtype, MSG_KILL_ACTION);
503 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
504 msg = inflictor.message;
505 else if (deathtype == DEATH_CUSTOM)
507 if(strstrofs(msg, "%", 0) < 0)
508 msg = strcat("%s ", msg);
510 GiveFrags(targ, targ, -1, deathtype);
511 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
512 AnnounceTo(targ, "botlike");
513 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
515 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
517 if (targ.killcount > 2)
518 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
520 LogDeath("accident", deathtype, targ, targ);
523 targ.death_origin = targ.origin;
525 targ.killer_origin = attacker.origin;
527 // FIXME: this should go in PutClientInServer
533 // these are updated by each Damage call for use in button triggering and such
535 entity damage_inflictor;
536 entity damage_attacker;
538 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
543 entity attacker_save;
547 if (gameover || targ.killcount == -666)
554 damage_inflictor = inflictor;
555 damage_attacker = attacker;
556 attacker_save = attacker;
558 if(targ.classname == "player")
561 if(targ.hook.aiment == attacker)
562 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
564 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
565 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
567 if(targ.classname == "player")
568 if not(IsDifferentTeam(targ, attacker))
575 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
577 // These are ALWAYS lethal
578 // No damage modification here
579 // Instead, prepare the victim for his death...
581 targ.spawnshieldtime = 0;
582 targ.health = 0.9; // this is < 1
583 targ.flags -= targ.flags & FL_GODMODE;
586 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
593 skill based bot damage? gtfo. (tZork)
594 if (targ.classname == "player")
595 if (attacker.classname == "player")
598 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
601 // nullify damage if teamplay is on
602 if(deathtype != DEATH_TELEFRAG)
603 if(attacker.classname == "player")
605 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
610 else if(!IsDifferentTeam(attacker, targ))
612 if(autocvar_teamplay_mode == 1)
614 else if(attacker != targ)
616 if(autocvar_teamplay_mode == 3)
618 else if(autocvar_teamplay_mode == 4)
620 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
622 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
623 attacker.dmg_team = attacker.dmg_team + damage;
624 if(attacker.dmg_team > teamdamage0 && !g_ca)
625 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
626 mirrorforce = autocvar_g_mirrordamage * vlen(force);
629 if(autocvar_g_friendlyfire == 0)
635 damage = autocvar_g_friendlyfire * damage;
636 // mirrordamage will be used LATER
638 if(autocvar_g_mirrordamage_virtual)
641 v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
642 v_z = 0; // fteqcc sucks
643 attacker.dmg_take += v_x;
644 attacker.dmg_save += v_y;
645 attacker.dmg_inflictor = inflictor;
650 if(autocvar_g_friendlyfire_virtual)
653 v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
654 v_z = 0; // fteqcc sucks
655 targ.dmg_take += v_x;
656 targ.dmg_save += v_y;
657 targ.dmg_inflictor = inflictor;
659 if(!autocvar_g_friendlyfire_virtual_force)
670 if(targ.classname == "player")
671 if(attacker.classname == "player")
674 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
675 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
678 if(targ.classname == "player")
681 if ((deathtype == DEATH_FALL) ||
682 (deathtype == DEATH_DROWN) ||
683 (deathtype == DEATH_SLIME) ||
684 (deathtype == DEATH_LAVA) ||
685 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
692 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
694 targ.armorvalue -= 1;
695 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
698 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
700 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
704 if (targ != attacker)
706 if ((targ.health >= 1) && (targ.classname == "player"))
707 centerprint(attacker, "Secondary fire inflicts no damage!");
715 if not(DEATH_ISSPECIAL(deathtype))
717 damage *= g_weapondamagefactor;
718 mirrordamage *= g_weapondamagefactor;
719 force = force * g_weaponforcefactor;
720 mirrorforce *= g_weaponforcefactor;
723 // should this be changed at all? If so, in what way?
724 frag_attacker = attacker;
726 frag_damage = damage;
728 frag_deathtype = deathtype;
729 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
730 damage = frag_damage;
733 // apply strength multiplier
734 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
738 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
739 force = force * autocvar_g_balance_powerup_strength_selfforce;
743 damage = damage * autocvar_g_balance_powerup_strength_damage;
744 force = force * autocvar_g_balance_powerup_strength_force;
748 // apply invincibility multiplier
749 if (targ.items & IT_INVINCIBLE && !g_minstagib)
750 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
752 if (targ == attacker)
754 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
757 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
760 // CTF: reduce damage/force
765 damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
766 force = force * autocvar_g_ctf_flagcarrier_selfforce;
771 // apply strength rune
772 if (attacker.runes & RUNE_STRENGTH)
774 if(attacker.runes & CURSE_WEAK) // have both curse & rune
776 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
777 force = force * autocvar_g_balance_rune_strength_combo_force;
781 damage = damage * autocvar_g_balance_rune_strength_damage;
782 force = force * autocvar_g_balance_rune_strength_force;
785 else if (attacker.runes & CURSE_WEAK)
787 damage = damage * autocvar_g_balance_curse_weak_damage;
788 force = force * autocvar_g_balance_curse_weak_force;
791 // apply defense rune
792 if (targ.runes & RUNE_DEFENSE)
794 if (targ.runes & CURSE_VULNER) // have both curse & rune
795 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
797 damage = damage * autocvar_g_balance_rune_defense_takedamage;
799 else if (targ.runes & CURSE_VULNER)
800 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
806 if(targ.takedamage == DAMAGE_AIM)
809 if(damage_headshotbonus > 0)
811 if(targ.classname == "player")
814 // find height of hit on player axis
815 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
816 vector headmins, headmaxs, org;
817 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
818 headmins = org + GetHeadshotMins(targ);
819 headmaxs = org + GetHeadshotMaxs(targ);
820 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
822 deathtype |= HITTYPE_HEADSHOT;
825 else if(targ.classname == "turret_head")
827 deathtype |= HITTYPE_HEADSHOT;
829 if(deathtype & HITTYPE_HEADSHOT)
830 damage *= 1 + damage_headshotbonus;
834 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
839 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
841 if(IsDifferentTeam(victim, attacker))
845 if(deathtype != DEATH_FIRE)
847 if(victim.BUTTON_CHAT)
848 attacker.typehitsound += 1;
850 attacker.hitsound += 1;
853 damage_goodhits += 1;
854 damage_gooddamage += damage;
856 if not(DEATH_ISSPECIAL(deathtype))
858 if(targ.classname == "player") // don't do this for vehicles
864 if(victim.items & IT_STRENGTH)
867 if(deathtype & HITTYPE_HEADSHOT)
871 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
876 if(deathtype != DEATH_FIRE)
878 attacker.typehitsound += 1;
881 if(time > attacker.teamkill_complain)
883 attacker.teamkill_complain = time + 5;
884 attacker.teamkill_soundtime = time + 0.4;
885 attacker.teamkill_soundsource = targ;
893 if (self.damageforcescale)
895 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
897 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
898 if(self.movetype == MOVETYPE_PHYSICS)
902 farcent.classname = "farce";
903 farcent.enemy = self;
904 farcent.movedir = farce * 10;
906 farcent.movedir = farcent.movedir * self.mass;
907 farcent.origin = hitloc;
908 farcent.forcetype = FORCETYPE_FORCEATPOS;
909 farcent.nextthink = time + 0.1;
910 farcent.think = SUB_Remove;
913 self.velocity = self.velocity + farce;
914 self.flags &~= FL_ONGROUND;
915 UpdateCSQCProjectile(self);
918 if (damage != 0 || (self.damageforcescale && vlen(force)))
919 if (self.event_damage)
920 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
923 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
927 if (attacker.runes & RUNE_VAMPIRE)
929 // apply vampire rune
930 if (attacker.runes & CURSE_EMPATHY) // have the curse too
932 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
933 attacker.health = bound(
934 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
935 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
936 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
940 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
941 attacker.health = bound(
942 attacker.health, // LA: was 3, but changed so that you can't lose health
943 // empathy won't let you gain health in the same way...
944 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
945 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
948 // apply empathy curse
949 else if (attacker.runes & CURSE_EMPATHY)
951 attacker.health = bound(
952 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
953 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
959 // apply mirror damage if any
960 if(mirrordamage > 0 || mirrorforce > 0)
962 attacker = attacker_save;
966 // just lose extra LIVES, don't kill the player for mirror damage
967 if(attacker.armorvalue > 0)
969 attacker.armorvalue = attacker.armorvalue - 1;
970 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
971 attacker.hitsound += 1;
976 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
977 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
981 float RadiusDamage_running;
982 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
983 // Returns total damage applies to creatures
993 float total_damage_to_creatures;
998 float stat_damagedone;
1000 if(RadiusDamage_running)
1002 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
1006 RadiusDamage_running = 1;
1008 tfloordmg = autocvar_g_throughfloor_damage;
1009 tfloorforce = autocvar_g_throughfloor_force;
1011 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1012 total_damage_to_creatures = 0;
1014 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1015 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
1017 force = inflictor.velocity;
1018 if(vlen(force) == 0)
1021 force = normalize(force);
1022 if(forceintensity >= 0)
1023 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
1025 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
1028 stat_damagedone = 0;
1030 targ = WarpZone_FindRadius (blastorigin, rad + MAX_DAMAGEEXTRARADIUS, FALSE);
1034 if (targ != inflictor)
1035 if (ignore != targ) if(targ.takedamage)
1037 // LordHavoc: measure distance to nearest point on target (not origin)
1038 // (this guarentees 100% damage on a touch impact)
1039 nearest = targ.WarpZone_findradius_nearest;
1040 diff = targ.WarpZone_findradius_dist;
1041 // round up a little on the damage to ensure full damage on impacts
1042 // and turn the distance into a fraction of the radius
1043 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
1045 //bprint(ftos(power));
1046 //if (targ == attacker)
1047 // print(ftos(power), "\n");
1052 finaldmg = coredamage * power + edgedamage * (1 - power);
1061 vector myblastorigin;
1062 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1063 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1064 // if it's a player, use the view origin as reference
1065 if (targ.classname == "player")
1066 center = targ.origin + targ.view_ofs;
1067 force = normalize(center - myblastorigin);
1068 force = force * (finaldmg / coredamage) * forceintensity;
1069 // test line of sight to multiple positions on box,
1070 // and do damage if any of them hit
1072 if (targ.classname == "player")
1073 total = ceil(bound(1, finaldmg, 50));
1075 total = ceil(bound(1, finaldmg/10, 5));
1080 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1081 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1082 if (trace_fraction == 1 || trace_ent == targ)
1086 hitloc = hitloc + nearest;
1090 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1091 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1092 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1095 nearest = hitloc * (1 / max(1, hits));
1096 hitratio = (hits / total);
1097 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1098 finaldmg = finaldmg * a;
1099 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1102 // laser force adjustments :P
1103 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1105 if (targ == attacker)
1110 float force_velocitybiasramp;
1111 float force_velocitybias;
1113 force_velocitybiasramp = autocvar_sv_maxspeed;
1114 if(deathtype & HITTYPE_SECONDARY)
1116 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1117 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1121 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1122 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1125 vel = targ.velocity;
1127 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1131 normalize(normalize(force) + vel);
1133 force_z *= force_zscale;
1137 if(deathtype & HITTYPE_SECONDARY)
1139 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1143 force *= autocvar_g_balance_laser_primary_force_other_scale;
1148 //if (targ == attacker)
1150 // print("hits ", ftos(hits), " / ", ftos(total));
1151 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1152 // print(" (", ftos(a), ")\n");
1154 if(hits || tfloordmg || tfloorforce)
1158 total_damage_to_creatures += finaldmg;
1160 if(accuracy_isgooddamage(attacker, targ))
1161 stat_damagedone += finaldmg;
1164 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1165 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1167 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1175 RadiusDamage_running = 0;
1177 if(!DEATH_ISSPECIAL(deathtype))
1178 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1180 return total_damage_to_creatures;
1183 .float fire_damagepersec;
1184 .float fire_endtime;
1185 .float fire_deathtype;
1187 .float fire_hitsound;
1188 .entity fire_burner;
1190 void fireburner_think();
1192 float Fire_IsBurning(entity e)
1194 return (time < e.fire_endtime);
1197 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1200 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1202 if(e.classname == "player")
1211 // print("adding a fire burner to ", e.classname, "\n");
1212 e.fire_burner = spawn();
1213 e.fire_burner.classname = "fireburner";
1214 e.fire_burner.think = fireburner_think;
1215 e.fire_burner.nextthink = time;
1216 e.fire_burner.owner = e;
1222 if(Fire_IsBurning(e))
1224 mintime = e.fire_endtime - time;
1225 maxtime = max(mintime, t);
1227 mindps = e.fire_damagepersec;
1228 maxdps = max(mindps, dps);
1230 if(maxtime > mintime || maxdps > mindps)
1232 mindamage = mindps * mintime;
1233 maxdamage = mindamage + d;
1235 // interval [mintime, maxtime] * [mindps, maxdps]
1237 // [mindamage, maxdamage]
1240 if(maxdamage >= maxtime * maxdps)
1242 totaltime = maxtime;
1243 totaldamage = maxtime * maxdps;
1245 // this branch increases totaldamage if either t > mintime, or dps > mindps
1249 // maxdamage is inside the interval!
1250 // first, try to use mindps; only if this fails, increase dps as needed
1251 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1252 totaldamage = maxdamage;
1253 // can totaldamage / totaltime be >= maxdps?
1254 // max(mindps, maxdamage / maxtime) >= maxdps?
1255 // we know maxdamage < maxtime * maxdps
1258 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1261 // total conditions for increasing:
1262 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1264 // if maxtime = mintime, maxdps = mindps
1266 // maxdamage = mindamage + d
1267 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1268 // so the last condition is not needed
1270 e.fire_damagepersec = totaldamage / totaltime;
1271 e.fire_endtime = time + totaltime;
1272 if(totaldamage > 1.2 * mindamage)
1274 e.fire_deathtype = dt;
1275 if(e.fire_owner != o)
1278 e.fire_hitsound = FALSE;
1281 if(accuracy_isgooddamage(o, e))
1282 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1283 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1290 e.fire_damagepersec = dps;
1291 e.fire_endtime = time + t;
1292 e.fire_deathtype = dt;
1294 e.fire_hitsound = FALSE;
1295 if(accuracy_isgooddamage(o, e))
1296 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1301 void Fire_ApplyDamage(entity e)
1306 if not(Fire_IsBurning(e))
1309 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1310 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1313 // water and slime stop fire
1315 if(e.watertype != CONTENT_LAVA)
1319 if(e.freezetag_frozen)
1322 t = min(frametime, e.fire_endtime - time);
1323 d = e.fire_damagepersec * t;
1325 hi = e.fire_owner.hitsound;
1326 ty = e.fire_owner.typehitsound;
1327 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1328 if(e.fire_hitsound && e.fire_owner)
1330 e.fire_owner.hitsound = hi;
1331 e.fire_owner.typehitsound = ty;
1333 e.fire_hitsound = TRUE;
1335 if not(IS_INDEPENDENT_PLAYER(e))
1336 FOR_EACH_PLAYER(other) if(e != other)
1338 if(other.classname == "player")
1339 if(other.deadflag == DEAD_NO)
1340 if not(IS_INDEPENDENT_PLAYER(other))
1341 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1343 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1344 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1345 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1350 void Fire_ApplyEffect(entity e)
1352 if(Fire_IsBurning(e))
1353 e.effects |= EF_FLAME;
1355 e.effects &~= EF_FLAME;
1358 void fireburner_think()
1360 // for players, this is done in the regular loop
1361 if(wasfreed(self.owner))
1366 Fire_ApplyEffect(self.owner);
1367 if(!Fire_IsBurning(self.owner))
1369 self.owner.fire_burner = world;
1373 Fire_ApplyDamage(self.owner);
1374 self.nextthink = time;