Skip to content

Commit

Permalink
+ exports for game_objects: set_weight, use, start_trade, start_upgrade
Browse files Browse the repository at this point in the history
- remove distance check when opening inventory boxes
  • Loading branch information
revolucas authored and Xottab-DUTY committed Dec 18, 2017
1 parent afa17f0 commit 8a423ed
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/xrGame/Weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ class CWeapon : public CHudItemObject, public CShootingObject
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; };
u8 GetAmmoType() { return m_ammoType; }
//-Alundaio

protected:
Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/inventory_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class CInventoryItem : public CAttachableItem,
virtual u32 Cost() const { return m_cost; }
// u32 Cost () const { return m_cost; }
virtual float Weight() const { return m_weight; }
void SetWeight(float w) { m_weight = w; }

public:
CInventory* m_pInventory;
shared_str m_section_id;
Expand Down
121 changes: 114 additions & 7 deletions src/xrGame/script_game_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
#include "damage_manager.h" //Alundaio: For set_visual
#include "ai/phantom/phantom.h"

#include "UIGameCustom.h"
#include "ui/UIActorMenu.h"
#include "InventoryBox.h"

class CScriptBinderObject;

//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -360,6 +364,14 @@ void CScriptGameObject::SetAmmoType(u8 type)
weapon->SetAmmoType(type);
}

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

return weapon->GetAmmoType();
}

void CScriptGameObject::SetMainWeaponType(u32 type)
{
CWeapon* weapon = smart_cast<CWeapon*>(&object());
Expand All @@ -379,15 +391,15 @@ void CScriptGameObject::SetWeaponType(u32 type)
u32 CScriptGameObject::GetMainWeaponType()
{
CWeapon* weapon = smart_cast<CWeapon*>(&object());
if (!weapon) return 0;
if (!weapon) return 255;

return weapon->ef_main_weapon_type();
}

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

return weapon->ef_weapon_type();
}
Expand All @@ -403,7 +415,7 @@ bool CScriptGameObject::HasAmmoType(u8 type)
u8 CScriptGameObject::GetWeaponSubstate()
{
CWeapon* weapon = smart_cast<CWeapon*>(&object());
if (!weapon) return 0;
if (!weapon) return 255;

return weapon->m_sub_state;
}
Expand Down Expand Up @@ -673,9 +685,104 @@ void CScriptGameObject::PhantomSetEnemy(CScriptGameObject* enemy)
if (!phant)
return;

IGameObject* obj = smart_cast<IGameObject*>(enemy);
if (!obj)
phant->SetEnemy(&enemy->object());
}

//Allows to force use an object if passed obj is the actor
bool CScriptGameObject::Use(CScriptGameObject* obj)
{
bool ret = object().use(&obj->object());

CActor* actor = smart_cast<CActor*>(&obj->object());
if (!actor)
return ret;

CInventoryOwner* pActorInv = smart_cast<CInventoryOwner*>(actor);
if (!pActorInv)
return ret;

CUIActorMenu& ActorMenu = CurrentGameUI()->GetActorMenu();

CInventoryBox* pBox = smart_cast<CInventoryBox*>(&object());
if (pBox)
{
ActorMenu.SetActor(pActorInv);
ActorMenu.SetInvBox(pBox);

ActorMenu.SetMenuMode(mmDeadBodySearch);
ActorMenu.ShowDialog(true);

return true;
}
else
{
CInventoryOwner* pOtherOwner = smart_cast<CInventoryOwner*>(&object());
if (!pOtherOwner)
return ret;

/*
CEntityAlive* e = smart_cast<CEntityAlive*>(pOtherOwner);
if (e && e->g_Alive())
{
actor->RunTalkDialog(pOtherOwner, false);
return true;
}
*/

ActorMenu.SetActor(pActorInv);
ActorMenu.SetPartner(pOtherOwner);

ActorMenu.SetMenuMode(mmDeadBodySearch);
ActorMenu.ShowDialog(true);

return true;
}

return false;
}

void CScriptGameObject::StartTrade(CScriptGameObject* obj)
{
CActor* actor = smart_cast<CActor*>(&obj->object());
if (!actor)
return;

phant->SetEnemy(obj);

CInventoryOwner* pActorInv = smart_cast<CInventoryOwner*>(actor);
if (!pActorInv)
return;

CInventoryOwner* pOtherOwner = smart_cast<CInventoryOwner*>(&object());
if (!pOtherOwner)
return;

CUIActorMenu& ActorMenu = CurrentGameUI()->GetActorMenu();

ActorMenu.SetActor(pActorInv);
ActorMenu.SetPartner(pOtherOwner);

ActorMenu.SetMenuMode(mmTrade);
ActorMenu.ShowDialog(true);
}

