From 052aa80bacbfd16b1ad26ca3267f4970d2e0275f Mon Sep 17 00:00:00 2001
From: Phillip Stephens <antidote.crk@gmail.com>
Date: Fri, 6 Mar 2020 18:03:13 -0800
Subject: [PATCH] Fix initial AI issues

---
 Runtime/MP1/World/CChozoGhost.cpp | 19 +++++++++++--------
 Runtime/MP1/World/CChozoGhost.hpp |  2 +-
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/Runtime/MP1/World/CChozoGhost.cpp b/Runtime/MP1/World/CChozoGhost.cpp
index 8ad615c90..e770960c0 100644
--- a/Runtime/MP1/World/CChozoGhost.cpp
+++ b/Runtime/MP1/World/CChozoGhost.cpp
@@ -97,7 +97,7 @@ CChozoGhost::CChozoGhost(TUniqueId uid, std::string_view name, const CEntityInfo
 , x65c_nearChance(nearChance)
 , x660_midChance(midChance)
 , x664_24_onGround(w1)
-, x664_25_flinch(w1)
+, x664_25_flinch(!w1)
 , x664_26_(false)
 , x664_27_(false)
 , x664_28_(false)
@@ -123,7 +123,7 @@ CChozoGhost::CChozoGhost(TUniqueId uid, std::string_view name, const CEntityInfo
           GetAnimationDistance(CPASAnimParmData(7, CPASAnimParm::FromEnum(1), CPASAnimParm::FromEnum(2)));
 
   if (projectileVisorEffect.IsValid())
-    x640_ = g_SimplePool->GetObj({SBIG('PART'), projectileVisorEffect});
+    x640_projectileVisor = g_SimplePool->GetObj({SBIG('PART'), projectileVisorEffect});
   x460_knockBackController.SetEnableBurn(false);
   x460_knockBackController.SetEnableLaggedBurnDeath(false);
   x460_knockBackController.SetEnableShock(false);
@@ -143,6 +143,10 @@ void CChozoGhost::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStat
     RemoveFromTeam(mgr);
     break;
   case EScriptObjectMessage::Action:
+    if (x664_25_flinch)
+      x665_29_aggressive = true;
+    break;
+  case EScriptObjectMessage::Alert:
     if (x664_26_)
       break;
     x664_26_ = true;
@@ -265,7 +269,7 @@ void CChozoGhost::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node,
     if (x67c_ == 2) {
       CGameProjectile* proj =
           LaunchProjectile(xf, mgr, 2, EProjectileAttrib::BigStrike | EProjectileAttrib::StaticInterference, true,
-                           {x640_}, x650_sound_ProjectileVisor, false, zeus::skOne3f);
+                           x640_projectileVisor, x650_sound_ProjectileVisor, false, zeus::skOne3f);
       if (proj) {
         proj->AddAttrib(EProjectileAttrib::BigStrike);
         proj->SetDamageDuration(x62c_);
@@ -276,7 +280,7 @@ void CChozoGhost::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node,
     } else {
       CGameProjectile* proj =
           LaunchProjectile(xf, mgr, 5, EProjectileAttrib::DamageFalloff | EProjectileAttrib::StaticInterference, true,
-                           {x640_}, x650_sound_ProjectileVisor, false, zeus::skOne3f);
+                           {x640_projectileVisor}, x650_sound_ProjectileVisor, false, zeus::skOne3f);
       if (proj) {
         proj->AddAttrib(EProjectileAttrib::BigStrike);
         proj->SetDamageDuration(x62c_);
@@ -621,10 +625,9 @@ bool CChozoGhost::ShouldMove(CStateManager& mgr, float arg) { return x680_behave
 bool CChozoGhost::AIStage(CStateManager& mgr, float arg) { return arg == x63c_; }
 
 u8 CChozoGhost::GetModelAlphau8(const CStateManager& mgr) const {
-  if (mgr.GetPlayerState()->GetActiveVisor(mgr) != CPlayerState::EPlayerVisor::XRay || !IsAlive())
-    return u8(x42c_color.a() * 255);
-
-  return 255;
+  if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay && IsAlive())
+    return 255;
+  return u8(x42c_color.a() * 255);
 }
 
 bool CChozoGhost::IsOnGround() const { return x664_24_onGround; }
diff --git a/Runtime/MP1/World/CChozoGhost.hpp b/Runtime/MP1/World/CChozoGhost.hpp
index ccd871891..30cf80aa8 100644
--- a/Runtime/MP1/World/CChozoGhost.hpp
+++ b/Runtime/MP1/World/CChozoGhost.hpp
@@ -54,7 +54,7 @@ private:
   float x634_;
   float x638_hurlRecoverTime;
   u32 x63c_;
-  TLockedToken<CGenDescription> x640_;
+  std::optional<TLockedToken<CGenDescription>> x640_projectileVisor;
   s16 x650_sound_ProjectileVisor;
   float x654_;
   float x658_;