Weapon firing bug fix

Not sure how or why it happened, but the code was causing the bow to use wrong cross hairs, and auto weapon switch.  I believe there was a mistake on my end when cleaning up the code in the player.cpp and playercursor.cpp files.
Additionally having a second weapon to use the soul cube hud notice is not needed as the planned weapon is not happening anytime soon.
This commit is contained in:
revility 2018-09-27 15:17:52 -04:00 committed by Daniel Gibson
parent 8d95330115
commit 63152f3283
2 changed files with 315 additions and 23 deletions

View file

@ -51,7 +51,7 @@ const int ASYNC_PLAYER_INV_CLIP_BITS = -7; // -7 bits to cover the range
/*
===============================================================================
Player control.
Player control of the Doom Marine.
This object handles all player movement and world interaction.
===============================================================================
@ -156,6 +156,8 @@ EVENT( EV_Weapon_StartParticle, idPlayer::Event_StartWeaponParticle ) //proxy
EVENT( EV_Weapon_StopParticle, idPlayer::Event_StopWeaponParticle ) //proxy for weapon
EVENT( EV_Weapon_StartAutoMelee, idPlayer::Event_StartAutoMelee ) //proxy for weapon
EVENT( EV_Weapon_StopAutoMelee, idPlayer::Event_StopAutoMelee ) //proxy for weapon
//EVENT( EV_Weapon_StartMeleeBeam, idPlayer::Event_StartMeleeBeam ) //proxy for weapon
//EVENT( EV_Weapon_StopMeleeBeam, idPlayer::Event_StopMeleeBeam ) //proxy for weapon
EVENT( EV_Player_DropWeapon, idPlayer::Event_DropWeapon)
EVENT( EV_Player_HudEvent, idPlayer::Event_HudEvent)
EVENT( EV_Player_SetHudParm, idPlayer::Event_SetHudParm)
@ -930,8 +932,15 @@ bool idInventory::Give( idPlayer *owner, const idDict &spawnArgs, const char *st
continue;
}
if ( !gameLocal.world->spawnArgs.GetBool( "no_Weapons" ) || ( weaponName == "weapon_fists" ) || ( weaponName == "weapon_giltine" )) { //Rev 2018
if ( !gameLocal.world->spawnArgs.GetBool( "no_Weapons" ) || ( weaponName == "weapon_fists" ) || ( weaponName == "weapon_soulcube" ) ) {
if ( ( weapons & ( 1 << i ) ) == 0 || gameLocal.isMultiplayer ) {
/*
//commented out by ivan: picked up weapon is now selected in idPlayer::AddWeaponToSlots
if ( owner->GetUserInfo()->GetBool( "ui_autoSwitch" ) && idealWeapon ) {
assert( !gameLocal.isClient );
*idealWeapon = i;
}
*/
if ( owner->hud && updateHud && lastGiveTime + 1000 < gameLocal.time ) {
owner->hud->SetStateInt( "newWeapon", i );
@ -1011,6 +1020,31 @@ int idInventory::NumWeapForAmmoType( const idDict &spawnArgs, ammo_t ammoType )
}
}
}
/*
const char *weap;
int w;
int s;
int numfound = 0;
s = NUM_SLOTS;
while( s > 0 ) {
s--;
w = weaponSlot[s];
if( w == -1 ){ //slot is empty
continue;
}
weap = spawnArgs.GetString( va( "def_weapon%d", w ) );
tempAmmoType = AmmoIndexForWeaponClass( weap, NULL );
if( tempAmmoType == ammoType ) numfound++;
}
*/
//gameLocal.Printf("number of weapons with same ammo type: %d\n", numfound );
return numfound;
}
@ -1165,7 +1199,7 @@ idPlayer::idPlayer() {
noclip = false;
godmode = false;
telishield = 1; //added Rev 2018 for shield spell
telishield = 1; //added Revility 2018 for shield spells, player taking no damage
//ivan start
animMoveNoGravity = false;
animMoveType = ANIMMOVE_NONE;
@ -1516,7 +1550,7 @@ void idPlayer::Init( void ) {
quickWeapon = -1; //new
weaponSwitchTime = 0;
weaponEnabled = true;
weapon_soulcube = SlotForWeapon ( "weapon_soulcube" ) && ( "weapon_giltine" ); //Rev 2018
weapon_soulcube = SlotForWeapon( "weapon_soulcube" );
weapon_pda = SlotForWeapon( "weapon_pda" );
weapon_fists = SlotForWeapon( "weapon_fists" );
showWeaponViewModel = GetUserInfo()->GetBool( "ui_showGun" );
@ -1722,7 +1756,34 @@ void idPlayer::Init( void ) {
}
cvarSystem->SetCVarBool( "ui_chat", false );
/*
//ivan start from hq2
health_lost = 0;
save_walk_dir = false;
keep_walk_dir = false;
old_viewAngles_yaw = 0.0f;
fw_toggled = false;
fw_inverted = false;
viewPos = 0.0f;
lockedXpos = 0.0f;
isXlocked = true;
blendModelYaw = false;
forcedMovIncreasingX = false;
forcedMovCanBeAborted = false;
forcedMovTotalForce = false;
forcedMovAborted = false;
forcedMovDelta = vec3_zero;
forcedMovOldOrg = vec3_zero;
forcedMovTarget = NULL;
skipCameraZblend = true; //force instant update first frame
enableCameraYblend = false;
forceCameraY = false;
inhibitInputTime = 0;
inhibitAimCrouchTime = 0;
forcedCameraYpos = 0.0f;
//ivan end
*/
}
/*
@ -3068,7 +3129,7 @@ void idPlayer::UpdateHudStats( idUserInterface *_hud ) {
_hud->HandleNamedEvent( "armorPulse" );
inventory.armorPulse = false;
}
//rev 2018 show the hud when pressing the run key or zoom key.
//2018 update. show the hud when pressing the run key or zoom key... now both changed to walk and shield
if(weapon.GetEntity()->GetIsFiring() || weapon.GetEntity()->GetIsSecFiring() || force_torso_override || (usercmd.buttons & BUTTON_RUN) || (usercmd.buttons & BUTTON_ZOOM) ){ //firing or combo
_hud->HandleNamedEvent( "weaponFiringOrCombo" );
}
@ -3115,8 +3176,15 @@ void idPlayer::UpdateHudWeapon( bool flashWeapon ) {
//ivan start - upd weapon mode
if ( idealWeapon >= 0 ) {
//hud->SetStateInt( va( "mode_weapon%d", currentWeapon ), (inventory.weapon_mode[currentWeapon] ) );
hud->SetStateInt("current_weapon_mode", (inventory.weapon_mode[idealWeapon] ) );
}
/*
if( flashMode ){
hud->HandleNamedEvent( "modeChange" );
}
*/
//ivan end
if ( flashWeapon ) {
@ -3309,8 +3377,20 @@ void idPlayer::UpdateConditions( void ) {
AI_STRAFE_RIGHT = false;
}
AI_RUN = ( usercmd.buttons & BUTTON_RUN ); //Rev 2018 Run does not use stamina gauge
AI_RUN = ( usercmd.buttons & BUTTON_RUN ); // || (( usercmd.buttons & BUTTON_ZOOM ) && ( ( !pm_stamina.GetFloat() ) || ( stamina > pm_staminathreshold.GetFloat() ) )); //2018 update. Zoom key now uses stamina, run key does not because it is a walk animation now.
AI_DEAD = ( health <= 0 );
//ivan start
/*
if( weapon.GetEntity() ){
AI_RUN = !( weapon.GetEntity()->GetIsFiring() || weapon.GetEntity()->GetIsSecFiring());
}else{
AI_RUN = true;
}*/
//AI_RUN = ( weapon.GetEntity() ) ? (!weapon.GetEntity()->HasToWalk()) : true; /// commented out in 2018 Rev
//ivan end
}
@ -3715,6 +3795,7 @@ bool idPlayer::GiveItem( idItem *item ) {
// display the pickup feedback on the hud
if ( gave && ( numPickup == inventory.pickupItemNames.Num() ) ) {
// inventory.AddPickupName( item->spawnArgs.GetString( "inv_name" ), item->spawnArgs.GetString( "inv_icon" ) );
inventory.AddPickupName( item->spawnArgs.GetString( "inv_name" ), item->spawnArgs.GetString( "inv_icon" ), this ); //New _D3XP
}
@ -4425,6 +4506,13 @@ void idPlayer::NextWeapon( void ) {
weap = spawnArgs.GetString( va( "def_weapon%d", w ) );
/*
//the following should be already assured by slots
if ( !spawnArgs.GetBool( va( "weapon%d_cycle", w ) ) ) {
continue;
}
*/
if ( !weap[ 0 ] ) {
continue;
}
@ -4444,6 +4532,37 @@ void idPlayer::NextWeapon( void ) {
break;
}
}
/* was:
w = idealWeapon;
while( 1 ) {
w++;
if ( w >= MAX_WEAPONS ) {
w = 0;
}
weap = spawnArgs.GetString( va( "def_weapon%d", w ) );
if ( !spawnArgs.GetBool( va( "weapon%d_cycle", w ) ) ) {
continue;
}
if ( !weap[ 0 ] ) {
continue;
}
if ( ( inventory.weapons & ( 1 << w ) ) == 0 ) {
continue;
}
//ivan start - allow selecting empty weapons
if ( spawnArgs.GetBool( va( "weapon%d_allowempty", w ) ) ) {
break;
}
//ivan end
if ( inventory.HasAmmo( weap, true, this ) ) {//new
// if ( inventory.HasAmmo( weap ) ) {
break;
}
}
*/
//ivan end
if ( ( w != currentWeapon ) && ( w != idealWeapon ) ) {
@ -4498,6 +4617,13 @@ void idPlayer::PrevWeapon( void ) {
weap = spawnArgs.GetString( va( "def_weapon%d", w ) );
/*
//the following should be already assured by slots
if ( !spawnArgs.GetBool( va( "weapon%d_cycle", w ) ) ) {
continue;
}
*/
if ( !weap[ 0 ] ) {
continue;
}
@ -4518,6 +4644,31 @@ void idPlayer::PrevWeapon( void ) {
}
}
/* was:
w = idealWeapon;
while( 1 ) {
w--;
if ( w < 0 ) {
w = MAX_WEAPONS - 1;
}
weap = spawnArgs.GetString( va( "def_weapon%d", w ) );
if ( !spawnArgs.GetBool( va( "weapon%d_cycle", w ) ) ) {
continue;
}
if ( !weap[ 0 ] ) {
continue;
}
if ( ( inventory.weapons & ( 1 << w ) ) == 0 ) {
continue;
}
if ( inventory.HasAmmo( weap, true, this ) ) { //new
//if ( inventory.HasAmmo( weap ) ) {
break;
}
}
*/
//ivan end
if ( ( w != currentWeapon ) && ( w != idealWeapon ) ) {
@ -6861,7 +7012,7 @@ void idPlayer::AdjustSpeed( void ) {
} else if ( noclip ) {
speed = pm_noclipspeed.GetFloat();
bobFrac = 0.0f;
} else if (( usercmd.buttons & BUTTON_ZOOM ) ) { //Rev 2018. holding zoom key now is the only thing to trigger loosing stamina for the shield spell
} else if (( usercmd.buttons & BUTTON_ZOOM ) ) { //2018 revility update. holding zoom key now is the only thing to trigger loosing stamina for the shield spell
if ( !gameLocal.isMultiplayer && !physicsObj.IsCrouching() && !PowerUpActive( ADRENALINE ) ) {
stamina -= MS2SEC( gameLocal.msec );
spawnArgs.Set( "telishield", "1" ); //rev 2018 used in code to change skin and animations for shield spell
@ -6896,7 +7047,7 @@ void idPlayer::AdjustSpeed( void ) {
speed = pm_walkspeed.GetFloat();
bobFrac = 0.0f;
}
//rev 2018 moved outside of the stamina stuff running is not associated with stamina gauge anymore.
//revility 2018 moved outside of the stamina stuff because run key is now aim walk.
if ( usercmd.buttons & BUTTON_RUN ) {
speed = pm_runspeed.GetFloat();
}
@ -6908,6 +7059,40 @@ void idPlayer::AdjustSpeed( void ) {
}
physicsObj.SetSpeed( speed, pm_crouchspeed.GetFloat() );
}
/*
//Commented out in 2018 by Rev
void idPlayer::AdjustSpeed( void ) {
float speed;
//float rate;
if ( spectating ) {
speed = pm_spectatespeed.GetFloat();
bobFrac = 0.0f;
} else if ( noclip ) {
speed = pm_noclipspeed.GetFloat();
bobFrac = 0.0f;
}
//ivan start
else {
speed = pm_walkspeed.GetFloat();
bobFrac = 0.0f;
//weapon based walk speed
//if( weapon.GetEntity() ){
//speed *= weapon.GetEntity()->GetWalkSpeedMult();
//}
}
//ivan end
speed *= PowerUpModifier(SPEED);
if ( influenceActive == INFLUENCE_LEVEL3 ) {
speed *= 0.33f;
}
physicsObj.SetSpeed( speed, pm_crouchspeed.GetFloat() );
}
*/
/*
==============
@ -7477,8 +7662,8 @@ void idPlayer::Think( void ) {
}
// zooming
if ( ( usercmd.buttons ^ oldCmd.buttons ) & BUTTON_RUN ) { //Rev 2018 for walk aiming. trigger zooming when pressing run button
if ( ( usercmd.buttons & BUTTON_RUN ) && weapon.GetEntity() ) { //Rev 2018
if ( ( usercmd.buttons ^ oldCmd.buttons ) & BUTTON_RUN ) { //Updated Rev 2018 for walk aiming. We want the zoom to trigger when pressing the Run key... which is now walking
if ( ( usercmd.buttons & BUTTON_RUN ) && weapon.GetEntity() ) { //Updated Rev 2018 for walk aiming
zoomFov.Init( gameLocal.time, 200.0f, CalcFov( false ), weapon.GetEntity()->GetZoomFov() );
} else {
zoomFov.Init( gameLocal.time, 200.0f, zoomFov.GetCurrentValue( gameLocal.time ), DefaultFov() );
@ -7890,7 +8075,7 @@ void idPlayer::Killed( idEntity *inflictor, idEntity *attacker, int damage, cons
animator.ClearAllJoints();
if ( StartRagdoll() ) {
pm_modelView.SetInteger( 1 ); //rev 2018 always keep on. remove this?
pm_modelView.SetInteger( 0 );
minRespawnTime = gameLocal.time + RAGDOLL_DEATH_TIME;
maxRespawnTime = minRespawnTime + MAX_RESPAWN_TIME;
} else {
@ -8035,14 +8220,17 @@ void idPlayer::CalcDamagePoints( idEntity *inflictor, idEntity *attacker, const
}
}
//REV 2018 start.
////REVILITY 2018 start.
telishield = spawnArgs.GetInt( "telishield" );
if ( (usercmd.buttons & BUTTON_ZOOM) && stamina > 0 ) {
//if ( telishield > 0 ) { // we no longer have to check this to trigger damage stopping...
//if ( telishield > 0 ) { // we no longer have to check this key to trigger damage stopping...
damage = 0;
//damage *= damageDef->GetFloat( "selfDamageScale", "0.5" );
//the above line is useful for reducing a specific % of damage.
}
////REVILITY END
// inform the attacker that they hit someone
attacker->DamageFeedback( this, inflictor, damage );
@ -8392,10 +8580,10 @@ float idPlayer::CalcFov( bool honorZoom ) {
#ifdef _DENTONMOD_PLAYER_CPP
if ( zoomFov.IsDone( gameLocal.time ) ) {
fov = ( honorZoom && ((usercmd.buttons & BUTTON_RUN) || weaponZoom.startZoom )) && weapon.GetEntity() ? weapon.GetEntity()->GetZoomFov() : DefaultFov(); // Updated By Clone JCD //Updated Rev 2018
fov = ( honorZoom && ((usercmd.buttons & BUTTON_RUN) || weaponZoom.startZoom )) && weapon.GetEntity() ? weapon.GetEntity()->GetZoomFov() : DefaultFov(); // Updated By Clone JCD //Updated Rev 2018 for walk aiming
#else
if ( zoomFov.IsDone( gameLocal.time ) ) {
fov = ( honorZoom && (usercmd.buttons & BUTTON_RUN)) && weapon.GetEntity() ? weapon.GetEntity()->GetZoomFov() : DefaultFov(); // Updated By Clone JCD //Updated Rev 2018
fov = ( honorZoom && (usercmd.buttons & BUTTON_RUN)) && weapon.GetEntity() ? weapon.GetEntity()->GetZoomFov() : DefaultFov(); // Updated By Clone JCD //Updated Rev 2018 for walk aiming
#endif// _DENTONMOD_PLAYER_CPP
} else {
fov = zoomFov.GetCurrentValue( gameLocal.time );
@ -8614,10 +8802,10 @@ void idPlayer::OffsetThirdPersonView( float angle, float range, float height, bo
idMath::SinCos( DEG2RAD( angle ), sideScale, forwardScale );
view -= range * forwardScale * renderView->viewaxis[ 0 ];
//Rev move thirdperson camera sideways cvar
//// REVILITY START ALLOWS THE THIRDPERSON CAMERA TO BE OFFSET LEFT TO RIGHT
//view += range * sideScale * renderView->viewaxis[ 1 ];
view += range * (pm_thirdPersonSideScale.GetFloat()) * renderView->viewaxis[ 1 ];
//Rev end
////REVILITY END
if ( clip ) {
// trace a ray from the origin to the viewpoint to make sure the view isn't
@ -8700,7 +8888,7 @@ idPlayer::CalculateFirstPersonView
===============
*/
void idPlayer::CalculateFirstPersonView( void ) {
if ( ( pm_modelView.GetInteger() == 1 ) || ( ( pm_modelView.GetInteger() == 2 ) ) ) { //rev 2018 removed && ( health <= 0 ) cross hair origin fix
if ( ( pm_modelView.GetInteger() == 1 ) || ( ( pm_modelView.GetInteger() == 2 ) && ( health <= 0 ) ) ) {
// Displays the view from the point of view of the "camera" joint in the player model
idMat3 axis;
@ -8710,10 +8898,10 @@ void idPlayer::CalculateFirstPersonView( void ) {
ang = viewBobAngles + playerView.AngleOffset();
ang.yaw += viewAxis[ 180 ].ToYaw();
jointHandle_t joint = animator.GetJointHandle( "SHOTGUN_ATTACHER" ); //rev 2018. origin of crossline when pm_modelview is 1.
jointHandle_t joint = animator.GetJointHandle( "SHOTGUN_ATTACHER" ); //now set to an actual joint on the player model Revility 2018. This moves the line to draw the crosshair closer to the weapon.
animator.GetJointTransform( joint, gameLocal.time, origin, axis );
firstPersonViewOrigin = ( origin + modelOffset ) * ( viewAxis * physicsObj.GetGravityAxis() ) + physicsObj.GetOrigin() + viewBob;
firstPersonViewAxis = renderView->viewaxis; //Rev 2018 changed to the axis of the camera and not the bone.
firstPersonViewAxis = renderView->viewaxis; //changed to the axis of the camera and not the bone. Revility 2018
} else {
// offset for local bobbing and kicks
GetViewPos( firstPersonViewOrigin, firstPersonViewAxis );
@ -8785,7 +8973,6 @@ void idPlayer::CalculateRenderView( void ) {
}
} else if ( pm_thirdPerson.GetBool() ) {
OffsetThirdPersonView( pm_thirdPersonAngle.GetFloat(), pm_thirdPersonRange.GetFloat(), pm_thirdPersonHeight.GetFloat(), pm_thirdPersonClip.GetBool() );
cvarSystem->SetCVarInteger( "pm_modelView", 1 ); //Rev 2018. Cross hair origin fix. Would reset everytime a map loads without this.
} else if ( pm_thirdPersonDeath.GetBool() ) {
range = gameLocal.time < minRespawnTime ? ( gameLocal.time + RAGDOLL_DEATH_TIME - minRespawnTime ) * ( 120.0f / RAGDOLL_DEATH_TIME ) : 120.0f;
OffsetThirdPersonView( 0.0f, 20.0f + range, 0.0f, false );
@ -10116,6 +10303,25 @@ bool idPlayer::WeaponAvailable( const char* name ) {
return false;
}
/*
=================
idPlayer::GetCurrentWeapon //New
=================
idStr idPlayer::GetCurrentWeapon() {
const char *weapon;
if ( currentWeapon >= 0 ) {
weapon = spawnArgs.GetString( va( "def_weapon%d", currentWeapon ) );
return weapon;
} else {
return "";
}
}
*/
//Ivan start
/*
===============
idPlayer::IsComboActive
@ -10269,6 +10475,8 @@ idPlayer::Event_StartWeaponParticle
void idPlayer::Event_StartWeaponParticle( const char* prtName ) {
if ( weapon.GetEntity() ) {
weapon.GetEntity()->StartWeaponParticle( prtName );
//weapon.GetEntity()->ProcessEvent( &EV_Weapon_StartWeaponParticle, "ruinblade_prt1" );
}
}
@ -10305,6 +10513,34 @@ void idPlayer::Event_StopAutoMelee( void ) {
}
}
/*
=====================
idPlayer::Event_StartMeleeBeam
=====================
void idPlayer::Event_StartMeleeBeam( int num ) {
if ( weapon.GetEntity() ) {
weapon.GetEntity()->StartMeleeBeam( num );
}
}
*/
/*
=====================
idPlayer::Event_StopMeleeBeam
=====================
void idPlayer::Event_StopMeleeBeam( void ) {
if ( weapon.GetEntity() ) {
weapon.GetEntity()->StopMeleeBeam();
}
}
*/
//ivan end
//ivan test
/*
=====================
idPlayer::Event_StartKick
@ -10573,6 +10809,14 @@ void idPlayer::ShowPossibleInteract( int flags ){
if( flags & INTERACT_IMPULSE ){
hud->HandleNamedEvent( "interactImpulse" );
}
/*
if( flags & INTERACT_UP ){
hud->HandleNamedEvent( "interactUp" );
}
if( flags & INTERACT_DOWN ){
hud->HandleNamedEvent( "interactDown" );
}
*/
}
//ivan test end

View file

@ -70,6 +70,54 @@ void idPlayerCursor::Draw( const idVec3 &origin, const idMat3 &axis,const char *
//linearly interpolate 5 feet between the camera position and the point at which the weapon is aiming
endPos.Lerp(cameraOrigin,endPos,length);
/*
//ivan start
idVec3 localDir;
idVec3 dir;
dir = endPos - cameraOrigin; //vettore da camera a dest
dir.NormalizeFast();
cameraAxis.ProjectVector( dir, localDir ); //proietto su piano telecamera
idAngles destLookAng;
destLookAng = (endPos - cameraOrigin).ToAngles().Normalize180();
idAngles cameraLookAng;
cameraLookAng = cameraAxis.ToAngles().Normalize180();
//fix
if( destLookAng[0] < -70 ){ //if it goes beyond this value all is wrong! Don't know why.
destLookAng[1] = 90;
cameraLookAng[1] = 89;
}
idAngles deltaLookAng;
deltaLookAng = (destLookAng - cameraLookAng).Normalize180();
gameLocal.Printf("destLookAng: %s\n", destLookAng.ToString() );
gameLocal.Printf("cameraLookAng: %s\n", cameraLookAng.ToString() );
gameLocal.Printf("delta: %s\n", deltaLookAng.ToString() );
//x: lungo su/giù retta. 0 = centro, pos = mirino sotto, neg = mirino sopra
//y: pos = quanto sx
//z: 0
int cposx = (int) (320 - 320 * ( deltaLookAng[1] / 90.0f ));
int cposy = (int) (240 + 240 * ( deltaLookAng[0] / 45.0f ));
gameLocal.Printf("cposx: %d, cposy: %d\n", cposx, cposy );
localPlayer->cursor->SetStateInt( "cposx", cposx );
localPlayer->cursor->SetStateInt( "cposy", cposy );
localPlayer->cursor->StateChanged( gameLocal.time );
//red: weapon
gameRenderWorld->DebugLine( colorRed, origin, endPos, gameLocal.msec );
//yellow: camera
gameRenderWorld->DebugLine( colorYellow, origin , cameraOrigin + cameraAxis[ 0 ] * 64.0f, gameLocal.msec );
//ivan end
*/
if ( !CreateCursor(localPlayer, endPos, cameraAxis,material )) {
UpdateCursor(localPlayer, endPos, cameraAxis);
}