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?
128 PlayerScore_Add(attacker, SP_KILLS, 1);
131 PlayerScore_Add(targ, SP_DEATHS, 1);
134 if(autocvar_g_arena_roundbased)
137 if(targ != attacker) // not for suicides
138 if(g_weaponarena_random)
140 // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
142 culprit = DEATH_WEAPONOF(deathtype);
143 if(!culprit || !(attacker.weapons & W_WeaponBit(culprit)))
144 culprit = attacker.weapon;
146 if(g_weaponarena_random_with_laser && culprit == WEPBIT_LASER)
153 w = warmup_start_weapons;
157 // all others (including the culprit): remove
158 w &~= attacker.weapons;
160 // among the remaining ones, choose one by random
161 w = randombits(w, 1, FALSE);
164 attacker.weapons |= w;
165 attacker.weapons &~= W_WeaponBit(culprit);
169 // after a frag, choose another random weapon set
170 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
171 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
174 // FIXME fix the mess this is (we have REAL points now!)
178 frag_attacker = attacker;
181 if(MUTATOR_CALLHOOK(GiveFragsForKill))
191 f = RunematchHandleFrags(attacker, targ, f);
197 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
198 if(tl < lms_lowest_lives)
199 lms_lowest_lives = tl;
203 lms_next_place = player_count;
204 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
211 if(g_ctf_ignore_frags)
216 attacker.totalfrags += f;
219 UpdateFrags(attacker, f);
222 string AppendItemcodes(string s, entity player)
227 // w = player.switchweapon;
229 w = player.cnt; // previous weapon!
230 s = strcat(s, ftos(w));
231 if(time < player.strength_finished)
233 if(time < player.invincible_finished)
235 if(player.flagcarried != world)
237 if(player.BUTTON_CHAT)
242 s = strcat(s, "|", ftos(player.runes));
246 void LogDeath(string mode, float deathtype, entity killer, entity killed)
249 if(!autocvar_sv_eventlog)
251 s = strcat(":kill:", mode);
252 s = strcat(s, ":", ftos(killer.playerid));
253 s = strcat(s, ":", ftos(killed.playerid));
254 s = strcat(s, ":type=", ftos(deathtype));
255 s = strcat(s, ":items=");
256 s = AppendItemcodes(s, killer);
259 s = strcat(s, ":victimitems=");
260 s = AppendItemcodes(s, killed);
265 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
267 WriteByte(MSG_ALL, SVC_TEMPENTITY);
268 WriteByte(MSG_ALL, TE_CSQC_NOTIFY);
269 WriteByte(MSG_ALL, CSQC_KILLNOTIFY);
270 WriteString(MSG_ALL, s1);
271 WriteString(MSG_ALL, s2);
272 WriteString(MSG_ALL, s3);
273 WriteShort(MSG_ALL, msg);
274 WriteByte(MSG_ALL, type);
277 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
278 void Send_CSQC_Centerprint(entity e, string s1, string s2, float msg, float type)
280 if (clienttype(e) == CLIENTTYPE_REAL)
283 WRITESPECTATABLE_MSG_ONE({
284 WriteByte(MSG_ONE, SVC_TEMPENTITY);
285 WriteByte(MSG_ONE, TE_CSQC_NOTIFY);
286 WriteByte(MSG_ONE, CSQC_CENTERPRINT);
287 WriteString(MSG_ONE, s1);
288 WriteString(MSG_ONE, s2);
289 WriteShort(MSG_ONE, msg);
290 WriteByte(MSG_ONE, type);
295 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
300 if (targ.classname == "player" || targ.classname == "corpse")
302 if (targ.classname == "corpse")
307 a = attacker.netname;
309 if (targ == attacker) // suicides
311 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
312 msg = ColoredTeamName(targ.team); // TODO: check if needed?
313 if(!g_cts) // no "killed your own dumb self" message in CTS
314 Send_CSQC_Centerprint(targ, msg, "", deathtype, MSG_SUICIDE);
316 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
318 LogDeath("suicide", deathtype, targ, targ);
319 GiveFrags(attacker, targ, -1, deathtype);
322 if (targ.killcount > 2)
323 msg = ftos(targ.killcount);
324 if(teams_matter && deathtype == DEATH_MIRRORDAMAGE)
326 if(attacker.team == COLOR_TEAM1)
327 deathtype = KILL_TEAM_RED;
329 deathtype = KILL_TEAM_BLUE;
332 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
334 else if (attacker.classname == "player" || attacker.classname == "gib")
336 if(teams_matter && attacker.team == targ.team)
338 if(attacker.team == COLOR_TEAM1)
339 type = KILL_TEAM_RED;
341 type = KILL_TEAM_BLUE;
343 GiveFrags(attacker, targ, -1, deathtype);
345 Send_CSQC_Centerprint(attacker, s, "", type, MSG_KILL);
347 if (targ.killcount > 2) {
348 msg = ftos(targ.killcount);
351 if (attacker.killcount > 2) {
352 msg = ftos(attacker.killcount);
353 type = KILL_TEAM_SPREE;
355 Send_KillNotification(a, s, msg, type, MSG_KILL);
357 attacker.killcount = 0;
359 LogDeath("tk", deathtype, attacker, targ);
363 if (!checkrules_firstblood)
365 checkrules_firstblood = TRUE;
366 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
367 // TODO: make these print a newline if they dont
368 Send_CSQC_Centerprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
369 Send_CSQC_Centerprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
372 if((autocvar_sv_fragmessage_information_typefrag) && (targ.BUTTON_CHAT)) {
373 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_TYPEFRAG, MSG_KILL);
374 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_TYPEFRAGGED, MSG_KILL);
376 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_FRAG, MSG_KILL);
377 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_FRAGGED, MSG_KILL);
380 attacker.taunt_soundtime = time + 1;
383 if (deathtype == DEATH_CUSTOM)
386 msg = inflictor.message2;
388 if(strstrofs(msg, "%", 0) < 0)
389 msg = strcat("%s ", msg, " by %s");
391 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
393 if(g_ctf && targ.flagcarried)
395 UpdateFrags(attacker, ctf_score_value("score_kill"));
396 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
397 GiveFrags(attacker, targ, 0, deathtype); // for logging
400 GiveFrags(attacker, targ, 1, deathtype);
402 if (targ.killcount > 2) {
403 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
406 attacker.killcount = attacker.killcount + 1;
408 if (attacker.killcount > 2) {
409 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
411 else if (attacker.killcount == 3)
413 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
414 AnnounceTo(attacker, "03kills");
416 else if (attacker.killcount == 5)
418 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
419 AnnounceTo(attacker, "05kills");
421 else if (attacker.killcount == 10)
423 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
424 AnnounceTo(attacker, "10kills");
426 else if (attacker.killcount == 15)
428 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
429 AnnounceTo(attacker, "15kills");
431 else if (attacker.killcount == 20)
433 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
434 AnnounceTo(attacker, "20kills");
436 else if (attacker.killcount == 25)
438 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
439 AnnounceTo(attacker, "25kills");
441 else if (attacker.killcount == 30)
443 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
444 AnnounceTo(attacker, "30kills");
446 LogDeath("frag", deathtype, attacker, targ);
451 Send_CSQC_Centerprint(targ, "", "", deathtype, MSG_KILL_ACTION);
452 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
453 msg = inflictor.message;
454 else if (deathtype == DEATH_CUSTOM)
456 if(strstrofs(msg, "%", 0) < 0)
457 msg = strcat("%s ", msg);
459 GiveFrags(targ, targ, -1, deathtype);
460 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
461 AnnounceTo(targ, "botlike");
463 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
465 if (targ.killcount > 2)
466 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
468 LogDeath("accident", deathtype, targ, targ);
471 targ.death_origin = targ.origin;
473 targ.killer_origin = attacker.origin;
475 // FIXME: this should go in PutClientInServer
481 // these are updated by each Damage call for use in button triggering and such
483 entity damage_inflictor;
484 entity damage_attacker;
487 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
492 entity attacker_save;
496 if (gameover || targ.killcount == -666)
499 local entity oldself;
503 damage_inflictor = inflictor;
504 damage_attacker = attacker;
505 attacker_save = attacker;
507 if(targ.classname == "player")
510 if(targ.hook.aiment == attacker)
511 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
513 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
514 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
516 if(targ.classname == "player")
517 if not(IsDifferentTeam(targ, attacker))
524 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
526 // These are ALWAYS lethal
527 // No damage modification here
528 // Instead, prepare the victim for his death...
530 targ.spawnshieldtime = 0;
531 targ.health = 0.9; // this is < 1
532 targ.flags -= targ.flags & FL_GODMODE;
535 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
541 if (targ.classname == "player")
542 if (attacker.classname == "player")
545 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
547 // nullify damage if teamplay is on
548 if(deathtype != DEATH_TELEFRAG)
549 if(attacker.classname == "player")
551 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
556 else if(teams_matter && attacker.team == targ.team)
558 if(autocvar_teamplay_mode == 1)
560 else if(attacker != targ)
562 if(autocvar_teamplay_mode == 3)
564 else if(autocvar_teamplay_mode == 4)
566 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
568 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
569 attacker.dmg_team = attacker.dmg_team + damage;
570 if(attacker.dmg_team > teamdamage0 && !g_ca)
571 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
572 mirrorforce = autocvar_g_mirrordamage * vlen(force);
575 if(autocvar_g_friendlyfire == 0)
581 damage = autocvar_g_friendlyfire * damage;
582 // mirrordamage will be used LATER
584 if(autocvar_g_mirrordamage_virtual)
587 v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
588 attacker.dmg_take += v_x;
589 attacker.dmg_save += v_y;
590 attacker.dmg_inflictor = inflictor;
595 if(autocvar_g_friendlyfire_virtual)
598 v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
599 targ.dmg_take += v_x;
600 targ.dmg_save += v_y;
601 targ.dmg_inflictor = inflictor;
603 if(!autocvar_g_friendlyfire_virtual_force)
614 if(targ.classname == "player")
615 if(attacker.classname == "player")
618 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
619 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
622 if(targ.classname == "player")
625 if ((deathtype == DEATH_FALL) ||
626 (deathtype == DEATH_DROWN) ||
627 (deathtype == DEATH_SLIME) ||
628 (deathtype == DEATH_LAVA) ||
629 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
636 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
638 targ.armorvalue -= 1;
639 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
642 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
644 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
648 if (targ != attacker)
650 if ((targ.health >= 1) && (targ.classname == "player"))
651 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
659 if not(DEATH_ISSPECIAL(deathtype))
661 damage *= g_weapondamagefactor;
662 mirrordamage *= g_weapondamagefactor;
663 force = force * g_weaponforcefactor;
664 mirrorforce *= g_weaponforcefactor;
667 // should this be changed at all? If so, in what way?
668 frag_attacker = attacker;
670 frag_damage = damage;
672 frag_deathtype = deathtype;
673 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
674 damage = frag_damage;
677 // apply strength multiplier
678 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
682 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
683 force = force * autocvar_g_balance_powerup_strength_selfforce;
687 damage = damage * autocvar_g_balance_powerup_strength_damage;
688 force = force * autocvar_g_balance_powerup_strength_force;
692 // apply invincibility multiplier
693 if (targ.items & IT_INVINCIBLE && !g_minstagib)
694 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
696 if (targ == attacker)
698 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
701 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
704 // CTF: reduce damage/force
709 damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
710 force = force * autocvar_g_ctf_flagcarrier_selfforce;
715 // apply strength rune
716 if (attacker.runes & RUNE_STRENGTH)
718 if(attacker.runes & CURSE_WEAK) // have both curse & rune
720 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
721 force = force * autocvar_g_balance_rune_strength_combo_force;
725 damage = damage * autocvar_g_balance_rune_strength_damage;
726 force = force * autocvar_g_balance_rune_strength_force;
729 else if (attacker.runes & CURSE_WEAK)
731 damage = damage * autocvar_g_balance_curse_weak_damage;
732 force = force * autocvar_g_balance_curse_weak_force;
735 // apply defense rune
736 if (targ.runes & RUNE_DEFENSE)
738 if (targ.runes & CURSE_VULNER) // have both curse & rune
739 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
741 damage = damage * autocvar_g_balance_rune_defense_takedamage;
743 else if (targ.runes & CURSE_VULNER)
744 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
750 if(targ.takedamage == DAMAGE_AIM)
753 if(targ.classname == "player")
756 // find height of hit on player axis
757 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
758 vector headmins, headmaxs, org;
759 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
760 headmins = org + GetHeadshotMins(targ);
761 headmaxs = org + GetHeadshotMaxs(targ);
762 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
764 deathtype |= HITTYPE_HEADSHOT;
767 else if(targ.classname == "turret_head")
769 deathtype |= HITTYPE_HEADSHOT;
771 if(deathtype & HITTYPE_HEADSHOT)
772 damage *= 1 + damage_headshotbonus;
774 if(targ.classname == "player")
776 if(IsDifferentTeam(targ, attacker))
780 if(attacker.weapon != WEP_LASER
781 && (attacker.weapon != WEP_ELECTRO || !autocvar_g_balance_electro_lightning)
782 && attacker.prevhitsound + autocvar_sv_hitsound_antispam_time < time)
785 attacker.typehitsound += 1;
787 attacker.hitsound += 1;
788 attacker.prevhitsound = time;
791 damage_goodhits += 1;
792 damage_gooddamage += damage;
794 if not(DEATH_ISSPECIAL(deathtype))
801 if(targ.items & IT_STRENGTH)
804 if(deathtype & HITTYPE_HEADSHOT)
808 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
813 if(deathtype != DEATH_FIRE
814 && attacker.prevhitsound + autocvar_sv_hitsound_antispam_time < time)
816 attacker.typehitsound += 1;
817 attacker.prevhitsound = time;
820 if(time > attacker.teamkill_complain)
822 attacker.teamkill_complain = time + 5;
823 attacker.teamkill_soundtime = time + 0.4;
824 attacker.teamkill_soundsource = targ;
832 if (self.damageforcescale)
834 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
836 self.velocity = self.velocity + self.damageforcescale * force;
837 self.flags &~= FL_ONGROUND;
838 UpdateCSQCProjectile(self);
841 if (damage != 0 || (self.damageforcescale && vlen(force)))
842 if (self.event_damage)
843 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
846 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
850 if (attacker.runes & RUNE_VAMPIRE)
852 // apply vampire rune
853 if (attacker.runes & CURSE_EMPATHY) // have the curse too
855 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
856 attacker.health = bound(
857 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
858 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
859 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
863 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
864 attacker.health = bound(
865 attacker.health, // LA: was 3, but changed so that you can't lose health
866 // empathy won't let you gain health in the same way...
867 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
868 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
871 // apply empathy curse
872 else if (attacker.runes & CURSE_EMPATHY)
874 attacker.health = bound(
875 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
876 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
882 // apply mirror damage if any
883 if(mirrordamage > 0 || mirrorforce > 0)
885 attacker = attacker_save;
889 // just lose extra LIVES, don't kill the player for mirror damage
890 if(attacker.armorvalue > 0)
892 attacker.armorvalue = attacker.armorvalue - 1;
893 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
894 attacker.hitsound += 1;
899 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
900 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
904 float RadiusDamage_running;
905 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
906 // Returns total damage applies to creatures
916 float total_damage_to_creatures;
921 float stat_damagedone;
923 if(RadiusDamage_running)
925 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
929 RadiusDamage_running = 1;
931 tfloordmg = autocvar_g_throughfloor_damage;
932 tfloorforce = autocvar_g_throughfloor_force;
934 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
935 total_damage_to_creatures = 0;
937 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
938 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
940 force = inflictor.velocity;
944 force = normalize(force);
945 if(forceintensity >= 0)
946 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
948 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
953 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
957 if (targ != inflictor)
958 if (ignore != targ) if(targ.takedamage)
960 // LordHavoc: measure distance to nearest point on target (not origin)
961 // (this guarentees 100% damage on a touch impact)
962 nearest = targ.WarpZone_findradius_nearest;
963 diff = targ.WarpZone_findradius_dist;
964 // round up a little on the damage to ensure full damage on impacts
965 // and turn the distance into a fraction of the radius
966 power = 1 - ((vlen (diff) - 2) / rad);
968 //bprint(ftos(power));
969 //if (targ == attacker)
970 // print(ftos(power), "\n");
975 finaldmg = coredamage * power + edgedamage * (1 - power);
982 local float hitratio;
984 local vector myblastorigin;
985 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
986 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
987 // if it's a player, use the view origin as reference
988 if (targ.classname == "player")
989 center = targ.origin + targ.view_ofs;
990 force = normalize(center - myblastorigin);
991 force = force * (finaldmg / coredamage) * forceintensity;
992 // test line of sight to multiple positions on box,
993 // and do damage if any of them hit
995 if (targ.classname == "player")
996 total = ceil(bound(1, finaldmg, 50));
998 total = ceil(bound(1, finaldmg/10, 5));
1003 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1004 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1005 if (trace_fraction == 1 || trace_ent == targ)
1009 hitloc = hitloc + nearest;
1013 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1014 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1015 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1018 nearest = hitloc * (1 / max(1, hits));
1019 hitratio = (hits / total);
1020 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1021 finaldmg = finaldmg * a;
1022 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1025 // laser force adjustments :P
1026 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1028 if (targ == attacker)
1033 float force_velocitybiasramp;
1034 float force_velocitybias;
1036 force_velocitybiasramp = autocvar_sv_maxspeed;
1037 if(deathtype & HITTYPE_SECONDARY)
1039 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1040 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1044 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1045 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1048 vel = targ.velocity;
1050 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1054 normalize(normalize(force) + vel);
1056 force_z *= force_zscale;
1060 if(deathtype & HITTYPE_SECONDARY)
1062 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1066 force *= autocvar_g_balance_laser_primary_force_other_scale;
1071 //if (targ == attacker)
1073 // print("hits ", ftos(hits), " / ", ftos(total));
1074 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1075 // print(" (", ftos(a), ")\n");
1077 if(hits || tfloordmg || tfloorforce)
1081 total_damage_to_creatures += finaldmg;
1083 if(accuracy_isgooddamage(attacker, targ))
1084 stat_damagedone += finaldmg;
1087 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1088 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1090 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1098 RadiusDamage_running = 0;
1100 if(!DEATH_ISSPECIAL(deathtype))
1101 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1103 return total_damage_to_creatures;
1106 .float fire_damagepersec;
1107 .float fire_endtime;
1108 .float fire_deathtype;
1110 .float fire_hitsound;
1111 .entity fire_burner;
1113 void fireburner_think();
1115 float Fire_IsBurning(entity e)
1117 return (time < e.fire_endtime);
1120 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1123 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1125 if(e.classname == "player")
1134 // print("adding a fire burner to ", e.classname, "\n");
1135 e.fire_burner = spawn();
1136 e.fire_burner.classname = "fireburner";
1137 e.fire_burner.think = fireburner_think;
1138 e.fire_burner.nextthink = time;
1139 e.fire_burner.owner = e;
1145 if(Fire_IsBurning(e))
1147 mintime = e.fire_endtime - time;
1148 maxtime = max(mintime, t);
1150 mindps = e.fire_damagepersec;
1151 maxdps = max(mindps, dps);
1153 if(maxtime > mintime || maxdps > mindps)
1155 mindamage = mindps * mintime;
1156 maxdamage = mindamage + d;
1158 // interval [mintime, maxtime] * [mindps, maxdps]
1160 // [mindamage, maxdamage]
1163 if(maxdamage >= maxtime * maxdps)
1165 totaltime = maxtime;
1166 totaldamage = maxtime * maxdps;
1168 // this branch increases totaldamage if either t > mintime, or dps > mindps
1172 // maxdamage is inside the interval!
1173 // first, try to use mindps; only if this fails, increase dps as needed
1174 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1175 totaldamage = maxdamage;
1176 // can totaldamage / totaltime be >= maxdps?
1177 // max(mindps, maxdamage / maxtime) >= maxdps?
1178 // we know maxdamage < maxtime * maxdps
1181 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1184 // total conditions for increasing:
1185 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1187 // if maxtime = mintime, maxdps = mindps
1189 // maxdamage = mindamage + d
1190 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1191 // so the last condition is not needed
1193 e.fire_damagepersec = totaldamage / totaltime;
1194 e.fire_endtime = time + totaltime;
1195 if(totaldamage > 1.2 * mindamage)
1197 e.fire_deathtype = dt;
1198 if(e.fire_owner != o)
1201 e.fire_hitsound = FALSE;
1204 if(accuracy_isgooddamage(o, e))
1205 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1206 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1213 e.fire_damagepersec = dps;
1214 e.fire_endtime = time + t;
1215 e.fire_deathtype = dt;
1217 e.fire_hitsound = FALSE;
1218 if(accuracy_isgooddamage(o, e))
1219 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1224 void Fire_ApplyDamage(entity e)
1229 if not(Fire_IsBurning(e))
1232 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1233 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1236 // water and slime stop fire
1238 if(e.watertype != CONTENT_LAVA)
1242 if(e.freezetag_frozen)
1245 t = min(frametime, e.fire_endtime - time);
1246 d = e.fire_damagepersec * t;
1248 hi = e.fire_owner.hitsound;
1249 ty = e.fire_owner.typehitsound;
1250 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1251 if(e.fire_hitsound && e.fire_owner)
1253 e.fire_owner.hitsound = hi;
1254 e.fire_owner.typehitsound = ty;
1256 e.fire_hitsound = TRUE;
1258 if not(IS_INDEPENDENT_PLAYER(e))
1259 FOR_EACH_PLAYER(other) if(e != other)
1261 if(other.classname == "player")
1262 if(other.deadflag == DEAD_NO)
1263 if not(IS_INDEPENDENT_PLAYER(other))
1264 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1266 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1267 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1268 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1273 void Fire_ApplyEffect(entity e)
1275 if(Fire_IsBurning(e))
1276 e.effects |= EF_FLAME;
1278 e.effects &~= EF_FLAME;
1281 void fireburner_think()
1283 // for players, this is done in the regular loop
1284 if(wasfreed(self.owner))
1289 Fire_ApplyEffect(self.owner);
1290 if(!Fire_IsBurning(self.owner))
1292 self.owner.fire_burner = world;
1296 Fire_ApplyDamage(self.owner);
1297 self.nextthink = time;