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
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
MP1::CActorContraption::CActorContraption(TUniqueId uid, const std::string& name, const CEntityInfo& info,
|
|
|
|
const zeus::CTransform& xf, CModelData&& mData, const zeus::CAABox& aabox,
|
2017-05-21 06:01:24 +00:00
|
|
|
const CMaterialList& matList, float mass, float zMomentum, const CHealthInfo& hInfo,
|
2017-02-03 23:32:15 +00:00
|
|
|
const CDamageVulnerability& dVuln, const CActorParameters& aParams,
|
|
|
|
ResId part, const CDamageInfo& dInfo, bool active)
|
2017-05-21 06:01:24 +00:00
|
|
|
: CScriptActor(uid, name, info, xf, std::move(mData), aabox, mass, zMomentum, matList, hInfo, dVuln, aParams, false, active, 0,
|
2017-05-09 13:27:07 +00:00
|
|
|
1.f, false, false, false, false)
|
|
|
|
, x300_flameThrowerGen(g_SimplePool->GetObj("FlameThrower"))
|
2017-05-20 07:41:49 +00:00
|
|
|
, x308_flameFxId(part)
|
2017-05-09 13:27:07 +00:00
|
|
|
, x30c_dInfo(dInfo)
|
2017-02-03 23:32:15 +00:00
|
|
|
{
|
|
|
|
}
|
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); }
|
|
|
|
|
|
|
|
void MP1::CActorContraption::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr)
|
2017-05-07 06:55:01 +00:00
|
|
|
{
|
2017-05-20 07:41:49 +00:00
|
|
|
bool curActive = GetActive();
|
|
|
|
if (msg == EScriptObjectMessage::Registered)
|
|
|
|
AddMaterial(EMaterialTypes::ScanPassthrough, mgr);
|
|
|
|
else if (msg == EScriptObjectMessage::SetToZero)
|
|
|
|
ResetFlameThrowers(mgr);
|
|
|
|
|
|
|
|
AcceptScriptMsg(msg, uid, mgr);
|
|
|
|
if (curActive == GetActive() || !GetActive())
|
|
|
|
return;
|
|
|
|
|
|
|
|
ResetFlameThrowers(mgr);
|
2017-05-07 06:55:01 +00:00
|
|
|
}
|
2017-05-09 13:27:07 +00:00
|
|
|
|
|
|
|
void MP1::CActorContraption::Think(float dt, CStateManager& mgr)
|
|
|
|
{
|
|
|
|
CScriptActor::Think(dt, mgr);
|
|
|
|
|
2017-05-20 07:41:49 +00:00
|
|
|
for (const std::pair<TUniqueId, std::string>& uid : x2e8_children)
|
2017-05-09 13:27:07 +00:00
|
|
|
{
|
|
|
|
CFlameThrower* act = static_cast<CFlameThrower*>(mgr.ObjectById(uid.first));
|
|
|
|
|
|
|
|
if (act && act->GetActive())
|
2017-05-10 00:03:20 +00:00
|
|
|
act->SetTransform(x34_transform * act->GetScaledLocatorTransform(uid.second));
|
2017-05-18 10:58:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 07:41:49 +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-18 10:58:15 +00:00
|
|
|
void MP1::CActorContraption::DoUserAnimEvent(CStateManager& mgr, CInt32POINode& node, EUserEventType evType)
|
|
|
|
{
|
|
|
|
if (evType == EUserEventType::DamageOff)
|
|
|
|
{
|
2017-05-20 07:41:49 +00:00
|
|
|
ResetFlameThrowers(mgr);
|
2017-05-09 13:27:07 +00:00
|
|
|
}
|
2017-05-18 10:58:15 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-05-20 07:41:49 +00:00
|
|
|
CFlameThrower* MP1::CActorContraption::CreateFlameThrower(const std::string& name, CStateManager& mgr)
|
2017-05-18 10:58:15 +00:00
|
|
|
{
|
2017-05-21 06:01:24 +00:00
|
|
|
const auto& it = std::find_if(x2e8_children.begin(), x2e8_children.end(),
|
2017-05-20 07:41:49 +00:00
|
|
|
[&name](const std::pair<TUniqueId, std::string>& p) { return p.second == name; });
|
|
|
|
|
|
|
|
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,
|
|
|
|
zeus::CTransform::Identity(), EMaterialTypes::CollisionActor, x30c_dInfo,
|
|
|
|
id, GetAreaId(), GetUniqueId(), 0, -1, -1, -1);
|
|
|
|
|
|
|
|
x2e8_children.emplace_back(id, name);
|
|
|
|
|
|
|
|
mgr.AddObject(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-05-21 06:01:24 +00:00
|
|
|
return static_cast<CFlameThrower*>(mgr.ObjectById(it->first));
|
2017-05-09 13:27:07 +00:00
|
|
|
}
|
2017-02-03 23:32:15 +00:00
|
|
|
}
|