Skip to content

Commit

Permalink
+ AxelDominator weight calculations for CEatableItem weight
Browse files Browse the repository at this point in the history
~ uncommented artefact immunities code to be displayed in tooltip
~ uncommented outfit immunities code to be displayed in tooltip
+ added new lua exported methods, for game_object class:
u8 get_remaining_uses()
void set_remaining_uses(u8)
u8 get_max_uses()
= potential fix for crash when placing item with 0 remaining uses into a container
~ global lua exported method UpdateActorMenu() now updates current item cell
+ added global lua exported method,
game_object CurrentItemAtCell() (**not working apparently)
  • Loading branch information
revolucas authored and Xottab-DUTY committed Dec 16, 2017
1 parent 9c726bd commit 7840b0f
Show file tree
Hide file tree
Showing 16 changed files with 283 additions and 111 deletions.
16 changes: 11 additions & 5 deletions src/xrGame/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,8 +1070,17 @@ bool CInventory::Eat(PIItem pIItem)
pItemToEat->object().cNameSect().c_str());
#endif // MP_LOGGING

if (IsGameTypeSingle() && Actor()->m_inventory == this)
Actor()->callback(GameObject::eUseObject)((smart_cast<CGameObject*>(pIItem))->lua_game_object());
if (Actor()->m_inventory == this)
{
if (IsGameTypeSingle())
Actor()->callback(GameObject::eUseObject)(smart_cast<CGameObject*>(pIItem)->lua_game_object());

if (pItemToEat->IsUsingCondition() && pItemToEat->GetRemainingUses() < 1 && pItemToEat->CanDelete())
CurrentGameUI()->GetActorMenu().RefreshCurrentItemCell();

CurrentGameUI()->GetActorMenu().SetCurrentItem(nullptr);
}


if (pItemToEat->Empty())
{
Expand All @@ -1081,9 +1090,6 @@ bool CInventory::Eat(PIItem pIItem)
pIItem->SetDropManual(true);
}

if (pItemToEat->IsUsingCondition() && Actor()->m_inventory == this)
CurrentGameUI()->GetActorMenu().RefreshConsumableCells();

return true;
}

Expand Down
24 changes: 24 additions & 0 deletions src/xrGame/UIGameCustom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

#include "xrEngine/x_ray.h"

#include "ui\UICellItem.h" //Alundaio
//#include "script_game_object.h" //Alundaio

EGameIDs ParseStringToGameType(const char* str);

struct predicate_find_stat
Expand Down Expand Up @@ -177,7 +180,28 @@ void CUIGameCustom::HideActorMenu()
void CUIGameCustom::UpdateActorMenu()
{
if (ActorMenu->IsShown())
{
ActorMenu->UpdateActor();
ActorMenu->RefreshCurrentItemCell();
}
}

CScriptGameObject* CUIGameCustom::CurrentItemAtCell()
{
CUICellItem* itm = ActorMenu->CurrentItem();
if (!itm->m_pData)
return nullptr;

PIItem IItm = static_cast<PIItem>(itm->m_pData);
if (!IItm)
return nullptr;

CGameObject* GO = IItm->cast_game_object();

if (GO)
return GO->lua_game_object();

return nullptr;
}
//-Alundaio

Expand Down
3 changes: 3 additions & 0 deletions src/xrGame/UIGameCustom.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "gametype_chooser.h"
#include "UIDialogHolder.h"
#include "xrEngine/CustomHUD.h"
#include "script_game_object.h"

