codemp/cgame/cg_weapons.c File Reference

#include "cg_local.h"
#include "fx_local.h"

Go to the source code of this file.

Defines

#define WEAPON_FORCE_BUSY_HOLSTER
#define ICON_WEAPONS   0
#define ICON_FORCE   1
#define ICON_INVENTORY   2

Functions

void CG_SetGhoul2InfoRef (refEntity_t *ent, refEntity_t *s1)
void CG_RegisterItemVisuals (int itemNum)
void CG_AddPlayerWeapon (refEntity_t *parent, playerState_t *ps, centity_t *cent, int team, vec3_t newAngles, qboolean thirdPerson)
void CG_AddViewWeapon (playerState_t *ps)
void CG_DrawIconBackground (void)
qboolean CG_WeaponCheck (int weap)
void CG_DrawWeaponSelect (void)
void CG_NextWeapon_f (void)
void CG_PrevWeapon_f (void)
void CG_Weapon_f (void)
void CG_WeaponClean_f (void)
void CG_OutOfAmmoChange (int oldWeapon)
void CG_GetClientWeaponMuzzleBoltPoint (int clIndex, vec3_t to)
void CG_FireWeapon (centity_t *cent, qboolean altFire)
qboolean CG_VehicleWeaponImpact (centity_t *cent)
void CG_MissileHitWall (int weapon, int clientNum, vec3_t origin, vec3_t dir, impactSound_t soundType, qboolean altFire, int charge)
void CG_MissileHitPlayer (int weapon, vec3_t origin, vec3_t dir, int entityNum, qboolean altFire)
qboolean CG_CalcMuzzlePoint (int entityNum, vec3_t muzzle)
void CG_InitG2Weapons (void)
void CG_ShutDownG2Weapons (void)
void * CG_G2WeaponInstance (centity_t *cent, int weapon)
void CG_CopyG2WeaponInstance (centity_t *cent, int weaponNum, void *toGhoul2)
void CG_CheckPlayerG2Weapons (playerState_t *ps, centity_t *cent)

Variables

vec4_t bluehudtint
vec4_t redhudtint
float * hudTintColor


Define Documentation

#define ICON_FORCE   1
 

Definition at line 891 of file cg_weapons.c.

#define ICON_INVENTORY   2
 

Definition at line 892 of file cg_weapons.c.

#define ICON_WEAPONS   0
 

Definition at line 890 of file cg_weapons.c.

#define WEAPON_FORCE_BUSY_HOLSTER
 

Definition at line 126 of file cg_weapons.c.


Function Documentation

void CG_AddPlayerWeapon refEntity_t parent,
playerState_t ps,
centity_t cent,
int  team,
vec3_t  newAngles,
qboolean  thirdPerson
 

Definition at line 404 of file cg_weapons.c.

References addspriteArgStruct_s::accel, addspriteArgStruct_t, weaponInfo_s::altMuzzleEffect, AnglesToAxis(), refEntity_t::axis, weaponInfo_s::barrelModel, addspriteArgStruct_s::bounce, cgMedia_t::bryarFrontFlash, centity_t, cg, cg_entities, CG_IsMindTricked(), CG_PositionEntityOnTag(), CG_PositionRotatedEntityOnTag(), CG_RegisterWeapon(), cg_weapons, CGCam_Shake(), cgs, entityState_s::clientNum, playerState_s::clientNum, entityState_s::constantLight, centity_s::currentState, addspriteArgStruct_s::dscale, addspriteArgStruct_s::eAlpha, EF_ALT_FIRING, EF_FIRING, entityState_s::eFlags, weaponInfo_s::firingSound, addspriteArgStruct_s::flags, weaponInfo_s::flashDlightColor, cgs_t::gameModels, centity_s::ghoul2, cgMedia_t::greenFrontFlash, weaponInfo_s::handsModel, refEntity_t::hModel, cg_t::lastFPFlashPoint, centity_s::lerpOrigin, addspriteArgStruct_s::life, refEntity_t::lightingOrigin, playerEntity_t::lightningFiring, cgMedia_t::lightningFlash, cgs_t::media, memset(), entityState_s::modelindex2, centity_s::modelScale, MUZZLE_FLASH_TIME, weaponInfo_s::muzzleEffect, centity_s::muzzleFlashTime, entityState_s::number, addspriteArgStruct_s::origin, ORIGIN, refEntity_t::origin, centity_s::pe, PITCH, playerState_t, PM_SPECTATOR, playerState_s::pm_type, POSITIVE_X, entityState_s::powerups, cg_t::predictedPlayerState, snapshot_t::ps, qfalse, qtrue, rand(), random, weaponInfo_s::readySound, refEntity_t::renderfx, cg_t::renderingThirdPerson, ROLL, addspriteArgStruct_s::rotation, addspriteArgStruct_s::sAlpha, addspriteArgStruct_s::scale, addspriteArgStruct_s::shader, refEntity_t::shadowPlane, cg_t::snap, cg_t::time, trap_FX_AddSprite(), trap_FX_PlayEffectID(), trap_FX_PlayEntityEffectID(), trap_G2API_GetBoltMatrix(), trap_G2API_HasGhoul2ModelOnIndex(), trap_R_AddLightToScene(), trap_R_RegisterModel(), trap_S_AddLoopingSound(), entityState_s::trickedentindex, entityState_s::trickedentindex2, entityState_s::trickedentindex3, entityState_s::trickedentindex4, vec3_origin, vec3_t, VectorClear, VectorCopy, addspriteArgStruct_s::vel, weaponInfo_s::viewModel, entityState_s::weapon, WEAPON_CHARGING, WEAPON_CHARGING_ALT, weapon_t, weaponInfo_t, weaponInfo_s::weaponModel, WP_BOWCASTER, WP_BRYAR_OLD, WP_BRYAR_PISTOL, WP_DEMP2, WP_EMPLACED_GUN, WP_STUN_BATON, and YAW.

