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, float deathtype)
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, exchange the current weapon (or the culprit, if detectable) by a new random weapon
144 culprit = DEATH_WEAPONOF(deathtype);
145 if(!culprit || !(attacker.weapons & W_WeaponBit(culprit)))
146 culprit = attacker.weapon;
148 if(g_weaponarena_random_with_laser && culprit == WEPBIT_LASER)
155 w = warmup_start_weapons;
159 // all others (including the culprit): remove
160 w &~= attacker.weapons;
162 // among the remaining ones, choose one by random
163 w = randombits(w, 1, FALSE);
166 attacker.weapons |= w;
167 attacker.weapons &~= W_WeaponBit(culprit);
171 // after a frag, choose another random weapon set
172 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
173 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
176 // FIXME fix the mess this is (we have REAL points now!)
180 frag_attacker = attacker;
183 if(MUTATOR_CALLHOOK(GiveFragsForKill))
193 f = RunematchHandleFrags(attacker, targ, f);
199 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
200 if(tl < lms_lowest_lives)
201 lms_lowest_lives = tl;
205 lms_next_place = player_count;
206 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
213 if(g_ctf_ignore_frags)
218 attacker.totalfrags += f;
221 UpdateFrags(attacker, f);
224 string AppendItemcodes(string s, entity player)
229 // w = player.switchweapon;
231 w = player.cnt; // previous weapon!
232 s = strcat(s, ftos(w));
233 if(time < player.strength_finished)
235 if(time < player.invincible_finished)
237 if(player.flagcarried != world)
239 if(player.BUTTON_CHAT)
244 s = strcat(s, "|", ftos(player.runes));
248 void LogDeath(string mode, float deathtype, entity killer, entity killed)
251 if(!autocvar_sv_eventlog)
253 s = strcat(":kill:", mode);
254 s = strcat(s, ":", ftos(killer.playerid));
255 s = strcat(s, ":", ftos(killed.playerid));
256 s = strcat(s, ":type=", ftos(deathtype));
257 s = strcat(s, ":items=");
258 s = AppendItemcodes(s, killer);
261 s = strcat(s, ":victimitems=");
262 s = AppendItemcodes(s, killed);
267 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
269 WriteByte(MSG_ALL, SVC_TEMPENTITY);
270 WriteByte(MSG_ALL, TE_CSQC_NOTIFY);
271 WriteByte(MSG_ALL, CSQC_KILLNOTIFY);
272 WriteString(MSG_ALL, s1);
273 WriteString(MSG_ALL, s2);
274 WriteString(MSG_ALL, s3);
275 WriteShort(MSG_ALL, msg);
276 WriteByte(MSG_ALL, type);
279 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
280 void Send_CSQC_Centerprint(entity e, string s1, string s2, float msg, float type)
282 if (clienttype(e) == CLIENTTYPE_REAL)
285 WRITESPECTATABLE_MSG_ONE({
286 WriteByte(MSG_ONE, SVC_TEMPENTITY);
287 WriteByte(MSG_ONE, TE_CSQC_NOTIFY);
288 WriteByte(MSG_ONE, CSQC_CENTERPRINT);
289 WriteString(MSG_ONE, s1);
290 WriteString(MSG_ONE, s2);
291 WriteShort(MSG_ONE, msg);
292 WriteByte(MSG_ONE, type);
297 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
302 if (targ.classname == "player" || targ.classname == "corpse")
304 if (targ.classname == "corpse")
309 a = attacker.netname;
311 if (targ == attacker) // suicides
313 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
314 msg = ColoredTeamName(targ.team); // TODO: check if needed?
315 if(!g_cts) // no "killed your own dumb self" message in CTS
316 Send_CSQC_Centerprint(targ, msg, "", deathtype, MSG_SUICIDE);
318 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
320 LogDeath("suicide", deathtype, targ, targ);
321 GiveFrags(attacker, targ, -1, deathtype);
324 if (targ.killcount > 2)
325 msg = ftos(targ.killcount);
326 if(teams_matter && deathtype == DEATH_MIRRORDAMAGE)
328 if(attacker.team == COLOR_TEAM1)
329 deathtype = KILL_TEAM_RED;
331 deathtype = KILL_TEAM_BLUE;
334 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
336 else if (attacker.classname == "player" || attacker.classname == "gib")
338 if(teams_matter && attacker.team == targ.team)
340 if(attacker.team == COLOR_TEAM1)
341 type = KILL_TEAM_RED;
343 type = KILL_TEAM_BLUE;
345 GiveFrags(attacker, targ, -1, deathtype);
347 Send_CSQC_Centerprint(attacker, s, "", type, MSG_KILL);
349 if (targ.killcount > 2) {
350 msg = ftos(targ.killcount);
353 if (attacker.killcount > 2) {
354 msg = ftos(attacker.killcount);
355 type = KILL_TEAM_SPREE;
357 Send_KillNotification(a, s, msg, type, MSG_KILL);
359 attacker.killcount = 0;
361 LogDeath("tk", deathtype, attacker, targ);
365 if (!checkrules_firstblood)
367 checkrules_firstblood = TRUE;
368 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
369 // TODO: make these print a newline if they dont
370 Send_CSQC_Centerprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
371 Send_CSQC_Centerprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
374 if((autocvar_sv_fragmessage_information_typefrag) && (targ.BUTTON_CHAT)) {
375 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_TYPEFRAG, MSG_KILL);
376 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_TYPEFRAGGED, MSG_KILL);
378 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_FRAG, MSG_KILL);
379 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_FRAGGED, MSG_KILL);
382 attacker.taunt_soundtime = time + 1;
385 if (deathtype == DEATH_CUSTOM)
388 msg = inflictor.message2;
390 if(strstrofs(msg, "%", 0) < 0)
391 msg = strcat("%s ", msg, " by %s");
393 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
395 if(g_ctf && targ.flagcarried)
397 UpdateFrags(attacker, ctf_score_value("score_kill"));
398 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
399 GiveFrags(attacker, targ, 0, deathtype); // for logging
402 GiveFrags(attacker, targ, 1, deathtype);
404 if (targ.killcount > 2) {
405 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
408 attacker.killcount = attacker.killcount + 1;
410 if (attacker.killcount > 2) {
411 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
413 else if (attacker.killcount == 3)
415 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
416 AnnounceTo(attacker, "03kills");
418 else if (attacker.killcount == 5)
420 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
421 AnnounceTo(attacker, "05kills");
423 else if (attacker.killcount == 10)
425 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
426 AnnounceTo(attacker, "10kills");
428 else if (attacker.killcount == 15)
430 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
431 AnnounceTo(attacker, "15kills");
433 else if (attacker.killcount == 20)
435 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
436 AnnounceTo(attacker, "20kills");
438 else if (attacker.killcount == 25)
440 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
441 AnnounceTo(attacker, "25kills");
443 else if (attacker.killcount == 30)
445 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
446 AnnounceTo(attacker, "30kills");
448 LogDeath("frag", deathtype, attacker, targ);
453 Send_CSQC_Centerprint(targ, "", "", deathtype, MSG_KILL_ACTION);
454 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
455 msg = inflictor.message;
456 else if (deathtype == DEATH_CUSTOM)
458 if(strstrofs(msg, "%", 0) < 0)
459 msg = strcat("%s ", msg);
461 GiveFrags(targ, targ, -1, deathtype);
462 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
463 AnnounceTo(targ, "botlike");
465 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
467 if (targ.killcount > 2)
468 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
470 LogDeath("accident", deathtype, targ, targ);
473 targ.death_origin = targ.origin;
475 targ.killer_origin = attacker.origin;
477 // FIXME: this should go in PutClientInServer
483 // these are updated by each Damage call for use in button triggering and such
485 entity damage_inflictor;
486 entity damage_attacker;
489 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
494 entity attacker_save;
498 if (gameover || targ.killcount == -666)
501 local entity oldself;
505 damage_inflictor = inflictor;
506 damage_attacker = attacker;
507 attacker_save = attacker;
509 if(targ.classname == "player")
512 if(targ.hook.aiment == attacker)
513 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
515 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
516 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
518 if(targ.classname == "player")
519 if not(IsDifferentTeam(targ, attacker))
526 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
528 // These are ALWAYS lethal
529 // No damage modification here
530 // Instead, prepare the victim for his death...
532 targ.spawnshieldtime = 0;
533 targ.health = 0.9; // this is < 1
534 targ.flags -= targ.flags & FL_GODMODE;
537 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
543 if (targ.classname == "player")
544 if (attacker.classname == "player")
547 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
549 // nullify damage if teamplay is on
550 if(deathtype != DEATH_TELEFRAG)
551 if(attacker.classname == "player")
553 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
558 else if(teams_matter && attacker.team == targ.team)
560 if(autocvar_teamplay_mode == 1)
562 else if(attacker != targ)
564 if(autocvar_teamplay_mode == 3)
566 else if(autocvar_teamplay_mode == 4)
568 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
570 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
571 attacker.dmg_team = attacker.dmg_team + damage;
572 if(attacker.dmg_team > teamdamage0 && !g_ca)
573 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
574 mirrorforce = autocvar_g_mirrordamage * vlen(force);
577 if(autocvar_g_friendlyfire == 0)
583 damage = autocvar_g_friendlyfire * damage;
584 // mirrordamage will be used LATER
586 if(autocvar_g_mirrordamage_virtual)
589 v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
590 attacker.dmg_take += v_x;
591 attacker.dmg_save += v_y;
592 attacker.dmg_inflictor = inflictor;
597 if(autocvar_g_friendlyfire_virtual)
600 v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
601 targ.dmg_take += v_x;
602 targ.dmg_save += v_y;
603 targ.dmg_inflictor = inflictor;
605 if(!autocvar_g_friendlyfire_virtual_force)
616 if(targ.classname == "player")
617 if(attacker.classname == "player")
620 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
621 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
624 if(targ.classname == "player")
627 if ((deathtype == DEATH_FALL) ||
628 (deathtype == DEATH_DROWN) ||
629 (deathtype == DEATH_SLIME) ||
630 (deathtype == DEATH_LAVA) ||
631 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
638 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
640 targ.armorvalue -= 1;
641 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
644 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
646 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
650 if (targ != attacker)
652 if ((targ.health >= 1) && (targ.classname == "player"))
653 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
661 if not(DEATH_ISSPECIAL(deathtype))
663 damage *= g_weapondamagefactor;
664 mirrordamage *= g_weapondamagefactor;
665 force = force * g_weaponforcefactor;
666 mirrorforce *= g_weaponforcefactor;
669 // should this be changed at all? If so, in what way?
670 frag_attacker = attacker;
672 frag_damage = damage;
674 frag_deathtype = deathtype;
675 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
676 damage = frag_damage;
679 // apply strength multiplier
680 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
684 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
685 force = force * autocvar_g_balance_powerup_strength_selfforce;
689 damage = damage * autocvar_g_balance_powerup_strength_damage;
690 force = force * autocvar_g_balance_powerup_strength_force;
694 // apply invincibility multiplier
695 if (targ.items & IT_INVINCIBLE && !g_minstagib)
696 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
698 if (targ == attacker)
700 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
703 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
706 // CTF: reduce damage/force
711 damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
712 force = force * autocvar_g_ctf_flagcarrier_selfforce;
717 // apply strength rune
718 if (attacker.runes & RUNE_STRENGTH)
720 if(attacker.runes & CURSE_WEAK) // have both curse & rune
722 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
723 force = force * autocvar_g_balance_rune_strength_combo_force;
727 damage = damage * autocvar_g_balance_rune_strength_damage;
728 force = force * autocvar_g_balance_rune_strength_force;
731 else if (attacker.runes & CURSE_WEAK)
733 damage = damage * autocvar_g_balance_curse_weak_damage;
734 force = force * autocvar_g_balance_curse_weak_force;
737 // apply defense rune
738 if (targ.runes & RUNE_DEFENSE)
740 if (targ.runes & CURSE_VULNER) // have both curse & rune
741 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
743 damage = damage * autocvar_g_balance_rune_defense_takedamage;
745 else if (targ.runes & CURSE_VULNER)
746 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
752 if(targ.takedamage == DAMAGE_AIM)
755 if(targ.classname == "player")
758 // find height of hit on player axis
759 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
760 vector headmins, headmaxs, org;
761 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
762 headmins = org + GetHeadshotMins(targ);
763 headmaxs = org + GetHeadshotMaxs(targ);
764 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
766 deathtype |= HITTYPE_HEADSHOT;
769 else if(targ.classname == "turret_head")
771 deathtype |= HITTYPE_HEADSHOT;
773 if(deathtype & HITTYPE_HEADSHOT)
774 damage *= 1 + damage_headshotbonus;
776 if(targ.classname == "player")
778 if(IsDifferentTeam(targ, attacker))
782 if(attacker.weapon != WEP_LASER
783 && (attacker.weapon != WEP_ELECTRO || !autocvar_g_balance_electro_lightning)
784 && attacker.prevhitsound + autocvar_sv_hitsound_antispam_time < time)
787 attacker.typehitsound += 1;
789 attacker.hitsound += 1;
790 attacker.prevhitsound = time;
793 damage_goodhits += 1;
794 damage_gooddamage += damage;
796 if not(DEATH_ISSPECIAL(deathtype))
803 if(targ.items & IT_STRENGTH)
806 if(deathtype & HITTYPE_HEADSHOT)
810 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
815 if(deathtype != DEATH_FIRE
816 && attacker.prevhitsound + autocvar_sv_hitsound_antispam_time < time)
818 attacker.typehitsound += 1;
819 attacker.prevhitsound = time;
822 if(time > attacker.teamkill_complain)
824 attacker.teamkill_complain = time + 5;
825 attacker.teamkill_soundtime = time + 0.4;
826 attacker.teamkill_soundsource = targ;
834 if (self.damageforcescale)
836 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
838 self.velocity = self.velocity + self.damageforcescale * force;
839 self.flags &~= FL_ONGROUND;
840 UpdateCSQCProjectile(self);
843 if (damage != 0 || (self.damageforcescale && vlen(force)))
844 if (self.event_damage)
845 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
848 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
852 if (attacker.runes & RUNE_VAMPIRE)
854 // apply vampire rune
855 if (attacker.runes & CURSE_EMPATHY) // have the curse too
857 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
858 attacker.health = bound(
859 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
860 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
861 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
865 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
866 attacker.health = bound(
867 attacker.health, // LA: was 3, but changed so that you can't lose health
868 // empathy won't let you gain health in the same way...
869 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
870 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
873 // apply empathy curse
874 else if (attacker.runes & CURSE_EMPATHY)
876 attacker.health = bound(
877 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
878 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
884 // apply mirror damage if any
885 if(mirrordamage > 0 || mirrorforce > 0)
887 attacker = attacker_save;
891 // just lose extra LIVES, don't kill the player for mirror damage
892 if(attacker.armorvalue > 0)
894 attacker.armorvalue = attacker.armorvalue - 1;
895 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
896 attacker.hitsound += 1;
901 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
902 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
906 float RadiusDamage_running;
907 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
908 // Returns total damage applies to creatures
918 float total_damage_to_creatures;
923 float stat_damagedone;
925 if(RadiusDamage_running)
927 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
931 RadiusDamage_running = 1;
933 tfloordmg = autocvar_g_throughfloor_damage;
934 tfloorforce = autocvar_g_throughfloor_force;
936 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
937 total_damage_to_creatures = 0;
939 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
940 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
942 force = inflictor.velocity;
946 force = normalize(force);
947 if(forceintensity >= 0)
948 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
950 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
955 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
959 if (targ != inflictor)
960 if (ignore != targ) if(targ.takedamage)
962 // LordHavoc: measure distance to nearest point on target (not origin)
963 // (this guarentees 100% damage on a touch impact)
964 nearest = targ.WarpZone_findradius_nearest;
965 diff = targ.WarpZone_findradius_dist;
966 // round up a little on the damage to ensure full damage on impacts
967 // and turn the distance into a fraction of the radius
968 power = 1 - ((vlen (diff) - 2) / rad);
970 //bprint(ftos(power));
971 //if (targ == attacker)
972 // print(ftos(power), "\n");
977 finaldmg = coredamage * power + edgedamage * (1 - power);
984 local float hitratio;
986 local vector myblastorigin;
987 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
988 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
989 // if it's a player, use the view origin as reference
990 if (targ.classname == "player")
991 center = targ.origin + targ.view_ofs;
992 force = normalize(center - myblastorigin);
993 force = force * (finaldmg / coredamage) * forceintensity;
994 // test line of sight to multiple positions on box,
995 // and do damage if any of them hit
997 if (targ.classname == "player")
998 total = ceil(bound(1, finaldmg, 50));
1000 total = ceil(bound(1, finaldmg/10, 5));
1005 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1006 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1007 if (trace_fraction == 1 || trace_ent == targ)
1011 hitloc = hitloc + nearest;
1015 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1016 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1017 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1020 nearest = hitloc * (1 / max(1, hits));
1021 hitratio = (hits / total);
1022 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1023 finaldmg = finaldmg * a;
1024 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1027 // laser force adjustments :P
1028 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1030 if (targ == attacker)
1035 float force_velocitybiasramp;
1036 float force_velocitybias;
1038 force_velocitybiasramp = autocvar_sv_maxspeed;
1039 if(deathtype & HITTYPE_SECONDARY)
1041 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1042 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1046 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1047 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1050 vel = targ.velocity;
1052 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1056 normalize(normalize(force) + vel);
1058 force_z *= force_zscale;
1062 if(deathtype & HITTYPE_SECONDARY)
1064 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1068 force *= autocvar_g_balance_laser_primary_force_other_scale;
1073 //if (targ == attacker)
1075 // print("hits ", ftos(hits), " / ", ftos(total));
1076 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1077 // print(" (", ftos(a), ")\n");
1079 if(hits || tfloordmg || tfloorforce)
1083 total_damage_to_creatures += finaldmg;
1085 if(accuracy_isgooddamage(attacker, targ))
1086 stat_damagedone += finaldmg;
1089 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1090 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1092 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1100 RadiusDamage_running = 0;
1102 if(!DEATH_ISSPECIAL(deathtype))
1103 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1105 return total_damage_to_creatures;
1108 .float fire_damagepersec;
1109 .float fire_endtime;
1110 .float fire_deathtype;
1112 .float fire_hitsound;
1113 .entity fire_burner;
1115 void fireburner_think();
1117 float Fire_IsBurning(entity e)
1119 return (time < e.fire_endtime);
1122 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1125 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1127 if(e.classname == "player")
1136 // print("adding a fire burner to ", e.classname, "\n");
1137 e.fire_burner = spawn();
1138 e.fire_burner.classname = "fireburner";
1139 e.fire_burner.think = fireburner_think;
1140 e.fire_burner.nextthink = time;
1141 e.fire_burner.owner = e;
1147 if(Fire_IsBurning(e))
1149 mintime = e.fire_endtime - time;
1150 maxtime = max(mintime, t);
1152 mindps = e.fire_damagepersec;
1153 maxdps = max(mindps, dps);
1155 if(maxtime > mintime || maxdps > mindps)
1157 mindamage = mindps * mintime;
1158 maxdamage = mindamage + d;
1160 // interval [mintime, maxtime] * [mindps, maxdps]
1162 // [mindamage, maxdamage]
1165 if(maxdamage >= maxtime * maxdps)
1167 totaltime = maxtime;
1168 totaldamage = maxtime * maxdps;
1170 // this branch increases totaldamage if either t > mintime, or dps > mindps
1174 // maxdamage is inside the interval!
1175 // first, try to use mindps; only if this fails, increase dps as needed
1176 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1177 totaldamage = maxdamage;
1178 // can totaldamage / totaltime be >= maxdps?
1179 // max(mindps, maxdamage / maxtime) >= maxdps?
1180 // we know maxdamage < maxtime * maxdps
1183 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1186 // total conditions for increasing:
1187 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1189 // if maxtime = mintime, maxdps = mindps
1191 // maxdamage = mindamage + d
1192 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1193 // so the last condition is not needed
1195 e.fire_damagepersec = totaldamage / totaltime;
1196 e.fire_endtime = time + totaltime;
1197 if(totaldamage > 1.2 * mindamage)
1199 e.fire_deathtype = dt;
1200 if(e.fire_owner != o)
1203 e.fire_hitsound = FALSE;
1206 if(accuracy_isgooddamage(o, e))
1207 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1208 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1215 e.fire_damagepersec = dps;
1216 e.fire_endtime = time + t;
1217 e.fire_deathtype = dt;
1219 e.fire_hitsound = FALSE;
1220 if(accuracy_isgooddamage(o, e))
1221 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1226 void Fire_ApplyDamage(entity e)
1231 if not(Fire_IsBurning(e))
1234 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1235 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1238 // water and slime stop fire
1240 if(e.watertype != CONTENT_LAVA)
1244 if(e.freezetag_frozen)
1247 t = min(frametime, e.fire_endtime - time);
1248 d = e.fire_damagepersec * t;
1250 hi = e.fire_owner.hitsound;
1251 ty = e.fire_owner.typehitsound;
1252 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1253 if(e.fire_hitsound && e.fire_owner)
1255 e.fire_owner.hitsound = hi;
1256 e.fire_owner.typehitsound = ty;
1258 e.fire_hitsound = TRUE;
1260 if not(IS_INDEPENDENT_PLAYER(e))
1261 FOR_EACH_PLAYER(other) if(e != other)
1263 if(other.classname == "player")
1264 if(other.deadflag == DEAD_NO)
1265 if not(IS_INDEPENDENT_PLAYER(other))
1266 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1268 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1269 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1270 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1275 void Fire_ApplyEffect(entity e)
1277 if(Fire_IsBurning(e))
1278 e.effects |= EF_FLAME;
1280 e.effects &~= EF_FLAME;
1283 void fireburner_think()
1285 // for players, this is done in the regular loop
1286 if(wasfreed(self.owner))
1291 Fire_ApplyEffect(self.owner);
1292 if(!Fire_IsBurning(self.owner))
1294 self.owner.fire_burner = world;
1298 Fire_ApplyDamage(self.owner);
1299 self.nextthink = time;