codemp/game/bg_misc.c File Reference

#include "q_shared.h"
#include "bg_public.h"
#include "bg_strap.h"
#include "../cgame/cg_local.h"
#include "../namespace_begin.h"
#include "../namespace_end.h"

Go to the source code of this file.

Defines

#define MAX_POOL_SIZE   512000

Functions

qboolean BG_FileExists (const char *fileName)
char * CG_NewString (const char *string)
void BG_ParseField (BG_field_t *l_fields, const char *key, const char *value, byte *ent)
qboolean BG_LegalizedForcePowers (char *powerOut, int maxRank, qboolean freeSaber, int teamForce, int gametype, int fpDisabled)
float vectoyaw (const vec3_t vec)
qboolean BG_HasYsalamiri (int gametype, playerState_t *ps)
qboolean BG_CanUseFPNow (int gametype, playerState_t *ps, int time, forcePowers_t power)
gitem_tBG_FindItemForPowerup (powerup_t pw)
gitem_tBG_FindItemForHoldable (holdable_t pw)
gitem_tBG_FindItemForWeapon (weapon_t weapon)
gitem_tBG_FindItemForAmmo (ammo_t ammo)
gitem_tBG_FindItem (const char *classname)
qboolean BG_PlayerTouchesItem (playerState_t *ps, entityState_t *item, int atTime)
int BG_ProperForceIndex (int power)
void BG_CycleForce (playerState_t *ps, int direction)
int BG_GetItemIndexByTag (int tag, int type)
qboolean BG_IsItemSelectable (playerState_t *ps, int item)
void BG_CycleInven (playerState_t *ps, int direction)
qboolean BG_CanItemBeGrabbed (int gametype, const entityState_t *ent, const playerState_t *ps)
void BG_EvaluateTrajectory (const trajectory_t *tr, int atTime, vec3_t result)
void BG_EvaluateTrajectoryDelta (const trajectory_t *tr, int atTime, vec3_t result)
void BG_AddPredictableEventToPlayerstate (int newEvent, int eventParm, playerState_t *ps)
void BG_TouchJumpPad (playerState_t *ps, entityState_t *jumppad)
int BG_EmplacedView (vec3_t baseAngles, vec3_t angles, float *newYaw, float constraint)
qboolean BG_IsValidCharacterModel (const char *modelName, const char *skinName)
qboolean BG_ValidateSkinForTeam (const char *modelName, char *skinName, int team, float *colors)
void BG_PlayerStateToEntityState (playerState_t *ps, entityState_t *s, qboolean snap)
void BG_PlayerStateToEntityStateExtraPolate (playerState_t *ps, entityState_t *s, int time, qboolean snap)
qhandle_t trap_R_RegisterModel (const char *name)
qhandle_t trap_R_RegisterSkin (const char *name)
int BG_ModelCache (const char *modelName, const char *skinName)
void * BG_Alloc (int size)
void * BG_AllocUnaligned (int size)
void * BG_TempAlloc (int size)
void BG_TempFree (int size)
char * BG_StringAlloc (const char *source)
qboolean BG_OutOfMemory (void)

Variables

const char * bgToggleableSurfaces [BG_NUM_TOGGLEABLE_SURFACES]
const int bgToggleableSurfaceDebris [BG_NUM_TOGGLEABLE_SURFACES]
const char * bg_customSiegeSoundNames [MAX_CUSTOM_SIEGE_SOUNDS]
char * forceMasteryLevels [NUM_FORCE_MASTERY_LEVELS]
int forceMasteryPoints [NUM_FORCE_MASTERY_LEVELS]
int bgForcePowerCost [NUM_FORCE_POWERS][NUM_FORCE_POWER_LEVELS]
int forcePowerSorted [NUM_FORCE_POWERS]
int forcePowerDarkLight [NUM_FORCE_POWERS]
int WeaponReadyAnim [WP_NUM_WEAPONS]
int WeaponReadyLegsAnim [WP_NUM_WEAPONS]
int WeaponAttackAnim [WP_NUM_WEAPONS]
gitem_t bg_itemlist []
int bg_numItems = sizeof(bg_itemlist) / sizeof(bg_itemlist[0]) - 1
char * eventnames []


Define Documentation

#define MAX_POOL_SIZE   512000
 

Definition at line 3316 of file bg_misc.c.

Referenced by BG_OutOfMemory(), and BG_TempFree().


Function Documentation

void BG_AddPredictableEventToPlayerstate int  newEvent,
int  eventParm,
playerState_t ps
 

Definition at line 2635 of file bg_misc.c.

References Com_Printf(), eventnames, playerState_s::eventParms, playerState_s::events, playerState_s::eventSequence, vmCvar_t::integer, MAX_PS_EVENTS, playerState_t, playerState_s::pmove_framecount, qboolean, qfalse, qtrue, and trap_Cvar_Register().

Referenced by G_AddPredictableEvent(), PM_AddEvent(), PM_AddEventWithParm(), PM_SaberLockBreak(), PM_SaberLocked(), PM_SetSaberMove(), and Touch_Item().