Referenced by CG_AddViewWeapon(), and CG_Player().

00404                                                                                                                                      {
00405         refEntity_t     gun;
00406         refEntity_t     barrel;
00407         vec3_t          angles;
00408         weapon_t        weaponNum;
00409         weaponInfo_t    *weapon;
00410         centity_t       *nonPredictedCent;
00411         refEntity_t     flash;
00412 
00413         weaponNum = cent->currentState.weapon;
00414 
00415         if (cent->currentState.weapon == WP_EMPLACED_GUN)
00416         {
00417                 return;
00418         }
00419 
00420         if (cg.predictedPlayerState.pm_type == PM_SPECTATOR &&
00421                 cent->currentState.number == cg.predictedPlayerState.clientNum)
00422         { //spectator mode, don't draw it...
00423                 return;
00424         }
00425 
00426         CG_RegisterWeapon( weaponNum );
00427         weapon = &cg_weapons[weaponNum];
00428 /*
00429 Ghoul2 Insert Start
00430 */
00431 
00432         memset( &gun, 0, sizeof( gun ) );
00433 
00434         // only do this if we are in first person, since world weapons are now handled on the server by Ghoul2
00435         if (!thirdPerson)
00436         {
00437 
00438                 // add the weapon
00439                 VectorCopy( parent->lightingOrigin, gun.lightingOrigin );
00440                 gun.shadowPlane = parent->shadowPlane;
00441                 gun.renderfx = parent->renderfx;
00442 
00443                 if (ps)
00444                 {       // this player, in first person view
00445                         gun.hModel = weapon->viewModel;
00446                 }
00447                 else
00448                 {
00449                         gun.hModel = weapon->weaponModel;
00450                 }
00451                 if (!gun.hModel) {
00452                         return;
00453                 }
00454 
00455                 if ( !ps ) {
00456                         // add weapon ready sound
00457                         cent->pe.lightningFiring = qfalse;
00458                         if ( ( cent->currentState.eFlags & EF_FIRING ) && weapon->firingSound ) {
00459                                 // lightning gun and guantlet make a different sound when fire is held down
00460                                 trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, weapon->firingSound );
00461                                 cent->pe.lightningFiring = qtrue;
00462                         } else if ( weapon->readySound ) {
00463                                 trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, weapon->readySound );
00464                         }
00465                 }
00466         
00467                 CG_PositionEntityOnTag( &gun, parent, parent->hModel, "tag_weapon");
00468 
00469                 if (!CG_IsMindTricked(cent->currentState.trickedentindex,
00470                         cent->currentState.trickedentindex2,
00471                         cent->currentState.trickedentindex3,
00472                         cent->currentState.trickedentindex4,
00473                         cg.snap->ps.clientNum))
00474                 {
00475                         CG_AddWeaponWithPowerups( &gun, cent->currentState.powerups ); //don't draw the weapon if the player is invisible
00476                         /*
00477                         if ( weaponNum == WP_STUN_BATON )
00478                         {
00479                                 gun.shaderRGBA[0] = gun.shaderRGBA[1] = gun.shaderRGBA[2] = 25;
00480         
00481                                 gun.customShader = trap_R_RegisterShader( "gfx/effects/stunPass" );
00482                                 gun.renderfx = RF_RGB_TINT | RF_FIRST_PERSON | RF_DEPTHHACK;
00483                                 trap_R_AddRefEntityToScene( &gun );
00484                         }
00485                         */
00486                 }
00487 
00488                 if (weaponNum == WP_STUN_BATON)
00489                 {
00490                         int i = 0;
00491 
00492                         while (i < 3)
00493                         {
00494                                 memset( &barrel, 0, sizeof( barrel ) );
00495                                 VectorCopy( parent->lightingOrigin, barrel.lightingOrigin );
00496                                 barrel.shadowPlane = parent->shadowPlane;
00497                                 barrel.renderfx = parent->renderfx;
00498 
00499                                 if (i == 0)
00500                                 {
00501                                         barrel.hModel = trap_R_RegisterModel("models/weapons2/stun_baton/baton_barrel.md3");
00502                                 }
00503                                 else if (i == 1)
00504                                 {
00505                                         barrel.hModel = trap_R_RegisterModel("models/weapons2/stun_baton/baton_barrel2.md3");
00506                                 }
00507                                 else
00508                                 {
00509                                         barrel.hModel = trap_R_RegisterModel("models/weapons2/stun_baton/baton_barrel3.md3");
00510                                 }
00511                                 angles[YAW] = 0;
00512                                 angles[PITCH] = 0;
00513                                 angles[ROLL] = 0;
00514 
00515                                 AnglesToAxis( angles, barrel.axis );
00516 
00517                                 if (i == 0)
00518                                 {
00519                                         CG_PositionRotatedEntityOnTag( &barrel, parent/*&gun*/, /*weapon->weaponModel*/weapon->handsModel, "tag_barrel" );
00520                                 }
00521                                 else if (i == 1)
00522                                 {
00523                                         CG_PositionRotatedEntityOnTag( &barrel, parent/*&gun*/, /*weapon->weaponModel*/weapon->handsModel, "tag_barrel2" );
00524                                 }
00525                                 else
00526                                 {
00527                                         CG_PositionRotatedEntityOnTag( &barrel, parent/*&gun*/, /*weapon->weaponModel*/weapon->handsModel, "tag_barrel3" );
00528                                 }
00529                                 CG_AddWeaponWithPowerups( &barrel, cent->currentState.powerups );
00530 
00531                                 i++;
00532                         }
00533                 }
00534                 else
00535                 {
00536                         // add the spinning barrel
00537                         if ( weapon->barrelModel ) {
00538                                 memset( &barrel, 0, sizeof( barrel ) );
00539                                 VectorCopy( parent->lightingOrigin, barrel.lightingOrigin );
00540                                 barrel.shadowPlane = parent->shadowPlane;
00541                                 barrel.renderfx = parent->renderfx;
00542 
00543                                 barrel.hModel = weapon->barrelModel;
00544                                 angles[YAW] = 0;
00545                                 angles[PITCH] = 0;
00546                                 angles[ROLL] = 0;
00547 
00548                                 AnglesToAxis( angles, barrel.axis );
00549 
00550                                 CG_PositionRotatedEntityOnTag( &barrel, parent/*&gun*/, /*weapon->weaponModel*/weapon->handsModel, "tag_barrel" );
00551 
00552                                 CG_AddWeaponWithPowerups( &barrel, cent->currentState.powerups );
00553                         }
00554                 }
00555         }
00556 /*
00557 Ghoul2 Insert End
00558 */
00559 
00560         memset (&flash, 0, sizeof(flash));
00561         CG_PositionEntityOnTag( &flash, &gun, gun.hModel, "tag_flash");
00562 
00563         VectorCopy(flash.origin, cg.lastFPFlashPoint);
00564 
00565         // Do special charge bits
00566         //-----------------------
00567         if ( (ps || cg.renderingThirdPerson || cg.predictedPlayerState.clientNum != cent->currentState.number) &&
00568                 ( ( cent->currentState.modelindex2 == WEAPON_CHARGING_ALT && cent->currentState.weapon == WP_BRYAR_PISTOL ) ||
00569                   ( cent->currentState.modelindex2 == WEAPON_CHARGING_ALT && cent->currentState.weapon == WP_BRYAR_OLD ) ||
00570                   ( cent->currentState.weapon == WP_BOWCASTER && cent->currentState.modelindex2 == WEAPON_CHARGING ) ||
00571                   ( cent->currentState.weapon == WP_DEMP2 && cent->currentState.modelindex2 == WEAPON_CHARGING_ALT) ) )
00572         {
00573                 int             shader = 0;
00574                 float   val = 0.0f;
00575                 float   scale = 1.0f;
00576                 addspriteArgStruct_t fxSArgs;
00577                 vec3_t flashorigin, flashdir;
00578 
00579                 if (!thirdPerson)
00580                 {
00581                         VectorCopy(flash.origin, flashorigin);
00582                         VectorCopy(flash.axis[0], flashdir);
00583                 }
00584                 else
00585                 {
00586                         mdxaBone_t              boltMatrix;
00587 
00588                         if (!trap_G2API_HasGhoul2ModelOnIndex(&(cent->ghoul2), 1))
00589                         { //it's quite possible that we may have have no weapon model and be in a valid state, so return here if this is the case
00590                                 return;
00591                         }
00592 
00593                         // go away and get me the bolt position for this frame please
00594                         if (!(trap_G2API_GetBoltMatrix(cent->ghoul2, 1, 0, &boltMatrix, newAngles, cent->lerpOrigin, cg.time, cgs.gameModels, cent->modelScale)))
00595                         {       // Couldn't find bolt point.
00596                                 return;
00597                         }
00598                         
00599                         BG_GiveMeVectorFromMatrix(&boltMatrix, ORIGIN, flashorigin);
00600                         BG_GiveMeVectorFromMatrix(&boltMatrix, POSITIVE_X, flashdir);
00601                 }
00602 
00603                 if ( cent->currentState.weapon == WP_BRYAR_PISTOL ||
00604                         cent->currentState.weapon == WP_BRYAR_OLD)
00605                 {
00606                         // Hardcoded max charge time of 1 second
00607                         val = ( cg.time - cent->currentState.constantLight ) * 0.001f;
00608                         shader = cgs.media.bryarFrontFlash;
00609                 }
00610                 else if ( cent->currentState.weapon == WP_BOWCASTER )
00611                 {
00612                         // Hardcoded max charge time of 1 second
00613                         val = ( cg.time - cent->currentState.constantLight ) * 0.001f;
00614                         shader = cgs.media.greenFrontFlash;
00615                 }
00616                 else if ( cent->currentState.weapon == WP_DEMP2 )
00617                 {
00618                         val = ( cg.time - cent->currentState.constantLight ) * 0.001f;
00619                         shader = cgs.media.lightningFlash;
00620                         scale = 1.75f;
00621                 }
00622 
00623                 if ( val < 0.0f )
00624                 {
00625                         val = 0.0f;
00626                 }
00627                 else if ( val > 1.0f )
00628                 {
00629                         val = 1.0f;
00630                         if (ps && cent->currentState.number == ps->clientNum)
00631                         {
00632                                 CGCam_Shake( /*0.1f*/0.2f, 100 );
00633                         }
00634                 }
00635                 else
00636                 {
00637                         if (ps && cent->currentState.number == ps->clientNum)
00638                         {
00639                                 CGCam_Shake( val * val * /*0.3f*/0.6f, 100 );
00640                         }
00641                 }
00642 
00643                 val += random() * 0.5f;
00644 
00645                 VectorCopy(flashorigin, fxSArgs.origin);
00646                 VectorClear(fxSArgs.vel);
00647                 VectorClear(fxSArgs.accel);
00648                 fxSArgs.scale = 3.0f*val*scale;
00649                 fxSArgs.dscale = 0.0f;
00650                 fxSArgs.sAlpha = 0.7f;
00651                 fxSArgs.eAlpha = 0.7f;
00652                 fxSArgs.rotation = random()*360;
00653                 fxSArgs.bounce = 0.0f;
00654                 fxSArgs.life = 1.0f;
00655                 fxSArgs.shader = shader;
00656                 fxSArgs.flags = 0x08000000;
00657 
00658                 //FX_AddSprite( flash.origin, NULL, NULL, 3.0f * val, 0.0f, 0.7f, 0.7f, WHITE, WHITE, random() * 360, 0.0f, 1.0f, shader, FX_USE_ALPHA );
00659                 trap_FX_AddSprite(&fxSArgs);
00660         }
00661 
00662         // make sure we aren't looking at cg.predictedPlayerEntity for LG
00663         nonPredictedCent = &cg_entities[cent->currentState.clientNum];
00664 
00665         // if the index of the nonPredictedCent is not the same as the clientNum
00666         // then this is a fake player (like on teh single player podiums), so
00667         // go ahead and use the cent
00668         if( ( nonPredictedCent - cg_entities ) != cent->currentState.clientNum ) {
00669                 nonPredictedCent = cent;
00670         }
00671 
00672         // add the flash
00673         if ( ( weaponNum == WP_DEMP2)
00674                 && ( nonPredictedCent->currentState.eFlags & EF_FIRING ) ) 
00675         {
00676                 // continuous flash
00677         } else {
00678                 // impulse flash
00679                 if ( cg.time - cent->muzzleFlashTime > MUZZLE_FLASH_TIME) {
00680                         return;
00681                 }
00682         }
00683 
00684         if ( ps || cg.renderingThirdPerson ||
00685                         cent->currentState.number != cg.predictedPlayerState.clientNum ) 
00686         {       // Make sure we don't do the thirdperson model effects for the local player if we're in first person
00687                 vec3_t flashorigin, flashdir;
00688                 refEntity_t     flash;
00689 
00690                 memset (&flash, 0, sizeof(flash));
00691 
00692                 if (!thirdPerson)
00693                 {
00694                         CG_PositionEntityOnTag( &flash, &gun, gun.hModel, "tag_flash");
00695                         VectorCopy(flash.origin, flashorigin);
00696                         VectorCopy(flash.axis[0], flashdir);
00697                 }
00698                 else
00699                 {
00700                         mdxaBone_t              boltMatrix;
00701 
00702                         if (!trap_G2API_HasGhoul2ModelOnIndex(&(cent->ghoul2), 1))
00703                         { //it's quite possible that we may have have no weapon model and be in a valid state, so return here if this is the case
00704                                 return;
00705                         }
00706 
00707                         // go away and get me the bolt position for this frame please
00708                         if (!(trap_G2API_GetBoltMatrix(cent->ghoul2, 1, 0, &boltMatrix, newAngles, cent->lerpOrigin, cg.time, cgs.gameModels, cent->modelScale)))
00709                         {       // Couldn't find bolt point.
00710                                 return;
00711                         }
00712                         
00713                         BG_GiveMeVectorFromMatrix(&boltMatrix, ORIGIN, flashorigin);
00714                         BG_GiveMeVectorFromMatrix(&boltMatrix, POSITIVE_X, flashdir);
00715                 }
00716 
00717                 if ( cg.time - cent->muzzleFlashTime <= MUZZLE_FLASH_TIME + 10 )
00718                 {       // Handle muzzle flashes
00719                         if ( cent->currentState.eFlags & EF_ALT_FIRING )
00720                         {       // Check the alt firing first.
00721                                 if (weapon->altMuzzleEffect)
00722                                 {
00723                                         if (!thirdPerson)
00724                                         {
00725                                                 trap_FX_PlayEntityEffectID(weapon->altMuzzleEffect, flashorigin, flash.axis, -1, -1, -1, -1  );
00726                                         }
00727                                         else
00728                                         {
00729                                                 trap_FX_PlayEffectID(weapon->altMuzzleEffect, flashorigin, flashdir, -1, -1);
00730                                         }
00731                                 }
00732                         }
00733                         else
00734                         {       // Regular firing
00735                                 if (weapon->muzzleEffect)
00736                                 {
00737                                         if (!thirdPerson)
00738                                         {
00739                                                 trap_FX_PlayEntityEffectID(weapon->muzzleEffect, flashorigin, flash.axis, -1, -1, -1, -1  );
00740                                         }
00741                                         else
00742                                         {
00743                                                 trap_FX_PlayEffectID(weapon->muzzleEffect, flashorigin, flashdir, -1, -1);
00744                                         }
00745                                 }
00746                         }
00747                 }
00748 
00749                 // add lightning bolt
00750                 CG_LightningBolt( nonPredictedCent, flashorigin );
00751 
00752                 if ( weapon->flashDlightColor[0] || weapon->flashDlightColor[1] || weapon->flashDlightColor[2] ) {
00753                         trap_R_AddLightToScene( flashorigin, 300 + (rand()&31), weapon->flashDlightColor[0],
00754                                 weapon->flashDlightColor[1], weapon->flashDlightColor[2] );
00755                 }
00756         }
00757 }

