2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/Weapon/CFlameThrower.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CSimplePool.hpp"
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/Collision/CInternalRayCastStructure.hpp"
|
|
|
|
#include "Runtime/Graphics/CBooRenderer.hpp"
|
|
|
|
#include "Runtime/Particle/CElementGen.hpp"
|
|
|
|
#include "Runtime/Weapon/CFlameInfo.hpp"
|
|
|
|
#include "Runtime/Weapon/CFlameThrower.hpp"
|
|
|
|
#include "Runtime/World/CGameLight.hpp"
|
|
|
|
#include "Runtime/World/CPlayer.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2019-04-16 08:00:46 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2017-05-09 13:27:07 +00:00
|
|
|
const zeus::CVector3f CFlameThrower::kLightOffset(0, 3.f, 2.f);
|
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
CFlameThrower::CFlameThrower(const TToken<CWeaponDescription>& wDesc, std::string_view name, EWeaponType wType,
|
2017-05-09 13:27:07 +00:00
|
|
|
const CFlameInfo& flameInfo, const zeus::CTransform& xf, EMaterialTypes matType,
|
2017-09-05 03:00:19 +00:00
|
|
|
const CDamageInfo& dInfo, TUniqueId uid, TAreaId aId, TUniqueId owner,
|
2019-06-30 07:29:49 +00:00
|
|
|
EProjectileAttrib attribs, CAssetId playerSteamTxtr, s16 playerHitSfx,
|
|
|
|
CAssetId playerIceTxtr)
|
2017-09-05 03:00:19 +00:00
|
|
|
: CGameProjectile(false, wDesc, name, wType, xf, matType, dInfo, uid, aId, owner, kInvalidUniqueId, attribs, false,
|
2017-05-09 13:27:07 +00:00
|
|
|
zeus::CVector3f(1.f), {}, -1, false)
|
2019-06-12 02:05:17 +00:00
|
|
|
, x2e8_flameXf(xf)
|
2019-04-16 08:00:46 +00:00
|
|
|
, x338_(flameInfo.x10_)
|
2017-05-11 19:42:43 +00:00
|
|
|
, x33c_flameDesc(g_SimplePool->GetObj({FOURCC('PART'), flameInfo.GetFlameFxId()}))
|
2019-09-12 03:50:38 +00:00
|
|
|
, x348_flameGen(std::make_unique<CElementGen>(x33c_flameDesc))
|
2019-06-12 02:05:17 +00:00
|
|
|
, x34c_flameWarp(176.f - float(flameInfo.GetLength()), xf.origin, bool(flameInfo.GetAttributes() & 0x4))
|
2019-06-30 07:29:49 +00:00
|
|
|
, x3f4_playerSteamTxtr(playerSteamTxtr)
|
|
|
|
, x3f8_playerHitSfx(playerHitSfx)
|
|
|
|
, x3fc_playerIceTxtr(playerIceTxtr)
|
2020-04-11 04:49:02 +00:00
|
|
|
, x400_26_((flameInfo.GetAttributes() & 1) == 0)
|
|
|
|
, x400_27_coneCollision((flameInfo.GetAttributes() & 0x2) != 0) {}
|
2017-05-09 13:27:07 +00:00
|
|
|
|
2017-05-10 10:03:29 +00:00
|
|
|
void CFlameThrower::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
|
|
|
|
2019-05-10 02:33:56 +00:00
|
|
|
void CFlameThrower::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
if (msg == EScriptObjectMessage::Registered) {
|
2020-05-10 02:05:53 +00:00
|
|
|
xe6_27_thermalVisorFlags = 2;
|
2019-05-10 02:33:56 +00:00
|
|
|
mgr.AddWeaponId(xec_ownerId, xf0_weaponType);
|
|
|
|
} else if (msg == EScriptObjectMessage::Deleted) {
|
|
|
|
mgr.RemoveWeaponId(xec_ownerId, xf0_weaponType);
|
|
|
|
DeleteProjectileLight(mgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
CGameProjectile::AcceptScriptMsg(msg, uid, mgr);
|
|
|
|
}
|
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
void CFlameThrower::SetTransform(const zeus::CTransform& xf, float) { x2e8_flameXf = xf; }
|
2017-05-18 10:58:15 +00:00
|
|
|
|
2019-05-10 02:33:56 +00:00
|
|
|
void CFlameThrower::Reset(CStateManager& mgr, bool resetWarp) {
|
|
|
|
SetFlameLightActive(mgr, false);
|
|
|
|
if (resetWarp) {
|
|
|
|
SetActive(false);
|
2019-06-12 02:05:17 +00:00
|
|
|
x400_25_particlesActive = false;
|
|
|
|
x3f0_flameState = EFlameState::Default;
|
|
|
|
x330_particleWaitDelayTimer = 0.f;
|
|
|
|
x334_fireStopTimer = 0.f;
|
|
|
|
x318_flameBounds = zeus::skNullBox;
|
2019-05-10 02:33:56 +00:00
|
|
|
x348_flameGen->SetParticleEmission(false);
|
2019-06-12 02:05:17 +00:00
|
|
|
x34c_flameWarp.ResetPosition(x2e8_flameXf.origin);
|
2019-05-10 02:33:56 +00:00
|
|
|
} else {
|
|
|
|
x348_flameGen->SetParticleEmission(false);
|
2019-06-12 02:05:17 +00:00
|
|
|
x400_25_particlesActive = false;
|
|
|
|
x3f0_flameState = EFlameState::FireStopTimer;
|
2019-05-10 02:33:56 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-18 10:58:15 +00:00
|
|
|
|
2019-04-16 08:00:46 +00:00
|
|
|
void CFlameThrower::Fire(const zeus::CTransform&, CStateManager& mgr, bool) {
|
|
|
|
SetActive(true);
|
2019-06-12 02:05:17 +00:00
|
|
|
x400_25_particlesActive = true;
|
|
|
|
x400_24_active = true;
|
|
|
|
x3f0_flameState = EFlameState::FireStart;
|
2019-04-16 08:00:46 +00:00
|
|
|
CreateFlameParticles(mgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFlameThrower::CreateFlameParticles(CStateManager& mgr) {
|
|
|
|
DeleteProjectileLight(mgr);
|
2019-09-12 03:50:38 +00:00
|
|
|
x348_flameGen = std::make_unique<CElementGen>(x33c_flameDesc);
|
2019-04-16 08:00:46 +00:00
|
|
|
x348_flameGen->SetParticleEmission(true);
|
2019-06-16 02:22:23 +00:00
|
|
|
x348_flameGen->SetZTest(x400_27_coneCollision);
|
2019-06-12 02:05:17 +00:00
|
|
|
x348_flameGen->AddModifier(&x34c_flameWarp);
|
2019-04-16 08:00:46 +00:00
|
|
|
if (x348_flameGen->SystemHasLight() && x2c8_projectileLight == kInvalidUniqueId)
|
|
|
|
CreateProjectileLight("FlameThrower_Light"sv, x348_flameGen->GetLight(), mgr);
|
|
|
|
}
|
|
|
|
|
2020-04-05 11:54:02 +00:00
|
|
|
void CFlameThrower::AddToRenderer(const zeus::CFrustum&, CStateManager& mgr) {
|
2019-04-16 08:00:46 +00:00
|
|
|
g_Renderer->AddParticleGen(*x348_flameGen);
|
2019-06-12 02:05:17 +00:00
|
|
|
EnsureRendered(mgr, x2e8_flameXf.origin, GetRenderBounds());
|
2019-04-16 08:00:46 +00:00
|
|
|
}
|
2019-05-10 02:33:56 +00:00
|
|
|
|
2020-04-09 17:28:20 +00:00
|
|
|
void CFlameThrower::Render(CStateManager&) {}
|
2020-03-04 11:49:49 +00:00
|
|
|
|
|
|
|
std::optional<zeus::CAABox> CFlameThrower::GetTouchBounds() const { return std::nullopt; }
|
|
|
|
|
|
|
|
void CFlameThrower::Touch(CActor&, CStateManager&) {}
|
|
|
|
|
2019-05-10 02:33:56 +00:00
|
|
|
void CFlameThrower::SetFlameLightActive(CStateManager& mgr, bool active) {
|
|
|
|
if (x2c8_projectileLight == kInvalidUniqueId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (TCastToPtr<CGameLight> light = mgr.ObjectById(x2c8_projectileLight))
|
|
|
|
light->SetActive(active);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFlameThrower::UpdateFlameState(float dt, CStateManager& mgr) {
|
2021-06-07 19:29:18 +00:00
|
|
|
switch (x3f0_flameState) {
|
2019-06-12 02:05:17 +00:00
|
|
|
case EFlameState::FireStart:
|
|
|
|
x3f0_flameState = EFlameState::FireActive;
|
2019-05-10 02:33:56 +00:00
|
|
|
break;
|
2019-06-12 02:05:17 +00:00
|
|
|
case EFlameState::FireStopTimer:
|
|
|
|
x334_fireStopTimer += 4.f * dt;
|
|
|
|
if (x334_fireStopTimer > 1.f) {
|
|
|
|
x334_fireStopTimer = 1.f;
|
|
|
|
x3f0_flameState = EFlameState::FireWaitForParticlesDone;
|
|
|
|
x400_24_active = false;
|
2019-05-10 02:33:56 +00:00
|
|
|
}
|
|
|
|
break;
|
2019-06-12 02:05:17 +00:00
|
|
|
case EFlameState::FireWaitForParticlesDone:
|
|
|
|
x330_particleWaitDelayTimer += dt;
|
|
|
|
if (x330_particleWaitDelayTimer > 0.1f && x348_flameGen && x348_flameGen->GetParticleCountAll() == 0) {
|
|
|
|
x3f0_flameState = EFlameState::Default;
|
2019-05-10 02:33:56 +00:00
|
|
|
Reset(mgr, true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
CRayCastResult CFlameThrower::DoCollisionCheck(TUniqueId& idOut, const zeus::CAABox& aabb, CStateManager& mgr) {
|
|
|
|
CRayCastResult ret;
|
2021-06-07 00:07:45 +00:00
|
|
|
EntityList nearList;
|
2019-06-12 02:05:17 +00:00
|
|
|
mgr.BuildNearList(nearList, aabb, CMaterialFilter::skPassEverything, this);
|
2019-06-16 02:22:23 +00:00
|
|
|
const auto& colPoints = x34c_flameWarp.GetCollisionPoints();
|
2020-03-18 01:53:39 +00:00
|
|
|
|
|
|
|
if (x400_27_coneCollision && !colPoints.empty()) {
|
|
|
|
const float radiusPitch =
|
|
|
|
(x34c_flameWarp.GetMaxSize() - x34c_flameWarp.GetMinSize()) / float(colPoints.size()) * 0.5f;
|
2019-06-16 02:22:23 +00:00
|
|
|
float curRadius = radiusPitch;
|
2020-03-18 01:53:39 +00:00
|
|
|
|
|
|
|
for (size_t i = 1; i < colPoints.size(); ++i) {
|
|
|
|
const zeus::CVector3f delta = colPoints[i] - colPoints[i - 1];
|
2019-06-16 02:22:23 +00:00
|
|
|
zeus::CTransform lookXf = zeus::lookAt(colPoints[i - 1], colPoints[i]);
|
|
|
|
lookXf.origin = delta * 0.5f + colPoints[i - 1];
|
2020-03-18 01:53:39 +00:00
|
|
|
const zeus::COBBox obb(lookXf, {curRadius, delta.magnitude() * 0.5f, curRadius});
|
|
|
|
|
2020-09-18 21:04:50 +00:00
|
|
|
for (const auto& id : nearList) {
|
2020-03-18 01:53:39 +00:00
|
|
|
if (auto* act = static_cast<CActor*>(mgr.ObjectById(id))) {
|
|
|
|
const CProjectileTouchResult tres = CanCollideWith(*act, mgr);
|
|
|
|
if (tres.GetActorId() == kInvalidUniqueId) {
|
2019-06-12 02:05:17 +00:00
|
|
|
continue;
|
2020-03-18 01:53:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto tb = act->GetTouchBounds();
|
|
|
|
if (!tb) {
|
2019-06-12 02:05:17 +00:00
|
|
|
continue;
|
2020-03-18 01:53:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
if (obb.AABoxIntersectsBox(*tb)) {
|
2020-03-18 01:53:39 +00:00
|
|
|
const CCollidableAABox caabb(*tb, act->GetMaterialList());
|
|
|
|
const zeus::CVector3f flameToAct = act->GetAimPosition(mgr, 0.f) - x2e8_flameXf.origin;
|
|
|
|
const float flameToActDist = flameToAct.magnitude();
|
|
|
|
const CInternalRayCastStructure rc(x2e8_flameXf.origin, flameToAct.normalized(), flameToActDist, {},
|
|
|
|
CMaterialFilter::skPassEverything);
|
|
|
|
const CRayCastResult cres = caabb.CastRayInternal(rc);
|
|
|
|
if (cres.IsInvalid()) {
|
2019-06-12 02:05:17 +00:00
|
|
|
continue;
|
2020-03-18 01:53:39 +00:00
|
|
|
}
|
2019-06-12 02:05:17 +00:00
|
|
|
return cres;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-18 01:53:39 +00:00
|
|
|
|
2019-06-16 02:22:23 +00:00
|
|
|
curRadius += radiusPitch;
|
2019-06-12 02:05:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-18 01:53:39 +00:00
|
|
|
for (size_t i = 0; i < colPoints.size() - 1; ++i) {
|
|
|
|
const zeus::CVector3f delta = colPoints[i + 1] - colPoints[i];
|
|
|
|
const float deltaMag = delta.magnitude();
|
|
|
|
if (deltaMag <= 0.f) {
|
2019-06-12 02:05:17 +00:00
|
|
|
break;
|
2020-03-18 01:53:39 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 19:29:18 +00:00
|
|
|
const CRayCastResult cres =
|
|
|
|
RayCollisionCheckWithWorld(idOut, colPoints[i], colPoints[i + 1], deltaMag, nearList, mgr);
|
2020-03-18 01:53:39 +00:00
|
|
|
if (cres.IsValid()) {
|
2019-06-12 02:05:17 +00:00
|
|
|
return cres;
|
2020-03-18 01:53:39 +00:00
|
|
|
}
|
2019-06-12 02:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-18 01:53:39 +00:00
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFlameThrower::ApplyDamageToActor(CStateManager& mgr, TUniqueId id, float dt) {
|
|
|
|
if (mgr.GetPlayer().GetUniqueId() == id && x3f4_playerSteamTxtr.IsValid() && x3fc_playerIceTxtr.IsValid())
|
|
|
|
mgr.GetPlayer().Freeze(mgr, x3f4_playerSteamTxtr, x3f8_playerHitSfx, x3fc_playerIceTxtr);
|
|
|
|
CDamageInfo useDInfo = CDamageInfo(x12c_curDamageInfo, dt);
|
|
|
|
ApplyDamageToActors(mgr, useDInfo);
|
|
|
|
}
|
|
|
|
|
2019-05-10 02:33:56 +00:00
|
|
|
void CFlameThrower::Think(float dt, CStateManager& mgr) {
|
|
|
|
CWeapon::Think(dt, mgr);
|
|
|
|
if (!GetActive())
|
|
|
|
return;
|
|
|
|
|
|
|
|
UpdateFlameState(dt, mgr);
|
2019-06-12 02:05:17 +00:00
|
|
|
|
|
|
|
zeus::CVector3f flamePoint = x2e8_flameXf.origin;
|
|
|
|
bool r28 = x3f0_flameState == EFlameState::FireActive || x3f0_flameState == EFlameState::FireStopTimer;
|
|
|
|
if (r28) {
|
|
|
|
x34c_flameWarp.Activate(true);
|
|
|
|
x34c_flameWarp.SetWarpPoint(flamePoint);
|
|
|
|
x34c_flameWarp.SetStateManager(mgr);
|
|
|
|
x348_flameGen->SetTranslation(flamePoint);
|
|
|
|
x348_flameGen->SetOrientation(x2e8_flameXf.getRotation());
|
|
|
|
} else {
|
|
|
|
x34c_flameWarp.Activate(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
x348_flameGen->Update(dt);
|
|
|
|
x34c_flameWarp.SetMaxDistSq(0.f);
|
|
|
|
x34c_flameWarp.SetFloatingPoint(flamePoint);
|
|
|
|
|
|
|
|
if (r28 && x34c_flameWarp.IsProcessed()) {
|
|
|
|
x318_flameBounds = x34c_flameWarp.CalculateBounds();
|
|
|
|
TUniqueId id = kInvalidUniqueId;
|
2020-05-10 02:28:35 +00:00
|
|
|
const CRayCastResult res = DoCollisionCheck(id, x318_flameBounds, mgr);
|
|
|
|
if (TCastToConstPtr<CActor>(mgr.ObjectById(id))) {
|
2019-06-12 02:05:17 +00:00
|
|
|
ApplyDamageToActor(mgr, id, dt);
|
|
|
|
} else if (res.IsValid()) {
|
2020-05-10 02:28:35 +00:00
|
|
|
const CMaterialFilter useFilter = xf8_filter;
|
|
|
|
const CDamageInfo useDInfo = CDamageInfo(x12c_curDamageInfo, dt);
|
2019-06-12 02:05:17 +00:00
|
|
|
mgr.ApplyDamageToWorld(xec_ownerId, *this, res.GetPoint(), useDInfo, useFilter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CActor::SetTransform(x2e8_flameXf.getRotation());
|
|
|
|
CActor::SetTranslation(x2e8_flameXf.origin);
|
|
|
|
|
|
|
|
if (x2c8_projectileLight != kInvalidUniqueId) {
|
|
|
|
if (TCastToPtr<CGameLight> light = mgr.ObjectById(x2c8_projectileLight)) {
|
|
|
|
light->SetTransform(GetTransform());
|
|
|
|
light->SetTranslation(x34c_flameWarp.GetFloatingPoint());
|
|
|
|
if (x348_flameGen && x348_flameGen->SystemHasLight())
|
|
|
|
light->SetLight(x348_flameGen->GetLight());
|
|
|
|
}
|
|
|
|
}
|
2019-05-10 02:33:56 +00:00
|
|
|
}
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|