Skip to content

Commit

Permalink
+ new config defines for custom animations and sounds - NEW_ANIMS, NE…
Browse files Browse the repository at this point in the history
…W_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)
  • Loading branch information
avoitishin authored and Xottab-DUTY committed Aug 18, 2017
1 parent 4010599 commit 47cba24
Show file tree
Hide file tree
Showing 20 changed files with 435 additions and 47 deletions.
2 changes: 2 additions & 0 deletions src/Common/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
//#define FP_DEATH // first person death view
#define DETAIL_RADIUS // detail draw radius (by K.D.)
#define ECO_RENDER //ECO_RENDER adds a small delay between rendering, reduce FPS in main menu or in videos
#define NEW_ANIMS // use new animations. Please enclose any new animation additions with this define
#define NEW_SOUNDS // use new sounds. Please enclose any new sound additions with this define
47 changes: 38 additions & 9 deletions src/xrGame/HudItem.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#include "stdafx.h"
#include "HudItem.h"
#include "physic_item.h"
#include "actor.h"
#include "actoreffector.h"
#include "Actor.h"
#include "ActorEffector.h"
#include "Missile.h"
#include "xrmessages.h"
#include "xrMessages.h"
#include "Level.h"
#include "inventory.h"
#include "Inventory.h"
#include "xrEngine/CameraBase.h"
#include "player_hud.h"
#include "xrCore/Animation/SkeletonMotions.hpp"

#include "Common/Config.hpp"
#include "ui_base.h"

CHudItem::CHudItem()
{
RenderHud(TRUE);
Expand Down Expand Up @@ -327,18 +330,44 @@ bool CHudItem::TryPlayAnimIdle()
PlayAnimIdleSprint();
return true;
}
else if (!st.bCrouch && pActor->AnyMove())
if (pActor->AnyMove())
{
PlayAnimIdleMoving();
return true;
if (!st.bCrouch)
{
PlayAnimIdleMoving();
return true;
}
#ifdef NEW_ANIMS //AVO: new crouch idle animation
if (st.bCrouch && isHUDAnimationExist("anm_idle_moving_crouch"))
{
PlayAnimIdleMovingCrouch();
return true;
}
#endif //-NEW_ANIMS
}
}
}
return false;
}

void CHudItem::PlayAnimIdleMoving() { PlayHUDMotion("anm_idle_moving", TRUE, NULL, GetState()); }
void CHudItem::PlayAnimIdleSprint() { PlayHUDMotion("anm_idle_sprint", TRUE, NULL, GetState()); }
//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());
return false;
}

