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);
17 WriteByte(MSG_ENTITY, self.species);
21 void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, float deathtype, float bloodtype, entity dmgowner)
23 // TODO maybe call this from non-edgedamage too?
24 // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
28 if(!sound_allowed(MSG_BROADCAST, dmgowner))
33 e.projectiledeathtype = deathtype;
35 e.dmg_edge = edgedamage;
37 e.dmg_force = vlen(force);
39 e.oldorigin_x = compressShortVector(e.velocity);
40 e.species = bloodtype;
42 Net_LinkEntity(e, FALSE, 0.2, Damage_DamageInfo_SendEntity);
45 float checkrules_firstblood;
48 float damage_goodhits;
49 float damage_gooddamage;
52 .float teamkill_complain;
53 .float teamkill_soundtime;
54 .entity teamkill_soundsource;
57 .float taunt_soundtime;
60 float IsDifferentTeam(entity a, entity b)
75 float IsFlying(entity a)
77 if(a.flags & FL_ONGROUND)
79 if(a.waterlevel >= WATERLEVEL_SWIMMING)
81 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
82 if(trace_fraction < 1)
87 void UpdateFrags(entity player, float f)
89 PlayerTeamScore_AddScore(player, f);
92 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
93 void W_SwitchWeapon_Force(entity e, float w);
94 entity GiveFrags_randomweapons;
95 void GiveFrags (entity attacker, entity targ, float f, float deathtype)
97 // TODO route through PlayerScores instead
105 PlayerScore_Add(attacker, SP_SUICIDES, 1);
110 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
116 PlayerScore_Add(attacker, SP_KILLS, 1);
118 PlayerStats_Event(attacker, sprintf("kills-%d", targ.playerid), 1);
121 PlayerScore_Add(targ, SP_DEATHS, 1);
124 if(autocvar_g_arena_roundbased)
127 if(targ != attacker) // not for suicides
128 if(g_weaponarena_random)
130 // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
132 culprit = DEATH_WEAPONOF(deathtype);
134 culprit = attacker.weapon;
135 else if(!WEPSET_CONTAINS_EW(attacker, culprit))
136 culprit = attacker.weapon;
138 if(g_weaponarena_random_with_laser && culprit == WEP_LASER)
144 if(!GiveFrags_randomweapons)
146 GiveFrags_randomweapons = spawn();
147 GiveFrags_randomweapons.classname = "GiveFrags_randomweapons";
151 WEPSET_COPY_EA(GiveFrags_randomweapons, warmup_start_weapons);
153 WEPSET_COPY_EA(GiveFrags_randomweapons, start_weapons);
155 // all others (including the culprit): remove
156 WEPSET_ANDNOT_EE(GiveFrags_randomweapons, attacker);
157 WEPSET_ANDNOT_EW(GiveFrags_randomweapons, culprit);
159 // among the remaining ones, choose one by random
160 W_RandomWeapons(GiveFrags_randomweapons, 1);
162 if(!WEPSET_EMPTY_E(GiveFrags_randomweapons))
164 WEPSET_OR_EE(attacker, GiveFrags_randomweapons);
165 WEPSET_ANDNOT_EW(attacker, culprit);
169 // after a frag, choose another random weapon set
170 if not(WEPSET_CONTAINS_EW(attacker, 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 attacker.totalfrags += f;
216 UpdateFrags(attacker, f);
219 /*string Obituary_ExtraFragInfo(entity player) // Extra fragmessage information
221 string health_output = string_null;
222 string ping_output = string_null;
223 string handicap_output = string_null;
224 string output = string_null;
226 if(autocvar_sv_fraginfo && ((autocvar_sv_fraginfo == 2) || inWarmupStage))
228 // health/armor of attacker (person who killed you)
229 if(autocvar_sv_fraginfo_stats && (player.health >= 1))
230 health_output = strcat("^7(Health ^1", ftos(rint(player.health)), "^7 / Armor ^2", ftos(rint(player.armorvalue)), "^7)");
233 if(autocvar_sv_fraginfo_ping)
234 ping_output = ((clienttype(player) == CLIENTTYPE_BOT) ? "^2Bot" : strcat("Ping ", ((player.ping >= 150) ? "^1" : "^2"), ftos(rint(player.ping)), "ms"));
237 if(autocvar_sv_fraginfo_handicap)
239 if(autocvar_sv_fraginfo_handicap == 2)
240 handicap_output = strcat(output, strcat("Handicap ^2", ((player.cvar_cl_handicap <= 1) ? "Off" : ftos(rint(player.cvar_cl_handicap)))));
241 else if(player.cvar_cl_handicap) // with _handicap 1, only show this if there actually is a handicap enabled.
242 handicap_output = strcat("Handicap ^2", ftos(rint(player.cvar_cl_handicap)));
246 output = strcat(health_output, (health_output ? ((ping_output || handicap_output) ? " ^7(" : "") : ((ping_output || handicap_output) ? "^7(" : "")),
247 ping_output, (handicap_output ? "^7 / " : ""),
248 handicap_output, ((ping_output || handicap_output) ? "^7)" : ""));
250 // add new line to the beginning if there is a message
251 if(output) { output = strcat("\n", output); }
257 string AppendItemcodes(string s, entity player)
262 // w = player.switchweapon;
264 w = player.cnt; // previous weapon!
265 s = strcat(s, ftos(w));
266 if(time < player.strength_finished)
268 if(time < player.invincible_finished)
270 if(player.flagcarried != world)
272 if(player.BUTTON_CHAT)
277 s = strcat(s, "|", ftos(player.runes));
281 void LogDeath(string mode, float deathtype, entity killer, entity killed)
284 if(!autocvar_sv_eventlog)
286 s = strcat(":kill:", mode);
287 s = strcat(s, ":", ftos(killer.playerid));
288 s = strcat(s, ":", ftos(killed.playerid));
289 s = strcat(s, ":type=", Deathtype_Name(deathtype));
290 s = strcat(s, ":items=");
291 s = AppendItemcodes(s, killer);
294 s = strcat(s, ":victimitems=");
295 s = AppendItemcodes(s, killed);
300 #define INFO_NO_MSG 0
302 void Obituary_SpecialDeath(entity notif_target, float murder, float deathtype, string s1, string s2, float f1, float f2, float f3)
304 float handled = 0, hits = 0;
305 if(DEATH_ISSPECIAL(deathtype))
307 #define DEATHTYPE(name,msg_death,msg_death_by,position) \
308 { if(deathtype == max(0, name)) \
310 #if msg_death != NO_MSG \
313 Send_Notification_Legacy_Wrapper(NOTIF_ONE, notif_target, MSG_DEATH, msg_death, s1, s2, f1, f2, f3); \
314 Send_Notification_Legacy_Wrapper(NOTIF_ANY_EXCEPT, notif_target, MSG_INFO, INFO_##msg_death, s1, s2, f1, f2, f3); \
318 #if msg_death_by != NO_MSG \
321 Send_Notification_Legacy_Wrapper(NOTIF_ONE, notif_target, MSG_DEATH, msg_death_by, s1, s2, f1, f2, f3); \
322 Send_Notification_Legacy_Wrapper(NOTIF_ANY_EXCEPT, notif_target, MSG_INFO, INFO_##msg_death_by, s1, s2, f1, f2, f3); \
334 backtrace("Obituary_SpecialDeath(): Unhandled deathtype- Please notify Samual!\n");
338 dprint(sprintf("Obituary_SpecialDeath(): ^1Deathtype ^7(%s-%d)^1 has no notification!\n", Deathtype_Name(deathtype), deathtype));
345 float Obituary_WeaponDeath(entity notif_target, float murder, float deathtype, string s1, string s2, float f1)
347 float death_weapon = DEATH_WEAPONOF(deathtype);
351 w_deathtype = deathtype;
352 float death_message = weapon_action(death_weapon, ((murder) ? WR_KILLMESSAGE : WR_SUICIDEMESSAGE));
357 Send_Notification_Legacy_Wrapper(NOTIF_ONE, notif_target, MSG_WEAPON, death_message, s1, s2, f1, NO_FL_ARG, NO_FL_ARG);
358 Send_Notification_Legacy_Wrapper(NOTIF_ANY_EXCEPT, notif_target, MSG_INFO, Get_Notif_Infval(MSG_WEAPON, death_message), s1, s2, f1, NO_FL_ARG, NO_FL_ARG);
359 //print(Get_Field_Value(F_INFVAL, MSG_WEAPON, death_message), "\n");
361 else { dprint(sprintf("Obituary_WeaponDeath(): ^1Deathtype ^7(%s-%d)^1 has no notification for weapon %d!\n", Deathtype_Name(deathtype), deathtype, death_weapon)); }
369 void Obituary(entity attacker, entity inflictor, entity targ, float deathtype)
372 if not(targ.classname == STR_PLAYER) { backtrace("Obituary called on non-player?!\n"); return; }
375 string s1 = NO_STR_ARG, s2 = NO_STR_ARG;
376 float f1 = NO_FL_ARG, f2 = NO_FL_ARG, f3 = NO_FL_ARG;
377 float notif_firstblood = FALSE;
379 //dprint(sprintf("Obituary(): Deathtype = %s (%d), Attacker = %s, Inflictor = %s, Target = %s...\n", Deathtype_Name(deathtype), deathtype, attacker.netname, inflictor.netname, targ.netname));
386 if(DEATH_ISSPECIAL(deathtype))
388 if(deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
397 case DEATH_MIRRORDAMAGE:
413 LogDeath("suicide", deathtype, targ, targ);
414 GiveFrags(attacker, targ, -1, deathtype);
417 Obituary_SpecialDeath(targ, FALSE, deathtype, s1, s2, f1, f2, NO_FL_ARG);
419 else if not(Obituary_WeaponDeath(targ, FALSE, deathtype, targ.netname, NO_STR_ARG, targ.killcount))
421 backtrace("SUICIDE: what the hell happened here?\n");
428 else if(attacker.classname == "player")
430 s1 = attacker.netname;
433 // TODO: ADD REAL CHECK HERE!
434 attacker.FRAG_VERBOSE = TRUE;
435 targ.FRAG_VERBOSE = TRUE;
437 if(!IsDifferentTeam(attacker, targ))
439 LogDeath("tk", deathtype, attacker, targ);
440 GiveFrags(attacker, targ, -1, deathtype);
442 attacker.killcount = 0;
444 Send_Notification_Legacy_Wrapper(NOTIF_ONE, attacker, MSG_DEATH, DEATH_TEAMKILL_FRAG, s2, NO_STR_ARG, NO_FL_ARG, NO_FL_ARG, NO_FL_ARG);
445 Send_Notification_Legacy_Wrapper(NOTIF_ONE, targ, MSG_DEATH, DEATH_TEAMKILL_FRAGGED, s1, NO_STR_ARG, NO_FL_ARG, NO_FL_ARG, NO_FL_ARG);
446 Send_Notification_Legacy_Wrapper(NOTIF_ANY, world, MSG_INFO, APP_TEAM_NUM_4(targ.team, INFO_DEATH_TEAMKILL_), s2, s1, targ.killcount, NO_FL_ARG, NO_FL_ARG);
448 // In this case, the death message will ALWAYS be "foo was betrayed by bar"
449 // No need for specific death/weapon messages...
453 LogDeath("frag", deathtype, attacker, targ);
454 GiveFrags(attacker, targ, 1, deathtype);
456 attacker.taunt_soundtime = time + 1;
457 attacker.killcount = attacker.killcount + 1;
459 #define ADD_ACHIEVEMENT_CASE(numa,numb) \
462 AnnounceTo(attacker, strcat(#numb, "kills")); \
463 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_##numa, 1); \
466 switch(attacker.killcount)
468 ADD_ACHIEVEMENT_CASE(3, 03)
469 ADD_ACHIEVEMENT_CASE(5, 05)
470 ADD_ACHIEVEMENT_CASE(10, 10)
471 ADD_ACHIEVEMENT_CASE(15, 15)
472 ADD_ACHIEVEMENT_CASE(20, 20)
473 ADD_ACHIEVEMENT_CASE(25, 25)
474 ADD_ACHIEVEMENT_CASE(30, 30)
477 #undef ADD_ACHIEVEMENT_CASE
479 if(!checkrules_firstblood)
481 checkrules_firstblood = TRUE;
482 notif_firstblood = TRUE; // modify the current messages so that they too show firstblood information
483 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
484 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
487 if(notif_firstblood) // first blood, no kill sprees yet
491 Send_Notification_Legacy_Wrapper(NOTIF_ONE, attacker, MSG_DEATH, (attacker.FRAG_VERBOSE ? DEATH_MURDER_TYPEFRAG_FIRST_VERBOSE : DEATH_MURDER_TYPEFRAG_FIRST),
492 s2, s1, (attacker.FRAG_VERBOSE ? ((clienttype(targ) == CLIENTTYPE_BOT) ? BOT_PING : targ.ping) : NO_FL_ARG), NO_FL_ARG, NO_FL_ARG);
494 Send_Notification_Legacy_Wrapper(NOTIF_ONE, targ, MSG_DEATH, (targ.FRAG_VERBOSE ? DEATH_MURDER_TYPEFRAGGED_FIRST_VERBOSE : DEATH_MURDER_TYPEFRAGGED_FIRST),
495 s1, NO_STR_ARG, (targ.FRAG_VERBOSE ? attacker.health : NO_FL_ARG), (targ.FRAG_VERBOSE ? attacker.armorvalue : NO_FL_ARG), (targ.FRAG_VERBOSE ? ((clienttype(attacker) == CLIENTTYPE_BOT) ? BOT_PING : attacker.ping) : NO_FL_ARG));
499 Send_Notification_Legacy_Wrapper(NOTIF_ONE, attacker, MSG_DEATH, (attacker.FRAG_VERBOSE ? DEATH_MURDER_FRAG_FIRST_VERBOSE : DEATH_MURDER_FRAG_FIRST),
500 s2, s1, (attacker.FRAG_VERBOSE ? ((clienttype(targ) == CLIENTTYPE_BOT) ? BOT_PING : targ.ping) : NO_FL_ARG), NO_FL_ARG, NO_FL_ARG);
502 Send_Notification_Legacy_Wrapper(NOTIF_ONE, targ, MSG_DEATH, (targ.FRAG_VERBOSE ? DEATH_MURDER_FRAGGED_FIRST_VERBOSE : DEATH_MURDER_FRAGGED_FIRST),
503 s1, NO_STR_ARG, (targ.FRAG_VERBOSE ? attacker.health : NO_FL_ARG), (targ.FRAG_VERBOSE ? attacker.armorvalue : NO_FL_ARG), (targ.FRAG_VERBOSE ? ((clienttype(attacker) == CLIENTTYPE_BOT) ? BOT_PING : attacker.ping) : NO_FL_ARG));
506 else // normal frags, kill sprees listed
510 Send_Notification_Legacy_Wrapper(NOTIF_ONE, attacker, MSG_DEATH, (attacker.FRAG_VERBOSE ? DEATH_MURDER_TYPEFRAG_VERBOSE : DEATH_MURDER_TYPEFRAG),
511 s2, NO_STR_ARG, attacker.killcount, (attacker.FRAG_VERBOSE ? ((clienttype(targ) == CLIENTTYPE_BOT) ? BOT_PING : targ.ping) : NO_FL_ARG), NO_FL_ARG);
513 Send_Notification_Legacy_Wrapper(NOTIF_ONE, targ, MSG_DEATH, (targ.FRAG_VERBOSE ? DEATH_MURDER_TYPEFRAGGED_VERBOSE : DEATH_MURDER_TYPEFRAGGED),
514 s1, NO_STR_ARG, (targ.FRAG_VERBOSE ? attacker.health : NO_FL_ARG), (targ.FRAG_VERBOSE ? attacker.armorvalue : NO_FL_ARG), (targ.FRAG_VERBOSE ? ((clienttype(attacker) == CLIENTTYPE_BOT) ? BOT_PING : attacker.ping) : NO_FL_ARG));
518 Send_Notification_Legacy_Wrapper(NOTIF_ONE, attacker, MSG_DEATH, (attacker.FRAG_VERBOSE ? DEATH_MURDER_FRAG_VERBOSE : DEATH_MURDER_FRAG),
519 s2, NO_STR_ARG, attacker.killcount, (attacker.FRAG_VERBOSE ? ((clienttype(targ) == CLIENTTYPE_BOT) ? BOT_PING : targ.ping) : NO_FL_ARG), NO_FL_ARG);
521 Send_Notification_Legacy_Wrapper(NOTIF_ONE, targ, MSG_DEATH, (targ.FRAG_VERBOSE ? DEATH_MURDER_FRAGGED_VERBOSE : DEATH_MURDER_FRAGGED),
522 s1, NO_STR_ARG, (targ.FRAG_VERBOSE ? attacker.health : NO_FL_ARG), (targ.FRAG_VERBOSE ? attacker.armorvalue : NO_FL_ARG), (targ.FRAG_VERBOSE ? ((clienttype(attacker) == CLIENTTYPE_BOT) ? BOT_PING : attacker.ping) : NO_FL_ARG));
526 //print("targ_killcount = ", ftos(targ.killcount), ", attacker_killcount = ", ftos(attacker.killcount), ".\n");
527 if not(Obituary_WeaponDeath(targ, TRUE, deathtype, targ.netname, attacker.netname, targ.killcount))
528 Obituary_SpecialDeath(targ, TRUE, deathtype, s2, s1, targ.killcount, NO_FL_ARG, NO_FL_ARG);
539 // For now, we're just forcing HURTTRIGGER to behave as "DEATH_VOID" and giving it no special options...
540 // Later on you will only be able to make custom messages using DEATH_CUSTOM,
541 // and there will be a REAL DEATH_VOID implementation which mappers will use.
542 /*case DEATH_HURTTRIGGER:
545 s2 = inflictor.message;
546 if(strstrofs(s2, "%", 0) < 0) { s2 = strcat("%s ", s2); }
555 if(strstrofs(s2, "%", 0) < 0) { s2 = strcat("%s ", s2); }
570 LogDeath("accident", deathtype, targ, targ);
571 GiveFrags(targ, targ, -1, deathtype);
573 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5)
575 AnnounceTo(targ, "botlike");
576 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
579 Obituary_SpecialDeath(targ, FALSE, deathtype, s1, s2, f1, f2, f3);
582 // Set final information for the death
583 targ.death_origin = targ.origin;
584 if(targ != attacker) { targ.killer_origin = attacker.origin; }
585 if(targ.killcount) { targ.killcount = 0; }
588 // these are updated by each Damage call for use in button triggering and such
590 entity damage_inflictor;
591 entity damage_attacker;
593 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
598 entity attacker_save;
602 if (gameover || targ.killcount == -666)
609 damage_inflictor = inflictor;
610 damage_attacker = attacker;
611 attacker_save = attacker;
613 if(targ.classname == "player")
616 if(targ.hook.aiment == attacker)
617 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
619 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
620 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
622 if(targ.classname == "player")
623 if not(IsDifferentTeam(targ, attacker))
630 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
632 // These are ALWAYS lethal
633 // No damage modification here
634 // Instead, prepare the victim for his death...
636 targ.spawnshieldtime = 0;
637 targ.health = 0.9; // this is < 1
638 targ.flags -= targ.flags & FL_GODMODE;
641 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
648 skill based bot damage? gtfo. (tZork)
649 if (targ.classname == "player")
650 if (attacker.classname == "player")
653 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
656 // nullify damage if teamplay is on
657 if(deathtype != DEATH_TELEFRAG)
658 if(attacker.classname == "player")
660 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
665 else if(!IsDifferentTeam(attacker, targ))
667 if(autocvar_teamplay_mode == 1)
669 else if(attacker != targ)
671 if(autocvar_teamplay_mode == 3)
673 else if(autocvar_teamplay_mode == 4)
675 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
677 teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
678 attacker.dmg_team = attacker.dmg_team + damage;
679 if(attacker.dmg_team > teamdamage0 && !g_ca)
680 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
681 mirrorforce = autocvar_g_mirrordamage * vlen(force);
684 if(autocvar_g_friendlyfire == 0)
690 damage = autocvar_g_friendlyfire * damage;
691 // mirrordamage will be used LATER
693 if(autocvar_g_mirrordamage_virtual)
695 vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
696 attacker.dmg_take += v_x;
697 attacker.dmg_save += v_y;
698 attacker.dmg_inflictor = inflictor;
699 mirrordamage = v_z; // = 0, to make fteqcc stfu
703 if(autocvar_g_friendlyfire_virtual)
705 vector v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
706 targ.dmg_take += v_x;
707 targ.dmg_save += v_y;
708 targ.dmg_inflictor = inflictor;
710 if(!autocvar_g_friendlyfire_virtual_force)
721 if(targ.classname == "player")
722 if(attacker.classname == "player")
725 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
726 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
729 if(targ.classname == "player")
732 if ((deathtype == DEATH_FALL) ||
733 (deathtype == DEATH_DROWN) ||
734 (deathtype == DEATH_SLIME) ||
735 (deathtype == DEATH_LAVA) ||
736 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
743 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
745 targ.armorvalue -= 1;
746 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
749 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
751 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
755 if (targ != attacker)
757 if ((targ.health >= 1) && (targ.classname == "player"))
758 centerprint(attacker, "Secondary fire inflicts no damage!");
766 if not(DEATH_ISSPECIAL(deathtype))
768 damage *= g_weapondamagefactor;
769 mirrordamage *= g_weapondamagefactor;
770 force = force * g_weaponforcefactor;
771 mirrorforce *= g_weaponforcefactor;
774 // should this be changed at all? If so, in what way?
775 frag_attacker = attacker;
777 frag_damage = damage;
779 frag_deathtype = deathtype;
780 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
781 damage = frag_damage;
784 // apply strength multiplier
785 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
789 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
790 force = force * autocvar_g_balance_powerup_strength_selfforce;
794 damage = damage * autocvar_g_balance_powerup_strength_damage;
795 force = force * autocvar_g_balance_powerup_strength_force;
799 // apply invincibility multiplier
800 if (targ.items & IT_INVINCIBLE && !g_minstagib)
801 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
803 if (targ == attacker)
805 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
808 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
813 // apply strength rune
814 if (attacker.runes & RUNE_STRENGTH)
816 if(attacker.runes & CURSE_WEAK) // have both curse & rune
818 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
819 force = force * autocvar_g_balance_rune_strength_combo_force;
823 damage = damage * autocvar_g_balance_rune_strength_damage;
824 force = force * autocvar_g_balance_rune_strength_force;
827 else if (attacker.runes & CURSE_WEAK)
829 damage = damage * autocvar_g_balance_curse_weak_damage;
830 force = force * autocvar_g_balance_curse_weak_force;
833 // apply defense rune
834 if (targ.runes & RUNE_DEFENSE)
836 if (targ.runes & CURSE_VULNER) // have both curse & rune
837 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
839 damage = damage * autocvar_g_balance_rune_defense_takedamage;
841 else if (targ.runes & CURSE_VULNER)
842 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
848 if(targ.takedamage == DAMAGE_AIM)
852 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
857 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
859 if(IsDifferentTeam(victim, attacker))
863 if(deathtype != DEATH_FIRE)
865 if(victim.BUTTON_CHAT)
866 attacker.typehitsound += 1;
868 attacker.hitsound += 1;
871 damage_goodhits += 1;
872 damage_gooddamage += damage;
874 if not(DEATH_ISSPECIAL(deathtype))
876 if(targ.classname == "player") // don't do this for vehicles
882 if(victim.items & IT_STRENGTH)
889 if(deathtype != DEATH_FIRE)
891 attacker.typehitsound += 1;
894 if(time > attacker.teamkill_complain)
896 attacker.teamkill_complain = time + 5;
897 attacker.teamkill_soundtime = time + 0.4;
898 attacker.teamkill_soundsource = targ;
906 if (self.damageforcescale)
908 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
910 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
911 if(self.movetype == MOVETYPE_PHYSICS)
915 farcent.classname = "farce";
916 farcent.enemy = self;
917 farcent.movedir = farce * 10;
919 farcent.movedir = farcent.movedir * self.mass;
920 farcent.origin = hitloc;
921 farcent.forcetype = FORCETYPE_FORCEATPOS;
922 farcent.nextthink = time + 0.1;
923 farcent.think = SUB_Remove;
926 self.velocity = self.velocity + farce;
927 self.flags &~= FL_ONGROUND;
928 UpdateCSQCProjectile(self);
931 if (damage != 0 || (self.damageforcescale && vlen(force)))
932 if (self.event_damage)
933 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
936 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
940 if (attacker.runes & RUNE_VAMPIRE)
942 // apply vampire rune
943 if (attacker.runes & CURSE_EMPATHY) // have the curse too
945 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
946 attacker.health = bound(
947 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
948 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
949 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
953 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
954 attacker.health = bound(
955 attacker.health, // LA: was 3, but changed so that you can't lose health
956 // empathy won't let you gain health in the same way...
957 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
958 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
961 // apply empathy curse
962 else if (attacker.runes & CURSE_EMPATHY)
964 attacker.health = bound(
965 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
966 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
972 // apply mirror damage if any
973 if(mirrordamage > 0 || mirrorforce > 0)
975 attacker = attacker_save;
979 // just lose extra LIVES, don't kill the player for mirror damage
980 if(attacker.armorvalue > 0)
982 attacker.armorvalue = attacker.armorvalue - 1;
983 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
984 attacker.hitsound += 1;
989 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
990 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
994 float RadiusDamage_running;
995 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
996 // Returns total damage applies to creatures
1001 float total_damage_to_creatures;
1006 float stat_damagedone;
1008 if(RadiusDamage_running)
1010 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
1014 RadiusDamage_running = 1;
1016 tfloordmg = autocvar_g_throughfloor_damage;
1017 tfloorforce = autocvar_g_throughfloor_force;
1019 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1020 total_damage_to_creatures = 0;
1022 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1023 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
1025 force = inflictor.velocity;
1026 if(vlen(force) == 0)
1029 force = normalize(force);
1030 if(forceintensity >= 0)
1031 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
1033 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
1036 stat_damagedone = 0;
1038 targ = WarpZone_FindRadius (blastorigin, rad + MAX_DAMAGEEXTRARADIUS, FALSE);
1042 if (targ != inflictor)
1043 if (ignore != targ) if(targ.takedamage)
1049 // LordHavoc: measure distance to nearest point on target (not origin)
1050 // (this guarentees 100% damage on a touch impact)
1051 nearest = targ.WarpZone_findradius_nearest;
1052 diff = targ.WarpZone_findradius_dist;
1053 // round up a little on the damage to ensure full damage on impacts
1054 // and turn the distance into a fraction of the radius
1055 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
1057 //bprint(ftos(power));
1058 //if (targ == attacker)
1059 // print(ftos(power), "\n");
1065 finaldmg = coredamage * power + edgedamage * (1 - power);
1071 vector myblastorigin;
1074 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1076 // if it's a player, use the view origin as reference
1077 center = CENTER_OR_VIEWOFS(targ);
1079 force = normalize(center - myblastorigin);
1080 force = force * (finaldmg / coredamage) * forceintensity;
1083 if(targ != directhitentity)
1088 float mininv_f, mininv_d;
1090 // test line of sight to multiple positions on box,
1091 // and do damage if any of them hit
1094 // we know: max stddev of hitratio = 1 / (2 * sqrt(n))
1095 // so for a given max stddev:
1096 // n = (1 / (2 * max stddev of hitratio))^2
1098 mininv_d = (finaldmg * (1-tfloordmg)) / autocvar_g_throughfloor_damage_max_stddev;
1099 mininv_f = (vlen(force) * (1-tfloorforce)) / autocvar_g_throughfloor_force_max_stddev;
1101 if(autocvar_g_throughfloor_debug)
1102 print(sprintf("THROUGHFLOOR: D=%f F=%f max(dD)=1/%f max(dF)=1/%f", finaldmg, vlen(force), mininv_d, mininv_f));
1104 total = 0.25 * pow(max(mininv_f, mininv_d), 2);
1106 if(autocvar_g_throughfloor_debug)
1107 print(sprintf(" steps=%f", total));
1109 if (targ.classname == "player")
1110 total = ceil(bound(autocvar_g_throughfloor_min_steps_player, total, autocvar_g_throughfloor_max_steps_player));
1112 total = ceil(bound(autocvar_g_throughfloor_min_steps_other, total, autocvar_g_throughfloor_max_steps_other));
1114 if(autocvar_g_throughfloor_debug)
1115 print(sprintf(" steps=%f dD=%f dF=%f", total, finaldmg * (1-tfloordmg) / (2 * sqrt(total)), vlen(force) * (1-tfloorforce) / (2 * sqrt(total))));
1117 for(c = 0; c < total; ++c)
1119 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1120 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1121 if (trace_fraction == 1 || trace_ent == targ)
1125 hitloc = hitloc + nearest;
1129 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1130 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1131 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1134 nearest = hitloc * (1 / max(1, hits));
1135 hitratio = (hits / total);
1136 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1137 finaldmg = finaldmg * a;
1138 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1141 if(autocvar_g_throughfloor_debug)
1142 print(sprintf(" D=%f F=%f\n", finaldmg, vlen(force)));
1145 // laser force adjustments :P
1146 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1148 if (targ == attacker)
1153 float force_velocitybiasramp;
1154 float force_velocitybias;
1156 force_velocitybiasramp = autocvar_sv_maxspeed;
1157 if(deathtype & HITTYPE_SECONDARY)
1159 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1160 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1164 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1165 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1168 vel = targ.velocity;
1170 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1174 normalize(normalize(force) + vel);
1176 force_z *= force_zscale;
1180 if(deathtype & HITTYPE_SECONDARY)
1182 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1186 force *= autocvar_g_balance_laser_primary_force_other_scale;
1191 //if (targ == attacker)
1193 // print("hits ", ftos(hits), " / ", ftos(total));
1194 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1195 // print(" (", ftos(a), ")\n");
1197 if(finaldmg || vlen(force))
1201 total_damage_to_creatures += finaldmg;
1203 if(accuracy_isgooddamage(attacker, targ))
1204 stat_damagedone += finaldmg;
1207 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1208 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1210 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1218 RadiusDamage_running = 0;
1220 if(!DEATH_ISSPECIAL(deathtype))
1221 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1223 return total_damage_to_creatures;
1226 .float fire_damagepersec;
1227 .float fire_endtime;
1228 .float fire_deathtype;
1230 .float fire_hitsound;
1231 .entity fire_burner;
1233 void fireburner_think();
1235 float Fire_IsBurning(entity e)
1237 return (time < e.fire_endtime);
1240 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1243 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1245 if(e.classname == "player")
1254 // print("adding a fire burner to ", e.classname, "\n");
1255 e.fire_burner = spawn();
1256 e.fire_burner.classname = "fireburner";
1257 e.fire_burner.think = fireburner_think;
1258 e.fire_burner.nextthink = time;
1259 e.fire_burner.owner = e;
1265 if(Fire_IsBurning(e))
1267 mintime = e.fire_endtime - time;
1268 maxtime = max(mintime, t);
1270 mindps = e.fire_damagepersec;
1271 maxdps = max(mindps, dps);
1273 if(maxtime > mintime || maxdps > mindps)
1277 // damage we have right now
1278 mindamage = mindps * mintime;
1280 // damage we want to get
1281 maxdamage = mindamage + d;
1283 // but we can't exceed maxtime * maxdps!
1284 totaldamage = min(maxdamage, maxtime * maxdps);
1288 // totaldamage = min(mindamage + d, maxtime * maxdps)
1290 // totaldamage <= maxtime * maxdps
1291 // ==> totaldamage / maxdps <= maxtime.
1293 // totaldamage / mindps = min(mindamage / mindps + d, maxtime * maxdps / mindps)
1294 // >= min(mintime, maxtime)
1295 // ==> totaldamage / maxdps >= mintime.
1298 // how long do we damage then?
1299 // at least as long as before
1300 // but, never exceed maxdps
1301 totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime due to lemma
1305 // at most as long as maximum allowed
1306 // but, never below mindps
1307 totaltime = min(maxtime, totaldamage / mindps); // always >= mintime due to lemma
1309 // assuming t > mintime, dps > mindps:
1310 // we get d = t * dps = maxtime * maxdps
1311 // totaldamage = min(maxdamage, maxtime * maxdps) = min(... + d, maxtime * maxdps) = maxtime * maxdps
1312 // totaldamage / maxdps = maxtime
1313 // totaldamage / mindps > totaldamage / maxdps = maxtime
1315 // a) totaltime = max(mintime, maxtime) = maxtime
1316 // b) totaltime = min(maxtime, totaldamage / maxdps) = maxtime
1318 // assuming t <= mintime:
1319 // we get maxtime = mintime
1320 // a) totaltime = max(mintime, ...) >= mintime, also totaltime <= maxtime by the lemma, therefore totaltime = mintime = maxtime
1321 // b) totaltime = min(maxtime, ...) <= maxtime, also totaltime >= mintime by the lemma, therefore totaltime = mintime = maxtime
1323 // assuming dps <= mindps:
1324 // we get mindps = maxdps.
1325 // With this, the lemma says that mintime <= totaldamage / mindps = totaldamage / maxdps <= maxtime.
1326 // a) totaltime = max(mintime, totaldamage / maxdps) = totaldamage / maxdps
1327 // b) totaltime = min(maxtime, totaldamage / mindps) = totaldamage / maxdps
1329 e.fire_damagepersec = totaldamage / totaltime;
1330 e.fire_endtime = time + totaltime;
1331 if(totaldamage > 1.2 * mindamage)
1333 e.fire_deathtype = dt;
1334 if(e.fire_owner != o)
1337 e.fire_hitsound = FALSE;
1340 if(accuracy_isgooddamage(o, e))
1341 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1342 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1349 e.fire_damagepersec = dps;
1350 e.fire_endtime = time + t;
1351 e.fire_deathtype = dt;
1353 e.fire_hitsound = FALSE;
1354 if(accuracy_isgooddamage(o, e))
1355 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1360 void Fire_ApplyDamage(entity e)
1365 if not(Fire_IsBurning(e))
1368 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1369 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1372 // water and slime stop fire
1374 if(e.watertype != CONTENT_LAVA)
1378 if(e.freezetag_frozen)
1381 t = min(frametime, e.fire_endtime - time);
1382 d = e.fire_damagepersec * t;
1384 hi = e.fire_owner.hitsound;
1385 ty = e.fire_owner.typehitsound;
1386 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1387 if(e.fire_hitsound && e.fire_owner)
1389 e.fire_owner.hitsound = hi;
1390 e.fire_owner.typehitsound = ty;
1392 e.fire_hitsound = TRUE;
1394 if not(IS_INDEPENDENT_PLAYER(e))
1395 FOR_EACH_PLAYER(other) if(e != other)
1397 if(other.classname == "player")
1398 if(other.deadflag == DEAD_NO)
1399 if not(IS_INDEPENDENT_PLAYER(other))
1400 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1402 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1403 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1404 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1409 void Fire_ApplyEffect(entity e)
1411 if(Fire_IsBurning(e))
1412 e.effects |= EF_FLAME;
1414 e.effects &~= EF_FLAME;
1417 void fireburner_think()
1419 // for players, this is done in the regular loop
1420 if(wasfreed(self.owner))
1425 Fire_ApplyEffect(self.owner);
1426 if(!Fire_IsBurning(self.owner))
1428 self.owner.fire_burner = world;
1432 Fire_ApplyDamage(self.owner);
1433 self.nextthink = time;