Initial CPatterned imps

This commit is contained in:
Phillip Stephens 2018-09-07 16:51:07 -07:00
parent 95fbcf914c
commit ee97ede3fe
11 changed files with 299 additions and 22 deletions

View File

@ -224,7 +224,9 @@ public:
SAdvancementDeltas AdvanceIgnoreParticles(float, CRandom16&, bool advTree); SAdvancementDeltas AdvanceIgnoreParticles(float, CRandom16&, bool advTree);
void AdvanceAnim(CCharAnimTime& time, zeus::CVector3f&, zeus::CQuaternion&); void AdvanceAnim(CCharAnimTime& time, zeus::CVector3f&, zeus::CQuaternion&);
void SetXRayModel(const TLockedToken<CModel>& model, const TLockedToken<CSkinRules>& skinRules); void SetXRayModel(const TLockedToken<CModel>& model, const TLockedToken<CSkinRules>& skinRules);
std::shared_ptr<CSkinnedModel> GetXRayModel() const { return xf4_xrayModel; }
void SetInfraModel(const TLockedToken<CModel>& model, const TLockedToken<CSkinRules>& skinRules); void SetInfraModel(const TLockedToken<CModel>& model, const TLockedToken<CSkinRules>& skinRules);
std::shared_ptr<CSkinnedModel> GetInfraModel() const { return xf8_infraModel; }
const TCachedToken<CSkinnedModel>& GetModelData() const { return xd8_modelData; } const TCachedToken<CSkinnedModel>& GetModelData() const { return xd8_modelData; }
static void PoseSkinnedModel(CSkinnedModel& model, const CPoseAsTransforms& pose, static void PoseSkinnedModel(CSkinnedModel& model, const CPoseAsTransforms& pose,
@ -253,6 +255,7 @@ public:
s32 GetCharacterIndex() const { return x204_charIdx; } s32 GetCharacterIndex() const { return x204_charIdx; }
u16 GetDefaultAnimation() const { return x208_defaultAnim; } u16 GetDefaultAnimation() const { return x208_defaultAnim; }
const TLockedToken<CMorphableSkinnedModel>& GetIceModel() const { return xe4_iceModelData; }
}; };
} }

View File

@ -158,6 +158,31 @@ public:
void SetScale(const zeus::CVector3f& scale) { x0_scale = scale; } void SetScale(const zeus::CVector3f& scale) { x0_scale = scale; }
bool HasAnimData() const { return x10_animData != nullptr; } bool HasAnimData() const { return x10_animData != nullptr; }
bool HasNormalModel() const { return x1c_normalModel; } bool HasNormalModel() const { return x1c_normalModel; }
bool HasModel(EWhichModel which)
{
if (x10_animData)
{
switch(which)
{
case EWhichModel::Normal: return true;
case EWhichModel::XRay: return x10_animData->GetXRayModel().operator bool();
case EWhichModel::Thermal: return x10_animData->GetInfraModel().operator bool();
default:
return false;
}
}
switch(which)
{
case EWhichModel::Normal:
return x1c_normalModel;
case EWhichModel::XRay:
return x2c_xrayModel;
case EWhichModel::Thermal:
return x3c_infraModel;
default: return false;
}
}
}; };
} }

View File

@ -9,6 +9,7 @@ namespace urde
class CSteeringBehaviors class CSteeringBehaviors
{ {
float x0_ = M_PIF / 2.f;
public: public:
static zeus::CVector3f ProjectOrbitalPosition(const zeus::CVector3f& pos, const zeus::CVector3f& vel, static zeus::CVector3f ProjectOrbitalPosition(const zeus::CVector3f& pos, const zeus::CVector3f& vel,
const zeus::CVector3f& orbitPoint, float dt, float preThinkDt); const zeus::CVector3f& orbitPoint, float dt, float preThinkDt);

View File

@ -10,10 +10,14 @@ class CSkinRules;
class CVertexMorphEffect class CVertexMorphEffect
{ {
u32 x0_ = 0;
u32 x4_ = 1;
public: public:
void MorphVertices(std::vector<std::pair<zeus::CVector3f, zeus::CVector3f>>& vn, void MorphVertices(std::vector<std::pair<zeus::CVector3f, zeus::CVector3f>>& vn,
const float* magnitudes, const TLockedToken<CSkinRules>& skinRules, const float* magnitudes, const TLockedToken<CSkinRules>& skinRules,
const CPoseAsTransforms& pose) const; const CPoseAsTransforms& pose) const;
void Update(float) {}
}; };
} }

