metaforce/Runtime/MP1/World/CActorContraption.cpp

105 lines
4.0 KiB
C++
Raw Normal View History

#include "Runtime/MP1/World/CActorContraption.hpp"
#include "Runtime/CSimplePool.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Character/CInt32POINode.hpp"
#include "Runtime/Weapon/CFlameInfo.hpp"
#include "Runtime/Weapon/CFlameThrower.hpp"
#include "TCastTo.hpp" // Generated file, do not modify include path
2017-02-03 23:32:15 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
2017-02-03 23:32:15 +00:00
2017-11-13 06:19:18 +00:00
MP1::CActorContraption::CActorContraption(TUniqueId uid, std::string_view name, const CEntityInfo& info,
2017-02-03 23:32:15 +00:00
const zeus::CTransform& xf, CModelData&& mData, const zeus::CAABox& aabox,
2018-12-08 05:30:43 +00:00
const CMaterialList& matList, float mass, float zMomentum,
const CHealthInfo& hInfo, const CDamageVulnerability& dVuln,
const CActorParameters& aParams, CAssetId part, const CDamageInfo& dInfo,
bool active)
: CScriptActor(uid, name, info, xf, std::move(mData), aabox, mass, zMomentum, matList, hInfo, dVuln, aParams, false,
active, 0, 1.f, false, false, false, false)
2017-05-09 13:27:07 +00:00
, x300_flameThrowerGen(g_SimplePool->GetObj("FlameThrower"))
2017-05-20 07:41:49 +00:00
, x308_flameFxId(part)
2018-12-08 05:30:43 +00:00
, x30c_dInfo(dInfo) {}
2017-05-07 06:55:01 +00:00
2017-05-20 07:41:49 +00:00
void MP1::CActorContraption::Accept(IVisitor& visitor) { visitor.Visit(this); }
2018-12-08 05:30:43 +00:00
void MP1::CActorContraption::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
bool curActive = GetActive();
switch (msg) {
case EScriptObjectMessage::Registered:
2018-12-08 05:30:43 +00:00
AddMaterial(EMaterialTypes::ScanPassthrough, mgr);
break;
case EScriptObjectMessage::Deleted:
for (const std::pair<TUniqueId, std::string>& p : x2e8_children)
mgr.FreeScriptObject(p.first);
x2e8_children.clear();
break;
case EScriptObjectMessage::SetToZero:
2018-12-08 05:30:43 +00:00
ResetFlameThrowers(mgr);
break;
default:
break;
}
2017-05-20 07:41:49 +00:00
2018-12-08 05:30:43 +00:00
CScriptActor::AcceptScriptMsg(msg, uid, mgr);
if (curActive != GetActive() && !GetActive()) {
ResetFlameThrowers(mgr);
CActor::RemoveEmitter();
}
2017-05-07 06:55:01 +00:00
}
2017-05-09 13:27:07 +00:00
2018-12-08 05:30:43 +00:00
void MP1::CActorContraption::Think(float dt, CStateManager& mgr) {
CScriptActor::Think(dt, mgr);
2017-05-09 13:27:07 +00:00
for (const auto& [uid, name] : x2e8_children) {
auto* act = static_cast<CFlameThrower*>(mgr.ObjectById(uid));
2017-05-09 13:27:07 +00:00
if (act && act->GetActive()) {
act->SetTransform(x34_transform * GetScaledLocatorTransform(name), dt);
}
2018-12-08 05:30:43 +00:00
}
}
2018-12-08 05:30:43 +00:00
void MP1::CActorContraption::ResetFlameThrowers(CStateManager& mgr) {
for (const std::pair<TUniqueId, std::string>& uid : x2e8_children) {
CFlameThrower* act = static_cast<CFlameThrower*>(mgr.ObjectById(uid.first));
if (act && act->GetParticlesActive())
2018-12-08 05:30:43 +00:00
act->Reset(mgr, false);
}
2017-05-20 07:41:49 +00:00
}
2018-12-08 05:30:43 +00:00
void MP1::CActorContraption::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType evType,
float dt) {
if (evType == EUserEventType::DamageOff) {
ResetFlameThrowers(mgr);
} else if (evType == EUserEventType::DamageOn) {
CFlameThrower* fl = CreateFlameThrower(node.GetLocatorName(), mgr);
if (fl && !fl->GetParticlesActive())
2018-12-08 05:30:43 +00:00
fl->Fire(GetTransform(), mgr, false);
} else
CActor::DoUserAnimEvent(mgr, node, evType, dt);
}
2018-12-08 05:30:43 +00:00
CFlameThrower* MP1::CActorContraption::CreateFlameThrower(std::string_view name, CStateManager& mgr) {
2021-06-07 19:29:18 +00:00
const auto it =
std::find_if(x2e8_children.cbegin(), x2e8_children.cend(), [&name](const auto& p) { return p.second == name; });
2017-05-20 07:41:49 +00:00
if (it != x2e8_children.cend()) {
return static_cast<CFlameThrower*>(mgr.ObjectById(it->first));
}
2017-05-20 07:41:49 +00:00
const TUniqueId id = mgr.AllocateUniqueId();
const CFlameInfo flameInfo(6, 6, x308_flameFxId, 20, 0.5f, 1.f, 1.f);
auto* ret = new CFlameThrower(x300_flameThrowerGen, name, EWeaponType::Missile, flameInfo, zeus::CTransform(),
EMaterialTypes::CollisionActor, x30c_dInfo, id, GetAreaId(), GetUniqueId(),
EProjectileAttrib::None, -1, -1, -1);
2017-05-20 07:41:49 +00:00
x2e8_children.emplace_back(id, name);
mgr.AddObject(ret);
return ret;
2017-02-03 23:32:15 +00:00
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce