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.6 0 0' * targ.mins_x + '0 0.6 0' * targ.mins_y + '0 0 1' * (1.3 * targ.view_ofs_z - 0.3 * targ.maxs_z);
93 vector GetHeadshotMaxs(entity targ)
95 return '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_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?
128 PlayerScore_Add(attacker, SP_KILLS, 1);
131 PlayerScore_Add(targ, SP_DEATHS, 1);
134 if(cvar("g_arena_roundbased"))
137 if(targ != attacker) // not for suicides
138 if(g_weaponarena_random)
140 // after a frag, choose another random weapon set
142 w = warmup_start_weapons;
146 attacker.weapons = randombits(w - (w & W_WeaponBit(attacker.weapon)), g_weaponarena_random, TRUE);
147 if(attacker.weapons < 0)
149 // error from randombits: no weapon available
150 // this means we can just give ALL weapons
151 attacker.weapons = w;
153 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
154 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
157 // FIXME fix the mess this is (we have REAL points now!)
161 frag_attacker = attacker;
164 if(MUTATOR_CALLHOOK(GiveFragsForKill))
174 f = RunematchHandleFrags(attacker, targ, f);
180 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
181 if(tl < lms_lowest_lives)
182 lms_lowest_lives = tl;
186 lms_next_place = player_count;
187 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
194 if(g_ctf_ignore_frags)
199 attacker.totalfrags += f;
202 UpdateFrags(attacker, f);
205 string AppendItemcodes(string s, entity player)
210 // w = player.switchweapon;
212 w = player.cnt; // previous weapon!
213 s = strcat(s, ftos(w));
214 if(time < player.strength_finished)
216 if(time < player.invincible_finished)
218 if(player.flagcarried != world)
220 if(player.BUTTON_CHAT)
225 s = strcat(s, "|", ftos(player.runes));
229 void LogDeath(string mode, float deathtype, entity killer, entity killed)
232 if(!cvar("sv_eventlog"))
234 s = strcat(":kill:", mode);
235 s = strcat(s, ":", ftos(killer.playerid));
236 s = strcat(s, ":", ftos(killed.playerid));
237 s = strcat(s, ":type=", ftos(deathtype));
238 s = strcat(s, ":items=");
239 s = AppendItemcodes(s, killer);
242 s = strcat(s, ":victimitems=");
243 s = AppendItemcodes(s, killed);
248 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
250 WriteByte(MSG_ALL, SVC_TEMPENTITY);
251 WriteByte(MSG_ALL, TE_CSQC_NOTIFY);
252 WriteByte(MSG_ALL, CSQC_KILLNOTIFY);
253 WriteString(MSG_ALL, s1);
254 WriteString(MSG_ALL, s2);
255 WriteString(MSG_ALL, s3);
256 WriteShort(MSG_ALL, msg);
257 WriteByte(MSG_ALL, type);
260 // TODO: writespectatable?
261 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
262 void Send_CSQC_Centerprint(entity e, string s1, float msg, float type)
264 if (clienttype(e) == CLIENTTYPE_REAL)
267 WriteByte(MSG_ONE, SVC_TEMPENTITY);
268 WriteByte(MSG_ONE, TE_CSQC_NOTIFY);
269 WriteByte(MSG_ONE, CSQC_CENTERPRINT);
270 WriteString(MSG_ONE, s1);
271 WriteShort(MSG_ONE, msg);
272 WriteByte(MSG_ONE, type);
276 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
281 if (targ.classname == "player" || targ.classname == "corpse")
283 if (targ.classname == "corpse")
288 a = attacker.netname;
290 if (targ == attacker) // suicides
292 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
293 msg = ColoredTeamName(targ.team); // TODO: check if needed?
294 Send_CSQC_Centerprint(targ, msg, deathtype, MSG_SUICIDE);
296 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
298 LogDeath("suicide", deathtype, targ, targ);
299 GiveFrags(attacker, targ, -1);
303 if (targ.killcount > 2)
304 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
307 // TODO: wut is this?
308 // givefrags for logging apparently?
309 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
311 LogDeath("suicide", deathtype, targ, targ);
312 GiveFrags(attacker, targ, -1);
315 if (targ.killcount > 2)
316 msg = ftos(targ.killcount);
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)
325 GiveFrags(attacker, targ, -1);
327 if (targ.killcount > 2) {
328 msg = ftos(targ.killcount);
331 if (attacker.killcount > 2) {
332 msg = ftos(attacker.killcount);
333 type = KILL_TEAM_SPREE;
336 attacker.killcount = 0;
338 LogDeath("tk", deathtype, attacker, targ);
339 Send_CSQC_Centerprint(attacker, s, type, MSG_KILL);
340 Send_KillNotification(a, msg, "", type, MSG_KILL);
344 string blood_message, victim_message;
345 if (!checkrules_firstblood)
347 checkrules_firstblood = TRUE;
348 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
349 // TODO: make these print at newline if they dont
350 Send_CSQC_Centerprint(attacker, "", KILL_FIRST_BLOOD, MSG_KILL);
351 Send_CSQC_Centerprint(targ, "", KILL_FIRST_VICTIM, MSG_KILL);
354 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
355 Send_CSQC_Centerprint(attacker, s, KILL_TYPEFRAG, MSG_KILL);
356 Send_CSQC_Centerprint(targ, a, KILL_TYPEFRAGGED, MSG_KILL);
358 Send_CSQC_Centerprint(attacker, s, KILL_FRAG, MSG_KILL);
359 Send_CSQC_Centerprint(targ, a, KILL_FRAGGED, MSG_KILL);
361 attacker.taunt_soundtime = time + 1;
364 if (deathtype == DEATH_CUSTOM)
365 msg = strcat(deathmessage, " by ^1", msg);
366 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
368 msg = ftos(strstrofs(inflictor.message2, "#", 0));
370 Send_KillNotification(s, a, msg, deathtype, MSG_KILL);
372 if(g_ctf && targ.flagcarried)
374 UpdateFrags(attacker, ctf_score_value("score_kill"));
375 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
376 GiveFrags(attacker, targ, 0); // for logging
379 GiveFrags(attacker, targ, 1);
381 if (targ.killcount > 2) {
382 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
385 attacker.killcount = attacker.killcount + 1;
387 if (attacker.killcount > 2) {
388 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
391 LogDeath("frag", deathtype, attacker, targ);
393 if (attacker.killcount == 3)
395 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
396 AnnounceTo(attacker, "03kills");
398 else if (attacker.killcount == 5)
400 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
401 AnnounceTo(attacker, "05kills");
403 else if (attacker.killcount == 10)
405 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
406 AnnounceTo(attacker, "10kills");
408 else if (attacker.killcount == 15)
410 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
411 AnnounceTo(attacker, "15kills");
413 else if (attacker.killcount == 20)
415 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
416 AnnounceTo(attacker, "20kills");
418 else if (attacker.killcount == 25)
420 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
421 AnnounceTo(attacker, "25kills");
423 else if (attacker.killcount == 30)
425 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
426 AnnounceTo(attacker, "30kills");
432 Send_CSQC_Centerprint(targ, "", deathtype, MSG_KILL_ACTION);
433 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
434 msg = inflictor.message;
435 else if (deathtype == DEATH_CUSTOM)
438 GiveFrags(targ, targ, -1);
439 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
440 AnnounceTo(targ, "botlike");
442 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
444 if (targ.killcount > 2)
445 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
447 LogDeath("accident", deathtype, targ, targ);
450 targ.death_origin = targ.origin;
452 targ.killer_origin = attacker.origin;
454 // FIXME: this should go in PutClientInServer
460 // these are updated by each Damage call for use in button triggering and such
462 entity damage_inflictor;
463 entity damage_attacker;
465 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
470 entity attacker_save;
474 if (gameover || targ.killcount == -666)
477 local entity oldself;
481 damage_inflictor = inflictor;
482 damage_attacker = attacker;
483 attacker_save = attacker;
485 if(targ.classname == "player")
488 if(targ.hook.aiment == attacker)
489 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
491 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
492 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
494 if(targ.classname == "player")
495 if not(IsDifferentTeam(targ, attacker))
502 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
504 // These are ALWAYS lethal
505 // No damage modification here
506 // Instead, prepare the victim for his death...
508 targ.spawnshieldtime = 0;
509 targ.health = 0.9; // this is < 1
510 targ.flags -= targ.flags & FL_GODMODE;
513 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
519 if (targ.classname == "player")
520 if (attacker.classname == "player")
523 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
525 // nullify damage if teamplay is on
526 if(deathtype != DEATH_TELEFRAG)
527 if(attacker.classname == "player")
529 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
534 else if(attacker.team == targ.team)
538 else if(attacker != targ)
542 else if(teamplay == 4)
544 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
546 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
547 attacker.dmg_team = attacker.dmg_team + damage;
548 if(attacker.dmg_team > teamdamage0 && !g_ca)
549 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
550 mirrorforce = cvar("g_mirrordamage") * vlen(force);
553 if(cvar("g_friendlyfire") == 0)
559 damage = cvar("g_friendlyfire") * damage;
560 // mirrordamage will be used LATER
569 if(targ.classname == "player")
570 if(attacker.classname == "player")
573 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
574 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
577 if(targ.classname == "player")
580 if ((deathtype == DEATH_FALL) ||
581 (deathtype == DEATH_DROWN) ||
582 (deathtype == DEATH_SLIME) ||
583 (deathtype == DEATH_LAVA) ||
584 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
591 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
593 targ.armorvalue -= 1;
594 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
597 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
599 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
602 if (targ != attacker)
604 if ((targ.health >= 1) && (targ.classname == "player"))
605 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
615 if not(DEATH_ISSPECIAL(deathtype))
617 damage *= g_weapondamagefactor;
618 mirrordamage *= g_weapondamagefactor;
619 force = force * g_weaponforcefactor;
620 mirrorforce *= g_weaponforcefactor;
623 // apply strength multiplier
624 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
628 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
629 force = force * cvar("g_balance_powerup_strength_selfforce");
633 damage = damage * cvar("g_balance_powerup_strength_damage");
634 force = force * cvar("g_balance_powerup_strength_force");
638 // apply invincibility multiplier
639 if (targ.items & IT_INVINCIBLE && !g_minstagib)
640 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
642 if (targ == attacker)
644 if(g_ca || (g_cts && !cvar("g_cts_selfdamage")))
647 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
650 // CTF: reduce damage/force
655 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
656 force = force * cvar("g_ctf_flagcarrier_selfforce");
661 // apply strength rune
662 if (attacker.runes & RUNE_STRENGTH)
664 if(attacker.runes & CURSE_WEAK) // have both curse & rune
666 damage = damage * cvar("g_balance_rune_strength_combo_damage");
667 force = force * cvar("g_balance_rune_strength_combo_force");
671 damage = damage * cvar("g_balance_rune_strength_damage");
672 force = force * cvar("g_balance_rune_strength_force");
675 else if (attacker.runes & CURSE_WEAK)
677 damage = damage * cvar("g_balance_curse_weak_damage");
678 force = force * cvar("g_balance_curse_weak_force");
681 // apply defense rune
682 if (targ.runes & RUNE_DEFENSE)
684 if (targ.runes & CURSE_VULNER) // have both curse & rune
685 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
687 damage = damage * cvar("g_balance_rune_defense_takedamage");
689 else if (targ.runes & CURSE_VULNER)
690 damage = damage * cvar("g_balance_curse_vulner_takedamage");
696 if(targ.takedamage == DAMAGE_AIM)
699 if(targ.classname == "player")
702 // find height of hit on player axis
703 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
704 vector headmins, headmaxs, org;
705 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
706 headmins = org + GetHeadshotMins(targ);
707 headmaxs = org + GetHeadshotMaxs(targ);
708 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
710 deathtype |= HITTYPE_HEADSHOT;
713 else if(targ.classname == "turret_head")
715 deathtype |= HITTYPE_HEADSHOT;
717 if(deathtype & HITTYPE_HEADSHOT)
718 damage *= 1 + damage_headshotbonus;
720 if(targ.classname == "player")
722 if(IsDifferentTeam(targ, attacker))
727 attacker.typehitsound += 1;
729 attacker.hitsound += 1;
731 damage_goodhits += 1;
732 damage_gooddamage += damage;
734 if not(DEATH_ISSPECIAL(deathtype))
741 if(targ.items & IT_STRENGTH)
744 if(deathtype & HITTYPE_HEADSHOT)
751 if(deathtype != DEATH_FIRE)
752 attacker.typehitsound += 1;
754 if(time > attacker.teamkill_complain)
756 attacker.teamkill_complain = time + 5;
757 attacker.teamkill_soundtime = time + 0.4;
758 attacker.teamkill_soundsource = targ;
766 if (self.damageforcescale)
768 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
770 self.velocity = self.velocity + self.damageforcescale * force;
771 self.flags &~= FL_ONGROUND;
772 UpdateCSQCProjectile(self);
775 if (damage != 0 || (self.damageforcescale && vlen(force)))
776 if (self.event_damage)
777 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
780 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
782 // Savage: vampire mode
785 if (time >= self.spawnshieldtime)
787 attacker.health += damage;
791 if (attacker.runes & RUNE_VAMPIRE)
793 // apply vampire rune
794 if (attacker.runes & CURSE_EMPATHY) // have the curse too
796 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
797 attacker.health = bound(
798 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
799 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
800 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
804 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
805 attacker.health = bound(
806 attacker.health, // LA: was 3, but changed so that you can't lose health
807 // empathy won't let you gain health in the same way...
808 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
809 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
812 // apply empathy curse
813 else if (attacker.runes & CURSE_EMPATHY)
815 attacker.health = bound(
816 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
817 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
823 // apply mirror damage if any
824 if(mirrordamage > 0 || mirrorforce > 0)
826 attacker = attacker_save;
830 // just lose extra LIVES, don't kill the player for mirror damage
831 if(attacker.armorvalue > 0)
833 attacker.armorvalue = attacker.armorvalue - 1;
834 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
835 attacker.hitsound += 1;
839 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
840 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
844 vector NearestPointOnBox(entity box, vector org)
846 vector m1, m2, nearest;
848 m1 = box.mins + box.origin;
849 m2 = box.maxs + box.origin;
851 nearest_x = bound(m1_x, org_x, m2_x);
852 nearest_y = bound(m1_y, org_y, m2_y);
853 nearest_z = bound(m1_z, org_z, m2_z);
858 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
861 weaponid = DEATH_WEAPONOF(deathtype);
863 if not(inWarmupStage)
865 if ((clienttype(attacker) == CLIENTTYPE_REAL) | (clienttype(attacker) == CLIENTTYPE_BOT)) {
866 attacker.stats_hit[weaponid - 1] += damage;
867 attacker.stat_hit = weaponid + 64 * floor(attacker.stats_hit[weaponid - 1]);
871 float RadiusDamage_running;
872 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
873 // Returns total damage applies to creatures
883 float total_damage_to_creatures;
888 float stat_damagedone;
889 float stat_maxdamage;
891 if(RadiusDamage_running)
894 print("RadiusDamage called recursively!\n");
895 print("Expect stuff to go HORRIBLY wrong.\n");
896 print("Causing a stack trace...\n");
897 save = cvar_string("prvm_backtraceforwarnings");
898 cvar_set("prvm_backtraceforwarnings", "1");
899 fclose(-1); // calls VM_Warning
900 cvar_set("prvm_backtraceforwarnings", save);
904 RadiusDamage_running = 1;
906 tfloordmg = cvar("g_throughfloor_damage");
907 tfloorforce = cvar("g_throughfloor_force");
909 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
910 total_damage_to_creatures = 0;
912 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
913 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
915 force = inflictor.velocity;
919 force = normalize(force);
920 if(forceintensity >= 0)
921 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
923 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
929 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
933 if (targ != inflictor)
934 if (ignore != targ) if(targ.takedamage)
936 // LordHavoc: measure distance to nearest point on target (not origin)
937 // (this guarentees 100% damage on a touch impact)
938 nearest = targ.WarpZone_findradius_nearest;
939 diff = targ.WarpZone_findradius_dist;
940 // round up a little on the damage to ensure full damage on impacts
941 // and turn the distance into a fraction of the radius
942 power = 1 - ((vlen (diff) - 2) / rad);
944 //bprint(ftos(power));
945 //if (targ == attacker)
946 // print(ftos(power), "\n");
951 finaldmg = coredamage * power + edgedamage * (1 - power);
958 local float hitratio;
960 local vector myblastorigin;
961 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
962 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
963 // if it's a player, use the view origin as reference
964 if (targ.classname == "player")
965 center = targ.origin + targ.view_ofs;
966 force = normalize(center - myblastorigin);
967 force = force * (finaldmg / coredamage) * forceintensity;
968 // test line of sight to multiple positions on box,
969 // and do damage if any of them hit
971 if (targ.classname == "player")
972 total = ceil(bound(1, finaldmg, 50));
974 total = ceil(bound(1, finaldmg/10, 5));
979 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
980 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
981 if (trace_fraction == 1 || trace_ent == targ)
985 hitloc = hitloc + nearest;
989 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
990 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
991 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
994 nearest = hitloc * (1 / max(1, hits));
995 hitratio = (hits / total);
996 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
997 finaldmg = finaldmg * a;
998 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1000 //if (targ == attacker)
1002 // print("hits ", ftos(hits), " / ", ftos(total));
1003 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1004 // print(" (", ftos(a), ")\n");
1006 if(hits || tfloordmg || tfloorforce)
1010 total_damage_to_creatures += finaldmg;
1012 if(targ.flags & FL_CLIENT)
1013 if(targ.deadflag == DEAD_NO)
1014 if(targ != attacker)
1015 if(!teamplay || targ.team != attacker.team)
1017 stat_damagedone += finaldmg;
1018 stat_maxdamage += coredamage;
1022 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1023 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1025 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1033 RadiusDamage_running = 0;
1035 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1037 return total_damage_to_creatures;
1040 .float fire_damagepersec;
1041 .float fire_endtime;
1042 .float fire_deathtype;
1044 .float fire_hitsound;
1045 .entity fire_burner;
1047 void fireburner_think();
1049 float Fire_IsBurning(entity e)
1051 return (time < e.fire_endtime);
1054 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1057 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1059 if(e.classname == "player")
1068 // print("adding a fire burner to ", e.classname, "\n");
1069 e.fire_burner = spawn();
1070 e.fire_burner.classname = "fireburner";
1071 e.fire_burner.think = fireburner_think;
1072 e.fire_burner.nextthink = time;
1073 e.fire_burner.owner = e;
1079 if(Fire_IsBurning(e))
1081 mintime = e.fire_endtime - time;
1082 maxtime = max(mintime, t);
1084 mindps = e.fire_damagepersec;
1085 maxdps = max(mindps, dps);
1087 if(maxtime > mintime || maxdps > mindps)
1089 mindamage = mindps * mintime;
1090 maxdamage = mindamage + d;
1092 // interval [mintime, maxtime] * [mindps, maxdps]
1094 // [mindamage, maxdamage]
1097 if(maxdamage >= maxtime * maxdps)
1099 totaltime = maxtime;
1100 totaldamage = maxtime * maxdps;
1102 // this branch increases totaldamage if either t > mintime, or dps > mindps
1106 // maxdamage is inside the interval!
1107 // first, try to use mindps; only if this fails, increase dps as needed
1108 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1109 totaldamage = maxdamage;
1110 // can totaldamage / totaltime be >= maxdps?
1111 // max(mindps, maxdamage / maxtime) >= maxdps?
1112 // we know maxdamage < maxtime * maxdps
1115 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1118 // total conditions for increasing:
1119 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1121 // if maxtime = mintime, maxdps = mindps
1123 // maxdamage = mindamage + d
1124 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1125 // so the last condition is not needed
1127 e.fire_damagepersec = totaldamage / totaltime;
1128 e.fire_endtime = time + totaltime;
1129 if(totaldamage > 1.2 * mindamage)
1131 e.fire_deathtype = dt;
1132 if(e.fire_owner != o)
1135 e.fire_hitsound = FALSE;
1138 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1145 e.fire_damagepersec = dps;
1146 e.fire_endtime = time + t;
1147 e.fire_deathtype = dt;
1149 e.fire_hitsound = FALSE;
1154 void Fire_ApplyDamage(entity e)
1159 if not(Fire_IsBurning(e))
1165 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1168 // water and slime stop fire
1170 if(e.watertype != CONTENT_LAVA)
1173 t = min(frametime, e.fire_endtime - time);
1174 d = e.fire_damagepersec * t;
1176 hi = e.fire_owner.hitsound;
1177 ty = e.fire_owner.typehitsound;
1178 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1179 if(e.fire_hitsound && e.fire_owner)
1181 e.fire_owner.hitsound = hi;
1182 e.fire_owner.typehitsound = ty;
1184 e.fire_hitsound = TRUE;
1186 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1188 if not(IS_INDEPENDENT_PLAYER(e))
1189 FOR_EACH_PLAYER(other) if(e != other)
1191 if(other.classname == "player")
1192 if(other.deadflag == DEAD_NO)
1193 if not(IS_INDEPENDENT_PLAYER(other))
1194 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1196 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1197 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1198 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1203 void Fire_ApplyEffect(entity e)
1205 if(Fire_IsBurning(e))
1206 e.effects |= EF_FLAME;
1208 e.effects &~= EF_FLAME;
1211 void fireburner_think()
1213 // for players, this is done in the regular loop
1214 if(wasfreed(self.owner))
1219 Fire_ApplyEffect(self.owner);
1220 if(!Fire_IsBurning(self.owner))
1222 self.owner.fire_burner = world;
1226 Fire_ApplyDamage(self.owner);
1227 self.nextthink = time;