1414#include " entity_alive.h"
1515#include " EntityCondition.h"
1616#include " InventoryOwner.h"
17+ #include " UIGameCustom.h"
1718
1819CEatableItem::CEatableItem ()
1920{
20- m_iPortionsNum = -1 ;
2121 m_physic_item = 0 ;
22+ m_iMaxUses = 1 ;
23+ m_iRemainingUses = 1 ;
24+ m_bRemoveAfterUse = true ;
2225}
2326
2427CEatableItem::~CEatableItem () {}
@@ -32,15 +35,35 @@ void CEatableItem::Load(LPCSTR section)
3235{
3336 inherited::Load (section);
3437
35- m_iPortionsNum = pSettings->r_s32 (section, " eat_portions_num" );
36- VERIFY (m_iPortionsNum < 10000 );
38+ m_iRemainingUses = m_iMaxUses = READ_IF_EXISTS (pSettings, r_u16, section, " max_uses" , 1 );
39+ m_bRemoveAfterUse = READ_IF_EXISTS (pSettings, r_bool, section, " remove_after_use" , true );
40+
41+ if (IsUsingCondition ())
42+ SetCondition ((float )m_iRemainingUses / (float )m_iMaxUses );
43+ }
44+
45+ void CEatableItem::load (IReader& packet)
46+ {
47+ inherited::load (packet);
48+
49+ m_iRemainingUses = packet.r_u16 ();
50+ }
51+
52+ void CEatableItem::save (NET_Packet& packet)
53+ {
54+ inherited::save (packet);
55+
56+ packet.w_u16 (m_iRemainingUses);
3757}
3858
3959BOOL CEatableItem::net_Spawn (CSE_Abstract* DC)
4060{
4161 if (!inherited::net_Spawn (DC))
4262 return FALSE ;
4363
64+ if (IsUsingCondition ())
65+ SetCondition ((float )m_iRemainingUses / (float )m_iMaxUses);
66+
4467 return TRUE ;
4568};
4669
@@ -50,7 +73,7 @@ bool CEatableItem::Useful() const
5073 return false ;
5174
5275 // проверить не все ли еще съедено
53- if (m_iPortionsNum == 0 )
76+ if (m_iRemainingUses == 0 )
5477 return false ;
5578
5679 return true ;
@@ -108,10 +131,14 @@ bool CEatableItem::UseBy(CEntityAlive* entity_alive)
108131 Level ().Send (tmp_packet);
109132 }
110133
111- if (m_iPortionsNum > 0 )
112- --m_iPortionsNum ;
134+ if (m_iRemainingUses > 0 )
135+ --m_iRemainingUses ;
113136 else
114- m_iPortionsNum = 0 ;
137+ m_iRemainingUses = 0 ;
138+
139+ SetCondition ((float )m_iRemainingUses / (float )m_iMaxUses);
140+ CurrentGameUI ()->HideActorMenu ();
141+ CurrentGameUI ()->ShowActorMenu ();
115142
116143 return true ;
117144}
0 commit comments