Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match FuefukiState #173

Merged
merged 9 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions include/Game/Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down
31 changes: 20 additions & 11 deletions include/Game/EnemyBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<EnemyParmsBase*>(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)
{
Expand Down
3 changes: 1 addition & 2 deletions src/plugProjectNishimuraU/FuefukiState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/plugProjectNishimuraU/Ujia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Game/MapMgr.h"
#include "efx/TUjinko.h"
#include "Dolphin/rand.h"
#include "Game/MapMgr.h"

namespace Game {
namespace Ujia {
Expand Down