02635                                                                                            {
02636 
02637 #ifdef _DEBUG
02638         {
02639                 static vmCvar_t         showEvents;
02640                 static qboolean         isRegistered = qfalse;
02641 
02642                 if (!isRegistered)
02643                 {
02644                         trap_Cvar_Register(&showEvents, "showevents", "0", 0);
02645                         isRegistered = qtrue;
02646                 }
02647 
02648                 if ( showEvents.integer != 0 ) {
02649 #ifdef QAGAME
02650                         Com_Printf(" game event svt %5d -> %5d: num = %20s parm %d\n", ps->pmove_framecount/*ps->commandTime*/, ps->eventSequence, eventnames[newEvent], eventParm);
02651 #else
02652                         Com_Printf("Cgame event svt %5d -> %5d: num = %20s parm %d\n", ps->pmove_framecount/*ps->commandTime*/, ps->eventSequence, eventnames[newEvent], eventParm);
02653 #endif
02654                 }
02655         }
02656 #endif
02657         ps->events[ps->eventSequence & (MAX_PS_EVENTS-1)] = newEvent;
02658         ps->eventParms[ps->eventSequence & (MAX_PS_EVENTS-1)] = eventParm;
02659         ps->eventSequence++;
02660 }

void* BG_Alloc int  size  ) 
 

Definition at line 3328 of file bg_misc.c.

References Com_Error(), and ERR_DROP.

Referenced by B_Alloc(), BG_AnimsetAlloc(), BG_StringAlloc(), CG_CreateNPCClient(), G_CreateAnimalNPC(), G_CreateFakeClient(), G_CreateFighterNPC(), G_CreateSpeederNPC(), G_CreateWalkerNPC(), New_NPC_t(), ParseAnimationEvtBlock(), UI_AnimsetAlloc(), and UI_InsertG2Pointer().

03329 {
03330         bg_poolSize = ((bg_poolSize + 0x00000003) & 0xfffffffc);
03331 
03332         if (bg_poolSize + size > bg_poolTail)
03333         {
03334                 Com_Error( ERR_DROP, "BG_Alloc: buffer exceeded tail (%d > %d)", bg_poolSize + size, bg_poolTail);
03335                 return 0;
03336         }
03337 
03338         bg_poolSize += size;
03339 
03340         return &bg_pool[bg_poolSize-size];
03341 }

void* BG_AllocUnaligned int  size  ) 
 

Definition at line 3343 of file bg_misc.c.

References Com_Error(), and ERR_DROP.

03344 {
03345         if (bg_poolSize + size > bg_poolTail)
03346         {
03347                 Com_Error( ERR_DROP, "BG_AllocUnaligned: buffer exceeded tail (%d > %d)", bg_poolSize + size, bg_poolTail);
03348                 return 0;
03349         }
03350 
03351         bg_poolSize += size;
03352 
03353         return &bg_pool[bg_poolSize-size];
03354 }

qboolean BG_CanItemBeGrabbed int  gametype,
const entityState_t ent,
const playerState_t ps
 

Definition at line 2192 of file bg_misc.c.

References playerState_s::ammo, ammoData, bg_itemlist, bg_numItems, playerState_s::clientNum, Com_Error(), Com_Printf(), playerState_s::duelInProgress, EF_DROPPEDWEAPON, entityState_s::eFlags, entityState_t, ERR_DROP, playerState_s::fd, forcedata_s::forcePowersActive, FP_RAGE, entityState_s::generic1, gitem_s::giTag, gitem_t, gitem_s::giType, GT_CTF, GT_CTY, HI_SEEKER, playerState_s::isJediMaster, IT_AMMO, IT_ARMOR, IT_BAD, IT_HEALTH, IT_HOLDABLE, IT_POWERUP, IT_TEAM, IT_WEAPON, ammoData_s::max, entityState_s::modelindex, entityState_s::modelindex2, PERS_TEAM, playerState_s::persistant, playerState_t, entityState_s::powerups, playerState_s::powerups, PW_BLUEFLAG, PW_REDFLAG, PW_YSALAMIRI, qboolean, qfalse, qtrue, gitem_s::quantity, STAT_ARMOR, STAT_HEALTH, STAT_HOLDABLE_ITEMS, STAT_MAX_HEALTH, STAT_WEAPONS, playerState_s::stats, TEAM_BLUE, TEAM_RED, playerState_s::trueJedi, playerState_s::trueNonJedi, weaponData, WP_DET_PACK, WP_SABER, WP_THERMAL, and WP_TRIP_MINE.

Referenced by Touch_Item().

