Skip to content

Commit

Permalink
Inventory fixes for SOC (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Dec 12, 2024
1 parent f319478 commit 068fc05
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
4 changes: 4 additions & 0 deletions res/gamedata/configs/openxray.ltx
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ allow_escape_sequences = false
; cop, cs, shoc or soc and unlock
; unlock is cop with disabled restrictions
game_mode = cop

; Always try to put item in the slot, SOC behaviour
; For the comparison, COP tries to do that only if item has default_to_ruck = false
default_to_slot = false
49 changes: 29 additions & 20 deletions src/xrGame/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int g_auto_ammo_unload = 0;

bool defaultSlotActiveness[] =
{
false, // no slot
true, // knife
true, // pistol
true, // automatic
Expand Down Expand Up @@ -176,33 +177,30 @@ void CInventory::Take(CGameObject* pObj, bool bNotActivate, bool strict_placemen

if (pIItem->CurrPlace() == eItemPlaceUndefined)
{
if (!pIItem->RuckDefault())
const bool slotFirst = pSettingsOpenXRay->read_if_exists<bool>("compatibility", "default_to_slot", ShadowOfChernobylMode);
const bool defaultToRuck = pIItem->RuckDefault();

if (slotFirst || !defaultToRuck)
{
if (CanPutInSlot(pIItem, pIItem->BaseSlot()))
{
result = Slot(pIItem->BaseSlot(), pIItem, bNotActivate, strict_placement);
VERIFY(result);
}
else if (CanPutInBelt(pIItem))
else if (!defaultToRuck && CanPutInBelt(pIItem))
{
result = Belt(pIItem, strict_placement);
VERIFY(result);
}
else
{
result = Ruck(pIItem, strict_placement);
VERIFY(result);
CWeaponMagazined* pWeapon = smart_cast<CWeaponMagazined*>(pIItem);
if (pWeapon && result && g_auto_ammo_unload)
{
pWeapon->UnloadMagazine();
}
}
}
else

if (!result)
{
result = Ruck(pIItem, strict_placement);
VERIFY(result);
CWeaponMagazined* pWeapon = smart_cast<CWeaponMagazined*>(pIItem);
if (pWeapon && result && !defaultToRuck && g_auto_ammo_unload)
{
pWeapon->UnloadMagazine();
}
}
}

Expand Down Expand Up @@ -607,10 +605,16 @@ void CInventory::Activate(u16 slot, bool bForce)
PIItem active_item = ActiveItem();
if (active_item && !bForce)
{
CHudItem* tempItem = active_item->cast_hud_item();
R_ASSERT2(tempItem, active_item->object().cNameSect().c_str());
if (CHudItem* tempItem = active_item->cast_hud_item())
tempItem->SendDeactivateItem();
else
{
#ifndef MASTER_GOLD
Msg("! Can't cast [%s] to CHudItem", active_item->object().cNameSect().c_str());
#endif
active_item->DeactivateItem();
}

tempItem->SendDeactivateItem();
#ifdef DEBUG
// Msg("--- Inventory owner [%s]: send deactivate item [%s]", m_pOwner->Name(), active_item->NameItem());
#endif // #ifdef DEBUG
Expand Down Expand Up @@ -801,7 +805,7 @@ void CInventory::Update()
{
CHudItem* hi = ActiveItem()->cast_hud_item();

if (!hi->IsHidden())
if (hi && !hi->IsHidden())
{
if (hi->GetState() == CHUDState::eIdle && hi->GetNextState() == CHUDState::eIdle)
hi->SendDeactivateItem();
Expand Down Expand Up @@ -833,8 +837,13 @@ void CInventory::Update()

m_iActiveSlot = GetNextActiveSlot();
}
if ((GetNextActiveSlot() != NO_ACTIVE_SLOT) && ActiveItem() && ActiveItem()->cast_hud_item()->IsHidden())
if (GetNextActiveSlot() != NO_ACTIVE_SLOT &&
ActiveItem() &&
ActiveItem()->cast_hud_item() &&
ActiveItem()->cast_hud_item()->IsHidden())
{
ActiveItem()->ActivateItem();
}
}
UpdateDropTasks();
}
Expand Down
7 changes: 5 additions & 2 deletions src/xrGame/inventory_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ void CInventoryItem::Load(LPCSTR section)
R_ASSERT(m_weight >= 0.f);

m_cost = pSettings->r_u32(section, "cost");
u32 sl = pSettings->read_if_exists<u32>(section, "slot", NO_ACTIVE_SLOT);
m_ItemCurrPlace.base_slot_id = (sl == u32(-1)) ? 0 : (sl + 1);

// Assets follow initial SOC system, where slots start from -1
u32 sl = pSettings->read_if_exists<u32>(section, "slot", NO_ACTIVE_SLOT - 1);
// Engine is following new system since COP: slots start from 0
m_ItemCurrPlace.base_slot_id = sl + 1;

// Description
if (pSettings->line_exist(section, DESCRIPTION_KEY))
Expand Down

0 comments on commit 068fc05

Please sign in to comment.