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