02192                                                                                                 {
02193         gitem_t *item;
02194 
02195         if ( ent->modelindex < 1 || ent->modelindex >= bg_numItems ) {
02196                 Com_Error( ERR_DROP, "BG_CanItemBeGrabbed: index out of range" );
02197         }
02198 
02199         item = &bg_itemlist[ent->modelindex];
02200 
02201         if ( ps )
02202         {
02203                 if ( ps->trueJedi )
02204                 {//force powers and saber only
02205                         if ( item->giType != IT_TEAM //not a flag
02206                                 && item->giType != IT_ARMOR//not shields
02207                                 && (item->giType != IT_WEAPON || item->giTag != WP_SABER)//not a saber
02208                                 && (item->giType != IT_HOLDABLE || item->giTag != HI_SEEKER)//not a seeker
02209                                 && (item->giType != IT_POWERUP || item->giTag == PW_YSALAMIRI) )//not a force pick-up
02210                         {
02211                                 return qfalse;
02212                         }
02213                 }
02214                 else if ( ps->trueNonJedi )
02215                 {//can't pick up force powerups
02216                         if ( (item->giType == IT_POWERUP && item->giTag != PW_YSALAMIRI) //if a powerup, can only can pick up ysalamiri
02217                                 || (item->giType == IT_HOLDABLE && item->giTag == HI_SEEKER)//if holdable, cannot pick up seeker 
02218                                 || (item->giType == IT_WEAPON && item->giTag == WP_SABER ) )//or if it's a saber
02219                         {
02220                                 return qfalse;
02221                         }
02222                 }
02223                 if ( ps->isJediMaster && item && (item->giType == IT_WEAPON || item->giType == IT_AMMO))
02224                 {//jedi master cannot pick up weapons
02225                         return qfalse;
02226                 }
02227                 if ( ps->duelInProgress )
02228                 { //no picking stuff up while in a duel, no matter what the type is
02229                         return qfalse;
02230                 }
02231         }
02232         else
02233         {//safety return since below code assumes a non-null ps
02234                 return qfalse;
02235         }
02236 
02237         switch( item->giType ) {
02238         case IT_WEAPON:
02239                 if (ent->generic1 == ps->clientNum && ent->powerups)
02240                 {
02241                         return qfalse;
02242                 }
02243                 if (!(ent->eFlags & EF_DROPPEDWEAPON) && (ps->stats[STAT_WEAPONS] & (1 << item->giTag)) &&
02244                         item->giTag != WP_THERMAL && item->giTag != WP_TRIP_MINE && item->giTag != WP_DET_PACK)
02245                 { //weaponstay stuff.. if this isn't dropped, and you already have it, you don't get it.
02246                         return qfalse;
02247                 }
02248                 if (item->giTag == WP_THERMAL || item->giTag == WP_TRIP_MINE || item->giTag == WP_DET_PACK)
02249                 { //check to see if full on ammo for this, if so, then..
02250                         int ammoIndex = weaponData[item->giTag].ammoIndex;
02251                         if (ps->ammo[ammoIndex] >= ammoData[ammoIndex].max)
02252                         { //don't need it
02253                                 return qfalse;
02254                         }
02255                 }
02256                 return qtrue;   // weapons are always picked up
02257 
02258         case IT_AMMO:
02259                 if (item->giTag == -1)
02260                 { //special case for "all ammo" packs
02261                         return qtrue;
02262                 }
02263                 if ( ps->ammo[item->giTag] >= ammoData[item->giTag].max) {
02264                         return qfalse;          // can't hold any more
02265                 }
02266                 return qtrue;
02267 
02268         case IT_ARMOR:
02269                 if ( ps->stats[STAT_ARMOR] >= ps->stats[STAT_MAX_HEALTH]/* * item->giTag*/ ) {
02270                         return qfalse;
02271                 }
02272                 return qtrue;
02273 
02274         case IT_HEALTH:
02275                 // small and mega healths will go over the max, otherwise
02276                 // don't pick up if already at max
02277                 if ((ps->fd.forcePowersActive & (1 << FP_RAGE)))
02278                 {
02279                         return qfalse;
02280                 }
02281 
02282                 if ( item->quantity == 5 || item->quantity == 100 ) {
02283                         if ( ps->stats[STAT_HEALTH] >= ps->stats[STAT_MAX_HEALTH] * 2 ) {
02284                                 return qfalse;
02285                         }
02286                         return qtrue;
02287                 }
02288 
02289                 if ( ps->stats[STAT_HEALTH] >= ps->stats[STAT_MAX_HEALTH] ) {
02290                         return qfalse;
02291                 }
02292                 return qtrue;
02293 
02294         case IT_POWERUP:
02295                 if (ps && (ps->powerups[PW_YSALAMIRI]))
02296                 {
02297                         if (item->giTag != PW_YSALAMIRI)
02298                         {
02299                                 return qfalse;
02300                         }
02301                 }
02302                 return qtrue;   // powerups are always picked up
02303 
02304         case IT_TEAM: // team items, such as flags
02305                 if( gametype == GT_CTF || gametype == GT_CTY ) {
02306                         // ent->modelindex2 is non-zero on items if they are dropped
02307                         // we need to know this because we can pick up our dropped flag (and return it)
02308                         // but we can't pick up our flag at base
02309                         if (ps->persistant[PERS_TEAM] == TEAM_RED) {
02310                                 if (item->giTag == PW_BLUEFLAG ||
02311                                         (item->giTag == PW_REDFLAG && ent->modelindex2) ||
02312                                         (item->giTag == PW_REDFLAG && ps->powerups[PW_BLUEFLAG]) )
02313                                         return qtrue;
02314                         } else if (ps->persistant[PERS_TEAM] == TEAM_BLUE) {
02315                                 if (item->giTag == PW_REDFLAG ||
02316                                         (item->giTag == PW_BLUEFLAG && ent->modelindex2) ||
02317                                         (item->giTag == PW_BLUEFLAG && ps->powerups[PW_REDFLAG]) )
02318                                         return qtrue;
02319                         }
02320                 }
02321 
02322                 return qfalse;
02323 
02324         case IT_HOLDABLE:
02325                 if ( ps->stats[STAT_HOLDABLE_ITEMS] & (1 << item->giTag))
02326                 {
02327                         return qfalse;
02328                 }
02329                 return qtrue;
02330 
02331         case IT_BAD:
02332             Com_Error( ERR_DROP, "BG_CanItemBeGrabbed: IT_BAD" );
02333         default:
02334 #ifndef Q3_VM
02335 #ifndef NDEBUG // bk0001204
02336           Com_Printf("BG_CanItemBeGrabbed: unknown enum %d\n", item->giType );
02337 #endif
02338 #endif
02339          break;
02340         }
02341 
02342         return qfalse;
02343 }

