Skip to content

Commit 7840b0f

Browse files
revolucasXottab-DUTY
authored andcommitted
+ AxelDominator weight calculations for CEatableItem weight
~ 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)
1 parent 9c726bd commit 7840b0f

16 files changed

+283
-111
lines changed

src/xrGame/Inventory.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,17 @@ bool CInventory::Eat(PIItem pIItem)
10701070
pItemToEat->object().cNameSect().c_str());
10711071
#endif // MP_LOGGING
10721072

1073-
if (IsGameTypeSingle() && Actor()->m_inventory == this)
1074-
Actor()->callback(GameObject::eUseObject)((smart_cast<CGameObject*>(pIItem))->lua_game_object());
1073+
if (Actor()->m_inventory == this)
1074+
{
1075+
if (IsGameTypeSingle())
1076+
Actor()->callback(GameObject::eUseObject)(smart_cast<CGameObject*>(pIItem)->lua_game_object());
1077+
1078+
if (pItemToEat->IsUsingCondition() && pItemToEat->GetRemainingUses() < 1 && pItemToEat->CanDelete())
1079+
CurrentGameUI()->GetActorMenu().RefreshCurrentItemCell();
1080+
1081+
CurrentGameUI()->GetActorMenu().SetCurrentItem(nullptr);
1082+
}
1083+
10751084

10761085
if (pItemToEat->Empty())
10771086
{
@@ -1081,9 +1090,6 @@ bool CInventory::Eat(PIItem pIItem)
10811090
pIItem->SetDropManual(true);
10821091
}
10831092

1084-
if (pItemToEat->IsUsingCondition() && Actor()->m_inventory == this)
1085-
CurrentGameUI()->GetActorMenu().RefreshConsumableCells();
1086-
10871093
return true;
10881094
}
10891095

src/xrGame/UIGameCustom.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
#include "xrEngine/x_ray.h"
2020

21+
#include "ui\UICellItem.h" //Alundaio
22+
//#include "script_game_object.h" //Alundaio
23+
2124
EGameIDs ParseStringToGameType(const char* str);
2225

2326
struct predicate_find_stat
@@ -177,7 +180,28 @@ void CUIGameCustom::HideActorMenu()
177180
void CUIGameCustom::UpdateActorMenu()
178181
{
179182
if (ActorMenu->IsShown())
183+
{
180184
ActorMenu->UpdateActor();
185+
ActorMenu->RefreshCurrentItemCell();
186+
}
187+
}
188+
189+
CScriptGameObject* CUIGameCustom::CurrentItemAtCell()
190+
{
191+
CUICellItem* itm = ActorMenu->CurrentItem();
192+
if (!itm->m_pData)
193+
return nullptr;
194+
195+
PIItem IItm = static_cast<PIItem>(itm->m_pData);
196+
if (!IItm)
197+
return nullptr;
198+
199+
CGameObject* GO = IItm->cast_game_object();
200+
201+
if (GO)
202+
return GO->lua_game_object();
203+
204+
return nullptr;
181205
}
182206
//-Alundaio
183207

src/xrGame/UIGameCustom.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "gametype_chooser.h"
66
#include "UIDialogHolder.h"
77
#include "xrEngine/CustomHUD.h"
8+
#include "script_game_object.h"
9+
810
// refs
911
class CUI;
1012
class CTeamBaseZone;
@@ -101,6 +103,7 @@ class CUIGameCustom : public FactoryObjectBase, public CDialogHolder
101103
bool ShowActorMenu();
102104
void HideActorMenu();
103105
void UpdateActorMenu(); //Alundaio
106+
CScriptGameObject* CurrentItemAtCell(); //Alundaio
104107
bool ShowPdaMenu();
105108
void HidePdaMenu();
106109
void ShowMessagesWindow();

