Finish CFlickerBat imps

This commit is contained in:
Phillip Stephens 2018-12-16 21:40:27 -08:00
parent b7f35e0528
commit 6fe99a7ddf
5 changed files with 147 additions and 12 deletions

View File

@ -860,6 +860,14 @@ void CStateManager::SetupFogForArea(TAreaId area) const {
SetupFogForArea(*areaObj); SetupFogForArea(*areaObj);
} }
void CStateManager::SetupFogForAreaNonCurrent(TAreaId area) const {
if (area == kInvalidAreaId)
area = x8cc_nextAreaId;
const CGameArea* areaObj = x850_world->GetAreaAlways(area);
if (areaObj->IsPostConstructed())
SetupFogForAreaNonCurrent(*areaObj);
}
void CStateManager::SetupFogForArea(const CGameArea& area) const { void CStateManager::SetupFogForArea(const CGameArea& area) const {
if (SetupFogForDraw()) if (SetupFogForDraw())
return; return;
@ -874,6 +882,18 @@ void CStateManager::SetupFogForArea(const CGameArea& area) const {
} }
} }
void CStateManager::SetupFogForAreaNonCurrent(const CGameArea& area) const {
if (SetupFogForDraw())
return;
if (x8b8_playerState->GetActiveVisor(*this) == CPlayerState::EPlayerVisor::XRay) {
float fogDist = area.GetXRayFogDistance();
float farz = g_tweakGui->GetXRayFogNearZ() * (1.f - fogDist) + g_tweakGui->GetXRayFogFarZ() * fogDist;
g_Renderer->SetWorldFog(ERglFogMode(g_tweakGui->GetXRayFogMode()), g_tweakGui->GetXRayFogNearZ(), farz,
g_tweakGui->GetXRayFogColor());
}
}
bool CStateManager::SetupFogForDraw() const { bool CStateManager::SetupFogForDraw() const {
switch (x8b8_playerState->GetActiveVisor(*this)) { switch (x8b8_playerState->GetActiveVisor(*this)) {
case CPlayerState::EPlayerVisor::Thermal: case CPlayerState::EPlayerVisor::Thermal:

View File

@ -172,7 +172,7 @@ private:
zeus::CVector2f xf2c_viewportScale = {1.f, 1.f}; zeus::CVector2f xf2c_viewportScale = {1.f, 1.f};
EThermalDrawFlag xf34_thermalFlag = EThermalDrawFlag::Bypass; EThermalDrawFlag xf34_thermalFlag = EThermalDrawFlag::Bypass;
TUniqueId xf38_skipCineSpecialFunc = kInvalidUniqueId; TUniqueId xf38_skipCineSpecialFunc = kInvalidUniqueId;
std::list<u32> xf3c_; std::list<TUniqueId> xf3c_activeFlickerBats;
std::list<TUniqueId> xf54_activeParasites; std::list<TUniqueId> xf54_activeParasites;
TUniqueId xf6c_playerActorHead = kInvalidUniqueId; TUniqueId xf6c_playerActorHead = kInvalidUniqueId;
u32 xf70_ = 0; u32 xf70_ = 0;
@ -248,7 +248,9 @@ public:
void ResetViewAfterDraw(const SViewport& backupViewport, const zeus::CTransform& backupViewMatrix) const; void ResetViewAfterDraw(const SViewport& backupViewport, const zeus::CTransform& backupViewMatrix) const;
void DrawWorld() const; void DrawWorld() const;
void SetupFogForArea(TAreaId area) const; void SetupFogForArea(TAreaId area) const;
void SetupFogForAreaNonCurrent(TAreaId area) const;
void SetupFogForArea(const CGameArea& area) const; void SetupFogForArea(const CGameArea& area) const;
void SetupFogForAreaNonCurrent(const CGameArea& area) const;
bool SetupFogForDraw() const; bool SetupFogForDraw() const;
void PreRender(); void PreRender();
void GetCharacterRenderMaskAndTarget(bool thawed, int& mask, int& target) const; void GetCharacterRenderMaskAndTarget(bool thawed, int& mask, int& target) const;
@ -429,6 +431,7 @@ public:
} }
TUniqueId GetPlayerActorHead() const { return xf6c_playerActorHead; } TUniqueId GetPlayerActorHead() const { return xf6c_playerActorHead; }
void SetPlayerActorHead(TUniqueId id) { xf6c_playerActorHead = id; } void SetPlayerActorHead(TUniqueId id) { xf6c_playerActorHead = id; }
std::list<TUniqueId>& GetActiveFlickerBats() { return xf3c_activeFlickerBats; }
std::list<TUniqueId>& GetActiveParasites() { return xf54_activeParasites; } std::list<TUniqueId>& GetActiveParasites() { return xf54_activeParasites; }
std::shared_ptr<CWorldLayerState>& WorldLayerStateNC() { return x8c8_worldLayerState; } std::shared_ptr<CWorldLayerState>& WorldLayerStateNC() { return x8c8_worldLayerState; }
static float g_EscapeShakeCountdown; static float g_EscapeShakeCountdown;

View File

@ -430,6 +430,7 @@ public:
DeliverCmd(EBodyStateCmd::AdditiveReaction); DeliverCmd(EBodyStateCmd::AdditiveReaction);
} }
void DeliverCmd(const CBCLocomotionCmd& cmd); void DeliverCmd(const CBCLocomotionCmd& cmd);
void DeliverFaceVector(const zeus::CVector3f& f) { xc_face = f; }
void DeliverTargetVector(const zeus::CVector3f& t) { x18_target = t; } void DeliverTargetVector(const zeus::CVector3f& t) { x18_target = t; }
void DeliverAdditiveTargetVector(const zeus::CVector3f& t) { x24_additiveTarget = t; } void DeliverAdditiveTargetVector(const zeus::CVector3f& t) { x24_additiveTarget = t; }
void SetSteeringBlendSpeed(float s) { x3c_steeringSpeed = s; } void SetSteeringBlendSpeed(float s) { x3c_steeringSpeed = s; }