qboolean BG_CanUseFPNow int  gametype,
playerState_t ps,
int  time,
forcePowers_t  power
 

Definition at line 1810 of file bg_misc.c.

References BG_HasYsalamiri(), BROKENLIMB_LARM, BROKENLIMB_RARM, playerState_s::brokenLimbs, playerState_s::duelInProgress, playerState_s::fallingToDeath, forcePowers_t, playerState_s::forceRestricted, FP_DRAIN, FP_GRIP, FP_LEVITATION, FP_LIGHTNING, FP_PULL, FP_PUSH, FP_SABER_DEFENSE, FP_SABER_OFFENSE, playerState_s::m_iVehicleNum, playerState_t, qboolean, qfalse, qtrue, playerState_s::saberLockFrame, playerState_s::saberLockTime, playerState_s::trueNonJedi, playerState_s::weapon, and WP_EMPLACED_GUN.

Referenced by ForcePowerUsableOn(), PM_ForceJumpingUp(), PM_WeaponLightsaber(), saberFirstThrown(), WP_ForcePowersUpdate(), and WP_ForcePowerUsable().

01811 {
01812         if (BG_HasYsalamiri(gametype, ps))
01813         {
01814                 return qfalse;
01815         }
01816 
01817         if ( ps->forceRestricted || ps->trueNonJedi )
01818         {
01819                 return qfalse;
01820         }
01821 
01822         if (ps->weapon == WP_EMPLACED_GUN)
01823         { //can't use any of your powers while on an emplaced weapon
01824                 return qfalse;
01825         }
01826 
01827         if (ps->m_iVehicleNum)
01828         { //can't use powers while riding a vehicle (this may change, I don't know)
01829                 return qfalse;
01830         }
01831 
01832         if (ps->duelInProgress)
01833         {
01834                 if (power != FP_SABER_OFFENSE && power != FP_SABER_DEFENSE && /*power != FP_SABERTHROW &&*/
01835                         power != FP_LEVITATION)
01836                 {
01837                         if (!ps->saberLockFrame || power != FP_PUSH)
01838                         {
01839                                 return qfalse;
01840                         }
01841                 }
01842         }
01843 
01844         if (ps->saberLockFrame || ps->saberLockTime > time)
01845         {
01846                 if (power != FP_PUSH)
01847                 {
01848                         return qfalse;
01849                 }
01850         }
01851 
01852         if (ps->fallingToDeath)
01853         {
01854                 return qfalse;
01855         }
01856 
01857         if ((ps->brokenLimbs & (1 << BROKENLIMB_RARM)) ||
01858                 (ps->brokenLimbs & (1 << BROKENLIMB_LARM)))
01859         { //powers we can't use with a broken arm
01860         switch (power)
01861                 {
01862                 case FP_PUSH:
01863                 case FP_PULL:
01864                 case FP_GRIP:
01865                 case FP_LIGHTNING:
01866                 case FP_DRAIN:
01867                         return qfalse;
01868                 default:
01869                         break;
01870                 }
01871         }
01872 
01873         return qtrue;
01874 }

void BG_CycleForce playerState_t ps,
int  direction
 

Definition at line 2014 of file bg_misc.c.

References BG_ProperForceIndex(), playerState_s::fd, forcedata_s::forcePowerSelected, forcedata_s::forcePowersKnown, forcePowerSorted, FP_LEVITATION, FP_SABER_DEFENSE, FP_SABER_OFFENSE, FP_SABERTHROW, NUM_FORCE_POWERS, and playerState_t.

Referenced by CG_NextForcePower_f(), and CG_PrevForcePower_f().

