2016-11-20 21:53:15 +00:00
|
|
|
#include "CScriptActorKeyframe.hpp"
|
2018-05-14 21:44:09 +00:00
|
|
|
#include "CStateManager.hpp"
|
|
|
|
#include "World/CScriptActor.hpp"
|
|
|
|
#include "World/CScriptPlatform.hpp"
|
2018-05-17 00:04:07 +00:00
|
|
|
#include "World/CPatterned.hpp"
|
2017-01-15 03:07:01 +00:00
|
|
|
#include "TCastTo.hpp"
|
2016-11-20 21:53:15 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2017-11-13 06:19:18 +00:00
|
|
|
CScriptActorKeyframe::CScriptActorKeyframe(TUniqueId uid, std::string_view name, const CEntityInfo& info, s32 animId,
|
2018-11-11 03:27:54 +00:00
|
|
|
bool looping, float lifetime, bool isPassive, u32 fadeOut, bool active,
|
2018-05-17 00:04:07 +00:00
|
|
|
float totalPlayback)
|
2016-12-19 18:27:58 +00:00
|
|
|
: CEntity(uid, info, active, name)
|
|
|
|
, x34_animationId(animId)
|
2018-05-14 21:44:09 +00:00
|
|
|
, x38_initialLifetime(lifetime)
|
|
|
|
, x3c_playbackRate(totalPlayback)
|
2018-12-08 05:30:43 +00:00
|
|
|
, x40_lifetime(lifetime) {
|
|
|
|
x44_24_looping = looping;
|
|
|
|
x44_25_isPassive = isPassive;
|
|
|
|
x44_26_fadeOut = fadeOut;
|
|
|
|
x44_27_timedLoop = fadeOut;
|
|
|
|
x44_28_playing = false;
|
|
|
|
x44_29_ = false;
|
2016-11-20 21:53:15 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptActorKeyframe::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptActorKeyframe::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
if (msg == EScriptObjectMessage::Action) {
|
|
|
|
if (GetActive()) {
|
|
|
|
if (!x44_25_isPassive) {
|
|
|
|
for (const SConnection& conn : x20_conns) {
|
|
|
|
if (conn.x0_state != EScriptObjectState::Play || conn.x4_msg != EScriptObjectMessage::Play)
|
|
|
|
continue;
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
auto search = mgr.GetIdListForScript(conn.x8_objId);
|
|
|
|
for (auto it = search.first; it != search.second; ++it)
|
|
|
|
UpdateEntity(it->second, mgr);
|
2018-05-14 21:44:09 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
x44_28_playing = true;
|
|
|
|
SendScriptMsgs(EScriptObjectState::Play, mgr, EScriptObjectMessage::None);
|
2018-05-14 21:44:09 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else if (msg == EScriptObjectMessage::InitializedInArea) {
|
|
|
|
if (x34_animationId == -1)
|
|
|
|
x34_animationId = 0;
|
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity::AcceptScriptMsg(msg, uid, mgr);
|
2018-05-14 21:44:09 +00:00
|
|
|
}
|
2016-11-20 21:53:15 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptActorKeyframe::Think(float dt, CStateManager& mgr) {
|
|
|
|
if (x44_25_isPassive || !x44_24_looping || !x44_27_timedLoop || !x44_28_playing || x40_lifetime <= 0.f) {
|
|
|
|
CEntity::Think(dt, mgr);
|
|
|
|
return;
|
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x40_lifetime -= dt;
|
|
|
|
if (x40_lifetime > 0.f) {
|
|
|
|
CEntity::Think(dt, mgr);
|
|
|
|
return;
|
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x44_28_playing = false;
|
|
|
|
for (const SConnection& conn : x20_conns) {
|
|
|
|
if (conn.x0_state != EScriptObjectState::Play || conn.x4_msg != EScriptObjectMessage::Play)
|
|
|
|
continue;
|
|
|
|
CEntity* ent = mgr.ObjectById(mgr.GetIdForScript(conn.x8_objId));
|
|
|
|
if (TCastToPtr<CScriptActor> act = ent) {
|
|
|
|
if (act->HasModelData() && act->GetModelData()->HasAnimData()) {
|
|
|
|
CAnimData* animData = act->ModelData()->AnimationData();
|
|
|
|
if (animData->IsAdditiveAnimation(x34_animationId))
|
|
|
|
animData->DelAdditiveAnimation(x34_animationId);
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (animData->GetDefaultAnimation() == x34_animationId)
|
|
|
|
animData->EnableLooping(false);
|
|
|
|
}
|
|
|
|
} else if (TCastToPtr<CPatterned> ai = ent) {
|
|
|
|
CAnimData* animData = ai->ModelData()->AnimationData();
|
|
|
|
if (animData->IsAdditiveAnimation(x34_animationId)) {
|
|
|
|
animData->DelAdditiveAnimation(x34_animationId);
|
|
|
|
} else if (ai->GetBodyController()->GetCurrentStateId() == pas::EAnimationState::Scripted &&
|
|
|
|
animData->GetDefaultAnimation() == x34_animationId) {
|
|
|
|
ai->BodyController()->GetCommandMgr().DeliverCmd(CBodyStateCmd(EBodyStateCmd::ExitState));
|
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity::Think(dt, mgr);
|
2016-11-20 21:53:15 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptActorKeyframe::UpdateEntity(TUniqueId uid, CStateManager& mgr) {
|
|
|
|
CEntity* ent = mgr.ObjectById(uid);
|
|
|
|
CActor* act = nullptr;
|
|
|
|
if (TCastToPtr<CScriptActor> tmp = ent)
|
|
|
|
act = tmp;
|
|
|
|
else if (TCastToPtr<CScriptPlatform> tmp = ent)
|
|
|
|
act = tmp;
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (act) {
|
|
|
|
if (!act->GetActive())
|
|
|
|
mgr.SendScriptMsg(act, GetUniqueId(), EScriptObjectMessage::Activate);
|
2019-02-24 07:15:54 +00:00
|
|
|
act->SetDrawFlags({0, 0, 3, zeus::skWhite});
|
2018-12-08 05:30:43 +00:00
|
|
|
if (act->HasModelData() && act->GetModelData()->HasAnimData()) {
|
|
|
|
CAnimData* animData = act->ModelData()->AnimationData();
|
|
|
|
if (animData->IsAdditiveAnimation(x34_animationId)) {
|
|
|
|
animData->AddAdditiveAnimation(x34_animationId, 1.f, x44_24_looping, x44_26_fadeOut);
|
|
|
|
} else {
|
|
|
|
animData->SetAnimation(CAnimPlaybackParms(x34_animationId, -1, 1.f, true), false);
|
|
|
|
act->ModelData()->EnableLooping(x44_24_looping);
|
|
|
|
animData->MultiplyPlaybackRate(x3c_playbackRate);
|
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else if (TCastToPtr<CPatterned> ai = ent) {
|
|
|
|
CAnimData* animData = ai->ModelData()->AnimationData();
|
|
|
|
if (animData->IsAdditiveAnimation(x34_animationId)) {
|
|
|
|
animData->AddAdditiveAnimation(x34_animationId, 1.f, x44_24_looping, x44_26_fadeOut);
|
|
|
|
} else {
|
|
|
|
ai->BodyController()->GetCommandMgr().DeliverCmd(
|
|
|
|
CBCScriptedCmd(x34_animationId, x44_24_looping, x44_27_timedLoop, x38_initialLifetime));
|
2018-05-17 00:04:07 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|