void CG_AddViewWeapon playerState_t ps  ) 
 

Definition at line 766 of file cg_weapons.c.

References AnglesToAxis(), refEntity_t::axis, lerpFrame_t::backlerp, refEntity_t::backlerp, centity_t, cg, CG_AddPlayerWeapon(), cg_drawGun, cg_entities, cg_fov, cg_gun_frame, cg_gun_x, cg_gun_y, cg_gun_z, CG_RegisterWeapon(), cg_weapons, cgs, cgs_t::clientinfo, entityState_s::clientNum, playerState_s::clientNum, centity_s::currentState, EF_FIRING, playerState_s::eFlags, ET_NPC, entityState_s::eType, lerpFrame_t::frame, refEntity_t::frame, weaponInfo_s::handsModel, refEntity_t::hModel, vmCvar_t::integer, memset(), centity_s::npcClient, lerpFrame_t::oldFrame, refEntity_t::oldframe, refEntity_t::origin, centity_s::pe, PERS_TEAM, playerState_s::persistant, playerState_t, PM_INTERMISSION, playerState_s::pm_type, cg_t::predictedPlayerState, qfalse, cg_t::refdef, refEntity_t::renderfx, cg_t::renderingThirdPerson, RF_DEPTHHACK, RF_FIRST_PERSON, TEAM_SPECTATOR, cg_t::testGun, playerEntity_t::torso, entityState_s::torsoAnim, vmCvar_t::value, vec3_t, VectorCopy, VectorMA, refdef_t::viewaxis, refdef_t::vieworg, playerState_s::weapon, weaponInfo_t, and playerState_s::zoomMode.

