Skip to content

Commit 47cba24

Browse files
avoitishinXottab-DUTY
authored andcommitted
+ new config defines for custom animations and sounds - NEW_ANIMS, NEW_SOUNDS
+ new weapon classes (WeaponCustomPistolAuto and WeaponRevolver) + new weapon animations (anm_idle_moving_crouch, anm_reload_empty, anm_reload_empty_w_gl, anm_idle_moving_crouch_g, anm_idle_moving_crouch_w_gl) + new weapon sounds (snd_reload_empty)
1 parent 4010599 commit 47cba24

20 files changed

+435
-47
lines changed

src/Common/Config.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212
//#define FP_DEATH // first person death view
1313
#define DETAIL_RADIUS // detail draw radius (by K.D.)
1414
#define ECO_RENDER //ECO_RENDER adds a small delay between rendering, reduce FPS in main menu or in videos
15+
#define NEW_ANIMS // use new animations. Please enclose any new animation additions with this define
16+
#define NEW_SOUNDS // use new sounds. Please enclose any new sound additions with this define

src/xrGame/HudItem.cpp

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#include "stdafx.h"
22
#include "HudItem.h"
33
#include "physic_item.h"
4-
#include "actor.h"
5-
#include "actoreffector.h"
4+
#include "Actor.h"
5+
#include "ActorEffector.h"
66
#include "Missile.h"
7-
#include "xrmessages.h"
7+
#include "xrMessages.h"
88
#include "Level.h"
9-
#include "inventory.h"
9+
#include "Inventory.h"
1010
#include "xrEngine/CameraBase.h"
1111
#include "player_hud.h"
1212
#include "xrCore/Animation/SkeletonMotions.hpp"
1313

14+
#include "Common/Config.hpp"
15+
#include "ui_base.h"
16+
1417
CHudItem::CHudItem()
1518
{
1619
RenderHud(TRUE);
@@ -327,18 +330,44 @@ bool CHudItem::TryPlayAnimIdle()
327330
PlayAnimIdleSprint();
328331
return true;
329332
}
330-
else if (!st.bCrouch && pActor->AnyMove())
333+
if (pActor->AnyMove())
331334
{
332-
PlayAnimIdleMoving();
333-
return true;
335+
if (!st.bCrouch)
336+
{
337+
PlayAnimIdleMoving();
338+
return true;
339+
}
340+
#ifdef NEW_ANIMS //AVO: new crouch idle animation
341+
if (st.bCrouch && isHUDAnimationExist("anm_idle_moving_crouch"))
342+
{
343+
PlayAnimIdleMovingCrouch();
344+
return true;
345+
}
346+
#endif //-NEW_ANIMS
334347
}
335348
}
336349
}
337350
return false;
338351
}
339352

340-
void CHudItem::PlayAnimIdleMoving() { PlayHUDMotion("anm_idle_moving", TRUE, NULL, GetState()); }
341-
void CHudItem::PlayAnimIdleSprint() { PlayHUDMotion("anm_idle_sprint", TRUE, NULL, GetState()); }
353+
//AVO: check if animation exists
354+
bool CHudItem::isHUDAnimationExist(pcstr anim_name)
355+
{
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());
365+
return false;
366+
}
367+
368+
void CHudItem::PlayAnimIdleMovingCrouch() { PlayHUDMotion("anm_idle_moving_crouch", true, nullptr, GetState()); }
369+
void CHudItem::PlayAnimIdleMoving() { PlayHUDMotion("anm_idle_moving", true, nullptr, GetState()); }
370+
void CHudItem::PlayAnimIdleSprint() { PlayHUDMotion("anm_idle_sprint", true, nullptr, GetState()); }
342371
void CHudItem::OnMovementChanged(ACTOR_DEFS::EMoveCommand cmd)
343372
{
344373
if (GetState() == eIdle && !m_bStopAtEndAnimIsRunning)

src/xrGame/HudItem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,6 @@ class CHudItem : public CHUDState
180180
virtual void debug_draw_firedeps(){};
181181

182182
virtual CHudItem* cast_hud_item() { return this; }
183+
void PlayAnimIdleMovingCrouch(); //AVO: new crouch idle animation
184+
bool isHUDAnimationExist(pcstr anim_name);
183185
};

