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() {
|
2020-05-07 11:58:12 +00:00
|
|
|
const float extent = 0.33f * g_tweakPlayer->GetPlayerBallHalfExtent();
|
2018-12-08 05:30:43 +00:00
|
|
|
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_25_stopPlayer(b2) {
|
2018-05-08 02:18:18 +00:00
|
|
|
|
2020-05-07 11:58:12 +00:00
|
|
|
if (vec.canBeNormalized()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x15c_forceAngle = vec.normalized();
|
2020-05-07 11:58:12 +00:00
|
|
|
}
|
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) {
|
2020-05-07 11:58:12 +00:00
|
|
|
if (!GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-07 11:58:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
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 =
|
2020-06-25 23:33:43 +00:00
|
|
|
GetTranslation() - (player.GetTranslation() + zeus::CVector3f{0.f, 0.f, ballRadius});
|
2018-12-08 05:30:43 +00:00
|
|
|
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) {
|
2020-05-07 11:58:12 +00:00
|
|
|
if (distance < ballRadius) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x168_24_canApplyForce = true;
|
2020-05-07 11:58:12 +00:00
|
|
|
} else {
|
|
|
|
const zeus::CVector3f offset = radiusPosDif.normalized();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (std::cos(zeus::degToRad(x154_minAngle)) < (-offset).dot(x15c_forceAngle) && distance < x158_maxDistance) {
|
2021-04-02 11:56:24 +00:00
|
|
|
const float force = zeus::min((1.f / dt * distance), x150_force * (x158_maxDistance / (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) {
|
2020-05-07 11:58:12 +00:00
|
|
|
const zeus::CVector3f offset = GetTranslation() - zeus::CVector3f(0.f, 0.f, ballRadius);
|
|
|
|
if (x168_25_stopPlayer) {
|
2018-12-08 05:30:43 +00:00
|
|
|
player.Stop();
|
2020-05-07 11:58:12 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
player.MoveToWR(offset, dt);
|
2020-05-07 11:58:12 +00:00
|
|
|
}
|
2018-05-08 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptBallTrigger::InhabitantAdded(CActor& act, CStateManager& /*mgr*/) {
|
2020-05-07 11:58:12 +00:00
|
|
|
if (const TCastToPtr<CPlayer> player = act) {
|
2018-12-08 05:30:43 +00:00
|
|
|
player->GetMorphBall()->SetBallBoostState(CMorphBall::EBallBoostState::BoostDisabled);
|
2020-05-07 11:58:12 +00:00
|
|
|
}
|
2018-05-08 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptBallTrigger::InhabitantExited(CActor& act, CStateManager&) {
|
2020-05-07 11:58:12 +00:00
|
|
|
if (const TCastToPtr<CPlayer> player = act) {
|
2018-12-08 05:30:43 +00:00
|
|
|
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
|