Referenced by CG_DrawActiveFrame().

00766                                            {
00767         refEntity_t     hand;
00768         centity_t       *cent;
00769         clientInfo_t    *ci;
00770         float           fovOffset;
00771         vec3_t          angles;
00772         weaponInfo_t    *weapon;
00773         float   cgFov = cg_fov.value;
00774 
00775         if (cgFov < 1)
00776         {
00777                 cgFov = 1;
00778         }
00779         if (cgFov > 97)
00780         {
00781                 cgFov = 97;
00782         }
00783 
00784         if ( ps->persistant[PERS_TEAM] == TEAM_SPECTATOR ) {
00785                 return;
00786         }
00787 
00788         if ( ps->pm_type == PM_INTERMISSION ) {
00789                 return;
00790         }
00791 
00792         // no gun if in third person view or a camera is active
00793         //if ( cg.renderingThirdPerson || cg.cameraMode) {
00794         if ( cg.renderingThirdPerson ) {
00795                 return;
00796         }
00797 
00798         // allow the gun to be completely removed
00799         if ( !cg_drawGun.integer || cg.predictedPlayerState.zoomMode) {
00800                 vec3_t          origin;
00801 
00802                 if ( cg.predictedPlayerState.eFlags & EF_FIRING ) {
00803                         // special hack for lightning gun...
00804                         VectorCopy( cg.refdef.vieworg, origin );
00805                         VectorMA( origin, -8, cg.refdef.viewaxis[2], origin );
00806                         CG_LightningBolt( &cg_entities[ps->clientNum], origin );
00807                 }
00808                 return;
00809         }
00810 
00811         // don't draw if testing a gun model
00812         if ( cg.testGun ) {
00813                 return;
00814         }
00815 
00816         // drop gun lower at higher fov
00817         if ( cgFov > 90 ) {
00818                 fovOffset = -0.2 * ( cgFov - 90 );
00819         } else {
00820                 fovOffset = 0;
00821         }
00822 
00823         cent = &cg_entities[cg.predictedPlayerState.clientNum];
00824         CG_RegisterWeapon( ps->weapon );
00825         weapon = &cg_weapons[ ps->weapon ];
00826 
00827         memset (&hand, 0, sizeof(hand));
00828 
00829         // set up gun position
00830         CG_CalculateWeaponPosition( hand.origin, angles );
00831 
00832         VectorMA( hand.origin, cg_gun_x.value, cg.refdef.viewaxis[0], hand.origin );
00833         VectorMA( hand.origin, cg_gun_y.value, cg.refdef.viewaxis[1], hand.origin );
00834         VectorMA( hand.origin, (cg_gun_z.value+fovOffset), cg.refdef.viewaxis[2], hand.origin );
00835 
00836         AnglesToAxis( angles, hand.axis );
00837 
00838         // map torso animations to weapon animations
00839         if ( cg_gun_frame.integer ) {
00840                 // development tool
00841                 hand.frame = hand.oldframe = cg_gun_frame.integer;
00842                 hand.backlerp = 0;
00843         } else {
00844                 // get clientinfo for animation map
00845                 if (cent->currentState.eType == ET_NPC)
00846                 {
00847                         if (!cent->npcClient)
00848                         {
00849                                 return;
00850                         }
00851 
00852                         ci = cent->npcClient;
00853                 }
00854                 else
00855                 {
00856                         ci = &cgs.clientinfo[ cent->currentState.clientNum ];
00857                 }
00858                 hand.frame = CG_MapTorsoToWeaponFrame( ci, cent->pe.torso.frame, cent->currentState.torsoAnim );
00859                 hand.oldframe = CG_MapTorsoToWeaponFrame( ci, cent->pe.torso.oldFrame, cent->currentState.torsoAnim );
00860                 hand.backlerp = cent->pe.torso.backlerp;
00861 
00862                 // Handle the fringe situation where oldframe is invalid
00863                 if ( hand.frame == -1 )
00864                 {
00865                         hand.frame = 0;
00866                         hand.oldframe = 0;
00867                         hand.backlerp = 0;
00868                 }
00869                 else if ( hand.oldframe == -1 )
00870                 {
00871                         hand.oldframe = hand.frame;
00872                         hand.backlerp = 0;
00873                 }
00874         }
00875 
00876         hand.hModel = weapon->handsModel;
00877         hand.renderfx = RF_DEPTHHACK | RF_FIRST_PERSON;// | RF_MINLIGHT;
00878 
00879         // add everything onto the hand
00880         CG_AddPlayerWeapon( &hand, ps, &cg_entities[cg.predictedPlayerState.clientNum], ps->persistant[PERS_TEAM], angles, qfalse );
00881 }