// refs
class CUI;
class CTeamBaseZone;
Expand Down Expand Up @@ -101,6 +103,7 @@ class CUIGameCustom : public FactoryObjectBase, public CDialogHolder
bool ShowActorMenu();
void HideActorMenu();
void UpdateActorMenu(); //Alundaio
CScriptGameObject* CurrentItemAtCell(); //Alundaio
bool ShowPdaMenu();
void HidePdaMenu();
void ShowMessagesWindow();
Expand Down
5 changes: 4 additions & 1 deletion src/xrGame/UIGameCustom_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ SCRIPT_EXPORT(CUIGameCustom, (), {
.def("AddCustomStatic", &CUIGameCustom::AddCustomStatic)
.def("RemoveCustomStatic", &CUIGameCustom::RemoveCustomStatic)
.def("HideActorMenu", &CUIGameCustom::HideActorMenu)
.def("UpdateActorMenu", &CUIGameCustom::UpdateActorMenu) //Alundaio
//Alundaio
.def("UpdateActorMenu", &CUIGameCustom::UpdateActorMenu)
.def("CurrentItemAtCell", &CUIGameCustom::CurrentItemAtCell)
//-Alundaio
.def("HidePdaMenu", &CUIGameCustom::HidePdaMenu)
.def("show_messages", &CUIGameCustom::ShowMessagesWindow)
.def("hide_messages", &CUIGameCustom::HideMessagesWindow)
Expand Down
59 changes: 49 additions & 10 deletions src/xrGame/eatable_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,32 @@ void CEatableItem::Load(LPCSTR section)
{
inherited::Load(section);

m_iRemainingUses = m_iMaxUses = READ_IF_EXISTS(pSettings, r_u16, section, "max_uses", 1);
m_iRemainingUses = m_iMaxUses = READ_IF_EXISTS(pSettings, r_u8, section, "max_uses", 1);
m_bRemoveAfterUse = READ_IF_EXISTS(pSettings, r_bool, section, "remove_after_use", true);
m_fWeightFull = m_weight;
m_fWeightEmpty = READ_IF_EXISTS(pSettings, r_float, section, "empty_weight", 0.0f);

if (IsUsingCondition())
SetCondition((float)m_iRemainingUses / (float)m_iMaxUses );
{
if (m_iMaxUses > 0)
SetCondition(static_cast<float>(m_iRemainingUses / m_iMaxUses));
else
SetCondition(0.f);
}
}

void CEatableItem::load(IReader& packet)
{
inherited::load(packet);

m_iRemainingUses = packet.r_u16();
m_iRemainingUses = packet.r_u8();
}

void CEatableItem::save(NET_Packet& packet)
{
inherited::save(packet);

packet.w_u16(m_iRemainingUses);
packet.w_u8(m_iRemainingUses);
}

BOOL CEatableItem::net_Spawn(CSE_Abstract* DC)
Expand All @@ -63,7 +70,12 @@ BOOL CEatableItem::net_Spawn(CSE_Abstract* DC)
return FALSE;

if (IsUsingCondition())
SetCondition((float)m_iRemainingUses / (float)m_iMaxUses);
{
if (m_iMaxUses > 0)
SetCondition(static_cast<float>(m_iRemainingUses / m_iMaxUses));
else
SetCondition(0);
}

return TRUE;
};
Expand All @@ -74,8 +86,10 @@ bool CEatableItem::Useful() const
return false;

//проверить не все ли еще съедено
/*Alundaio: Commented out to prevent crash when placing items with 0 remaining uses inside inventory boxes
if (m_iRemainingUses == 0)
return false;
*/

return true;
}
Expand Down Expand Up @@ -132,12 +146,37 @@ bool CEatableItem::UseBy(CEntityAlive* entity_alive)
Level().Send(tmp_packet);
}

if (m_iRemainingUses > 0)
--m_iRemainingUses;
else
m_iRemainingUses = 0;
// If uses 255, then skip the decrement for infinite usages
if (m_iRemainingUses != -1)
{
if (m_iRemainingUses > 0)
--m_iRemainingUses;
else
m_iRemainingUses = 0;
}

SetCondition((float)m_iRemainingUses / (float)m_iMaxUses);
if (IsUsingCondition())
{
if (m_iMaxUses > 0)
SetCondition(static_cast<float>(m_iRemainingUses / m_iMaxUses));
else
SetCondition(0.f);
}

return true;
}

float CEatableItem::Weight() const
{
float res = inherited::Weight();

if (IsUsingCondition())
{
const float net_weight = m_fWeightFull - m_fWeightEmpty;
const float use_weight = m_iMaxUses > 0 ? net_weight / m_iMaxUses : 0.f;

res = m_fWeightEmpty + m_iRemainingUses * use_weight;
}

return res;
}
12 changes: 8 additions & 4 deletions src/xrGame/eatable_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ class CEatableItem : public CInventoryItem
protected:
CPhysicItem* m_physic_item;

u16 m_iMaxUses;
u16 m_iRemainingUses;
u8 m_iMaxUses;
u8 m_iRemainingUses;
bool m_bRemoveAfterUse;
float m_fWeightFull;
float m_fWeightEmpty;