02015 {
02016         int i = ps->fd.forcePowerSelected;
02017         int x = i;
02018         int presel = i;
02019         int foundnext = -1;
02020 
02021         if (!ps->fd.forcePowersKnown & (1 << x) ||
02022                 x >= NUM_FORCE_POWERS ||
02023                 x == -1)
02024         { //apparently we have no valid force powers
02025                 return;
02026         }
02027 
02028         x = BG_ProperForceIndex(x);
02029         presel = x;
02030 
02031         if (direction == 1)
02032         { //get the next power
02033                 x++;
02034         }
02035         else
02036         { //get the previous power
02037                 x--;
02038         }
02039 
02040         if (x >= NUM_FORCE_POWERS)
02041         { //cycled off the end.. cycle around to the first
02042                 x = 0;
02043         }
02044         if (x < 0)
02045         { //cycled off the beginning.. cycle around to the last
02046                 x = NUM_FORCE_POWERS-1;
02047         }
02048 
02049         i = forcePowerSorted[x]; //the "sorted" value of this power
02050 
02051         while (x != presel)
02052         { //loop around to the current force power
02053                 if (ps->fd.forcePowersKnown & (1 << i) && i != ps->fd.forcePowerSelected)
02054                 { //we have the force power
02055                         if (i != FP_LEVITATION &&
02056                                 i != FP_SABER_OFFENSE &&
02057                                 i != FP_SABER_DEFENSE &&
02058                                 i != FP_SABERTHROW)
02059                         { //it's selectable
02060                                 foundnext = i;
02061                                 break;
02062                         }
02063                 }
02064 
02065                 if (direction == 1)
02066                 { //next
02067                         x++;
02068                 }
02069                 else
02070                 { //previous
02071                         x--;
02072                 }
02073         
02074                 if (x >= NUM_FORCE_POWERS)
02075                 { //loop around
02076                         x = 0;
02077                 }
02078                 if (x < 0)
02079                 { //loop around
02080                         x = NUM_FORCE_POWERS-1;
02081                 }
02082 
02083                 i = forcePowerSorted[x]; //set to the sorted value again
02084         }
02085 
02086         if (foundnext != -1)
02087         { //found one, select it
02088                 ps->fd.forcePowerSelected = foundnext;
02089         }
02090 }

void BG_CycleInven playerState_t ps,
int  direction
 

Definition at line 2121 of file bg_misc.c.

References BG_GetItemIndexByTag(), BG_IsItemSelectable(), bg_itemlist, HI_NUM_HOLDABLE, IT_HOLDABLE, playerState_t, STAT_HOLDABLE_ITEM, STAT_HOLDABLE_ITEMS, and playerState_s::stats.

Referenced by CG_NextInventory_f(), CG_PrevInventory_f(), and EWebDie().

02122 {
02123         int i;
02124         int dontFreeze = 0;
02125         int original;
02126 
02127         i = bg_itemlist[ps->stats[STAT_HOLDABLE_ITEM]].giTag;
02128         original = i;
02129 
02130         if (direction == 1)
02131         { //next
02132                 i++;
02133                 if (i == HI_NUM_HOLDABLE)
02134                 {
02135                         i = 1;
02136                 }
02137         }
02138         else
02139         { //previous
02140                 i--;
02141                 if (i == 0)
02142                 {
02143                         i = HI_NUM_HOLDABLE-1;
02144                 }
02145         }
02146 
02147         while (i != original)
02148         { //go in a full loop until hitting something, if hit nothing then select nothing
02149                 if (ps->stats[STAT_HOLDABLE_ITEMS] & (1 << i))
02150                 { //we have it, select it.
02151                         if (BG_IsItemSelectable(ps, i))
02152                         {
02153                                 ps->stats[STAT_HOLDABLE_ITEM] = BG_GetItemIndexByTag(i, IT_HOLDABLE);
02154                                 break;
02155                         }
02156                 }
02157 
02158                 if (direction == 1)
02159                 { //next
02160                         i++;
02161                 }
02162                 else
02163                 { //previous
02164                         i--;
02165                 }
02166 
02167                 if (i <= 0)
02168                 { //wrap around to the last
02169                         i = HI_NUM_HOLDABLE-1;
02170                 }
02171                 else if (i >= HI_NUM_HOLDABLE)
02172                 { //wrap around to the first
02173                         i = 1;
02174                 }
02175 
02176                 dontFreeze++;
02177                 if (dontFreeze >= 32)
02178                 { //yeah, sure, whatever (it's 2 am and I'm paranoid and can't frickin think)
02179                         break;
02180                 }
02181         }
02182 }

int BG_EmplacedView vec3_t  baseAngles,
vec3_t  angles,
float *  newYaw,
float  constraint
 

Definition at line 2703 of file bg_misc.c.

References AngleSubtract(), vec3_t, and YAW.

Referenced by CG_EmplacedView(), CG_Player(), EWebThink(), and FireWeapon().

02704 {
02705         float dif = AngleSubtract(baseAngles[YAW], angles[YAW]);
02706 
02707         if (dif > constraint ||
02708                 dif < -constraint)
02709         {
02710                 float amt;
02711 
02712                 if (dif > constraint)
02713                 {
02714                         amt = (dif-constraint);
02715                         dif = constraint;
02716                 }
02717                 else if (dif < -constraint)
02718                 {
02719                         amt = (dif+constraint);
02720                         dif = -constraint;
02721                 }
02722                 else
02723                 {
02724                         amt = 0.0f;
02725                 }
02726 
02727                 *newYaw = AngleSubtract(angles[YAW], -dif);
02728 
02729                 if (amt > 1.0f || amt < -1.0f)
02730                 { //significant, force the view
02731                         return 2;
02732                 }
02733                 else
02734                 { //just a little out of range
02735                         return 1;
02736                 }
02737         }
02738 
02739         return 0;
02740 }

void BG_EvaluateTrajectory const trajectory_t tr,
int  atTime,
vec3_t  result
 