qboolean CG_CalcMuzzlePoint int  entityNum,
vec3_t  muzzle
 

Definition at line 2215 of file cg_weapons.c.

References AngleVectors(), entityState_s::apos, BOTH_CROUCH1IDLE, BOTH_CROUCH1WALK, centity_t, cg, cg_entities, playerState_s::clientNum, CROUCH_VIEWHEIGHT, centity_s::currentState, centity_s::currentValid, DEFAULT_VIEWHEIGHT, playerState_s::emplacedIndex, entityState_s::legsAnim, centity_s::lerpAngles, centity_s::lerpOrigin, NULL, PITCH, entityState_s::pos, cg_t::predictedPlayerState, snapshot_t::ps, qboolean, qfalse, qtrue, cg_t::refdef, cg_t::renderingThirdPerson, cg_t::snap, trajectory_t::trBase, vec3_t, VectorClear, VectorCopy, VectorMA, refdef_t::viewangles, playerState_s::viewheight, refdef_t::vieworg, playerState_s::weapon, WP_DISRUPTOR, WP_EMPLACED_GUN, WP_MELEE, WP_MuzzlePoint, WP_SABER, and WP_STUN_BATON.

02215                                                             {
02216         vec3_t          forward, right;
02217         vec3_t          gunpoint;
02218         centity_t       *cent;
02219         int                     anim;
02220 
02221         if ( entityNum == cg.snap->ps.clientNum )
02222         { //I'm not exactly sure why we'd be rendering someone else's crosshair, but hey.
02223                 int weapontype = cg.snap->ps.weapon;
02224                 vec3_t weaponMuzzle;
02225                 centity_t *pEnt = &cg_entities[cg.predictedPlayerState.clientNum];
02226 
02227                 VectorCopy(WP_MuzzlePoint[weapontype], weaponMuzzle);
02228 
02229                 if (weapontype == WP_DISRUPTOR || weapontype == WP_STUN_BATON || weapontype == WP_MELEE || weapontype == WP_SABER)
02230                 {
02231                         VectorClear(weaponMuzzle);
02232                 }
02233 
02234                 if (cg.renderingThirdPerson)
02235                 {
02236                         VectorCopy( pEnt->lerpOrigin, gunpoint );
02237                         AngleVectors( pEnt->lerpAngles, forward, right, NULL );
02238                 }
02239                 else
02240                 {
02241                         VectorCopy( cg.refdef.vieworg, gunpoint );
02242                         AngleVectors( cg.refdef.viewangles, forward, right, NULL );
02243                 }
02244 
02245                 if (weapontype == WP_EMPLACED_GUN && cg.snap->ps.emplacedIndex)
02246                 {
02247                         centity_t *gunEnt = &cg_entities[cg.snap->ps.emplacedIndex];
02248 
02249                         if (gunEnt)
02250                         {
02251                                 vec3_t pitchConstraint;
02252 
02253                                 VectorCopy(gunEnt->lerpOrigin, gunpoint);
02254                                 gunpoint[2] += 46;
02255 
02256                                 if (cg.renderingThirdPerson)
02257                                 {
02258                                         VectorCopy(pEnt->lerpAngles, pitchConstraint);
02259                                 }
02260                                 else
02261                                 {
02262                                         VectorCopy(cg.refdef.viewangles, pitchConstraint);
02263                                 }
02264 
02265                                 if (pitchConstraint[PITCH] > 40)
02266                                 {
02267                                         pitchConstraint[PITCH] = 40;
02268                                 }
02269                                 AngleVectors( pitchConstraint, forward, right, NULL );
02270                         }
02271                 }
02272 
02273                 VectorCopy(gunpoint, muzzle);
02274 
02275                 VectorMA(muzzle, weaponMuzzle[0], forward, muzzle);
02276                 VectorMA(muzzle, weaponMuzzle[1], right, muzzle);
02277 
02278                 if (weapontype == WP_EMPLACED_GUN && cg.snap->ps.emplacedIndex)
02279                 {
02280                         //Do nothing
02281                 }
02282                 else if (cg.renderingThirdPerson)
02283                 {
02284                         muzzle[2] += cg.snap->ps.viewheight + weaponMuzzle[2];
02285                 }
02286                 else
02287                 {
02288                         muzzle[2] += weaponMuzzle[2];
02289                 }
02290 
02291                 return qtrue;
02292         }
02293 
02294         cent = &cg_entities[entityNum];
02295         if ( !cent->currentValid ) {
02296                 return qfalse;
02297         }
02298 
02299         VectorCopy( cent->currentState.pos.trBase, muzzle );
02300 
02301         AngleVectors( cent->currentState.apos.trBase, forward, NULL, NULL );
02302         anim = cent->currentState.legsAnim;
02303         if ( anim == BOTH_CROUCH1WALK || anim == BOTH_CROUCH1IDLE ) {
02304                 muzzle[2] += CROUCH_VIEWHEIGHT;
02305         } else {
02306                 muzzle[2] += DEFAULT_VIEWHEIGHT;
02307         }
02308 
02309         VectorMA( muzzle, 14, forward, muzzle );
02310 
02311         return qtrue;
02312 
02313 }

