2017-02-03 23:32:15 +00:00
|
|
|
#include "MP1/World/CActorContraption.hpp"
|
2017-05-09 13:27:07 +00:00
|
|
|
#include "Weapon/CFlameThrower.hpp"
|
2017-05-20 07:41:49 +00:00
|
|
|
#include "Weapon/CFlameInfo.hpp"
|
2017-05-18 10:58:15 +00:00
|
|
|
#include "Character/CInt32POINode.hpp"
|
2017-05-09 13:27:07 +00:00
|
|
|
#include "GameGlobalObjects.hpp"
|
|
|
|
#include "CSimplePool.hpp"
|
|
|
|
#include "CStateManager.hpp"
|
2017-05-07 06:55:01 +00:00
|
|
|
#include "TCastTo.hpp"
|
2017-02-03 23:32:15 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
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();
|
|
|
|
if (msg == EScriptObjectMessage::Registered)
|
|
|
|
AddMaterial(EMaterialTypes::ScanPassthrough, mgr);
|
|
|
|
else if (msg == EScriptObjectMessage::SetToZero)
|
|
|
|
ResetFlameThrowers(mgr);
|
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())
|
|
|
|
return;
|
2017-05-20 07:41:49 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
ResetFlameThrowers(mgr);
|
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
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const std::pair<TUniqueId, std::string>& uid : x2e8_children) {
|
|
|
|
CFlameThrower* act = static_cast<CFlameThrower*>(mgr.ObjectById(uid.first));
|
2017-05-09 13:27:07 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (act && act->GetActive())
|
2018-12-31 08:37:52 +00:00
|
|
|
act->SetTransform(x34_transform * act->GetScaledLocatorTransform(uid.second), dt);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-05-18 10:58:15 +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->GetX400_25())
|
|
|
|
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->GetX400_25())
|
|
|
|
fl->Fire(GetTransform(), mgr, false);
|
|
|
|
} else
|
|
|
|
CActor::DoUserAnimEvent(mgr, node, evType, dt);
|
2017-05-18 10:58:15 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CFlameThrower* MP1::CActorContraption::CreateFlameThrower(std::string_view name, CStateManager& mgr) {
|
|
|
|
const auto& it = std::find_if(x2e8_children.begin(), x2e8_children.end(),
|
|
|
|
[&name](const std::pair<TUniqueId, std::string>& p) { return p.second == name; });
|
2017-05-20 07:41:49 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (it == x2e8_children.end()) {
|
|
|
|
TUniqueId id = mgr.AllocateUniqueId();
|
|
|
|
CFlameInfo flameInfo(6, 6, x308_flameFxId, 20, 0.5f, 1.f, 1.f);
|
|
|
|
CFlameThrower* ret = new CFlameThrower(x300_flameThrowerGen, name, EWeaponType::Missile, flameInfo,
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CTransform(), EMaterialTypes::CollisionActor, x30c_dInfo, id,
|
2018-12-08 05:30:43 +00:00
|
|
|
GetAreaId(), GetUniqueId(), EProjectileAttrib::None, -1, -1, -1);
|
2017-05-20 07:41:49 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x2e8_children.emplace_back(id, name);
|
2017-05-20 07:41:49 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.AddObject(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return static_cast<CFlameThrower*>(mgr.ObjectById(it->first));
|
2017-02-03 23:32:15 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|