Skip to content

Commit 05a48e4

Browse files
avoitishinXottab-DUTY
authored andcommitted
+ initial framework for misfire sounds and animations (aka gunslinger)
* added ability to check for existence of 3rd person animations * refactoring
1 parent 513f918 commit 05a48e4

File tree

6 files changed

+89
-31
lines changed

6 files changed

+89
-31
lines changed

src/xrGame/HudItem.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,20 @@ bool CHudItem::TryPlayAnimIdle()
353353
//AVO: check if animation exists
354354
bool CHudItem::isHUDAnimationExist(pcstr anim_name)
355355
{
356-
string256 anim_name_r;
357-
bool is_16x9 = UI().is_widescreen();
358-
u16 attach_place_idx = pSettings->r_u16(HudItemData()->m_sect_name, "attach_place_idx");
359-
xr_sprintf(anim_name_r, "%s%s", anim_name, ((attach_place_idx == 1) && is_16x9) ? "_16x9" : "");
360-
player_hud_motion* anm = HudItemData()->m_hand_motions.find_motion(anim_name_r);
361-
//VERIFY2(anm, make_string("Animation [%s] not found", anim_name).c_str());
362-
if (anm)
363-
return true;
364-
Msg("~ [WARNING] ------ Animation [%s] does not exist in [%s]", anim_name, HudItemData()->m_sect_name.c_str());
356+
if (HudItemData()) // First person
357+
{
358+
string256 anim_name_r;
359+
bool is_16x9 = UI().is_widescreen();
360+
u16 attach_place_idx = pSettings->r_u16(HudItemData()->m_sect_name, "attach_place_idx");
361+
xr_sprintf(anim_name_r, "%s%s", anim_name, (attach_place_idx == 1 && is_16x9) ? "_16x9" : "");
362+
player_hud_motion* anm = HudItemData()->m_hand_motions.find_motion(anim_name_r);
363+
if (anm)
364+
return true;
365+
}
366+
else // Third person
367+
if (g_player_hud->motion_length(anim_name, HudSection(), m_current_motion_def) > 100)
368+
return true;
369+
Msg("~ [WARNING] ------ Animation [%s] does not exist in [%s]", anim_name, HudSection().c_str());
365370
return false;
366371
}
367372

src/xrGame/WeaponCustomPistolAuto.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ void CWeaponCustomPistolAuto::FireEnd()
2121
inherited::FireEnd();
2222
}
2323
}
24+
25+
void CWeaponCustomPistolAuto::PlayAnimReload()
26+
{
27+
inherited::PlayAnimReload();
28+
}

src/xrGame/WeaponCustomPistolAuto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ class CWeaponCustomPistolAuto: public CWeaponMagazined
1414
protected:
1515
void FireEnd() override;
1616
void switch2_Fire() override;
17+
void PlayAnimReload() override;
1718
};

src/xrGame/WeaponMagazined.cpp

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -717,17 +717,30 @@ void CWeaponMagazined::switch2_Empty()
717717
void CWeaponMagazined::PlayReloadSound()
718718
{
719719
if (m_sounds_enabled)
720-
if (iAmmoElapsed == 0)
720+
{
721+
#ifdef NEW_SOUNDS //AVO: use custom sounds
722+
if (bMisfire)
721723
{
722-
#ifdef NEW_SOUNDS //AVO: custom reload sound
723-
if (m_sounds.FindSoundItem("sndReloadEmpty", false))
724-
PlaySound("sndReloadEmpty", get_LastFP());
724+
//TODO: make sure correct sound is loaded in CWeaponMagazined::Load(LPCSTR section)
725+
if (m_sounds.FindSoundItem("sndReloadMisfire", false))
726+
PlaySound("sndReloadMisfire", get_LastFP());
725727
else
726-
#endif //-NEW_SOUNDS
727728
PlaySound("sndReload", get_LastFP());
728729
}
729730
else
730-
PlaySound("sndReload", get_LastFP());
731+
{
732+
if (iAmmoElapsed == 0)
733+
if (m_sounds.FindSoundItem("sndReloadEmpty", false))
734+
PlaySound("sndReloadEmpty", get_LastFP());
735+
else
736+
PlaySound("sndReload", get_LastFP());
737+
else
738+
PlaySound("sndReload", get_LastFP());
739+
}
740+
#else
741+
PlaySound("sndReload", get_LastFP());
742+
#endif //-AVO
743+
}
731744
}
732745

733746
void CWeaponMagazined::switch2_Reload()
@@ -1107,11 +1120,30 @@ void CWeaponMagazined::PlayAnimHide()
11071120