void CHudItem::PlayAnimIdleMovingCrouch() { PlayHUDMotion("anm_idle_moving_crouch", true, nullptr, GetState()); }
void CHudItem::PlayAnimIdleMoving() { PlayHUDMotion("anm_idle_moving", true, nullptr, GetState()); }
void CHudItem::PlayAnimIdleSprint() { PlayHUDMotion("anm_idle_sprint", true, nullptr, GetState()); }
void CHudItem::OnMovementChanged(ACTOR_DEFS::EMoveCommand cmd)
{
if (GetState() == eIdle && !m_bStopAtEndAnimIsRunning)
Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/HudItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,6 @@ class CHudItem : public CHUDState
virtual void debug_draw_firedeps(){};

virtual CHudItem* cast_hud_item() { return this; }
void PlayAnimIdleMovingCrouch(); //AVO: new crouch idle animation
bool isHUDAnimationExist(pcstr anim_name);
};
4 changes: 3 additions & 1 deletion src/xrGame/HudSound.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ struct HUD_SOUND_ITEM
class HUD_SOUND_COLLECTION
{
xr_vector<HUD_SOUND_ITEM> m_sound_items;
HUD_SOUND_ITEM* FindSoundItem(LPCSTR alias, bool b_assert);

public:
~HUD_SOUND_COLLECTION();

HUD_SOUND_ITEM* FindSoundItem(LPCSTR alias, bool b_assert); //AVO: made public to check if sound is loaded

void PlaySound(LPCSTR alias, const Fvector& position, const IGameObject* parent, bool hud_mode, bool looped = false,
u8 index = u8(-1));

Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/WeaponAutomaticShotgun.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CWeaponAutomaticShotgun : public CWeaponMagazined
void PlayAnimCloseWeapon();

virtual bool Action(u16 cmd, u32 flags);
virtual int GetCurrentFireMode() { return m_aFireModes[m_iCurFireMode]; };
//virtual int GetCurrentFireMode() { return m_aFireModes[m_iCurFireMode]; } //AVO: this is already implemented in parent class (CWeaponMagazined)
protected:
virtual void OnAnimationEnd(u32 state);
void TriStateReload();
Expand Down
5 changes: 2 additions & 3 deletions src/xrGame/WeaponCustomPistol.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include "stdafx.h"

#include "Entity.h"
#include "WeaponCustomPistol.h"

CWeaponCustomPistol::CWeaponCustomPistol() : CWeaponMagazined(SOUND_TYPE_WEAPON_PISTOL) {}
CWeaponCustomPistol::~CWeaponCustomPistol() {}

void CWeaponCustomPistol::switch2_Fire()
{
m_bFireSingleShot = true;
Expand All @@ -17,7 +16,7 @@ void CWeaponCustomPistol::FireEnd()
{
if (fShotTimeCounter <= 0)
{
SetPending(FALSE);
SetPending(false);
inherited::FireEnd();
}
}
11 changes: 5 additions & 6 deletions src/xrGame/WeaponCustomPistol.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#pragma once

#include "WeaponMagazined.h"

class CWeaponCustomPistol : public CWeaponMagazined
{
private:
typedef CWeaponMagazined inherited;
using inherited = CWeaponMagazined;

public:
CWeaponCustomPistol();
virtual ~CWeaponCustomPistol();
virtual int GetCurrentFireMode() { return 1; };
int GetCurrentFireMode() override { return 1; }

protected:
virtual void FireEnd();
virtual void switch2_Fire();
void FireEnd() override;
void switch2_Fire() override;
};
23 changes: 23 additions & 0 deletions src/xrGame/WeaponCustomPistolAuto.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "stdafx.h"
#include "WeaponCustomPistolAuto.h"

CWeaponCustomPistolAuto::CWeaponCustomPistolAuto() : CWeaponMagazined(SOUND_TYPE_WEAPON_PISTOL) {}

CWeaponCustomPistolAuto::~CWeaponCustomPistolAuto() {}

void CWeaponCustomPistolAuto::switch2_Fire()
{
m_bFireSingleShot = true;
//bWorking = false;
m_iShotNum = 0;
m_bStopedAfterQueueFired = false;
}

void CWeaponCustomPistolAuto::FireEnd()
{
//if (fShotTimeCounter <= 0)
{
//SetPending(false);
inherited::FireEnd();
}
}
17 changes: 17 additions & 0 deletions src/xrGame/WeaponCustomPistolAuto.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include "WeaponMagazined.h"

class CWeaponCustomPistolAuto: public CWeaponMagazined
{
using inherited = CWeaponMagazined;

public:
CWeaponCustomPistolAuto();
virtual ~CWeaponCustomPistolAuto();
//int GetCurrentFireMode() override { return 1; };

protected:
void FireEnd() override;
void switch2_Fire() override;
};
62 changes: 60 additions & 2 deletions src/xrGame/WeaponMagazined.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include "game_object_space.h"
#include "script_callback_ex.h"
#include "script_game_object.h"
#include "HudSound.h"

#include "Common/Config.hpp"

ENGINE_API bool g_dedicated_server;

Expand All @@ -42,6 +45,7 @@ CWeaponMagazined::CWeaponMagazined(ESoundTypes eSoundType) : CWeapon()
m_eSoundShot = ESoundTypes(SOUND_TYPE_WEAPON_SHOOTING | eSoundType);
m_eSoundEmptyClick = ESoundTypes(SOUND_TYPE_WEAPON_EMPTY_CLICKING | eSoundType);
m_eSoundReload = ESoundTypes(SOUND_TYPE_WEAPON_RECHARGING | eSoundType);
m_eSoundReloadEmpty = ESoundTypes(SOUND_TYPE_WEAPON_RECHARGING | eSoundType);
m_sounds_enabled = true;

m_sSndShotCurrent = NULL;
Expand All @@ -60,6 +64,20 @@ CWeaponMagazined::~CWeaponMagazined()
}

void CWeaponMagazined::net_Destroy() { inherited::net_Destroy(); }

//AVO: for custom added sounds check if sound exists
bool CWeaponMagazined::WeaponSoundExist(LPCSTR section, LPCSTR sound_name)
{
pcstr str;
bool sec_exist = process_if_exists_set(section, sound_name, &CInifile::r_string, str, true);
if (sec_exist)
return true;
Msg("~ [WARNING] ------ Sound [%s] does not exist in [%s]", sound_name, section);
return false;
}

//-AVO

void CWeaponMagazined::Load(LPCSTR section)
{
inherited::Load(section);
Expand All @@ -71,6 +89,11 @@ void CWeaponMagazined::Load(LPCSTR section)
m_sounds.LoadSound(section, "snd_empty", "sndEmptyClick", false, m_eSoundEmptyClick);
m_sounds.LoadSound(section, "snd_reload", "sndReload", true, m_eSoundReload);

#ifdef NEW_SOUNDS //AVO: custom sounds go here
if (WeaponSoundExist(section, "snd_reload_empty"))
m_sounds.LoadSound(section, "snd_reload_empty", "sndReloadEmpty", true, m_eSoundReloadEmpty);
#endif //-NEW_SOUNDS

m_sSndShotCurrent = "sndShot";

//звуки и партиклы глушителя, еслит такой есть
Expand Down Expand Up @@ -457,6 +480,12 @@ void CWeaponMagazined::UpdateSounds()
m_sounds.SetPosition("sndHide", P);
//. nah m_sounds.SetPosition("sndShot", P);
m_sounds.SetPosition("sndReload", P);

#ifdef NEW_SOUNDS //AVO: custom sounds go here
if (m_sounds.FindSoundItem("sndReloadEmpty", false))
m_sounds.SetPosition("sndReloadEmpty", P);
#endif //-NEW_SOUNDS

//. nah m_sounds.SetPosition("sndEmptyClick", P);
}

Expand Down Expand Up @@ -688,7 +717,17 @@ void CWeaponMagazined::switch2_Empty()
void CWeaponMagazined::PlayReloadSound()
{
if (m_sounds_enabled)
PlaySound("sndReload", get_LastFP());
if (iAmmoElapsed == 0)
{
#ifdef NEW_SOUNDS //AVO: custom reload sound
if (m_sounds.FindSoundItem("sndReloadEmpty", false))
PlaySound("sndReloadEmpty", get_LastFP());
else
#endif //-NEW_SOUNDS
PlaySound("sndReload", get_LastFP());
}
else
PlaySound("sndReload", get_LastFP());
}

void CWeaponMagazined::switch2_Reload()
Expand Down Expand Up @@ -1053,7 +1092,17 @@ void CWeaponMagazined::PlayAnimShow()
void CWeaponMagazined::PlayAnimHide()
{
VERIFY(GetState() == eHiding);
PlayHUDMotion("anm_hide", TRUE, this, GetState());
if (iAmmoElapsed == 0)
{
#ifdef NEW_ANIMS //AVO: new reload animation
if (isHUDAnimationExist("anm_reload_empty"))
PlayHUDMotion("anm_reload_empty", true, this, GetState());
else
#endif //-NEW_ANIMS
PlayHUDMotion("anm_reload", true, this, GetState());
}
else
PlayHUDMotion("anm_reload", true, this, GetState());
}

void CWeaponMagazined::PlayAnimReload()
Expand Down Expand Up @@ -1348,6 +1397,15 @@ bool CWeaponMagazined::install_upgrade_impl(LPCSTR section, bool test)
}
result |= result2;