Definition at line 2353 of file bg_misc.c.

References Com_Error(), cos(), DEFAULT_GRAVITY, DEG2RAD, ERR_DROP, M_PI, sin(), TR_GRAVITY, TR_INTERPOLATE, TR_LINEAR, TR_LINEAR_STOP, TR_NONLINEAR_STOP, TR_SINE, TR_STATIONARY, trajectory_t::trBase, trajectory_t::trDelta, trajectory_t::trDuration, trajectory_t::trTime, trajectory_t::trType, vec3_t, VectorCopy, and VectorMA.

Referenced by BG_PlayerTouchesItem(), CG_AddFragment(), CG_AdjustPositionForMover(), CG_BloodTrail(), CG_CalcEntityLerpPositions(), CG_CheckEvents(), CG_DrawRadar(), CG_ResetPlayerEntity(), fx_runner_think(), G_ExplodeMissile(), G_MoverTeam(), G_RunItem(), G_RunMissile(), G_RunObject(), SetMoverState(), thermalDetonatorExplode(), WP_LobFire(), and WP_SaberPositionUpdate().

02353                                                                                 {
02354         float           deltaTime;
02355         float           phase;
02356 
02357         switch( tr->trType ) {
02358         case TR_STATIONARY:
02359         case TR_INTERPOLATE:
02360                 VectorCopy( tr->trBase, result );
02361                 break;
02362         case TR_LINEAR:
02363                 deltaTime = ( atTime - tr->trTime ) * 0.001;    // milliseconds to seconds
02364                 VectorMA( tr->trBase, deltaTime, tr->trDelta, result );
02365                 break;
02366         case TR_SINE:
02367                 deltaTime = ( atTime - tr->trTime ) / (float) tr->trDuration;
02368                 phase = sin( deltaTime * M_PI * 2 );
02369                 VectorMA( tr->trBase, phase, tr->trDelta, result );
02370                 break;
02371         case TR_LINEAR_STOP:
02372                 if ( atTime > tr->trTime + tr->trDuration ) {
02373                         atTime = tr->trTime + tr->trDuration;
02374                 }
02375                 deltaTime = ( atTime - tr->trTime ) * 0.001;    // milliseconds to seconds
02376                 if ( deltaTime < 0 ) {
02377                         deltaTime = 0;
02378                 }
02379                 VectorMA( tr->trBase, deltaTime, tr->trDelta, result );
02380                 break;
02381         case TR_NONLINEAR_STOP:
02382                 if ( atTime > tr->trTime + tr->trDuration ) 
02383                 {
02384                         atTime = tr->trTime + tr->trDuration;
02385                 }
02386                 //new slow-down at end
02387                 if ( atTime - tr->trTime > tr->trDuration || atTime - tr->trTime <= 0  )
02388                 {
02389                         deltaTime = 0;
02390                 }
02391                 else
02392                 {//FIXME: maybe scale this somehow?  So that it starts out faster and stops faster?
02393                         deltaTime = tr->trDuration*0.001f*((float)cos( DEG2RAD(90.0f - (90.0f*((float)atTime-tr->trTime)/(float)tr->trDuration)) ));
02394                 }
02395                 VectorMA( tr->trBase, deltaTime, tr->trDelta, result );
02396                 break;
02397         case TR_GRAVITY:
02398                 deltaTime = ( atTime - tr->trTime ) * 0.001;    // milliseconds to seconds
02399                 VectorMA( tr->trBase, deltaTime, tr->trDelta, result );
02400                 result[2] -= 0.5 * DEFAULT_GRAVITY * deltaTime * deltaTime;             // FIXME: local gravity...
02401                 break;
02402         default:
02403 #ifdef QAGAME
02404                 Com_Error( ERR_DROP, "BG_EvaluateTrajectory: [GAME SIDE] unknown trType: %i", tr->trType );
02405 #else
02406                 Com_Error( ERR_DROP, "BG_EvaluateTrajectory: [CLIENTGAME SIDE] unknown trType: %i", tr->trType );
02407 #endif
02408                 break;
02409         }
02410 }

void BG_EvaluateTrajectoryDelta const trajectory_t tr,
int  atTime,
vec3_t  result
 

Definition at line 2419 of file bg_misc.c.

References Com_Error(), cos(), DEFAULT_GRAVITY, DEG2RAD, ERR_DROP, M_PI, TR_GRAVITY, TR_INTERPOLATE, TR_LINEAR, TR_LINEAR_STOP, TR_NONLINEAR_STOP, TR_SINE, TR_STATIONARY, trajectory_t::trDelta, trajectory_t::trDuration, trajectory_t::trTime, trajectory_t::trType, vec3_t, VectorClear, VectorCopy, and VectorScale.

Referenced by CG_ReflectVelocity(), G_BounceItem(), G_BounceMissile(), G_BounceObject(), and G_MissileImpact().

