2016-04-19 21:25:26 +00:00
|
|
|
#include "CScriptCounter.hpp"
|
2017-07-07 12:23:20 +00:00
|
|
|
#include "CStateManager.hpp"
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2016-04-19 21:25:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2016-04-19 21:25:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CScriptCounter::CScriptCounter(TUniqueId uid, std::string_view name, const CEntityInfo& info, 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)
|
2018-12-08 05:30:43 +00:00
|
|
|
, x40_autoReset(autoReset) {}
|
2016-04-19 21:25:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptCounter::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +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);
|
2017-07-07 12:23:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x40_autoReset)
|
|
|
|
x38_current = x34_initial;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::SetToMax:
|
|
|
|
if (GetActive()) {
|
|
|
|
x38_current = x3c_max;
|
|
|
|
SendScriptMsgs(EScriptObjectState::MaxReached, stateMgr, EScriptObjectMessage::None);
|
2017-07-07 12:23:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x40_autoReset)
|
|
|
|
x38_current = x34_initial;
|
2017-07-07 12:23:20 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
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) {
|
2019-01-16 04:22:44 +00:00
|
|
|
SendScriptMsgs(EScriptObjectState::MaxReached, stateMgr, EScriptObjectMessage::None);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x40_autoReset)
|
|
|
|
x38_current = x34_initial;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Reset:
|
|
|
|
if (GetActive())
|
|
|
|
x38_current = x34_initial;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-07-07 12:23:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity::AcceptScriptMsg(msg, objId, stateMgr);
|
2017-07-07 12:23:20 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|