void CScriptGameObject::StartUpgrade(CScriptGameObject* obj)
{
CActor* actor = smart_cast<CActor*>(&obj->object());
if (!actor)
return;

CInventoryOwner* pActorInv = smart_cast<CInventoryOwner*>(actor);
if (!pActorInv)
return;

CInventoryOwner* pOtherOwner = smart_cast<CInventoryOwner*>(&object());
if (!pOtherOwner)
return;

CUIActorMenu& ActorMenu = CurrentGameUI()->GetActorMenu();

ActorMenu.SetActor(pActorInv);
ActorMenu.SetPartner(pOtherOwner);

ActorMenu.SetMenuMode(mmUpgrade);
ActorMenu.ShowDialog(true);
}
5 changes: 5 additions & 0 deletions src/xrGame/script_game_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,10 @@ class CScriptGameObject
//Alundaio
float GetLuminocityHemi();
float GetLuminocity();
bool Use(CScriptGameObject* obj);
void StartTrade(CScriptGameObject* obj);
void StartUpgrade(CScriptGameObject* obj);
void SetWeight(float w);

//Weapon
void Weapon_AddonAttach(CScriptGameObject* item);
Expand All @@ -843,6 +847,7 @@ class CScriptGameObject
u32 GetMainWeaponType();
u32 GetWeaponType();
u8 GetWeaponSubstate();
u8 GetAmmoType();

//Weapon & Outfit
bool InstallUpgrade(pcstr upgrade);
Expand Down
12 changes: 12 additions & 0 deletions src/xrGame/script_game_object_inventory_owner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,18 @@ float CScriptGameObject::Weight() const
return inventory_item->Weight();
}

void CScriptGameObject::SetWeight(float w)
{
CInventoryItem* inventory_item = smart_cast<CInventoryItem*>(&object());
if (!inventory_item)
{
ai().script_engine().script_log(LuaMessageType::Error,
"CSciptEntity : cannot access class member SetWeight!");
return;
}
inventory_item->SetWeight(w);
}

float CScriptGameObject::GetActorJumpSpeed() const
{
CActor* pActor = smart_cast<CActor*>(&object());
Expand Down
5 changes: 5 additions & 0 deletions src/xrGame/script_game_object_script2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ class_<CScriptGameObject>& script_register_game_object1(class_<CScriptGameObject
.def("get_ammo_total", &CScriptGameObject::GetSuitableAmmoTotal)
.def("set_ammo_elapsed", &CScriptGameObject::SetAmmoElapsed)
//Alundaio
.def("use", &CScriptGameObject::Use)
.def("start_trade", &CScriptGameObject::StartTrade)
.def("start_upgrade", &CScriptGameObject::StartUpgrade)
.def("get_ammo_type", &CScriptGameObject::GetAmmoType)
.def("set_ammo_type", &CScriptGameObject::SetAmmoType)
.def("get_ammo_count_for_type", &CScriptGameObject::GetAmmoCount)
.def("get_main_weapon_type", &CScriptGameObject::GetMainWeaponType)
Expand All @@ -151,6 +155,7 @@ class_<CScriptGameObject>& script_register_game_object1(class_<CScriptGameObject
.def("set_weapon_type", &CScriptGameObject::SetWeaponType)
.def("has_ammo_type", &CScriptGameObject::HasAmmoType)
.def("get_weapon_substate", &CScriptGameObject::GetWeaponSubstate)
.def("set_weight", &CScriptGameObject::SetWeight)
//-Alundaio
.def("set_queue_size", &CScriptGameObject::SetQueueSize)
// .def("best_hit", &CScriptGameObject::GetBestHit)
Expand Down
3 changes: 2 additions & 1 deletion src/xrGame/ui/UIActorMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ void CUIActorMenu::Update()
}
case mmDeadBodySearch:
{
CheckDistance();
// Alundaio: remove distance check when opening inventory boxes
//CheckDistance();
break;
}
default: R_ASSERT(0); break;
Expand Down

0 comments on commit 8a423ed

Please sign in to comment.