2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CScriptEMPulse.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CSimplePool.hpp"
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/Graphics/CBooRenderer.hpp"
|
|
|
|
#include "Runtime/Particle/CGenDescription.hpp"
|
|
|
|
#include "Runtime/Particle/CElementGen.hpp"
|
|
|
|
#include "Runtime/World/CActorParameters.hpp"
|
|
|
|
#include "Runtime/World/CPlayer.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2018-10-11 22:57:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2018-10-11 22:57:05 +00:00
|
|
|
|
|
|
|
CScriptEMPulse::CScriptEMPulse(TUniqueId uid, std::string_view name, const CEntityInfo& info,
|
|
|
|
const zeus::CTransform& xf, bool active, float initialRadius, float finalRadius,
|
2018-12-08 05:30:43 +00:00
|
|
|
float duration, float interferenceDur, float f5, float interferenceMag, float f7,
|
|
|
|
CAssetId partId)
|
|
|
|
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(EMaterialTypes::Projectile),
|
|
|
|
CActorParameters::None().HotInThermal(true), kInvalidUniqueId)
|
|
|
|
, xe8_duration(duration)
|
|
|
|
, xec_finalRadius(finalRadius)
|
|
|
|
, xf0_currentRadius(initialRadius)
|
|
|
|
, xf4_initialRadius(initialRadius)
|
|
|
|
, xf8_interferenceDur(interferenceDur)
|
|
|
|
, xfc_(f5)
|
|
|
|
, x100_interferenceMag(interferenceMag)
|
|
|
|
, x104_(f7)
|
|
|
|
, x108_particleDesc(g_SimplePool->GetObj({SBIG('PART'), partId})) {}
|
|
|
|
|
|
|
|
void CScriptEMPulse::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
|
|
|
|
|
|
|
void CScriptEMPulse::Think(float dt, CStateManager& mgr) {
|
2020-05-07 17:29:46 +00:00
|
|
|
if (!GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-07 17:29:46 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
xf0_currentRadius += ((xec_finalRadius - xf4_initialRadius) / xe8_duration) * dt;
|
2020-05-07 17:29:46 +00:00
|
|
|
if (xf0_currentRadius < xec_finalRadius) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.FreeScriptObject(GetUniqueId());
|
2020-05-07 17:29:46 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
x114_particleGen->Update(dt);
|
2018-10-11 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptEMPulse::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
CActor::AcceptScriptMsg(msg, uid, mgr);
|
2020-05-07 17:29:46 +00:00
|
|
|
|
|
|
|
if (msg != EScriptObjectMessage::Activate) {
|
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-07 17:29:46 +00:00
|
|
|
|
|
|
|
x114_particleGen = std::make_unique<CElementGen>(x108_particleDesc, CElementGen::EModelOrientationType::Normal,
|
|
|
|
CElementGen::EOptionalSystemFlags::One);
|
|
|
|
|
|
|
|
x114_particleGen->SetOrientation(GetTransform().getRotation());
|
|
|
|
x114_particleGen->SetGlobalTranslation(GetTranslation());
|
|
|
|
x114_particleGen->SetParticleEmission(true);
|
|
|
|
mgr.GetPlayerState()->GetStaticInterference().AddSource(GetUniqueId(), x100_interferenceMag, xf8_interferenceDur);
|
2018-10-11 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 11:54:02 +00:00
|
|
|
void CScriptEMPulse::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CActor::AddToRenderer(frustum, mgr);
|
2020-04-05 11:54:02 +00:00
|
|
|
if (GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
g_Renderer->AddParticleGen(*x114_particleGen);
|
2020-04-05 11:54:02 +00:00
|
|
|
}
|
2018-10-11 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptEMPulse::CalculateRenderBounds() { x9c_renderBounds = CalculateBoundingBox(); }
|
2018-10-11 22:57:05 +00:00
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
std::optional<zeus::CAABox> CScriptEMPulse::GetTouchBounds() const { return {CalculateBoundingBox()}; }
|
2018-10-11 22:57:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptEMPulse::Touch(CActor& act, CStateManager& mgr) {
|
2020-05-07 17:29:46 +00:00
|
|
|
if (!GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-07 17:29:46 +00:00
|
|
|
}
|
2018-10-11 22:57:05 +00:00
|
|
|
|
2020-05-07 17:29:46 +00:00
|
|
|
if (const TCastToPtr<CPlayer> pl = act) {
|
|
|
|
const zeus::CVector3f posDiff = GetTranslation() - pl->GetTranslation();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (posDiff.magnitude() < xec_finalRadius) {
|
2020-05-07 17:29:46 +00:00
|
|
|
const float dur =
|
2018-12-08 05:30:43 +00:00
|
|
|
((1.f - (posDiff.magnitude() / xec_finalRadius)) * (xfc_ - xf8_interferenceDur)) + xf8_interferenceDur;
|
2020-05-07 17:29:46 +00:00
|
|
|
const float mag =
|
2018-12-08 05:30:43 +00:00
|
|
|
((1.f - (posDiff.magnitude() / xec_finalRadius)) * (x104_ - xf8_interferenceDur)) + x100_interferenceMag;
|
2018-10-11 22:57:05 +00:00
|
|
|
|
2020-05-07 17:29:46 +00:00
|
|
|
if (dur > pl->GetStaticTimer()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
pl->SetHudDisable(dur, 0.5f, 2.5f);
|
2020-05-07 17:29:46 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.GetPlayerState()->GetStaticInterference().AddSource(GetUniqueId(), mag, dur);
|
2020-05-07 17:29:46 +00:00
|
|
|
}
|
2018-10-11 22:57:05 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-10-11 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CAABox CScriptEMPulse::CalculateBoundingBox() const {
|
|
|
|
return zeus::CAABox(GetTranslation() - xf0_currentRadius, GetTranslation() + xf0_currentRadius);
|
2018-10-11 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|