void CG_CheckPlayerG2Weapons playerState_t ps,
centity_t cent
 

Definition at line 2494 of file cg_weapons.c.

References BG_SI_SetDesiredLength(), centity_t, CG_CopyG2WeaponInstance(), cg_entities, CG_G2WeaponInstance(), cgs, CHAN_AUTO, cgs_t::clientinfo, playerState_s::clientNum, centity_s::currentState, EF_DEAD, entityState_s::eFlags, ET_NPC, entityState_s::eType, centity_s::ghoul2, centity_s::ghoul2weapon, centity_s::lerpOrigin, NULL, entityState_s::number, PERS_TEAM, playerState_s::persistant, playerState_t, playerState_s::pm_flags, PMF_FOLLOW, playerState_s::saberHolstered, entityState_s::saberInFlight, centity_s::saberWasInFlight, TEAM_SPECTATOR, centity_s::torsoBolt, trap_S_StartSound(), playerState_s::weapon, centity_s::weapon, and WP_SABER.

Referenced by CG_AddPacketEntities().

02495 {
02496         if (!ps)
02497         {
02498                 assert(0);
02499                 return;
02500         }
02501 
02502         if (ps->pm_flags & PMF_FOLLOW)
02503         {
02504                 return;
02505         }
02506 
02507         if (cent->currentState.eType == ET_NPC)
02508         {
02509                 assert(0);
02510                 return;
02511         }
02512 
02513         // should we change the gun model on this player?
02514         if (cent->currentState.saberInFlight)
02515         {
02516                 cent->ghoul2weapon = CG_G2WeaponInstance(cent, WP_SABER);
02517         }
02518 
02519         if (cent->currentState.eFlags & EF_DEAD)
02520         { //no updating weapons when dead
02521                 cent->ghoul2weapon = NULL;
02522                 return;
02523         }
02524 
02525         if (cent->torsoBolt)
02526         { //got our limb cut off, no updating weapons until it's restored
02527                 cent->ghoul2weapon = NULL;
02528                 return;
02529         }
02530 
02531         if (cgs.clientinfo[ps->clientNum].team == TEAM_SPECTATOR ||
02532                 ps->persistant[PERS_TEAM] == TEAM_SPECTATOR)
02533         {
02534                 cent->ghoul2weapon = cg_entities[ps->clientNum].ghoul2weapon = NULL;
02535                 cent->weapon = cg_entities[ps->clientNum].weapon = 0;
02536                 return;
02537         }
02538 
02539         if (cent->ghoul2 && cent->ghoul2weapon != CG_G2WeaponInstance(cent, ps->weapon) &&
02540                 ps->clientNum == cent->currentState.number) //don't want spectator mode forcing one client's weapon instance over another's
02541         {
02542                 CG_CopyG2WeaponInstance(cent, ps->weapon, cent->ghoul2);
02543                 cent->ghoul2weapon = CG_G2WeaponInstance(cent, ps->weapon);
02544                 if (cent->weapon == WP_SABER && cent->weapon != ps->weapon && !ps->saberHolstered)
02545                 { //switching away from the saber
02546                         //trap_S_StartSound(cent->lerpOrigin, cent->currentState.number, CHAN_AUTO, trap_S_RegisterSound( "sound/weapons/saber/saberoffquick.wav" ));
02547                         if (cgs.clientinfo[ps->clientNum].saber[0].soundOff && !ps->saberHolstered)
02548                         {
02549                                 trap_S_StartSound(cent->lerpOrigin, cent->currentState.number, CHAN_AUTO, cgs.clientinfo[ps->clientNum].saber[0].soundOff);
02550                         }
02551 
02552                         if (cgs.clientinfo[ps->clientNum].saber[1].soundOff &&
02553                                 cgs.clientinfo[ps->clientNum].saber[1].model[0] &&
02554                                 !ps->saberHolstered)
02555                         {
02556                                 trap_S_StartSound(cent->lerpOrigin, cent->currentState.number, CHAN_AUTO, cgs.clientinfo[ps->clientNum].saber[1].soundOff);
02557                         }
02558                 }
02559                 else if (ps->weapon == WP_SABER && cent->weapon != ps->weapon && !cent->saberWasInFlight)
02560                 { //switching to the saber
02561                         //trap_S_StartSound(cent->lerpOrigin, cent->currentState.number, CHAN_AUTO, trap_S_RegisterSound( "sound/weapons/saber/saberon.wav" ));
02562                         if (cgs.clientinfo[ps->clientNum].saber[0].soundOn)
02563                         {
02564                                 trap_S_StartSound(cent->lerpOrigin, cent->currentState.number, CHAN_AUTO, cgs.clientinfo[ps->clientNum].saber[0].soundOn);
02565                         }
02566 
02567                         if (cgs.clientinfo[ps->clientNum].saber[1].soundOn)
02568                         {
02569                                 trap_S_StartSound(cent->lerpOrigin, cent->currentState.number, CHAN_AUTO, cgs.clientinfo[ps->clientNum].saber[1].soundOn);
02570                         }
02571 
02572                         BG_SI_SetDesiredLength(&cgs.clientinfo[ps->clientNum].saber[0], 0, -1);
02573                         BG_SI_SetDesiredLength(&cgs.clientinfo[ps->clientNum].saber[1], 0, -1);
02574                 }
02575                 cent->weapon = ps->weapon;
02576         }
02577 }

