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