Skip to content

Commit afa17f0

Browse files
revolucasXottab-DUTY
authored andcommitted
+ added new exported game_object methods for weapons:
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)
1 parent 4ddecbb commit afa17f0

File tree

4 files changed

+100
-4
lines changed

4 files changed

+100
-4
lines changed

src/xrGame/Weapon.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,16 @@ class CWeapon : public CHudItemObject, public CShootingObject
127127
EWeaponSubStates GetReloadState() const { return (EWeaponSubStates)m_sub_state; }
128128
protected:
129129
bool m_bTriStateReload;
130-
u8 m_sub_state;
130+
131131
// a misfire happens, you'll need to rearm weapon
132132
bool bMisfire;
133133

134134
BOOL m_bAutoSpawnAmmo;
135135
virtual bool AllowBore();
136136

137137
public:
138+
u8 m_sub_state; // Alundaio: made public
139+
138140
bool IsGrenadeLauncherAttached() const;
139141
bool IsScopeAttached() const;
140142
bool IsSilencerAttached() const;
@@ -402,7 +404,6 @@ class CWeapon : public CHudItemObject, public CShootingObject
402404
CParticlesObject* m_pFlameParticles2;
403405

404406
protected:
405-
int GetAmmoCount_forType(shared_str const& ammo_type) const;
406407
int GetAmmoCount(u8 ammo_type) const;
407408

408409
public:
@@ -477,6 +478,13 @@ class CWeapon : public CHudItemObject, public CShootingObject
477478
virtual u32 ef_main_weapon_type() const;
478479
virtual u32 ef_weapon_type() const;
479480

481+
//Alundaio
482+
int GetAmmoCount_forType(shared_str const& ammo_type) const;
483+
virtual void set_ef_main_weapon_type(u32 type) { m_ef_main_weapon_type = type; };
484+
virtual void set_ef_weapon_type(u32 type) { m_ef_weapon_type = type; };
485+
virtual void SetAmmoType(u8 type) { m_ammoType = type; };
486+
//-Alundaio
487+
480488
protected:
481489
// This is because when scope is attached we can't ask scope for these params
482490
// therefore we should hold them by ourself :-((

src/xrGame/script_game_object.cpp

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,82 @@ void CScriptGameObject::SetAmmoElapsed(int ammo_elapsed)
340340
weapon->SetAmmoElapsed(ammo_elapsed);
341341
}
342342

343+
//Alundaio
344+
int CScriptGameObject::GetAmmoCount(u8 type)
345+
{
346+
CWeapon* weapon = smart_cast<CWeapon*>(&object());
347+
if (!weapon) return 0;
348+
349+
if (type < weapon->m_ammoTypes.size())
350+
return weapon->GetAmmoCount_forType(weapon->m_ammoTypes[type]);
351+
352+
return 0;
353+
}
354+
355+
void CScriptGameObject::SetAmmoType(u8 type)
356+
{
357+
CWeapon* weapon = smart_cast<CWeapon*>(&object());
358+
if (!weapon) return;
359+
360+
weapon->SetAmmoType(type);
361+
}
362+
363+
void CScriptGameObject::SetMainWeaponType(u32 type)
364+
{
365+
CWeapon* weapon = smart_cast<CWeapon*>(&object());
366+
if (!weapon) return;
367+
368+
weapon->set_ef_main_weapon_type(type);
369+
}
370+
371+
void CScriptGameObject::SetWeaponType(u32 type)
372+
{
373+
CWeapon* weapon = smart_cast<CWeapon*>(&object());
374+
if (!weapon) return;
375+
376+
weapon->set_ef_weapon_type(type);
377+
}
378+
379+
u32 CScriptGameObject::GetMainWeaponType()
380+
{
381+
CWeapon* weapon = smart_cast<CWeapon*>(&object());
382+
if (!weapon) return 0;
383+
384+
return weapon->ef_main_weapon_type();
385+
}
386+
387+
u32 CScriptGameObject::GetWeaponType()
388+
{
389+
CWeapon* weapon = smart_cast<CWeapon*>(&object());
390+
if (!weapon) return 0;
391+
392+
return weapon->ef_weapon_type();
393+
}
394+
395+
bool CScriptGameObject::HasAmmoType(u8 type)
396+
{
397+
CWeapon* weapon = smart_cast<CWeapon*>(&object());
398+
if (!weapon) return false;
399+
400+
return type < weapon->m_ammoTypes.size();
401+
}
402+
403+
u8 CScriptGameObject::GetWeaponSubstate()
404+
{
405+
CWeapon* weapon = smart_cast<CWeapon*>(&object());
406+
if (!weapon) return 0;
407+
408+
return weapon->m_sub_state;
409+
}
410+
411+
//-Alundaio
412+
343413
u32 CScriptGameObject::GetSuitableAmmoTotal() const
344414
{
345415
const CWeapon* weapon = smart_cast<const CWeapon*>(&object());
346416
if (!weapon)
347-
return (0);
348-
return (weapon->GetSuitableAmmoTotal(true));
417+
return 0;
418+
return weapon->GetSuitableAmmoTotal(true);
349419
}
350420

351421
//////////////////////////////////////////////////////////////////////////

src/xrGame/script_game_object.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,14 @@ class CScriptGameObject
835835
//Weapon
836836
void Weapon_AddonAttach(CScriptGameObject* item);
837837
void Weapon_AddonDetach(pcstr item_section);
838+
bool HasAmmoType(u8 type);
839+
int GetAmmoCount(u8 type);
840+
void SetAmmoType(u8 type);
841+
void SetMainWeaponType(u32 type);
842+
void SetWeaponType(u32 type);
843+
u32 GetMainWeaponType();
844+
u32 GetWeaponType();
845+
u8 GetWeaponSubstate();
838846

839847
//Weapon & Outfit
840848
bool InstallUpgrade(pcstr upgrade);

src/xrGame/script_game_object_script2.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ class_<CScriptGameObject>& script_register_game_object1(class_<CScriptGameObject
142142
.def("get_ammo_in_magazine", &CScriptGameObject::GetAmmoElapsed)
143143
.def("get_ammo_total", &CScriptGameObject::GetSuitableAmmoTotal)
144144
.def("set_ammo_elapsed", &CScriptGameObject::SetAmmoElapsed)
145+
//Alundaio
146+
.def("set_ammo_type", &CScriptGameObject::SetAmmoType)
147+
.def("get_ammo_count_for_type", &CScriptGameObject::GetAmmoCount)
148+
.def("get_main_weapon_type", &CScriptGameObject::GetMainWeaponType)
149+
.def("get_weapon_type", &CScriptGameObject::GetWeaponType)
150+
.def("set_main_weapon_type", &CScriptGameObject::SetMainWeaponType)
151+
.def("set_weapon_type", &CScriptGameObject::SetWeaponType)
152+
.def("has_ammo_type", &CScriptGameObject::HasAmmoType)
153+
.def("get_weapon_substate", &CScriptGameObject::GetWeaponSubstate)
154+
//-Alundaio
145155
.def("set_queue_size", &CScriptGameObject::SetQueueSize)
146156
// .def("best_hit", &CScriptGameObject::GetBestHit)
147157
// .def("best_sound", &CScriptGameObject::GetBestSound)

0 commit comments

Comments
 (0)