2016-04-19 21:25:26 +00:00
|
|
|
#include "CScriptCounter.hpp"
|
2017-07-07 12:23:20 +00:00
|
|
|
#include "CStateManager.hpp"
|
2017-01-15 03:07:01 +00:00
|
|
|
#include "TCastTo.hpp"
|
2016-04-19 21:25:26 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
CScriptCounter::CScriptCounter(TUniqueId uid, const std::string& name, const CEntityInfo& info,
|
2017-07-07 12:23:20 +00:00
|
|
|
s32 initial, s32 max, bool autoReset, bool active)
|
2016-04-20 21:44:18 +00:00
|
|
|
: CEntity(uid, info, active, name)
|
2017-07-07 12:23:20 +00:00
|
|
|
, x34_initial(initial)
|
|
|
|
, x38_current(initial)
|
|
|
|
, x3c_max(max)
|
|
|
|
, x40_autoReset(autoReset)
|
2016-04-19 21:25:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-15 03:07:01 +00:00
|
|
|
void CScriptCounter::Accept(IVisitor& visitor)
|
|
|
|
{
|
|
|
|
visitor.Visit(this);
|
|
|
|
}
|
|
|
|
|
2017-07-07 12:23:20 +00:00
|
|
|
void CScriptCounter::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr)
|
|
|
|
{
|
|
|
|
switch(msg)
|
|
|
|
{
|
|
|
|
case EScriptObjectMessage::SetToZero:
|
|
|
|
if (GetActive())
|
|
|
|
{
|
|
|
|
x38_current = 0;
|
|
|
|
SendScriptMsgs(EScriptObjectState::Zero, stateMgr, EScriptObjectMessage::None);
|
|
|
|
|
|
|
|
if (x40_autoReset)
|
|
|
|
x38_current = x34_initial;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::SetToMax:
|
|
|
|
if (GetActive())
|
|
|
|
{
|
|
|
|
x38_current = x3c_max;
|
|
|
|
SendScriptMsgs(EScriptObjectState::MaxReached, stateMgr, EScriptObjectMessage::None);
|
|
|
|
|
|
|
|
if (x40_autoReset)
|
|
|
|
x38_current = x34_initial;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Decrement:
|
|
|
|
if (GetActive() && x38_current > 0)
|
|
|
|
{
|
|
|
|
--x38_current;
|
|
|
|
if (x38_current == 0)
|
|
|
|
{
|
|
|
|
SendScriptMsgs(EScriptObjectState::Zero, stateMgr, EScriptObjectMessage::None);
|
|
|
|
if (x40_autoReset)
|
|
|
|
x38_current = x34_initial;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Increment:
|
|
|
|
if (GetActive() && x38_current < x3c_max)
|
|
|
|
{
|
|
|
|
++x38_current;
|
|
|
|
if (x38_current >= x3c_max)
|
|
|
|
{
|
|
|
|
SendScriptMsgs(EScriptObjectState::Zero, stateMgr, EScriptObjectMessage::None);
|
|
|
|
if (x40_autoReset)
|
|
|
|
x38_current = x34_initial;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Reset:
|
|
|
|
if (GetActive())
|
|
|
|
x38_current = x34_initial;
|
|
|
|
break;
|
2017-07-31 05:19:05 +00:00
|
|
|
default:
|
|
|
|
break;
|
2017-07-07 12:23:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CEntity::AcceptScriptMsg(msg, objId, stateMgr);
|
|
|
|
}
|
|
|
|
|
2016-04-19 21:25:26 +00:00
|
|
|
}
|