Debian Codegraph @

code/game/g_combat.c

raw ◀ ▶
Source reconstructed at patch state 1 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 //
23 // g_combat.c
24
25 #include "g_local.h"
26 #include "challenges.h"
27
28 /*
29 ============
30 ScorePlum
31 ============
32 */
33 void ScorePlum( gentity_t *ent, vec3_t origin, int score ) {
34 gentity_t *plum;
35
36 plum = G_TempEntity( origin, EV_SCOREPLUM );
37 // only send this temp entity to a single client
38 plum->r.svFlags |= SVF_SINGLECLIENT;
39 plum->r.singleClient = ent->s.number;
40 //
41 plum->s.otherEntityNum = ent->s.number;
42 plum->s.time = score;
43 }
44
45 /*
46 ============
47 AddScore
48
49 Adds score to both the client and his team
50 ============
51 */
52 void AddScore( gentity_t *ent, vec3_t origin, int score ) {
53 int i;
54
55 if ( !ent->client ) {
56 return;
57 }
58 // no scoring during pre-match warmup
59 if ( level.warmupTime ) {
60 return;
61 }
62
63 //No scoring during intermission
64 if ( level.intermissiontime ) {
65 return;
66 }
67 // show score plum
68 if( level.numNonSpectatorClients<3 && score < 0 && (g_gametype.integer<GT_TEAM || g_ffa_gt==1)) {
69 for ( i = 0 ; i < level.maxclients ; i++ ) {
70 if ( level.clients[ i ].pers.connected != CON_CONNECTED )
71 continue; //Client was not connected
72
73 if (level.clients[i].sess.sessionTeam == TEAM_SPECTATOR)
74 continue; //Don't give anything to spectators
75
76 if (g_entities+i == ent)
77 continue; //Don't award dead one
78
79 level.clients[i].ps.persistant[PERS_SCORE] -= score;
80 ScorePlum(ent, origin, -score);
81 }
82 }
83 else {
84 ScorePlum(ent, origin, score);
85 //
86 ent->client->ps.persistant[PERS_SCORE] += score;
87 if ( g_gametype.integer == GT_TEAM ) {
88 int team = ent->client->ps.persistant[PERS_TEAM];
89 level.teamScores[ team ] += score;
90 G_LogPrintf("TeamScore: %i %i: Team %d now has %d points\n",
91 team, level.teamScores[ team ], team, level.teamScores[ team ] );
92 }
93 }
94 G_LogPrintf("PlayerScore: %i %i: %s now has %d points\n",
95 ent->s.number, ent->client->ps.persistant[PERS_SCORE], ent->client->pers.netname, ent->client->ps.persistant[PERS_SCORE] );
96 CalculateRanks();
97 }
98
99 /*
100 =================
101 TossClientItems
102
103 Toss the weapon and powerups for the killed player
104 =================
105 */
106 void TossClientItems( gentity_t *self ) {
107 gitem_t *item;
108 int weapon;
109 float angle;
110 int i;
111 gentity_t *drop;
112
113 // drop the weapon if not a gauntlet or machinegun
114 weapon = self->s.weapon;
115
116 //Never drop in elimination or last man standing mode!
117 if( g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_LMS)
118 return;
119
120 // make a special check to see if they are changing to a new
121 // weapon that isn't the mg or gauntlet. Without this, a client
122 // can pick up a weapon, be killed, and not drop the weapon because
123 // their weapon change hasn't completed yet and they are still holding the MG.
124 if ( weapon == WP_MACHINEGUN || weapon == WP_GRAPPLING_HOOK ) {
125 if ( self->client->ps.weaponstate == WEAPON_DROPPING ) {
126 weapon = self->client->pers.cmd.weapon;
127 }
128 if ( !( self->client->ps.stats[STAT_WEAPONS] & ( 1 << weapon ) ) ) {
129 weapon = WP_NONE;
130 }
131 }
132
133 if (g_instantgib.integer || g_rockets.integer || g_gametype.integer == GT_CTF_ELIMINATION || g_elimination_allgametypes.integer){
134 //Nothing!
135 }
136 else
137 if ( weapon > WP_MACHINEGUN && weapon != WP_GRAPPLING_HOOK &&
138 self->client->ps.ammo[ weapon ] ) {
139 // find the item type for this weapon
140 item = BG_FindItemForWeapon( weapon );
141
142 // spawn the item
143 Drop_Item( self, item, 0 );
144 }
145
146 // drop all the powerups if not in teamplay
147 if ( g_gametype.integer != GT_TEAM ) {
148 angle = 45;
149 for ( i = 1 ; i < PW_NUM_POWERUPS ; i++ ) {
150 if ( self->client->ps.powerups[ i ] > level.time ) {
151 item = BG_FindItemForPowerup( i );
152 if ( !item ) {
153 continue;
154 }
155 drop = Drop_Item( self, item, angle );
156 // decide how many seconds it has left
157 drop->count = ( self->client->ps.powerups[ i ] - level.time ) / 1000;
158 if ( drop->count < 1 ) {
159 drop->count = 1;
160 }
161 angle += 45;
162 }
163 }
164 }
165 }
166
167 /*
168 =================
169 TossClientCubes
170 =================
171 */
172 extern gentity_t *neutralObelisk;
173
174 void TossClientCubes( gentity_t *self ) {
175 gitem_t *item;
176 gentity_t *drop;
177 vec3_t velocity;
178 vec3_t angles;
179 vec3_t origin;
180
181 self->client->ps.generic1 = 0;
182
183 // this should never happen but we should never
184 // get the server to crash due to skull being spawned in
185 if (!G_EntitiesFree()) {
186 return;
187 }
188
189 if( self->client->sess.sessionTeam == TEAM_RED ) {
190 item = BG_FindItem( "Red Cube" );
191 }
192 else {
193 item = BG_FindItem( "Blue Cube" );
194 }
195
196 angles[YAW] = (float)(level.time % 360);
197 angles[PITCH] = 0; // always forward
198 angles[ROLL] = 0;
199
200 AngleVectors( angles, velocity, NULL, NULL );
201 VectorScale( velocity, 150, velocity );
202 velocity[2] += 200 + crandom() * 50;
203
204 if( neutralObelisk ) {
205 VectorCopy( neutralObelisk->s.pos.trBase, origin );
206 origin[2] += 44;
207 } else {
208 VectorClear( origin ) ;
209 }
210
211 drop = LaunchItem( item, origin, velocity );
212
213 drop->nextthink = level.time + g_cubeTimeout.integer * 1000;
214 drop->think = G_FreeEntity;
215 drop->spawnflags = self->client->sess.sessionTeam;
216 }
217
218 /*
219 =================
220 TossClientPersistantPowerups
221 =================
222 */
223 void TossClientPersistantPowerups( gentity_t *ent ) {
224 gentity_t *powerup;
225
226 if( !ent->client ) {
227 return;
228 }
229
230 if( !ent->client->persistantPowerup ) {
231 return;
232 }
233
234 powerup = ent->client->persistantPowerup;
235
236 powerup->r.svFlags &= ~SVF_NOCLIENT;
237 powerup->s.eFlags &= ~EF_NODRAW;
238 powerup->r.contents = CONTENTS_TRIGGER;
239 trap_LinkEntity( powerup );
240
241 ent->client->ps.stats[STAT_PERSISTANT_POWERUP] = 0;
242 ent->client->persistantPowerup = NULL;
243 }
244
245
246 /*
247 ==================
248 LookAtKiller
249 ==================
250 */
251 void LookAtKiller( gentity_t *self, gentity_t *inflictor, gentity_t *attacker ) {
252 vec3_t dir;
253 //vec3_t angles;
254
255 if ( attacker && attacker != self ) {
256 VectorSubtract (attacker->s.pos.trBase, self->s.pos.trBase, dir);
257 } else if ( inflictor && inflictor != self ) {
258 VectorSubtract (inflictor->s.pos.trBase, self->s.pos.trBase, dir);
259 } else {
260 self->client->ps.stats[STAT_DEAD_YAW] = self->s.angles[YAW];
261 return;
262 }
263
264 self->client->ps.stats[STAT_DEAD_YAW] = vectoyaw ( dir );
265
266 /*angles[YAW] =*/ vectoyaw ( dir );
267 //angles[PITCH] = 0;
268 //angles[ROLL] = 0;
269 }
270
271 /*
272 ==================
273 GibEntity
274 ==================
275 */
276 void GibEntity( gentity_t *self, int killer ) {
277 gentity_t *ent;
278 int i;
279
280 //if this entity still has kamikaze
281 if (self->s.eFlags & EF_KAMIKAZE) {
282 // check if there is a kamikaze timer around for this owner
283 for (i = 0; i < MAX_GENTITIES; i++) {
284 ent = &g_entities[i];
285 if (!ent->inuse)
286 continue;
287 if (ent->activator != self)
288 continue;
289 if (strcmp(ent->classname, "kamikaze timer"))
290 continue;
291 G_FreeEntity(ent);
292 break;
293 }
294 }
295 G_AddEvent( self, EV_GIB_PLAYER, killer );
296 self->takedamage = qfalse;
297 self->s.eType = ET_INVISIBLE;
298 self->r.contents = 0;
299 }
300
301 /*
302 ==================
303 body_die
304 ==================
305 */
306 void body_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int meansOfDeath ) {
307 if ( self->health > GIB_HEALTH ) {
308 return;
309 }
310 if ( !g_blood.integer ) {
311 self->health = GIB_HEALTH+1;
312 return;
313 }
314
315 GibEntity( self, 0 );
316 }
317
318
319 // these are just for logging, the client prints its own messages
320 char *modNames[] = {
321 "MOD_UNKNOWN",
322 "MOD_SHOTGUN",
323 "MOD_GAUNTLET",
324 "MOD_MACHINEGUN",
325 "MOD_GRENADE",
326 "MOD_GRENADE_SPLASH",
327 "MOD_ROCKET",
328 "MOD_ROCKET_SPLASH",
329 "MOD_PLASMA",
330 "MOD_PLASMA_SPLASH",
331 "MOD_RAILGUN",
332 "MOD_LIGHTNING",
333 "MOD_BFG",
334 "MOD_BFG_SPLASH",
335 "MOD_WATER",
336 "MOD_SLIME",
337 "MOD_LAVA",
338 "MOD_CRUSH",
339 "MOD_TELEFRAG",
340 "MOD_FALLING",
341 "MOD_SUICIDE",
342 "MOD_TARGET_LASER",
343 "MOD_TRIGGER_HURT",
344 "MOD_NAIL",
345 "MOD_CHAINGUN",
346 "MOD_PROXIMITY_MINE",
347 "MOD_KAMIKAZE",
348 "MOD_JUICED",
349 "MOD_GRAPPLE"
350 };
351
352 /*
353 ==================
354 Kamikaze_DeathActivate
355 ==================
356 */
357 void Kamikaze_DeathActivate( gentity_t *ent ) {
358 G_StartKamikaze(ent);
359 G_FreeEntity(ent);
360 }
361
362 /*
363 ==================
364 Kamikaze_DeathTimer
365 ==================
366 */
367 void Kamikaze_DeathTimer( gentity_t *self ) {
368 gentity_t *ent;
369
370 ent = G_Spawn();
371 ent->classname = "kamikaze timer";
372 VectorCopy(self->s.pos.trBase, ent->s.pos.trBase);
373 ent->r.svFlags |= SVF_NOCLIENT;
374 ent->think = Kamikaze_DeathActivate;
375 ent->nextthink = level.time + 5 * 1000;
376
377 ent->activator = self;
378 }
379
380
381 /*
382 ==================
383 CheckAlmostCapture
384 ==================
385 */
386 void CheckAlmostCapture( gentity_t *self, gentity_t *attacker ) {
387 gentity_t *ent;
388 vec3_t dir;
389 char *classname;
390
391 // if this player was carrying a flag
392 if ( self->client->ps.powerups[PW_REDFLAG] ||
393 self->client->ps.powerups[PW_BLUEFLAG] ||
394 self->client->ps.powerups[PW_NEUTRALFLAG] ) {
395 // get the goal flag this player should have been going for
396 if ( g_gametype.integer == GT_CTF || g_gametype.integer == GT_CTF_ELIMINATION) {
397 if ( self->client->sess.sessionTeam == TEAM_BLUE ) {
398 classname = "team_CTF_blueflag";
399 }
400 else {
401 classname = "team_CTF_redflag";
402 }
403 }
404 else {
405 if ( self->client->sess.sessionTeam == TEAM_BLUE ) {
406 classname = "team_CTF_redflag";
407 }
408 else {
409 classname = "team_CTF_blueflag";
410 }
411 }
412 ent = NULL;
413 do
414 {
415 ent = G_Find(ent, FOFS(classname), classname);
416 } while (ent && (ent->flags & FL_DROPPED_ITEM));
417 // if we found the destination flag and it's not picked up
418 if (ent && !(ent->r.svFlags & SVF_NOCLIENT) ) {
419 // if the player was *very* close
420 VectorSubtract( self->client->ps.origin, ent->s.origin, dir );
421 if ( VectorLength(dir) < 200 ) {
422 self->client->ps.persistant[PERS_PLAYEREVENTS] ^= PLAYEREVENT_HOLYSHIT;
423 if ( attacker->client ) {
424 attacker->client->ps.persistant[PERS_PLAYEREVENTS] ^= PLAYEREVENT_HOLYSHIT;
425 }
426 }
427 }
428 }
429 }
430
431 /*
432 ==================
433 CheckAlmostScored
434 ==================
435 */
436 void CheckAlmostScored( gentity_t *self, gentity_t *attacker ) {
437 gentity_t *ent;
438 vec3_t dir;
439 char *classname;
440
441 // if the player was carrying cubes
442 if ( self->client->ps.generic1 ) {
443 if ( self->client->sess.sessionTeam == TEAM_BLUE ) {
444 classname = "team_redobelisk";
445 }
446 else {
447 classname = "team_blueobelisk";
448 }
449 ent = G_Find(NULL, FOFS(classname), classname);
450 // if we found the destination obelisk
451 if ( ent ) {
452 // if the player was *very* close
453 VectorSubtract( self->client->ps.origin, ent->s.origin, dir );
454 if ( VectorLength(dir) < 200 ) {
455 self->client->ps.persistant[PERS_PLAYEREVENTS] ^= PLAYEREVENT_HOLYSHIT;
456 if ( attacker->client ) {
457 attacker->client->ps.persistant[PERS_PLAYEREVENTS] ^= PLAYEREVENT_HOLYSHIT;
458 }
459 }
460 }
461 }
462 }
463
464 /*
465 ==================
466 player_die
467 ==================
468 */
469 void player_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int meansOfDeath ) {
470 gentity_t *ent;
471 int anim;
472 int contents;
473 int killer;
474 int i,counter2;
475 char *killerName, *obit;
476
477 if ( self->client->ps.pm_type == PM_DEAD ) {
478 return;
479 }
480
481 if ( level.intermissiontime ) {
482 return;
483 }
484
485 //unlagged - backward reconciliation #2
486 // make sure the body shows up in the client's current position
487 G_UnTimeShiftClient( self );
488 //unlagged - backward reconciliation #2
489 //KK-OAX Here is where we run the streak logic.
490 G_RunStreakLogic( attacker, self );
491
492 // check for an almost capture
493 CheckAlmostCapture( self, attacker );
494 // check for a player that almost brought in cubes
495 CheckAlmostScored( self, attacker );
496
497 if (self->client && self->client->hook) {
498 Weapon_HookFree(self->client->hook);
499 }
500 if ((self->client->ps.eFlags & EF_TICKING) && self->activator) {
501 self->client->ps.eFlags &= ~EF_TICKING;
502 self->activator->think = G_FreeEntity;
503 self->activator->nextthink = level.time;
504 }
505 self->client->ps.pm_type = PM_DEAD;
506
507 if ( attacker ) {
508 killer = attacker->s.number;
509 if ( attacker->client ) {
510 killerName = attacker->client->pers.netname;
511 } else {
512 killerName = "<non-client>";
513 }
514 } else {
515 killer = ENTITYNUM_WORLD;
516 killerName = "<world>";
517 }
518
519 if ( killer < 0 || killer >= MAX_CLIENTS ) {
520 killer = ENTITYNUM_WORLD;
521 killerName = "<world>";
522 }
523
524 if ( meansOfDeath < 0 || meansOfDeath >= sizeof( modNames ) / sizeof( modNames[0] ) ) {
525 obit = "<bad obituary>";
526 } else {
527 obit = modNames[meansOfDeath];
528 }
529
530 G_LogPrintf("Kill: %i %i %i: %s killed %s by %s\n",
531 killer, self->s.number, meansOfDeath, killerName,
532 self->client->pers.netname, obit );
533
534 // broadcast the death event to everyone
535 ent = G_TempEntity( self->r.currentOrigin, EV_OBITUARY );
536 ent->s.eventParm = meansOfDeath;
537 ent->s.otherEntityNum = self->s.number;
538 ent->s.otherEntityNum2 = killer;
539 //Sago: Hmmm... generic? Can I transmit anything I like? Like if it is a team kill? Let's try
540 ent->s.generic1 = OnSameTeam (self, attacker);
541 if( !((g_gametype.integer==GT_ELIMINATION || g_gametype.integer==GT_CTF_ELIMINATION) && level.time < level.roundStartTime) )
542 ent->r.svFlags = SVF_BROADCAST; // send to everyone (if not an elimination gametype during active warmup)
543 else
544 ent->r.svFlags = SVF_NOCLIENT;
545
546 self->enemy = attacker;
547
548 self->client->ps.persistant[PERS_KILLED]++;
549
550 if (attacker && attacker->client) {
551 attacker->client->lastkilled_client = self->s.number;
552
553 if ( attacker == self || OnSameTeam (self, attacker ) ) {
554 if(g_gametype.integer!=GT_LMS && !((g_gametype.integer==GT_ELIMINATION || g_gametype.integer==GT_CTF_ELIMINATION) && level.time < level.roundStartTime))
555 if( (g_gametype.integer <GT_TEAM && g_ffa_gt!=1 && self->client->ps.persistant[PERS_SCORE]>0) || level.numNonSpectatorClients<3) //Cannot get negative scores by suicide
556 AddScore( attacker, self->r.currentOrigin, -1 );
557 } else {
558 if(g_gametype.integer!=GT_LMS)
559 AddScore( attacker, self->r.currentOrigin, 1 );
560
561 if( meansOfDeath == MOD_GAUNTLET ) {
562
563 // Attack gets a challenge complete:
564 if(!(attacker->r.svFlags & SVF_BOT) && !(self->r.svFlags & SVF_BOT))
565 ChallengeMessage(attacker,WEAPON_GAUNTLET_KILLS);
566
567 // play humiliation on player
568 attacker->client->ps.persistant[PERS_GAUNTLET_FRAG_COUNT]++;
569 G_LogPrintf( "Award: %i %i: %s gained the %s award!\n", attacker->client->ps.clientNum, 0, attacker->client->pers.netname, "GAUNTLET" );
570
571 // add the sprite over the player's head
572 attacker->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
573 attacker->client->ps.eFlags |= EF_AWARD_GAUNTLET;
574 attacker->client->rewardTime = level.time + REWARD_SPRITE_TIME;
575
576 // also play humiliation on target
577 self->client->ps.persistant[PERS_PLAYEREVENTS] ^= PLAYEREVENT_GAUNTLETREWARD;
578 }
579
580 //If neither attacker or taget is bots and not the same
581 if(!(attacker->r.svFlags & SVF_BOT) && !(self->r.svFlags & SVF_BOT) && self!=attacker)
582 {
583 switch(meansOfDeath)
584 {
585 case MOD_GAUNTLET:
586 ChallengeMessage(attacker,WEAPON_GAUNTLET_KILLS);
587 break;
588 case MOD_MACHINEGUN:
589 ChallengeMessage(attacker,WEAPON_MACHINEGUN_KILLS);
590 break;
591 case MOD_SHOTGUN:
592 ChallengeMessage(attacker,WEAPON_SHOTGUN_KILLS);
593 break;
594 case MOD_GRENADE:
595 case MOD_GRENADE_SPLASH:
596 ChallengeMessage(attacker,WEAPON_GRANADE_KILLS);
597 break;
598 case MOD_ROCKET:
599 case MOD_ROCKET_SPLASH:
600 ChallengeMessage(attacker,WEAPON_ROCKET_KILLS);
601 break;
602 case MOD_LIGHTNING:
603 ChallengeMessage(attacker,WEAPON_LIGHTNING_KILLS);
604 break;
605 case MOD_PLASMA:
606 case MOD_PLASMA_SPLASH:
607 ChallengeMessage(attacker,WEAPON_PLASMA_KILLS);
608 break;
609 case MOD_RAILGUN:
610 if(g_instantgib.integer)
611 ChallengeMessage(attacker,WEAPON_INSTANT_RAIL_KILLS);
612 else
613 ChallengeMessage(attacker,WEAPON_RAIL_KILLS);
614 break;
615 case MOD_BFG:
616 case MOD_BFG_SPLASH:
617 ChallengeMessage(attacker,WEAPON_BFG_KILLS);
618 break;
619 case MOD_NAIL:
620 ChallengeMessage(attacker,WEAPON_NAILGUN_KILLS);
621 break;
622 case MOD_CHAINGUN:
623 ChallengeMessage(attacker,WEAPON_CHAINGUN_KILLS);
624 break;
625 case MOD_PROXIMITY_MINE:
626 ChallengeMessage(attacker,WEAPON_MINE_KILLS);
627 break;
628 case MOD_GRAPPLE:
629 ChallengeMessage(attacker,WEAPON_GRAPPLE_KILLS);
630 break;
631 case MOD_LAVA:
632 case MOD_SLIME:
633 case MOD_TRIGGER_HURT:
634 case MOD_FALLING:
635 ChallengeMessage(attacker,WEAPON_PUSH_KILLS);
636 break;
637 case MOD_CRUSH:
638 ChallengeMessage(attacker,WEAPON_CRUSH_KILLS);
639 break;
640 case MOD_TELEFRAG:
641 ChallengeMessage(attacker,WEAPON_TELEFRAG_KILLS);
642 break;
643 };
644 ChallengeMessage(attacker,GENERAL_TOTALKILLS);
645 ChallengeMessage(self,GENERAL_TOTALDEATHS);
646
647 //Lets count number of powerups:
648 i = 0;
649 counter2 = 0;
650
651 if(attacker->client->ps.powerups[PW_QUAD]) {
652 ChallengeMessage(attacker,POWERUP_QUAD_KILL);
653 counter2++;
654 }
655 if(self->client->ps.powerups[PW_QUAD]) {
656 ChallengeMessage(attacker,POWERUP_COUNTER_QUAD);
657 i++;
658 }
659
660 if(attacker->client->ps.powerups[PW_HASTE]) {
661 ChallengeMessage(attacker,POWERUP_SPEED_KILL);
662 counter2++;
663 }
664 if(self->client->ps.powerups[PW_HASTE]) {
665 ChallengeMessage(attacker,POWERUP_COUNTER_SPEED);
666 i++;
667 }
668
669 if(attacker->client->ps.powerups[PW_INVIS]) {
670 ChallengeMessage(attacker,POWERUP_INVIS_KILL);
671 counter2++;
672 }
673 if(self->client->ps.powerups[PW_INVIS]) {
674 ChallengeMessage(attacker,POWERUP_COUNTER_INVIS);
675 i++;
676 }
677
678 if(attacker->client->ps.powerups[PW_FLIGHT]) {
679 ChallengeMessage(attacker,POWERUP_FLIGHT_KILL);
680 counter2++;
681 }
682 if(self->client->ps.powerups[PW_FLIGHT]) {
683 ChallengeMessage(attacker,POWERUP_COUNTER_FLIGHT);
684 i++;
685 }
686
687 if(self->client->ps.powerups[PW_BATTLESUIT]) {
688 ChallengeMessage(attacker,POWERUP_COUNTER_ENVIR);
689 i++;
690 }
691
692 if(self->client->ps.powerups[PW_REGEN]) {
693 ChallengeMessage(attacker,POWERUP_COUNTER_REGEN);
694 i++;
695 }
696
697 if(i>1) //The target had more than one powerup
698 ChallengeMessage(attacker,POWERUP_COUNTER_MULTI);
699 if(counter2>1) //The attacker has more than one powerup
700 ChallengeMessage(attacker,POWERUP_MULTI_KILL);
701 }
702
703 // check for two kills in a short amount of time
704 // if this is close enough to the last kill, give a reward sound
705 if ( level.time - attacker->client->lastKillTime < CARNAGE_REWARD_TIME ) {
706 // KK-OAX
707 // Check if Multikills are enabled
708 if( g_altExcellent.integer ) {
709 attacker->client->pers.multiKillCount++;
710 G_checkForMultiKill( attacker );
711 } // play excellent on player
712 attacker->client->ps.persistant[PERS_EXCELLENT_COUNT]++;
713 G_LogPrintf( "Award: %i %i: %s gained the %s award!\n", attacker->client->ps.clientNum, 1, attacker->client->pers.netname, "EXCELLENT" );
714 if(!level.hadBots) //There has not been any bots
715 ChallengeMessage(attacker,AWARD_EXCELLENT);
716 // add the sprite over the player's head
717 attacker->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
718 attacker->client->ps.eFlags |= EF_AWARD_EXCELLENT;
719 attacker->client->rewardTime = level.time + REWARD_SPRITE_TIME;
720 } else {
721 //KK-OAX Clear multikill count
722 //Must be 1 so the correct number of kills are displayed to the clients.
723 attacker->client->pers.multiKillCount = 1;
724 }
725 attacker->client->lastKillTime = level.time;
726 }
727 } else {
728 if(g_gametype.integer!=GT_LMS && !((g_gametype.integer==GT_ELIMINATION || g_gametype.integer==GT_CTF_ELIMINATION) && level.time < level.roundStartTime))
729 if(self->client->ps.persistant[PERS_SCORE]>0 || level.numNonSpectatorClients<3) //Cannot get negative scores by suicide
730 AddScore( self, self->r.currentOrigin, -1 );
731 }
732
733 // Add team bonuses
734 Team_FragBonuses(self, inflictor, attacker);
735
736 // if I committed suicide, the flag does not fall, it returns.
737 if (meansOfDeath == MOD_SUICIDE) {
738 if ( self->client->ps.powerups[PW_NEUTRALFLAG] ) { // only happens in One Flag CTF
739 Team_ReturnFlag( TEAM_FREE );
740 self->client->ps.powerups[PW_NEUTRALFLAG] = 0;
741 }
742 else if ( self->client->ps.powerups[PW_REDFLAG] ) { // only happens in standard CTF
743 Team_ReturnFlag( TEAM_RED );
744 self->client->ps.powerups[PW_REDFLAG] = 0;
745 }
746 else if ( self->client->ps.powerups[PW_BLUEFLAG] ) { // only happens in standard CTF
747 Team_ReturnFlag( TEAM_BLUE );
748 self->client->ps.powerups[PW_BLUEFLAG] = 0;
749 }
750 }
751 TossClientPersistantPowerups( self );
752 if( g_gametype.integer == GT_HARVESTER ) {
753 TossClientCubes( self );
754 }
755 // if client is in a nodrop area, don't drop anything (but return CTF flags!)
756 TossClientItems( self );
757 //#endif
758
759 Cmd_Score_f( self ); // show scores
760 // send updated scores to any clients that are following this one,
761 // or they would get stale scoreboards
762 for ( i = 0 ; i < level.maxclients ; i++ ) {
763 gclient_t *client;
764
765 client = &level.clients[i];
766 if ( client->pers.connected != CON_CONNECTED ) {
767 continue;
768 }
769 if ( client->sess.sessionTeam != TEAM_SPECTATOR ) {
770 continue;
771 }
772 if ( client->sess.spectatorClient == self->s.number ) {
773 Cmd_Score_f( g_entities + i );
774 }
775 }
776
777 self->takedamage = qtrue; // can still be gibbed
778
779 self->s.weapon = WP_NONE;
780 self->s.powerups = 0;
781 self->r.contents = CONTENTS_CORPSE;
782
783 self->s.angles[0] = 0;
784 self->s.angles[2] = 0;
785 LookAtKiller (self, inflictor, attacker);
786
787 VectorCopy( self->s.angles, self->client->ps.viewangles );
788
789 self->s.loopSound = 0;
790
791 self->r.maxs[2] = -8;
792
793 // don't allow respawn until the death anim is done
794 // g_forcerespawn may force spawning at some later time
795 self->client->respawnTime = level.time + 1700 +i;
796 if(g_respawntime.integer>0) {
797 for(i=0; self->client->respawnTime > i*g_respawntime.integer*1000;i++);
798
799 self->client->respawnTime = i*g_respawntime.integer*1000;
800 }
801 //For testing:
802 //G_Printf("Respawntime: %i\n",self->client->respawnTime);
803 //However during warm up, we should respawn quicker!
804 if(g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION || g_gametype.integer == GT_LMS)
805 if(level.time<=level.roundStartTime && level.time>level.roundStartTime-1000*g_elimination_activewarmup.integer)
806 self->client->respawnTime = level.time + rand()%800;
807
808 RespawnTimeMessage(self,self->client->respawnTime);
809
810
811 // remove powerups
812 memset( self->client->ps.powerups, 0, sizeof(self->client->ps.powerups) );
813
814 // never gib in a nodrop
815 contents = trap_PointContents( self->r.currentOrigin, -1 );
816
817 if ( (self->health <= GIB_HEALTH && !(contents & CONTENTS_NODROP) && g_blood.integer) || meansOfDeath == MOD_SUICIDE) {
818 // gib death
819 GibEntity( self, killer );
820 } else {
821 // normal death
822 static int i;
823
824 switch ( i ) {
825 case 0:
826 anim = BOTH_DEATH1;
827 break;
828 case 1:
829 anim = BOTH_DEATH2;
830 break;
831 case 2:
832 default:
833 anim = BOTH_DEATH3;
834 break;
835 }
836
837 // for the no-blood option, we need to prevent the health
838 // from going to gib level
839 if ( self->health <= GIB_HEALTH ) {
840 self->health = GIB_HEALTH+1;
841 }
842
843 self->client->ps.legsAnim =
844 ( ( self->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim;
845 self->client->ps.torsoAnim =
846 ( ( self->client->ps.torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim;
847
848 G_AddEvent( self, EV_DEATH1 + i, killer );
849
850 // the body can still be gibbed
851 self->die = body_die;
852
853 // globally cycle through the different death animations
854 i = ( i + 1 ) % 3;
855
856 if (self->s.eFlags & EF_KAMIKAZE) {
857 Kamikaze_DeathTimer( self );
858 }
859 }
860
861 trap_LinkEntity (self);
862
863 }
864
865
866 /*
867 ================
868 CheckArmor
869 ================
870 */
871 int CheckArmor (gentity_t *ent, int damage, int dflags)
872 {
873 gclient_t *client;
874 int save;
875 int count;
876
877 if (!damage)
878 return 0;
879
880 client = ent->client;
881
882 if (!client)
883 return 0;
884
885 if (dflags & DAMAGE_NO_ARMOR)
886 return 0;
887
888 // armor
889 count = client->ps.stats[STAT_ARMOR];
890 save = ceil( damage * ARMOR_PROTECTION );
891 if (save >= count)
892 save = count;
893
894 if (!save)
895 return 0;
896
897 client->ps.stats[STAT_ARMOR] -= save;
898
899 return save;
900 }
901
902 /*
903 ================
904 RaySphereIntersections
905 ================
906 */
907 int RaySphereIntersections( vec3_t origin, float radius, vec3_t point, vec3_t dir, vec3_t intersections[2] ) {
908 float b, c, d, t;
909
910 // | origin - (point + t * dir) | = radius
911 // a = dir[0]^2 + dir[1]^2 + dir[2]^2;
912 // b = 2 * (dir[0] * (point[0] - origin[0]) + dir[1] * (point[1] - origin[1]) + dir[2] * (point[2] - origin[2]));
913 // c = (point[0] - origin[0])^2 + (point[1] - origin[1])^2 + (point[2] - origin[2])^2 - radius^2;
914
915 // normalize dir so a = 1
916 VectorNormalize(dir);
917 b = 2 * (dir[0] * (point[0] - origin[0]) + dir[1] * (point[1] - origin[1]) + dir[2] * (point[2] - origin[2]));
918 c = (point[0] - origin[0]) * (point[0] - origin[0]) +
919 (point[1] - origin[1]) * (point[1] - origin[1]) +
920 (point[2] - origin[2]) * (point[2] - origin[2]) -
921 radius * radius;
922
923 d = b * b - 4 * c;
924 if (d > 0) {
925 t = (- b + sqrt(d)) / 2;
926 VectorMA(point, t, dir, intersections[0]);
927 t = (- b - sqrt(d)) / 2;
928 VectorMA(point, t, dir, intersections[1]);
929 return 2;
930 }
931 else if (d == 0) {
932 t = (- b ) / 2;
933 VectorMA(point, t, dir, intersections[0]);
934 return 1;
935 }
936 return 0;
937 }
938
939 /*
940 ================
941 G_InvulnerabilityEffect
942 ================
943 */
944 int G_InvulnerabilityEffect( gentity_t *targ, vec3_t dir, vec3_t point, vec3_t impactpoint, vec3_t bouncedir ) {
945 gentity_t *impact;
946 vec3_t intersections[2], vec;
947 int n;
948
949 if ( !targ->client ) {
950 return qfalse;
951 }
952 VectorCopy(dir, vec);
953 VectorInverse(vec);
954 // sphere model radius = 42 units
955 n = RaySphereIntersections( targ->client->ps.origin, 42, point, vec, intersections);
956 if (n > 0) {
957 impact = G_TempEntity( targ->client->ps.origin, EV_INVUL_IMPACT );
958 VectorSubtract(intersections[0], targ->client->ps.origin, vec);
959 vectoangles(vec, impact->s.angles);
960 impact->s.angles[0] += 90;
961 if (impact->s.angles[0] > 360)
962 impact->s.angles[0] -= 360;
963 if ( impactpoint ) {
964 VectorCopy( intersections[0], impactpoint );
965 }
966 if ( bouncedir ) {
967 VectorCopy( vec, bouncedir );
968 VectorNormalize( bouncedir );
969 }
970 return qtrue;
971 }
972 else {
973 return qfalse;
974 }
975 }
976
977 /*
978 catchup_damage
979 */
980 static int catchup_damage(int damage, int attacker_points, int target_points) {
981 int newdamage;
982 if(g_catchup.integer <= 0 )
983 return damage;
984 //Reduce damage
985 if(attacker_points<=target_points+5)
986 return damage; //Never reduce damage if only 5 points ahead.
987
988 newdamage=damage-((attacker_points-target_points-5) * (g_catchup.integer*damage))/100;
989 if(newdamage<damage/2)
990 return damage/2;
991 return newdamage;
992 }
993
994 /*
995 ============
996 T_Damage
997
998 targ entity that is being damaged
999 inflictor entity that is causing the damage
1000 attacker entity that caused the inflictor to damage targ
1001 example: targ=monster, inflictor=rocket, attacker=player
1002
1003 dir direction of the attack for knockback
1004 point point at which the damage is being inflicted, used for headshots
1005 damage amount of damage being inflicted
1006 knockback force to be applied against targ as a result of the damage
1007
1008 inflictor, attacker, dir, and point can be NULL for environmental effects
1009
1010 dflags these flags are used to control how T_Damage works
1011 DAMAGE_RADIUS damage was indirect (from a nearby explosion)
1012 DAMAGE_NO_ARMOR armor does not protect from this damage
1013 DAMAGE_NO_KNOCKBACK do not affect velocity, just view angles
1014 DAMAGE_NO_PROTECTION kills godmode, armor, everything
1015 ============
1016 */
1017
1018 void G_Damage( gentity_t *targ, gentity_t *inflictor, gentity_t *attacker,
1019 vec3_t dir, vec3_t point, int damage, int dflags, int mod ) {
1020 gclient_t *client;
1021 int take;
1022 //int save;
1023 int asave;
1024 int knockback;
1025 int max;
1026
1027 vec3_t bouncedir, impactpoint;
1028
1029 if (!targ->takedamage) {
1030 return;
1031 }
1032
1033 // the intermission has already been qualified for, so don't
1034 // allow any extra scoring
1035 if ( level.intermissionQueued ) {
1036 return;
1037 }
1038 if ( targ->client && mod != MOD_JUICED) {
1039 if ( targ->client->invulnerabilityTime > level.time) {
1040 if ( dir && point ) {
1041 G_InvulnerabilityEffect( targ, dir, point, impactpoint, bouncedir );
1042 }
1043 return;
1044 }
1045 }
1046 //Sago: This was moved up
1047 client = targ->client;
1048
1049 //Sago: See if the client was sent flying
1050 //Check if damage is by somebody who is not a player!
1051 if( (!attacker || attacker->s.eType != ET_PLAYER) && client && client->lastSentFlying>-1 && ( mod==MOD_FALLING || mod==MOD_LAVA || mod==MOD_SLIME || mod==MOD_TRIGGER_HURT || mod==MOD_SUICIDE) ) {
1052 if( client->lastSentFlyingTime+5000<level.time) {
1053 client->lastSentFlying = -1; //More than 5 seconds, not a kill!
1054 } else {
1055 //G_Printf("LastSentFlying %i\n",client->lastSentFlying);
1056 attacker = &g_entities[client->lastSentFlying];
1057 }
1058 }
1059
1060 if ( !inflictor ) {
1061 inflictor = &g_entities[ENTITYNUM_WORLD];
1062 }
1063 if ( !attacker ) {
1064 attacker = &g_entities[ENTITYNUM_WORLD];
1065 }
1066
1067 // shootable doors / buttons don't actually have any health
1068 if ( targ->s.eType == ET_MOVER ) {
1069 if ( targ->use && targ->moverState == MOVER_POS1 ) {
1070 targ->use( targ, inflictor, attacker );
1071 }
1072 return;
1073 }
1074 if( g_gametype.integer == GT_OBELISK && CheckObeliskAttack( targ, attacker ) ) {
1075 return;
1076 }
1077 // reduce damage by the attacker's handicap value
1078 // unless they are rocket jumping
1079 if ( attacker->client && attacker != targ ) {
1080 max = attacker->client->ps.stats[STAT_MAX_HEALTH];
1081 if( bg_itemlist[attacker->client->ps.stats[STAT_PERSISTANT_POWERUP]].giTag == PW_GUARD ) {
1082 max /= 2;
1083 }
1084 damage = damage * max / 100;
1085 }
1086
1087 //Sago: I have moved this up
1088 //client = targ->client;
1089
1090 if ( client ) {
1091 if ( client->noclip ) {
1092 return;
1093 }
1094 }
1095
1096 if ( !dir ) {
1097 dflags |= DAMAGE_NO_KNOCKBACK;
1098 } else {
1099 VectorNormalize(dir);
1100 }
1101
1102 knockback = damage;
1103 if ( knockback > 200 ) {
1104 knockback = 200;
1105 }
1106 if ( targ->flags & FL_NO_KNOCKBACK ) {
1107 knockback = 0;
1108 }
1109 if ( dflags & DAMAGE_NO_KNOCKBACK ) {
1110 knockback = 0;
1111 }
1112
1113 // figure momentum add, even if the damage won't be taken
1114 if ( knockback && targ->client ) {
1115 vec3_t kvel;
1116 float mass;
1117
1118 mass = 200;
1119
1120 VectorScale (dir, g_knockback.value * (float)knockback / mass, kvel);
1121 VectorAdd (targ->client->ps.velocity, kvel, targ->client->ps.velocity);
1122
1123 // set the timer so that the other client can't cancel
1124 // out the movement immediately
1125 if ( !targ->client->ps.pm_time ) {
1126 int t;
1127
1128 t = knockback * 2;
1129 if ( t < 50 ) {
1130 t = 50;
1131 }
1132 if ( t > 200 ) {
1133 t = 200;
1134 }
1135 targ->client->ps.pm_time = t;
1136 targ->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
1137 }
1138 //Remeber the last person to hurt the player
1139 if( !g_awardpushing.integer || targ==attacker || OnSameTeam (targ, attacker)) {
1140 targ->client->lastSentFlying = -1;
1141 } else {
1142 /*if ( pm->waterlevel <= 1 ) {
1143 if ( pml.walking && !(pml.groundTrace.surfaceFlags & SURF_SLICK) ) {
1144 // if getting knocked back, no friction
1145 if ( ! (pm->ps->pm_flags & PMF_TIME_KNOCKBACK) ) {
1146 control = speed < pm_stopspeed ? pm_stopspeed : speed;
1147 drop += control*pm_friction*pml.frametime;
1148 }
1149 }
1150 }*/
1151 targ->client->lastSentFlying = attacker->s.number;
1152 targ->client->lastSentFlyingTime = level.time;
1153 }
1154 }
1155
1156 // check for completely getting out of the damage
1157 if ( !(dflags & DAMAGE_NO_PROTECTION) ) {
1158
1159 // if TF_NO_FRIENDLY_FIRE is set, don't do damage to the target
1160 // if the attacker was on the same team
1161 if ( mod != MOD_JUICED && mod != MOD_CRUSH && targ != attacker && !(dflags & DAMAGE_NO_TEAM_PROTECTION) && OnSameTeam (targ, attacker) ) {
1162 if ( ( !g_friendlyFire.integer && g_gametype.integer != GT_ELIMINATION && g_gametype.integer != GT_CTF_ELIMINATION ) || ( g_elimination_selfdamage.integer<2 && (g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION) ) ) {
1163 return;
1164 }
1165 }
1166 if (mod == MOD_PROXIMITY_MINE) {
1167 if (inflictor && inflictor->parent && OnSameTeam(targ, inflictor->parent)) {
1168 return;
1169 }
1170 if (targ == attacker) {
1171 return;
1172 }
1173 }
1174
1175 // check for godmode
1176 if ( targ->flags & FL_GODMODE ) {
1177 return;
1178 }
1179
1180 if(targ->client && targ->client->spawnprotected) {
1181 if(level.time>targ->client->respawnTime+g_spawnprotect.integer)
1182 targ->client->spawnprotected = qfalse;
1183 else
1184 if( (mod > MOD_UNKNOWN && mod < MOD_WATER) || mod == MOD_TELEFRAG || mod>MOD_TRIGGER_HURT)
1185 return;
1186 }
1187 }
1188
1189 // battlesuit protects from all radius damage (but takes knockback)
1190 // and protects 50% against all damage
1191 if ( client && client->ps.powerups[PW_BATTLESUIT] ) {
1192 G_AddEvent( targ, EV_POWERUP_BATTLESUIT, 0 );
1193 if ( ( dflags & DAMAGE_RADIUS ) || ( mod == MOD_FALLING ) ) {
1194 return;
1195 }
1196 damage *= 0.5;
1197 }
1198
1199 // add to the attacker's hit counter (if the target isn't a general entity like a prox mine)
1200 if ( attacker->client && client
1201 && targ != attacker && targ->health > 0
1202 && targ->s.eType != ET_MISSILE
1203 && targ->s.eType != ET_GENERAL) {
1204 if ( OnSameTeam( targ, attacker ) ) {
1205 attacker->client->ps.persistant[PERS_HITS]--;
1206 } else {
1207 attacker->client->ps.persistant[PERS_HITS]++;
1208 }
1209 attacker->client->ps.persistant[PERS_ATTACKEE_ARMOR] = (targ->health<<8)|(client->ps.stats[STAT_ARMOR]);
1210 }
1211
1212 // always give half damage if hurting self
1213 // calculated after knockback, so rocket jumping works
1214 if ( targ == attacker) {
1215 damage *= 0.5;
1216 }
1217
1218 if(targ && targ->client && attacker->client )
1219 damage = catchup_damage(damage, attacker->client->ps.persistant[PERS_SCORE], targ->client->ps.persistant[PERS_SCORE]);
1220
1221 if(g_damageModifier.value > 0.01) {
1222 damage *= g_damageModifier.value;
1223 }
1224
1225 if ( damage < 1 ) {
1226 damage = 1;
1227 }
1228
1229 if(targ == attacker && (g_dmflags.integer & DF_NO_SELF_DAMAGE) )
1230 damage = 0;
1231
1232 if ((g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION || g_gametype.integer == GT_LMS || g_elimination_allgametypes.integer)
1233 && g_elimination_selfdamage.integer<1 && ( targ == attacker || mod == MOD_FALLING )) {
1234 damage = 0;
1235 }
1236
1237
1238 //So people can be telefragged!
1239 if ((g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION || g_gametype.integer == GT_LMS) && level.time < level.roundStartTime && ((mod == MOD_LAVA) || (mod == MOD_SLIME)) ) {
1240 damage = 1000;
1241 }
1242
1243
1244 take = damage;
1245 //save = 0;
1246
1247 // save some from armor
1248 asave = CheckArmor (targ, take, dflags);
1249 take -= asave;
1250
1251 if ( g_debugDamage.integer ) {
1252 G_Printf( "%i: client:%i health:%i damage:%i armor:%i\n", level.time, targ->s.number,
1253 targ->health, take, asave );
1254 }
1255
1256 // add to the damage inflicted on a player this frame
1257 // the total will be turned into screen blends and view angle kicks
1258 // at the end of the frame
1259 if ( client ) {
1260 if ( attacker ) {
1261 client->ps.persistant[PERS_ATTACKER] = attacker->s.number;
1262 } else if(client->lastSentFlying) {
1263 client->ps.persistant[PERS_ATTACKER] = client->lastSentFlying;
1264 } else {
1265 client->ps.persistant[PERS_ATTACKER] = ENTITYNUM_WORLD;
1266 }
1267 client->damage_armor += asave;
1268 client->damage_blood += take;
1269 client->damage_knockback += knockback;
1270 if ( dir ) {
1271 VectorCopy ( dir, client->damage_from );
1272 client->damage_fromWorld = qfalse;
1273 } else {
1274 VectorCopy ( targ->r.currentOrigin, client->damage_from );
1275 client->damage_fromWorld = qtrue;
1276 }
1277 }
1278
1279 // See if it's the player hurting the emeny flag carrier
1280 if( g_gametype.integer == GT_CTF || g_gametype.integer == GT_1FCTF || g_gametype.integer == GT_CTF_ELIMINATION) {
1281 Team_CheckHurtCarrier(targ, attacker);
1282 }
1283
1284 if (targ->client) {
1285 // set the last client who damaged the target
1286 targ->client->lasthurt_client = attacker->s.number;
1287 targ->client->lasthurt_mod = mod;
1288 }
1289
1290 //If vampire is enabled, gain health but not from self or teammate, cannot steal more than targ has
1291 if( g_vampire.value>0.0 && (targ != attacker) && take > 0 &&
1292 !(OnSameTeam(targ, attacker)) && attacker->health > 0 && targ->health > 0 )
1293 {
1294 if(take<targ->health)
1295 attacker->health += (int)(((float)take)*g_vampire.value);
1296 else
1297 attacker->health += (int)(((float)targ->health)*g_vampire.value);
1298 if(attacker->health>g_vampireMaxHealth.integer)
1299 attacker->health = g_vampireMaxHealth.integer;
1300 }
1301
1302 // do the damage
1303 if (take) {
1304 targ->health = targ->health - take;
1305 if ( targ->client ) {
1306 targ->client->ps.stats[STAT_HEALTH] = targ->health;
1307 }
1308
1309 if ( targ->health <= 0 ) {
1310 if ( client )
1311 targ->flags |= FL_NO_KNOCKBACK;
1312
1313 if (targ->health < -999)
1314 targ->health = -999;
1315
1316 targ->enemy = attacker;
1317 targ->die (targ, inflictor, attacker, take, mod);
1318 return;
1319 } else if ( targ->pain ) {
1320 targ->pain (targ, attacker, take);
1321 }
1322 }
1323
1324
1325 }
1326
1327
1328 /*
1329 ============
1330 CanDamage
1331
1332 Returns qtrue if the inflictor can directly damage the target. Used for
1333 explosions and melee attacks.
1334 ============
1335 */
1336 qboolean CanDamage (gentity_t *targ, vec3_t origin) {
1337 vec3_t dest;
1338 trace_t tr;
1339 vec3_t midpoint;
1340
1341 // use the midpoint of the bounds instead of the origin, because
1342 // bmodels may have their origin is 0,0,0
1343 VectorAdd (targ->r.absmin, targ->r.absmax, midpoint);
1344 VectorScale (midpoint, 0.5, midpoint);
1345
1346 VectorCopy (midpoint, dest);
1347 trap_Trace ( &tr, origin, vec3_origin, vec3_origin, dest, ENTITYNUM_NONE, MASK_SOLID);
1348 if (tr.fraction == 1.0 || tr.entityNum == targ->s.number)
1349 return qtrue;
1350
1351 // this should probably check in the plane of projection,
1352 // rather than in world coordinate, and also include Z
1353 VectorCopy (midpoint, dest);
1354 dest[0] += 15.0;
1355 dest[1] += 15.0;
1356 trap_Trace ( &tr, origin, vec3_origin, vec3_origin, dest, ENTITYNUM_NONE, MASK_SOLID);
1357 if (tr.fraction == 1.0)
1358 return qtrue;
1359
1360 VectorCopy (midpoint, dest);
1361 dest[0] += 15.0;
1362 dest[1] -= 15.0;
1363 trap_Trace ( &tr, origin, vec3_origin, vec3_origin, dest, ENTITYNUM_NONE, MASK_SOLID);
1364 if (tr.fraction == 1.0)
1365 return qtrue;
1366
1367 VectorCopy (midpoint, dest);
1368 dest[0] -= 15.0;
1369 dest[1] += 15.0;
1370 trap_Trace ( &tr, origin, vec3_origin, vec3_origin, dest, ENTITYNUM_NONE, MASK_SOLID);
1371 if (tr.fraction == 1.0)
1372 return qtrue;
1373
1374 VectorCopy (midpoint, dest);
1375 dest[0] -= 15.0;
1376 dest[1] -= 15.0;
1377 trap_Trace ( &tr, origin, vec3_origin, vec3_origin, dest, ENTITYNUM_NONE, MASK_SOLID);
1378 if (tr.fraction == 1.0)
1379 return qtrue;
1380
1381
1382 return qfalse;
1383 }
1384
1385
1386 /*
1387 ============
1388 G_RadiusDamage
1389 ============
1390 */
1391 qboolean G_RadiusDamage ( vec3_t origin, gentity_t *attacker, float damage, float radius,
1392 gentity_t *ignore, int mod) {
1393 float points, dist;
1394 gentity_t *ent;
1395 int entityList[MAX_GENTITIES];
1396 int numListedEntities;
1397 vec3_t mins, maxs;
1398 vec3_t v;
1399 vec3_t dir;
1400 int i, e;
1401 qboolean hitClient = qfalse;
1402
1403 if ( radius < 1 ) {
1404 radius = 1;
1405 }
1406
1407 for ( i = 0 ; i < 3 ; i++ ) {
1408 mins[i] = origin[i] - radius;
1409 maxs[i] = origin[i] + radius;
1410 }
1411
1412 numListedEntities = trap_EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
1413
1414 for ( e = 0 ; e < numListedEntities ; e++ ) {
1415 ent = &g_entities[entityList[ e ]];
1416
1417 if (ent == ignore)
1418 continue;
1419 if (!ent->takedamage)
1420 continue;
1421
1422 // find the distance from the edge of the bounding box
1423 for ( i = 0 ; i < 3 ; i++ ) {
1424 if ( origin[i] < ent->r.absmin[i] ) {
1425 v[i] = ent->r.absmin[i] - origin[i];
1426 } else if ( origin[i] > ent->r.absmax[i] ) {
1427 v[i] = origin[i] - ent->r.absmax[i];
1428 } else {
1429 v[i] = 0;
1430 }
1431 }
1432
1433 dist = VectorLength( v );
1434 if ( dist >= radius ) {
1435 continue;
1436 }
1437
1438 points = damage * ( 1.0 - dist / radius );
1439
1440 if( CanDamage (ent, origin) ) {
1441 if( LogAccuracyHit( ent, attacker ) ) {
1442 hitClient = qtrue;
1443 }
1444 VectorSubtract (ent->r.currentOrigin, origin, dir);
1445 // push the center of mass higher than the origin so players
1446 // get knocked into the air more
1447 dir[2] += 24;
1448 G_Damage (ent, NULL, attacker, dir, origin, (int)points, DAMAGE_RADIUS, mod);
1449 }
1450 }
1451
1452 return hitClient;
1453 }