void CG_CopyG2WeaponInstance centity_t cent,
int  weaponNum,
void *  toGhoul2
 

Definition at line 2414 of file cg_weapons.c.

References centity_t, CG_G2WeaponInstance(), cgs, cgs_t::clientinfo, centity_s::currentState, ET_NPC, entityState_s::eType, clientInfo_t::ghoul2Weapons, MAX_SABERS, MAX_WEAPONS, saberInfo_t::model, centity_s::npcClient, NULL, entityState_s::number, qboolean, clientInfo_t::saber, trap_G2API_CleanGhoul2Models(), trap_G2API_CopySpecificGhoul2Model(), trap_G2API_HasGhoul2ModelOnIndex(), trap_G2API_RemoveGhoul2Model(), WP_EMPLACED_GUN, WP_MELEE, and WP_SABER.

Referenced by CG_CheckPlayerG2Weapons(), CG_NewClientInfo(), CG_Player(), CG_ResetPlayerEntity(), and CG_SetInitialSnapshot().

02415 {
02416         //rww - the -1 is because there is no "weapon" for WP_NONE
02417         assert(weaponNum < MAX_WEAPONS);
02418         if (CG_G2WeaponInstance(cent, weaponNum/*-1*/))
02419         {
02420                 if (weaponNum == WP_SABER)
02421                 {
02422                         clientInfo_t *ci = NULL;
02423 
02424                         if (cent->currentState.eType == ET_NPC)
02425                         {
02426                                 ci = cent->npcClient;
02427                         }
02428                         else
02429                         {
02430                                 ci = &cgs.clientinfo[cent->currentState.number];
02431                         }
02432 
02433                         if (!ci)
02434                         {
02435                                 trap_G2API_CopySpecificGhoul2Model(CG_G2WeaponInstance(cent, weaponNum/*-1*/), 0, toGhoul2, 1); 
02436                         }
02437                         else
02438                         { //Try both the left hand saber and the right hand saber
02439                                 int i = 0;
02440 
02441                                 while (i < MAX_SABERS)
02442                                 {
02443                                         if (ci->saber[i].model[0] &&
02444                                                 ci->ghoul2Weapons[i])
02445                                         {
02446                                                 trap_G2API_CopySpecificGhoul2Model(ci->ghoul2Weapons[i], 0, toGhoul2, i+1); 
02447                                         }
02448                                         else if (ci->ghoul2Weapons[i])
02449                                         { //if the second saber has been removed, then be sure to remove it and free the instance.
02450                                                 qboolean g2HasSecondSaber = trap_G2API_HasGhoul2ModelOnIndex(&(toGhoul2), 2);
02451 
02452                                                 if (g2HasSecondSaber)
02453                                                 { //remove it now since we're switching away from sabers
02454                                                         trap_G2API_RemoveGhoul2Model(&(toGhoul2), 2);
02455                                                 }
02456                                                 trap_G2API_CleanGhoul2Models(&ci->ghoul2Weapons[i]);
02457                                         }
02458 
02459                                         i++;
02460                                 }
02461                         }
02462                 }
02463                 else
02464                 {
02465                         qboolean g2HasSecondSaber = trap_G2API_HasGhoul2ModelOnIndex(&(toGhoul2), 2);
02466 
02467                         if (g2HasSecondSaber)
02468                         { //remove it now since we're switching away from sabers
02469                                 trap_G2API_RemoveGhoul2Model(&(toGhoul2), 2);
02470                         }
02471 
02472                         if (weaponNum == WP_EMPLACED_GUN)
02473                         { //a bit of a hack to remove gun model when using an emplaced weap
02474                                 if (trap_G2API_HasGhoul2ModelOnIndex(&(toGhoul2), 1))
02475                                 {
02476                                         trap_G2API_RemoveGhoul2Model(&(toGhoul2), 1);
02477                                 }
02478                         }
02479                         else if (weaponNum == WP_MELEE)
02480                         { //don't want a weapon on the model for this one
02481                                 if (trap_G2API_HasGhoul2ModelOnIndex(&(toGhoul2), 1))
02482                                 {
02483                                         trap_G2API_RemoveGhoul2Model(&(toGhoul2), 1);
02484                                 }
02485                         }
02486                         else
02487                         {
02488                                 trap_G2API_CopySpecificGhoul2Model(CG_G2WeaponInstance(cent, weaponNum/*-1*/), 0, toGhoul2, 1); 
02489                         }
02490                 }
02491         }
02492 }

