Skip to content

Commit 8a423ed

Browse files
revolucasXottab-DUTY
authored andcommitted
+ exports for game_objects: set_weight, use, start_trade, start_upgrade
- remove distance check when opening inventory boxes
1 parent afa17f0 commit 8a423ed

File tree

7 files changed

+141
-8
lines changed

7 files changed

+141
-8
lines changed

src/xrGame/Weapon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ class CWeapon : public CHudItemObject, public CShootingObject
483483
virtual void set_ef_main_weapon_type(u32 type) { m_ef_main_weapon_type = type; };
484484
virtual void set_ef_weapon_type(u32 type) { m_ef_weapon_type = type; };
485485
virtual void SetAmmoType(u8 type) { m_ammoType = type; };
486+
u8 GetAmmoType() { return m_ammoType; }
486487
//-Alundaio
487488

488489
protected:

src/xrGame/inventory_item.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ class CInventoryItem : public CAttachableItem,
141141
virtual u32 Cost() const { return m_cost; }
142142
// u32 Cost () const { return m_cost; }
143143
virtual float Weight() const { return m_weight; }
144+
void SetWeight(float w) { m_weight = w; }
145+
144146
public:
145147
CInventory* m_pInventory;
146148
shared_str m_section_id;

src/xrGame/script_game_object.cpp

Lines changed: 114 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
#include "damage_manager.h" //Alundaio: For set_visual
4444
#include "ai/phantom/phantom.h"
4545

46+
#include "UIGameCustom.h"
47+
#include "ui/UIActorMenu.h"
48+
#include "InventoryBox.h"
49+
4650
class CScriptBinderObject;
4751

4852
//////////////////////////////////////////////////////////////////////////
@@ -360,6 +364,14 @@ void CScriptGameObject::SetAmmoType(u8 type)
360364
weapon->SetAmmoType(type);
361365
}
362366

367+
u8 CScriptGameObject::GetAmmoType()
368+
{
369+
CWeapon* weapon = smart_cast<CWeapon*>(&object());
370+
if (!weapon) return 255;
371+
372+
return weapon->GetAmmoType();
373+
}
374+
363375
void CScriptGameObject::SetMainWeaponType(u32 type)
364376
{
365377
CWeapon* weapon = smart_cast<CWeapon*>(&object());
@@ -379,15 +391,15 @@ void CScriptGameObject::SetWeaponType(u32 type)
379391
u32 CScriptGameObject::GetMainWeaponType()
380392
{
381393
CWeapon* weapon = smart_cast<CWeapon*>(&object());
382-
if (!weapon) return 0;
394+
if (!weapon) return 255;
383395

384396
return weapon->ef_main_weapon_type();
385397
}
386398

387399
u32 CScriptGameObject::GetWeaponType()
388400
{
389401
CWeapon* weapon = smart_cast<CWeapon*>(&object());
390-
if (!weapon) return 0;
402+
if (!weapon) return 255;
391403

392404
return weapon->ef_weapon_type();
393405
}
@@ -403,7 +415,7 @@ bool CScriptGameObject::HasAmmoType(u8 type)
403415
u8 CScriptGameObject::GetWeaponSubstate()
404416
{
405417
CWeapon* weapon = smart_cast<CWeapon*>(&object());
406-
if (!weapon) return 0;
418+
if (!weapon) return 255;
407419

408420
return weapon->m_sub_state;
409421
}
@@ -673,9 +685,104 @@ void CScriptGameObject::PhantomSetEnemy(CScriptGameObject* enemy)
673685
if (!phant)
674686
return;
675687

676-
IGameObject* obj = smart_cast<IGameObject*>(enemy);
677-
if (!obj)
688+
phant->SetEnemy(&enemy->object());
689+
}
690+
691+
//Allows to force use an object if passed obj is the actor
692+
bool CScriptGameObject::Use(CScriptGameObject* obj)
693+
{
694+
bool ret = object().use(&obj->object());
695+
696+
CActor* actor = smart_cast<CActor*>(&obj->object());
697+
if (!actor)
698+
return ret;
699+
700+
CInventoryOwner* pActorInv = smart_cast<CInventoryOwner*>(actor);
701+
if (!pActorInv)
702+
return ret;
703+
704+
CUIActorMenu& ActorMenu = CurrentGameUI()->GetActorMenu();
705+
706+
CInventoryBox* pBox = smart_cast<CInventoryBox*>(&object());
707+
if (pBox)
708+
{
709+
ActorMenu.SetActor(pActorInv);
710+
ActorMenu.SetInvBox(pBox);
711+
712+
ActorMenu.SetMenuMode(mmDeadBodySearch);
713+
ActorMenu.ShowDialog(true);
714+
715+
return true;
716+
}
717+
else
718+
{
719+
CInventoryOwner* pOtherOwner = smart_cast<CInventoryOwner*>(&object());
720+
if (!pOtherOwner)
721+
return ret;
722+
723+
/*
724+
CEntityAlive* e = smart_cast<CEntityAlive*>(pOtherOwner);
725+
if (e && e->g_Alive())
726+
{
727+
actor->RunTalkDialog(pOtherOwner, false);
728+
return true;
729+
}
730+
*/
731+
732+
ActorMenu.SetActor(pActorInv);
733+
ActorMenu.SetPartner(pOtherOwner);
734+
735+
ActorMenu.SetMenuMode(mmDeadBodySearch);
736+
ActorMenu.ShowDialog(true);
737+
738+
return true;
739+
}
740+
741+
return false;
742+
}
743+
744+
void CScriptGameObject::StartTrade(CScriptGameObject* obj)
745+
{
746+
CActor* actor = smart_cast<CActor*>(&obj->object());
747+
if (!actor)
678748
return;
679-
680-
phant->SetEnemy(obj);
749+
750+
CInventoryOwner* pActorInv = smart_cast<CInventoryOwner*>(actor);
751+
if (!pActorInv)
752+
return;
753+
754+
CInventoryOwner* pOtherOwner = smart_cast<CInventoryOwner*>(&object());
755+
if (!pOtherOwner)
756+
return;
757+
758+
CUIActorMenu& ActorMenu = CurrentGameUI()->GetActorMenu();
759+
760+
ActorMenu.SetActor(pActorInv);
761+
ActorMenu.SetPartner(pOtherOwner);
762+
763+
ActorMenu.SetMenuMode(mmTrade);
764+
ActorMenu.ShowDialog(true);
765+
}
766+
767+
void CScriptGameObject::StartUpgrade(CScriptGameObject* obj)
768+
{
769+
CActor* actor = smart_cast<CActor*>(&obj->object());
770+
if (!actor)
771+
return;
772+
773+
CInventoryOwner* pActorInv = smart_cast<CInventoryOwner*>(actor);
774+
if (!pActorInv)
775+
return;
776+
777+
CInventoryOwner* pOtherOwner = smart_cast<CInventoryOwner*>(&object());
778+
if (!pOtherOwner)
779+
return;
780+
781+
CUIActorMenu& ActorMenu = CurrentGameUI()->GetActorMenu();
782+
783+
ActorMenu.SetActor(pActorInv);
784+
ActorMenu.SetPartner(pOtherOwner);
785+
786+
ActorMenu.SetMenuMode(mmUpgrade);
787+
ActorMenu.ShowDialog(true);
681788
}

