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=", ftos(deathtype));
290 s = strcat(s, ":items=");
291 s = AppendItemcodes(s, killer);
294 s = strcat(s, ":victimitems=");
295 s = AppendItemcodes(s, killed);
300 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
302 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
303 WriteByte(MSG_BROADCAST, TE_CSQC_KILLNOTIFY);
304 WriteString(MSG_BROADCAST, s1);
305 WriteString(MSG_BROADCAST, s2);
306 WriteString(MSG_BROADCAST, s3);
307 WriteShort(MSG_BROADCAST, msg);
308 WriteByte(MSG_BROADCAST, type);
311 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
312 void Send_CSQC_KillCenterprint(entity e, string s1, string s2, float msg, float type)
314 if (clienttype(e) == CLIENTTYPE_REAL)
317 WRITESPECTATABLE_MSG_ONE({
318 WriteByte(MSG_ONE, SVC_TEMPENTITY);
319 WriteByte(MSG_ONE, TE_CSQC_KILLCENTERPRINT);
320 WriteString(MSG_ONE, s1);
321 WriteString(MSG_ONE, s2);
322 WriteShort(MSG_ONE, msg);
323 WriteByte(MSG_ONE, type);
328 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
333 if (targ.classname == "player")
336 a = attacker.netname;
338 if (targ == attacker) // suicides
340 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
341 msg = ColoredTeamName(targ.team); // TODO: check if needed?
344 if(!g_cts) // no "killed your own dumb self" message in CTS
345 Send_CSQC_KillCenterprint(targ, msg, "", deathtype, MSG_SUICIDE);
347 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
349 LogDeath("suicide", deathtype, targ, targ);
350 GiveFrags(attacker, targ, -1, deathtype);
353 if (targ.killcount > 2)
354 msg = ftos(targ.killcount);
357 if(teamplay && deathtype == DEATH_MIRRORDAMAGE)
359 if(attacker.team == COLOR_TEAM1)
360 deathtype = KILL_TEAM_RED;
362 deathtype = KILL_TEAM_BLUE;
365 Send_KillNotification(s, msg, "", deathtype, MSG_SUICIDE);
367 else if (attacker.classname == "player")
369 if(!IsDifferentTeam(attacker, targ))
371 if(attacker.team == COLOR_TEAM1)
372 type = KILL_TEAM_RED;
374 type = KILL_TEAM_BLUE;
376 GiveFrags(attacker, targ, -1, deathtype);
378 Send_CSQC_KillCenterprint(attacker, s, "", type, MSG_KILL);
380 if (targ.killcount > 2)
381 msg = ftos(targ.killcount);
385 if (attacker.killcount > 2) {
386 msg = ftos(attacker.killcount);
387 type = KILL_TEAM_SPREE;
389 Send_KillNotification(a, s, msg, type, MSG_KILL);
391 attacker.killcount = 0;
393 LogDeath("tk", deathtype, attacker, targ);
397 if (!checkrules_firstblood)
399 checkrules_firstblood = TRUE;
400 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
401 // TODO: make these print a newline if they dont
402 Send_CSQC_KillCenterprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
403 Send_CSQC_KillCenterprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
404 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
405 PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
408 if(targ.istypefrag) {
409 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_TYPEFRAG, MSG_KILL);
410 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_TYPEFRAGGED, MSG_KILL);
412 Send_CSQC_KillCenterprint(attacker, s, Obituary_ExtraFragInfo(targ), KILL_FRAG, MSG_KILL);
413 Send_CSQC_KillCenterprint(targ, a, Obituary_ExtraFragInfo(attacker), KILL_FRAGGED, MSG_KILL);
416 attacker.taunt_soundtime = time + 1;
418 if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
419 msg = inflictor.message2;
420 else if (deathtype == DEATH_CUSTOM)
425 if(strstrofs(msg, "%", 0) < 0)
426 msg = strcat("%s ", msg, " by %s");
428 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
430 GiveFrags(attacker, targ, 1, deathtype);
432 if (targ.killcount > 2) {
433 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
436 attacker.killcount = attacker.killcount + 1;
438 if (attacker.killcount == 3)
440 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
441 AnnounceTo(attacker, "03kills");
442 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
444 else if (attacker.killcount == 5)
446 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
447 AnnounceTo(attacker, "05kills");
448 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
450 else if (attacker.killcount == 10)
452 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
453 AnnounceTo(attacker, "10kills");
454 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
456 else if (attacker.killcount == 15)
458 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
459 AnnounceTo(attacker, "15kills");
460 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
462 else if (attacker.killcount == 20)
464 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
465 AnnounceTo(attacker, "20kills");
466 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
468 else if (attacker.killcount == 25)
470 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
471 AnnounceTo(attacker, "25kills");
472 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
474 else if (attacker.killcount == 30)
476 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
477 AnnounceTo(attacker, "30kills");
478 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
480 else if (attacker.killcount > 2) {
481 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
483 LogDeath("frag", deathtype, attacker, targ);
488 Send_CSQC_KillCenterprint(targ, "", "", deathtype, MSG_KILL_ACTION);
489 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
490 msg = inflictor.message;
491 else if (deathtype == DEATH_CUSTOM)
495 if(strstrofs(msg, "%", 0) < 0)
496 msg = strcat("%s ", msg);
498 GiveFrags(targ, targ, -1, deathtype);
499 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
500 AnnounceTo(targ, "botlike");
501 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
503 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
505 if (targ.killcount > 2)
506 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
508 LogDeath("accident", deathtype, targ, targ);
511 targ.death_origin = targ.origin;
513 targ.killer_origin = attacker.origin;
515 // FIXME: this should go in PutClientInServer
523 if(self.owner.health < 1)
528 setorigin(self, self.owner.origin - '0 0 16');
529 self.nextthink = time;
532 void Freeze (entity targ, float freeze_time)
534 float monster = (targ.flags & FL_MONSTER);
535 float player = (targ.flags & FL_CLIENT);
537 if(!player && !monster) // only specified entities can be freezed
540 if(targ.frozen || targ.freezetag_frozen)
544 targ.revive_progress = 0;
546 targ.revive_speed = freeze_time;
551 ice.classname = "ice";
552 ice.scale = targ.scale;
553 ice.think = Ice_Think;
554 ice.nextthink = time;
555 ice.frame = floor(random() * 21); // ice model has 20 different looking frames
556 setmodel(ice, "models/ice/ice.md3");
564 RemoveGrapplingHook(targ);
567 void Unfreeze (entity targ)
570 targ.revive_progress = 0;
571 targ.health = ((targ.classname == STR_PLAYER) ? autocvar_g_balance_health_start : targ.max_health);
573 // remove the ice block
575 for(ice = world; (ice = find(ice, classname, "ice")); ) if(ice.owner == targ)
582 // these are updated by each Damage call for use in button triggering and such
584 entity damage_inflictor;
585 entity damage_attacker;
587 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
591 float complainteamdamage = 0;
592 entity attacker_save;
596 if (gameover || targ.killcount == -666)
603 damage_inflictor = inflictor;
604 damage_attacker = attacker;
605 attacker_save = attacker;
607 if(targ.classname == "player")
610 if(targ.hook.aiment == attacker)
611 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
613 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
614 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
616 if(targ.classname == "player")
617 if not(IsDifferentTeam(targ, attacker))
624 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
626 // These are ALWAYS lethal
627 // No damage modification here
628 // Instead, prepare the victim for his death...
630 targ.spawnshieldtime = 0;
631 targ.health = 0.9; // this is < 1
632 targ.flags -= targ.flags & FL_GODMODE;
635 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
642 skill based bot damage? gtfo. (tZork)
643 if (targ.classname == "player")
644 if (attacker.classname == "player")
647 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
650 // nullify damage if teamplay is on
651 if(deathtype != DEATH_TELEFRAG)
652 if(attacker.classname == "player")
654 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
659 else if(!IsDifferentTeam(attacker, targ))
661 if(autocvar_teamplay_mode == 1)
663 else if(attacker != targ)
665 if(autocvar_teamplay_mode == 3)
667 else if(autocvar_teamplay_mode == 4)
669 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
671 attacker.dmg_team = attacker.dmg_team + damage;
672 complainteamdamage = attacker.dmg_team - autocvar_g_teamdamage_threshold;
673 if(complainteamdamage > 0 && !g_ca) // FIXME why is g_ca ruled out here? Why not just g_mirrordamage 0 on CA servers?
674 mirrordamage = autocvar_g_mirrordamage * complainteamdamage;
675 mirrorforce = autocvar_g_mirrordamage * vlen(force);
678 if(autocvar_g_friendlyfire == 0)
684 damage = autocvar_g_friendlyfire * damage;
685 // mirrordamage will be used LATER
687 if(autocvar_g_mirrordamage_virtual)
689 vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
690 attacker.dmg_take += v_x;
691 attacker.dmg_save += v_y;
692 attacker.dmg_inflictor = inflictor;
693 mirrordamage = v_z; // = 0, to make fteqcc stfu
697 if(autocvar_g_friendlyfire_virtual)
699 vector v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
700 targ.dmg_take += v_x;
701 targ.dmg_save += v_y;
702 targ.dmg_inflictor = inflictor;
704 if(!autocvar_g_friendlyfire_virtual_force)
715 if(targ.classname == "player")
716 if(attacker.classname == "player")
719 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
720 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
723 if(targ.classname == "player")
726 if ((deathtype == DEATH_FALL) ||
727 (deathtype == DEATH_DROWN) ||
728 (deathtype == DEATH_SLIME) ||
729 (deathtype == DEATH_LAVA) ||
730 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
737 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
739 targ.armorvalue -= 1;
740 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
743 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
745 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
749 complainteamdamage = 0;
750 if (targ != attacker)
752 if ((targ.health >= 1) && (targ.classname == "player"))
753 centerprint(attacker, "Secondary fire inflicts no damage!");
761 if not(DEATH_ISSPECIAL(deathtype))
763 damage *= g_weapondamagefactor;
764 mirrordamage *= g_weapondamagefactor;
765 complainteamdamage *= g_weapondamagefactor;
766 force = force * g_weaponforcefactor;
767 mirrorforce *= g_weaponforcefactor;
770 if(targ.frozen && attacker.classname != "monster_spider")
776 // should this be changed at all? If so, in what way?
777 frag_attacker = attacker;
779 frag_damage = damage;
781 frag_deathtype = deathtype;
782 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
783 damage = frag_damage;
786 // apply strength multiplier
787 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
791 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
792 force = force * autocvar_g_balance_powerup_strength_selfforce;
796 damage = damage * autocvar_g_balance_powerup_strength_damage;
797 force = force * autocvar_g_balance_powerup_strength_force;
801 // apply invincibility multiplier
802 if (targ.items & IT_INVINCIBLE && !g_minstagib)
803 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
805 if (targ == attacker)
807 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
810 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
815 // apply strength rune
816 if (attacker.runes & RUNE_STRENGTH)
818 if(attacker.runes & CURSE_WEAK) // have both curse & rune
820 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
821 force = force * autocvar_g_balance_rune_strength_combo_force;
825 damage = damage * autocvar_g_balance_rune_strength_damage;
826 force = force * autocvar_g_balance_rune_strength_force;
829 else if (attacker.runes & CURSE_WEAK)
831 damage = damage * autocvar_g_balance_curse_weak_damage;
832 force = force * autocvar_g_balance_curse_weak_force;
835 // apply defense rune
836 if (targ.runes & RUNE_DEFENSE)
838 if (targ.runes & CURSE_VULNER) // have both curse & rune
839 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
841 damage = damage * autocvar_g_balance_rune_defense_takedamage;
843 else if (targ.runes & CURSE_VULNER)
844 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
850 if(targ.takedamage == DAMAGE_AIM)
854 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
859 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET || victim.flags & FL_MONSTER)
861 if(IsDifferentTeam(victim, attacker))
865 if(deathtype != DEATH_FIRE)
867 if(victim.BUTTON_CHAT)
868 attacker.typehitsound += 1;
870 attacker.hitsound += 1;
873 damage_goodhits += 1;
874 damage_gooddamage += damage;
876 if not(DEATH_ISSPECIAL(deathtype))
878 if(targ.classname == "player") // don't do this for vehicles
884 if(victim.items & IT_STRENGTH)
891 if(deathtype != DEATH_FIRE)
893 attacker.typehitsound += 1;
895 if(complainteamdamage > 0)
896 if(time > attacker.teamkill_complain)
898 attacker.teamkill_complain = time + 5;
899 attacker.teamkill_soundtime = time + 0.4;
900 attacker.teamkill_soundsource = targ;
908 if (self.damageforcescale)
910 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
912 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
913 if(self.movetype == MOVETYPE_PHYSICS)
917 farcent.classname = "farce";
918 farcent.enemy = self;
919 farcent.movedir = farce * 10;
921 farcent.movedir = farcent.movedir * self.mass;
922 farcent.origin = hitloc;
923 farcent.forcetype = FORCETYPE_FORCEATPOS;
924 farcent.nextthink = time + 0.1;
925 farcent.think = SUB_Remove;
928 self.velocity = self.velocity + farce;
929 self.flags &~= FL_ONGROUND;
930 UpdateCSQCProjectile(self);
933 if (damage != 0 || (self.damageforcescale && vlen(force)))
934 if (self.event_damage)
935 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
938 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
942 if (attacker.runes & RUNE_VAMPIRE)
944 // apply vampire rune
945 if (attacker.runes & CURSE_EMPATHY) // have the curse too
947 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
948 attacker.health = bound(
949 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
950 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
951 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
955 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
956 attacker.health = bound(
957 attacker.health, // LA: was 3, but changed so that you can't lose health
958 // empathy won't let you gain health in the same way...
959 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
960 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
963 // apply empathy curse
964 else if (attacker.runes & CURSE_EMPATHY)
966 attacker.health = bound(
967 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
968 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
974 // apply mirror damage if any
975 if(mirrordamage > 0 || mirrorforce > 0)
977 attacker = attacker_save;
981 // just lose extra LIVES, don't kill the player for mirror damage
982 if(attacker.armorvalue > 0)
984 attacker.armorvalue = attacker.armorvalue - 1;
985 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
986 attacker.hitsound += 1;
991 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
992 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
996 float RadiusDamage_running;
997 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
998 // Returns total damage applies to creatures
1003 float total_damage_to_creatures;
1008 float stat_damagedone;
1010 if(RadiusDamage_running)
1012 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
1016 RadiusDamage_running = 1;
1018 tfloordmg = autocvar_g_throughfloor_damage;
1019 tfloorforce = autocvar_g_throughfloor_force;
1021 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1022 total_damage_to_creatures = 0;
1024 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1025 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
1027 force = inflictor.velocity;
1028 if(vlen(force) == 0)
1031 force = normalize(force);
1032 if(forceintensity >= 0)
1033 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
1035 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
1038 stat_damagedone = 0;
1040 targ = WarpZone_FindRadius (blastorigin, rad + MAX_DAMAGEEXTRARADIUS, FALSE);
1044 if (targ != inflictor)
1045 if (ignore != targ) if(targ.takedamage)
1051 // LordHavoc: measure distance to nearest point on target (not origin)
1052 // (this guarentees 100% damage on a touch impact)
1053 nearest = targ.WarpZone_findradius_nearest;
1054 diff = targ.WarpZone_findradius_dist;
1055 // round up a little on the damage to ensure full damage on impacts
1056 // and turn the distance into a fraction of the radius
1057 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
1059 //bprint(ftos(power));
1060 //if (targ == attacker)
1061 // print(ftos(power), "\n");
1067 finaldmg = coredamage * power + edgedamage * (1 - power);
1073 vector myblastorigin;
1076 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1078 // if it's a player, use the view origin as reference
1079 center = CENTER_OR_VIEWOFS(targ);
1081 force = normalize(center - myblastorigin);
1082 force = force * (finaldmg / coredamage) * forceintensity;
1085 if(targ != directhitentity)
1090 float mininv_f, mininv_d;
1092 // test line of sight to multiple positions on box,
1093 // and do damage if any of them hit
1096 // we know: max stddev of hitratio = 1 / (2 * sqrt(n))
1097 // so for a given max stddev:
1098 // n = (1 / (2 * max stddev of hitratio))^2
1100 mininv_d = (finaldmg * (1-tfloordmg)) / autocvar_g_throughfloor_damage_max_stddev;
1101 mininv_f = (vlen(force) * (1-tfloorforce)) / autocvar_g_throughfloor_force_max_stddev;
1103 if(autocvar_g_throughfloor_debug)
1104 print(sprintf("THROUGHFLOOR: D=%f F=%f max(dD)=1/%f max(dF)=1/%f", finaldmg, vlen(force), mininv_d, mininv_f));
1106 total = 0.25 * pow(max(mininv_f, mininv_d), 2);
1108 if(autocvar_g_throughfloor_debug)
1109 print(sprintf(" steps=%f", total));
1111 if (targ.classname == "player")
1112 total = ceil(bound(autocvar_g_throughfloor_min_steps_player, total, autocvar_g_throughfloor_max_steps_player));
1114 total = ceil(bound(autocvar_g_throughfloor_min_steps_other, total, autocvar_g_throughfloor_max_steps_other));
1116 if(autocvar_g_throughfloor_debug)
1117 print(sprintf(" steps=%f dD=%f dF=%f", total, finaldmg * (1-tfloordmg) / (2 * sqrt(total)), vlen(force) * (1-tfloorforce) / (2 * sqrt(total))));
1119 for(c = 0; c < total; ++c)
1121 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1122 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1123 if (trace_fraction == 1 || trace_ent == targ)
1127 hitloc = hitloc + nearest;
1131 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1132 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1133 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1136 nearest = hitloc * (1 / max(1, hits));
1137 hitratio = (hits / total);
1138 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1139 finaldmg = finaldmg * a;
1140 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1143 if(autocvar_g_throughfloor_debug)
1144 print(sprintf(" D=%f F=%f\n", finaldmg, vlen(force)));
1147 // laser force adjustments :P
1148 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1150 if (targ == attacker)
1155 float force_velocitybiasramp;
1156 float force_velocitybias;
1158 force_velocitybiasramp = autocvar_sv_maxspeed;
1159 if(deathtype & HITTYPE_SECONDARY)
1161 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1162 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1166 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1167 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1170 vel = targ.velocity;
1172 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1176 normalize(normalize(force) + vel);
1178 force_z *= force_zscale;
1182 if(deathtype & HITTYPE_SECONDARY)
1184 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1188 force *= autocvar_g_balance_laser_primary_force_other_scale;
1193 //if (targ == attacker)
1195 // print("hits ", ftos(hits), " / ", ftos(total));
1196 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1197 // print(" (", ftos(a), ")\n");
1199 if(finaldmg || vlen(force))
1203 total_damage_to_creatures += finaldmg;
1205 if(accuracy_isgooddamage(attacker, targ))
1206 stat_damagedone += finaldmg;
1209 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1210 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1212 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1220 RadiusDamage_running = 0;
1222 if(!DEATH_ISSPECIAL(deathtype))
1223 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1225 return total_damage_to_creatures;
1228 .float fire_damagepersec;
1229 .float fire_endtime;
1230 .float fire_deathtype;
1232 .float fire_hitsound;
1233 .entity fire_burner;
1235 void fireburner_think();
1237 float Fire_IsBurning(entity e)
1239 return (time < e.fire_endtime);
1242 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1245 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1247 if(e.classname == "player")
1256 // print("adding a fire burner to ", e.classname, "\n");
1257 e.fire_burner = spawn();
1258 e.fire_burner.classname = "fireburner";
1259 e.fire_burner.think = fireburner_think;
1260 e.fire_burner.nextthink = time;
1261 e.fire_burner.owner = e;
1267 if(Fire_IsBurning(e))
1269 mintime = e.fire_endtime - time;
1270 maxtime = max(mintime, t);
1272 mindps = e.fire_damagepersec;
1273 maxdps = max(mindps, dps);
1275 if(maxtime > mintime || maxdps > mindps)
1279 // damage we have right now
1280 mindamage = mindps * mintime;
1282 // damage we want to get
1283 maxdamage = mindamage + d;
1285 // but we can't exceed maxtime * maxdps!
1286 totaldamage = min(maxdamage, maxtime * maxdps);
1290 // totaldamage = min(mindamage + d, maxtime * maxdps)
1292 // totaldamage <= maxtime * maxdps
1293 // ==> totaldamage / maxdps <= maxtime.
1295 // totaldamage / mindps = min(mindamage / mindps + d, maxtime * maxdps / mindps)
1296 // >= min(mintime, maxtime)
1297 // ==> totaldamage / maxdps >= mintime.
1300 // how long do we damage then?
1301 // at least as long as before
1302 // but, never exceed maxdps
1303 totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime due to lemma
1307 // at most as long as maximum allowed
1308 // but, never below mindps
1309 totaltime = min(maxtime, totaldamage / mindps); // always >= mintime due to lemma
1311 // assuming t > mintime, dps > mindps:
1312 // we get d = t * dps = maxtime * maxdps
1313 // totaldamage = min(maxdamage, maxtime * maxdps) = min(... + d, maxtime * maxdps) = maxtime * maxdps
1314 // totaldamage / maxdps = maxtime
1315 // totaldamage / mindps > totaldamage / maxdps = maxtime
1317 // a) totaltime = max(mintime, maxtime) = maxtime
1318 // b) totaltime = min(maxtime, totaldamage / maxdps) = maxtime
1320 // assuming t <= mintime:
1321 // we get maxtime = mintime
1322 // a) totaltime = max(mintime, ...) >= mintime, also totaltime <= maxtime by the lemma, therefore totaltime = mintime = maxtime
1323 // b) totaltime = min(maxtime, ...) <= maxtime, also totaltime >= mintime by the lemma, therefore totaltime = mintime = maxtime
1325 // assuming dps <= mindps:
1326 // we get mindps = maxdps.
1327 // With this, the lemma says that mintime <= totaldamage / mindps = totaldamage / maxdps <= maxtime.
1328 // a) totaltime = max(mintime, totaldamage / maxdps) = totaldamage / maxdps
1329 // b) totaltime = min(maxtime, totaldamage / mindps) = totaldamage / maxdps
1331 e.fire_damagepersec = totaldamage / totaltime;
1332 e.fire_endtime = time + totaltime;
1333 if(totaldamage > 1.2 * mindamage)
1335 e.fire_deathtype = dt;
1336 if(e.fire_owner != o)
1339 e.fire_hitsound = FALSE;
1342 if(accuracy_isgooddamage(o, e))
1343 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1344 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1351 e.fire_damagepersec = dps;
1352 e.fire_endtime = time + t;
1353 e.fire_deathtype = dt;
1355 e.fire_hitsound = FALSE;
1356 if(accuracy_isgooddamage(o, e))
1357 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1362 void Fire_ApplyDamage(entity e)
1367 if not(Fire_IsBurning(e))
1370 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1371 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1374 // water and slime stop fire
1376 if(e.watertype != CONTENT_LAVA)
1380 if(e.freezetag_frozen || e.frozen)
1383 t = min(frametime, e.fire_endtime - time);
1384 d = e.fire_damagepersec * t;
1386 hi = e.fire_owner.hitsound;
1387 ty = e.fire_owner.typehitsound;
1388 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1389 if(e.fire_hitsound && e.fire_owner)
1391 e.fire_owner.hitsound = hi;
1392 e.fire_owner.typehitsound = ty;
1394 e.fire_hitsound = TRUE;
1396 if not(IS_INDEPENDENT_PLAYER(e))
1397 FOR_EACH_PLAYER(other) if(e != other)
1399 if(other.classname == "player")
1400 if(other.deadflag == DEAD_NO)
1401 if not(IS_INDEPENDENT_PLAYER(other))
1402 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1404 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1405 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1406 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1411 void Fire_ApplyEffect(entity e)
1413 if(Fire_IsBurning(e))
1414 e.effects |= EF_FLAME;
1416 e.effects &~= EF_FLAME;
1419 void fireburner_think()
1421 // for players, this is done in the regular loop
1422 if(wasfreed(self.owner))
1427 Fire_ApplyEffect(self.owner);
1428 if(!Fire_IsBurning(self.owner))
1430 self.owner.fire_burner = world;
1434 Fire_ApplyDamage(self.owner);
1435 self.nextthink = time;