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(cvar("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(!cvar("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 Send_CSQC_Centerprint(targ, msg, "", deathtype, MSG_SUICIDE);
300 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
302 LogDeath("suicide", deathtype, targ, targ);
303 GiveFrags(attacker, targ, -1);
306 if (targ.killcount > 2)
307 msg = ftos(targ.killcount);
308 if(teams_matter && deathtype == DEATH_MIRRORDAMAGE)
310 if(attacker.team == COLOR_TEAM1)
311 deathtype = KILL_TEAM_RED;
313 deathtype = KILL_TEAM_BLUE;
316 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
318 else if (attacker.classname == "player" || attacker.classname == "gib")
320 if(teams_matter && attacker.team == targ.team)
322 if(attacker.team == COLOR_TEAM1)
323 type = KILL_TEAM_RED;
325 type = KILL_TEAM_BLUE;
327 GiveFrags(attacker, targ, -1);
329 Send_CSQC_Centerprint(attacker, s, "", type, MSG_KILL);
331 if (targ.killcount > 2) {
332 msg = ftos(targ.killcount);
335 if (attacker.killcount > 2) {
336 msg = ftos(attacker.killcount);
337 type = KILL_TEAM_SPREE;
339 Send_KillNotification(a, s, msg, type, MSG_KILL);
341 attacker.killcount = 0;
343 LogDeath("tk", deathtype, attacker, targ);
347 if (!checkrules_firstblood)
349 checkrules_firstblood = TRUE;
350 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
351 // TODO: make these print a newline if they dont
352 Send_CSQC_Centerprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
353 Send_CSQC_Centerprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
356 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
357 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_TYPEFRAG, MSG_KILL);
358 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_TYPEFRAGGED, MSG_KILL);
360 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_FRAG, MSG_KILL);
361 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_FRAGGED, MSG_KILL);
364 attacker.taunt_soundtime = time + 1;
367 if (deathtype == DEATH_CUSTOM)
370 msg = inflictor.message2;
372 if(strstrofs(msg, "%", 0) < 0)
373 msg = strcat("%s ", msg, " by %s");
375 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
377 if(g_ctf && targ.flagcarried)
379 UpdateFrags(attacker, ctf_score_value("score_kill"));
380 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
381 GiveFrags(attacker, targ, 0); // for logging
384 GiveFrags(attacker, targ, 1);
386 if (targ.killcount > 2) {
387 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
390 attacker.killcount = attacker.killcount + 1;
392 if (attacker.killcount > 2) {
393 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
395 else if (attacker.killcount == 3)
397 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
398 AnnounceTo(attacker, "03kills");
400 else if (attacker.killcount == 5)
402 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
403 AnnounceTo(attacker, "05kills");
405 else if (attacker.killcount == 10)
407 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
408 AnnounceTo(attacker, "10kills");
410 else if (attacker.killcount == 15)
412 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
413 AnnounceTo(attacker, "15kills");
415 else if (attacker.killcount == 20)
417 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
418 AnnounceTo(attacker, "20kills");
420 else if (attacker.killcount == 25)
422 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
423 AnnounceTo(attacker, "25kills");
425 else if (attacker.killcount == 30)
427 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
428 AnnounceTo(attacker, "30kills");
430 LogDeath("frag", deathtype, attacker, targ);
435 Send_CSQC_Centerprint(targ, "", "", deathtype, MSG_KILL_ACTION);
436 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
437 msg = inflictor.message;
438 else if (deathtype == DEATH_CUSTOM)
440 if(strstrofs(msg, "%", 0) < 0)
441 msg = strcat("%s ", msg);
443 GiveFrags(targ, targ, -1);
444 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
445 AnnounceTo(targ, "botlike");
447 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
449 if (targ.killcount > 2)
450 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
452 LogDeath("accident", deathtype, targ, targ);
455 targ.death_origin = targ.origin;
457 targ.killer_origin = attacker.origin;
459 // FIXME: this should go in PutClientInServer
465 // these are updated by each Damage call for use in button triggering and such
467 entity damage_inflictor;
468 entity damage_attacker;
471 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
476 entity attacker_save;
480 if (gameover || targ.killcount == -666)
483 local entity oldself;
487 damage_inflictor = inflictor;
488 damage_attacker = attacker;
489 attacker_save = attacker;
491 if(targ.classname == "player")
494 if(targ.hook.aiment == attacker)
495 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
497 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
498 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
500 if(targ.classname == "player")
501 if not(IsDifferentTeam(targ, attacker))
508 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
510 // These are ALWAYS lethal
511 // No damage modification here
512 // Instead, prepare the victim for his death...
514 targ.spawnshieldtime = 0;
515 targ.health = 0.9; // this is < 1
516 targ.flags -= targ.flags & FL_GODMODE;
519 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
525 if (targ.classname == "player")
526 if (attacker.classname == "player")
529 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
531 // nullify damage if teamplay is on
532 if(deathtype != DEATH_TELEFRAG)
533 if(attacker.classname == "player")
535 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
540 else if(attacker.team == targ.team)
544 else if(attacker != targ)
548 else if(teamplay == 4)
550 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
552 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
553 attacker.dmg_team = attacker.dmg_team + damage;
554 if(attacker.dmg_team > teamdamage0 && !g_ca)
555 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
556 mirrorforce = cvar("g_mirrordamage") * vlen(force);
559 if(cvar("g_friendlyfire") == 0)
565 damage = cvar("g_friendlyfire") * damage;
566 // mirrordamage will be used LATER
575 if(targ.classname == "player")
576 if(attacker.classname == "player")
579 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
580 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
583 if(targ.classname == "player")
586 if ((deathtype == DEATH_FALL) ||
587 (deathtype == DEATH_DROWN) ||
588 (deathtype == DEATH_SLIME) ||
589 (deathtype == DEATH_LAVA) ||
590 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
597 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
599 targ.armorvalue -= 1;
600 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
603 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
605 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
608 if (targ != attacker)
610 if ((targ.health >= 1) && (targ.classname == "player"))
611 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
621 if not(DEATH_ISSPECIAL(deathtype))
623 damage *= g_weapondamagefactor;
624 mirrordamage *= g_weapondamagefactor;
625 force = force * g_weaponforcefactor;
626 mirrorforce *= g_weaponforcefactor;
629 // apply strength multiplier
630 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
634 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
635 force = force * cvar("g_balance_powerup_strength_selfforce");
639 damage = damage * cvar("g_balance_powerup_strength_damage");
640 force = force * cvar("g_balance_powerup_strength_force");
644 // apply invincibility multiplier
645 if (targ.items & IT_INVINCIBLE && !g_minstagib)
646 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
648 if (targ == attacker)
650 if(g_ca || (g_cts && !cvar("g_cts_selfdamage")))
653 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
656 // CTF: reduce damage/force
661 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
662 force = force * cvar("g_ctf_flagcarrier_selfforce");
667 // apply strength rune
668 if (attacker.runes & RUNE_STRENGTH)
670 if(attacker.runes & CURSE_WEAK) // have both curse & rune
672 damage = damage * cvar("g_balance_rune_strength_combo_damage");
673 force = force * cvar("g_balance_rune_strength_combo_force");
677 damage = damage * cvar("g_balance_rune_strength_damage");
678 force = force * cvar("g_balance_rune_strength_force");
681 else if (attacker.runes & CURSE_WEAK)
683 damage = damage * cvar("g_balance_curse_weak_damage");
684 force = force * cvar("g_balance_curse_weak_force");
687 // apply defense rune
688 if (targ.runes & RUNE_DEFENSE)
690 if (targ.runes & CURSE_VULNER) // have both curse & rune
691 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
693 damage = damage * cvar("g_balance_rune_defense_takedamage");
695 else if (targ.runes & CURSE_VULNER)
696 damage = damage * cvar("g_balance_curse_vulner_takedamage");
702 if(targ.takedamage == DAMAGE_AIM)
705 if(targ.classname == "player")
708 // find height of hit on player axis
709 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
710 vector headmins, headmaxs, org;
711 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
712 headmins = org + GetHeadshotMins(targ);
713 headmaxs = org + GetHeadshotMaxs(targ);
714 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
716 deathtype |= HITTYPE_HEADSHOT;
719 else if(targ.classname == "turret_head")
721 deathtype |= HITTYPE_HEADSHOT;
723 if(deathtype & HITTYPE_HEADSHOT)
724 damage *= 1 + damage_headshotbonus;
726 if(targ.classname == "player")
728 if(IsDifferentTeam(targ, attacker))
732 if(attacker.weapon != WEP_ELECTRO && attacker.weapon != WEP_LASER || ((attacker.weapon == WEP_ELECTRO && cvar("g_balance_electro_lightning") || attacker.weapon == WEP_LASER) && attacker.prevhitsound + cvar("sv_hitsound_antispam_time") < time))
735 attacker.typehitsound += 1;
737 attacker.hitsound += 1;
738 attacker.prevhitsound = time;
741 damage_goodhits += 1;
742 damage_gooddamage += damage;
744 if not(DEATH_ISSPECIAL(deathtype))
751 if(targ.items & IT_STRENGTH)
754 if(deathtype & HITTYPE_HEADSHOT)
758 PlayerScore_Add(attacker, SP_SCORE, damage * cvar("g_ca_damage2score_multiplier"));
763 if(deathtype != DEATH_FIRE)
764 attacker.typehitsound += 1;
766 if(time > attacker.teamkill_complain)
768 attacker.teamkill_complain = time + 5;
769 attacker.teamkill_soundtime = time + 0.4;
770 attacker.teamkill_soundsource = targ;
778 if (self.damageforcescale)
780 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
782 self.velocity = self.velocity + self.damageforcescale * force;
783 self.flags &~= FL_ONGROUND;
784 UpdateCSQCProjectile(self);
787 if (damage != 0 || (self.damageforcescale && vlen(force)))
788 if (self.event_damage)
789 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
792 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
796 if (attacker.runes & RUNE_VAMPIRE)
798 // apply vampire rune
799 if (attacker.runes & CURSE_EMPATHY) // have the curse too
801 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
802 attacker.health = bound(
803 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
804 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
805 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
809 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
810 attacker.health = bound(
811 attacker.health, // LA: was 3, but changed so that you can't lose health
812 // empathy won't let you gain health in the same way...
813 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
814 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
817 // apply empathy curse
818 else if (attacker.runes & CURSE_EMPATHY)
820 attacker.health = bound(
821 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
822 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
828 // apply mirror damage if any
829 if(mirrordamage > 0 || mirrorforce > 0)
831 attacker = attacker_save;
835 // just lose extra LIVES, don't kill the player for mirror damage
836 if(attacker.armorvalue > 0)
838 attacker.armorvalue = attacker.armorvalue - 1;
839 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
840 attacker.hitsound += 1;
844 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
845 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
849 float RadiusDamage_running;
850 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
851 // Returns total damage applies to creatures
861 float total_damage_to_creatures;
866 float stat_damagedone;
868 if(RadiusDamage_running)
871 print("RadiusDamage called recursively!\n");
872 print("Expect stuff to go HORRIBLY wrong.\n");
873 print("Causing a stack trace...\n");
874 save = cvar_string("prvm_backtraceforwarnings");
875 cvar_set("prvm_backtraceforwarnings", "1");
876 fclose(-1); // calls VM_Warning
877 cvar_set("prvm_backtraceforwarnings", save);
881 RadiusDamage_running = 1;
883 tfloordmg = cvar("g_throughfloor_damage");
884 tfloorforce = cvar("g_throughfloor_force");
886 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
887 total_damage_to_creatures = 0;
889 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
890 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
892 force = inflictor.velocity;
896 force = normalize(force);
897 if(forceintensity >= 0)
898 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
900 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
905 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
909 if (targ != inflictor)
910 if (ignore != targ) if(targ.takedamage)
912 // LordHavoc: measure distance to nearest point on target (not origin)
913 // (this guarentees 100% damage on a touch impact)
914 nearest = targ.WarpZone_findradius_nearest;
915 diff = targ.WarpZone_findradius_dist;
916 // round up a little on the damage to ensure full damage on impacts
917 // and turn the distance into a fraction of the radius
918 power = 1 - ((vlen (diff) - 2) / rad);
920 //bprint(ftos(power));
921 //if (targ == attacker)
922 // print(ftos(power), "\n");
927 finaldmg = coredamage * power + edgedamage * (1 - power);
934 local float hitratio;
936 local vector myblastorigin;
937 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
938 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
939 // if it's a player, use the view origin as reference
940 if (targ.classname == "player")
941 center = targ.origin + targ.view_ofs;
942 force = normalize(center - myblastorigin);
943 force = force * (finaldmg / coredamage) * forceintensity;
944 // test line of sight to multiple positions on box,
945 // and do damage if any of them hit
947 if (targ.classname == "player")
948 total = ceil(bound(1, finaldmg, 50));
950 total = ceil(bound(1, finaldmg/10, 5));
955 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
956 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
957 if (trace_fraction == 1 || trace_ent == targ)
961 hitloc = hitloc + nearest;
965 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
966 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
967 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
970 nearest = hitloc * (1 / max(1, hits));
971 hitratio = (hits / total);
972 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
973 finaldmg = finaldmg * a;
974 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
977 // laser force adjustments :P
978 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
983 float force_velocitybiasramp;
984 float force_velocitybias;
986 force_velocitybiasramp = cvar("sv_maxspeed");
987 if(deathtype & HITTYPE_SECONDARY)
989 force_zscale = cvar("g_balance_laser_secondary_force_zscale");
990 force_velocitybias = cvar("g_balance_laser_secondary_force_velocitybias");
994 force_zscale = cvar("g_balance_laser_primary_force_zscale");
995 force_velocitybias = cvar("g_balance_laser_primary_force_velocitybias");
1000 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1004 normalize(normalize(force) + vel);
1006 force_z *= force_zscale;
1009 //if (targ == attacker)
1011 // print("hits ", ftos(hits), " / ", ftos(total));
1012 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1013 // print(" (", ftos(a), ")\n");
1015 if(hits || tfloordmg || tfloorforce)
1019 total_damage_to_creatures += finaldmg;
1021 if(accuracy_isgooddamage(attacker, targ))
1022 stat_damagedone += finaldmg;
1025 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1026 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1028 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1036 RadiusDamage_running = 0;
1038 if(!DEATH_ISSPECIAL(deathtype))
1039 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1041 return total_damage_to_creatures;
1044 .float fire_damagepersec;
1045 .float fire_endtime;
1046 .float fire_deathtype;
1048 .float fire_hitsound;
1049 .entity fire_burner;
1051 void fireburner_think();
1053 float Fire_IsBurning(entity e)
1055 return (time < e.fire_endtime);
1058 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1061 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1063 if(e.classname == "player")
1072 // print("adding a fire burner to ", e.classname, "\n");
1073 e.fire_burner = spawn();
1074 e.fire_burner.classname = "fireburner";
1075 e.fire_burner.think = fireburner_think;
1076 e.fire_burner.nextthink = time;
1077 e.fire_burner.owner = e;
1083 if(Fire_IsBurning(e))
1085 mintime = e.fire_endtime - time;
1086 maxtime = max(mintime, t);
1088 mindps = e.fire_damagepersec;
1089 maxdps = max(mindps, dps);
1091 if(maxtime > mintime || maxdps > mindps)
1093 mindamage = mindps * mintime;
1094 maxdamage = mindamage + d;
1096 // interval [mintime, maxtime] * [mindps, maxdps]
1098 // [mindamage, maxdamage]
1101 if(maxdamage >= maxtime * maxdps)
1103 totaltime = maxtime;
1104 totaldamage = maxtime * maxdps;
1106 // this branch increases totaldamage if either t > mintime, or dps > mindps
1110 // maxdamage is inside the interval!
1111 // first, try to use mindps; only if this fails, increase dps as needed
1112 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1113 totaldamage = maxdamage;
1114 // can totaldamage / totaltime be >= maxdps?
1115 // max(mindps, maxdamage / maxtime) >= maxdps?
1116 // we know maxdamage < maxtime * maxdps
1119 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1122 // total conditions for increasing:
1123 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1125 // if maxtime = mintime, maxdps = mindps
1127 // maxdamage = mindamage + d
1128 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1129 // so the last condition is not needed
1131 e.fire_damagepersec = totaldamage / totaltime;
1132 e.fire_endtime = time + totaltime;
1133 if(totaldamage > 1.2 * mindamage)
1135 e.fire_deathtype = dt;
1136 if(e.fire_owner != o)
1139 e.fire_hitsound = FALSE;
1142 if(accuracy_isgooddamage(o, e))
1143 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1144 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1151 e.fire_damagepersec = dps;
1152 e.fire_endtime = time + t;
1153 e.fire_deathtype = dt;
1155 e.fire_hitsound = FALSE;
1156 if(accuracy_isgooddamage(o, e))
1157 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1162 void Fire_ApplyDamage(entity e)
1167 if not(Fire_IsBurning(e))
1170 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1171 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1174 // water and slime stop fire
1176 if(e.watertype != CONTENT_LAVA)
1179 t = min(frametime, e.fire_endtime - time);
1180 d = e.fire_damagepersec * t;
1182 hi = e.fire_owner.hitsound;
1183 ty = e.fire_owner.typehitsound;
1184 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1185 if(e.fire_hitsound && e.fire_owner)
1187 e.fire_owner.hitsound = hi;
1188 e.fire_owner.typehitsound = ty;
1190 e.fire_hitsound = TRUE;
1192 if not(IS_INDEPENDENT_PLAYER(e))
1193 FOR_EACH_PLAYER(other) if(e != other)
1195 if(other.classname == "player")
1196 if(other.deadflag == DEAD_NO)
1197 if not(IS_INDEPENDENT_PLAYER(other))
1198 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1200 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1201 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1202 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1207 void Fire_ApplyEffect(entity e)
1209 if(Fire_IsBurning(e))
1210 e.effects |= EF_FLAME;
1212 e.effects &~= EF_FLAME;
1215 void fireburner_think()
1217 // for players, this is done in the regular loop
1218 if(wasfreed(self.owner))
1223 Fire_ApplyEffect(self.owner);
1224 if(!Fire_IsBurning(self.owner))
1226 self.owner.fire_burner = world;
1230 Fire_ApplyDamage(self.owner);
1231 self.nextthink = time;