View File

@ -13,7 +13,7 @@ CFlickerBat::CFlickerBat(TUniqueId uid, std::string_view name, CPatterned::EFlav
EColliderType colType, bool b1, const CActorParameters& actParms, bool b2) EColliderType colType, bool b1, const CActorParameters& actParms, bool b2)
: CPatterned(ECharacter::FlickerBat, uid, name, flavor, info, xf, std::move(mData), pInfo, EMovementType::Flyer, : CPatterned(ECharacter::FlickerBat, uid, name, flavor, info, xf, std::move(mData), pInfo, EMovementType::Flyer,
colType, EBodyType::Pitchable, actParms, EKnockBackVariant::Small) colType, EBodyType::Pitchable, actParms, EKnockBackVariant::Small)
, x580_24_(false) , x580_24_wasInXray(false)
, x580_25_heardShot(false) , x580_25_heardShot(false)
, x580_26_(false) , x580_26_(false)
, x580_27_(b2) , x580_27_(b2)
@ -31,11 +31,11 @@ void CFlickerBat::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStat
if (msg == EScriptObjectMessage::Registered) { if (msg == EScriptObjectMessage::Registered) {
RemoveMaterial(EMaterialTypes::Solid, mgr); RemoveMaterial(EMaterialTypes::Solid, mgr);
/* TODO: Implement xf3c_ in CStateManager (skipping 801311B8 - 80131224) */ mgr.GetActiveFlickerBats().push_back(GetUniqueId());
x450_bodyController->Activate(mgr); x450_bodyController->Activate(mgr);
x450_bodyController->BodyStateInfo().SetMaximumPitch(zeus::degToRad(60.f)); x450_bodyController->BodyStateInfo().SetMaximumPitch(zeus::degToRad(60.f));
} else if (msg == EScriptObjectMessage::Deleted) { } else if (msg == EScriptObjectMessage::Deleted) {
/* sub80125D88(mgr.xf3c_, uid) */ mgr.GetActiveFlickerBats().remove(GetUniqueId());
} }
} }
@ -55,14 +55,83 @@ void CFlickerBat::Think(float dt, CStateManager& mgr) {
} }
} }
bool inXray = mgr.GetPlayerState()->GetCurrentVisor() == CPlayerState::EPlayerVisor::XRay;
if (inXray != x580_24_wasInXray) {
if (inXray) {
if (GetFlickerBatState() == EFlickerBatState::One) {
AddMaterial(EMaterialTypes::Target, EMaterialTypes::Orbit, mgr);
SetMuted(false);
}
CreateShadow(false);
} else {
if (GetFlickerBatState() == EFlickerBatState::One) {
RemoveMaterial(EMaterialTypes::Target, EMaterialTypes::Orbit, mgr);
SetMuted(true);
}
CreateShadow(true);
}
x580_24_wasInXray = inXray;
}
float alpha = 0.f;
if (!x580_24_wasInXray) {
if (GetFlickerBatState() == EFlickerBatState::Zero)
alpha = 1.f;
else if (GetFlickerBatState() == EFlickerBatState::Two || GetFlickerBatState() == EFlickerBatState::Three) {
alpha = x578_ * x57c_;
if (GetFlickerBatState() == EFlickerBatState::Two)
alpha = 1.f - alpha;
}
} else
alpha = 1.f;
x42c_color.a() = alpha;
x94_simpleShadow->SetUserAlpha(alpha);
bool targetable = true;
if (mgr.GetPlayerState()->GetCurrentVisor() != CPlayerState::EPlayerVisor::XRay &&
(x574_state == EFlickerBatState::Zero || x574_state == EFlickerBatState::Two))
targetable = false;
xe7_31_targetable = targetable;
CPatterned::Think(dt, mgr); CPatterned::Think(dt, mgr);
} }
void CFlickerBat::Render(const CStateManager& mgr) const { CPatterned::Render(mgr); } void CFlickerBat::Render(const CStateManager& mgr) const {
if (!x580_24_wasInXray && x580_26_ &&
(GetFlickerBatState() == EFlickerBatState::Two || GetFlickerBatState() == EFlickerBatState::Three)) {
float strength = 0.f;
if (GetFlickerBatState() == EFlickerBatState::Two) {
strength = 4.f * (x578_ - .75f);
} else if (GetFlickerBatState() == EFlickerBatState::Three) {
strength = 4.f * x578_;
}
if (strength > 0.f && strength < 1.f)
mgr.DrawSpaceWarp(GetTranslation(), 0.3f * std::sin(M_PIF * strength));
}
void CFlickerBat::Touch(CActor& act, CStateManager& mgr) { CPatterned::Touch(act, mgr); } if (x580_26_) {
mgr.SetupFogForAreaNonCurrent(GetAreaIdAlways());
CPatterned::Render(mgr);
mgr.SetupFogForArea(GetAreaIdAlways());
} else
CPatterned::Render(mgr);
}
void CFlickerBat::Touch(CActor& act, CStateManager& mgr) {
if (TCastToPtr<CPlayer> pl = act) {
if (x420_curDamageRemTime <= 0.f) {
mgr.ApplyDamage(GetUniqueId(), pl->GetUniqueId(), GetUniqueId(), GetContactDamage(),
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {});
x420_curDamageRemTime = x424_damageWaitTime;
}
}
CPatterned::Touch(act, mgr);
}
void CFlickerBat::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType type, float dt) { void CFlickerBat::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType type, float dt) {
if (type == EUserEventType::FadeIn)
ToggleVisible(mgr);
else
CPatterned::DoUserAnimEvent(mgr, node, type, dt); CPatterned::DoUserAnimEvent(mgr, node, type, dt);
} }
@ -76,13 +145,35 @@ bool CFlickerBat::CanBeShot(CStateManager& mgr, int) {
mgr.GetPlayerState()->GetCurrentVisor() == CPlayerState::EPlayerVisor::XRay); mgr.GetPlayerState()->GetCurrentVisor() == CPlayerState::EPlayerVisor::XRay);
} }
void CFlickerBat::Patrol(CStateManager& mgr, EStateMsg state, float dt) { CPatterned::Patrol(mgr, state, dt); } void CFlickerBat::Patrol(CStateManager& mgr, EStateMsg state, float dt)
{
CPatterned::Patrol(mgr, state, dt);
x450_bodyController->GetCommandMgr().DeliverFaceVector((x2e0_destPos - GetTranslation()).normalized());
}
void CFlickerBat::Attack(CStateManager&, EStateMsg, float) {} void CFlickerBat::Attack(CStateManager&, EStateMsg msg, float) {
if (msg == EStateMsg::Update) {
x450_bodyController->GetCommandMgr().DeliverCmd(
CBCLocomotionCmd((x2e0_destPos - GetTranslation()).normalized(), {}, 1.f));
}
}
void CFlickerBat::Shuffle(CStateManager&, EStateMsg, float) {} void CFlickerBat::Shuffle(CStateManager& mgr, EStateMsg msg, float) {
if (msg == EStateMsg::Activate) {
CRandom16* rnd = mgr.GetActiveRandom();
SetDestPos(GetTranslation() +
zeus::CVector3f(100.f * rnd->Float() - 50.f, 100.f * rnd->Float() - 50.f, 100.f * rnd->Float() - 50.f));
} else if (msg == EStateMsg::Update) {
ApproachDest(mgr);
}
}
void CFlickerBat::Taunt(CStateManager&, EStateMsg, float) {} void CFlickerBat::Taunt(CStateManager& mgr, EStateMsg msg, float) {
if (msg == EStateMsg::Activate) {
NotifyNeighbors(mgr);
x400_24_hitByPlayerProjectile = false;
}
}
bool CFlickerBat::InPosition(CStateManager& mgr, float arg) { bool CFlickerBat::InPosition(CStateManager& mgr, float arg) {
return GetTransform().frontVector().dot(mgr.GetPlayer().GetAimPosition(mgr, 0.f) - GetTranslation()) > 0.f; return GetTransform().frontVector().dot(mgr.GetPlayer().GetAimPosition(mgr, 0.f) - GetTranslation()) > 0.f;
@ -145,4 +236,21 @@ void CFlickerBat::CheckStaticIntersection(CStateManager& mgr) {
CMaterialFilter::MakeExclude({EMaterialTypes::SeeThrough})); CMaterialFilter::MakeExclude({EMaterialTypes::SeeThrough}));
} }
void CFlickerBat::NotifyNeighbors(CStateManager& mgr) {
for (TUniqueId uid : mgr.GetActiveFlickerBats()) {
if (CFlickerBat* flick = CPatterned::CastTo<CFlickerBat>(mgr.ObjectById(uid)))
if ((GetTranslation() - flick->GetTranslation()).magnitude() < 100.f)
flick->SetHeardShot(true);
}
}
void CFlickerBat::ToggleVisible(CStateManager& mgr) {
if (GetFlickerBatState() == EFlickerBatState::Zero || GetFlickerBatState() == EFlickerBatState::Two)
SetFlickerBatState(EFlickerBatState::Three, mgr);
else
SetFlickerBatState(EFlickerBatState::Two, mgr);
x578_ = 1.f;
x57c_ = 1.f / x578_;
}
} // namespace urde::MP1 } // namespace urde::MP1

View File

@ -14,11 +14,14 @@ private:
EFlickerBatState x574_state; EFlickerBatState x574_state;
float x578_ = 1.f; float x578_ = 1.f;
float x57c_ = 0.f; float x57c_ = 0.f;
bool x580_24_ : 1; bool x580_24_wasInXray : 1;
bool x580_25_heardShot : 1; bool x580_25_heardShot : 1;
bool x580_26_ : 1; bool x580_26_ : 1;
bool x580_27_ : 1; bool x580_27_ : 1;
void NotifyNeighbors(CStateManager&);
void ToggleVisible(CStateManager&);
void SetHeardShot(bool heardShot) { x580_25_heardShot = heardShot; }
public: public:
DEFINE_PATTERNED(FlickerBat) DEFINE_PATTERNED(FlickerBat)
CFlickerBat(TUniqueId, std::string_view name, EFlavorType, const CEntityInfo&, const zeus::CTransform&, CModelData&&, CFlickerBat(TUniqueId, std::string_view name, EFlavorType, const CEntityInfo&, const zeus::CTransform&, CModelData&&,