mirror of https://github.com/AxioDL/metaforce.git
CFireFlea: Unindent FindSafeRoute()
Makes the function much nicer to follow by using guard clauses to unindent the code.
This commit is contained in:
parent
99c564cfe4
commit
8808a3a324
|
@ -129,45 +129,46 @@ void CFireFlea::TargetPatrol(CStateManager& mgr, EStateMsg msg, float arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
zeus::CVector3f CFireFlea::FindSafeRoute(CStateManager& mgr, const zeus::CVector3f& forward) {
|
zeus::CVector3f CFireFlea::FindSafeRoute(CStateManager& mgr, const zeus::CVector3f& forward) {
|
||||||
float mag = forward.magnitude();
|
const float mag = forward.magnitude();
|
||||||
if (mag > 0.f) {
|
if (mag <= 0.f) {
|
||||||
CRayCastResult res = mgr.RayStaticIntersection(GetTranslation(), forward.normalized(), 1.f,
|
return {};
|
||||||
CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
|
||||||
if (res.IsValid() || CheckNearWater(mgr, forward.normalized())) {
|
|
||||||
zeus::CVector3f right = forward.normalized().cross(zeus::skUp).normalized();
|
|
||||||
CRayCastResult res1 = mgr.RayStaticIntersection(GetTranslation(), right, 1.f,
|
|
||||||
CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
|
||||||
if (res1.IsValid()) {
|
|
||||||
zeus::CVector3f left = -right;
|
|
||||||
CRayCastResult res2 = mgr.RayStaticIntersection(GetTranslation(), left, 1.f,
|
|
||||||
CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
|
||||||
if (res2.IsValid()) {
|
|
||||||
zeus::CVector3f up = right.cross(forward.normalized());
|
|
||||||
CRayCastResult res3 = mgr.RayStaticIntersection(GetTranslation(), up, 1.f,
|
|
||||||
CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
|
||||||
if (res3.IsValid()) {
|
|
||||||
zeus::CVector3f down = -up;
|
|
||||||
CRayCastResult res4 = mgr.RayStaticIntersection(GetTranslation(), down, 1.f,
|
|
||||||
CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
|
||||||
if (res4.IsInvalid()) {
|
|
||||||
return mag * down;
|
|
||||||
} else {
|
|
||||||
return -forward;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return mag * up;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return mag * left;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return mag * right;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return forward;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return {};
|
|
||||||
|
const CRayCastResult res = mgr.RayStaticIntersection(GetTranslation(), forward.normalized(), 1.f,
|
||||||
|
CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
||||||
|
if (res.IsInvalid() && !CheckNearWater(mgr, forward.normalized())) {
|
||||||
|
return forward;
|
||||||
|
}
|
||||||
|
|
||||||
|
const zeus::CVector3f right = forward.normalized().cross(zeus::skUp).normalized();
|
||||||
|
const CRayCastResult res1 =
|
||||||
|
mgr.RayStaticIntersection(GetTranslation(), right, 1.f, CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
||||||
|
if (res1.IsInvalid()) {
|
||||||
|
return mag * right;
|
||||||
|
}
|
||||||
|
|
||||||
|
const zeus::CVector3f left = -right;
|
||||||
|
const CRayCastResult res2 =
|
||||||
|
mgr.RayStaticIntersection(GetTranslation(), left, 1.f, CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
||||||
|
if (res2.IsInvalid()) {
|
||||||
|
return mag * left;
|
||||||
|
}
|
||||||
|
|
||||||
|
const zeus::CVector3f up = right.cross(forward.normalized());
|
||||||
|
const CRayCastResult res3 =
|
||||||
|
mgr.RayStaticIntersection(GetTranslation(), up, 1.f, CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
||||||
|
if (res3.IsInvalid()) {
|
||||||
|
return mag * up;
|
||||||
|
}
|
||||||
|
|
||||||
|
const zeus::CVector3f down = -up;
|
||||||
|
const CRayCastResult res4 =
|
||||||
|
mgr.RayStaticIntersection(GetTranslation(), down, 1.f, CMaterialFilter::MakeInclude({EMaterialTypes::Solid}));
|
||||||
|
if (res4.IsInvalid()) {
|
||||||
|
return mag * down;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -forward;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFireFlea::CheckNearWater(const CStateManager& mgr, const zeus::CVector3f& dir) {
|
bool CFireFlea::CheckNearWater(const CStateManager& mgr, const zeus::CVector3f& dir) {
|
||||||
|
|
Loading…
Reference in New Issue