1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
|
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of Quake III Arena source code.
Quake III Arena source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Quake III Arena source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Quake III Arena source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
//
// bg_misc.c -- both games misc functions, all completely stateless
#include "../qcommon/q_shared.h"
#include "bg_public.h"
/*
================
BG_EvaluateTrajectoryDelta
For determining velocity at a given time
================
*/
void BG_EvaluateTrajectoryDelta(const trajectory_t *tr, int atTime, vec3_t result) {}
// FIXME: OLD Q3 CODE
#if 0
/*
================
BG_CanItemBeGrabbed
Returns false if the item should not be picked up.
This needs to be the same for client side prediction and server use.
================
*/
qboolean BG_CanItemBeGrabbed( int gametype, const entityState_t *ent, const playerState_t *ps )
{
gitem_t *item;
# ifdef MISSIONPACK
int upperBound;
# endif
if ( ent->modelindex < 1 || ent->modelindex >= bg_numItems ) {
Com_Error( ERR_DROP, "BG_CanItemBeGrabbed: index out of range" );
}
item = &bg_itemlist[ent->modelindex];
switch( item->giType ) {
case IT_WEAPON:
return qtrue; // weapons are always picked up
case IT_AMMO:
if ( ps->ammo[ item->giTag ] >= 200 ) {
return qfalse; // can't hold any more
}
return qtrue;
case IT_ARMOR:
# ifdef MISSIONPACK
if( bg_itemlist[ps->stats[STAT_PERSISTANT_POWERUP]].giTag == PW_SCOUT ) {
return qfalse;
}
// we also clamp armor to the maxhealth for handicapping
if( bg_itemlist[ps->stats[STAT_PERSISTANT_POWERUP]].giTag == PW_GUARD ) {
upperBound = ps->stats[STAT_MAX_HEALTH];
}
else {
upperBound = ps->stats[STAT_MAX_HEALTH] * 2;
}
if ( ps->stats[STAT_ARMOR] >= upperBound ) {
return qfalse;
}
# else
if ( ps->stats[STAT_ARMOR] >= ps->stats[STAT_MAX_HEALTH] * 2 ) {
return qfalse;
}
# endif
return qtrue;
case IT_HEALTH:
// small and mega healths will go over the max, otherwise
// don't pick up if already at max
# ifdef MISSIONPACK
if( bg_itemlist[ps->stats[STAT_PERSISTANT_POWERUP]].giTag == PW_GUARD ) {
upperBound = ps->stats[STAT_MAX_HEALTH];
}
else
# endif
if ( item->quantity == 5 || item->quantity == 100 ) {
if ( ps->stats[STAT_HEALTH] >= ps->stats[STAT_MAX_HEALTH] * 2 ) {
return qfalse;
}
return qtrue;
}
if ( ps->stats[STAT_HEALTH] >= ps->stats[STAT_MAX_HEALTH] ) {
return qfalse;
}
return qtrue;
case IT_POWERUP:
return qtrue; // powerups are always picked up
# ifdef MISSIONPACK
case IT_PERSISTANT_POWERUP:
// can only hold one item at a time
if ( ps->stats[STAT_PERSISTANT_POWERUP] ) {
return qfalse;
}
// check team only
if( ( ent->generic1 & 2 ) && ( ps->stats[STAT_TEAM] != TEAM_RED ) ) {
return qfalse;
}
if( ( ent->generic1 & 4 ) && ( ps->stats[STAT_TEAM] != TEAM_BLUE ) ) {
return qfalse;
}
return qtrue;
# endif
case IT_TEAM: // team items, such as flags
# ifdef MISSIONPACK
if( gametype == GT_1FCTF ) {
// neutral flag can always be picked up
if( item->giTag == PW_NEUTRALFLAG ) {
return qtrue;
}
if (ps->stats[STAT_TEAM] == TEAM_RED) {
if (item->giTag == PW_BLUEFLAG && ps->powerups[PW_NEUTRALFLAG] ) {
return qtrue;
}
} else if (ps->stats[STAT_TEAM] == TEAM_BLUE) {
if (item->giTag == PW_REDFLAG && ps->powerups[PW_NEUTRALFLAG] ) {
return qtrue;
}
}
}
# endif
if( gametype == GT_CTF ) {
// ent->modelindex2 is non-zero on items if they are dropped
// we need to know this because we can pick up our dropped flag (and return it)
// but we can't pick up our flag at base
if (ps->stats[STAT_TEAM] == TEAM_RED) {
if (item->giTag == PW_BLUEFLAG ||
(item->giTag == PW_REDFLAG && ent->modelindex2) ||
(item->giTag == PW_REDFLAG && ps->powerups[PW_BLUEFLAG]) )
return qtrue;
} else if (ps->stats[STAT_TEAM] == TEAM_BLUE) {
if (item->giTag == PW_REDFLAG ||
(item->giTag == PW_BLUEFLAG && ent->modelindex2) ||
(item->giTag == PW_BLUEFLAG && ps->powerups[PW_REDFLAG]) )
return qtrue;
}
}
# ifdef MISSIONPACK
if( gametype == GT_HARVESTER ) {
return qtrue;
}
# endif
return qfalse;
case IT_HOLDABLE:
// can only hold one item at a time
if ( ps->stats[STAT_HOLDABLE_ITEM] ) {
return qfalse;
}
return qtrue;
case IT_BAD:
Com_Error( ERR_DROP, "BG_CanItemBeGrabbed: IT_BAD" );
default:
# ifndef Q3_VM
# ifndef NDEBUG
Com_Printf("BG_CanItemBeGrabbed: unknown enum %d\n", item->giType );
# endif
# endif
break;
}
return qfalse;
}
//======================================================================
/*
================
BG_EvaluateTrajectory
================
*/
void BG_EvaluateTrajectory( const trajectory_t *tr, int atTime, vec3_t result )
{
float deltaTime;
float phase;
switch( tr->trType ) {
case TR_STATIONARY:
case TR_INTERPOLATE:
VectorCopy( tr->trBase, result );
break;
case TR_LINEAR:
deltaTime = ( atTime - tr->trTime ) * 0.001; // milliseconds to seconds
VectorMA( tr->trBase, deltaTime, tr->trDelta, result );
break;
case TR_SINE:
deltaTime = ( atTime - tr->trTime ) / (float) tr->trDuration;
phase = sin( deltaTime * M_PI * 2 );
VectorMA( tr->trBase, phase, tr->trDelta, result );
break;
case TR_LINEAR_STOP:
if ( atTime > tr->trTime + tr->trDuration ) {
atTime = tr->trTime + tr->trDuration;
}
deltaTime = ( atTime - tr->trTime ) * 0.001; // milliseconds to seconds
if ( deltaTime < 0 ) {
deltaTime = 0;
}
VectorMA( tr->trBase, deltaTime, tr->trDelta, result );
break;
case TR_GRAVITY:
deltaTime = ( atTime - tr->trTime ) * 0.001; // milliseconds to seconds
VectorMA( tr->trBase, deltaTime, tr->trDelta, result );
result[2] -= 0.5 * DEFAULT_GRAVITY * deltaTime * deltaTime; // FIXME: local gravity...
break;
default:
Com_Error( ERR_DROP, "BG_EvaluateTrajectory: unknown trType: %i", tr->trTime );
break;
}
}
/*
================
BG_EvaluateTrajectoryDelta
For determining velocity at a given time
================
*/
void BG_EvaluateTrajectoryDelta( const trajectory_t *tr, int atTime, vec3_t result ) {
float deltaTime;
float phase;
switch( tr->trType ) {
case TR_STATIONARY:
case TR_INTERPOLATE:
VectorClear( result );
break;
case TR_LINEAR:
VectorCopy( tr->trDelta, result );
break;
case TR_SINE:
deltaTime = ( atTime - tr->trTime ) / (float) tr->trDuration;
phase = cos( deltaTime * M_PI * 2 ); // derivative of sin = cos
phase *= 0.5;
VectorScale( tr->trDelta, phase, result );
break;
case TR_LINEAR_STOP:
if ( atTime > tr->trTime + tr->trDuration ) {
VectorClear( result );
return;
}
VectorCopy( tr->trDelta, result );
break;
case TR_GRAVITY:
deltaTime = ( atTime - tr->trTime ) * 0.001; // milliseconds to seconds
VectorCopy( tr->trDelta, result );
result[2] -= DEFAULT_GRAVITY * deltaTime; // FIXME: local gravity...
break;
default:
Com_Error( ERR_DROP, "BG_EvaluateTrajectoryDelta: unknown trType: %i", tr->trTime );
break;
}
}
#endif
/*
========================
BG_TouchJumpPad
========================
*/
void BG_TouchJumpPad(playerState_t *ps, entityState_t *jumppad) {}
/*
========================
BG_PlayerStateToEntityState
This is done after each set of usercmd_t on the server,
and after local prediction on the client
========================
*/
void BG_PlayerStateToEntityState(playerState_t *ps, entityState_t *s, qboolean snap)
{
if (ps->pm_type == PM_NOCLIP) {
s->eType = 0; //ET_INVISIBLE;
//} else if ( ps->stats[STAT_HEALTH] <= GIB_HEALTH ) {
// s->eType = 0;//ET_INVISIBLE;
} else {
s->eType = ET_PLAYER;
}
s->number = ps->clientNum;
VectorCopy(ps->origin, s->origin);
if (snap) {
SnapVector(s->origin);
}
// set the trDelta for flag direction
VectorCopy(ps->velocity, s->pos.trDelta);
VectorCopy(ps->viewangles, s->angles);
if (snap) {
SnapVector(s->angles);
}
//s->angles2[YAW] = ps->movementDir;
s->clientNum = ps->clientNum; // ET_PLAYER looks here instead of at number
// so corpses can also reference the proper config
//s->eFlags = ps->eFlags;
//if ( ps->stats[STAT_HEALTH] <= 0 ) {
// s->eFlags |= EF_DEAD;
//} else {
// s->eFlags &= ~EF_DEAD;
//}
s->groundEntityNum = ps->groundEntityNum;
}
/*
========================
BG_PlayerStateToEntityStateExtraPolate
This is done after each set of usercmd_t on the server,
and after local prediction on the client
========================
*/
void BG_PlayerStateToEntityStateExtraPolate(playerState_t *ps, entityState_t *s, int time, qboolean snap)
{
if (ps->pm_type == PM_NOCLIP) {
s->eType = 0; //ET_INVISIBLE;
//} else if ( ps->stats[STAT_HEALTH] <= GIB_HEALTH ) {
// s->eType = 0;//ET_INVISIBLE;
} else {
s->eType = ET_PLAYER;
}
s->number = ps->clientNum;
VectorCopy(ps->origin, s->origin);
if (snap) {
SnapVector(s->origin);
}
// set the trDelta for flag direction and linear prediction
VectorCopy(ps->velocity, s->pos.trDelta);
// set the time for linear prediction
s->pos.trTime = time;
VectorCopy(ps->viewangles, s->angles);
if (snap) {
SnapVector(s->angles);
}
s->clientNum = ps->clientNum; // ET_PLAYER looks here instead of at number
// so corpses can also reference the proper config
s->groundEntityNum = ps->groundEntityNum;
}
/*
========================
BG_MapCGMToProtocol
This is done after each set of usercmd_t on the server,
and after local prediction on the client
========================
*/
int BG_MapCGMToProtocol(int protocol, int messageNumber)
{
int newMessageNumber = messageNumber;
if (protocol >= PROTOCOL_MOHTA_MIN) {
// no need translation
return messageNumber;
}
if (messageNumber > 40) {
// unsupported...
return messageNumber;
}
if (messageNumber >= 17) {
return messageNumber - 3;
}
if (messageNumber == 15 || messageNumber == 16) {
// return explosion effect number 2
return 14;
}
if (messageNumber > 10) {
return messageNumber - 1;
}
return newMessageNumber;
}
|