More CFlaahgra imps

This commit is contained in:
Phillip Stephens 2019-06-26 18:06:03 -07:00
parent a1745cff96
commit 44cae7bdb9
5 changed files with 247 additions and 22 deletions

View File

@ -78,7 +78,7 @@ enum class EStepDirection { Invalid = -1, Forward = 0, Backward = 1, Left = 2, R
enum class EStepType { Normal = 0, Dodge = 1, BreakDodge = 2, RollDodge = 3 };
enum class ESeverity { Invalid = -1, Zero = 0, One = 1, Two = 2, Eight = 8 };
enum class ESeverity { Invalid = -1, Zero = 0, One = 1, Two = 2, Three, Four, Seven = 7, Eight = 8 };
enum class EGetupType { Invalid = -1, Zero = 0, One = 1, Two = 2 };

View File

@ -89,7 +89,15 @@ CFlaahgra::CFlaahgra(TUniqueId uid, std::string_view name, const CEntityInfo& in
x460_knockBackController.SetEnableLaggedBurnDeath(false);
x430_damageColor = skDamageColor;
LoadDependencies(x56c_.x158_);
/* TODO: Math that makes me go cross eyed */
float curAngle = zeus::degToRad(17.5f);
while (curAngle < zeus::degToRad(360.f)) {
x82c_.push_back(GetTransform().rotate(zeus::CVector3f(std::cos(curAngle), std::sin(curAngle), 0.f)));
x860_.push_back(GetTransform().rotate(
zeus::CVector3f(std::cos(curAngle + zeus::degToRad(45.f)), std::sin(curAngle + zeus::degToRad(45.f)), 0.f)));
curAngle += zeus::degToRad(90.f);
}
}
void CFlaahgra::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
@ -287,12 +295,10 @@ void CFlaahgra::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, E
CMaterialFilter::MakeInclude({EMaterialTypes::Floor}));
if (res.IsValid()) {
#if 0
CFlaahgraPlants* plants = new CFlaahgraPlants(x6d4_, x56c_.xd8_, mgr.AllocateUniqueId(), GetAreaIdAlways(),
GetUniqueId(), xf, x56c_.xbc_, {5.f, 10.f, 5.f});
mgr.AddObject(plants);
mgr.SetActorAreaId(*plants, GetAreaIdAlways());
#endif
x7cc_ = 8.f;
}
x8e4_27_ = true;
@ -502,6 +508,41 @@ void CFlaahgra::sub801ae980(CStateManager& mgr) {
++x788_;
}
void CFlaahgra::sub801ade80() {
x894_ = (x7ac_ ? -GetTransform().basis[0] : GetTransform().basis[0]);
const rstl::reserved_vector<zeus::CVector3f, 4>& vec = (x7ac_ ? x82c_ : x860_);
for (const zeus::CVector3f& v : vec) {
if (v.magSquared() < 0.f)
continue;
if (GetTransform().basis[1].dot(v) > FLT_MIN)
x894_ = v;
}
}
bool CFlaahgra::ShouldAttack(CStateManager& mgr, float) {
if (x788_ <= 0 || x788_ > 3 || x7c0_ > 0.f || mgr.GetPlayer().IsInWaterMovement() || x8e4_31_)
return false;
CPlayer& player = mgr.GetPlayer();
zeus::CVector2f diff = player.GetTranslation().toVec2f() - GetTranslation().toVec2f();
float dist = diff.magSquared();
float minSq = x2fc_minAttackRange * x2fc_minAttackRange;
float maxSq = x300_maxAttackRange * x300_maxAttackRange;
if ((player.GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Morphed || dist < minSq ||
dist > maxSq) &&
(x7cc_ > 0.f || player.GetVelocity().magSquared() < 25.f))
return false;
return zeus::CVector2f::getAngleDiff(GetTransform().basis[1].toVec2f(), diff) > zeus::degToRad(45.f);
}
void CFlaahgra::UpdateHeadDamageVulnerability(CStateManager& mgr, bool b) {
if (TCastToPtr<CCollisionActor> head = mgr.ObjectById(x80c_headActor)) {
head->SetDamageVulnerability(b ? *GetDamageVulnerability() : x56c_.x10_);
@ -658,7 +699,6 @@ void CFlaahgra::TurnAround(CStateManager& mgr, EStateMsg msg, float) {
x6cc_boneTracking->SetActive(false);
}
}
bool CFlaahgra::sub801ae670() { return (x7a8_ == 2 || x7a8_ == 3 || x7a8_ == 4); }
bool CFlaahgra::IsSphereCollider(TUniqueId uid) {
auto it = std::find(x7fc_sphereColliders.begin(), x7fc_sphereColliders.end(), uid);
@ -797,8 +837,8 @@ void CFlaahgra::RattlePlayer(CStateManager& mgr, const zeus::CVector3f& vec) {
}
}
static const pas::ESeverity kSeverities[2]{pas::ESeverity::Zero, pas::ESeverity::Eight};
void CFlaahgra::Faint(CStateManager& mgr, EStateMsg msg, float arg) {
static const pas::ESeverity kSeverities[2] {pas::ESeverity::Zero, pas::ESeverity::One};
if (msg == EStateMsg::Activate) {
x568_ = 0;
x7d4_ = 0.f;
@ -807,7 +847,7 @@ void CFlaahgra::Faint(CStateManager& mgr, EStateMsg msg, float arg) {
SendScriptMsgs(EScriptObjectState::Entered, mgr, EScriptObjectMessage::None);
SendScriptMsgs(EScriptObjectState::Retreat, mgr, EScriptObjectMessage::None);
x450_bodyController->GetCommandMgr().DeliverCmd(
CBCKnockBackCmd(-GetTransform().frontVector(), kSeverities[u32(x7ac_)]));
CBCKnockDownCmd(-GetTransform().frontVector(), kSeverities[u32(x7ac_)]));
} else if (msg == EStateMsg::Update) {
if (x568_ == 0) {
if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() == pas::EAnimationState::Fall) {
@ -816,7 +856,7 @@ void CFlaahgra::Faint(CStateManager& mgr, EStateMsg msg, float arg) {
UpdateHeadDamageVulnerability(mgr, true);
} else {
x450_bodyController->GetCommandMgr().DeliverCmd(
CBCKnockBackCmd(-GetTransform().frontVector(), kSeverities[u32(x7ac_)]));
CBCKnockDownCmd(-GetTransform().frontVector(), kSeverities[u32(x7ac_)]));
}
} else if (x568_ == 2) {
if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() == pas::EAnimationState::LieOnGround) {
@ -870,16 +910,47 @@ void CFlaahgra::Dead(CStateManager& mgr, EStateMsg msg, float) {
mgr.FreeScriptObject(GetUniqueId());
}
}
void CFlaahgra::Attack(CStateManager& mgr, EStateMsg msg, float) {
static const pas::ESeverity kStates1[5]{pas::ESeverity::Invalid, pas::ESeverity::Invalid, pas::ESeverity::Invalid,
pas::ESeverity::Two, pas::ESeverity::Invalid};
void CFlaahgra::Attack(CStateManager& mgr, EStateMsg msg, float arg) {
static const pas::ESeverity kSeverity[5] {
pas::ESeverity::Three, pas::ESeverity::Four, pas::ESeverity::One, pas::ESeverity::Zero, pas::ESeverity::Invalid
};
if (msg == EStateMsg::Activate) {
x568_ = 0;
x7a8_ = sub801ae828(mgr);
SendScriptMsgs(EScriptObjectState::Attack, mgr, EScriptObjectMessage::None);
} else if (msg == EStateMsg::Update) {
if (x568_ == 0) {
if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() == pas::EAnimationState::MeleeAttack) {
x568_ = kStates1[x7a8_] != pas::ESeverity::Invalid ? 1 : 2;
if (sub801ae670()) {
SetCollisionActorBounds(mgr, x79c_leftArmCollision, skUnkVec1);
SetCollisionActorBounds(mgr, x7a0_rightArmCollision, skUnkVec1);
}
x798_animState = x450_bodyController->GetBodyStateInfo().GetCurrentStateId();
x78c_ = sub801ae754(mgr);
} else {
x450_bodyController->GetCommandMgr().DeliverCmd(CBCMeleeAttackCmd(kSeverity[x7a8_]));
}
} else if (x568_ == 1) {
if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() != pas::EAnimationState::MeleeAttack)
x568_ = 4;
else {
if (x798_animState != x450_bodyController->GetBodyStateInfo().GetCurrentStateId()) {
x568_ = 2;
} else {
if (!ShouldAttack(mgr, 0.f))
return;
x450_bodyController->GetCommandMgr().DeliverCmd(CBCMeleeAttackCmd(kStates1[x7a8_]));
}
}
} else if (x568_ == 2) {
if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() != pas::EAnimationState::MeleeAttack)
x568_ = 4;
@ -913,6 +984,137 @@ u32 CFlaahgra::sub801ae828(CStateManager& mgr) {
return 0;
}
zeus::CVector3f CFlaahgra::sub801ae754(CStateManager& mgr) {
float dt = (sub801ae650() && mgr.GetPlayer().GetMorphballTransitionState() != CPlayer::EPlayerMorphBallState::Morphed
? 0.75f
: 0.5f);
return GetAimPosition(mgr, dt * x450_bodyController->GetAnimTimeRemaining()) - GetTranslation();
}
void CFlaahgra::Dizzy(CStateManager&, EStateMsg msg, float arg) {
if (msg == EStateMsg::Activate) {
x7b8_ = 0.f;
x814_ = 0.f;
x8e5_30_ = false;
} else if (msg == EStateMsg::Update) {
x7b8_ += arg;
if (x7b8_ >= (x788_ < 2 ? x56c_.x144_ : -1.5f + x56c_.x144_)) {
x450_bodyController->GetCommandMgr().DeliverCmd(CBodyStateCmd(EBodyStateCmd::ExitState));
x8e5_30_ = true;
} else {
x814_ = 0.f;
}
} else if (msg == EStateMsg::Deactivate) {
x8e5_30_ = false;
x810_ = x814_;
x7bc_ = x56c_.x148_;
x450_bodyController->GetCommandMgr().DeliverCmd(CBodyStateCmd(EBodyStateCmd::ExitState));
}
}
void CFlaahgra::Suck(CStateManager& mgr, EStateMsg msg, float) {
if (msg == EStateMsg::Activate) {
x568_ = 0;
x8e4_26_ = false;
x450_bodyController->GetCommandMgr().DeliverCmd(CBCGenerateCmd(pas::EGenerateType::Two));
} else if (msg == EStateMsg::Update) {
if (x568_ == 0) {
if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() == pas::EAnimationState::Getup)
x568_ = 2;
else
x450_bodyController->GetCommandMgr().DeliverCmd(CBCGetupCmd(pas::EGetupType::Zero));
} else if (x568_ == 2) {
if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() != pas::EAnimationState::Getup)
x568_ = 4;
else if (x8e4_26_) {
UpdateScale(x7c4_ > 0.f ? 1.f - (GetEndActionTime() / x7c4_) : 1.f, x56c_.x4_, x56c_.x0_);
}
}
} else if (msg == EStateMsg::Deactivate) {
x8e4_26_ = false;
x780_ = 2;
x79c_leftArmCollision->SetActive(mgr, false);
x7a0_rightArmCollision->SetActive(mgr, false);
}
}
void CFlaahgra::ProjectileAttack(CStateManager&, EStateMsg, float) {
}
void CFlaahgra::Cover(CStateManager& mgr, EStateMsg msg, float) {
static pas::ESeverity severities[2]{pas::ESeverity::Eight, pas::ESeverity::Seven};
if (msg == EStateMsg::Activate) {
x77c_ = GetMirrorNearestPlayer(mgr);
x568_ = (x77c_ == kInvalidUniqueId ? 4 : 1);
x6cc_boneTracking->SetTarget(mgr.GetPlayer().GetUniqueId());
x6cc_boneTracking->SetActive(true);
} else if (msg == EStateMsg::Update) {
if (x568_ == 0) {
if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() == pas::EAnimationState::MeleeAttack)
x568_ = 2;
else
x450_bodyController->GetCommandMgr().DeliverCmd(CBCMeleeAttackCmd(severities[x7b0_]));
} else if (x568_ == 1) {
if (TCastToConstPtr<CScriptWaypoint> wp = mgr.GetObjectById(x77c_)) {
zeus::CVector3f direction = wp->GetTranslation() - GetTranslation();
if (zeus::CVector2f::getAngleDiff(GetTransform().basis[1].toVec2f(), direction.toVec2f()) >
zeus::degToRad(15.f) &&
direction.canBeNormalized()) {
x450_bodyController->GetCommandMgr().DeliverCmd(CBCLocomotionCmd({}, direction.normalized(), 1.f));
} else {
x568_ = 0;
x6cc_boneTracking->SetActive(false);
}
} else
x568_ = 4;
} else if (x568_ == 2) {
if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() != pas::EAnimationState::MeleeAttack)
x568_ = 4;
else if (TCastToConstPtr<CScriptWaypoint> wp = mgr.GetObjectById(x77c_)) {
x450_bodyController->GetCommandMgr().SetTargetVector(wp->GetTranslation() - GetTranslation());
}
}
} else if (msg == EStateMsg::Deactivate) {
if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() == pas::EAnimationState::MeleeAttack) {
x450_bodyController->GetCommandMgr().DeliverCmd(CBodyStateCmd(EBodyStateCmd::NextState));
}
x77c_ = kInvalidUniqueId;
x7bc_ = x56c_.x148_;
x7b0_ ^= 1;
}
}
void CFlaahgra::SpecialAttack(CStateManager&, EStateMsg, float) {}
bool CFlaahgra::CoverCheck(CStateManager& mgr, float) {
if (x7f8_ < 0 && x7bc_ > 0.f)
return false;
for (TUniqueId id : x770_mirrorWaypoints) {
if (const CEntity* ent = mgr.GetObjectById(id)) {
if (ent->GetActive())
return true;
}
}
return false;
}
TUniqueId CFlaahgra::GetMirrorNearestPlayer(CStateManager& mgr) {
zeus::CVector3f playerPos = mgr.GetPlayer().GetTranslation();
TUniqueId nearId = kInvalidUniqueId;
for (TUniqueId id : x770_mirrorWaypoints) {
if (TCastToConstPtr<CScriptWaypoint> wp = mgr.GetObjectById(id)) {
if (!wp->GetActive())
continue;
if ((wp->GetTranslation() - playerPos).magSquared() > -1.f)
nearId = id;
}
}
return nearId;
}
CFlaahgraPlants::CFlaahgraPlants(const TToken<CGenDescription>& genDesc, const CActorParameters& actParms,
TUniqueId uid, TAreaId aId, TUniqueId owner, const zeus::CTransform& xf,
@ -978,8 +1180,18 @@ void CFlaahgraPlants::Touch(CActor& act, CStateManager& mgr) {
zeus::COBBox plObb = zeus::COBBox::FromAABox(mgr.GetPlayer().GetBoundingBox(), {});
if (x130_obbox.OBBIntersectsBox(plObb)) {
/* TODO: Finish */
}
if (!x130_obbox.OBBIntersectsBox(plObb))
return;
CDamageInfo dInfo = xf4_damageInfo;
float newDamage = x12c_lastDt * xf4_damageInfo.GetDamage();
dInfo.SetDamage(newDamage);
dInfo.SetRadiusDamage(newDamage);
dInfo.SetNoImmunity(true);
zeus::CVector3f diffVec = mgr.GetPlayer().GetTranslation() - GetTranslation();
mgr.ApplyDamage(GetUniqueId(), act.GetUniqueId(), GetUniqueId(), dInfo,
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}),
diffVec.dot(GetTransform().basis[0]) > 0.f ? GetTransform().basis[0] : -GetTransform().basis[0]);
}
} // namespace urde::MP1