void CG_DrawIconBackground void   ) 
 

Definition at line 895 of file cg_weapons.c.

References cg, cg_hudFiles, cg_t::forceSelectTime, cg_t::iconHUDActive, cg_t::iconHUDPercent, cg_t::iconSelectTime, vmCvar_t::integer, cg_t::invenSelectTime, snapshot_t::ps, qfalse, qtrue, SCREEN_HEIGHT, cg_t::snap, STAT_HEALTH, playerState_s::stats, cg_t::time, WEAPON_SELECT_TIME, and cg_t::weaponSelectTime.

00896 {
00897         int                             height,xAdd,x2,y2,t;
00898 //      int                             prongLeftX,prongRightX;
00899         float                   inTime = cg.invenSelectTime+WEAPON_SELECT_TIME;
00900         float                   wpTime = cg.weaponSelectTime+WEAPON_SELECT_TIME;
00901         float                   fpTime = cg.forceSelectTime+WEAPON_SELECT_TIME;
00902 //      int                             drawType = cgs.media.weaponIconBackground;
00903 //      int                             yOffset = 0;
00904 
00905 #ifdef _XBOX
00906         //yOffset = -50;
00907 #endif
00908 
00909         // don't display if dead
00910         if ( cg.snap->ps.stats[STAT_HEALTH] <= 0 ) 
00911         {
00912                 return;
00913         }
00914 
00915         if (cg_hudFiles.integer)
00916         { //simple hud
00917                 return;
00918         }
00919 
00920         x2 = 30;
00921         y2 = SCREEN_HEIGHT-70;
00922 
00923         //prongLeftX =x2+37; 
00924         //prongRightX =x2+544; 
00925 
00926         if (inTime > wpTime)
00927         {
00928 //              drawType = cgs.media.inventoryIconBackground;
00929                 cg.iconSelectTime = cg.invenSelectTime;
00930         }
00931         else
00932         {
00933 //              drawType = cgs.media.weaponIconBackground;
00934                 cg.iconSelectTime = cg.weaponSelectTime;
00935         }
00936 
00937         if (fpTime > inTime && fpTime > wpTime)
00938         {
00939 //              drawType = cgs.media.forceIconBackground;
00940                 cg.iconSelectTime = cg.forceSelectTime;
00941         }
00942 
00943         if ((cg.iconSelectTime+WEAPON_SELECT_TIME)<cg.time)     // Time is up for the HUD to display
00944         {
00945                 if (cg.iconHUDActive)           // The time is up, but we still need to move the prongs back to their original position
00946                 {
00947                         t =  cg.time - (cg.iconSelectTime+WEAPON_SELECT_TIME);
00948                         cg.iconHUDPercent = t/ 130.0f;
00949                         cg.iconHUDPercent = 1 - cg.iconHUDPercent;
00950 
00951                         if (cg.iconHUDPercent<0)
00952                         {
00953                                 cg.iconHUDActive = qfalse;
00954                                 cg.iconHUDPercent=0;
00955                         }
00956 
00957                         xAdd = (int) 8*cg.iconHUDPercent;
00958 
00959                         height = (int) (60.0f*cg.iconHUDPercent);
00960                         //CG_DrawPic( x2+60, y2+30+yOffset, 460, -height, drawType);    // Top half
00961                         //CG_DrawPic( x2+60, y2+30-2+yOffset, 460, height, drawType);   // Bottom half
00962 
00963                 }
00964                 else
00965                 {
00966                         xAdd = 0;
00967                 }
00968 
00969                 return;
00970         }
00971         //prongLeftX =x2+37; 
00972         //prongRightX =x2+544; 
00973 
00974         if (!cg.iconHUDActive)
00975         {
00976                 t = cg.time - cg.iconSelectTime;
00977                 cg.iconHUDPercent = t/ 130.0f;
00978 
00979                 // Calc how far into opening sequence we are
00980                 if (cg.iconHUDPercent>1)
00981                 {
00982                         cg.iconHUDActive =