src/xrGame/script_game_object.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,10 @@ class CScriptGameObject
831831
//Alundaio
832832
float GetLuminocityHemi();
833833
float GetLuminocity();
834+
bool Use(CScriptGameObject* obj);
835+
void StartTrade(CScriptGameObject* obj);
836+
void StartUpgrade(CScriptGameObject* obj);
837+
void SetWeight(float w);
834838

835839
//Weapon
836840
void Weapon_AddonAttach(CScriptGameObject* item);
@@ -843,6 +847,7 @@ class CScriptGameObject
843847
u32 GetMainWeaponType();
844848
u32 GetWeaponType();
845849
u8 GetWeaponSubstate();
850+
u8 GetAmmoType();
846851

847852
//Weapon & Outfit
848853
bool InstallUpgrade(pcstr upgrade);

src/xrGame/script_game_object_inventory_owner.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,18 @@ float CScriptGameObject::Weight() const
19611961
return inventory_item->Weight();
19621962
}
19631963

1964+
void CScriptGameObject::SetWeight(float w)
1965+
{
1966+
CInventoryItem* inventory_item = smart_cast<CInventoryItem*>(&object());
1967+
if (!inventory_item)
1968+
{
1969+
ai().script_engine().script_log(LuaMessageType::Error,
1970+
"CSciptEntity : cannot access class member SetWeight!");
1971+
return;
1972+
}
1973+
inventory_item->SetWeight(w);
1974+
}
1975+
19641976
float CScriptGameObject::GetActorJumpSpeed() const
19651977
{
19661978
CActor* pActor = smart_cast<CActor*>(&object());

src/xrGame/script_game_object_script2.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ class_<CScriptGameObject>& script_register_game_object1(class_<CScriptGameObject
143143
.def("get_ammo_total", &CScriptGameObject::GetSuitableAmmoTotal)
144144
.def("set_ammo_elapsed", &CScriptGameObject::SetAmmoElapsed)
145145
//Alundaio
146+
.def("use", &CScriptGameObject::Use)
147+
.def("start_trade", &CScriptGameObject::StartTrade)
148+
.def("start_upgrade", &CScriptGameObject::StartUpgrade)
149+
.def("get_ammo_type", &CScriptGameObject::GetAmmoType)
146150
.def("set_ammo_type", &CScriptGameObject::SetAmmoType)
147151
.def("get_ammo_count_for_type", &CScriptGameObject::GetAmmoCount)
148152
.def("get_main_weapon_type", &CScriptGameObject::GetMainWeaponType)
@@ -151,6 +155,7 @@ class_<CScriptGameObject>& script_register_game_object1(class_<CScriptGameObject
151155
.def("set_weapon_type", &CScriptGameObject::SetWeaponType)
152156
.def("has_ammo_type", &CScriptGameObject::HasAmmoType)
153157
.def("get_weapon_substate", &CScriptGameObject::GetWeaponSubstate)
158+
.def("set_weight", &CScriptGameObject::SetWeight)
154159
//-Alundaio
155160
.def("set_queue_size", &CScriptGameObject::SetQueueSize)
156161
// .def("best_hit", &CScriptGameObject::GetBestHit)

src/xrGame/ui/UIActorMenu.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ void CUIActorMenu::Update()
211211
}
212212
case mmDeadBodySearch:
213213
{
214-
CheckDistance();
214+
// Alundaio: remove distance check when opening inventory boxes
215+
//CheckDistance();
215216
break;
216217
}
217218
default: R_ASSERT(0); break;

0 commit comments

Comments
 (0)