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;
205 lms_next_place = min(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);
372 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
373 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
376 if((autocvar_sv_fragmessage_information_typefrag) && (targ.BUTTON_CHAT)) {
377 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_TYPEFRAG, MSG_KILL);
378 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_TYPEFRAGGED, MSG_KILL);
380 Send_CSQC_Centerprint(attacker, s, GetAdvancedDeathReports(targ), KILL_FRAG, MSG_KILL);
381 Send_CSQC_Centerprint(targ, a, GetAdvancedDeathReports(attacker), KILL_FRAGGED, MSG_KILL);
384 attacker.taunt_soundtime = time + 1;
387 if (deathtype == DEATH_CUSTOM)
390 msg = inflictor.message2;
392 if(strstrofs(msg, "%", 0) < 0)
393 msg = strcat("%s ", msg, " by %s");
395 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
397 if(g_ctf && targ.flagcarried)
399 UpdateFrags(attacker, ctf_score_value("score_kill"));
400 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
401 GiveFrags(attacker, targ, 0, deathtype); // for logging
404 GiveFrags(attacker, targ, 1, deathtype);
406 if (targ.killcount > 2) {
407 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
410 attacker.killcount = attacker.killcount + 1;
412 if (attacker.killcount > 2) {
413 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
415 else if (attacker.killcount == 3)
417 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
418 AnnounceTo(attacker, "03kills");
419 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
421 else if (attacker.killcount == 5)
423 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
424 AnnounceTo(attacker, "05kills");
425 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
427 else if (attacker.killcount == 10)
429 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
430 AnnounceTo(attacker, "10kills");
431 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
433 else if (attacker.killcount == 15)
435 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
436 AnnounceTo(attacker, "15kills");
437 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
439 else if (attacker.killcount == 20)
441 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
442 AnnounceTo(attacker, "20kills");
443 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
445 else if (attacker.killcount == 25)
447 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
448 AnnounceTo(attacker, "25kills");
449 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
451 else if (attacker.killcount == 30)
453 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
454 AnnounceTo(attacker, "30kills");
455 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
457 LogDeath("frag", deathtype, attacker, targ);
462 Send_CSQC_Centerprint(targ, "", "", deathtype, MSG_KILL_ACTION);
463 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
464 msg = inflictor.message;
465 else if (deathtype == DEATH_CUSTOM)
467 if(strstrofs(msg, "%", 0) < 0)
468 msg = strcat("%s ", msg);
470 GiveFrags(targ, targ, -1, deathtype);
471 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
472 AnnounceTo(targ, "botlike");
473 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
475 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
477 if (targ.killcount > 2)
478 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
480 LogDeath("accident", deathtype, targ, targ);
483 targ.death_origin = targ.origin;
485 targ.killer_origin = attacker.origin;
487 // FIXME: this should go in PutClientInServer
493 // these are updated by each Damage call for use in button triggering and such
495 entity damage_inflictor;
496 entity damage_attacker;
498 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
500 dprint(strcat(ftos(DEATH_WEAPONOF(deathtype)), "--\n"));
505 entity attacker_save;
509 if (gameover || targ.killcount == -666)
512 local entity oldself;
516 damage_inflictor = inflictor;
517 damage_attacker = attacker;
518 attacker_save = attacker;
520 if(targ.classname == "player")
523 if(targ.hook.aiment == attacker)
524 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
526 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
527 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
529 if(targ.classname == "player")
530 if not(IsDifferentTeam(targ, attacker))
537 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
539 // These are ALWAYS lethal
540 // No damage modification here
541 // Instead, prepare the victim for his death...
543 targ.spawnshieldtime = 0;
544 targ.health = 0.9; // this is < 1
545 targ.flags -= targ.flags & FL_GODMODE;
548 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
554 if (targ.classname == "player")
555 if (attacker.classname == "player")
558 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
560 // nullify damage if teamplay is on
561 if(deathtype != DEATH_TELEFRAG)
562 if(attacker.classname == "player")
564 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
569 else if(teams_matter && attacker.team == targ.team)
571 if(autocvar_teamplay_mode == 1)
573 else if(attacker != targ)
575 if(autocvar_teamplay_mode == 3)
577 else if(autocvar_teamplay_mode == 4)
579 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
581 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
582 attacker.dmg_team = attacker.dmg_team + damage;
583 if(attacker.dmg_team > teamdamage0 && !g_ca)
584 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
585 mirrorforce = autocvar_g_mirrordamage * vlen(force);
588 if(autocvar_g_friendlyfire == 0)
594 damage = autocvar_g_friendlyfire * damage;
595 // mirrordamage will be used LATER
597 if(autocvar_g_mirrordamage_virtual)
600 v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
601 attacker.dmg_take += v_x;
602 attacker.dmg_save += v_y;
603 attacker.dmg_inflictor = inflictor;
608 if(autocvar_g_friendlyfire_virtual)
611 v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
612 targ.dmg_take += v_x;
613 targ.dmg_save += v_y;
614 targ.dmg_inflictor = inflictor;
616 if(!autocvar_g_friendlyfire_virtual_force)
627 if(targ.classname == "player")
628 if(attacker.classname == "player")
631 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
632 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
635 if(targ.classname == "player")
638 if ((deathtype == DEATH_FALL) ||
639 (deathtype == DEATH_DROWN) ||
640 (deathtype == DEATH_SLIME) ||
641 (deathtype == DEATH_LAVA) ||
642 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
649 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
651 targ.armorvalue -= 1;
652 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
655 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
657 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
661 if (targ != attacker)
663 if ((targ.health >= 1) && (targ.classname == "player"))
664 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
672 if not(DEATH_ISSPECIAL(deathtype))
674 damage *= g_weapondamagefactor;
675 mirrordamage *= g_weapondamagefactor;
676 force = force * g_weaponforcefactor;
677 mirrorforce *= g_weaponforcefactor;
680 // should this be changed at all? If so, in what way?
681 frag_attacker = attacker;
683 frag_damage = damage;
685 frag_deathtype = deathtype;
686 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
687 damage = frag_damage;
690 // apply strength multiplier
691 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
695 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
696 force = force * autocvar_g_balance_powerup_strength_selfforce;
700 damage = damage * autocvar_g_balance_powerup_strength_damage;
701 force = force * autocvar_g_balance_powerup_strength_force;
705 // apply invincibility multiplier
706 if (targ.items & IT_INVINCIBLE && !g_minstagib)
707 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
709 if (targ == attacker)
711 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
714 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
717 // CTF: reduce damage/force
722 damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
723 force = force * autocvar_g_ctf_flagcarrier_selfforce;
728 // apply strength rune
729 if (attacker.runes & RUNE_STRENGTH)
731 if(attacker.runes & CURSE_WEAK) // have both curse & rune
733 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
734 force = force * autocvar_g_balance_rune_strength_combo_force;
738 damage = damage * autocvar_g_balance_rune_strength_damage;
739 force = force * autocvar_g_balance_rune_strength_force;
742 else if (attacker.runes & CURSE_WEAK)
744 damage = damage * autocvar_g_balance_curse_weak_damage;
745 force = force * autocvar_g_balance_curse_weak_force;
748 // apply defense rune
749 if (targ.runes & RUNE_DEFENSE)
751 if (targ.runes & CURSE_VULNER) // have both curse & rune
752 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
754 damage = damage * autocvar_g_balance_rune_defense_takedamage;
756 else if (targ.runes & CURSE_VULNER)
757 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
763 if(targ.takedamage == DAMAGE_AIM)
766 if(targ.classname == "player")
769 // find height of hit on player axis
770 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
771 vector headmins, headmaxs, org;
772 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
773 headmins = org + GetHeadshotMins(targ);
774 headmaxs = org + GetHeadshotMaxs(targ);
775 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
777 deathtype |= HITTYPE_HEADSHOT;
780 else if(targ.classname == "turret_head")
782 deathtype |= HITTYPE_HEADSHOT;
784 if(deathtype & HITTYPE_HEADSHOT)
785 damage *= 1 + damage_headshotbonus;
787 if(targ.classname == "player")
789 if(IsDifferentTeam(targ, attacker))
793 if(deathtype != DEATH_FIRE)
796 attacker.typehitsound += 1;
798 attacker.hitsound += 1;
801 damage_goodhits += 1;
802 damage_gooddamage += damage;
804 if not(DEATH_ISSPECIAL(deathtype))
811 if(targ.items & IT_STRENGTH)
814 if(deathtype & HITTYPE_HEADSHOT)
818 PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
823 if(deathtype != DEATH_FIRE)
825 attacker.typehitsound += 1;
828 if(time > attacker.teamkill_complain)
830 attacker.teamkill_complain = time + 5;
831 attacker.teamkill_soundtime = time + 0.4;
832 attacker.teamkill_soundsource = targ;
840 if (self.damageforcescale)
842 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
844 self.velocity = self.velocity + damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
845 self.flags &~= FL_ONGROUND;
846 UpdateCSQCProjectile(self);
849 if (damage != 0 || (self.damageforcescale && vlen(force)))
850 if (self.event_damage)
851 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
854 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
858 if (attacker.runes & RUNE_VAMPIRE)
860 // apply vampire rune
861 if (attacker.runes & CURSE_EMPATHY) // have the curse too
863 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
864 attacker.health = bound(
865 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
866 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
867 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
871 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
872 attacker.health = bound(
873 attacker.health, // LA: was 3, but changed so that you can't lose health
874 // empathy won't let you gain health in the same way...
875 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
876 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
879 // apply empathy curse
880 else if (attacker.runes & CURSE_EMPATHY)
882 attacker.health = bound(
883 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
884 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
890 // apply mirror damage if any
891 if(mirrordamage > 0 || mirrorforce > 0)
893 attacker = attacker_save;
897 // just lose extra LIVES, don't kill the player for mirror damage
898 if(attacker.armorvalue > 0)
900 attacker.armorvalue = attacker.armorvalue - 1;
901 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
902 attacker.hitsound += 1;
907 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
908 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
912 float RadiusDamage_running;
913 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
914 // Returns total damage applies to creatures
924 float total_damage_to_creatures;
929 float stat_damagedone;
931 if(RadiusDamage_running)
933 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
937 RadiusDamage_running = 1;
939 tfloordmg = autocvar_g_throughfloor_damage;
940 tfloorforce = autocvar_g_throughfloor_force;
942 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
943 total_damage_to_creatures = 0;
945 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
946 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
948 force = inflictor.velocity;
952 force = normalize(force);
953 if(forceintensity >= 0)
954 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
956 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
961 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
965 if (targ != inflictor)
966 if (ignore != targ) if(targ.takedamage)
968 // LordHavoc: measure distance to nearest point on target (not origin)
969 // (this guarentees 100% damage on a touch impact)
970 nearest = targ.WarpZone_findradius_nearest;
971 diff = targ.WarpZone_findradius_dist;
972 // round up a little on the damage to ensure full damage on impacts
973 // and turn the distance into a fraction of the radius
974 power = 1 - ((vlen (diff) - 2) / rad);
976 //bprint(ftos(power));
977 //if (targ == attacker)
978 // print(ftos(power), "\n");
983 finaldmg = coredamage * power + edgedamage * (1 - power);
990 local float hitratio;
992 local vector myblastorigin;
993 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
994 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
995 // if it's a player, use the view origin as reference
996 if (targ.classname == "player")
997 center = targ.origin + targ.view_ofs;
998 force = normalize(center - myblastorigin);
999 force = force * (finaldmg / coredamage) * forceintensity;
1000 // test line of sight to multiple positions on box,
1001 // and do damage if any of them hit
1003 if (targ.classname == "player")
1004 total = ceil(bound(1, finaldmg, 50));
1006 total = ceil(bound(1, finaldmg/10, 5));
1011 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1012 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1013 if (trace_fraction == 1 || trace_ent == targ)
1017 hitloc = hitloc + nearest;
1021 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1022 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1023 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1026 nearest = hitloc * (1 / max(1, hits));
1027 hitratio = (hits / total);
1028 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1029 finaldmg = finaldmg * a;
1030 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1033 // laser force adjustments :P
1034 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1036 if (targ == attacker)
1041 float force_velocitybiasramp;
1042 float force_velocitybias;
1044 force_velocitybiasramp = autocvar_sv_maxspeed;
1045 if(deathtype & HITTYPE_SECONDARY)
1047 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1048 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1052 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1053 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1056 vel = targ.velocity;
1058 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1062 normalize(normalize(force) + vel);
1064 force_z *= force_zscale;
1068 if(deathtype & HITTYPE_SECONDARY)
1070 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1074 force *= autocvar_g_balance_laser_primary_force_other_scale;
1079 //if (targ == attacker)
1081 // print("hits ", ftos(hits), " / ", ftos(total));
1082 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1083 // print(" (", ftos(a), ")\n");
1085 if(hits || tfloordmg || tfloorforce)
1089 total_damage_to_creatures += finaldmg;
1091 if(accuracy_isgooddamage(attacker, targ))
1092 stat_damagedone += finaldmg;
1095 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1096 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1098 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1106 RadiusDamage_running = 0;
1108 if(!DEATH_ISSPECIAL(deathtype))
1109 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1111 return total_damage_to_creatures;
1114 .float fire_damagepersec;
1115 .float fire_endtime;
1116 .float fire_deathtype;
1118 .float fire_hitsound;
1119 .entity fire_burner;
1121 void fireburner_think();
1123 float Fire_IsBurning(entity e)
1125 return (time < e.fire_endtime);
1128 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1131 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1133 if(e.classname == "player")
1142 // print("adding a fire burner to ", e.classname, "\n");
1143 e.fire_burner = spawn();
1144 e.fire_burner.classname = "fireburner";
1145 e.fire_burner.think = fireburner_think;
1146 e.fire_burner.nextthink = time;
1147 e.fire_burner.owner = e;
1153 if(Fire_IsBurning(e))
1155 mintime = e.fire_endtime - time;
1156 maxtime = max(mintime, t);
1158 mindps = e.fire_damagepersec;
1159 maxdps = max(mindps, dps);
1161 if(maxtime > mintime || maxdps > mindps)
1163 mindamage = mindps * mintime;
1164 maxdamage = mindamage + d;
1166 // interval [mintime, maxtime] * [mindps, maxdps]
1168 // [mindamage, maxdamage]
1171 if(maxdamage >= maxtime * maxdps)
1173 totaltime = maxtime;
1174 totaldamage = maxtime * maxdps;
1176 // this branch increases totaldamage if either t > mintime, or dps > mindps
1180 // maxdamage is inside the interval!
1181 // first, try to use mindps; only if this fails, increase dps as needed
1182 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1183 totaldamage = maxdamage;
1184 // can totaldamage / totaltime be >= maxdps?
1185 // max(mindps, maxdamage / maxtime) >= maxdps?
1186 // we know maxdamage < maxtime * maxdps
1189 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1192 // total conditions for increasing:
1193 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1195 // if maxtime = mintime, maxdps = mindps
1197 // maxdamage = mindamage + d
1198 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1199 // so the last condition is not needed
1201 e.fire_damagepersec = totaldamage / totaltime;
1202 e.fire_endtime = time + totaltime;
1203 if(totaldamage > 1.2 * mindamage)
1205 e.fire_deathtype = dt;
1206 if(e.fire_owner != o)
1209 e.fire_hitsound = FALSE;
1212 if(accuracy_isgooddamage(o, e))
1213 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1214 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1221 e.fire_damagepersec = dps;
1222 e.fire_endtime = time + t;
1223 e.fire_deathtype = dt;
1225 e.fire_hitsound = FALSE;
1226 if(accuracy_isgooddamage(o, e))
1227 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1232 void Fire_ApplyDamage(entity e)
1237 if not(Fire_IsBurning(e))
1240 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1241 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1244 // water and slime stop fire
1246 if(e.watertype != CONTENT_LAVA)
1250 if(e.freezetag_frozen)
1253 t = min(frametime, e.fire_endtime - time);
1254 d = e.fire_damagepersec * t;
1256 hi = e.fire_owner.hitsound;
1257 ty = e.fire_owner.typehitsound;
1258 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1259 if(e.fire_hitsound && e.fire_owner)
1261 e.fire_owner.hitsound = hi;
1262 e.fire_owner.typehitsound = ty;
1264 e.fire_hitsound = TRUE;
1266 if not(IS_INDEPENDENT_PLAYER(e))
1267 FOR_EACH_PLAYER(other) if(e != other)
1269 if(other.classname == "player")
1270 if(other.deadflag == DEAD_NO)
1271 if not(IS_INDEPENDENT_PLAYER(other))
1272 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1274 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1275 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1276 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1281 void Fire_ApplyEffect(entity e)
1283 if(Fire_IsBurning(e))
1284 e.effects |= EF_FLAME;
1286 e.effects &~= EF_FLAME;
1289 void fireburner_think()
1291 // for players, this is done in the regular loop
1292 if(wasfreed(self.owner))
1297 Fire_ApplyEffect(self.owner);
1298 if(!Fire_IsBurning(self.owner))
1300 self.owner.fire_burner = world;
1304 Fire_ApplyDamage(self.owner);
1305 self.nextthink = time;