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 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);
144 if(!culprit || !WEPSET_CONTAINS_EW(attacker, culprit))
145 culprit = attacker.weapon;
147 if(g_weaponarena_random_with_laser && culprit == WEP_LASER)
154 WEPSET_COPY_AA(w, warmup_start_weapons);
156 WEPSET_COPY_AA(w, start_weapons);
158 // all others (including the culprit): remove
159 WEPSET_ANDNOT_AE(w, attacker);
160 WEPSET_ANDNOT_AW(w, culprit);
162 // among the remaining ones, choose one by random
163 w = randombits(w, 1, FALSE);
166 WEPSET_OR_EA(attacker, w);
167 WEPSET_ANDNOT_EW(attacker, culprit);
171 // after a frag, choose another random weapon set
172 if not(WEPSET_CONTAINS_EW(attacker, attacker.weapon))
173 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
176 // FIXME fix the mess this is (we have REAL points now!)
180 frag_attacker = attacker;
183 if(MUTATOR_CALLHOOK(GiveFragsForKill))
193 f = RunematchHandleFrags(attacker, targ, f);
199 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
200 if(tl < lms_lowest_lives)
201 lms_lowest_lives = tl;
205 lms_next_place = player_count;
207 lms_next_place = min(lms_next_place, player_count);
208 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
215 if(g_ctf_ignore_frags)
220 attacker.totalfrags += f;
223 UpdateFrags(attacker, f);
226 string Obituary_ExtraFragInfo(entity player) // Extra fragmessage information
228 string health_output;
230 string handicap_output;
233 if(autocvar_sv_fraginfo && ((autocvar_sv_fraginfo == 2) || inWarmupStage))
235 // health/armor of attacker (person who killed you)
236 if(autocvar_sv_fraginfo_stats && (player.health >= 1))
237 health_output = strcat("^7(Health ^1", ftos(rint(player.health)), "^7 / Armor ^2", ftos(rint(player.armorvalue)), "^7)");
240 if(autocvar_sv_fraginfo_ping)
241 ping_output = ((clienttype(player) == CLIENTTYPE_BOT) ? "^2Bot" : strcat("Ping ", ((player.ping >= 150) ? "^1" : "^2"), ftos(rint(player.ping)), "ms"));
244 if(autocvar_sv_fraginfo_handicap)
246 if(autocvar_sv_fraginfo_handicap == 2)
247 handicap_output = strcat(output, strcat("Handicap ^2", ((player.cvar_cl_handicap <= 1) ? "Off" : ftos(rint(player.cvar_cl_handicap)))));
248 else if(player.cvar_cl_handicap) // with _handicap 1, only show this if there actually is a handicap enabled.
249 handicap_output = strcat("Handicap ^2", ftos(rint(player.cvar_cl_handicap)));
253 output = strcat(health_output, (health_output ? ((ping_output || handicap_output) ? " ^7(" : "") : ((ping_output || handicap_output) ? "^7(" : "")),
254 ping_output, (handicap_output ? "^7 / " : ""),
255 handicap_output, ((ping_output || handicap_output) ? "^7)" : ""));
257 // add new line to the beginning if there is a message
258 if(output) { output = strcat("\n", output); }
264 string AppendItemcodes(string s, entity player)
269 // w = player.switchweapon;
271 w = player.cnt; // previous weapon!
272 s = strcat(s, ftos(w));
273 if(time < player.strength_finished)
275 if(time < player.invincible_finished)
277 if(player.flagcarried != world)
279 if(player.BUTTON_CHAT)
284 s = strcat(s, "|", ftos(player.runes));
288 void LogDeath(string mode, float deathtype, entity killer, entity killed)
291 if(!autocvar_sv_eventlog)
293 s = strcat(":kill:", mode);
294 s = strcat(s, ":", ftos(killer.playerid));
295 s = strcat(s, ":", ftos(killed.playerid));
296 s = strcat(s, ":type=", ftos(deathtype));
297 s = strcat(s, ":items=");
298 s = AppendItemcodes(s, killer);
301 s = strcat(s, ":victimitems=");
302 s = AppendItemcodes(s, killed);
307 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
309 WriteByte(MSG_ALL, SVC_TEMPENTITY);
310 WriteByte(MSG_ALL, TE_CSQC_KILLNOTIFY);
311 WriteString(MSG_ALL, s1);
312 WriteString(MSG_ALL, s2);
313 WriteString(MSG_ALL, s3);
314 WriteShort(MSG_ALL, msg);
315 WriteByte(MSG_ALL, type);
318 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
319 void Send_CSQC_KillCenterprint(entity e, string s1, string s2, float msg, float type)
321 if (clienttype(e) == CLIENTTYPE_REAL)
324 WRITESPECTATABLE_MSG_ONE({
325 WriteByte(MSG_ONE, SVC_TEMPENTITY);
326 WriteByte(MSG_ONE, TE_CSQC_KILLCENTERPRINT);
327 WriteString(MSG_ONE, s1);
328 WriteString(MSG_ONE, s2);
329 WriteShort(MSG_ONE, msg);
330 WriteByte(MSG_ONE, type);
335 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
340 if (targ.classname == "player")
343 a = attacker.netname;
345 if (targ == attacker) // suicides
347 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
348 msg = ColoredTeamName(targ.team); // TODO: check if needed?
349 if(!g_cts) // no "killed your own dumb self" message in CTS
350 Send_CSQC_KillCenterprint(targ, msg, "", deathtype, MSG_SUICIDE);
352 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
354 LogDeath("suicide", deathtype, targ, targ);
355 GiveFrags(attacker, targ, -1, deathtype);
358 if (targ.killcount > 2)
359 msg = ftos(targ.killcount);
360 if(teamplay && deathtype == DEATH_MIRRORDAMAGE)
362 if(attacker.team == COLOR_TEAM1)
363 deathtype = KILL_TEAM_RED;
365 deathtype = KILL_TEAM_BLUE;
368 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
370 else if (attacker.classname == "player")
372 if(!IsDifferentTeam(attacker, targ))
374 if(attacker.team == COLOR_TEAM1)
375 type = KILL_TEAM_RED;
377 type = KILL_TEAM_BLUE;
379 GiveFrags(attacker, targ, -1, deathtype);
381 Send_CSQC_KillCenterprint(attacker, s, "", type, MSG_KILL);
383 if (targ.killcount > 2) {
384 msg = ftos(targ.killcount);
387 if (attacker.killcount > 2) {
388 msg = ftos(attacker.killcount);
389 type = KILL_TEAM_SPREE;
391 Send_KillNotification(a, s, msg, type, MSG_KILL);
393 attacker.killcount = 0;
395 LogDeath("tk", deathtype, attacker, targ);
399 if (!checkrules_firstblood)
401 checkrules_firstblood = TRUE;
402 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
403 // TODO: make these print a newline if they dont
404 Send_CSQC_KillCenterprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
405 Send_CSQC_KillCenterprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
406 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
407 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
410 if(targ.BUTTON_CHAT) {
411 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_TYPEFRAG, MSG_KILL);
412 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_TYPEFRAGGED, MSG_KILL);
414 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_FRAG, MSG_KILL);
415 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_FRAGGED, MSG_KILL);
418 attacker.taunt_soundtime = time + 1;
421 if (deathtype == DEATH_CUSTOM)
424 msg = inflictor.message2;
426 if(strstrofs(msg, "%", 0) < 0)
427 msg = strcat("%s ", msg, " by %s");
429 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
431 if(g_ctf && targ.flagcarried)
433 UpdateFrags(attacker, ctf_score_value("score_kill"));
434 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
435 GiveFrags(attacker, targ, 0, deathtype); // for logging
438 GiveFrags(attacker, targ, 1, deathtype);
440 if (targ.killcount > 2) {
441 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
444 attacker.killcount = attacker.killcount + 1;
446 if (attacker.killcount > 2) {
447 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
449 else if (attacker.killcount == 3)
451 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
452 AnnounceTo(attacker, "03kills");
453 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
455 else if (attacker.killcount == 5)
457 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
458 AnnounceTo(attacker, "05kills");
459 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
461 else if (attacker.killcount == 10)
463 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
464 AnnounceTo(attacker, "10kills");
465 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
467 else if (attacker.killcount == 15)
469 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
470 AnnounceTo(attacker, "15kills");
471 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
473 else if (attacker.killcount == 20)
475 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
476 AnnounceTo(attacker, "20kills");
477 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
479 else if (attacker.killcount == 25)
481 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
482 AnnounceTo(attacker, "25kills");
483 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
485 else if (attacker.killcount == 30)
487 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
488 AnnounceTo(attacker, "30kills");
489 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
491 LogDeath("frag", deathtype, attacker, targ);
496 Send_CSQC_KillCenterprint(targ, "", "", deathtype, MSG_KILL_ACTION);
497 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
498 msg = inflictor.message;
499 else if (deathtype == DEATH_CUSTOM)
501 if(strstrofs(msg, "%", 0) < 0)
502 msg = strcat("%s ", msg);
504 GiveFrags(targ, targ, -1, deathtype);
505 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
506 AnnounceTo(targ, "botlike");
507 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
509 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
511 if (targ.killcount > 2)
512 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
514 LogDeath("accident", deathtype, targ, targ);
517 targ.death_origin = targ.origin;
519 targ.killer_origin = attacker.origin;
521 // FIXME: this should go in PutClientInServer
527 // these are updated by each Damage call for use in button triggering and such
529 entity damage_inflictor;
530 entity damage_attacker;
532 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
537 entity attacker_save;
541 if (gameover || targ.killcount == -666)
548 damage_inflictor = inflictor;
549 damage_attacker = attacker;
550 attacker_save = attacker;
552 if(targ.classname == "player")
555 if(targ.hook.aiment == attacker)
556 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
558 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
559 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
561 if(targ.classname == "player")
562 if not(IsDifferentTeam(targ, attacker))
569 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
571 // These are ALWAYS lethal
572 // No damage modification here
573 // Instead, prepare the victim for his death...
575 targ.spawnshieldtime = 0;
576 targ.health = 0.9; // this is < 1
577 targ.flags -= targ.flags & FL_GODMODE;
580 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
587 skill based bot damage? gtfo. (tZork)
588 if (targ.classname == "player")
589 if (attacker.classname == "player")
592 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
595 // nullify damage if teamplay is on
596 if(deathtype != DEATH_TELEFRAG)
597 if(attacker.classname == "player")
599 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
604 else if(!IsDifferentTeam(attacker, targ))
606 if(autocvar_teamplay_mode == 1)
608 else if(attacker != targ)
610 if(autocvar_teamplay_mode == 3)
612 else if(autocvar_teamplay_mode == 4)
614 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
616 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
617 attacker.dmg_team = attacker.dmg_team + damage;
618 if(attacker.dmg_team > teamdamage0 && !g_ca)
619 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
620 mirrorforce = autocvar_g_mirrordamage * vlen(force);
623 if(autocvar_g_friendlyfire == 0)
629 damage = autocvar_g_friendlyfire * damage;
630 // mirrordamage will be used LATER
632 if(autocvar_g_mirrordamage_virtual)
635 v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
636 v_z = 0; // fteqcc sucks
637 attacker.dmg_take += v_x;
638 attacker.dmg_save += v_y;
639 attacker.dmg_inflictor = inflictor;
644 if(autocvar_g_friendlyfire_virtual)
647 v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
648 v_z = 0; // fteqcc sucks
649 targ.dmg_take += v_x;
650 targ.dmg_save += v_y;
651 targ.dmg_inflictor = inflictor;
653 if(!autocvar_g_friendlyfire_virtual_force)
664 if(targ.classname == "player")
665 if(attacker.classname == "player")
668 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
669 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
672 if(targ.classname == "player")
675 if ((deathtype == DEATH_FALL) ||
676 (deathtype == DEATH_DROWN) ||
677 (deathtype == DEATH_SLIME) ||
678 (deathtype == DEATH_LAVA) ||
679 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
686 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
688 targ.armorvalue -= 1;
689 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
692 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
694 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
698 if (targ != attacker)
700 if ((targ.health >= 1) && (targ.classname == "player"))
701 centerprint(attacker, "Secondary fire inflicts no damage!");
709 if not(DEATH_ISSPECIAL(deathtype))
711 damage *= g_weapondamagefactor;
712 mirrordamage *= g_weapondamagefactor;
713 force = force * g_weaponforcefactor;
714 mirrorforce *= g_weaponforcefactor;
717 // should this be changed at all? If so, in what way?
718 frag_attacker = attacker;
720 frag_damage = damage;
722 frag_deathtype = deathtype;
723 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
724 damage = frag_damage;
727 // apply strength multiplier
728 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
732 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
733 force = force * autocvar_g_balance_powerup_strength_selfforce;
737 damage = damage * autocvar_g_balance_powerup_strength_damage;
738 force = force * autocvar_g_balance_powerup_strength_force;
742 // apply invincibility multiplier
743 if (targ.items & IT_INVINCIBLE && !g_minstagib)
744 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
746 if (targ == attacker)
748 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
751 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
754 // CTF: reduce damage/force
759 damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
760 force = force * autocvar_g_ctf_flagcarrier_selfforce;
765 // apply strength rune
766 if (attacker.runes & RUNE_STRENGTH)
768 if(attacker.runes & CURSE_WEAK) // have both curse & rune
770 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
771 force = force * autocvar_g_balance_rune_strength_combo_force;
775 damage = damage * autocvar_g_balance_rune_strength_damage;
776 force = force * autocvar_g_balance_rune_strength_force;
779 else if (attacker.runes & CURSE_WEAK)
781 damage = damage * autocvar_g_balance_curse_weak_damage;
782 force = force * autocvar_g_balance_curse_weak_force;
785 // apply defense rune
786 if (targ.runes & RUNE_DEFENSE)
788 if (targ.runes & CURSE_VULNER) // have both curse & rune
789 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
791 damage = damage * autocvar_g_balance_rune_defense_takedamage;
793 else if (targ.runes & CURSE_VULNER)
794 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
800 if(targ.takedamage == DAMAGE_AIM)
803 if(damage_headshotbonus > 0)
805 if(targ.classname == "player")
808 // find height of hit on player axis
809 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
810 vector headmins, headmaxs, org;
811 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
812 headmins = org + GetHeadshotMins(targ);
813 headmaxs = org + GetHeadshotMaxs(targ);
814 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
816 deathtype |= HITTYPE_HEADSHOT;
819 else if(targ.classname == "turret_head")
821 deathtype |= HITTYPE_HEADSHOT;
823 if(deathtype & HITTYPE_HEADSHOT)
824 damage *= 1 + damage_headshotbonus;
828 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
833 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
835 if(IsDifferentTeam(victim, attacker))
839 if(deathtype != DEATH_FIRE)
841 if(victim.BUTTON_CHAT)
842 attacker.typehitsound += 1;
844 attacker.hitsound += 1;
847 damage_goodhits += 1;
848 damage_gooddamage += damage;
850 if not(DEATH_ISSPECIAL(deathtype))
852 if(targ.classname == "player") // don't do this for vehicles
858 if(victim.items & IT_STRENGTH)
861 if(deathtype & HITTYPE_HEADSHOT)
865 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
870 if(deathtype != DEATH_FIRE)
872 attacker.typehitsound += 1;
875 if(time > attacker.teamkill_complain)
877 attacker.teamkill_complain = time + 5;
878 attacker.teamkill_soundtime = time + 0.4;
879 attacker.teamkill_soundsource = targ;
887 if (self.damageforcescale)
889 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
891 self.velocity = self.velocity + damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
892 self.flags &~= FL_ONGROUND;
893 UpdateCSQCProjectile(self);
896 if (damage != 0 || (self.damageforcescale && vlen(force)))
897 if (self.event_damage)
898 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
901 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
905 if (attacker.runes & RUNE_VAMPIRE)
907 // apply vampire rune
908 if (attacker.runes & CURSE_EMPATHY) // have the curse too
910 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
911 attacker.health = bound(
912 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
913 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
914 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
918 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
919 attacker.health = bound(
920 attacker.health, // LA: was 3, but changed so that you can't lose health
921 // empathy won't let you gain health in the same way...
922 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
923 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
926 // apply empathy curse
927 else if (attacker.runes & CURSE_EMPATHY)
929 attacker.health = bound(
930 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
931 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
937 // apply mirror damage if any
938 if(mirrordamage > 0 || mirrorforce > 0)
940 attacker = attacker_save;
944 // just lose extra LIVES, don't kill the player for mirror damage
945 if(attacker.armorvalue > 0)
947 attacker.armorvalue = attacker.armorvalue - 1;
948 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
949 attacker.hitsound += 1;
954 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
955 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
959 float RadiusDamage_running;
960 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
961 // Returns total damage applies to creatures
971 float total_damage_to_creatures;
976 float stat_damagedone;
978 if(RadiusDamage_running)
980 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
984 RadiusDamage_running = 1;
986 tfloordmg = autocvar_g_throughfloor_damage;
987 tfloorforce = autocvar_g_throughfloor_force;
989 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
990 total_damage_to_creatures = 0;
992 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
993 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
995 force = inflictor.velocity;
999 force = normalize(force);
1000 if(forceintensity >= 0)
1001 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
1003 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
1006 stat_damagedone = 0;
1008 targ = WarpZone_FindRadius (blastorigin, rad + MAX_DAMAGEEXTRARADIUS, FALSE);
1012 if (targ != inflictor)
1013 if (ignore != targ) if(targ.takedamage)
1015 // LordHavoc: measure distance to nearest point on target (not origin)
1016 // (this guarentees 100% damage on a touch impact)
1017 nearest = targ.WarpZone_findradius_nearest;
1018 diff = targ.WarpZone_findradius_dist;
1019 // round up a little on the damage to ensure full damage on impacts
1020 // and turn the distance into a fraction of the radius
1021 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
1023 //bprint(ftos(power));
1024 //if (targ == attacker)
1025 // print(ftos(power), "\n");
1030 finaldmg = coredamage * power + edgedamage * (1 - power);
1039 vector myblastorigin;
1040 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1041 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1042 // if it's a player, use the view origin as reference
1043 if (targ.classname == "player")
1044 center = targ.origin + targ.view_ofs;
1045 force = normalize(center - myblastorigin);
1046 force = force * (finaldmg / coredamage) * forceintensity;
1047 // test line of sight to multiple positions on box,
1048 // and do damage if any of them hit
1050 if (targ.classname == "player")
1051 total = ceil(bound(1, finaldmg, 50));
1053 total = ceil(bound(1, finaldmg/10, 5));
1058 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1059 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1060 if (trace_fraction == 1 || trace_ent == targ)
1064 hitloc = hitloc + nearest;
1068 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1069 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1070 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1073 nearest = hitloc * (1 / max(1, hits));
1074 hitratio = (hits / total);
1075 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1076 finaldmg = finaldmg * a;
1077 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1080 // laser force adjustments :P
1081 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1083 if (targ == attacker)
1088 float force_velocitybiasramp;
1089 float force_velocitybias;
1091 force_velocitybiasramp = autocvar_sv_maxspeed;
1092 if(deathtype & HITTYPE_SECONDARY)
1094 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1095 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1099 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1100 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1103 vel = targ.velocity;
1105 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1109 normalize(normalize(force) + vel);
1111 force_z *= force_zscale;
1115 if(deathtype & HITTYPE_SECONDARY)
1117 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1121 force *= autocvar_g_balance_laser_primary_force_other_scale;
1126 //if (targ == attacker)
1128 // print("hits ", ftos(hits), " / ", ftos(total));
1129 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1130 // print(" (", ftos(a), ")\n");
1132 if(hits || tfloordmg || tfloorforce)
1136 total_damage_to_creatures += finaldmg;
1138 if(accuracy_isgooddamage(attacker, targ))
1139 stat_damagedone += finaldmg;
1142 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1143 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1145 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1153 RadiusDamage_running = 0;
1155 if(!DEATH_ISSPECIAL(deathtype))
1156 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1158 return total_damage_to_creatures;
1161 .float fire_damagepersec;
1162 .float fire_endtime;
1163 .float fire_deathtype;
1165 .float fire_hitsound;
1166 .entity fire_burner;
1168 void fireburner_think();
1170 float Fire_IsBurning(entity e)
1172 return (time < e.fire_endtime);
1175 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1178 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1180 if(e.classname == "player")
1189 // print("adding a fire burner to ", e.classname, "\n");
1190 e.fire_burner = spawn();
1191 e.fire_burner.classname = "fireburner";
1192 e.fire_burner.think = fireburner_think;
1193 e.fire_burner.nextthink = time;
1194 e.fire_burner.owner = e;
1200 if(Fire_IsBurning(e))
1202 mintime = e.fire_endtime - time;
1203 maxtime = max(mintime, t);
1205 mindps = e.fire_damagepersec;
1206 maxdps = max(mindps, dps);
1208 if(maxtime > mintime || maxdps > mindps)
1210 mindamage = mindps * mintime;
1211 maxdamage = mindamage + d;
1213 // interval [mintime, maxtime] * [mindps, maxdps]
1215 // [mindamage, maxdamage]
1218 if(maxdamage >= maxtime * maxdps)
1220 totaltime = maxtime;
1221 totaldamage = maxtime * maxdps;
1223 // this branch increases totaldamage if either t > mintime, or dps > mindps
1227 // maxdamage is inside the interval!
1228 // first, try to use mindps; only if this fails, increase dps as needed
1229 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1230 totaldamage = maxdamage;
1231 // can totaldamage / totaltime be >= maxdps?
1232 // max(mindps, maxdamage / maxtime) >= maxdps?
1233 // we know maxdamage < maxtime * maxdps
1236 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1239 // total conditions for increasing:
1240 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1242 // if maxtime = mintime, maxdps = mindps
1244 // maxdamage = mindamage + d
1245 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1246 // so the last condition is not needed
1248 e.fire_damagepersec = totaldamage / totaltime;
1249 e.fire_endtime = time + totaltime;
1250 if(totaldamage > 1.2 * mindamage)
1252 e.fire_deathtype = dt;
1253 if(e.fire_owner != o)
1256 e.fire_hitsound = FALSE;
1259 if(accuracy_isgooddamage(o, e))
1260 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1261 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1268 e.fire_damagepersec = dps;
1269 e.fire_endtime = time + t;
1270 e.fire_deathtype = dt;
1272 e.fire_hitsound = FALSE;
1273 if(accuracy_isgooddamage(o, e))
1274 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1279 void Fire_ApplyDamage(entity e)
1284 if not(Fire_IsBurning(e))
1287 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1288 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1291 // water and slime stop fire
1293 if(e.watertype != CONTENT_LAVA)
1297 if(e.freezetag_frozen)
1300 t = min(frametime, e.fire_endtime - time);
1301 d = e.fire_damagepersec * t;
1303 hi = e.fire_owner.hitsound;
1304 ty = e.fire_owner.typehitsound;
1305 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1306 if(e.fire_hitsound && e.fire_owner)
1308 e.fire_owner.hitsound = hi;
1309 e.fire_owner.typehitsound = ty;
1311 e.fire_hitsound = TRUE;
1313 if not(IS_INDEPENDENT_PLAYER(e))
1314 FOR_EACH_PLAYER(other) if(e != other)
1316 if(other.classname == "player")
1317 if(other.deadflag == DEAD_NO)
1318 if not(IS_INDEPENDENT_PLAYER(other))
1319 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1321 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1322 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1323 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1328 void Fire_ApplyEffect(entity e)
1330 if(Fire_IsBurning(e))
1331 e.effects |= EF_FLAME;
1333 e.effects &~= EF_FLAME;
1336 void fireburner_think()
1338 // for players, this is done in the regular loop
1339 if(wasfreed(self.owner))
1344 Fire_ApplyEffect(self.owner);
1345 if(!Fire_IsBurning(self.owner))
1347 self.owner.fire_burner = world;
1351 Fire_ApplyDamage(self.owner);
1352 self.nextthink = time;