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);
20 void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, float deathtype, entity dmgowner)
22 // TODO maybe call this from non-edgedamage too?
23 // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
27 if(!sound_allowed(MSG_BROADCAST, dmgowner))
32 e.projectiledeathtype = deathtype;
34 e.dmg_edge = edgedamage;
36 e.dmg_force = vlen(force);
39 e.oldorigin_x = compressShortVector(e.velocity);
41 Net_LinkEntity(e, FALSE, 0.2, Damage_DamageInfo_SendEntity);
44 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
46 float checkrules_firstblood;
49 float damage_goodhits;
50 float damage_gooddamage;
52 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
55 .float teamkill_complain;
56 .float teamkill_soundtime;
57 .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 void GiveFrags (entity attacker, entity targ, float f)
109 // TODO route through PlayerScores instead
117 PlayerScore_Add(attacker, SP_SUICIDES, 1);
122 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
123 PlayerStats_Event(attacker, PLAYERSTATS_KILLS, -1);
129 PlayerScore_Add(attacker, SP_KILLS, 1);
130 PlayerStats_Event(attacker, PLAYERSTATS_KILLS, 1);
133 PlayerScore_Add(targ, SP_DEATHS, 1);
136 if(autocvar_g_arena_roundbased)
139 if(targ != attacker) // not for suicides
140 if(g_weaponarena_random)
142 // after a frag, choose another random weapon set
144 w = warmup_start_weapons;
148 attacker.weapons = randombits(w - (w & W_WeaponBit(attacker.weapon)), g_weaponarena_random, TRUE);
149 if(attacker.weapons < 0)
151 // error from randombits: no weapon available
152 // this means we can just give ALL weapons
153 attacker.weapons = w;
155 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
156 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
159 // FIXME fix the mess this is (we have REAL points now!)
163 frag_attacker = attacker;
166 if(MUTATOR_CALLHOOK(GiveFragsForKill))
176 f = RunematchHandleFrags(attacker, targ, f);
182 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
183 if(tl < lms_lowest_lives)
184 lms_lowest_lives = tl;
188 lms_next_place = player_count;
189 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
196 if(g_ctf_ignore_frags)
201 attacker.totalfrags += f;
204 UpdateFrags(attacker, f);
207 string AppendItemcodes(string s, entity player)
212 // w = player.switchweapon;
214 w = player.cnt; // previous weapon!
215 s = strcat(s, ftos(w));
216 if(time < player.strength_finished)
218 if(time < player.invincible_finished)
220 if(player.flagcarried != world)
222 if(player.BUTTON_CHAT)
227 s = strcat(s, "|", ftos(player.runes));
231 void LogDeath(string mode, float deathtype, entity killer, entity killed)
234 if(!autocvar_sv_eventlog)
236 s = strcat(":kill:", mode);
237 s = strcat(s, ":", ftos(killer.playerid));
238 s = strcat(s, ":", ftos(killed.playerid));
239 s = strcat(s, ":type=", ftos(deathtype));
240 s = strcat(s, ":items=");
241 s = AppendItemcodes(s, killer);
244 s = strcat(s, ":victimitems=");
245 s = AppendItemcodes(s, killed);
250 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
252 WriteByte(MSG_ALL, SVC_TEMPENTITY);
253 WriteByte(MSG_ALL, TE_CSQC_NOTIFY);
254 WriteByte(MSG_ALL, CSQC_KILLNOTIFY);
255 WriteString(MSG_ALL, s1);
256 WriteString(MSG_ALL, s2);
257 WriteString(MSG_ALL, s3);
258 WriteShort(MSG_ALL, msg);
259 WriteByte(MSG_ALL, type);
262 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
263 void Send_CSQC_Centerprint(entity e, string s1, string s2, float msg, float type)
265 if (clienttype(e) == CLIENTTYPE_REAL)
268 WRITESPECTATABLE_MSG_ONE({
269 WriteByte(MSG_ONE, SVC_TEMPENTITY);
270 WriteByte(MSG_ONE, TE_CSQC_NOTIFY);
271 WriteByte(MSG_ONE, CSQC_CENTERPRINT);
272 WriteString(MSG_ONE, s1);
273 WriteString(MSG_ONE, s2);
274 WriteShort(MSG_ONE, msg);
275 WriteByte(MSG_ONE, type);
280 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
285 if (targ.classname == "player" || targ.classname == "corpse")
287 if (targ.classname == "corpse")
292 a = attacker.netname;
294 if (targ == attacker) // suicides
296 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
297 msg = ColoredTeamName(targ.team); // TODO: check if needed?
298 if(!g_cts) // no "killed your own dumb self" message in CTS
299 Send_CSQC_Centerprint(targ, msg, "", deathtype, MSG_SUICIDE);
301 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
303 LogDeath("suicide", deathtype, targ, targ);
304 GiveFrags(attacker, targ, -1);
307 if (targ.killcount > 2)
308 msg = ftos(targ.killcount);
309 if(teams_matter && deathtype == DEATH_MIRRORDAMAGE)
311 if(attacker.team == COLOR_TEAM1)
312 deathtype = KILL_TEAM_RED;
314 deathtype = KILL_TEAM_BLUE;
317 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
319 else if (attacker.classname == "player" || attacker.classname == "gib")
321 if(teams_matter && attacker.team == targ.team)
323 if(attacker.team == COLOR_TEAM1)
324 type = KILL_TEAM_RED;
326 type = KILL_TEAM_BLUE;
328 GiveFrags(attacker, targ, -1);
330 Send_CSQC_Centerprint(attacker, s, "", type, MSG_KILL);
332 if (targ.killcount > 2) {
333 msg = ftos(targ.killcount);
336 if (attacker.killcount > 2) {
337 msg = ftos(attacker.killcount);
338 type = KILL_TEAM_SPREE;
340 Send_KillNotification(a, s, msg, type, MSG_KILL);
342 attacker.killcount = 0;
344 LogDeath("tk", deathtype, attacker, targ);
348 if (!checkrules_firstblood)
350 checkrules_firstblood = TRUE;
351 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
352 // TODO: make these print a newline if they dont
353 Send_CSQC_Centerprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
354 Send_CSQC_Centerprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
357 if((autocvar_sv_fragmessage_information_typefrag) && (targ.BUTTON_CHAT)) {
358 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_TYPEFRAG, MSG_KILL);
359 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_TYPEFRAGGED, MSG_KILL);
361 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_FRAG, MSG_KILL);
362 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_FRAGGED, MSG_KILL);
365 attacker.taunt_soundtime = time + 1;
368 if (deathtype == DEATH_CUSTOM)
371 msg = inflictor.message2;
373 if(strstrofs(msg, "%", 0) < 0)
374 msg = strcat("%s ", msg, " by %s");
376 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
378 if(g_ctf && targ.flagcarried)
380 UpdateFrags(attacker, ctf_score_value("score_kill"));
381 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
382 GiveFrags(attacker, targ, 0); // for logging
385 GiveFrags(attacker, targ, 1);
387 if (targ.killcount > 2) {
388 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
391 attacker.killcount = attacker.killcount + 1;
393 if (attacker.killcount > 2) {
394 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
396 else if (attacker.killcount == 3)
398 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
399 AnnounceTo(attacker, "03kills");
401 else if (attacker.killcount == 5)
403 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
404 AnnounceTo(attacker, "05kills");
406 else if (attacker.killcount == 10)
408 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
409 AnnounceTo(attacker, "10kills");
411 else if (attacker.killcount == 15)
413 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
414 AnnounceTo(attacker, "15kills");
416 else if (attacker.killcount == 20)
418 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
419 AnnounceTo(attacker, "20kills");
421 else if (attacker.killcount == 25)
423 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
424 AnnounceTo(attacker, "25kills");
426 else if (attacker.killcount == 30)
428 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
429 AnnounceTo(attacker, "30kills");
431 LogDeath("frag", deathtype, attacker, targ);
436 Send_CSQC_Centerprint(targ, "", "", deathtype, MSG_KILL_ACTION);
437 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
438 msg = inflictor.message;
439 else if (deathtype == DEATH_CUSTOM)
441 if(strstrofs(msg, "%", 0) < 0)
442 msg = strcat("%s ", msg);
444 GiveFrags(targ, targ, -1);
445 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
446 AnnounceTo(targ, "botlike");
448 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
450 if (targ.killcount > 2)
451 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
453 LogDeath("accident", deathtype, targ, targ);
456 targ.death_origin = targ.origin;
458 targ.killer_origin = attacker.origin;
460 // FIXME: this should go in PutClientInServer
466 // these are updated by each Damage call for use in button triggering and such
468 entity damage_inflictor;
469 entity damage_attacker;
472 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
477 entity attacker_save;
481 if (gameover || targ.killcount == -666)
484 local entity oldself;
488 damage_inflictor = inflictor;
489 damage_attacker = attacker;
490 attacker_save = attacker;
492 if(targ.classname == "player")
495 if(targ.hook.aiment == attacker)
496 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
498 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
499 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
501 if(targ.classname == "player")
502 if not(IsDifferentTeam(targ, attacker))
509 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
511 // These are ALWAYS lethal
512 // No damage modification here
513 // Instead, prepare the victim for his death...
515 targ.spawnshieldtime = 0;
516 targ.health = 0.9; // this is < 1
517 targ.flags -= targ.flags & FL_GODMODE;
520 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
526 if (targ.classname == "player")
527 if (attacker.classname == "player")
530 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
532 // nullify damage if teamplay is on
533 if(deathtype != DEATH_TELEFRAG)
534 if(attacker.classname == "player")
536 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
541 else if(teams_matter && attacker.team == targ.team)
543 if(autocvar_teamplay_mode == 1)
545 else if(attacker != targ)
547 if(autocvar_teamplay_mode == 3)
549 else if(autocvar_teamplay_mode == 4)
551 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
553 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
554 attacker.dmg_team = attacker.dmg_team + damage;
555 if(attacker.dmg_team > teamdamage0 && !g_ca)
556 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
557 mirrorforce = autocvar_g_mirrordamage * vlen(force);
560 if(autocvar_g_friendlyfire == 0)
566 damage = autocvar_g_friendlyfire * damage;
567 // mirrordamage will be used LATER
576 if(targ.classname == "player")
577 if(attacker.classname == "player")
580 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
581 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
584 if(targ.classname == "player")
587 if ((deathtype == DEATH_FALL) ||
588 (deathtype == DEATH_DROWN) ||
589 (deathtype == DEATH_SLIME) ||
590 (deathtype == DEATH_LAVA) ||
591 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
598 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
600 targ.armorvalue -= 1;
601 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
604 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
606 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
609 if (targ != attacker)
611 if ((targ.health >= 1) && (targ.classname == "player"))
612 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
622 if not(DEATH_ISSPECIAL(deathtype))
624 damage *= g_weapondamagefactor;
625 mirrordamage *= g_weapondamagefactor;
626 force = force * g_weaponforcefactor;
627 mirrorforce *= g_weaponforcefactor;
630 // should this be changed at all? If so, in what way?
631 frag_attacker = attacker;
633 frag_damage = damage;
635 frag_deathtype = deathtype;
636 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
637 damage = frag_damage;
640 // apply strength multiplier
641 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
645 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
646 force = force * autocvar_g_balance_powerup_strength_selfforce;
650 damage = damage * autocvar_g_balance_powerup_strength_damage;
651 force = force * autocvar_g_balance_powerup_strength_force;
655 // apply invincibility multiplier
656 if (targ.items & IT_INVINCIBLE && !g_minstagib)
657 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
659 if (targ == attacker)
661 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
664 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
667 // CTF: reduce damage/force
672 damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
673 force = force * autocvar_g_ctf_flagcarrier_selfforce;
678 // apply strength rune
679 if (attacker.runes & RUNE_STRENGTH)
681 if(attacker.runes & CURSE_WEAK) // have both curse & rune
683 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
684 force = force * autocvar_g_balance_rune_strength_combo_force;
688 damage = damage * autocvar_g_balance_rune_strength_damage;
689 force = force * autocvar_g_balance_rune_strength_force;
692 else if (attacker.runes & CURSE_WEAK)
694 damage = damage * autocvar_g_balance_curse_weak_damage;
695 force = force * autocvar_g_balance_curse_weak_force;
698 // apply defense rune
699 if (targ.runes & RUNE_DEFENSE)
701 if (targ.runes & CURSE_VULNER) // have both curse & rune
702 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
704 damage = damage * autocvar_g_balance_rune_defense_takedamage;
706 else if (targ.runes & CURSE_VULNER)
707 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
713 if(targ.takedamage == DAMAGE_AIM)
716 if(targ.classname == "player")
719 // find height of hit on player axis
720 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
721 vector headmins, headmaxs, org;
722 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
723 headmins = org + GetHeadshotMins(targ);
724 headmaxs = org + GetHeadshotMaxs(targ);
725 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
727 deathtype |= HITTYPE_HEADSHOT;
730 else if(targ.classname == "turret_head")
732 deathtype |= HITTYPE_HEADSHOT;
734 if(deathtype & HITTYPE_HEADSHOT)
735 damage *= 1 + damage_headshotbonus;
737 if(targ.classname == "player")
739 if(IsDifferentTeam(targ, attacker))
743 if(attacker.weapon != WEP_ELECTRO && attacker.weapon != WEP_LASER || ((attacker.weapon == WEP_ELECTRO && autocvar_g_balance_electro_lightning || attacker.weapon == WEP_LASER) && attacker.prevhitsound + autocvar_sv_hitsound_antispam_time < time))
746 attacker.typehitsound += 1;
748 attacker.hitsound += 1;
749 attacker.prevhitsound = time;
752 damage_goodhits += 1;
753 damage_gooddamage += damage;
755 if not(DEATH_ISSPECIAL(deathtype))
762 if(targ.items & IT_STRENGTH)
765 if(deathtype & HITTYPE_HEADSHOT)
769 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
774 if(deathtype != DEATH_FIRE)
775 attacker.typehitsound += 1;
777 if(time > attacker.teamkill_complain)
779 attacker.teamkill_complain = time + 5;
780 attacker.teamkill_soundtime = time + 0.4;
781 attacker.teamkill_soundsource = targ;
789 if (self.damageforcescale)
791 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
793 self.velocity = self.velocity + self.damageforcescale * force;
794 self.flags &~= FL_ONGROUND;
795 UpdateCSQCProjectile(self);
798 if (damage != 0 || (self.damageforcescale && vlen(force)))
799 if (self.event_damage)
800 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
803 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
807 if (attacker.runes & RUNE_VAMPIRE)
809 // apply vampire rune
810 if (attacker.runes & CURSE_EMPATHY) // have the curse too
812 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
813 attacker.health = bound(
814 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
815 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
816 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
820 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
821 attacker.health = bound(
822 attacker.health, // LA: was 3, but changed so that you can't lose health
823 // empathy won't let you gain health in the same way...
824 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
825 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
828 // apply empathy curse
829 else if (attacker.runes & CURSE_EMPATHY)
831 attacker.health = bound(
832 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
833 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
839 // apply mirror damage if any
840 if(mirrordamage > 0 || mirrorforce > 0)
842 attacker = attacker_save;
846 // just lose extra LIVES, don't kill the player for mirror damage
847 if(attacker.armorvalue > 0)
849 attacker.armorvalue = attacker.armorvalue - 1;
850 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
851 attacker.hitsound += 1;
855 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
856 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
860 float RadiusDamage_running;
861 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
862 // Returns total damage applies to creatures
872 float total_damage_to_creatures;
877 float stat_damagedone;
879 if(RadiusDamage_running)
881 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
885 RadiusDamage_running = 1;
887 tfloordmg = autocvar_g_throughfloor_damage;
888 tfloorforce = autocvar_g_throughfloor_force;
890 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
891 total_damage_to_creatures = 0;
893 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
894 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
896 force = inflictor.velocity;
900 force = normalize(force);
901 if(forceintensity >= 0)
902 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
904 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
909 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
913 if (targ != inflictor)
914 if (ignore != targ) if(targ.takedamage)
916 // LordHavoc: measure distance to nearest point on target (not origin)
917 // (this guarentees 100% damage on a touch impact)
918 nearest = targ.WarpZone_findradius_nearest;
919 diff = targ.WarpZone_findradius_dist;
920 // round up a little on the damage to ensure full damage on impacts
921 // and turn the distance into a fraction of the radius
922 power = 1 - ((vlen (diff) - 2) / rad);
924 //bprint(ftos(power));
925 //if (targ == attacker)
926 // print(ftos(power), "\n");
931 finaldmg = coredamage * power + edgedamage * (1 - power);
938 local float hitratio;
940 local vector myblastorigin;
941 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
942 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
943 // if it's a player, use the view origin as reference
944 if (targ.classname == "player")
945 center = targ.origin + targ.view_ofs;
946 force = normalize(center - myblastorigin);
947 force = force * (finaldmg / coredamage) * forceintensity;
948 // test line of sight to multiple positions on box,
949 // and do damage if any of them hit
951 if (targ.classname == "player")
952 total = ceil(bound(1, finaldmg, 50));
954 total = ceil(bound(1, finaldmg/10, 5));
959 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
960 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
961 if (trace_fraction == 1 || trace_ent == targ)
965 hitloc = hitloc + nearest;
969 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
970 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
971 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
974 nearest = hitloc * (1 / max(1, hits));
975 hitratio = (hits / total);
976 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
977 finaldmg = finaldmg * a;
978 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
981 // laser force adjustments :P
982 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
987 float force_velocitybiasramp;
988 float force_velocitybias;
990 force_velocitybiasramp = autocvar_sv_maxspeed;
991 if(deathtype & HITTYPE_SECONDARY)
993 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
994 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
998 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
999 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1002 vel = targ.velocity;
1004 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1008 normalize(normalize(force) + vel);
1010 force_z *= force_zscale;
1013 //if (targ == attacker)
1015 // print("hits ", ftos(hits), " / ", ftos(total));
1016 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1017 // print(" (", ftos(a), ")\n");
1019 if(hits || tfloordmg || tfloorforce)
1023 total_damage_to_creatures += finaldmg;
1025 if(accuracy_isgooddamage(attacker, targ))
1026 stat_damagedone += finaldmg;
1029 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1030 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1032 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1040 RadiusDamage_running = 0;
1042 if(!DEATH_ISSPECIAL(deathtype))
1043 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1045 return total_damage_to_creatures;
1048 .float fire_damagepersec;
1049 .float fire_endtime;
1050 .float fire_deathtype;
1052 .float fire_hitsound;
1053 .entity fire_burner;
1055 void fireburner_think();
1057 float Fire_IsBurning(entity e)
1059 return (time < e.fire_endtime);
1062 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1065 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1067 if(e.classname == "player")
1076 // print("adding a fire burner to ", e.classname, "\n");
1077 e.fire_burner = spawn();
1078 e.fire_burner.classname = "fireburner";
1079 e.fire_burner.think = fireburner_think;
1080 e.fire_burner.nextthink = time;
1081 e.fire_burner.owner = e;
1087 if(Fire_IsBurning(e))
1089 mintime = e.fire_endtime - time;
1090 maxtime = max(mintime, t);
1092 mindps = e.fire_damagepersec;
1093 maxdps = max(mindps, dps);
1095 if(maxtime > mintime || maxdps > mindps)
1097 mindamage = mindps * mintime;
1098 maxdamage = mindamage + d;
1100 // interval [mintime, maxtime] * [mindps, maxdps]
1102 // [mindamage, maxdamage]
1105 if(maxdamage >= maxtime * maxdps)
1107 totaltime = maxtime;
1108 totaldamage = maxtime * maxdps;
1110 // this branch increases totaldamage if either t > mintime, or dps > mindps
1114 // maxdamage is inside the interval!
1115 // first, try to use mindps; only if this fails, increase dps as needed
1116 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1117 totaldamage = maxdamage;
1118 // can totaldamage / totaltime be >= maxdps?
1119 // max(mindps, maxdamage / maxtime) >= maxdps?
1120 // we know maxdamage < maxtime * maxdps
1123 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1126 // total conditions for increasing:
1127 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1129 // if maxtime = mintime, maxdps = mindps
1131 // maxdamage = mindamage + d
1132 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1133 // so the last condition is not needed
1135 e.fire_damagepersec = totaldamage / totaltime;
1136 e.fire_endtime = time + totaltime;
1137 if(totaldamage > 1.2 * mindamage)
1139 e.fire_deathtype = dt;
1140 if(e.fire_owner != o)
1143 e.fire_hitsound = FALSE;
1146 if(accuracy_isgooddamage(o, e))
1147 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1148 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1155 e.fire_damagepersec = dps;
1156 e.fire_endtime = time + t;
1157 e.fire_deathtype = dt;
1159 e.fire_hitsound = FALSE;
1160 if(accuracy_isgooddamage(o, e))
1161 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1166 void Fire_ApplyDamage(entity e)
1171 if not(Fire_IsBurning(e))
1174 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1175 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1178 // water and slime stop fire
1180 if(e.watertype != CONTENT_LAVA)
1183 t = min(frametime, e.fire_endtime - time);
1184 d = e.fire_damagepersec * t;
1186 hi = e.fire_owner.hitsound;
1187 ty = e.fire_owner.typehitsound;
1188 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1189 if(e.fire_hitsound && e.fire_owner)
1191 e.fire_owner.hitsound = hi;
1192 e.fire_owner.typehitsound = ty;
1194 e.fire_hitsound = TRUE;
1196 if not(IS_INDEPENDENT_PLAYER(e))
1197 FOR_EACH_PLAYER(other) if(e != other)
1199 if(other.classname == "player")
1200 if(other.deadflag == DEAD_NO)
1201 if not(IS_INDEPENDENT_PLAYER(other))
1202 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1204 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1205 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1206 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1211 void Fire_ApplyEffect(entity e)
1213 if(Fire_IsBurning(e))
1214 e.effects |= EF_FLAME;
1216 e.effects &~= EF_FLAME;
1219 void fireburner_think()
1221 // for players, this is done in the regular loop
1222 if(wasfreed(self.owner))
1227 Fire_ApplyEffect(self.owner);
1228 if(!Fire_IsBurning(self.owner))
1230 self.owner.fire_burner = world;
1234 Fire_ApplyDamage(self.owner);
1235 self.nextthink = time;