metaforce/Runtime/World/CFire.cpp

103 lines
3.1 KiB
C++
Raw Normal View History

2018-11-14 04:16:11 +00:00
#include "CFire.hpp"
#include "Particle/CElementGen.hpp"
#include "CActorParameters.hpp"
#include "CStateManager.hpp"
#include "CPlayer.hpp"
#include "GameGlobalObjects.hpp"
#include "Graphics/CBooRenderer.hpp"
#include "TCastTo.hpp"
2018-12-08 05:30:43 +00:00
namespace urde {
2018-11-14 04:16:11 +00:00
CFire::CFire(TToken<CGenDescription> effect, TUniqueId uid, TAreaId aId, bool active, TUniqueId owner,
2018-12-08 05:30:43 +00:00
const zeus::CTransform& xf, const CDamageInfo& dInfo, const zeus::CAABox& aabox,
const zeus::CVector3f& vec, bool b1, CAssetId visorEffect, bool b2, bool b3, bool b4, float f1, float f2,
float f3, float f4)
2018-11-14 04:16:11 +00:00
: CActor(uid, active, "Fire"sv, CEntityInfo(aId, NullConnectionList), xf, CModelData::CModelDataNull(),
CMaterialList(EMaterialTypes::Projectile), CActorParameters::None(), owner)
2018-12-08 05:30:43 +00:00
, xe8_(new CElementGen(effect))
, xec_ownerId(owner)
, xf0_damageInfo(dInfo)
, x10c_damageInfo(dInfo)
, x128_(aabox)
, x144_(f1)
, x148_24_(b2)
, x148_25_(b3)
, x148_26_(b4)
, x148_27_(b4 && b3 && b2)
, x148_28_(false)
, x148_29_(b1)
, x14c_(f2)
, x150_(visorEffect)
, x154_(f3)
, x158_(f4) {
xe8_->SetGlobalScale(vec);
xe8_->SetTranslation(xf.origin);
2018-11-14 04:16:11 +00:00
}
2018-12-08 05:30:43 +00:00
void CFire::Accept(IVisitor& visitor) { visitor.Visit(this); }
2018-11-14 04:16:11 +00:00
2018-12-08 05:30:43 +00:00
void CFire::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
CActor::AcceptScriptMsg(msg, uid, mgr);
2018-11-14 04:16:11 +00:00
2018-12-08 05:30:43 +00:00
if (msg == EScriptObjectMessage::Registered) {
xe8_->SetParticleEmission(true);
SetActive(true);
}
2018-11-14 04:16:11 +00:00
}
2018-12-08 05:30:43 +00:00
void CFire::Think(float dt, CStateManager& mgr) {
float particleCount = xe8_->GetParticleCount() / xe8_->GetMaxParticles();
if (GetActive()) {
xe8_->Update(dt * x144_);
x10c_damageInfo = CDamageInfo(xf0_damageInfo, dt * std::max(0.5f, particleCount));
}
2018-11-14 04:16:11 +00:00
2018-12-08 05:30:43 +00:00
bool doFree = false;
if (xe8_->IsSystemDeletable())
doFree = true;
2018-11-14 04:16:11 +00:00
2018-12-08 05:30:43 +00:00
if (x148_29_) {
auto playerBounds = mgr.GetPlayer().GetTouchBounds();
auto bounds = GetTouchBounds();
if (playerBounds->intersects(*bounds) && doFree && particleCount > 0.5f)
mgr.GetPlayer().SetVisorSteam(particleCount * x14c_, x154_, x158_, x150_, true);
else
mgr.GetPlayer().SetVisorSteam(0.f, 1.f, 1.f, {}, true);
}
2018-11-14 04:16:11 +00:00
2018-12-08 05:30:43 +00:00
x15c_ += dt;
2018-11-14 04:16:11 +00:00
2018-12-08 05:30:43 +00:00
if (x15c_ > 45.f)
doFree = true;
2018-11-14 04:16:11 +00:00
2018-12-08 05:30:43 +00:00
if (doFree)
mgr.FreeScriptObject(GetUniqueId());
2018-11-14 04:16:11 +00:00
}
2018-12-08 05:30:43 +00:00
void CFire::Touch(CActor& act, CStateManager& mgr) {
if (act.GetUniqueId() == xec_ownerId)
return;
2018-11-14 04:16:11 +00:00
2018-12-08 05:30:43 +00:00
mgr.ApplyDamage(GetUniqueId(), act.GetUniqueId(), GetUniqueId(), x10c_damageInfo,
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {});
2018-11-14 04:16:11 +00:00
}
2018-12-08 05:30:43 +00:00
void CFire::AddToRenderer(const zeus::CFrustum& frustum, const CStateManager& mgr) const {
bool drawParticles = true;
if (!x148_27_) {
using EPlayerVisor = CPlayerState::EPlayerVisor;
CPlayerState::EPlayerVisor visor = mgr.GetPlayerState()->GetActiveVisor(mgr);
if (visor == EPlayerVisor::Combat || visor == EPlayerVisor::Scan)
drawParticles = x148_24_;
else if (visor == EPlayerVisor::XRay)
drawParticles = x148_26_;
else if (visor == EPlayerVisor::Thermal)
drawParticles = x148_25_;
}
2018-11-14 04:16:11 +00:00
2018-12-08 05:30:43 +00:00
if (drawParticles)
g_Renderer->AddParticleGen(*xe8_);
CActor::AddToRenderer(frustum, mgr);
2018-11-14 04:16:11 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace urde