src/xrGame/UIGameCustom_script.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ SCRIPT_EXPORT(CUIGameCustom, (), {
1818
.def("AddCustomStatic", &CUIGameCustom::AddCustomStatic)
1919
.def("RemoveCustomStatic", &CUIGameCustom::RemoveCustomStatic)
2020
.def("HideActorMenu", &CUIGameCustom::HideActorMenu)
21-
.def("UpdateActorMenu", &CUIGameCustom::UpdateActorMenu) //Alundaio
21+
//Alundaio
22+
.def("UpdateActorMenu", &CUIGameCustom::UpdateActorMenu)
23+
.def("CurrentItemAtCell", &CUIGameCustom::CurrentItemAtCell)
24+
//-Alundaio
2225
.def("HidePdaMenu", &CUIGameCustom::HidePdaMenu)
2326
.def("show_messages", &CUIGameCustom::ShowMessagesWindow)
2427
.def("hide_messages", &CUIGameCustom::HideMessagesWindow)

src/xrGame/eatable_item.cpp

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,32 @@ void CEatableItem::Load(LPCSTR section)
3636
{
3737
inherited::Load(section);
3838

39-
m_iRemainingUses = m_iMaxUses = READ_IF_EXISTS(pSettings, r_u16, section, "max_uses", 1);
39+
m_iRemainingUses = m_iMaxUses = READ_IF_EXISTS(pSettings, r_u8, section, "max_uses", 1);
4040
m_bRemoveAfterUse = READ_IF_EXISTS(pSettings, r_bool, section, "remove_after_use", true);
41+
m_fWeightFull = m_weight;
42+
m_fWeightEmpty = READ_IF_EXISTS(pSettings, r_float, section, "empty_weight", 0.0f);
4143

4244
if (IsUsingCondition())
43-
SetCondition((float)m_iRemainingUses / (float)m_iMaxUses );
45+
{
46+
if (m_iMaxUses > 0)
47+
SetCondition(static_cast<float>(m_iRemainingUses / m_iMaxUses));
48+
else
49+
SetCondition(0.f);
50+
}
4451
}
4552

4653
void CEatableItem::load(IReader& packet)
4754
{
4855
inherited::load(packet);
4956

50-
m_iRemainingUses = packet.r_u16();
57+
m_iRemainingUses = packet.r_u8();
5158
}
5259

5360
void CEatableItem::save(NET_Packet& packet)
5461
{
5562
inherited::save(packet);
5663

57-
packet.w_u16(m_iRemainingUses);
64+
packet.w_u8(m_iRemainingUses);
5865
}
5966

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

6572
if (IsUsingCondition())
66-
SetCondition((float)m_iRemainingUses / (float)m_iMaxUses);
73+
{
74+
if (m_iMaxUses > 0)
75+
SetCondition(static_cast<float>(m_iRemainingUses / m_iMaxUses));
76+
else
77+
SetCondition(0);
78+
}
6779

6880
return TRUE;
6981
};
@@ -74,8 +86,10 @@ bool CEatableItem::Useful() const
7486
return false;
7587

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

8094
return true;
8195
}
@@ -132,12 +146,37 @@ bool CEatableItem::UseBy(CEntityAlive* entity_alive)
132146
Level().Send(tmp_packet);
133147
}
134148

135-
if (m_iRemainingUses > 0)
136-
--m_iRemainingUses;
137-
else
138-
m_iRemainingUses = 0;
149+
// If uses 255, then skip the decrement for infinite usages
150+
if (m_iRemainingUses != -1)
151+
{
152+
if (m_iRemainingUses > 0)
153+
--m_iRemainingUses;
154+
else
155+
m_iRemainingUses = 0;
156+
}
139157

140-
SetCondition((float)m_iRemainingUses / (float)m_iMaxUses);
158+
if (IsUsingCondition())
159+
{
160+
if (m_iMaxUses > 0)
161+
SetCondition(static_cast<float>(m_iRemainingUses / m_iMaxUses));
162+
else
163+
SetCondition(0.f);
164+
}
141165

142166
return true;
143167
}
168+
169+
float CEatableItem::Weight() const
170+
{
171+
float res = inherited::Weight();
172+
173+
if (IsUsingCondition())
174+
{
175+
const float net_weight = m_fWeightFull - m_fWeightEmpty;
176+
const float use_weight = m_iMaxUses > 0 ? net_weight / m_iMaxUses : 0.f;
177+
178+
res = m_fWeightEmpty + m_iRemainingUses * use_weight;
179+
}
180+
181+
return res;
182+
}

src/xrGame/eatable_item.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ class CEatableItem : public CInventoryItem
1313
protected:
1414
CPhysicItem* m_physic_item;
1515

16-
u16 m_iMaxUses;
17-
u16 m_iRemainingUses;
16+
u8 m_iMaxUses;
17+
u8 m_iRemainingUses;
1818
bool m_bRemoveAfterUse;
19+
float m_fWeightFull;
20+
float m_fWeightEmpty;
1921

2022
public:
2123
CEatableItem();
@@ -34,6 +36,8 @@ class CEatableItem : public CInventoryItem
3436
virtual bool UseBy(CEntityAlive* npc);
3537
virtual bool Empty() const { return m_iRemainingUses == 0; }
3638
bool CanDelete() const { return m_bRemoveAfterUse == true; }
37-
virtual u16 GetMaxUses() const { return m_iMaxUses; }
38-
virtual u16 GetRemainingUses() const { return m_iRemainingUses; }
39+
virtual u8 GetMaxUses() const { return m_iMaxUses; }
40+
virtual u8 GetRemainingUses() const { return m_iRemainingUses; }
41+
void SetRemainingUses(u8 value) { if (value <= m_iMaxUses && value >= 0) m_iRemainingUses = value; };
42+
float Weight() const override;
3943
};