02419                                                                                      {
02420         float   deltaTime;
02421         float   phase;
02422 
02423         switch( tr->trType ) {
02424         case TR_STATIONARY:
02425         case TR_INTERPOLATE:
02426                 VectorClear( result );
02427                 break;
02428         case TR_LINEAR:
02429                 VectorCopy( tr->trDelta, result );
02430                 break;
02431         case TR_SINE:
02432                 deltaTime = ( atTime - tr->trTime ) / (float) tr->trDuration;
02433                 phase = cos( deltaTime * M_PI * 2 );    // derivative of sin = cos
02434                 phase *= 0.5;
02435                 VectorScale( tr->trDelta, phase, result );
02436                 break;
02437         case TR_LINEAR_STOP:
02438                 if ( atTime > tr->trTime + tr->trDuration ) {
02439                         VectorClear( result );
02440                         return;
02441                 }
02442                 VectorCopy( tr->trDelta, result );
02443                 break;
02444         case TR_NONLINEAR_STOP:
02445                 if ( atTime - tr->trTime > tr->trDuration || atTime - tr->trTime <= 0  )
02446                 {
02447                         VectorClear( result );
02448                         return;
02449                 }
02450                 deltaTime = tr->trDuration*0.001f*((float)cos( DEG2RAD(90.0f - (90.0f*((float)atTime-tr->trTime)/(float)tr->trDuration)) ));
02451                 VectorScale( tr->trDelta, deltaTime, result );
02452                 break;
02453         case TR_GRAVITY:
02454                 deltaTime = ( atTime - tr->trTime ) * 0.001;    // milliseconds to seconds
02455                 VectorCopy( tr->trDelta, result );
02456                 result[2] -= DEFAULT_GRAVITY * deltaTime;               // FIXME: local gravity...
02457                 break;
02458         default:
02459                 Com_Error( ERR_DROP, "BG_EvaluateTrajectoryDelta: unknown trType: %i", tr->trTime );
02460                 break;
02461         }
02462 }

qboolean BG_FileExists const char *  fileName  ) 
 

Definition at line 319 of file bg_misc.c.

References FS_READ, qboolean, qfalse, qtrue, trap_FS_FCloseFile(), and trap_FS_FOpenFile().

Referenced by BG_ValidateSkinForTeam().

00320 {
00321         if (fileName && fileName[0])
00322         {
00323                 int fh = 0;
00324                 trap_FS_FOpenFile(fileName, &fh, FS_READ);
00325                 if (fh > 0)
00326                 {
00327                         trap_FS_FCloseFile(fh);
00328                         return qtrue;
00329                 }
00330         }
00331 
00332         return qfalse;
00333 }

gitem_t* BG_FindItem const char *  classname  ) 
 

Definition at line 1960 of file bg_misc.c.

References bg_itemlist, gitem_s::classname, gitem_t, NULL, and Q_stricmp().

Referenced by Cmd_Give_f(), G_CheckTeamItems(), G_PrecacheDispensers(), ItemUse_UseDisp(), and SP_gametype_item().

01960                                               {
01961         gitem_t *it;
01962         
01963         for ( it = bg_itemlist + 1 ; it->classname ; it++ ) {
01964                 if ( !Q_stricmp( it->classname, classname) )
01965                         return it;
01966         }
01967 
01968         return NULL;
01969 }

gitem_t* BG_FindItemForAmmo ammo_t  ammo  ) 
 

Definition at line 1941 of file bg_misc.c.

References bg_itemlist, gitem_s::classname, Com_Error(), ERR_DROP, gitem_s::giTag, gitem_t, gitem_s::giType, IT_AMMO, and NULL.

Referenced by NPC_Mark1_Precache(), NPC_Mark2_Precache(), NPC_Probe_Precache(), NPC_Sentry_Precache(), and NPC_ShadowTrooper_Precache().

01941                                            {
01942         gitem_t *it;
01943         
01944         for ( it = bg_itemlist + 1 ; it->classname ; it++) {
01945                 if ( it->giType == IT_AMMO && it->giTag == ammo ) {
01946                         return it;
01947                 }
01948         }
01949 
01950         Com_Error( ERR_DROP, "Couldn't find item for ammo %i", ammo);
01951         return NULL;
01952 }

gitem_t* BG_FindItemForHoldable holdable_t  pw  ) 
 

Definition at line 1901 of file bg_misc.c.

References bg_itemlist, bg_numItems, Com_Error(), ERR_DROP, gitem_s::giTag, gitem_t, gitem_s::giType, holdable_t, IT_HOLDABLE, and NULL.

Referenced by G_SiegeRegisterWeaponsAndHoldables(), PlaceShield(), and UI_SiegeSetCvarsForClass().

01901                                                  {
01902         int             i;
01903 
01904         for ( i = 0 ; i < bg_numItems ; i++ ) {
01905                 if ( bg_itemlist[i].giType == IT_HOLDABLE && bg_itemlist[i].giTag == pw ) {
01906                         return &bg_itemlist[i];
01907                 }
01908         }
01909 
01910         Com_Error( ERR_DROP, "HoldableItem not found" );
01911 
01912         return NULL;
01913 }

gitem_t* BG_FindItemForPowerup powerup_t  pw  ) 
 

Definition at line 1881 of file bg_misc.c.

References bg_itemlist, bg_numItems, gitem_s::giTag, gitem_t, gitem_s::giType, IT_POWERUP, IT_TEAM, NULL, and powerup_t.

