2016-04-19 21:25:26 +00:00
|
|
|
#include "CScriptTrigger.hpp"
|
|
|
|
#include "Character/CModelData.hpp"
|
|
|
|
#include "CActorParameters.hpp"
|
|
|
|
#include "Collision/CMaterialList.hpp"
|
2016-04-29 10:08:46 +00:00
|
|
|
#include "CStateManager.hpp"
|
2017-01-15 03:07:01 +00:00
|
|
|
#include "TCastTo.hpp"
|
2017-01-15 03:59:37 +00:00
|
|
|
#include "World/CPlayer.hpp"
|
|
|
|
#include "Weapon/CGameProjectile.hpp"
|
|
|
|
#include "Weapon/CWeapon.hpp"
|
2017-02-12 04:43:33 +00:00
|
|
|
#include "Particle/CGenDescription.hpp"
|
2017-01-15 03:59:37 +00:00
|
|
|
#include "CPlayerState.hpp"
|
2016-04-19 21:25:26 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
CScriptTrigger::CScriptTrigger(TUniqueId uid, const std::string& name, const CEntityInfo& info,
|
2017-01-15 03:59:37 +00:00
|
|
|
const zeus::CVector3f& pos, const zeus::CAABox& bounds, const CDamageInfo& dInfo,
|
2017-04-22 11:04:07 +00:00
|
|
|
const zeus::CVector3f& forceField, ETriggerFlags triggerFlags, bool active, bool deactivateOnEntered,
|
|
|
|
bool deactivateOnExited)
|
2016-04-19 21:25:26 +00:00
|
|
|
: CActor(uid, active, name, info, zeus::CTransform::Translate(pos), CModelData::CModelDataNull(),
|
2017-01-15 03:59:37 +00:00
|
|
|
CMaterialList(EMaterialTypes::Trigger), CActorParameters::None(), kInvalidUniqueId)
|
|
|
|
, x100_damageInfo(dInfo)
|
|
|
|
, x11c_forceField(forceField)
|
|
|
|
, x128_forceMagnitude(forceField.magnitude())
|
|
|
|
, x12c_flags(triggerFlags)
|
|
|
|
, x130_bounds(bounds)
|
2016-04-19 21:25:26 +00:00
|
|
|
{
|
2017-04-22 11:04:07 +00:00
|
|
|
x148_26_deactivateOnEntered = deactivateOnEntered;
|
|
|
|
x148_27_deactivateOnExited = deactivateOnExited;
|
2016-04-19 21:25:26 +00:00
|
|
|
}
|
|
|
|
|
2017-02-13 21:29:00 +00:00
|
|
|
void CScriptTrigger::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2017-01-15 03:59:37 +00:00
|
|
|
void CScriptTrigger::Think(float dt, CStateManager& mgr)
|
2016-04-29 10:08:46 +00:00
|
|
|
{
|
2017-01-15 03:59:37 +00:00
|
|
|
if (GetActive())
|
|
|
|
UpdateInhabitants(dt, mgr);
|
|
|
|
}
|
2016-11-20 21:53:15 +00:00
|
|
|
|
2017-01-15 03:59:37 +00:00
|
|
|
void CScriptTrigger::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr)
|
|
|
|
{
|
2017-02-14 04:27:20 +00:00
|
|
|
if (GetActive() && (msg == EScriptObjectMessage::Deactivate || msg == EScriptObjectMessage::Deleted))
|
2017-01-15 03:59:37 +00:00
|
|
|
{
|
|
|
|
if (msg == EScriptObjectMessage::Deactivate)
|
|
|
|
{
|
|
|
|
xe8_inhabitants.clear();
|
|
|
|
x148_25_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x148_28_)
|
|
|
|
{
|
|
|
|
x148_28_ = false;
|
|
|
|
if (x148_29_didPhazonDamage)
|
|
|
|
{
|
|
|
|
mgr.Player()->DecrementPhazon();
|
|
|
|
x148_29_didPhazonDamage = false;
|
|
|
|
}
|
|
|
|
|
2017-01-18 22:30:02 +00:00
|
|
|
if (x8_uid == mgr.GetLastTriggerId())
|
|
|
|
mgr.SetLastTriggerId(kInvalidUniqueId);
|
2017-01-15 03:59:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CEntity::AcceptScriptMsg(msg, uid, mgr);
|
2016-04-29 10:08:46 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 03:59:37 +00:00
|
|
|
CScriptTrigger::CObjectTracker* CScriptTrigger::FindObject(TUniqueId id)
|
2016-04-29 10:08:46 +00:00
|
|
|
{
|
2017-01-15 03:59:37 +00:00
|
|
|
auto& inhabitants = GetInhabitants();
|
|
|
|
const auto& iter = std::find(inhabitants.begin(), inhabitants.end(), id);
|
|
|
|
|
|
|
|
if (iter != inhabitants.end())
|
|
|
|
return &(*iter);
|
|
|
|
return nullptr;
|
2016-04-29 10:08:46 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 03:59:37 +00:00
|
|
|
void CScriptTrigger::UpdateInhabitants(float dt, CStateManager& mgr)
|
2016-04-29 10:08:46 +00:00
|
|
|
{
|
2017-01-15 03:59:37 +00:00
|
|
|
#if 0
|
2017-02-13 21:29:00 +00:00
|
|
|
bool inhabitantExited = false;
|
|
|
|
bool player = false;
|
2017-01-15 03:59:37 +00:00
|
|
|
for (auto it = xe8_inhabitants.begin(); it != xe8_inhabitants.end();)
|
|
|
|
{
|
|
|
|
TCastToPtr<CActor> act(mgr.ObjectById((*it).GetObjectId()));
|
|
|
|
if (act->GetUniqueId() == mgr.Player()->GetUniqueId())
|
|
|
|
{
|
|
|
|
TCastToPtr<CPlayer> pl(act);
|
|
|
|
if (bool(x12c_flags & ETriggerFlags::DetectPlayer))
|
|
|
|
{
|
2017-02-13 21:29:00 +00:00
|
|
|
player = true;
|
2017-01-15 03:59:37 +00:00
|
|
|
using EPlayerMorphBallState = CPlayer::EPlayerMorphBallState;
|
|
|
|
EPlayerMorphBallState mState = pl->GetMorphballTransitionState();
|
|
|
|
if ((mState == EPlayerMorphBallState::Morphed &&
|
|
|
|
bool(x12c_flags & ETriggerFlags::DetectMorphedPlayer)) ||
|
|
|
|
(mState == EPlayerMorphBallState::Unmorphed &&
|
|
|
|
bool(x12c_flags & ETriggerFlags::DetectUnmorphedPlayer)))
|
|
|
|
{
|
|
|
|
it = xe8_inhabitants.erase(it);
|
|
|
|
if (x148_28_)
|
|
|
|
{
|
|
|
|
x148_28_ = false;
|
|
|
|
if (x148_29_didPhazonDamage)
|
|
|
|
{
|
|
|
|
mgr.Player()->DecrementPhazon();
|
|
|
|
x148_29_didPhazonDamage = false;
|
|
|
|
}
|
|
|
|
|
2017-02-13 21:29:00 +00:00
|
|
|
if (mgr.GetLastTriggerId() == GetUniqueId())
|
|
|
|
mgr.SetLastTriggerId(kInvalidUniqueId);
|
2017-01-15 03:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InhabitantExited(*act, mgr);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& touchBounds = GetTouchBounds();
|
|
|
|
const auto& actTouchBounds = act->GetTouchBounds();
|
|
|
|
if (touchBounds && actTouchBounds)
|
|
|
|
{
|
|
|
|
if (actTouchBounds->intersects(*touchBounds))
|
|
|
|
{
|
|
|
|
inhabitantExited = true;
|
|
|
|
InhabitantIdle(*act, mgr);
|
|
|
|
if (act->HealthInfo() && x100_damageInfo.GetDamage() > 0.f)
|
2017-02-13 21:29:00 +00:00
|
|
|
mgr.ApplyDamage(GetUniqueId(), act->GetUniqueId(), GetUniqueId(), x100_damageInfo,
|
|
|
|
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {0ull}));
|
2017-01-15 03:59:37 +00:00
|
|
|
|
|
|
|
TCastToPtr<CPhysicsActor> physAct{act};
|
|
|
|
if (physAct)
|
|
|
|
{
|
|
|
|
float forceMult = 1.f;
|
|
|
|
if (bool(x12c_flags & ETriggerFlags::UseBooleanIntersection))
|
2017-02-13 21:29:00 +00:00
|
|
|
forceMult =
|
|
|
|
touchBounds->booleanIntersection(*actTouchBounds).volume() / actTouchBounds->volume();
|
2017-01-15 03:59:37 +00:00
|
|
|
|
|
|
|
zeus::CVector3f force = forceMult * x11c_forceField;
|
|
|
|
if (bool(x12c_flags & ETriggerFlags::UseCollisionImpulses))
|
|
|
|
{
|
|
|
|
physAct->ApplyImpulseWR(force, zeus::CAxisAngle::sIdentity);
|
|
|
|
physAct->UseCollisionImpulses();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
physAct->ApplyForceWR(force, zeus::CAxisAngle::sIdentity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
it = xe8_inhabitants.erase(it);
|
|
|
|
if (mgr.Player()->GetUniqueId() == (*it).GetObjectId())
|
|
|
|
{
|
|
|
|
if (x148_28_)
|
|
|
|
{
|
|
|
|
x148_28_ = false;
|
|
|
|
if (x148_29_didPhazonDamage)
|
|
|
|
{
|
|
|
|
mgr.Player()->DecrementPhazon();
|
|
|
|
x148_29_didPhazonDamage = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 21:29:00 +00:00
|
|
|
if (mgr.GetLastTriggerId() == GetUniqueId())
|
|
|
|
mgr.SetLastTriggerId(kInvalidUniqueId);
|
2017-01-15 03:59:37 +00:00
|
|
|
|
|
|
|
InhabitantExited(*act, mgr);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
it = xe8_inhabitants.erase(it);
|
|
|
|
if (mgr.Player()->GetUniqueId() == (*it).GetObjectId())
|
|
|
|
{
|
|
|
|
if (x148_28_)
|
|
|
|
{
|
|
|
|
x148_28_ = false;
|
|
|
|
if (x148_29_didPhazonDamage)
|
|
|
|
{
|
|
|
|
mgr.Player()->DecrementPhazon();
|
|
|
|
x148_29_didPhazonDamage = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 21:29:00 +00:00
|
|
|
if (mgr.GetLastTriggerId() == GetUniqueId())
|
|
|
|
mgr.SetLastTriggerId(kInvalidUniqueId);
|
2017-01-15 03:59:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bool(x12c_flags & ETriggerFlags::DetectPlayerIfInside) && x148_24_playerInside && !inhabitantExited)
|
|
|
|
{
|
|
|
|
SendScriptMsgs(EScriptObjectState::Inside, mgr, EScriptObjectMessage::None);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!player)
|
|
|
|
{
|
|
|
|
SendScriptMsgs(EScriptObjectState::Exited, mgr, EScriptObjectMessage::None);
|
|
|
|
if (x148_27_deactivateOnExited)
|
|
|
|
{
|
2017-02-13 21:29:00 +00:00
|
|
|
mgr.SendScriptMsg(GetUniqueId(), mgr.GetEditorIdForUniqueId(GetUniqueId()),
|
|
|
|
EScriptObjectMessage::Deactivate, EScriptObjectState::Exited);
|
2017-01-15 03:59:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2016-04-29 10:08:46 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 03:59:37 +00:00
|
|
|
std::list<CScriptTrigger::CObjectTracker>& CScriptTrigger::GetInhabitants() { return xe8_inhabitants; }
|
|
|
|
|
2016-04-29 10:08:46 +00:00
|
|
|
rstl::optional_object<zeus::CAABox> CScriptTrigger::GetTouchBounds() const
|
|
|
|
{
|
|
|
|
if (x30_24_active)
|
|
|
|
return {GetTriggerBoundsWR()};
|
|
|
|
return {};
|
|
|
|
}
|
2017-01-15 03:59:37 +00:00
|
|
|
static const CWeaponMode sktonOHurtWeaponMode = CWeaponMode(EWeaponType::Power, false, false, true);
|
|
|
|
|
|
|
|
void CScriptTrigger::Touch(CActor& act, CStateManager& mgr)
|
|
|
|
{
|
|
|
|
if (!act.GetActive() || act.GetMaterialList().HasMaterial(EMaterialTypes::Trigger))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (FindObject(act.GetUniqueId()) == nullptr)
|
|
|
|
{
|
|
|
|
ETriggerFlags testFlags = ETriggerFlags::None;
|
|
|
|
TCastToPtr<CPlayer> pl(act);
|
|
|
|
if (pl)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (x128_forceMagnitude > 0.f && (x12c_flags & ETriggerFlags::DetectPlayer) != ETriggerFlags::None &&
|
2017-01-18 22:30:02 +00:00
|
|
|
mgr.GetLastTriggerId() == kInvalidUniqueId)
|
|
|
|
mgr.SetLastTriggerId(x8_uid);
|
2017-01-15 03:59:37 +00:00
|
|
|
|
|
|
|
testFlags |= ETriggerFlags::DetectPlayer;
|
|
|
|
if (pl->GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Unmorphed)
|
|
|
|
testFlags |= ETriggerFlags::DetectUnmorphedPlayer;
|
|
|
|
else if (pl->GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Morphed)
|
|
|
|
testFlags |= ETriggerFlags::DetectMorphedPlayer;
|
|
|
|
}
|
|
|
|
else if (TCastToPtr<CAi>(act))
|
|
|
|
{
|
|
|
|
testFlags |= ETriggerFlags::DetectAI;
|
|
|
|
}
|
|
|
|
else if (TCastToPtr<CGameProjectile>(act))
|
|
|
|
{
|
|
|
|
testFlags |= ETriggerFlags::DetectProjectiles1 | ETriggerFlags::DetectProjectiles2 |
|
|
|
|
ETriggerFlags::DetectProjectiles3 | ETriggerFlags::DetectProjectiles4 |
|
|
|
|
ETriggerFlags::DetectProjectiles5 | ETriggerFlags::DetectProjectiles6 |
|
|
|
|
ETriggerFlags::DetectProjectiles7;
|
|
|
|
}
|
|
|
|
else if (CWeapon* weap = TCastToPtr<CWeapon>(act))
|
|
|
|
{
|
|
|
|
if ((weap->GetAttribField() & CWeapon::EProjectileAttrib::Bombs) != CWeapon::EProjectileAttrib::None)
|
|
|
|
testFlags |= ETriggerFlags::DetectBombs;
|
|
|
|
else if ((weap->GetAttribField() & CWeapon::EProjectileAttrib::PowerBombs) !=
|
|
|
|
CWeapon::EProjectileAttrib::None)
|
|
|
|
testFlags |= ETriggerFlags::DetectPowerBombs;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((testFlags & x12c_flags) != ETriggerFlags::None)
|
|
|
|
{
|
|
|
|
xe8_inhabitants.push_back(act.GetUniqueId());
|
|
|
|
InhabitantAdded(act, mgr);
|
|
|
|
|
|
|
|
if (pl)
|
|
|
|
{
|
|
|
|
if (x148_28_ == false)
|
|
|
|
{
|
|
|
|
x148_28_ = true;
|
|
|
|
if (x148_29_didPhazonDamage)
|
|
|
|
{
|
|
|
|
mgr.Player()->DecrementPhazon();
|
|
|
|
x148_29_didPhazonDamage = false;
|
|
|
|
}
|
|
|
|
else if (x100_damageInfo.GetDamage() > 0.f)
|
|
|
|
{
|
|
|
|
const CDamageVulnerability* dVuln = mgr.Player()->GetDamageVulnerability();
|
|
|
|
if (dVuln->WeaponHurts(x100_damageInfo.GetWeaponMode(), 0) &&
|
|
|
|
x100_damageInfo.GetWeaponMode().GetType() == EWeaponType::Phazon &&
|
|
|
|
!mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::PhazonSuit))
|
|
|
|
{
|
|
|
|
pl->IncrementPhazon();
|
|
|
|
x148_29_didPhazonDamage = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SendScriptMsgs(EScriptObjectState::Entered, mgr, EScriptObjectMessage::None);
|
|
|
|
|
|
|
|
if (x148_26_deactivateOnEntered)
|
|
|
|
{
|
|
|
|
mgr.SendScriptMsg(x8_uid, mgr.GetEditorIdForUniqueId(x8_uid), EScriptObjectMessage::Deactivate,
|
|
|
|
EScriptObjectState::Entered);
|
|
|
|
if (act.HealthInfo() && x100_damageInfo.GetDamage() > 0.f)
|
|
|
|
{
|
|
|
|
mgr.ApplyDamage(x8_uid, act.GetUniqueId(), x8_uid, x100_damageInfo,
|
|
|
|
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {0ull}),
|
|
|
|
zeus::CVector3f::skZero);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((x12c_flags & ETriggerFlags::KillOnEnter) != ETriggerFlags::None && act.HealthInfo())
|
|
|
|
{
|
|
|
|
CHealthInfo* hInfo = act.HealthInfo();
|
|
|
|
mgr.ApplyDamage(
|
|
|
|
x8_uid, act.GetUniqueId(), x8_uid, {sktonOHurtWeaponMode, 10.f * hInfo->GetHP(), 0.f, 0.f},
|
|
|
|
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {0ull}), zeus::CVector3f::skZero);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
InhabitantRejected(act, mgr);
|
|
|
|
}
|
|
|
|
}
|
2016-04-29 10:08:46 +00:00
|
|
|
|
|
|
|
zeus::CAABox CScriptTrigger::GetTriggerBoundsWR() const
|
|
|
|
{
|
|
|
|
return {x130_bounds.min + x34_transform.origin, x130_bounds.max + x34_transform.origin};
|
|
|
|
}
|
2016-04-19 21:25:26 +00:00
|
|
|
}
|