6 float Damage_DamageInfo_SendEntity(entity to, float sf)
8 WriteByte(MSG_ENTITY, ENT_CLIENT_DAMAGEINFO);
9 WriteShort(MSG_ENTITY, self.projectiledeathtype);
10 WriteCoord(MSG_ENTITY, floor(self.origin_x));
11 WriteCoord(MSG_ENTITY, floor(self.origin_y));
12 WriteCoord(MSG_ENTITY, floor(self.origin_z));
13 WriteByte(MSG_ENTITY, bound(1, self.dmg, 255));
14 WriteByte(MSG_ENTITY, bound(0, self.dmg_radius, 255));
15 WriteByte(MSG_ENTITY, bound(1, self.dmg_edge, 255));
16 WriteShort(MSG_ENTITY, self.oldorigin_x);
20 void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, float deathtype, entity dmgowner)
22 // TODO maybe call this from non-edgedamage too?
23 // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
27 if(!sound_allowed(MSG_BROADCAST, dmgowner))
32 e.projectiledeathtype = deathtype;
34 e.dmg_edge = edgedamage;
36 e.dmg_force = vlen(force);
39 e.oldorigin_x = compressShortVector(e.velocity);
41 Net_LinkEntity(e, FALSE, 0.2, Damage_DamageInfo_SendEntity);
44 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
46 float checkrules_firstblood;
49 float damage_goodhits;
50 float damage_gooddamage;
52 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
55 .float teamkill_complain;
56 .float teamkill_soundtime;
57 .entity teamkill_soundsource;
59 .float taunt_soundtime;
62 float IsDifferentTeam(entity a, entity b)
77 float IsFlying(entity a)
79 if(a.flags & FL_ONGROUND)
81 if(a.waterlevel >= WATERLEVEL_SWIMMING)
83 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
84 if(trace_fraction < 1)
89 vector GetHeadshotMins(entity targ)
91 return '0.6 0 0' * targ.mins_x + '0 0.6 0' * targ.mins_y + '0 0 1' * (1.3 * targ.view_ofs_z - 0.3 * targ.maxs_z);
93 vector GetHeadshotMaxs(entity targ)
95 return '0.6 0 0' * targ.maxs_x + '0 0.6 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
98 void UpdateFrags(entity player, float f)
100 PlayerTeamScore_AddScore(player, f);
103 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
104 void W_SwitchWeapon_Force(entity e, float w);
105 void GiveFrags (entity attacker, entity targ, float f)
109 // TODO route through PlayerScores instead
117 PlayerScore_Add(attacker, SP_SUICIDES, 1);
122 PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
128 PlayerScore_Add(attacker, SP_KILLS, 1);
131 PlayerScore_Add(targ, SP_DEATHS, 1);
134 if(cvar("g_arena_roundbased"))
137 if(targ != attacker) // not for suicides
138 if(g_weaponarena_random)
140 // after a frag, choose another random weapon set
142 w = warmup_start_weapons;
146 attacker.weapons = randombits(w - (w & W_WeaponBit(attacker.weapon)), g_weaponarena_random, TRUE);
147 if(attacker.weapons < 0)
149 // error from randombits: no weapon available
150 // this means we can just give ALL weapons
151 attacker.weapons = w;
153 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
154 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
157 // FIXME fix the mess this is (we have REAL points now!)
161 frag_attacker = attacker;
164 if(MUTATOR_CALLHOOK(GiveFragsForKill))
174 f = RunematchHandleFrags(attacker, targ, f);
180 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
181 if(tl < lms_lowest_lives)
182 lms_lowest_lives = tl;
186 lms_next_place = player_count;
187 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
194 if(g_ctf_ignore_frags)
199 attacker.totalfrags += f;
202 UpdateFrags(attacker, f);
205 string AppendItemcodes(string s, entity player)
210 // w = player.switchweapon;
212 w = player.cnt; // previous weapon!
213 s = strcat(s, ftos(w));
214 if(time < player.strength_finished)
216 if(time < player.invincible_finished)
218 if(player.flagcarried != world)
220 if(player.BUTTON_CHAT)
225 s = strcat(s, "|", ftos(player.runes));
229 void LogDeath(string mode, float deathtype, entity killer, entity killed)
232 if(!cvar("sv_eventlog"))
234 s = strcat(":kill:", mode);
235 s = strcat(s, ":", ftos(killer.playerid));
236 s = strcat(s, ":", ftos(killed.playerid));
237 s = strcat(s, ":type=", ftos(deathtype));
238 s = strcat(s, ":items=");
239 s = AppendItemcodes(s, killer);
242 s = strcat(s, ":victimitems=");
243 s = AppendItemcodes(s, killed);
248 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
250 WriteByte(MSG_ALL, SVC_TEMPENTITY);
251 WriteByte(MSG_ALL, TE_CSQC_NOTIFY);
252 WriteByte(MSG_ALL, CSQC_KILLNOTIFY);
253 WriteString(MSG_ALL, s1);
254 WriteString(MSG_ALL, s2);
255 WriteString(MSG_ALL, s3);
256 WriteByte(MSG_ALL, msg);
257 WriteByte(MSG_ALL, type);
260 // TODO: writespectatable?
261 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
262 void Send_CSQC_Centerprint(entity e, string s1, float deathtype)
265 WriteByte(MSG_ONE, SVC_TEMPENTITY);
266 WriteByte(MSG_ONE, TE_CSQC_NOTIFY);
267 WriteByte(MSG_ONE, CSQC_CENTERPRINT);
268 WriteString(MSG_ONE, s1);
269 WriteByte(MSG_ONE, deathtype);
272 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
277 if (targ.classname == "player" || targ.classname == "corpse")
279 if (targ.classname == "corpse")
284 a = attacker.netname;
286 if (targ == attacker) // suicides
288 if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
289 msg = ColoredTeamName(targ.team); // TODO: check if needed?
291 if (deathtype == DEATH_TEAMCHANGE) {
292 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
293 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
294 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
296 } else if (deathtype == DEATH_CAMP) {
298 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
300 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
301 } else if (deathtype == DEATH_NOAMMO) {
303 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
305 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
306 } else if (deathtype == DEATH_ROT) {
308 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
310 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
311 } else if (deathtype == DEATH_MIRRORDAMAGE) {
313 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
315 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
316 } else if (deathtype == DEATH_QUIET) {
320 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
322 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
325 Send_CSQC_Centerprint(targ, msg, deathtype);
330 if (deathtype == DEATH_CAMP)
331 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
332 else if (deathtype == DEATH_MIRRORDAMAGE)
333 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
335 bprint ("^1",s, "^1 will be reinserted into the game due to their own actions\n");
337 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
339 LogDeath("suicide", deathtype, targ, targ);
340 GiveFrags(attacker, targ, -1);
342 if (targ.killcount > 2)
343 bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
345 else if (deathtype == DEATH_KILL)
346 bprint ("^1",s, "^1 couldn't take it anymore\n");
347 else if (deathtype == DEATH_ROT)
348 bprint ("^1",s, "^1 died\n");
349 else if (deathtype == DEATH_NOAMMO)
350 bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
351 else if (deathtype == DEATH_CAMP)
352 bprint ("^1",s, "^1 thought they found a nice camping ground\n");
353 else if (deathtype == DEATH_MIRRORDAMAGE)
354 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
355 else if (deathtype == DEATH_CHEAT)
356 bprint ("^1",s, "^1 unfairly eliminated themself\n");
357 else if (deathtype == DEATH_FIRE)
358 bprint ("^1",s, "^1 burned to death\n");
359 else if (deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
360 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
362 bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
366 w = DEATH_WEAPONOF(deathtype);
372 // TODO: wut is this?
373 // givefrags for logging apparently?
374 if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
376 LogDeath("suicide", deathtype, targ, targ);
377 GiveFrags(attacker, targ, -1);
380 if (targ.killcount > 2)
381 msg = ftos(targ.killcount);
382 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
384 else if (attacker.classname == "player" || attacker.classname == "gib")
386 if(teams_matter && attacker.team == targ.team)
391 // TODO: the centerprint!
392 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
393 bprint ("^1", a, "^1 took action against a team mate\n");
395 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
396 bprint ("^1", a, "^1 mows down a team mate\n");
399 GiveFrags(attacker, targ, -1);
401 if (targ.killcount > 2) {
403 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
405 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
407 if (attacker.killcount > 2) {
409 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
411 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
415 if (targ.killcount > 2) {
416 msg = ftos(targ.killcount);
419 if (attacker.killcount > 2) {
420 msg = ftos(attacker.killcount);
421 type = KILL_TEAM_SPREE;
424 attacker.killcount = 0;
426 LogDeath("tk", deathtype, attacker, targ);
427 Send_CSQC_Centerprint(attacker, s, MSG_KILL);
428 Send_KillNotification(a, msg, "", type, MSG_KILL);
432 string blood_message, victim_message;
433 if (!checkrules_firstblood)
435 checkrules_firstblood = TRUE;
436 Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
437 //bprint("^1",a, "^1 drew first blood", "\n");
438 // TODO: make these print at newline if they dont
439 Send_CSQC_Centerprint(attacker, "", KILL_FIRST_BLOOD);
440 Send_CSQC_Centerprint(targ, "", KILL_FIRST_VICTIM);
441 //blood_message = "^1First blood\n";
442 //victim_message = "^1First victim\n"; // or First casualty
444 //if(sv_gentle > 0) {
445 // centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You scored against ^7", s, GetAdvancedDeathReports(targ)));
446 // centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7", GetAdvancedDeathReports(attacker)));
448 if((cvar("sv_fragmessage_information_typefrag")) && (targ.BUTTON_CHAT)) {
449 Send_CSQC_Centerprint(attacker, s, KILL_TYPEFRAG);
450 //centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^1You typefragged ^7", s, GetAdvancedDeathReports(targ)));
451 Send_CSQC_Centerprint(targ, a, KILL_TYPEFRAGGED);
452 //centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were typefragged by ^7", a, GetAdvancedDeathReports(attacker)));
454 Send_CSQC_Centerprint(attacker, s, KILL_FRAG);
455 //centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s, GetAdvancedDeathReports(targ)));
456 Send_CSQC_Centerprint(targ, a, KILL_FRAGGED);
457 //centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a, GetAdvancedDeathReports(attacker)));
459 attacker.taunt_soundtime = time + 1;
463 // bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
466 w = DEATH_WEAPONOF(deathtype);
469 w_deathtypestring = "was blasted by";
470 w_deathtype = deathtype;
471 weapon_action(w, WR_KILLMESSAGE);
472 p = strstrofs(w_deathtypestring, "#", 0);
474 bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
476 bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
478 else if (deathtype == DEATH_TELEFRAG)
479 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
480 else if (deathtype == DEATH_DROWN)
481 bprint ("^1",s, "^1 was drowned by ", a, "\n");
482 else if (deathtype == DEATH_SLIME)
483 bprint ("^1",s, "^1 was slimed by ", a, "\n");
484 else if (deathtype == DEATH_LAVA)
485 bprint ("^1",s, "^1 was cooked by ", a, "\n");
486 else if (deathtype == DEATH_FALL)
487 bprint ("^1",s, "^1 was grounded by ", a, "\n");
488 else if (deathtype == DEATH_SHOOTING_STAR)
489 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
490 else if (deathtype == DEATH_SWAMP)
491 bprint ("^1",s, "^1 was conserved by ", a, "\n");
492 else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
494 p = strstrofs(inflictor.message2, "#", 0);
496 bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
498 bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
500 else if(deathtype == DEATH_SBCRUSH)
501 bprint ("^1",s, "^1 was crushed by ^1", a, "\n");
502 else if(deathtype == DEATH_SBMINIGUN)
503 bprint ("^1",s, "^1 got shredded by ^1", a, "\n");
504 else if(deathtype == DEATH_SBROCKET)
505 bprint ("^1",s, "^1 was blased to bits by ^1", a, "\n");
506 else if(deathtype == DEATH_SBBLOWUP)
507 bprint ("^1",s, "^1 got cought in the destruction of ^1", a, "'s vehicle\n");
509 else if(deathtype == DEATH_WAKIGUN)
510 bprint ("^1",s, "^1 was bolted down by ^1", a, "\n");
511 else if(deathtype == DEATH_WAKIROCKET)
512 bprint ("^1",s, "^1 could find no shelter from ^1", a, "'s rockets\n");
513 else if(deathtype == DEATH_WAKIBLOWUP)
514 bprint ("^1",s, "^1 dies when ^1", a, "'s wakizashi dies.\n");
516 else if(deathtype == DEATH_TURRET)
517 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
518 else if(deathtype == DEATH_TOUCHEXPLODE)
519 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
520 else if(deathtype == DEATH_CHEAT)
521 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
522 else if (deathtype == DEATH_FIRE)
523 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
524 else if (deathtype == DEATH_CUSTOM)
525 bprint ("^1",s, "^1 ", deathmessage, " by ^1", a, "\n");
527 bprint ("^1",s, "^1 was fragged by ", a, "\n");
530 w = DEATH_WEAPONOF(deathtype);
537 if (deathtype == DEATH_CUSTOM)
538 msg = strcat(deathmessage, " by ^1", msg);
539 Send_KillNotification(s, msg, ftos(w), deathtype, MSG_KILL);
542 if(g_ctf && targ.flagcarried)
544 UpdateFrags(attacker, ctf_score_value("score_kill"));
545 PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
546 GiveFrags(attacker, targ, 0); // for logging
549 GiveFrags(attacker, targ, 1);
551 if (targ.killcount > 2) {
554 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
556 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
558 Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
561 attacker.killcount = attacker.killcount + 1;
563 if (attacker.killcount > 2) {
566 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
568 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
570 Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
573 LogDeath("frag", deathtype, attacker, targ);
575 if (attacker.killcount == 3)
578 // bprint (a,"^7 made a ^1TRIPLE SCORE\n");
580 // bprint (a,"^7 made a ^1TRIPLE FRAG\n");
582 Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
583 AnnounceTo(attacker, "03kills");
587 else if (attacker.killcount == 5)
590 // bprint (a,"^7 unleashes ^1SCORING RAGE\n");
592 // bprint (a,"^7 unleashes ^1RAGE\n");
593 Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
594 AnnounceTo(attacker, "05kills");
597 else if (attacker.killcount == 10)
600 // bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
602 // bprint (a,"^7 starts the ^1MASSACRE!\n");
603 Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
604 AnnounceTo(attacker, "10kills");
607 else if (attacker.killcount == 15)
611 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
613 bprint (a,"^7 executes ^1MAYHEM!\n");
614 AnnounceTo(attacker, "15kills");
617 Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
618 AnnounceTo(attacker, "15kills");
620 else if (attacker.killcount == 20)
624 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
626 bprint (a,"^7 is a ^1BERSERKER!\n");
627 AnnounceTo(attacker, "20kills");
630 Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
631 AnnounceTo(attacker, "20kills");
633 else if (attacker.killcount == 25)
637 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
639 bprint (a,"^7 inflicts ^1CARNAGE!\n");
640 AnnounceTo(attacker, "25kills");
642 Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
643 AnnounceTo(attacker, "25kills");
645 else if (attacker.killcount == 30)
649 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
651 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
652 AnnounceTo(attacker, "30kills");
655 Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
656 AnnounceTo(attacker, "30kills");
662 //centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
663 Send_CSQC_Centerprint(targ, "", MSG_KILL_ACTION);
664 if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
665 msg = inflictor.message;
666 else if (deathtype == DEATH_CUSTOM)
668 //bprint ("^1",s, "^1 ", inflictor.message, "\n");
669 /*else if (deathtype == DEATH_DROWN)
671 bprint ("^1",s, "^1 was in the water for too long\n");
673 bprint ("^1",s, "^1 drowned\n");
674 else if (deathtype == DEATH_SLIME)
675 bprint ("^1",s, "^1 was slimed\n");
676 else if (deathtype == DEATH_LAVA)
678 bprint ("^1",s, "^1 found a hot place\n");
680 bprint ("^1",s, "^1 turned into hot slag\n");
681 else if (deathtype == DEATH_FALL)
683 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
685 bprint ("^1",s, "^1 hit the ground with a crunch\n");
686 else if (deathtype == DEATH_SHOOTING_STAR)
687 bprint ("^1",s, "^1 became a shooting star\n");
688 else if (deathtype == DEATH_SWAMP)
690 bprint ("^1",s, "^1 discovered a swamp\n");
692 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
693 else if(deathtype == DEATH_TURRET)
694 bprint ("^1",s, "^1 was mowed down by a turret \n");
695 else if (deathtype == DEATH_CUSTOM)
696 bprint ("^1",s, "^1 ", deathmessage, "\n");
697 else if(deathtype == DEATH_TOUCHEXPLODE)
698 bprint ("^1",s, "^1 died in an accident\n");
699 else if(deathtype == DEATH_CHEAT)
700 bprint ("^1",s, "^1 was unfairly eliminated\n");
701 else if(deathtype == DEATH_FIRE)
703 bprint ("^1",s, "^1 felt a little hot\n");
705 bprint ("^1",s, "^1 burnt to death\n");
708 bprint ("^1",s, "^1 needs a restart\n");
710 bprint ("^1",s, "^1 died\n");
712 GiveFrags(targ, targ, -1);
713 if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
714 AnnounceTo(targ, "botlike");
716 Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
718 if (targ.killcount > 2)
719 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
721 // bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
723 // bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
725 LogDeath("accident", deathtype, targ, targ);
728 targ.death_origin = targ.origin;
730 targ.killer_origin = attacker.origin;
732 // FIXME: this should go in PutClientInServer
738 // these are updated by each Damage call for use in button triggering and such
740 entity damage_inflictor;
741 entity damage_attacker;
743 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
748 entity attacker_save;
752 if (gameover || targ.killcount == -666)
755 local entity oldself;
759 damage_inflictor = inflictor;
760 damage_attacker = attacker;
761 attacker_save = attacker;
763 if(targ.classname == "player")
766 if(targ.hook.aiment == attacker)
767 RemoveGrapplingHook(targ); // STOP THAT, you parasite!
769 // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
770 if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
772 if(targ.classname == "player")
773 if not(IsDifferentTeam(targ, attacker))
780 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
782 // These are ALWAYS lethal
783 // No damage modification here
784 // Instead, prepare the victim for his death...
786 targ.spawnshieldtime = 0;
787 targ.health = 0.9; // this is < 1
788 targ.flags -= targ.flags & FL_GODMODE;
791 else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
797 if (targ.classname == "player")
798 if (attacker.classname == "player")
801 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
803 // nullify damage if teamplay is on
804 if(deathtype != DEATH_TELEFRAG)
805 if(attacker.classname == "player")
807 if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
812 else if(attacker.team == targ.team)
816 else if(attacker != targ)
820 else if(teamplay == 4)
822 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
824 teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
825 attacker.dmg_team = attacker.dmg_team + damage;
826 if(attacker.dmg_team > teamdamage0 && !g_ca)
827 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
828 mirrorforce = cvar("g_mirrordamage") * vlen(force);
831 if(cvar("g_friendlyfire") == 0)
837 damage = cvar("g_friendlyfire") * damage;
838 // mirrordamage will be used LATER
847 if(targ.classname == "player")
848 if(attacker.classname == "player")
851 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
852 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
855 if(targ.classname == "player")
858 if ((deathtype == DEATH_FALL) ||
859 (deathtype == DEATH_DROWN) ||
860 (deathtype == DEATH_SLIME) ||
861 (deathtype == DEATH_LAVA) ||
862 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
869 if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
871 targ.armorvalue -= 1;
872 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
875 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
877 if (DEATH_ISWEAPON(deathtype, WEP_LASER))
880 if (targ != attacker)
882 if ((targ.health >= 1) && (targ.classname == "player"))
883 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
893 if not(DEATH_ISSPECIAL(deathtype))
895 damage *= g_weapondamagefactor;
896 mirrordamage *= g_weapondamagefactor;
897 force = force * g_weaponforcefactor;
898 mirrorforce *= g_weaponforcefactor;
901 // apply strength multiplier
902 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
906 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
907 force = force * cvar("g_balance_powerup_strength_selfforce");
911 damage = damage * cvar("g_balance_powerup_strength_damage");
912 force = force * cvar("g_balance_powerup_strength_force");
916 // apply invincibility multiplier
917 if (targ.items & IT_INVINCIBLE && !g_minstagib)
918 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
920 if (targ == attacker)
922 if(g_ca || (g_cts && !cvar("g_cts_selfdamage")))
925 damage = damage * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
928 // CTF: reduce damage/force
933 damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
934 force = force * cvar("g_ctf_flagcarrier_selfforce");
939 // apply strength rune
940 if (attacker.runes & RUNE_STRENGTH)
942 if(attacker.runes & CURSE_WEAK) // have both curse & rune
944 damage = damage * cvar("g_balance_rune_strength_combo_damage");
945 force = force * cvar("g_balance_rune_strength_combo_force");
949 damage = damage * cvar("g_balance_rune_strength_damage");
950 force = force * cvar("g_balance_rune_strength_force");
953 else if (attacker.runes & CURSE_WEAK)
955 damage = damage * cvar("g_balance_curse_weak_damage");
956 force = force * cvar("g_balance_curse_weak_force");
959 // apply defense rune
960 if (targ.runes & RUNE_DEFENSE)
962 if (targ.runes & CURSE_VULNER) // have both curse & rune
963 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
965 damage = damage * cvar("g_balance_rune_defense_takedamage");
967 else if (targ.runes & CURSE_VULNER)
968 damage = damage * cvar("g_balance_curse_vulner_takedamage");
974 if(targ.takedamage == DAMAGE_AIM)
977 if(targ.classname == "player")
980 // find height of hit on player axis
981 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
982 vector headmins, headmaxs, org;
983 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
984 headmins = org + GetHeadshotMins(targ);
985 headmaxs = org + GetHeadshotMaxs(targ);
986 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
988 deathtype |= HITTYPE_HEADSHOT;
991 else if(targ.classname == "turret_head")
993 deathtype |= HITTYPE_HEADSHOT;
995 if(deathtype & HITTYPE_HEADSHOT)
996 damage *= 1 + damage_headshotbonus;
998 if(targ.classname == "player")
1000 if(IsDifferentTeam(targ, attacker))
1004 if(targ.BUTTON_CHAT)
1005 attacker.typehitsound += 1;
1007 attacker.hitsound += 1;
1009 damage_goodhits += 1;
1010 damage_gooddamage += damage;
1012 if not(DEATH_ISSPECIAL(deathtype))
1019 if(targ.items & IT_STRENGTH)
1022 if(deathtype & HITTYPE_HEADSHOT)
1029 if(deathtype != DEATH_FIRE)
1030 attacker.typehitsound += 1;
1031 if(mirrordamage > 0)
1032 if(time > attacker.teamkill_complain)
1034 attacker.teamkill_complain = time + 5;
1035 attacker.teamkill_soundtime = time + 0.4;
1036 attacker.teamkill_soundsource = targ;
1044 if (self.damageforcescale)
1046 if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
1048 self.velocity = self.velocity + self.damageforcescale * force;
1049 self.flags &~= FL_ONGROUND;
1050 UpdateCSQCProjectile(self);
1053 if (damage != 0 || (self.damageforcescale && vlen(force)))
1054 if (self.event_damage)
1055 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
1058 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
1060 // Savage: vampire mode
1063 if (time >= self.spawnshieldtime)
1065 attacker.health += damage;
1069 if (attacker.runes & RUNE_VAMPIRE)
1071 // apply vampire rune
1072 if (attacker.runes & CURSE_EMPATHY) // have the curse too
1074 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
1075 attacker.health = bound(
1076 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
1077 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
1078 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
1082 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
1083 attacker.health = bound(
1084 attacker.health, // LA: was 3, but changed so that you can't lose health
1085 // empathy won't let you gain health in the same way...
1086 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
1087 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
1090 // apply empathy curse
1091 else if (attacker.runes & CURSE_EMPATHY)
1093 attacker.health = bound(
1094 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
1095 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
1101 // apply mirror damage if any
1102 if(mirrordamage > 0 || mirrorforce > 0)
1104 attacker = attacker_save;
1106 if(mirrordamage > 0)
1108 // just lose extra LIVES, don't kill the player for mirror damage
1109 if(attacker.armorvalue > 0)
1111 attacker.armorvalue = attacker.armorvalue - 1;
1112 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
1113 attacker.hitsound += 1;
1117 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
1118 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
1122 vector NearestPointOnBox(entity box, vector org)
1124 vector m1, m2, nearest;
1126 m1 = box.mins + box.origin;
1127 m2 = box.maxs + box.origin;
1129 nearest_x = bound(m1_x, org_x, m2_x);
1130 nearest_y = bound(m1_y, org_y, m2_y);
1131 nearest_z = bound(m1_z, org_z, m2_z);
1136 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
1139 weaponid = DEATH_WEAPONOF(deathtype);
1141 if not(inWarmupStage)
1143 if ((clienttype(attacker) == CLIENTTYPE_REAL) | (clienttype(attacker) == CLIENTTYPE_BOT)) {
1144 attacker.stats_hit[weaponid - 1] += damage;
1145 attacker.stat_hit = weaponid + 64 * floor(attacker.stats_hit[weaponid - 1]);
1149 float RadiusDamage_running;
1150 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
1151 // Returns total damage applies to creatures
1161 float total_damage_to_creatures;
1166 float stat_damagedone;
1167 float stat_maxdamage;
1169 if(RadiusDamage_running)
1172 print("RadiusDamage called recursively!\n");
1173 print("Expect stuff to go HORRIBLY wrong.\n");
1174 print("Causing a stack trace...\n");
1175 save = cvar_string("prvm_backtraceforwarnings");
1176 cvar_set("prvm_backtraceforwarnings", "1");
1177 fclose(-1); // calls VM_Warning
1178 cvar_set("prvm_backtraceforwarnings", save);
1182 RadiusDamage_running = 1;
1184 tfloordmg = cvar("g_throughfloor_damage");
1185 tfloorforce = cvar("g_throughfloor_force");
1187 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1188 total_damage_to_creatures = 0;
1190 if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1191 if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
1193 force = inflictor.velocity;
1194 if(vlen(force) == 0)
1197 force = normalize(force);
1198 if(forceintensity >= 0)
1199 Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1201 Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1204 stat_damagedone = 0;
1207 targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
1211 if (targ != inflictor)
1212 if (ignore != targ) if(targ.takedamage)
1214 // LordHavoc: measure distance to nearest point on target (not origin)
1215 // (this guarentees 100% damage on a touch impact)
1216 nearest = targ.WarpZone_findradius_nearest;
1217 diff = targ.WarpZone_findradius_dist;
1218 // round up a little on the damage to ensure full damage on impacts
1219 // and turn the distance into a fraction of the radius
1220 power = 1 - ((vlen (diff) - 2) / rad);
1222 //bprint(ftos(power));
1223 //if (targ == attacker)
1224 // print(ftos(power), "\n");
1229 finaldmg = coredamage * power + edgedamage * (1 - power);
1236 local float hitratio;
1237 local vector hitloc;
1238 local vector myblastorigin;
1239 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
1240 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1241 // if it's a player, use the view origin as reference
1242 if (targ.classname == "player")
1243 center = targ.origin + targ.view_ofs;
1244 force = normalize(center - myblastorigin);
1245 force = force * (finaldmg / coredamage) * forceintensity;
1246 // test line of sight to multiple positions on box,
1247 // and do damage if any of them hit
1249 if (targ.classname == "player")
1250 total = ceil(bound(1, finaldmg, 50));
1252 total = ceil(bound(1, finaldmg/10, 5));
1257 //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1258 WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1259 if (trace_fraction == 1 || trace_ent == targ)
1263 hitloc = hitloc + nearest;
1267 nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1268 nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1269 nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1272 nearest = hitloc * (1 / max(1, hits));
1273 hitratio = (hits / total);
1274 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1275 finaldmg = finaldmg * a;
1276 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1278 //if (targ == attacker)
1280 // print("hits ", ftos(hits), " / ", ftos(total));
1281 // print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1282 // print(" (", ftos(a), ")\n");
1284 if(hits || tfloordmg || tfloorforce)
1288 total_damage_to_creatures += finaldmg;
1290 if(targ.flags & FL_CLIENT)
1291 if(targ.deadflag == DEAD_NO)
1292 if(targ != attacker)
1293 if(!teamplay || targ.team != attacker.team)
1295 stat_damagedone += finaldmg;
1296 stat_maxdamage += coredamage;
1300 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1301 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1303 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1311 RadiusDamage_running = 0;
1313 Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1315 return total_damage_to_creatures;
1318 .float fire_damagepersec;
1319 .float fire_endtime;
1320 .float fire_deathtype;
1322 .float fire_hitsound;
1323 .entity fire_burner;
1325 void fireburner_think();
1327 float Fire_IsBurning(entity e)
1329 return (time < e.fire_endtime);
1332 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1335 float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1337 if(e.classname == "player")
1346 // print("adding a fire burner to ", e.classname, "\n");
1347 e.fire_burner = spawn();
1348 e.fire_burner.classname = "fireburner";
1349 e.fire_burner.think = fireburner_think;
1350 e.fire_burner.nextthink = time;
1351 e.fire_burner.owner = e;
1357 if(Fire_IsBurning(e))
1359 mintime = e.fire_endtime - time;
1360 maxtime = max(mintime, t);
1362 mindps = e.fire_damagepersec;
1363 maxdps = max(mindps, dps);
1365 if(maxtime > mintime || maxdps > mindps)
1367 mindamage = mindps * mintime;
1368 maxdamage = mindamage + d;
1370 // interval [mintime, maxtime] * [mindps, maxdps]
1372 // [mindamage, maxdamage]
1375 if(maxdamage >= maxtime * maxdps)
1377 totaltime = maxtime;
1378 totaldamage = maxtime * maxdps;
1380 // this branch increases totaldamage if either t > mintime, or dps > mindps
1384 // maxdamage is inside the interval!
1385 // first, try to use mindps; only if this fails, increase dps as needed
1386 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1387 totaldamage = maxdamage;
1388 // can totaldamage / totaltime be >= maxdps?
1389 // max(mindps, maxdamage / maxtime) >= maxdps?
1390 // we know maxdamage < maxtime * maxdps
1393 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1396 // total conditions for increasing:
1397 // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1399 // if maxtime = mintime, maxdps = mindps
1401 // maxdamage = mindamage + d
1402 // mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1403 // so the last condition is not needed
1405 e.fire_damagepersec = totaldamage / totaltime;
1406 e.fire_endtime = time + totaltime;
1407 if(totaldamage > 1.2 * mindamage)
1409 e.fire_deathtype = dt;
1410 if(e.fire_owner != o)
1413 e.fire_hitsound = FALSE;
1416 return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1423 e.fire_damagepersec = dps;
1424 e.fire_endtime = time + t;
1425 e.fire_deathtype = dt;
1427 e.fire_hitsound = FALSE;
1432 void Fire_ApplyDamage(entity e)
1437 if not(Fire_IsBurning(e))
1443 if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1446 // water and slime stop fire
1448 if(e.watertype != CONTENT_LAVA)
1451 t = min(frametime, e.fire_endtime - time);
1452 d = e.fire_damagepersec * t;
1454 hi = e.fire_owner.hitsound;
1455 ty = e.fire_owner.typehitsound;
1456 Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1457 if(e.fire_hitsound && e.fire_owner)
1459 e.fire_owner.hitsound = hi;
1460 e.fire_owner.typehitsound = ty;
1462 e.fire_hitsound = TRUE;
1464 Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1466 if not(IS_INDEPENDENT_PLAYER(e))
1467 FOR_EACH_PLAYER(other) if(e != other)
1469 if(other.classname == "player")
1470 if(other.deadflag == DEAD_NO)
1471 if not(IS_INDEPENDENT_PLAYER(other))
1472 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1474 t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1475 d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1476 Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1481 void Fire_ApplyEffect(entity e)
1483 if(Fire_IsBurning(e))
1484 e.effects |= EF_FLAME;
1486 e.effects &~= EF_FLAME;
1489 void fireburner_think()
1491 // for players, this is done in the regular loop
1492 if(wasfreed(self.owner))
1497 Fire_ApplyEffect(self.owner);
1498 if(!Fire_IsBurning(self.owner))
1500 self.owner.fire_burner = world;
1504 Fire_ApplyDamage(self.owner);
1505 self.nextthink = time;