View File

@ -45,7 +45,7 @@ public:
bool Delay(CStateManager&, float) bool Delay(CStateManager&, float)
{ {
return x338_ == x568_; return x330_stateMachineState.GetTime() == x568_;
} }
}; };
} }

View File

@ -74,6 +74,7 @@ public:
const CVisorParameters& GetVisorParameters() const { return x54_visorParms; } const CVisorParameters& GetVisorParameters() const { return x54_visorParms; }
const CLightParameters& GetLightParameters() const { return x0_lightParms; } const CLightParameters& GetLightParameters() const { return x0_lightParms; }
bool HasThermalHeat() const { return x58_25_thermalHeat; } bool HasThermalHeat() const { return x58_25_thermalHeat; }
float GetThermalMag() const { return x64_thermalMag; }
}; };
} }

View File

@ -1,11 +1,19 @@
#include <Runtime/CStateManager.hpp>
#include "CPatterned.hpp" #include "CPatterned.hpp"
#include "CPatternedInfo.hpp" #include "CPatternedInfo.hpp"
#include "TCastTo.hpp" #include "TCastTo.hpp"
#include "CActorParameters.hpp" #include "CActorParameters.hpp"
#include "Character/CPASAnimParmData.hpp"
#include "GameGlobalObjects.hpp"
#include "CSimplePool.hpp"
#include "CPlayer.hpp"
#include "Weapon/CGameProjectile.hpp"
#include "Character/CAnimData.hpp"
namespace urde namespace urde
{ {
const zeus::CColor CPatterned::skDamageColor(0.5f, 0.f, 0.f);
CMaterialList gkPatternedGroundMaterialList(EMaterialTypes::Character, EMaterialTypes::Solid, CMaterialList gkPatternedGroundMaterialList(EMaterialTypes::Character, EMaterialTypes::Solid,
EMaterialTypes::Orbit, EMaterialTypes::GroundCollider, EMaterialTypes::Orbit, EMaterialTypes::GroundCollider,
EMaterialTypes::Target); EMaterialTypes::Target);
@ -14,8 +22,9 @@ CMaterialList gkPatternedFlyerMaterialList(EMaterialTypes::Character, EMaterialT
CPatterned::CPatterned(ECharacter character, TUniqueId uid, std::string_view name, CPatterned::EFlavorType flavor, CPatterned::CPatterned(ECharacter character, TUniqueId uid, std::string_view name, CPatterned::EFlavorType flavor,
const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData,
const CPatternedInfo& pInfo, CPatterned::EMovementType moveType, CPatterned::EColliderType, const CPatternedInfo& pInfo, CPatterned::EMovementType moveType,
EBodyType, const CActorParameters& actorParms, int variant) CPatterned::EColliderType colliderType, EBodyType bodyType, const CActorParameters& actorParms,
int variant)
: CAi(uid, pInfo.xf8_active, name, info, xf, std::move(mData), : CAi(uid, pInfo.xf8_active, name, info, xf, std::move(mData),
zeus::CAABox(pInfo.xcc_bodyOrigin - zeus::CVector3f{pInfo.xc4_halfExtent, pInfo.xc4_halfExtent, 0.f}, zeus::CAABox(pInfo.xcc_bodyOrigin - zeus::CVector3f{pInfo.xc4_halfExtent, pInfo.xc4_halfExtent, 0.f},
pInfo.xcc_bodyOrigin + pInfo.xcc_bodyOrigin +
@ -23,7 +32,21 @@ CPatterned::CPatterned(ECharacter character, TUniqueId uid, std::string_view nam
pInfo.x0_mass, pInfo.x54_healthInfo, pInfo.x5c_damageVulnerability, pInfo.x0_mass, pInfo.x54_healthInfo, pInfo.x5c_damageVulnerability,
moveType == EMovementType::Flyer ? gkPatternedFlyerMaterialList : gkPatternedGroundMaterialList, moveType == EMovementType::Flyer ? gkPatternedFlyerMaterialList : gkPatternedGroundMaterialList,
pInfo.xfc_stateMachineId, actorParms, pInfo.xd8_stepUpHeight, 0.8f), pInfo.xfc_stateMachineId, actorParms, pInfo.xd8_stepUpHeight, 0.8f),
x34c_character(character) x2fc_minAttackRange(pInfo.x18_minAttackRange),
x300_maxAttackRange(pInfo.x1c_maxAttackRange),
x304_averageAttackTime(pInfo.x20_averageAttackTime),
x308_attackTimeVariation(pInfo.x24_attackTimeVariation),
x34c_character(character),
x388_anim(pInfo.GetAnimationParameters().GetInitialAnimation()),
x3b4_speed(pInfo.x4_speed),
x3b8_turnSpeed(pInfo.x8_turnSpeed),
x3bc_detectionRange(pInfo.xc_detectionRange),
x3c0_detectionHeightRange(pInfo.x10_detectionHeightRange),
x3c4_detectionAngle(std::cos(zeus::degToRad(pInfo.x14_dectectionAngle))),
x3c8_leashRadius(pInfo.x28_leashRadius),
x3cc_playerLeashRadius(pInfo.x2c_playerLeashRadius),
x3d0_playerLeashTime(pInfo.x30_playerLeashTime),
x3fc_flavor(flavor)
{ {
x400_25_ = true; x400_25_ = true;
x400_31_ = moveType == CPatterned::EMovementType::Flyer; x400_31_ = moveType == CPatterned::EMovementType::Flyer;
@ -31,6 +54,122 @@ CPatterned::CPatterned(ECharacter character, TUniqueId uid, std::string_view nam
x402_30_ = x402_31_ = actorParms.HasThermalHeat(); x402_30_ = x402_31_ = actorParms.HasThermalHeat();
x403_25_ = true; x403_25_ = true;
x403_26_ = true; x403_26_ = true;
x404_ = pInfo.x34_damageInfo;
x424_damageWaitTime = pInfo.x50_damageWaitTime;
x454_deathSfx = pInfo.xe8_deathSfx;
x458_iceShatterSfx = pInfo.x134_iceShatterSfx;
x4f4_ = pInfo.x100_;
x4f8_ = pInfo.x104_;
x4fc_ = pInfo.x108_;
x508_colliderType = colliderType;
x50c_thermalMag = actorParms.GetThermalMag();
x510_.reset(new CVertexMorphEffect);
x514_ = pInfo.x110_particle1Scale;
x540_ = pInfo.x124_particle2Scale;
if (pInfo.x11c_particle1.IsValid())
x520_ = { g_SimplePool->GetObj({FOURCC('PART'), pInfo.x11c_particle1})};
if (pInfo.x120_electric.IsValid())
x530_ = { g_SimplePool->GetObj({FOURCC('ELSC'), pInfo.x120_electric})};
if (pInfo.x130_particle2.IsValid())
x54c_ = { g_SimplePool->GetObj({FOURCC('PART'), pInfo.x130_particle2})};
if (x404_.GetRadius() > 0.f)
x404_.SetRadius(0.f);
xe6_29_renderParticleDBInside = false;
x402_27_ = x64_modelData->HasModel(CModelData::EWhichModel::XRay);
BuildBodyController(bodyType);
}
void CPatterned::Think(float dt, urde::CStateManager& mgr)
{
if (!GetActive())
return;
#if 0
if (x402_30_)
sub80077854(x450_bodyController->GetPercentageFrozen() == 0.f);
#endif
if (x64_modelData->GetAnimationData()->GetIceModel())
x510_->Update(dt);
if (x402_26_)
{
float froz = x450_bodyController->GetPercentageFrozen();
if (froz > 0.8f)
x400_29_ = true;
}
}
void CPatterned::Touch(CActor& act, CStateManager& mgr)
{
if (!x400_25_)
return;
if (TCastToPtr<CGameProjectile> proj = act)
{
if (mgr.GetPlayer().GetUniqueId() == proj->GetOwnerId())
x400_24_ = true;
}
}
zeus::CVector3f CPatterned::GetAimPosition(const urde::CStateManager& mgr, float dt) const
{
zeus::CVector3f offset;
if (dt > 0.f)
offset = PredictMotion(dt).x0_translation;
CSegId segId = GetModelData()->GetAnimationData()->GetLocatorSegId("lockon_target_LCTR"sv);
if (segId != 0xFF)
{
zeus::CTransform xf = GetModelData()->GetAnimationData()->GetLocatorTransform(segId, nullptr);
zeus::CVector3f scaledOrigin = GetModelData()->GetScale() * xf.origin;
if (GetTouchBounds())
return offset + GetTouchBounds()->clampToBox(x34_transform * scaledOrigin);
zeus::CAABox aabox = GetBaseBoundingBox();
zeus::CAABox primBox(aabox.min + GetPrimitiveOffset(), aabox.max + GetPrimitiveOffset());
return offset + (x34_transform * primBox.clampToBox(scaledOrigin));
}
return offset + GetBoundingBox().center();
}
void CPatterned::BuildBodyController(EBodyType bodyType)
{
if (x450_bodyController)
return;
x450_bodyController.reset(new CBodyController(*this, x3b8_turnSpeed, bodyType));
auto anim = x450_bodyController->GetPASDatabase().FindBestAnimation(CPASAnimParmData(24,
CPASAnimParm::FromEnum(0)), -1);
/* TODO: Double check this */
x460_.x81_26_ = anim.first != 0.f;
}
zeus::CVector3f CPatterned::GetGunEyePos() const
{
zeus::CVector3f origin = GetOrigin();
zeus::CAABox baseBox = GetBaseBoundingBox();
origin.z = 0.6f * (baseBox.max.z - baseBox.min.z) + origin.z;
return origin;
}
void CPatterned::SetupPlayerCollision(bool v)
{
CMaterialList include = GetMaterialFilter().GetIncludeList();
CMaterialList exclude = GetMaterialFilter().GetExcludeList();
CMaterialList* modList = (v ? &exclude : &include);
modList->Add(EMaterialTypes::Player);
SetMaterialFilter(CMaterialFilter::MakeIncludeExclude(include, exclude));
} }
} }

View File

@ -3,15 +3,45 @@
#include "CAi.hpp" #include "CAi.hpp"
#include "Character/CBodyController.hpp" #include "Character/CBodyController.hpp"
#include "Character/CSteeringBehaviors.hpp"
#include "Graphics/CVertexMorphEffect.hpp"
#include "Particle/CGenDescription.hpp"
#include "Particle/CElectricDescription.hpp"
#include "TCastTo.hpp" #include "TCastTo.hpp"
#include "CDamageInfo.hpp"
namespace urde namespace urde
{ {
class CPatternedInfo; class CPatternedInfo;
class CPatternedUnknown2
{
friend class CPatterned;
u8 x80_ = 0;
union
{
struct
{
bool x81_24_ : 1;
bool x81_25_ : 1;
bool x81_26_ : 1;
bool x81_27_ : 1;
bool x81_28_ : 1;
bool x81_29_ : 1;
bool x81_30_ : 1;
bool x81_31_ : 1;
bool x82_24_ : 1;
bool x82_25_ : 1;
bool x82_26_ : 1;
};
u32 dummy = 0;
};
};
class CPatterned : public CAi class CPatterned : public CAi
{ {
public: public:
static const zeus::CColor skDamageColor;
enum class ECharacter enum class ECharacter
{ {
AtomicAlpha = 0, AtomicAlpha = 0,
@ -71,6 +101,17 @@ public:
}; };
protected: protected:
u32 x2d8_ = -1;
TUniqueId x2dc_ = kInvalidUniqueId;
zeus::CVector3f x2e0_;
zeus::CVector3f x2ec_;
float x2f8_ = 0.f;
float x2fc_minAttackRange;
float x300_maxAttackRange;
float x304_averageAttackTime;
float x308_attackTimeVariation;
u32 x30c_ = 0;
zeus::CVector3f x310_;
union union
{ {
struct struct
@ -82,9 +123,46 @@ protected:
}; };
u32 _dummy = 0; u32 _dummy = 0;
}; };
ECharacter x34c_character;
float x338_; u32 x32c_;
CStateMachineState x330_stateMachineState;
ECharacter x34c_character;
zeus::CVector3f x350_;
zeus::CVector3f x35c_;
zeus::CVector3f x368_;
u32 x374_ = 0;
u32 x378_ = 2;
u32 x37c_ = 1;
u32 x380_ = 0;
u32 x384_ = 0;
s32 x388_anim;
/*x38c_*/
u32 x390_ = 0;
u32 x394_ = 0;
u32 x398_ = 0;
u32 x39c_ = 0;
zeus::CVector3f x3a0_;
TUniqueId x3ac_ = kInvalidUniqueId;
float x3b0_ = 1.f;
float x3b4_speed;
float x3b8_turnSpeed;
float x3bc_detectionRange;
float x3c0_detectionHeightRange;
float x3c4_detectionAngle;
float x3c8_leashRadius;
float x3cc_playerLeashRadius;
float x3d0_playerLeashTime;
float x3d4_ = 0.f;
float x3d8_;
float x3dc_;
float x3e0_;
float x3e4_ = 0.f;
float x3e8_ = 0.f;
float x3ec_ = 0.f;
float x3f0_ = 0.f;
float x3f4_ = 0.f;
u32 x3f8_ = 0;
EFlavorType x3fc_flavor;
union union
{ {
@ -121,21 +199,36 @@ protected:
u32 _dummy2 = 0; u32 _dummy2 = 0;
}; };
CDamageInfo x404_;
float x420_ = 0.f;
float x424_damageWaitTime;
float x428_ = -1.f;
zeus::CColor x42c_ = zeus::CColor::skBlack;
zeus::CColor x430_ = skDamageColor;
CSteeringBehaviors x45c_;
std::unique_ptr<CBodyController> x450_bodyController; std::unique_ptr<CBodyController> x450_bodyController;
u32 x454_deathSfx;
u32 x458_iceShatterSfx;
union CPatternedUnknown2 x460_;
{ zeus::CVector3f x4e4_;
struct float x4f0_ = 0.f;
{ float x4f4_;
bool x4e1_24_ : 1; float x4f8_;
bool x4e1_25_ : 1; float x4fc_;
bool x4e1_26_ : 1;
};
u32 _dummy3 = 0;
};
float x500_ = 0.f; float x500_ = 0.f;
float x504_damageDur = 0.f; float x504_damageDur = 0.f;
EColliderType x508_colliderType;
float x50c_thermalMag;
std::unique_ptr<CVertexMorphEffect> x510_;
zeus::CVector3f x514_;
std::experimental::optional<TLockedToken<CGenDescription>> x520_;
std::experimental::optional<TLockedToken<CElectricDescription>> x530_;
zeus::CVector3f x540_;
std::experimental::optional<TLockedToken<CGenDescription>> x54c_;
/* x55c_ */
/* x560_ */
/* x564_ */
public: public:
CPatterned(ECharacter character, TUniqueId uid, std::string_view name, EFlavorType flavor, const CEntityInfo& info, CPatterned(ECharacter character, TUniqueId uid, std::string_view name, EFlavorType flavor, const CEntityInfo& info,
const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pinfo, const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pinfo,
@ -143,8 +236,16 @@ public:
const CActorParameters& params, int variant); const CActorParameters& params, int variant);
void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&) {} void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&) {}
void Think(float, CStateManager&);
void Touch(CActor&, CStateManager&);
virtual void Death(CStateManager&, const zeus::CVector3f&, EStateMsg) {} virtual void Death(CStateManager&, const zeus::CVector3f&, EStateMsg) {}
virtual void KnockBack(const zeus::CVector3f&, CStateManager&, const CDamageInfo& info, EKnockBackType, bool, float) {} virtual void KnockBack(const zeus::CVector3f&, CStateManager&, const CDamageInfo& info, EKnockBackType, bool, float) {}
zeus::CVector3f GetOrbitPosition(const CStateManager& mgr) const
{
return GetAimPosition(mgr, 0.f);
}
zeus::CVector3f GetAimPosition(const CStateManager& mgr, float) const;
template <class T> template <class T>
static T* CastTo(CEntity* ent) static T* CastTo(CEntity* ent)
@ -184,9 +285,12 @@ public:
virtual bool IsOnGround() const { return x328_27_onGround; } virtual bool IsOnGround() const { return x328_27_onGround; }
virtual float GetGravityConstant() const { return 24.525002f; } virtual float GetGravityConstant() const { return 24.525002f; }
float GetDamageDuration() const { return x504_damageDur; } float GetDamageDuration() const { return x504_damageDur; }
zeus::CVector3f GetGunEyePos() const;
void BuildBodyController(EBodyType);
const CBodyController* GetBodyController() const { return x450_bodyController.get(); } const CBodyController* GetBodyController() const { return x450_bodyController.get(); }
CBodyController* BodyController() { return x450_bodyController.get(); } CBodyController* BodyController() { return x450_bodyController.get(); }
void SetupPlayerCollision(bool);
}; };
} }

View File

@ -38,13 +38,13 @@ CPatternedInfo::CPatternedInfo(CInputStream& in, u32 pcount)
, x108_(in.readFloatBig()) , x108_(in.readFloatBig())
, x10c_particle1Frames(in.readUint32Big()) , x10c_particle1Frames(in.readUint32Big())
, x110_particle1Scale(zeus::CVector3f::ReadBig(in)) , x110_particle1Scale(zeus::CVector3f::ReadBig(in))
, x11c_particle1(in.readUint32Big()) , x11c_particle1(in)
, x120_particle2Frames(in.readUint32Big()) , x120_electric(in)
{ {
if (pcount >= 36) if (pcount >= 36)
x124_particle2Scale.readBig(in); x124_particle2Scale.readBig(in);
if (pcount >= 37) if (pcount >= 37)
x130_particle2 = in.readUint32Big(); x130_particle2 = CAssetId(in);
if (pcount >= 38) if (pcount >= 38)
x134_iceShatterSfx = CSfxManager::TranslateSFXID(in.readUint32Big()); x134_iceShatterSfx = CSfxManager::TranslateSFXID(in.readUint32Big());
} }

View File

@ -50,7 +50,7 @@ class CPatternedInfo
zeus::CVector3f x110_particle1Scale; zeus::CVector3f x110_particle1Scale;
CAssetId x11c_particle1; CAssetId x11c_particle1;
u32 x120_particle2Frames; CAssetId x120_electric;
zeus::CVector3f x124_particle2Scale; zeus::CVector3f x124_particle2Scale;
CAssetId x130_particle2; CAssetId x130_particle2;

View File

@ -55,7 +55,7 @@ s32 CStateMachine::GetStateIndex(std::string_view state) const
const std::vector<CAiState>& CStateMachine::GetStateVector() const { return x0_states; } const std::vector<CAiState>& CStateMachine::GetStateVector() const { return x0_states; }
float CStateMachineState::GetTime() const { return 0.f; } float CStateMachineState::GetTime() const { return x8_time; }
void CStateMachineState::SetState(CStateManager &, CAi &, s32 idx) void CStateMachineState::SetState(CStateManager &, CAi &, s32 idx)
{ {