src/xrGame/HudSound.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ struct HUD_SOUND_ITEM
5151
class HUD_SOUND_COLLECTION
5252
{
5353
xr_vector<HUD_SOUND_ITEM> m_sound_items;
54-
HUD_SOUND_ITEM* FindSoundItem(LPCSTR alias, bool b_assert);
5554

5655
public:
5756
~HUD_SOUND_COLLECTION();
57+
58+
HUD_SOUND_ITEM* FindSoundItem(LPCSTR alias, bool b_assert); //AVO: made public to check if sound is loaded
59+
5860
void PlaySound(LPCSTR alias, const Fvector& position, const IGameObject* parent, bool hud_mode, bool looped = false,
5961
u8 index = u8(-1));
6062

src/xrGame/WeaponAutomaticShotgun.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CWeaponAutomaticShotgun : public CWeaponMagazined
2525
void PlayAnimCloseWeapon();
2626

2727
virtual bool Action(u16 cmd, u32 flags);
28-
virtual int GetCurrentFireMode() { return m_aFireModes[m_iCurFireMode]; };
28+
//virtual int GetCurrentFireMode() { return m_aFireModes[m_iCurFireMode]; } //AVO: this is already implemented in parent class (CWeaponMagazined)
2929
protected:
3030
virtual void OnAnimationEnd(u32 state);
3131
void TriStateReload();

src/xrGame/WeaponCustomPistol.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#include "stdafx.h"
2-
3-
#include "Entity.h"
42
#include "WeaponCustomPistol.h"
53

64
CWeaponCustomPistol::CWeaponCustomPistol() : CWeaponMagazined(SOUND_TYPE_WEAPON_PISTOL) {}
75
CWeaponCustomPistol::~CWeaponCustomPistol() {}
6+
87
void CWeaponCustomPistol::switch2_Fire()
98
{
109
m_bFireSingleShot = true;
@@ -17,7 +16,7 @@ void CWeaponCustomPistol::FireEnd()
1716
{
1817
if (fShotTimeCounter <= 0)
1918
{
20-
SetPending(FALSE);
19+
SetPending(false);
2120
inherited::FireEnd();
2221
}
2322
}

src/xrGame/WeaponCustomPistol.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#pragma once
2-
32
#include "WeaponMagazined.h"
43

54
class CWeaponCustomPistol : public CWeaponMagazined
65
{
7-
private:
8-
typedef CWeaponMagazined inherited;
6+
using inherited = CWeaponMagazined;
97

108
public:
119
CWeaponCustomPistol();
1210
virtual ~CWeaponCustomPistol();
13-
virtual int GetCurrentFireMode() { return 1; };
11+
int GetCurrentFireMode() override { return 1; }
12+
1413
protected:
15-
virtual void FireEnd();
16-
virtual void switch2_Fire();
14+
void FireEnd() override;
15+
void switch2_Fire() override;
1716
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "stdafx.h"
2+
#include "WeaponCustomPistolAuto.h"
3+
4+
CWeaponCustomPistolAuto::CWeaponCustomPistolAuto() : CWeaponMagazined(SOUND_TYPE_WEAPON_PISTOL) {}
5+
6+
CWeaponCustomPistolAuto::~CWeaponCustomPistolAuto() {}
7+
8+
void CWeaponCustomPistolAuto::switch2_Fire()
9+
{
10+
m_bFireSingleShot = true;
11+
//bWorking = false;
12+
m_iShotNum = 0;
13+
m_bStopedAfterQueueFired = false;
14+
}
15+
16+
void CWeaponCustomPistolAuto::FireEnd()
17+
{
18+
//if (fShotTimeCounter <= 0)
19+
{
20+
//SetPending(false);
21+
inherited::FireEnd();
22+
}
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include "WeaponMagazined.h"
4+
5+
class CWeaponCustomPistolAuto: public CWeaponMagazined
6+
{
7+
using inherited = CWeaponMagazined;
8+
9+
public:
10+
CWeaponCustomPistolAuto();
11+
virtual ~CWeaponCustomPistolAuto();
12+
//int GetCurrentFireMode() override { return 1; };
13+
14+
protected:
15+
void FireEnd() override;
16+
void switch2_Fire() override;
17+
};

src/xrGame/WeaponMagazined.cpp

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#include "game_object_space.h"
2222
#include "script_callback_ex.h"
2323
#include "script_game_object.h"
24+
#include "HudSound.h"
25+
26+
#include "Common/Config.hpp"
2427

2528
ENGINE_API bool g_dedicated_server;
2629

@@ -42,6 +45,7 @@ CWeaponMagazined::CWeaponMagazined(ESoundTypes eSoundType) : CWeapon()
4245
m_eSoundShot = ESoundTypes(SOUND_TYPE_WEAPON_SHOOTING | eSoundType);
4346
m_eSoundEmptyClick = ESoundTypes(SOUND_TYPE_WEAPON_EMPTY_CLICKING | eSoundType);
4447
m_eSoundReload = ESoundTypes(SOUND_TYPE_WEAPON_RECHARGING | eSoundType);
48+
m_eSoundReloadEmpty = ESoundTypes(SOUND_TYPE_WEAPON_RECHARGING | eSoundType);
4549
m_sounds_enabled = true;
4650

4751
m_sSndShotCurrent = NULL;
@@ -60,6 +64,20 @@ CWeaponMagazined::~CWeaponMagazined()
6064
}
6165

6266
void CWeaponMagazined::net_Destroy() { inherited::net_Destroy(); }
67+
68+
//AVO: for custom added sounds check if sound exists
69+
bool CWeaponMagazined::WeaponSoundExist(LPCSTR section, LPCSTR sound_name)
70+
{
71+
pcstr str;
72+
bool sec_exist = process_if_exists_set(section, sound_name, &CInifile::r_string, str, true);
73+
if (sec_exist)
74+
return true;
75+
Msg("~ [WARNING] ------ Sound [%s] does not exist in [%s]", sound_name, section);
76+
return false;
77+
}
78+
79+
//-AVO
80+
6381
void CWeaponMagazined::Load(LPCSTR section)
6482
{
6583
inherited::Load(section);
@@ -71,6 +89,11 @@ void CWeaponMagazined::Load(LPCSTR section)
7189
m_sounds.LoadSound(section, "snd_empty", "sndEmptyClick", false, m_eSoundEmptyClick);
7290
m_sounds.LoadSound(section, "snd_reload", "sndReload", true, m_eSoundReload);
7391

92+
#ifdef NEW_SOUNDS //AVO: custom sounds go here
93+
if (WeaponSoundExist(section, "snd_reload_empty"))
94+
m_sounds.LoadSound(section, "snd_reload_empty", "sndReloadEmpty", true, m_eSoundReloadEmpty);
95+
#endif //-NEW_SOUNDS
96+
7497
m_sSndShotCurrent = "sndShot";
7598

7699
//звуки и партиклы глушителя, еслит такой есть
@@ -457,6 +480,12 @@ void CWeaponMagazined::UpdateSounds()
457480
m_sounds.SetPosition("sndHide", P);
458481
//. nah m_sounds.SetPosition("sndShot", P);
459482
m_sounds.SetPosition("sndReload", P);
483+
484+
#ifdef NEW_SOUNDS //AVO: custom sounds go here
485+
if (m_sounds.FindSoundItem("sndReloadEmpty", false))
486+
m_sounds.SetPosition("sndReloadEmpty", P);
487+
#endif //-NEW_SOUNDS
488+
460489
//. nah m_sounds.SetPosition("sndEmptyClick", P);
461490
}
462491

@@ -688,7 +717,17 @@ void CWeaponMagazined::switch2_Empty()
688717
void CWeaponMagazined::PlayReloadSound()
689718
{
690719
if (m_sounds_enabled)
691-
PlaySound("sndReload", get_LastFP());
720+
if (iAmmoElapsed == 0)
721+
{
722+
#ifdef NEW_SOUNDS //AVO: custom reload sound
723+
if (m_sounds.FindSoundItem("sndReloadEmpty", false))
724+
PlaySound("sndReloadEmpty", get_LastFP());
725+
else
726+
#endif //-NEW_SOUNDS
727+
PlaySound("sndReload", get_LastFP());
728+
}
729+
else
730+
PlaySound("sndReload", get_LastFP());
692731
}
693732

694733
void CWeaponMagazined::switch2_Reload()
@@ -1053,7 +1092,17 @@ void CWeaponMagazined::PlayAnimShow()
10531092
void CWeaponMagazined::PlayAnimHide()
10541093
{
10551094
VERIFY(GetState() == eHiding);
1056-
PlayHUDMotion("anm_hide", TRUE, this, GetState());
1095+
if (iAmmoElapsed == 0)
1096+
{
1097+
#ifdef NEW_ANIMS //AVO: new reload animation
1098+
if (isHUDAnimationExist("anm_reload_empty"))
1099+
PlayHUDMotion("anm_reload_empty", true, this, GetState());
1100+
else
1101+
#endif //-NEW_ANIMS
1102+
PlayHUDMotion("anm_reload", true, this, GetState());
1103+
}
1104+
else
1105+
PlayHUDMotion("anm_reload", true, this, GetState());
10571106
}
10581107

10591108
void CWeaponMagazined::PlayAnimReload()
@@ -1348,6 +1397,15 @@ bool CWeaponMagazined::install_upgrade_impl(LPCSTR section, bool test)
13481397
}
13491398
result |= result2;
13501399

1400+
#ifdef NEW_SOUNDS //AVO: custom sounds go here
1401+
result2 = process_if_exists_set(section, "snd_reload_empty", &CInifile::r_string, str, test);
1402+
if (result2 && !test)
1403+
{
1404+
m_sounds.LoadSound(section, "snd_reload_empty", "sndReloadEmpty", true, m_eSoundReloadEmpty);
1405+
}
1406+
result |= result2;
1407+
#endif //-NEW_SOUNDS
1408+
13511409
// snd_shoot1 = weapons\ak74u_shot_1 ??
13521410
// snd_shoot2 = weapons\ak74u_shot_2 ??
13531411
// snd_shoot3 = weapons\ak74u_shot_3 ??

0 commit comments

Comments
 (0)