Skip to content

Commit

Permalink
+ added new exported game_object methods for weapons:
Browse files Browse the repository at this point in the history
set_ammo_type(u8 ammo_type)
get_ammo_count_for_type(u8 ammo_type)
has_ammo_type(u8 ammo_type)
get_weapon_substate()
get_main_weapon_type()  -- deals with ef_main_weapon_type
set_main_weapon_type(u16 type)
get_weapon_type() -- deals with ef_weapon_type
set_weapon_type(u16 type)
  • Loading branch information
revolucas authored and Xottab-DUTY committed Dec 18, 2017
1 parent 4ddecbb commit afa17f0
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/xrGame/Weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,16 @@ class CWeapon : public CHudItemObject, public CShootingObject
EWeaponSubStates GetReloadState() const { return (EWeaponSubStates)m_sub_state; }
protected:
bool m_bTriStateReload;
u8 m_sub_state;

// a misfire happens, you'll need to rearm weapon
bool bMisfire;

BOOL m_bAutoSpawnAmmo;
virtual bool AllowBore();

public:
u8 m_sub_state; // Alundaio: made public

bool IsGrenadeLauncherAttached() const;
bool IsScopeAttached() const;
bool IsSilencerAttached() const;
Expand Down Expand Up @@ -402,7 +404,6 @@ class CWeapon : public CHudItemObject, public CShootingObject
CParticlesObject* m_pFlameParticles2;

protected:
int GetAmmoCount_forType(shared_str const& ammo_type) const;
int GetAmmoCount(u8 ammo_type) const;

public:
Expand Down Expand Up @@ -477,6 +478,13 @@ class CWeapon : public CHudItemObject, public CShootingObject
virtual u32 ef_main_weapon_type() const;
virtual u32 ef_weapon_type() const;

//Alundaio
int GetAmmoCount_forType(shared_str const& ammo_type) const;
virtual void set_ef_main_weapon_type(u32 type) { m_ef_main_weapon_type = type; };
virtual void set_ef_weapon_type(u32 type) { m_ef_weapon_type = type; };
virtual void SetAmmoType(u8 type) { m_ammoType = type; };
//-Alundaio

protected:
// This is because when scope is attached we can't ask scope for these params
// therefore we should hold them by ourself :-((
Expand Down
74 changes: 72 additions & 2 deletions src/xrGame/script_game_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,82 @@ void CScriptGameObject::SetAmmoElapsed(int ammo_elapsed)
weapon->SetAmmoElapsed(ammo_elapsed);
}

//Alundaio
int CScriptGameObject::GetAmmoCount(u8 type)
{
CWeapon* weapon = smart_cast<CWeapon*>(&object());
if (!weapon) return 0;

if (type < weapon->m_ammoTypes.size())
return weapon->GetAmmoCount_forType(weapon->m_ammoTypes[type]);

return 0;
}

void CScriptGameObject::SetAmmoType(u8 type)
{
CWeapon* weapon = smart_cast<CWeapon*>(&object());
if (!weapon) return;

weapon->SetAmmoType(type);
}

void CScriptGameObject::SetMainWeaponType(u32 type)
{
CWeapon* weapon = smart_cast<CWeapon*>(&object());
if (!weapon) return;

weapon->set_ef_main_weapon_type(type);
}

void CScriptGameObject::SetWeaponType(u32 type)
{
CWeapon* weapon = smart_cast<CWeapon*>(&object());
if (!weapon) return;

weapon->set_ef_weapon_type(type);
}

u32 CScriptGameObject::GetMainWeaponType()
{
CWeapon* weapon = smart_cast<CWeapon*>(&object());
if (!weapon) return 0;

return weapon->ef_main_weapon_type();
}

u32 CScriptGameObject::GetWeaponType()
{
CWeapon* weapon = smart_cast<CWeapon*>(&object());
if (!weapon) return 0;

return weapon->ef_weapon_type();
}

bool CScriptGameObject::HasAmmoType(u8 type)
{
CWeapon* weapon = smart_cast<CWeapon*>(&object());
if (!weapon) return false;

return type < weapon->m_ammoTypes.size();
}

u8 CScriptGameObject::GetWeaponSubstate()
{
CWeapon* weapon = smart_cast<CWeapon*>(&object());
if (!weapon) return 0;

return weapon->m_sub_state;
}

//-Alundaio

u32 CScriptGameObject::GetSuitableAmmoTotal() const
{
const CWeapon* weapon = smart_cast<const CWeapon*>(&object());
if (!weapon)
return (0);
return (weapon->GetSuitableAmmoTotal(true));
return 0;
return weapon->GetSuitableAmmoTotal(true);
}

//////////////////////////////////////////////////////////////////////////
Expand Down
8 changes: 8 additions & 0 deletions src/xrGame/script_game_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,14 @@ class CScriptGameObject
//Weapon
void Weapon_AddonAttach(CScriptGameObject* item);
void Weapon_AddonDetach(pcstr item_section);
bool HasAmmoType(u8 type);
int GetAmmoCount(u8 type);
void SetAmmoType(u8 type);
void SetMainWeaponType(u32 type);
void SetWeaponType(u32 type);
u32 GetMainWeaponType();
u32 GetWeaponType();
u8 GetWeaponSubstate();

//Weapon & Outfit
bool InstallUpgrade(pcstr upgrade);
Expand Down
10 changes: 10 additions & 0 deletions src/xrGame/script_game_object_script2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ class_<CScriptGameObject>& script_register_game_object1(class_<CScriptGameObject
.def("get_ammo_in_magazine", &CScriptGameObject::GetAmmoElapsed)
.def("get_ammo_total", &CScriptGameObject::GetSuitableAmmoTotal)
.def("set_ammo_elapsed", &CScriptGameObject::SetAmmoElapsed)
//Alundaio
.def("set_ammo_type", &CScriptGameObject::SetAmmoType)
.def("get_ammo_count_for_type", &CScriptGameObject::GetAmmoCount)
.def("get_main_weapon_type", &CScriptGameObject::GetMainWeaponType)
.def("get_weapon_type", &CScriptGameObject::GetWeaponType)
.def("set_main_weapon_type", &CScriptGameObject::SetMainWeaponType)
.def("set_weapon_type", &CScriptGameObject::SetWeaponType)
.def("has_ammo_type", &CScriptGameObject::HasAmmoType)
.def("get_weapon_substate", &CScriptGameObject::GetWeaponSubstate)
//-Alundaio
.def("set_queue_size", &CScriptGameObject::SetQueueSize)
// .def("best_hit", &CScriptGameObject::GetBestHit)
// .def("best_sound", &CScriptGameObject::GetBestSound)
Expand Down

0 comments on commit afa17f0

Please sign in to comment.