public:
CEatableItem();
Expand All @@ -34,6 +36,8 @@ class CEatableItem : public CInventoryItem
virtual bool UseBy(CEntityAlive* npc);
virtual bool Empty() const { return m_iRemainingUses == 0; }
bool CanDelete() const { return m_bRemoveAfterUse == true; }
virtual u16 GetMaxUses() const { return m_iMaxUses; }
virtual u16 GetRemainingUses() const { return m_iRemainingUses; }
virtual u8 GetMaxUses() const { return m_iMaxUses; }
virtual u8 GetRemainingUses() const { return m_iRemainingUses; }
void SetRemainingUses(u8 value) { if (value <= m_iMaxUses && value >= 0) m_iRemainingUses = value; };
float Weight() const override;
};
5 changes: 5 additions & 0 deletions src/xrGame/script_game_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,11 @@ class CScriptGameObject
void SetArtefactSatietyRestoreSpeed(float value);
void SetArtefactPowerRestoreSpeed(float value);
void SetArtefactBleedingRestoreSpeed(float value);

//Eatable items
void SetRemainingUses(u8 value);
u8 GetRemainingUses();
u8 GetMaxUses();
//-Alundaio
#endif // GAME_OBJECT_EXTENDED_EXPORTS
doors::door* m_door;
Expand Down
40 changes: 40 additions & 0 deletions src/xrGame/script_game_object3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "Actor.h"
#include "CharacterPhysicsSupport.h"
#include "player_hud.h"
#include "eatable_item.h"
#endif
//-Alundaio

Expand Down Expand Up @@ -1467,5 +1468,44 @@ void CScriptGameObject::ForceSetPosition(Fvector pos, bool bActivate)
ai().script_engine().script_log(LuaMessageType::Error, "force_set_position: object %s has no physics shell!",
*object().cName());
}

void CScriptGameObject::SetRemainingUses(u8 value)
{
CInventoryItem* IItm = object().cast_inventory_item();
if (!IItm)
return;

CEatableItem* eItm = IItm->cast_eatable_item();
if (!eItm)
return;

eItm->SetRemainingUses(value);
}

u8 CScriptGameObject::GetRemainingUses()
{
CInventoryItem* IItm = object().cast_inventory_item();
if (!IItm)
return 0;

CEatableItem* eItm = IItm->cast_eatable_item();
if (!eItm)
return 0;

return eItm->GetRemainingUses();
}

u8 CScriptGameObject::GetMaxUses()
{
CInventoryItem* IItm = object().cast_inventory_item();
if (!IItm)
return 0;

CEatableItem* eItm = IItm->cast_eatable_item();
if (!eItm)
return 0;

return eItm->GetMaxUses();
}
#endif
//-Alundaio
5 changes: 4 additions & 1 deletion src/xrGame/script_game_object_script3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,10 @@ class_<CScriptGameObject>& script_register_game_object2(class_<CScriptGameObject
.def("play_hud_motion", &CScriptGameObject::PlayHudMotion)
.def("switch_state", &CScriptGameObject::SwitchState)
.def("get_state", &CScriptGameObject::GetState)

// For EatableItem
.def("set_remaining_uses", &CScriptGameObject::SetRemainingUses)
.def("get_remaining_uses", &CScriptGameObject::GetRemainingUses)
.def("get_max_uses", &CScriptGameObject::GetMaxUses)
#endif
//-Alundaio

Expand Down
10 changes: 6 additions & 4 deletions src/xrGame/ui/UIActorMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CUIActorMenu : public CUIDialogWnd, public CUIWndCallback
CUICellItem* m_InfoCellItem;
u32 m_InfoCellItem_timer;
CUICellItem* m_pCurrentCellItem;
CUICellItem* m_pCurrentConsumable;

CUICellItem* m_upgrade_selected;
CUIPropertiesBox* m_UIPropertiesBox;

Expand Down Expand Up @@ -260,8 +260,12 @@ class CUIActorMenu : public CUIDialogWnd, public CUIWndCallback
void CurModeToScript();
void RepairEffect_CurItem();

public:
//Alundaio: Made public
void SetCurrentItem(CUICellItem* itm);
CUICellItem* CurrentItem();

protected:
PIItem CurrentIItem();

void InfoCurItem(CUICellItem* cell_item); // on update item
Expand Down Expand Up @@ -356,7 +360,5 @@ class CUIActorMenu : public CUIDialogWnd, public CUIWndCallback

IC UIHint* get_hint_wnd() { return m_hint_wnd; }

CUICellItem* GetCurrentConsumable() { return m_pCurrentConsumable; };
void SetCurrentConsumable(CUICellItem* ci) { m_pCurrentConsumable = ci; };
void RefreshConsumableCells();
void RefreshCurrentItemCell();
}; // class CUIActorMenu
Loading

0 comments on commit 7840b0f

Please sign in to comment.