src/xrGame/script_game_object.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,11 @@ class CScriptGameObject
865865
void SetArtefactSatietyRestoreSpeed(float value);
866866
void SetArtefactPowerRestoreSpeed(float value);
867867
void SetArtefactBleedingRestoreSpeed(float value);
868+
869+
//Eatable items
870+
void SetRemainingUses(u8 value);
871+
u8 GetRemainingUses();
872+
u8 GetMaxUses();
868873
//-Alundaio
869874
#endif // GAME_OBJECT_EXTENDED_EXPORTS
870875
doors::door* m_door;

src/xrGame/script_game_object3.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "Actor.h"
4646
#include "CharacterPhysicsSupport.h"
4747
#include "player_hud.h"
48+
#include "eatable_item.h"
4849
#endif
4950
//-Alundaio
5051

@@ -1467,5 +1468,44 @@ void CScriptGameObject::ForceSetPosition(Fvector pos, bool bActivate)
14671468
ai().script_engine().script_log(LuaMessageType::Error, "force_set_position: object %s has no physics shell!",
14681469
*object().cName());
14691470
}
1471+
1472+
void CScriptGameObject::SetRemainingUses(u8 value)
1473+
{
1474+
CInventoryItem* IItm = object().cast_inventory_item();
1475+
if (!IItm)
1476+
return;
1477+
1478+
CEatableItem* eItm = IItm->cast_eatable_item();
1479+
if (!eItm)
1480+
return;
1481+
1482+
eItm->SetRemainingUses(value);
1483+
}
1484+
1485+
u8 CScriptGameObject::GetRemainingUses()
1486+
{
1487+
CInventoryItem* IItm = object().cast_inventory_item();
1488+
if (!IItm)
1489+
return 0;
1490+
1491+
CEatableItem* eItm = IItm->cast_eatable_item();
1492+
if (!eItm)
1493+
return 0;
1494+
1495+
return eItm->GetRemainingUses();
1496+
}
1497+
1498+
u8 CScriptGameObject::GetMaxUses()
1499+
{
1500+
CInventoryItem* IItm = object().cast_inventory_item();
1501+
if (!IItm)
1502+
return 0;
1503+
1504+
CEatableItem* eItm = IItm->cast_eatable_item();
1505+
if (!eItm)
1506+
return 0;
1507+
1508+
return eItm->GetMaxUses();
1509+
}
14701510
#endif
14711511
//-Alundaio

src/xrGame/script_game_object_script3.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,10 @@ class_<CScriptGameObject>& script_register_game_object2(class_<CScriptGameObject
381381
.def("play_hud_motion", &CScriptGameObject::PlayHudMotion)
382382
.def("switch_state", &CScriptGameObject::SwitchState)
383383
.def("get_state", &CScriptGameObject::GetState)
384-
384+
// For EatableItem
385+
.def("set_remaining_uses", &CScriptGameObject::SetRemainingUses)
386+
.def("get_remaining_uses", &CScriptGameObject::GetRemainingUses)
387+
.def("get_max_uses", &CScriptGameObject::GetMaxUses)
385388
#endif
386389
//-Alundaio
387390

src/xrGame/ui/UIActorMenu.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class CUIActorMenu : public CUIDialogWnd, public CUIWndCallback
8888
CUICellItem* m_InfoCellItem;
8989
u32 m_InfoCellItem_timer;
9090
CUICellItem* m_pCurrentCellItem;
91-
CUICellItem* m_pCurrentConsumable;
91+
9292
CUICellItem* m_upgrade_selected;
9393
CUIPropertiesBox* m_UIPropertiesBox;
9494

@@ -260,8 +260,12 @@ class CUIActorMenu : public CUIDialogWnd, public CUIWndCallback
260260
void CurModeToScript();
261261
void RepairEffect_CurItem();
262262

263+
public:
264+
//Alundaio: Made public
263265
void SetCurrentItem(CUICellItem* itm);
264266
CUICellItem* CurrentItem();
267+
268+
protected:
265269
PIItem CurrentIItem();
266270

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

357361
IC UIHint* get_hint_wnd() { return m_hint_wnd; }
358362

359-
CUICellItem* GetCurrentConsumable() { return m_pCurrentConsumable; };
360-
void SetCurrentConsumable(CUICellItem* ci) { m_pCurrentConsumable = ci; };
361-
void RefreshConsumableCells();
363+
void RefreshCurrentItemCell();
362364
}; // class CUIActorMenu

0 commit comments

Comments
 (0)