View File

@ -93,12 +93,12 @@ class CFlaahgra : public CPatterned {
u32 x784_ = 1;
u32 x788_ = 0;
zeus::CVector3f x78c_;
s32 x798_ = -1;
pas::EAnimationState x798_animState = pas::EAnimationState::Invalid;
std::unique_ptr<CCollisionActorManager> x79c_leftArmCollision;
std::unique_ptr<CCollisionActorManager> x7a0_rightArmCollision;
std::unique_ptr<CCollisionActorManager> x7a4_sphereCollision;
s32 x7a8_ = -1;
bool x7ac_ = true;
bool x7ac_ = true; // Was an enum
u32 x7b0_ = 1;
s32 x7b4_ = -1;
float x7b8_ = 0.f;
@ -111,7 +111,7 @@ class CFlaahgra : public CPatterned {
float x7d4_ = 0.f;
float x7d8_ = 0.f;
CDamageInfo x7dc_;
u32 x7f8_;
u32 x7f8_ = 0;
rstl::reserved_vector<TUniqueId, 8> x7fc_sphereColliders;
TUniqueId x80c_headActor = kInvalidUniqueId;
float x810_ = 0.f;
@ -119,13 +119,12 @@ class CFlaahgra : public CPatterned {
float x818_curHp = 0.f;
float x81c_ = 0.f;
zeus::CVector3f x820_;
u32 x82c_ = 0;
u32 x860_ = 0;
rstl::reserved_vector<zeus::CVector3f, 4> x82c_;
rstl::reserved_vector<zeus::CVector3f, 4> x860_;
zeus::CVector3f x894_;
zeus::CVector3f x8a0_;
CAnimRes x8ac_;
std::optional<TToken<CDependencyGroup>> x8c8_depGroup;
bool x8d0_ = false;
std::vector<CToken> x8d4_tokens;
union {
struct {
@ -163,7 +162,8 @@ class CFlaahgra : public CPatterned {
void UpdateHealthInfo(CStateManager&);
void UpdateAimPosition(CStateManager&, float);
void SetMaterialProperties(const std::unique_ptr<CCollisionActorManager>&, CStateManager&);
bool sub801ae670();
bool sub801ae650() const { return (x7a8_ == 0 || x7a8_ == 1); }
bool sub801ae670() const { return (x7a8_ == 2 || x7a8_ == 3 || x7a8_ == 4); }
bool IsSphereCollider(TUniqueId);
void SetCollisionActorBounds(CStateManager& mgr, const std::unique_ptr<CCollisionActorManager>& colMgr,
const zeus::CVector3f& extendedBounds);
@ -174,10 +174,13 @@ class CFlaahgra : public CPatterned {
zeus::CVector3f GetAttacktargetPos(CStateManager&) const;
void RattlePlayer(CStateManager& mgr, const zeus::CVector3f& vec);
bool sub801e4f8() { return x7a8_ == 0 || x7a8_ == 1; }
void sub801ade80() {}
void sub801ade80();
void UpdateHeadDamageVulnerability(CStateManager&, bool);
u32 sub801ae828(CStateManager&);
zeus::CVector3f sub801ae754(CStateManager&);
TUniqueId GetMirrorNearestPlayer(CStateManager&);
public:
DEFINE_PATTERNED(Flaahgra);
CFlaahgra(TUniqueId, std::string_view, const CEntityInfo&, const zeus::CTransform&, const CAnimRes&,
@ -196,14 +199,15 @@ public:
bool AnimOver(CStateManager&, float) { return x568_ == 4; }
bool AIStage(CStateManager&, float arg) { return x780_ == u32(arg); }
bool HitSomething(CStateManager&, float arg) { return x7d0_ > 0; }
bool HitSomething(CStateManager&, float arg) { return x7d0_ > 0.f; }
bool OffLine(CStateManager&, float) { return (!x8e5_29_ && !x8e5_28_); }
bool ShouldTurn(CStateManager&, float);
bool ShouldAttack(CStateManager&, float) { return true; }
bool ShouldAttack(CStateManager&, float);
bool BreakAttack(CStateManager&, float) { return x7d4_ >= x56c_.xc_ && !x8e4_29_getup; }
bool IsDizzy(CStateManager&, float) {
return x450_bodyController->GetBodyStateInfo().GetCurrentStateId() == pas::EAnimationState::LoopReaction;
}
bool CoverCheck(CStateManager&, float);
void FadeIn(CStateManager&, EStateMsg, float);
void FadeOut(CStateManager&, EStateMsg, float);
@ -214,5 +218,11 @@ public:
void Faint(CStateManager&, EStateMsg, float);
void Dead(CStateManager&, EStateMsg, float);
void Attack(CStateManager&, EStateMsg, float);
void Dizzy(CStateManager&, EStateMsg, float);
void Suck(CStateManager&, EStateMsg, float);
void ProjectileAttack(CStateManager&, EStateMsg, float);
void Cover(CStateManager&, EStateMsg, float);
void SpecialAttack(CStateManager&, EStateMsg, float);
};
}

View File

@ -46,6 +46,7 @@ public:
void SetDamage(float d) { x8_damage = d; }
float GetDamage(const CDamageVulnerability& dVuln) const;
float GetRadiusDamage() const { return xc_radiusDamage; }
void SetRadiusDamage(float r) { xc_radiusDamage = r; }
float GetRadiusDamage(const CDamageVulnerability& dVuln) const;
bool NoImmunity() const { return x18_noImmunity; }
void SetNoImmunity(bool b) { x18_noImmunity = b; }

View File

@ -655,9 +655,11 @@ void CScriptSpecialFunction::ThinkSpinnerController(float dt, CStateManager& mgr
r23 = false;
} else
x1e4_26_sfx2Played = false;
(void)r23;
}
auto average = x184_.GetAverage();
(void)average;
/* TODO Finish */
}
}