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(string s1, string s2, float deathtype)
315 case DEATH_AUTOTEAMCHANGE:
319 case DEATH_TEAMCHANGE:
329 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
334 if (targ.classname == "player")
337 a = attacker.netname;
339 if (targ == attacker) // suicides
341 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
342 msg = ColoredTeamName(targ.team); // TODO: check if needed?
345 if(!g_cts) // no "killed your own dumb self" message in CTS
346 Send_CSQC_KillCenterprint(targ, msg, "", deathtype, MSG_SUICIDE);
348 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
350 LogDeath("suicide", deathtype, targ, targ);
351 GiveFrags(attacker, targ, -1, deathtype);
354 if (targ.killcount > 2)
355 msg = ftos(targ.killcount);
358 if(teamplay && deathtype == DEATH_MIRRORDAMAGE)
360 if(attacker.team == COLOR_TEAM1)
361 deathtype = KILL_TEAM_RED;
363 deathtype = KILL_TEAM_BLUE;
366 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
368 else if (attacker.classname == "player")
370 if(!IsDifferentTeam(attacker, targ))
372 if(attacker.team == COLOR_TEAM1)
373 type = KILL_TEAM_RED;
375 type = KILL_TEAM_BLUE;
377 GiveFrags(attacker, targ, -1, deathtype);
379 Send_CSQC_KillCenterprint(attacker, s, "", type, MSG_KILL);
381 if (targ.killcount > 2)
382 msg = ftos(targ.killcount);
386 if (attacker.killcount > 2) {
387 msg = ftos(attacker.killcount);
388 type = KILL_TEAM_SPREE;
390 Send_KillNotification(a, s, msg, type, MSG_KILL);
392 attacker.killcount = 0;
394 LogDeath("tk", deathtype, attacker, targ);
398 if (!checkrules_firstblood)
400 checkrules_firstblood = TRUE;
401 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
402 // TODO: make these print a newline if they dont
403 Send_CSQC_KillCenterprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
404 Send_CSQC_KillCenterprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
405 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
406 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
409 if(targ.istypefrag) {
410 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_TYPEFRAG, MSG_KILL);
411 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_TYPEFRAGGED, MSG_KILL);
413 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_FRAG, MSG_KILL);
414 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_FRAGGED, MSG_KILL);
417 attacker.taunt_soundtime = time + 1;
419 if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
420 msg = inflictor.message2;
421 else if (deathtype == DEATH_CUSTOM)
426 if(strstrofs(msg, "%", 0) < 0)
427 msg = strcat("%s ", msg, " by %s");
429 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
431 GiveFrags(attacker, targ, 1, deathtype);
433 if (targ.killcount > 2) {
434 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
437 attacker.killcount = attacker.killcount + 1;
439 if (attacker.killcount == 3)
441 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
442 AnnounceTo(attacker, "03kills");
443 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
445 else if (attacker.killcount == 5)
447 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
448 AnnounceTo(attacker, "05kills");
449 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
451 else if (attacker.killcount == 10)
453 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
454 AnnounceTo(attacker, "10kills");
455 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
457 else if (attacker.killcount == 15)
459 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
460 AnnounceTo(attacker, "15kills");
461 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
463 else if (attacker.killcount == 20)
465 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
466 AnnounceTo(attacker, "20kills");
467 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
469 else if (attacker.killcount == 25)
471 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
472 AnnounceTo(attacker, "25kills");
473 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
475 else if (attacker.killcount == 30)
477 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
478 AnnounceTo(attacker, "30kills");
479 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
481 else if (attacker.killcount > 2) {
482 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
484 LogDeath("frag", deathtype, attacker, targ);
489 Send_CSQC_KillCenterprint(targ, "", "", deathtype, MSG_KILL_ACTION);
490 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
491 msg = inflictor.message;
492 else if (deathtype == DEATH_CUSTOM)
496 if(strstrofs(msg, "%", 0) < 0)
497 msg = strcat("%s ", msg);
499 GiveFrags(targ, targ, -1, deathtype);
500 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
501 AnnounceTo(targ, "botlike");
502 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
504 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
506 if (targ.killcount > 2)
507 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
509 LogDeath("accident", deathtype, targ, targ);
512 targ.death_origin = targ.origin;
514 targ.killer_origin = attacker.origin;
516 // FIXME: this should go in PutClientInServer
522 // these are updated by each Damage call for use in button triggering and such
524 entity damage_inflictor;
525 entity damage_attacker;
527 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
532 entity attacker_save;
536 if (gameover || targ.killcount == -666)
543 damage_inflictor = inflictor;
544 damage_attacker = attacker;
545 attacker_save = attacker;
547 if(targ.classname == "player")
550 if(targ.hook.aiment == attacker)
551 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
553 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
554 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
556 if(targ.classname == "player")
557 if not(IsDifferentTeam(targ, attacker))
564 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
566 // These are ALWAYS lethal
567 // No damage modification here
568 // Instead, prepare the victim for his death...
570 targ.spawnshieldtime = 0;
571 targ.health = 0.9; // this is < 1
572 targ.flags -= targ.flags & FL_GODMODE;
575 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
582 skill based bot damage? gtfo. (tZork)
583 if (targ.classname == "player")
584 if (attacker.classname == "player")
587 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
590 // nullify damage if teamplay is on
591 if(deathtype != DEATH_TELEFRAG)
592 if(attacker.classname == "player")
594 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
599 else if(!IsDifferentTeam(attacker, targ))
601 if(autocvar_teamplay_mode == 1)
603 else if(attacker != targ)
605 if(autocvar_teamplay_mode == 3)
607 else if(autocvar_teamplay_mode == 4)
609 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
611 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
612 attacker.dmg_team = attacker.dmg_team + damage;
613 if(attacker.dmg_team > teamdamage0 && !g_ca)
614 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
615 mirrorforce = autocvar_g_mirrordamage * vlen(force);
618 if(autocvar_g_friendlyfire == 0)
624 damage = autocvar_g_friendlyfire * damage;
625 // mirrordamage will be used LATER
627 if(autocvar_g_mirrordamage_virtual)
629 vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
630 attacker.dmg_take += v_x;
631 attacker.dmg_save += v_y;
632 attacker.dmg_inflictor = inflictor;
633 mirrordamage = v_z; // = 0, to make fteqcc stfu
637 if(autocvar_g_friendlyfire_virtual)
639 vector v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
640 targ.dmg_take += v_x;
641 targ.dmg_save += v_y;
642 targ.dmg_inflictor = inflictor;
644 if(!autocvar_g_friendlyfire_virtual_force)
655 if(targ.classname == "player")
656 if(attacker.classname == "player")
659 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
660 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
663 if(targ.classname == "player")
666 if ((deathtype == DEATH_FALL) ||
667 (deathtype == DEATH_DROWN) ||
668 (deathtype == DEATH_SLIME) ||
669 (deathtype == DEATH_LAVA) ||
670 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
677 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
679 targ.armorvalue -= 1;
680 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
683 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
685 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
689 if (targ != attacker)
691 if ((targ.health >= 1) && (targ.classname == "player"))
692 centerprint(attacker, "Secondary fire inflicts no damage!");
700 if not(DEATH_ISSPECIAL(deathtype))
702 damage *= g_weapondamagefactor;
703 mirrordamage *= g_weapondamagefactor;
704 force = force * g_weaponforcefactor;
705 mirrorforce *= g_weaponforcefactor;
708 // should this be changed at all? If so, in what way?
709 frag_attacker = attacker;
711 frag_damage = damage;
713 frag_deathtype = deathtype;
714 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
715 damage = frag_damage;
718 // apply strength multiplier
719 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
723 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
724 force = force * autocvar_g_balance_powerup_strength_selfforce;
728 damage = damage * autocvar_g_balance_powerup_strength_damage;
729 force = force * autocvar_g_balance_powerup_strength_force;
733 // apply invincibility multiplier
734 if (targ.items & IT_INVINCIBLE && !g_minstagib)
735 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
737 if (targ == attacker)
739 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
742 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
747 // apply strength rune
748 if (attacker.runes & RUNE_STRENGTH)
750 if(attacker.runes & CURSE_WEAK) // have both curse & rune
752 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
753 force = force * autocvar_g_balance_rune_strength_combo_force;
757 damage = damage * autocvar_g_balance_rune_strength_damage;
758 force = force * autocvar_g_balance_rune_strength_force;
761 else if (attacker.runes & CURSE_WEAK)
763 damage = damage * autocvar_g_balance_curse_weak_damage;
764 force = force * autocvar_g_balance_curse_weak_force;
767 // apply defense rune
768 if (targ.runes & RUNE_DEFENSE)
770 if (targ.runes & CURSE_VULNER) // have both curse & rune
771 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
773 damage = damage * autocvar_g_balance_rune_defense_takedamage;
775 else if (targ.runes & CURSE_VULNER)
776 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
782 if(targ.takedamage == DAMAGE_AIM)
785 if(damage_headshotbonus)
787 if(targ.classname == "player")
790 // find height of hit on player axis
791 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
792 vector headmins, headmaxs, org;
793 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
794 headmins = org + GetHeadshotMins(targ);
795 headmaxs = org + GetHeadshotMaxs(targ);
796 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
798 deathtype |= HITTYPE_HEADSHOT;
801 else if(targ.classname == "turret_head")
803 deathtype |= HITTYPE_HEADSHOT;
805 if(deathtype & HITTYPE_HEADSHOT)
806 if(damage_headshotbonus > 0)
807 damage *= 1 + damage_headshotbonus;
811 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
816 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
818 if(IsDifferentTeam(victim, attacker))
822 if(deathtype != DEATH_FIRE)
824 if(victim.BUTTON_CHAT)
825 attacker.typehitsound += 1;
827 attacker.hitsound += 1;
830 damage_goodhits += 1;
831 damage_gooddamage += damage;
833 if not(DEATH_ISSPECIAL(deathtype))
835 if(targ.classname == "player") // don't do this for vehicles
841 if(victim.items & IT_STRENGTH)
844 if(deathtype & HITTYPE_HEADSHOT)
848 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
853 if(deathtype != DEATH_FIRE)
855 attacker.typehitsound += 1;
858 if(time > attacker.teamkill_complain)
860 attacker.teamkill_complain = time + 5;
861 attacker.teamkill_soundtime = time + 0.4;
862 attacker.teamkill_soundsource = targ;
870 if (self.damageforcescale)
872 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
874 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
875 if(self.movetype == MOVETYPE_PHYSICS)
879 farcent.classname = "farce";
880 farcent.enemy = self;
881 farcent.movedir = farce * 10;
883 farcent.movedir = farcent.movedir * self.mass;
884 farcent.origin = hitloc;
885 farcent.forcetype = FORCETYPE_FORCEATPOS;
886 farcent.nextthink = time + 0.1;
887 farcent.think = SUB_Remove;
890 self.velocity = self.velocity + farce;
891 self.flags &~= FL_ONGROUND;
892 UpdateCSQCProjectile(self);
895 if (damage != 0 || (self.damageforcescale && vlen(force)))
896 if (self.event_damage)
897 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
900 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
904 if (attacker.runes & RUNE_VAMPIRE)
906 // apply vampire rune
907 if (attacker.runes & CURSE_EMPATHY) // have the curse too
909 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
910 attacker.health = bound(
911 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
912 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
913 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
917 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
918 attacker.health = bound(
919 attacker.health, // LA: was 3, but changed so that you can't lose health
920 // empathy won't let you gain health in the same way...
921 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
922 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
925 // apply empathy curse
926 else if (attacker.runes & CURSE_EMPATHY)
928 attacker.health = bound(
929 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
930 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
936 // apply mirror damage if any
937 if(mirrordamage > 0 || mirrorforce > 0)
939 attacker = attacker_save;
943 // just lose extra LIVES, don't kill the player for mirror damage
944 if(attacker.armorvalue > 0)
946 attacker.armorvalue = attacker.armorvalue - 1;
947 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
948 attacker.hitsound += 1;
953 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
954 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
958 float RadiusDamage_running;
959 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
960 // Returns total damage applies to creatures
965 float total_damage_to_creatures;
970 float stat_damagedone;
972 if(RadiusDamage_running)
974 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
978 RadiusDamage_running = 1;
980 tfloordmg = autocvar_g_throughfloor_damage;
981 tfloorforce = autocvar_g_throughfloor_force;
983 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
984 total_damage_to_creatures = 0;
986 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
987 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
989 force = inflictor.velocity;
993 force = normalize(force);
994 if(forceintensity >= 0)
995 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
997 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
1000 stat_damagedone = 0;
1002 targ = WarpZone_FindRadius (blastorigin, rad + MAX_DAMAGEEXTRARADIUS, FALSE);
1006 if (targ != inflictor)
1007 if (ignore != targ) if(targ.takedamage)
1013 // LordHavoc: measure distance to nearest point on target (not origin)
1014 // (this guarentees 100% damage on a touch impact)
1015 nearest = targ.WarpZone_findradius_nearest;
1016 diff = targ.WarpZone_findradius_dist;
1017 // round up a little on the damage to ensure full damage on impacts
1018 // and turn the distance into a fraction of the radius
1019 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
1021 //bprint(ftos(power));
1022 //if (targ == attacker)
1023 // print(ftos(power), "\n");
1029 finaldmg = coredamage * power + edgedamage * (1 - power);
1035 vector myblastorigin;
1038 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1040 // if it's a player, use the view origin as reference
1041 center = CENTER_OR_VIEWOFS(targ);
1043 force = normalize(center - myblastorigin);
1044 force = force * (finaldmg / coredamage) * forceintensity;
1047 if(targ != directhitentity)
1052 float mininv_f, mininv_d;
1054 // test line of sight to multiple positions on box,
1055 // and do damage if any of them hit
1058 // we know: max stddev of hitratio = 1 / (2 * sqrt(n))
1059 // so for a given max stddev:
1060 // n = (1 / (2 * max stddev of hitratio))^2
1062 mininv_d = (finaldmg * (1-tfloordmg)) / autocvar_g_throughfloor_damage_max_stddev;
1063 mininv_f = (vlen(force) * (1-tfloorforce)) / autocvar_g_throughfloor_force_max_stddev;
1065 if(autocvar_g_throughfloor_debug)
1066 print(sprintf("THROUGHFLOOR: D=%f F=%f max(dD)=1/%f max(dF)=1/%f", finaldmg, vlen(force), mininv_d, mininv_f));
1068 total = 0.25 * pow(max(mininv_f, mininv_d), 2);
1070 if(autocvar_g_throughfloor_debug)
1071 print(sprintf(" steps=%f", total));
1073 if (targ.classname == "player")
1074 total = ceil(bound(autocvar_g_throughfloor_min_steps_player, total, autocvar_g_throughfloor_max_steps_player));
1076 total = ceil(bound(autocvar_g_throughfloor_min_steps_other, total, autocvar_g_throughfloor_max_steps_other));
1078 if(autocvar_g_throughfloor_debug)
1079 print(sprintf(" steps=%f dD=%f dF=%f", total, finaldmg * (1-tfloordmg) / (2 * sqrt(total)), vlen(force) * (1-tfloorforce) / (2 * sqrt(total))));
1081 for(c = 0; c < total; ++c)
1083 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1084 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1085 if (trace_fraction == 1 || trace_ent == targ)
1089 hitloc = hitloc + nearest;
1093 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1094 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1095 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1098 nearest = hitloc * (1 / max(1, hits));
1099 hitratio = (hits / total);
1100 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1101 finaldmg = finaldmg * a;
1102 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1105 if(autocvar_g_throughfloor_debug)
1106 print(sprintf(" D=%f F=%f\n", finaldmg, vlen(force)));
1109 // laser force adjustments :P
1110 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1112 if (targ == attacker)
1117 float force_velocitybiasramp;
1118 float force_velocitybias;
1120 force_velocitybiasramp = autocvar_sv_maxspeed;
1121 if(deathtype & HITTYPE_SECONDARY)
1123 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1124 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1128 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1129 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1132 vel = targ.velocity;
1134 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1138 normalize(normalize(force) + vel);
1140 force_z *= force_zscale;
1144 if(deathtype & HITTYPE_SECONDARY)
1146 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1150 force *= autocvar_g_balance_laser_primary_force_other_scale;
1155 //if (targ == attacker)
1157 // print("hits ", ftos(hits), " / ", ftos(total));
1158 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1159 // print(" (", ftos(a), ")\n");
1161 if(finaldmg || vlen(force))
1165 total_damage_to_creatures += finaldmg;
1167 if(accuracy_isgooddamage(attacker, targ))
1168 stat_damagedone += finaldmg;
1171 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1172 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1174 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1182 RadiusDamage_running = 0;
1184 if(!DEATH_ISSPECIAL(deathtype))
1185 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1187 return total_damage_to_creatures;
1190 .float fire_damagepersec;
1191 .float fire_endtime;
1192 .float fire_deathtype;
1194 .float fire_hitsound;
1195 .entity fire_burner;
1197 void fireburner_think();
1199 float Fire_IsBurning(entity e)
1201 return (time < e.fire_endtime);
1204 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1207 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1209 if(e.classname == "player")
1218 // print("adding a fire burner to ", e.classname, "\n");
1219 e.fire_burner = spawn();
1220 e.fire_burner.classname = "fireburner";
1221 e.fire_burner.think = fireburner_think;
1222 e.fire_burner.nextthink = time;
1223 e.fire_burner.owner = e;
1229 if(Fire_IsBurning(e))
1231 mintime = e.fire_endtime - time;
1232 maxtime = max(mintime, t);
1234 mindps = e.fire_damagepersec;
1235 maxdps = max(mindps, dps);
1237 if(maxtime > mintime || maxdps > mindps)
1241 // damage we have right now
1242 mindamage = mindps * mintime;
1244 // damage we want to get
1245 maxdamage = mindamage + d;
1247 // but we can't exceed maxtime * maxdps!
1248 totaldamage = min(maxdamage, maxtime * maxdps);
1252 // totaldamage = min(mindamage + d, maxtime * maxdps)
1254 // totaldamage <= maxtime * maxdps
1255 // ==> totaldamage / maxdps <= maxtime.
1257 // totaldamage / mindps = min(mindamage / mindps + d, maxtime * maxdps / mindps)
1258 // >= min(mintime, maxtime)
1259 // ==> totaldamage / maxdps >= mintime.
1262 // how long do we damage then?
1263 // at least as long as before
1264 // but, never exceed maxdps
1265 totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime due to lemma
1269 // at most as long as maximum allowed
1270 // but, never below mindps
1271 totaltime = min(maxtime, totaldamage / mindps); // always >= mintime due to lemma
1273 // assuming t > mintime, dps > mindps:
1274 // we get d = t * dps = maxtime * maxdps
1275 // totaldamage = min(maxdamage, maxtime * maxdps) = min(... + d, maxtime * maxdps) = maxtime * maxdps
1276 // totaldamage / maxdps = maxtime
1277 // totaldamage / mindps > totaldamage / maxdps = maxtime
1279 // a) totaltime = max(mintime, maxtime) = maxtime
1280 // b) totaltime = min(maxtime, totaldamage / maxdps) = maxtime
1282 // assuming t <= mintime:
1283 // we get maxtime = mintime
1284 // a) totaltime = max(mintime, ...) >= mintime, also totaltime <= maxtime by the lemma, therefore totaltime = mintime = maxtime
1285 // b) totaltime = min(maxtime, ...) <= maxtime, also totaltime >= mintime by the lemma, therefore totaltime = mintime = maxtime
1287 // assuming dps <= mindps:
1288 // we get mindps = maxdps.
1289 // With this, the lemma says that mintime <= totaldamage / mindps = totaldamage / maxdps <= maxtime.
1290 // a) totaltime = max(mintime, totaldamage / maxdps) = totaldamage / maxdps
1291 // b) totaltime = min(maxtime, totaldamage / mindps) = totaldamage / maxdps
1293 e.fire_damagepersec = totaldamage / totaltime;
1294 e.fire_endtime = time + totaltime;
1295 if(totaldamage > 1.2 * mindamage)
1297 e.fire_deathtype = dt;
1298 if(e.fire_owner != o)
1301 e.fire_hitsound = FALSE;
1304 if(accuracy_isgooddamage(o, e))
1305 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1306 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1313 e.fire_damagepersec = dps;
1314 e.fire_endtime = time + t;
1315 e.fire_deathtype = dt;
1317 e.fire_hitsound = FALSE;
1318 if(accuracy_isgooddamage(o, e))
1319 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1324 void Fire_ApplyDamage(entity e)
1329 if not(Fire_IsBurning(e))
1332 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1333 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1336 // water and slime stop fire
1338 if(e.watertype != CONTENT_LAVA)
1342 if(e.freezetag_frozen)
1345 t = min(frametime, e.fire_endtime - time);
1346 d = e.fire_damagepersec * t;
1348 hi = e.fire_owner.hitsound;
1349 ty = e.fire_owner.typehitsound;
1350 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1351 if(e.fire_hitsound && e.fire_owner)
1353 e.fire_owner.hitsound = hi;
1354 e.fire_owner.typehitsound = ty;
1356 e.fire_hitsound = TRUE;
1358 if not(IS_INDEPENDENT_PLAYER(e))
1359 FOR_EACH_PLAYER(other) if(e != other)
1361 if(other.classname == "player")
1362 if(other.deadflag == DEAD_NO)
1363 if not(IS_INDEPENDENT_PLAYER(other))
1364 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1366 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1367 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1368 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1373 void Fire_ApplyEffect(entity e)
1375 if(Fire_IsBurning(e))
1376 e.effects |= EF_FLAME;
1378 e.effects &~= EF_FLAME;
1381 void fireburner_think()
1383 // for players, this is done in the regular loop
1384 if(wasfreed(self.owner))
1389 Fire_ApplyEffect(self.owner);
1390 if(!Fire_IsBurning(self.owner))
1392 self.owner.fire_burner = world;
1396 Fire_ApplyDamage(self.owner);
1397 self.nextthink = time;