#ifdef NEW_SOUNDS //AVO: custom sounds go here
result2 = process_if_exists_set(section, "snd_reload_empty", &CInifile::r_string, str, test);
if (result2 && !test)
{
m_sounds.LoadSound(section, "snd_reload_empty", "sndReloadEmpty", true, m_eSoundReloadEmpty);
}
result |= result2;
#endif //-NEW_SOUNDS

// snd_shoot1 = weapons\ak74u_shot_1 ??
// snd_shoot2 = weapons\ak74u_shot_2 ??
// snd_shoot3 = weapons\ak74u_shot_3 ??
Expand Down
20 changes: 17 additions & 3 deletions src/xrGame/WeaponMagazined.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class CWeaponMagazined : public CWeapon
ESoundTypes m_eSoundShot;
ESoundTypes m_eSoundEmptyClick;
ESoundTypes m_eSoundReload;
#ifdef NEW_SOUNDS //AVO: new sounds go here
ESoundTypes m_eSoundReloadEmpty;
#endif //-NEW_SOUNDS

bool m_sounds_enabled;
// General
//кадр момента пересчета UpdateSounds
Expand Down Expand Up @@ -139,15 +143,22 @@ class CWeaponMagazined : public CWeapon
virtual void OnZoomOut();
void OnNextFireMode();
void OnPrevFireMode();
bool HasFireModes() { return m_bHasDifferentFireModes; };
virtual int GetCurrentFireMode() { return m_aFireModes[m_iCurFireMode]; };
bool HasFireModes() { return m_bHasDifferentFireModes; }

int GetCurrentFireMode() override
{
//AVO: fixed crash due to original GSC assumption that CWeaponMagazined will always have firemodes specified in configs.
if (HasFireModes())
return m_aFireModes[m_iCurFireMode];
return 1;
}

virtual void save(NET_Packet& output_packet);
virtual void load(IReader& input_packet);

protected:
virtual bool install_upgrade_impl(LPCSTR section, bool test);

protected:
virtual bool AllowFireWhileWorking() { return false; }
//виртуальные функции для проигрывания анимации HUD
virtual void PlayAnimShow();
Expand All @@ -163,4 +174,7 @@ class CWeaponMagazined : public CWeapon

virtual void FireBullet(const Fvector& pos, const Fvector& dir, float fire_disp, const CCartridge& cartridge,
u16 parent_id, u16 weapon_id, bool send_hit);

//AVO: for custom added sounds check if sound exists
bool WeaponSoundExist(pcstr section, pcstr sound_name);
};
Loading

0 comments on commit 47cba24

Please sign in to comment.