metaforce/Runtime/World/CScriptBeam.cpp

58 lines
2.4 KiB
C++
Raw Permalink Normal View History

#include "Runtime/World/CScriptBeam.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/Particle/CWeaponDescription.hpp"
#include "Runtime/Weapon/CPlasmaProjectile.hpp"
#include "Runtime/World/CActorParameters.hpp"
#include "TCastTo.hpp" // Generated file, do not modify include path
2021-04-10 08:42:06 +00:00
namespace metaforce {
2017-11-13 06:19:18 +00:00
CScriptBeam::CScriptBeam(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf,
bool active, const TToken<CWeaponDescription>& weaponDesc, const CBeamInfo& bInfo,
const CDamageInfo& dInfo)
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(), CActorParameters::None(),
kInvalidUniqueId)
, xe8_weaponDescription(weaponDesc)
, xf4_beamInfo(bInfo)
2018-12-08 05:30:43 +00:00
, x138_damageInfo(dInfo) {}
2018-12-08 05:30:43 +00:00
void CScriptBeam::Accept(IVisitor& visitor) { visitor.Visit(this); }
2017-01-15 03:07:01 +00:00
2018-12-08 05:30:43 +00:00
void CScriptBeam::Think(float dt, CStateManager& mgr) {
if (CPlasmaProjectile* proj = static_cast<CPlasmaProjectile*>(mgr.ObjectById(x154_projectileId))) {
if (proj->GetActive()) {
2018-12-08 05:30:43 +00:00
proj->UpdateFx(x34_transform, dt, mgr);
}
} else {
2018-12-08 05:30:43 +00:00
x154_projectileId = kInvalidUniqueId;
}
}
2018-12-08 05:30:43 +00:00
void CScriptBeam::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& mgr) {
if (msg == EScriptObjectMessage::Increment) {
if (CPlasmaProjectile* proj = static_cast<CPlasmaProjectile*>(mgr.ObjectById(x154_projectileId))) {
proj->ResetBeam(mgr, true);
proj->Fire(GetTransform(), mgr, false);
}
2018-12-08 05:30:43 +00:00
} else if (msg == EScriptObjectMessage::Decrement) {
if (CPlasmaProjectile* proj = static_cast<CPlasmaProjectile*>(mgr.ObjectById(x154_projectileId))) {
if (proj->GetActive()) {
proj->ResetBeam(mgr, false);
}
}
2018-12-08 05:30:43 +00:00
} else if (msg == EScriptObjectMessage::Registered) {
x154_projectileId = mgr.AllocateUniqueId();
mgr.AddObject(new CPlasmaProjectile(xe8_weaponDescription, x10_name + "-Projectile",
x138_damageInfo.GetWeaponMode().GetType(), xf4_beamInfo, x34_transform,
EMaterialTypes::Projectile, x138_damageInfo, x154_projectileId, x4_areaId,
GetUniqueId(), {}, false, EProjectileAttrib::PlasmaProjectile));
2018-12-08 05:30:43 +00:00
} else if (msg == EScriptObjectMessage::Deleted) {
mgr.FreeScriptObject(x154_projectileId);
2018-12-08 05:30:43 +00:00
}
2018-12-08 05:30:43 +00:00
CActor::AcceptScriptMsg(msg, objId, mgr);
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce