Skip to content

Commit

Permalink
Restored monsters inventory (#382, #392)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Oct 18, 2021
1 parent 1cf3c37 commit 3dc9f5a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/xrGame/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ void CActor::shedule_Update(u32 DT)
CGameObject* game_object = smart_cast<CGameObject*>(RQ.O);
m_pUsableObject = game_object;
m_pInvBoxWeLookingAt = smart_cast<CInventoryBox*>(game_object);
m_pPersonWeLookingAt = smart_cast<CInventoryOwner*>(game_object);
m_pPersonWeLookingAt = game_object->cast_inventory_owner();
m_pVehicleWeLookingAt = smart_cast<CHolderCustom*>(game_object);
CEntityAlive* pEntityAlive = smart_cast<CEntityAlive*>(game_object);

Expand Down
37 changes: 37 additions & 0 deletions src/xrGame/ai/monsters/basemonster/base_monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ IFactoryObject* CBaseMonster::_construct()

inherited::_construct();
CStepManager::_construct();
CInventoryOwner::_construct();
return (this);
}

Expand Down Expand Up @@ -871,10 +872,46 @@ bool CBaseMonster::check_start_conditions(ControlCom::EControlType type)
void CBaseMonster::OnEvent(NET_Packet& P, u16 type)
{
inherited::OnEvent(P, type);
CInventoryOwner::OnEvent(P, type);

u16 id;
switch (type)
{
case GE_TRADE_BUY:
case GE_OWNERSHIP_TAKE:
{
P.r_u16(id);
IGameObject* O = Level().Objects.net_Find(id);
VERIFY(O);

CGameObject* GO = smart_cast<CGameObject*>(O);
CInventoryItem* pIItem = smart_cast<CInventoryItem*>(GO);
VERIFY(inventory().CanTakeItem(pIItem));
pIItem->m_ItemCurrPlace.type = eItemPlaceRuck;

O->H_SetParent(this);
inventory().Take(GO, true, true);
break;
}
case GE_TRADE_SELL:
case GE_OWNERSHIP_REJECT:
{
P.r_u16(id);
IGameObject* O = Level().Objects.net_Find(id);
VERIFY(O);

const bool just_before_destroy = !P.r_eof() && P.r_u8();
const bool dont_create_shell = (type == GE_TRADE_SELL) || just_before_destroy;

O->SetTmpPreDestroy(just_before_destroy);
if (inventory().DropItem(smart_cast<CGameObject*>(O), just_before_destroy, dont_create_shell) &&
!O->getDestroy())
{
feel_touch_deny(O, 2000);
}
break;
}

case GE_KILL_SOMEONE:
P.r_u16(id);
IGameObject* O = Level().Objects.net_Find(id);
Expand Down
7 changes: 6 additions & 1 deletion src/xrGame/ai/monsters/basemonster/base_monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class text_tree;

class anti_aim_ability;

class CBaseMonster : public CCustomMonster, public CStepManager
class CBaseMonster : public CCustomMonster, public CStepManager, public CInventoryOwner
{
protected:
using inherited = CCustomMonster;
Expand All @@ -73,8 +73,10 @@ class CBaseMonster : public CCustomMonster, public CStepManager
virtual CScriptEntity* cast_script_entity() { return this; }
virtual CBaseMonster* cast_base_monster() { return this; }
virtual CGameObject* cast_game_object() { return this; }
virtual CInventoryOwner* cast_inventory_owner() override { return CallOfPripyatMode ? nullptr : this; }

public:
virtual void renderable_Render(IRenderable* root) override { return inherited::renderable_Render(root); }
virtual bool renderable_ShadowReceive() { return TRUE; }
virtual void Die(IGameObject* who);
virtual void HitSignal(float amount, Fvector& vLocalDir, IGameObject* who, s16 element);
Expand Down Expand Up @@ -141,8 +143,11 @@ class CBaseMonster : public CCustomMonster, public CStepManager

virtual void HitEntityInJump(const CEntity* pEntity) {}
virtual void on_before_sell(CInventoryItem* item);
virtual bool unlimited_ammo() override { return false; }

float GetSatiety() { return 0.5f; }
void ChangeSatiety(float v) {}

// ---------------------------------------------------------------------------------
// Process scripts
// ---------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions src/xrGame/ai/monsters/basemonster/base_monster_startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ void CBaseMonster::reload(LPCSTR section)
if (!CCustomMonster::use_simplified_visual())
CStepManager::reload(section);

CInventoryOwner::reload(section);
movement().reload(section);

// load base sounds
Expand Down Expand Up @@ -262,6 +263,7 @@ void CBaseMonster::reload(LPCSTR section)
void CBaseMonster::reinit()
{
inherited::reinit();
CInventoryOwner::reinit();

EnemyMemory.clear();
SoundMemory.clear();
Expand Down Expand Up @@ -330,6 +332,10 @@ bool CBaseMonster::net_Spawn(CSE_Abstract* DC)
"There is no AI-Map, level graph, cross table, or graph is not compiled into the game graph!");
monster_squad().register_member((u8)g_Team(), (u8)g_Squad(), (u8)g_Group(), this);
settings_overrides();

CHARACTER_COMMUNITY community;
community.set("monster");
CInventoryOwner::SetCommunity(community.index());

if (GetScriptControl())
{
Expand Down Expand Up @@ -384,6 +390,7 @@ void CBaseMonster::net_Destroy()
StateMan->critical_finalize();

inherited::net_Destroy();
CInventoryOwner::net_Destroy();

m_pPhysics_support->in_NetDestroy();

Expand Down
6 changes: 3 additions & 3 deletions src/xrGame/ui/UIActorMenuTrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,12 @@ void CUIActorMenu::UpdateActor()

void CUIActorMenu::UpdatePartnerBag()
{
/*CBaseMonster* monster = smart_cast<CBaseMonster*>(m_pPartnerInvOwner);
CBaseMonster* monster = smart_cast<CBaseMonster*>(m_pPartnerInvOwner);
if (monster || m_pPartnerInvOwner->use_simplified_visual())
{
m_PartnerWeight->SetText("");
m_PartnerMoney->SetText("");
}
else*/ if (m_pPartnerInvOwner->InfinitiveMoney())
else if (m_pPartnerInvOwner->InfinitiveMoney())
{
m_PartnerMoney->SetText("--- RU");
}
Expand Down

0 comments on commit 3dc9f5a

Please sign in to comment.