diff --git a/include/Game/Creature.h b/include/Game/Creature.h index 54c50d3b0..a56d4b8e1 100644 --- a/include/Game/Creature.h +++ b/include/Game/Creature.h @@ -331,12 +331,12 @@ struct Creature : public CellObject { return angDist(angBetween, getFaceDir()); } - inline f32 getAngDist(Vector3f& targetPos) - { - Vector3f pos = getPosition(); - f32 angBetween = _angXZ(targetPos.x, targetPos.z, pos.x, pos.z); - return angDist(angBetween, getFaceDir()); - } + inline f32 getAngDist(Vector3f& targetPos) + { + Vector3f pos = getPosition(); + f32 angBetween = angXZ(targetPos.x, targetPos.z, pos); + return angDist(angBetween, getFaceDir()); + } void applyAirDrag(f32, f32, f32); f32 calcSphereDistance(Creature*); diff --git a/include/Game/EnemyBase.h b/include/Game/EnemyBase.h index a14c1db2a..b9909f604 100644 --- a/include/Game/EnemyBase.h +++ b/include/Game/EnemyBase.h @@ -535,19 +535,28 @@ struct EnemyBase : public Creature, public SysShape::MotionListener, virtual pub return angleDist; } - inline f32 turnToTarget(Vector3f& targetPos, f32 turnFactor, f32 maxTurnSpeed) - { - f32 angleDist = getAngDist(targetPos); - f32 turnSpeed = angleDist * turnFactor; - f32 limit = PI * (DEG2RAD * maxTurnSpeed); - if (FABS(turnSpeed) > limit) { - turnSpeed = (turnSpeed > 0.0f) ? limit : -limit; - } + inline f32 limitting(f32 val, f32 limit) + { + if (FABS(val) > limit) { + val = (val > 0.0f) ? limit : -limit; + } + return val; + } + + inline f32 turnToTarget(Vector3f& targetPos) + { + EnemyParmsBase* parms = static_cast(mParms); + f32 maxTurnSpeed = parms->mGeneral.mRotationalSpeed.mValue; + f32 turnFactor = parms->mGeneral.mRotationalAccel.mValue; - updateFaceDir(roundAng(turnSpeed + getFaceDir())); + f32 angleDist = getAngDist(targetPos); + f32 turnSpeed = limitting(angleDist * turnFactor, PI * (DEG2RAD * maxTurnSpeed)); - return angleDist; - } + + updateFaceDir(roundAng(turnSpeed + getFaceDir())); + + return angleDist; + } inline bool checkDistAndAngle(Creature* target, f32 angle, f32 distRange, f32 angRange) { diff --git a/src/plugProjectNishimuraU/FuefukiState.cpp b/src/plugProjectNishimuraU/FuefukiState.cpp index 0a3ec0810..e2f7f0118 100644 --- a/src/plugProjectNishimuraU/FuefukiState.cpp +++ b/src/plugProjectNishimuraU/FuefukiState.cpp @@ -359,8 +359,7 @@ void StateTurn::exec(EnemyBase* enemy) Vector3f targetPos = Vector3f(fuefuki->mTargetPosition); // this is close. - f32 angleDist = fuefuki->turnToTarget(targetPos, *CG_PARMS(fuefuki)->mGeneral.mRotationalAccel(), - *CG_PARMS(fuefuki)->mGeneral.mRotationalSpeed()); + f32 angleDist = fuefuki->turnToTarget(targetPos); f64 abs = fabs(angleDist); if ((f32)abs <= PI / 6) { fuefuki->mNextState = FUEFUKI_Walk; diff --git a/src/plugProjectNishimuraU/Ujia.cpp b/src/plugProjectNishimuraU/Ujia.cpp index ce07e7f59..970e619c1 100644 --- a/src/plugProjectNishimuraU/Ujia.cpp +++ b/src/plugProjectNishimuraU/Ujia.cpp @@ -3,6 +3,7 @@ #include "Game/MapMgr.h" #include "efx/TUjinko.h" #include "Dolphin/rand.h" +#include "Game/MapMgr.h" namespace Game { namespace Ujia {