metaforce/Runtime/World/CPatterned.hpp

449 lines
16 KiB
C++
Raw Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
2016-04-25 05:03:38 +00:00
#include "CAi.hpp"
2016-08-15 20:43:04 +00:00
#include "Character/CBodyController.hpp"
2018-09-07 23:51:07 +00:00
#include "Character/CSteeringBehaviors.hpp"
#include "Graphics/CVertexMorphEffect.hpp"
#include "Particle/CGenDescription.hpp"
#include "Particle/CElectricDescription.hpp"
2017-06-12 04:23:34 +00:00
#include "TCastTo.hpp"
2018-09-07 23:51:07 +00:00
#include "CDamageInfo.hpp"
2018-11-05 06:12:53 +00:00
#include "CKnockBackController.hpp"
2016-04-25 05:03:38 +00:00
2018-09-14 00:49:34 +00:00
#ifndef DEFINE_PATTERNED
#define DEFINE_PATTERNED(type) static constexpr ECharacter CharacterType = ECharacter::type;
#endif
2016-04-25 05:03:38 +00:00
namespace urde
{
class CPatternedInfo;
2018-09-14 00:49:34 +00:00
class CProjectileInfo;
2018-11-11 03:27:54 +00:00
class CPathFindSearch;
2018-09-07 23:51:07 +00:00
2016-04-25 05:03:38 +00:00
class CPatterned : public CAi
{
public:
2018-09-07 23:51:07 +00:00
static const zeus::CColor skDamageColor;
2017-06-12 04:23:34 +00:00
enum class ECharacter
2016-04-25 05:03:38 +00:00
{
2017-06-12 04:23:34 +00:00
AtomicAlpha = 0,
AtomicBeta = 1,
Babygoth = 2,
Beetle = 3,
BloodFlower = 4,
Burrower = 5,
ChozoGhost = 6,
Drone = 7,
ElitePirate = 8,
EyeBall = 9,
FireFlea = 10,
Flaahgra = 11,
FlaahgraTentacle = 12,
FlickerBat = 13,
FlyingPirate = 14,
IceSheeegoth = 15,
JellyZap = 16,
Magdolite = 17,
Metaree = 18,
Metroid = 19,
MetroidBeta = 20,
MetroidPrimeExo = 21,
MetroidPrimeEssence = 22,
NewIntroBoss = 23,
Parasite = 24,
PuddleSpore = 27,
PuddleToad = 28,
Puffer = 29,
Ridley = 30,
Ripper = 31,
Seedling = 32,
SpacePirate = 34,
SpankWeed = 35,
PhazonHealingNodule = 35,
Thardus = 36,
ThardusRockProjectile = 37,
Tryclops = 38,
WarWasp = 39,
EnergyBall = 40
2016-04-25 05:03:38 +00:00
};
enum class EFlavorType
{
Zero = 0,
One = 1
2016-04-25 05:03:38 +00:00
};
enum class EMovementType
{
2016-04-25 05:46:28 +00:00
Ground = 0,
Flyer = 1
2016-04-25 05:03:38 +00:00
};
enum class EColliderType
{
2017-08-21 00:29:59 +00:00
Zero = 0,
2016-04-25 05:46:28 +00:00
One = 1
2016-04-25 05:03:38 +00:00
};
2018-11-11 03:27:54 +00:00
enum class EPatternTranslate
{
RelativeStart,
RelativePlayerStart,
RelativePlayer,
Absolute
};
enum class EPatternOrient
{
StartToPlayer,
StartToPlayerStart,
ReversePlayerForward,
Forward
};
enum class EPatternFit
{
Zero,
One
};
enum class EMoveState
{
Zero,
One,
Two,
Three,
Four
};
enum class EBehaviour
{
Zero
};
enum class EBehaviourOrient
{
MoveDir,
Constant,
Destination
};
enum class EBehaviourModifiers
{
Zero
};
enum class EPatrolState
{
Invalid = -1,
Patrol,
Pause,
Done
};
enum class EAnimState
{
Zero,
One,
Two,
Over
};
class CPatternNode
{
zeus::CVector3f x0_pos;
zeus::CVector3f xc_forward;
float x18_speed;
u8 x1c_behaviour;
u8 x1d_behaviourOrient;
u16 x1e_behaviourModifiers;
u32 x20_animation;
public:
CPatternNode(const zeus::CVector3f& pos, const zeus::CVector3f& forward, float speed,
u8 behaviour, u8 behaviourOrient, u16 behaviourModifiers, u32 animation)
: x0_pos(pos), xc_forward(forward), x18_speed(speed), x1c_behaviour(behaviour),
x1d_behaviourOrient(behaviourOrient), x1e_behaviourModifiers(behaviourModifiers),
x20_animation(animation) {}
const zeus::CVector3f& GetPos() const { return x0_pos; }
const zeus::CVector3f& GetForward() const { return xc_forward; }
float GetSpeed() const { return x18_speed; }
u8 GetBehaviour() const { return x1c_behaviour; }
u8 GetBehaviourOrient() const { return x1d_behaviourOrient; }
u16 GetBehaviourModifiers() const { return x1e_behaviourModifiers; }
};
2017-08-21 00:29:59 +00:00
protected:
2018-11-11 03:27:54 +00:00
EPatrolState x2d8_patrolState = EPatrolState::Invalid;
TUniqueId x2dc_destObj = kInvalidUniqueId;
2018-09-16 23:22:35 +00:00
zeus::CVector3f x2e0_destPos;
2018-11-11 03:27:54 +00:00
zeus::CVector3f x2ec_reflectedDestPos;
float x2f8_waypointPauseRemTime = 0.f;
2018-09-07 23:51:07 +00:00
float x2fc_minAttackRange;
float x300_maxAttackRange;
float x304_averageAttackTime;
float x308_attackTimeVariation;
2018-11-11 03:27:54 +00:00
EBehaviourOrient x30c_behaviourOrient = EBehaviourOrient::MoveDir;
zeus::CVector3f x310_moveVec;
zeus::CVector3f x31c_faceVec;
2017-07-10 04:55:51 +00:00
union
{
struct
{
2018-11-11 03:27:54 +00:00
bool x328_24_inPosition : 1;
bool x328_25_verticalMovement : 1;
bool x328_26_longJump : 1;
2017-07-10 04:55:51 +00:00
bool x328_27_onGround : 1;
2018-11-11 03:27:54 +00:00
bool x328_28_prevOnGround : 1;
bool x328_29_noPatternShagging : 1;
bool x328_30_lookAtDeathDir : 1;
2017-07-10 04:55:51 +00:00
};
u32 _dummy = 0;
};
2017-07-14 05:14:19 +00:00
2018-11-11 03:27:54 +00:00
EAnimState x32c_animState = EAnimState::Zero;
2018-09-07 23:51:07 +00:00
CStateMachineState x330_stateMachineState;
ECharacter x34c_character;
2018-11-11 03:27:54 +00:00
zeus::CVector3f x350_patternStartPos;
zeus::CVector3f x35c_patternStartPlayerPos;
zeus::CVector3f x368_destWPDelta;
EPatternTranslate x374_patternTranslate = EPatternTranslate::RelativeStart;
EPatternOrient x378_patternOrient = EPatternOrient::ReversePlayerForward;
EPatternFit x37c_patternFit = EPatternFit::One;
EBehaviour x380_behaviour = EBehaviour::Zero;
EBehaviourModifiers x384_behaviourModifiers = EBehaviourModifiers::Zero;
2018-09-07 23:51:07 +00:00
s32 x388_anim;
2018-11-11 03:27:54 +00:00
std::vector<CPatternNode> x38c_patterns;
u32 x39c_curPattern = 0;
zeus::CVector3f x3a0_latestLeashPosition;
TUniqueId x3ac_lastPatrolDest = kInvalidUniqueId;
float x3b0_moveSpeed = 1.f;
2018-09-07 23:51:07 +00:00
float x3b4_speed;
float x3b8_turnSpeed;
float x3bc_detectionRange;
float x3c0_detectionHeightRange;
float x3c4_detectionAngle;
float x3c8_leashRadius;
float x3cc_playerLeashRadius;
float x3d0_playerLeashTime;
2018-09-14 00:49:34 +00:00
float x3d4_curPlayerLeashTime = 0.f;
2018-11-11 03:27:54 +00:00
float x3d8_xDamageThreshold;
float x3dc_frozenXDamageThreshold;
float x3e0_xDamageDelay;
float x3e4_lastHP = 0.f;
float x3e8_alphaDelta = 0.f;
float x3ec_pendingFireDamage = 0.f;
float x3f0_pendingShockDamage = 0.f;
2018-11-08 00:53:38 +00:00
float x3f4_burnThinkRateTimer = 0.f;
2018-11-11 03:27:54 +00:00
EMoveState x3f8_moveState = EMoveState::Zero;
2018-09-07 23:51:07 +00:00
EFlavorType x3fc_flavor;
2017-08-25 06:18:09 +00:00
union
{
struct
{
2018-11-11 03:27:54 +00:00
bool x400_24_hitByPlayerProjectile : 1;
2018-11-05 06:12:53 +00:00
bool x400_25_alive : 1; // t
2017-08-25 06:18:09 +00:00
bool x400_26_ : 1;
2018-11-11 03:27:54 +00:00
bool x400_27_fadeToDeath : 1;
bool x400_28_pendingMassiveDeath : 1;
bool x400_29_pendingMassiveFrozenDeath : 1;
bool x400_30_patternShagged : 1;
bool x400_31_isFlyer : 1;
bool x401_24_pathOverCount : 2;
bool x401_26_disableMove : 1;
bool x401_27_phazingOut : 1;
2018-11-08 00:53:38 +00:00
bool x401_28_burning : 1;
bool x401_29_laggedBurnDeath : 1;
2018-11-11 03:27:54 +00:00
bool x401_30_pendingDeath : 1;
bool x401_31_nextPendingShock : 1;
bool x402_24_pendingShock : 1;
bool x402_25_lostMassiveFrozenHP : 1;
bool x402_26_dieIf80PercFrozen : 1;
bool x402_27_noXrayModel : 1;
bool x402_28_isMakingBigStrike : 1;
bool x402_29_drawParticles : 1; // t
bool x402_30_updateThermalFrozenState : 1;
2018-11-05 06:12:53 +00:00
bool x402_31_thawed : 1;
bool x403_24_keepThermalVisorState : 1;
2018-11-11 03:27:54 +00:00
bool x403_25_enableStateMachine : 1; // t
bool x403_26_stateControlledMassiveDeath : 1; // t
2017-08-25 06:18:09 +00:00
};
u32 _dummy2 = 0;
};
2018-09-14 00:49:34 +00:00
CDamageInfo x404_contactDamage;
2018-11-11 03:27:54 +00:00
float x420_curDamageRemTime = 0.f;
2018-09-07 23:51:07 +00:00
float x424_damageWaitTime;
2018-11-11 03:27:54 +00:00
float x428_damageCooldownTimer = -1.f;
2018-11-08 00:53:38 +00:00
zeus::CColor x42c_color = zeus::CColor::skBlack;
2018-11-11 03:27:54 +00:00
zeus::CColor x430_damageColor = skDamageColor;
2018-09-14 00:49:34 +00:00
zeus::CVector3f x434_posDelta;
zeus::CQuaternion x440_rotDelta;
2018-11-11 03:27:54 +00:00
CSteeringBehaviors x45c_steeringBehaviors;
2017-08-21 00:29:59 +00:00
std::unique_ptr<CBodyController> x450_bodyController;
2018-11-06 06:16:12 +00:00
u16 x454_deathSfx;
u16 x458_iceShatterSfx;
2017-08-21 00:29:59 +00:00
2018-11-05 06:12:53 +00:00
CKnockBackController x460_knockBackController;
2018-11-11 03:27:54 +00:00
zeus::CVector3f x4e4_latestPredictedTranslation;
float x4f0_predictedLeashTime = 0.f;
float x4f4_intoFreezeDur;
float x4f8_outofFreezeDur;
2018-09-07 23:51:07 +00:00
float x4fc_;
2018-11-11 03:27:54 +00:00
float x500_preThinkDt = 0.f;
2017-08-25 06:18:09 +00:00
float x504_damageDur = 0.f;
2018-09-07 23:51:07 +00:00
EColliderType x508_colliderType;
2018-11-11 03:27:54 +00:00
float x50c_baseDamageMag;
2018-11-05 06:12:53 +00:00
std::shared_ptr<CVertexMorphEffect> x510_vertexMorph;
2018-11-06 06:16:12 +00:00
zeus::CVector3f x514_deathExplosionOffset;
std::experimental::optional<TLockedToken<CGenDescription>> x520_deathExplosionParticle;
std::experimental::optional<TLockedToken<CElectricDescription>> x530_deathExplosionElectric;
zeus::CVector3f x540_iceDeathExplosionOffset;
std::experimental::optional<TLockedToken<CGenDescription>> x54c_iceDeathExplosionParticle;
2018-11-11 03:27:54 +00:00
zeus::CVector3f x55c_moveScale = zeus::CVector3f::skOne;
void UpdateThermalFrozenState(bool thawed);
2018-11-06 06:16:12 +00:00
void GenerateIceDeathExplosion(CStateManager& mgr);
void GenerateDeathExplosion(CStateManager& mgr);
2018-11-08 00:53:38 +00:00
void RenderIceModelWithFlags(const CModelFlags& flags) const;
2018-11-11 03:27:54 +00:00
TUniqueId GetWaypointForState(CStateManager& mgr, EScriptObjectState state, EScriptObjectMessage msg) const;
void UpdateActorKeyframe(CStateManager& mgr) const;
pas::EStepDirection GetStepDirection(const zeus::CVector3f& moveVec) const;
bool IsPatternObstructed(CStateManager& mgr, const zeus::CVector3f& p0, const zeus::CVector3f& p1) const;
void UpdateDest(CStateManager& mgr);
void ApproachDest(CStateManager& mgr);
std::pair<CScriptWaypoint*, CScriptWaypoint*> GetDestWaypoints(CStateManager& mgr) const;
zeus::CQuaternion FindPatternRotation(const zeus::CVector3f& dir) const;
zeus::CVector3f FindPatternDir(CStateManager& mgr) const;
void UpdatePatternDestPos(CStateManager& mgr);
void SetupPattern(CStateManager& mgr);
EScriptObjectState GetDesiredAttackState(CStateManager& mgr) const;
2016-04-25 05:03:38 +00:00
public:
2018-11-11 03:27:54 +00:00
CPatterned(ECharacter character, TUniqueId uid, std::string_view name, EFlavorType flavor,
const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData,
const CPatternedInfo& pinfo, CPatterned::EMovementType movement,
EColliderType collider, EBodyType body, const CActorParameters& params,
EKnockBackVariant kbVariant);
2016-04-25 05:03:38 +00:00
2018-09-14 00:49:34 +00:00
void Accept(IVisitor&);
void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&);
2018-11-11 03:27:54 +00:00
void PreThink(float, CStateManager& mgr) { CEntity::Think(x500_preThinkDt, mgr); }
2018-09-07 23:51:07 +00:00
void Think(float, CStateManager&);
2018-09-14 00:49:34 +00:00
void PreRender(CStateManager&, const zeus::CFrustum&);
2018-11-08 00:53:38 +00:00
void Render(const CStateManager& mgr) const;
2018-09-14 00:49:34 +00:00
2018-11-11 03:27:54 +00:00
void Touch(CActor& act, CStateManager& mgr);
2018-09-14 00:49:34 +00:00
std::experimental::optional<zeus::CAABox> GetTouchBounds() const;
bool CanRenderUnsorted(const CStateManager& mgr) const;
2018-09-07 23:51:07 +00:00
zeus::CVector3f GetOrbitPosition(const CStateManager& mgr) const
{
return GetAimPosition(mgr, 0.f);
}
zeus::CVector3f GetAimPosition(const CStateManager& mgr, float) const;
2017-06-12 04:23:34 +00:00
2018-11-06 06:16:12 +00:00
void DeathDelete(CStateManager& mgr);
2018-11-11 03:27:54 +00:00
void Death(CStateManager& mgr, const zeus::CVector3f& direction, EScriptObjectState state);
2018-11-05 06:12:53 +00:00
void KnockBack(const zeus::CVector3f&, CStateManager&, const CDamageInfo& info,
EKnockBackType type, bool inDeferred, float magnitude);
2018-11-11 03:27:54 +00:00
void TakeDamage(const zeus::CVector3f&, float arg);
bool FixedRandom(CStateManager&, float arg);
bool Random(CStateManager&, float arg);
bool CodeTrigger(CStateManager&, float arg);
bool FixedDelay(CStateManager&, float arg);
bool RandomDelay(CStateManager&, float arg);
bool Delay(CStateManager&, float arg);
bool PatrolPathOver(CStateManager&, float arg);
bool Stuck(CStateManager&, float arg);
bool AnimOver(CStateManager&, float arg);
bool InPosition(CStateManager&, float arg);
bool HasPatrolPath(CStateManager& mgr, float arg);
bool Attacked(CStateManager&, float arg);
bool PatternShagged(CStateManager&, float arg);
bool PatternOver(CStateManager&, float arg);
bool HasRetreatPattern(CStateManager& mgr, float arg);
bool HasAttackPattern(CStateManager& mgr, float arg);
bool NoPathNodes(CStateManager&, float arg);
bool PathShagged(CStateManager&, float arg);
bool PathFound(CStateManager&, float arg);
bool PathOver(CStateManager&, float arg);
bool Landed(CStateManager&, float arg);
bool PlayerSpot(CStateManager&, float arg);
bool SpotPlayer(CStateManager&, float arg);
bool Leash(CStateManager&, float arg);
bool InDetectionRange(CStateManager&, float arg);
bool InMaxRange(CStateManager&, float arg);
bool TooClose(CStateManager&, float arg);
bool InRange(CStateManager&, float arg);
bool OffLine(CStateManager&, float arg);
bool Default(CStateManager&, float arg) { return true; }
void PathFind(CStateManager&, EStateMsg msg, float arg);
void Dead(CStateManager&, EStateMsg msg, float arg);
void TargetPlayer(CStateManager&, EStateMsg msg, float arg);
void TargetPatrol(CStateManager&, EStateMsg msg, float arg);
void FollowPattern(CStateManager&, EStateMsg msg, float arg);
void Patrol(CStateManager&, EStateMsg msg, float arg);
void Start(CStateManager&, EStateMsg msg, float arg) {}
2018-09-14 00:49:34 +00:00
2018-11-11 03:27:54 +00:00
virtual bool KnockbackWhenFrozen() const { return true; }
virtual void MassiveDeath(CStateManager& mgr);
virtual void MassiveFrozenDeath(CStateManager& mgr);
2018-09-14 00:49:34 +00:00
virtual void Burn(float, float) {}
virtual void Shock(float, float) {}
2018-11-06 06:16:12 +00:00
virtual void Freeze(CStateManager& mgr, const zeus::CVector3f& pos,
const zeus::CUnitVector3f& dir, float magnitude) {}
2018-09-14 00:49:34 +00:00
virtual void ThinkAboutMove(float);
2018-11-11 03:27:54 +00:00
virtual CPathFindSearch* GetSearchPath() { return nullptr; }
2018-09-16 23:22:35 +00:00
virtual CDamageInfo GetContactDamage() const { return x404_contactDamage; }
2018-11-08 00:53:38 +00:00
virtual u8 GetModelAlphau8(const CStateManager&) const { return u8(x42c_color.a * 255);}
2018-09-14 00:49:34 +00:00
virtual bool IsOnGround() const { return x328_27_onGround; }
virtual float GetGravityConstant() const { return 24.525002f; }
virtual CProjectileInfo* GetProjectileInfo() { return nullptr; }
virtual void PhazeOut(CStateManager&) {}
2018-11-06 06:16:12 +00:00
virtual const std::experimental::optional<TLockedToken<CGenDescription>>&
GetDeathExplosionParticle() const { return x520_deathExplosionParticle; }
2018-09-14 00:49:34 +00:00
float GetDamageDuration() const { return x504_damageDur; }
zeus::CVector3f GetGunEyePos() const;
2018-11-05 06:12:53 +00:00
bool IsAlive() const { return x400_25_alive; }
2018-09-14 00:49:34 +00:00
void BuildBodyController(EBodyType);
const CBodyController* GetBodyController() const { return x450_bodyController.get(); }
CBodyController* BodyController() { return x450_bodyController.get(); }
2018-11-06 06:16:12 +00:00
const CKnockBackController& GetKnockBackController() const { return x460_knockBackController; }
2018-09-14 00:49:34 +00:00
void SetupPlayerCollision(bool);
2018-09-16 23:22:35 +00:00
void SetDestPos(const zeus::CVector3f& pos) { x2e0_destPos = pos; }
2018-11-11 03:27:54 +00:00
void UpdateAlphaDelta(float dt, CStateManager& mgr);
void SetModelAlpha(float a) { x42c_color.a = a; }
2018-11-08 00:53:38 +00:00
float CalcDyingThinkRate();
2018-11-11 03:27:54 +00:00
void UpdateDamageColor(float dt);
2018-09-14 00:49:34 +00:00
2018-11-11 03:27:54 +00:00
bool CanLongJump() const { return x328_26_longJump; }
bool IsMakingBigStrike() const { return x402_28_isMakingBigStrike; }
2018-09-14 00:49:34 +00:00
//region Casting Functions
2017-06-12 04:23:34 +00:00
template <class T>
static T* CastTo(CEntity* ent)
{
if (TCastToPtr<CPatterned> patterned = ent)
2017-08-31 02:42:37 +00:00
return CastTo<T>(patterned.GetPtr());
2017-06-12 04:23:34 +00:00
return nullptr;
}
template <class T>
static const T* CastTo(const CEntity* ent)
{
if (TCastToConstPtr<CPatterned> patterned = ent)
2017-08-31 02:42:37 +00:00
return CastTo<T>(patterned.GetPtr());
return nullptr;
}
template <class T>
static T* CastTo(CPatterned* patterned)
{
if (patterned->x34c_character == T::CharacterType)
return static_cast<T*>(patterned);
return nullptr;
}
template <class T>
static const T* CastTo(const CPatterned* patterned)
{
if (patterned->x34c_character == T::CharacterType)
return static_cast<const T*>(patterned);
2017-06-12 04:23:34 +00:00
return nullptr;
}
2017-07-10 04:55:51 +00:00
2018-09-14 00:49:34 +00:00
//endregion
2016-04-25 05:46:28 +00:00
};
2016-04-25 05:03:38 +00:00
}