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
521 // these are updated by each Damage call for use in button triggering and such
523 entity damage_inflictor;
524 entity damage_attacker;
526 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
530 float complainteamdamage = 0;
531 entity attacker_save;
535 if (gameover || targ.killcount == -666)
542 damage_inflictor = inflictor;
543 damage_attacker = attacker;
544 attacker_save = attacker;
546 if(targ.classname == "player")
549 if(targ.hook.aiment == attacker)
550 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
552 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
553 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
555 if(targ.classname == "player")
556 if not(IsDifferentTeam(targ, attacker))
563 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
565 // These are ALWAYS lethal
566 // No damage modification here
567 // Instead, prepare the victim for his death...
569 targ.spawnshieldtime = 0;
570 targ.health = 0.9; // this is < 1
571 targ.flags -= targ.flags & FL_GODMODE;
574 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
581 skill based bot damage? gtfo. (tZork)
582 if (targ.classname == "player")
583 if (attacker.classname == "player")
586 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
589 // nullify damage if teamplay is on
590 if(deathtype != DEATH_TELEFRAG)
591 if(attacker.classname == "player")
593 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
598 else if(!IsDifferentTeam(attacker, targ))
600 if(autocvar_teamplay_mode == 1)
602 else if(attacker != targ)
604 if(autocvar_teamplay_mode == 3)
606 else if(autocvar_teamplay_mode == 4)
608 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
610 attacker.dmg_team = attacker.dmg_team + damage;
611 complainteamdamage = attacker.dmg_team - autocvar_g_teamdamage_threshold;
612 if(complainteamdamage > 0 && !g_ca) // FIXME why is g_ca ruled out here? Why not just g_mirrordamage 0 on CA servers?
613 mirrordamage = autocvar_g_mirrordamage * complainteamdamage;
614 mirrorforce = autocvar_g_mirrordamage * vlen(force);
617 if(autocvar_g_friendlyfire == 0)
623 damage = autocvar_g_friendlyfire * damage;
624 // mirrordamage will be used LATER
626 if(autocvar_g_mirrordamage_virtual)
628 vector v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
629 attacker.dmg_take += v_x;
630 attacker.dmg_save += v_y;
631 attacker.dmg_inflictor = inflictor;
632 mirrordamage = v_z; // = 0, to make fteqcc stfu
636 if(autocvar_g_friendlyfire_virtual)
638 vector v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
639 targ.dmg_take += v_x;
640 targ.dmg_save += v_y;
641 targ.dmg_inflictor = inflictor;
643 if(!autocvar_g_friendlyfire_virtual_force)
654 if(targ.classname == "player")
655 if(attacker.classname == "player")
658 targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
659 attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
662 if(targ.classname == "player")
665 if ((deathtype == DEATH_FALL) ||
666 (deathtype == DEATH_DROWN) ||
667 (deathtype == DEATH_SLIME) ||
668 (deathtype == DEATH_LAVA) ||
669 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
676 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
678 targ.armorvalue -= 1;
679 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
682 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
684 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
688 complainteamdamage = 0;
689 if (targ != attacker)
691 if ((targ.health >= 1) && (targ.classname == "player"))
692 centerprint(attacker, "Secondary fire inflicts no damage!");
700 if not(DEATH_ISSPECIAL(deathtype))
702 damage *= g_weapondamagefactor;
703 mirrordamage *= g_weapondamagefactor;
704 complainteamdamage *= g_weapondamagefactor;
705 force = force * g_weaponforcefactor;
706 mirrorforce *= g_weaponforcefactor;
709 // should this be changed at all? If so, in what way?
710 frag_attacker = attacker;
712 frag_damage = damage;
714 frag_deathtype = deathtype;
715 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
716 damage = frag_damage;
719 // apply strength multiplier
720 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
724 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
725 force = force * autocvar_g_balance_powerup_strength_selfforce;
729 damage = damage * autocvar_g_balance_powerup_strength_damage;
730 force = force * autocvar_g_balance_powerup_strength_force;
734 // apply invincibility multiplier
735 if (targ.items & IT_INVINCIBLE && !g_minstagib)
736 damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
738 if (targ == attacker)
740 if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
743 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
748 // apply strength rune
749 if (attacker.runes & RUNE_STRENGTH)
751 if(attacker.runes & CURSE_WEAK) // have both curse & rune
753 damage = damage * autocvar_g_balance_rune_strength_combo_damage;
754 force = force * autocvar_g_balance_rune_strength_combo_force;
758 damage = damage * autocvar_g_balance_rune_strength_damage;
759 force = force * autocvar_g_balance_rune_strength_force;
762 else if (attacker.runes & CURSE_WEAK)
764 damage = damage * autocvar_g_balance_curse_weak_damage;
765 force = force * autocvar_g_balance_curse_weak_force;
768 // apply defense rune
769 if (targ.runes & RUNE_DEFENSE)
771 if (targ.runes & CURSE_VULNER) // have both curse & rune
772 damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
774 damage = damage * autocvar_g_balance_rune_defense_takedamage;
776 else if (targ.runes & CURSE_VULNER)
777 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
783 if(targ.takedamage == DAMAGE_AIM)
787 if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
792 if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
794 if(IsDifferentTeam(victim, attacker))
798 if(deathtype != DEATH_FIRE)
800 if(victim.BUTTON_CHAT)
801 attacker.typehitsound += 1;
803 attacker.hitsound += 1;
806 damage_goodhits += 1;
807 damage_gooddamage += damage;
809 if not(DEATH_ISSPECIAL(deathtype))
811 if(targ.classname == "player") // don't do this for vehicles
817 if(victim.items & IT_STRENGTH)
824 if(deathtype != DEATH_FIRE)
826 attacker.typehitsound += 1;
828 if(complainteamdamage > 0)
829 if(time > attacker.teamkill_complain)
831 attacker.teamkill_complain = time + 5;
832 attacker.teamkill_soundtime = time + 0.4;
833 attacker.teamkill_soundsource = targ;
841 if (self.damageforcescale)
843 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
845 vector farce = damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
846 if(self.movetype == MOVETYPE_PHYSICS)
850 farcent.classname = "farce";
851 farcent.enemy = self;
852 farcent.movedir = farce * 10;
854 farcent.movedir = farcent.movedir * self.mass;
855 farcent.origin = hitloc;
856 farcent.forcetype = FORCETYPE_FORCEATPOS;
857 farcent.nextthink = time + 0.1;
858 farcent.think = SUB_Remove;
861 self.velocity = self.velocity + farce;
862 self.flags &~= FL_ONGROUND;
863 UpdateCSQCProjectile(self);
866 if (damage != 0 || (self.damageforcescale && vlen(force)))
867 if (self.event_damage)
868 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
871 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
875 if (attacker.runes & RUNE_VAMPIRE)
877 // apply vampire rune
878 if (attacker.runes & CURSE_EMPATHY) // have the curse too
880 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
881 attacker.health = bound(
882 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
883 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
884 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
888 //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
889 attacker.health = bound(
890 attacker.health, // LA: was 3, but changed so that you can't lose health
891 // empathy won't let you gain health in the same way...
892 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
893 autocvar_g_balance_rune_vampire_maxhealth); // LA: was 1000, now 500
896 // apply empathy curse
897 else if (attacker.runes & CURSE_EMPATHY)
899 attacker.health = bound(
900 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
901 attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
907 // apply mirror damage if any
908 if(mirrordamage > 0 || mirrorforce > 0)
910 attacker = attacker_save;
914 // just lose extra LIVES, don't kill the player for mirror damage
915 if(attacker.armorvalue > 0)
917 attacker.armorvalue = attacker.armorvalue - 1;
918 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
919 attacker.hitsound += 1;
924 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
925 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
929 float RadiusDamage_running;
930 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
931 // Returns total damage applies to creatures
936 float total_damage_to_creatures;
941 float stat_damagedone;
943 if(RadiusDamage_running)
945 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
949 RadiusDamage_running = 1;
951 tfloordmg = autocvar_g_throughfloor_damage;
952 tfloorforce = autocvar_g_throughfloor_force;
954 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
955 total_damage_to_creatures = 0;
957 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
958 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
960 force = inflictor.velocity;
964 force = normalize(force);
965 if(forceintensity >= 0)
966 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, 0, attacker);
968 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, 0, attacker);
973 targ = WarpZone_FindRadius (blastorigin, rad + MAX_DAMAGEEXTRARADIUS, FALSE);
977 if (targ != inflictor)
978 if (ignore != targ) if(targ.takedamage)
984 // LordHavoc: measure distance to nearest point on target (not origin)
985 // (this guarentees 100% damage on a touch impact)
986 nearest = targ.WarpZone_findradius_nearest;
987 diff = targ.WarpZone_findradius_dist;
988 // round up a little on the damage to ensure full damage on impacts
989 // and turn the distance into a fraction of the radius
990 power = 1 - ((vlen (diff) - bound(MIN_DAMAGEEXTRARADIUS, targ.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
992 //bprint(ftos(power));
993 //if (targ == attacker)
994 // print(ftos(power), "\n");
1000 finaldmg = coredamage * power + edgedamage * (1 - power);
1006 vector myblastorigin;
1009 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1011 // if it's a player, use the view origin as reference
1012 center = CENTER_OR_VIEWOFS(targ);
1014 force = normalize(center - myblastorigin);
1015 force = force * (finaldmg / coredamage) * forceintensity;
1018 if(targ != directhitentity)
1023 float mininv_f, mininv_d;
1025 // test line of sight to multiple positions on box,
1026 // and do damage if any of them hit
1029 // we know: max stddev of hitratio = 1 / (2 * sqrt(n))
1030 // so for a given max stddev:
1031 // n = (1 / (2 * max stddev of hitratio))^2
1033 mininv_d = (finaldmg * (1-tfloordmg)) / autocvar_g_throughfloor_damage_max_stddev;
1034 mininv_f = (vlen(force) * (1-tfloorforce)) / autocvar_g_throughfloor_force_max_stddev;
1036 if(autocvar_g_throughfloor_debug)
1037 print(sprintf("THROUGHFLOOR: D=%f F=%f max(dD)=1/%f max(dF)=1/%f", finaldmg, vlen(force), mininv_d, mininv_f));
1039 total = 0.25 * pow(max(mininv_f, mininv_d), 2);
1041 if(autocvar_g_throughfloor_debug)
1042 print(sprintf(" steps=%f", total));
1044 if (targ.classname == "player")
1045 total = ceil(bound(autocvar_g_throughfloor_min_steps_player, total, autocvar_g_throughfloor_max_steps_player));
1047 total = ceil(bound(autocvar_g_throughfloor_min_steps_other, total, autocvar_g_throughfloor_max_steps_other));
1049 if(autocvar_g_throughfloor_debug)
1050 print(sprintf(" steps=%f dD=%f dF=%f", total, finaldmg * (1-tfloordmg) / (2 * sqrt(total)), vlen(force) * (1-tfloorforce) / (2 * sqrt(total))));
1052 for(c = 0; c < total; ++c)
1054 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1055 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1056 if (trace_fraction == 1 || trace_ent == targ)
1060 hitloc = hitloc + nearest;
1064 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1065 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1066 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1069 nearest = hitloc * (1 / max(1, hits));
1070 hitratio = (hits / total);
1071 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1072 finaldmg = finaldmg * a;
1073 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1076 if(autocvar_g_throughfloor_debug)
1077 print(sprintf(" D=%f F=%f\n", finaldmg, vlen(force)));
1080 // laser force adjustments :P
1081 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1083 if (targ == attacker)
1088 float force_velocitybiasramp;
1089 float force_velocitybias;
1091 force_velocitybiasramp = autocvar_sv_maxspeed;
1092 if(deathtype & HITTYPE_SECONDARY)
1094 force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1095 force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1099 force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1100 force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1103 vel = targ.velocity;
1105 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1109 normalize(normalize(force) + vel);
1111 force_z *= force_zscale;
1115 if(deathtype & HITTYPE_SECONDARY)
1117 force *= autocvar_g_balance_laser_secondary_force_other_scale;
1121 force *= autocvar_g_balance_laser_primary_force_other_scale;
1126 //if (targ == attacker)
1128 // print("hits ", ftos(hits), " / ", ftos(total));
1129 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1130 // print(" (", ftos(a), ")\n");
1132 if(finaldmg || vlen(force))
1136 total_damage_to_creatures += finaldmg;
1138 if(accuracy_isgooddamage(attacker, targ))
1139 stat_damagedone += finaldmg;
1142 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1143 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1145 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1153 RadiusDamage_running = 0;
1155 if(!DEATH_ISSPECIAL(deathtype))
1156 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1158 return total_damage_to_creatures;
1161 .float fire_damagepersec;
1162 .float fire_endtime;
1163 .float fire_deathtype;
1165 .float fire_hitsound;
1166 .entity fire_burner;
1168 void fireburner_think();
1170 float Fire_IsBurning(entity e)
1172 return (time < e.fire_endtime);
1175 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1178 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1180 if(e.classname == "player")
1189 // print("adding a fire burner to ", e.classname, "\n");
1190 e.fire_burner = spawn();
1191 e.fire_burner.classname = "fireburner";
1192 e.fire_burner.think = fireburner_think;
1193 e.fire_burner.nextthink = time;
1194 e.fire_burner.owner = e;
1200 if(Fire_IsBurning(e))
1202 mintime = e.fire_endtime - time;
1203 maxtime = max(mintime, t);
1205 mindps = e.fire_damagepersec;
1206 maxdps = max(mindps, dps);
1208 if(maxtime > mintime || maxdps > mindps)
1212 // damage we have right now
1213 mindamage = mindps * mintime;
1215 // damage we want to get
1216 maxdamage = mindamage + d;
1218 // but we can't exceed maxtime * maxdps!
1219 totaldamage = min(maxdamage, maxtime * maxdps);
1223 // totaldamage = min(mindamage + d, maxtime * maxdps)
1225 // totaldamage <= maxtime * maxdps
1226 // ==> totaldamage / maxdps <= maxtime.
1228 // totaldamage / mindps = min(mindamage / mindps + d, maxtime * maxdps / mindps)
1229 // >= min(mintime, maxtime)
1230 // ==> totaldamage / maxdps >= mintime.
1233 // how long do we damage then?
1234 // at least as long as before
1235 // but, never exceed maxdps
1236 totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime due to lemma
1240 // at most as long as maximum allowed
1241 // but, never below mindps
1242 totaltime = min(maxtime, totaldamage / mindps); // always >= mintime due to lemma
1244 // assuming t > mintime, dps > mindps:
1245 // we get d = t * dps = maxtime * maxdps
1246 // totaldamage = min(maxdamage, maxtime * maxdps) = min(... + d, maxtime * maxdps) = maxtime * maxdps
1247 // totaldamage / maxdps = maxtime
1248 // totaldamage / mindps > totaldamage / maxdps = maxtime
1250 // a) totaltime = max(mintime, maxtime) = maxtime
1251 // b) totaltime = min(maxtime, totaldamage / maxdps) = maxtime
1253 // assuming t <= mintime:
1254 // we get maxtime = mintime
1255 // a) totaltime = max(mintime, ...) >= mintime, also totaltime <= maxtime by the lemma, therefore totaltime = mintime = maxtime
1256 // b) totaltime = min(maxtime, ...) <= maxtime, also totaltime >= mintime by the lemma, therefore totaltime = mintime = maxtime
1258 // assuming dps <= mindps:
1259 // we get mindps = maxdps.
1260 // With this, the lemma says that mintime <= totaldamage / mindps = totaldamage / maxdps <= maxtime.
1261 // a) totaltime = max(mintime, totaldamage / maxdps) = totaldamage / maxdps
1262 // b) totaltime = min(maxtime, totaldamage / mindps) = totaldamage / maxdps
1264 e.fire_damagepersec = totaldamage / totaltime;
1265 e.fire_endtime = time + totaltime;
1266 if(totaldamage > 1.2 * mindamage)
1268 e.fire_deathtype = dt;
1269 if(e.fire_owner != o)
1272 e.fire_hitsound = FALSE;
1275 if(accuracy_isgooddamage(o, e))
1276 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1277 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1284 e.fire_damagepersec = dps;
1285 e.fire_endtime = time + t;
1286 e.fire_deathtype = dt;
1288 e.fire_hitsound = FALSE;
1289 if(accuracy_isgooddamage(o, e))
1290 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1295 void Fire_ApplyDamage(entity e)
1300 if not(Fire_IsBurning(e))
1303 for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1304 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1307 // water and slime stop fire
1309 if(e.watertype != CONTENT_LAVA)
1313 if(e.freezetag_frozen)
1316 t = min(frametime, e.fire_endtime - time);
1317 d = e.fire_damagepersec * t;
1319 hi = e.fire_owner.hitsound;
1320 ty = e.fire_owner.typehitsound;
1321 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1322 if(e.fire_hitsound && e.fire_owner)
1324 e.fire_owner.hitsound = hi;
1325 e.fire_owner.typehitsound = ty;
1327 e.fire_hitsound = TRUE;
1329 if not(IS_INDEPENDENT_PLAYER(e))
1330 FOR_EACH_PLAYER(other) if(e != other)
1332 if(other.classname == "player")
1333 if(other.deadflag == DEAD_NO)
1334 if not(IS_INDEPENDENT_PLAYER(other))
1335 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1337 t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1338 d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1339 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1344 void Fire_ApplyEffect(entity e)
1346 if(Fire_IsBurning(e))
1347 e.effects |= EF_FLAME;
1349 e.effects &~= EF_FLAME;
1352 void fireburner_think()
1354 // for players, this is done in the regular loop
1355 if(wasfreed(self.owner))
1360 Fire_ApplyEffect(self.owner);
1361 if(!Fire_IsBurning(self.owner))
1363 self.owner.fire_burner = world;
1367 Fire_ApplyDamage(self.owner);
1368 self.nextthink = time;