2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CScriptBallTrigger.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/World/CMorphBall.hpp"
|
|
|
|
#include "Runtime/World/CPlayer.hpp"
|
|
|
|
|
2018-05-08 02:18:18 +00:00
|
|
|
#include "DNAMP1/Tweaks/CTweakPlayer.hpp"
|
2019-12-22 20:04:07 +00:00
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2018-05-08 02:18:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2018-05-08 02:18:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
static zeus::CAABox calculate_ball_aabox() {
|
|
|
|
float extent = 0.33f * g_tweakPlayer->GetPlayerBallHalfExtent();
|
|
|
|
return {-extent, extent};
|
2018-05-08 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CScriptBallTrigger::CScriptBallTrigger(TUniqueId uid, std::string_view name, const CEntityInfo& info,
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CVector3f& pos, const zeus::CVector3f& scale, bool active, float f1,
|
|
|
|
float f2, float f3, const zeus::CVector3f& vec, bool b2)
|
|
|
|
: CScriptTrigger(uid, name, info, pos, calculate_ball_aabox(), CDamageInfo(CWeaponMode::Power(), 0.f, 0.f, 0.f),
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::skZero3f, ETriggerFlags::DetectMorphedPlayer, active, false, false)
|
2018-12-08 05:30:43 +00:00
|
|
|
, x150_force(f1)
|
|
|
|
, x154_minAngle(f2)
|
|
|
|
, x158_maxDistance(f3)
|
|
|
|
, x168_24_canApplyForce(false)
|
|
|
|
, x168_25_stopPlayer(b2) {
|
2018-05-08 02:18:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (vec.canBeNormalized())
|
|
|
|
x15c_forceAngle = vec.normalized();
|
2018-05-08 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptBallTrigger::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2018-05-08 02:18:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptBallTrigger::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
if (msg == EScriptObjectMessage::Deactivate && GetActive()) {
|
|
|
|
mgr.GetPlayer().GetMorphBall()->SetBallBoostState(CMorphBall::EBallBoostState::BoostAvailable);
|
|
|
|
x168_24_canApplyForce = false;
|
|
|
|
}
|
2018-05-08 02:18:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CScriptTrigger::AcceptScriptMsg(msg, uid, mgr);
|
2018-05-08 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptBallTrigger::Think(float dt, CStateManager& mgr) {
|
|
|
|
if (!GetActive())
|
|
|
|
return;
|
|
|
|
CScriptTrigger::Think(dt, mgr);
|
|
|
|
CPlayer& player = mgr.GetPlayer();
|
2018-05-08 02:18:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (player.GetMorphballTransitionState() != CPlayer::EPlayerMorphBallState::Morphed) {
|
|
|
|
x168_24_canApplyForce = false;
|
|
|
|
return;
|
|
|
|
}
|
2018-05-08 02:18:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const float ballRadius = player.GetMorphBall()->GetBallRadius();
|
|
|
|
const zeus::CVector3f radiusPosDif =
|
|
|
|
(player.GetTranslation() - (player.GetTranslation() + zeus::CVector3f{0.f, 0.f, ballRadius}));
|
|
|
|
const float distance = radiusPosDif.magnitude();
|
2018-05-08 02:18:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!x168_24_canApplyForce) {
|
|
|
|
if (distance < ballRadius)
|
|
|
|
x168_24_canApplyForce = true;
|
|
|
|
else {
|
|
|
|
zeus::CVector3f offset = radiusPosDif.normalized();
|
|
|
|
if (std::cos(zeus::degToRad(x154_minAngle)) < (-offset).dot(x15c_forceAngle) && distance < x158_maxDistance) {
|
|
|
|
float force = zeus::min((1.f / dt * distance), x150_force * (distance * distance));
|
2019-02-24 07:15:54 +00:00
|
|
|
player.ApplyForceWR(force * (player.GetMass() * offset), zeus::CAxisAngle());
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-05-08 02:18:18 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-05-08 02:18:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x148_28_playerTriggerProc) {
|
|
|
|
zeus::CVector3f offset = GetTranslation() - zeus::CVector3f(0.f, 0.f, ballRadius);
|
|
|
|
if (x168_25_stopPlayer)
|
|
|
|
player.Stop();
|
|
|
|
player.MoveToWR(offset, dt);
|
|
|
|
} else
|
|
|
|
x168_24_canApplyForce = false;
|
2018-05-08 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptBallTrigger::InhabitantAdded(CActor& act, CStateManager& /*mgr*/) {
|
|
|
|
if (TCastToPtr<CPlayer> player = act)
|
|
|
|
player->GetMorphBall()->SetBallBoostState(CMorphBall::EBallBoostState::BoostDisabled);
|
2018-05-08 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptBallTrigger::InhabitantExited(CActor& act, CStateManager&) {
|
|
|
|
if (TCastToPtr<CPlayer> player = act) {
|
|
|
|
player->GetMorphBall()->SetBallBoostState(CMorphBall::EBallBoostState::BoostAvailable);
|
|
|
|
x168_24_canApplyForce = false;
|
|
|
|
}
|
2018-05-08 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|