Skip to content

Commit

Permalink
+ initial framework for misfire sounds and animations (aka gunslinger)
Browse files Browse the repository at this point in the history
* added ability to check for existence of 3rd person animations
* refactoring
  • Loading branch information
avoitishin authored and Xottab-DUTY committed Aug 18, 2017
1 parent 513f918 commit 05a48e4
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 31 deletions.
23 changes: 14 additions & 9 deletions src/xrGame/HudItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,20 @@ bool CHudItem::TryPlayAnimIdle()
//AVO: check if animation exists
bool CHudItem::isHUDAnimationExist(pcstr anim_name)
{
string256 anim_name_r;
bool is_16x9 = UI().is_widescreen();
u16 attach_place_idx = pSettings->r_u16(HudItemData()->m_sect_name, "attach_place_idx");
xr_sprintf(anim_name_r, "%s%s", anim_name, ((attach_place_idx == 1) && is_16x9) ? "_16x9" : "");
player_hud_motion* anm = HudItemData()->m_hand_motions.find_motion(anim_name_r);
//VERIFY2(anm, make_string("Animation [%s] not found", anim_name).c_str());
if (anm)
return true;
Msg("~ [WARNING] ------ Animation [%s] does not exist in [%s]", anim_name, HudItemData()->m_sect_name.c_str());
if (HudItemData()) // First person
{
string256 anim_name_r;
bool is_16x9 = UI().is_widescreen();
u16 attach_place_idx = pSettings->r_u16(HudItemData()->m_sect_name, "attach_place_idx");
xr_sprintf(anim_name_r, "%s%s", anim_name, (attach_place_idx == 1 && is_16x9) ? "_16x9" : "");
player_hud_motion* anm = HudItemData()->m_hand_motions.find_motion(anim_name_r);
if (anm)
return true;
}
else // Third person
if (g_player_hud->motion_length(anim_name, HudSection(), m_current_motion_def) > 100)
return true;
Msg("~ [WARNING] ------ Animation [%s] does not exist in [%s]", anim_name, HudSection().c_str());
return false;
}

Expand Down
5 changes: 5 additions & 0 deletions src/xrGame/WeaponCustomPistolAuto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ void CWeaponCustomPistolAuto::FireEnd()
inherited::FireEnd();
}
}

void CWeaponCustomPistolAuto::PlayAnimReload()
{
inherited::PlayAnimReload();
}
1 change: 1 addition & 0 deletions src/xrGame/WeaponCustomPistolAuto.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ class CWeaponCustomPistolAuto: public CWeaponMagazined
protected:
void FireEnd() override;
void switch2_Fire() override;
void PlayAnimReload() override;
};
50 changes: 41 additions & 9 deletions src/xrGame/WeaponMagazined.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,17 +717,30 @@ void CWeaponMagazined::switch2_Empty()
void CWeaponMagazined::PlayReloadSound()
{
if (m_sounds_enabled)
if (iAmmoElapsed == 0)
{
#ifdef NEW_SOUNDS //AVO: use custom sounds
if (bMisfire)
{
#ifdef NEW_SOUNDS //AVO: custom reload sound
if (m_sounds.FindSoundItem("sndReloadEmpty", false))
PlaySound("sndReloadEmpty", get_LastFP());
//TODO: make sure correct sound is loaded in CWeaponMagazined::Load(LPCSTR section)
if (m_sounds.FindSoundItem("sndReloadMisfire", false))
PlaySound("sndReloadMisfire", get_LastFP());
else
#endif //-NEW_SOUNDS
PlaySound("sndReload", get_LastFP());
}
else
PlaySound("sndReload", get_LastFP());
{
if (iAmmoElapsed == 0)
if (m_sounds.FindSoundItem("sndReloadEmpty", false))
PlaySound("sndReloadEmpty", get_LastFP());
else
PlaySound("sndReload", get_LastFP());
else
PlaySound("sndReload", get_LastFP());
}
#else
PlaySound("sndReload", get_LastFP());
#endif //-AVO
}
}