11081121
void CWeaponMagazined::PlayAnimReload()
11091122
{
1110-
VERIFY(GetState() == eReload);
1111-
PlayHUDMotion("anm_reload", TRUE, this, GetState());
1123+
auto state = GetState();
1124+
VERIFY(state == eReload);
1125+
#ifdef NEW_ANIMS //AVO: use new animations
1126+
if (bMisfire)
1127+
if (isHUDAnimationExist("anm_reload_misfire"))
1128+
PlayHUDMotion("anm_reload_misfire", true, this, state);
1129+
else
1130+
PlayHUDMotion("anm_reload", true, this, state);
1131+
else
1132+
{
1133+
if (iAmmoElapsed == 0)
1134+
if (isHUDAnimationExist("anm_reload_empty"))
1135+
PlayHUDMotion("anm_reload_empty", true, this, state);
1136+
else
1137+
PlayHUDMotion("anm_reload", true, this, state);
1138+
else
1139+
PlayHUDMotion("anm_reload", true, this, state);
1140+
}
1141+
#else
1142+
PlayHUDMotion("anm_reload", true, this, state);
1143+
#endif //-NEW_ANIM
11121144
}
11131145

1114-
void CWeaponMagazined::PlayAnimAim() { PlayHUDMotion("anm_idle_aim", TRUE, NULL, GetState()); }
1146+
void CWeaponMagazined::PlayAnimAim() { PlayHUDMotion("anm_idle_aim", true, nullptr, GetState()); }
11151147
void CWeaponMagazined::PlayAnimIdle()
11161148
{
11171149
if (GetState() != eIdle)

src/xrGame/WeaponMagazinedWGrenade.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -594,20 +594,37 @@ void CWeaponMagazinedWGrenade::PlayAnimReload()
594594
auto state = GetState();
595595
VERIFY(state == eReload);
596596

597+
#ifdef NEW_ANIMS //AVO: use new animations
597598
if (IsGrenadeLauncherAttached())
598-
if (iAmmoElapsed == 0)
599+
{
600+
if (bMisfire)
599601
{
600-
#ifdef NEW_ANIMS //AVO: new reload animation
601-
if (isHUDAnimationExist("anm_reload_empty_w_gl"))
602-
PlayHUDMotion("anm_reload_empty_w_gl", true, this, state);
602+
if (isHUDAnimationExist("anm_reload_misfire_w_gl"))
603+
PlayHUDMotion("anm_reload_misfire_w_gl", true, this, state);
603604
else
604-
#endif //-NEW_ANIMS
605605
PlayHUDMotion("anm_reload_w_gl", true, this, state);
606606
}
607607
else
608-
PlayHUDMotion("anm_reload_w_gl", true, this, state);
608+
{
609+
if (iAmmoElapsed == 0)
610+
{
611+
if (isHUDAnimationExist("anm_reload_empty_w_gl"))
612+
PlayHUDMotion("anm_reload_empty_w_gl", true, this, state);
613+
else
614+
PlayHUDMotion("anm_reload_w_gl", true, this, state);
615+
}
616+
else
617+
PlayHUDMotion("anm_reload_w_gl", true, this, state);
618+
}
619+
}
620+
else
621+
inherited::PlayAnimReload();
622+
#else
623+
if (IsGrenadeLauncherAttached())
624+
PlayHUDMotion("anm_reload_w_gl", true, this, state);
609625
else
610626
inherited::PlayAnimReload();
627+
#endif //-NEW_ANIMS
611628
}
612629

613630
void CWeaponMagazinedWGrenade::PlayAnimIdle()

src/xrGame/WeaponPistol.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,13 @@ void CWeaponPistol::PlayAnimAim()
8686

8787
void CWeaponPistol::PlayAnimReload()
8888
{
89-
VERIFY(GetState() == eReload);
89+
/*VERIFY(GetState() == eReload);
9090
if (iAmmoElapsed == 0)
91-
{
92-
PlayHUDMotion("anm_reload_empty", TRUE, this, GetState());
93-
}
91+
PlayHUDMotion("anm_reload_empty", true, this, GetState());
9492
else
95-
{
96-
PlayHUDMotion("anm_reload", TRUE, this, GetState());
97-
}
93+
PlayHUDMotion("anm_reload", true, this, GetState());*/
94+
95+
inherited::PlayAnimReload(); //AVO: refactored to use grand-parent (CWeaponMagazined) function
9896
}
9997

10098
void CWeaponPistol::PlayAnimHide()

0 commit comments

Comments
 (0)