Referenced by CG_DrawFlagModel(), CG_DrawNewTeamInfo(), and TossClientItems().

01881                                                {
01882         int             i;
01883 
01884         for ( i = 0 ; i < bg_numItems ; i++ ) {
01885                 if ( (bg_itemlist[i].giType == IT_POWERUP || 
01886                                         bg_itemlist[i].giType == IT_TEAM) && 
01887                         bg_itemlist[i].giTag == pw ) {
01888                         return &bg_itemlist[i];
01889                 }
01890         }
01891 
01892         return NULL;
01893 }

gitem_t* BG_FindItemForWeapon weapon_t  weapon  ) 
 

Definition at line 1922 of file bg_misc.c.

References bg_itemlist, gitem_s::classname, Com_Error(), ERR_DROP, gitem_s::giTag, gitem_t, gitem_s::giType, IT_WEAPON, NULL, and weapon_t.

Referenced by CG_Init(), ClearRegisteredItems(), EWebPrecache(), finish_spawning_turretG2(), G_SiegeRegisterWeaponsAndHoldables(), InitShooter(), NPC_ATST_Precache(), NPC_Mark1_Precache(), NPC_Mark2_Precache(), NPC_Precache(), NPC_PrecacheWeapons(), NPC_Probe_Precache(), SP_emplaced_gun(), SP_misc_weapon_shooter(), TossClientItems(), TossClientWeapon(), turret_base_spawn_top(), and UI_SiegeSetCvarsForClass().

01922                                                  {
01923         gitem_t *it;
01924         
01925         for ( it = bg_itemlist + 1 ; it->classname ; it++) {
01926                 if ( it->giType == IT_WEAPON && it->giTag == weapon ) {
01927                         return it;
01928                 }
01929         }
01930 
01931         Com_Error( ERR_DROP, "Couldn't find item for weapon %i", weapon);
01932         return NULL;
01933 }

int BG_GetItemIndexByTag int  tag,
int  type
 

Definition at line 2092 of file bg_misc.c.

References bg_itemlist, bg_numItems, gitem_s::giTag, and gitem_s::giType.

Referenced by BG_CycleInven(), BotUseInventoryItem(), CG_DrawInvenSelect(), CG_NextInventory_f(), CG_PrevInventory_f(), PmoveSingle(), TossClientWeapon(), and vmMain().

02093 { //Get the itemlist index from the tag and type
02094         int i = 0;
02095 
02096         while (i < bg_numItems)
02097         {
02098                 if (bg_itemlist[i].giTag == tag &&
02099                         bg_itemlist[i].giType == type)
02100                 {
02101                         return i;
02102                 }
02103 
02104                 i++;
02105         }
02106 
02107         return 0;
02108 }

qboolean BG_HasYsalamiri int  gametype,
playerState_t ps
 

Definition at line 1794 of file bg_misc.c.

References GT_CTY, playerState_t, playerState_s::powerups, PW_BLUEFLAG, PW_REDFLAG, PW_YSALAMIRI, qboolean, qfalse, and qtrue.

Referenced by BG_CanUseFPNow(), ForcePowerUsableOn(), PM_ForceJumpingUp(), PM_WeaponLightsaber(), saberFirstThrown(), WP_ForcePowersUpdate(), and WP_ForcePowerUsable().

01795 {
01796         if (gametype == GT_CTY &&
01797                 (ps->powerups[PW_REDFLAG] || ps->powerups[PW_BLUEFLAG]))
01798         {
01799                 return qtrue;
01800         }
01801 
01802         if (ps->powerups[PW_YSALAMIRI])
01803         {
01804                 return qtrue;
01805         }
01806 
01807         return qfalse;
01808 }

qboolean BG_IsItemSelectable playerState_t ps,
int  item
 

Definition at line 2111 of file bg_misc.c.

References HI_AMMODISP, HI_HEALTHDISP, HI_JETPACK, playerState_t, qboolean, qfalse, and qtrue.

Referenced by BG_CycleInven(), CG_DrawInvenSelect(), G_ItemUsable(), and PM_ItemUsable().

02112 {
02113         if (item == HI_HEALTHDISP || item == HI_AMMODISP ||
02114                 item == HI_JETPACK)
02115         {
02116                 return qfalse;
02117         }
02118         return qtrue;
02119 }

qboolean BG_IsValidCharacterModel const char *  modelName,
const char *  skinName
 

Definition at line 2744 of file bg_misc.c.

References Q_stricmp(), qboolean, qfalse, and qtrue.

Referenced by BG_ValidateSkinForTeam(), and SetupGameGhoul2Model().

02745 {
02746         if (!Q_stricmp(skinName, "menu"))
02747         {
02748                 return qfalse;
02749         }
02750         else if (!Q_stricmp(modelName, "kyle"))
02751         {
02752                 if (!Q_stricmp(skinName, "fpls"))
02753                 {
02754                         return qfalse;
02755                 }
02756                 else if (!Q_stricmp(skinName, "fpls2"))
02757                 {
02758                         return qfalse;
02759                 }
02760                 else if (!Q_stricmp(skinName, "fpls3"))
02761                 {
02762                         return qfalse;
02763                 }
02764         }
02765         return qtrue;
02766 }