void CWeaponMagazined::switch2_Reload()
Expand Down Expand Up @@ -1107,11 +1120,30 @@ void CWeaponMagazined::PlayAnimHide()

void CWeaponMagazined::PlayAnimReload()
{
VERIFY(GetState() == eReload);
PlayHUDMotion("anm_reload", TRUE, this, GetState());
auto state = GetState();
VERIFY(state == eReload);
#ifdef NEW_ANIMS //AVO: use new animations
if (bMisfire)
if (isHUDAnimationExist("anm_reload_misfire"))
PlayHUDMotion("anm_reload_misfire", true, this, state);
else
PlayHUDMotion("anm_reload", true, this, state);
else
{
if (iAmmoElapsed == 0)
if (isHUDAnimationExist("anm_reload_empty"))
PlayHUDMotion("anm_reload_empty", true, this, state);
else
PlayHUDMotion("anm_reload", true, this, state);
else
PlayHUDMotion("anm_reload", true, this, state);
}
#else
PlayHUDMotion("anm_reload", true, this, state);
#endif //-NEW_ANIM
}

void CWeaponMagazined::PlayAnimAim() { PlayHUDMotion("anm_idle_aim", TRUE, NULL, GetState()); }
void CWeaponMagazined::PlayAnimAim() { PlayHUDMotion("anm_idle_aim", true, nullptr, GetState()); }
void CWeaponMagazined::PlayAnimIdle()
{
if (GetState() != eIdle)
Expand Down
29 changes: 23 additions & 6 deletions src/xrGame/WeaponMagazinedWGrenade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,20 +594,37 @@ void CWeaponMagazinedWGrenade::PlayAnimReload()
auto state = GetState();
VERIFY(state == eReload);

#ifdef NEW_ANIMS //AVO: use new animations
if (IsGrenadeLauncherAttached())
if (iAmmoElapsed == 0)
{
if (bMisfire)
{
#ifdef NEW_ANIMS //AVO: new reload animation
if (isHUDAnimationExist("anm_reload_empty_w_gl"))
PlayHUDMotion("anm_reload_empty_w_gl", true, this, state);
if (isHUDAnimationExist("anm_reload_misfire_w_gl"))
PlayHUDMotion("anm_reload_misfire_w_gl", true, this, state);
else
#endif //-NEW_ANIMS
PlayHUDMotion("anm_reload_w_gl", true, this, state);
}
else
PlayHUDMotion("anm_reload_w_gl", true, this, state);
{
if (iAmmoElapsed == 0)
{
if (isHUDAnimationExist("anm_reload_empty_w_gl"))
PlayHUDMotion("anm_reload_empty_w_gl", true, this, state);
else
PlayHUDMotion("anm_reload_w_gl", true, this, state);
}
else
PlayHUDMotion("anm_reload_w_gl", true, this, state);
}
}
else
inherited::PlayAnimReload();
#else
if (IsGrenadeLauncherAttached())
PlayHUDMotion("anm_reload_w_gl", true, this, state);
else
inherited::PlayAnimReload();
#endif //-NEW_ANIMS
}

void CWeaponMagazinedWGrenade::PlayAnimIdle()
Expand Down
12 changes: 5 additions & 7 deletions src/xrGame/WeaponPistol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,13 @@ void CWeaponPistol::PlayAnimAim()

void CWeaponPistol::PlayAnimReload()
{
VERIFY(GetState() == eReload);
/*VERIFY(GetState() == eReload);
if (iAmmoElapsed == 0)
{
PlayHUDMotion("anm_reload_empty", TRUE, this, GetState());
}
PlayHUDMotion("anm_reload_empty", true, this, GetState());
else
{
PlayHUDMotion("anm_reload", TRUE, this, GetState());
}
PlayHUDMotion("anm_reload", true, this, GetState());*/

inherited::PlayAnimReload(); //AVO: refactored to use grand-parent (CWeaponMagazined) function
}

void CWeaponPistol::PlayAnimHide()
Expand Down

0 comments on commit 05a48e4

Please sign in to comment.