From 3abef94a3dcb0d392c9ae1ab9017ad49706966d8 Mon Sep 17 00:00:00 2001 From: roeming Date: Thu, 7 Sep 2023 13:39:24 -0400 Subject: [PATCH 1/7] Match resetAppearCheck --- src/plugProjectNishimuraU/Ujia.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/plugProjectNishimuraU/Ujia.cpp b/src/plugProjectNishimuraU/Ujia.cpp index fcaa3110a..1cc65027a 100644 --- a/src/plugProjectNishimuraU/Ujia.cpp +++ b/src/plugProjectNishimuraU/Ujia.cpp @@ -155,16 +155,16 @@ void Obj::setInWaterDamage() * Address: 802664E4 * Size: 0000B4 */ -void Obj::resetAppearCheck() -{ - if (gameSystem && gameSystem->mMode == GSM_PIKLOPEDIA) { - int randCheck = randFloat() * 30.0f; - int idCheck = getCreatureID(); - _2C2 = (u8)(randCheck + idCheck) << 8; - } else { - _2C2 = 0; - } +void Obj::resetAppearCheck() { + if(Game::gameSystem && Game::gameSystem->mMode == GSM_PIKLOPEDIA) { + int v = (rand() / RAND_MAX) * 30.0f; + _2C2 = (v + 5 * getCreatureID()) << 8; + } + else { + + _2C2 = 0; + } /* stwu r1, -0x20(r1) mflr r0 @@ -225,7 +225,7 @@ void Obj::resetAppearCheck() */ bool Obj::isAppearCheck() { - if (_2C2) { + if (_2C2 != 0) { _2C2++; if ((u8)_2C2 > _2C2 >> 8) { _2C2 = 0; From 448d7914485177bc256b5994b437dcc14f6d3893 Mon Sep 17 00:00:00 2001 From: roeming Date: Thu, 7 Sep 2023 14:37:02 -0400 Subject: [PATCH 2/7] Match setNearestBridge --- src/plugProjectNishimuraU/Ujia.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/plugProjectNishimuraU/Ujia.cpp b/src/plugProjectNishimuraU/Ujia.cpp index 1cc65027a..fab52f8f5 100644 --- a/src/plugProjectNishimuraU/Ujia.cpp +++ b/src/plugProjectNishimuraU/Ujia.cpp @@ -271,6 +271,33 @@ void Obj::setBridgeSearch() */ void Obj::setNearestBridge() { + this->mBridge = nullptr; + this->_2CC = 0.0f; + this->_2D0 = 0.0f; + + if(ItemBridge::mgr) + { + f32 radius = C_PARMS->mGeneral.mTerritoryRadius.mValue; + radius = SQUARE(radius); + Iterator i(ItemBridge::mgr); + CI_LOOP(i) + { + ItemBridge::Item* cBridge = static_cast(*i); + Vector3f v = (cBridge)->getStartPos(); + float newRad = sqrDistanceXZ(mPosition, v); + if(newRad < radius) + { + mBridge = cBridge; + radius = newRad; + } + } + } + + if (mBridge) + { + f32 width = mBridge->getStageWidth() - 20.0f; + _2CC = -(0.5f*width - (rand() * width / RAND_MAX)); + } /* stwu r1, -0x50(r1) mflr r0 From 7c40223dbae42ea6a2354b36e14c6920bb7a635e Mon Sep 17 00:00:00 2001 From: roeming Date: Thu, 7 Sep 2023 16:42:17 -0400 Subject: [PATCH 3/7] Match checkBreakOrMove --- src/plugProjectNishimuraU/Ujia.cpp | 49 +++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/plugProjectNishimuraU/Ujia.cpp b/src/plugProjectNishimuraU/Ujia.cpp index fab52f8f5..9ac1cdc27 100644 --- a/src/plugProjectNishimuraU/Ujia.cpp +++ b/src/plugProjectNishimuraU/Ujia.cpp @@ -2,7 +2,7 @@ #include "Game/Entities/ItemBridge.h" #include "efx/TUjinko.h" #include "Dolphin/rand.h" - +#include "Game/MapMgr.h" namespace Game { namespace Ujia { @@ -516,6 +516,53 @@ void Obj::setCullingCheck() { } */ int Obj::checkBreakOrMove() { + if (mBridge) + { + Vector3f zVec = mBridge->getBridgeZVec(); + Vector3f bridgeDir = mBridge->getStartPos() - mPosition; + + if (dot(zVec, bridgeDir) > 0.0f) + { + return 7; + } + + Vector3f xVec = mBridge->getBridgeXVec(); + f32 width = mBridge->getStageWidth(); + + f32 xVecDotBridgeDir = dot(xVec, bridgeDir); + + f32 adjustedWidth = 20.0f + (width * 0.5f); + if (xVecDotBridgeDir < 0.0f) + { + _2D0 = adjustedWidth; + } + else + { + _2D0 = -adjustedWidth; + } + + xVecDotBridgeDir = (xVecDotBridgeDir > 0.0f) ? xVecDotBridgeDir : -xVecDotBridgeDir; + + if(xVecDotBridgeDir > width * 0.5f) + { + return 6; + } + + f32 pos = mapMgr->getMinY(mPosition); + if(mPosition.y > (pos + 5.0f)) + { + return 8; + } + else + { + return 6; + } + } + else + { + return 7; + } + /* stwu r1, -0xa0(r1) mflr r0 From 73d9b4831890bee1a45f36e47c9c3ddd06ff50c3 Mon Sep 17 00:00:00 2001 From: roeming Date: Thu, 7 Sep 2023 16:44:27 -0400 Subject: [PATCH 4/7] Revert "Match checkBreakOrMove" This reverts commit 7c40223dbae42ea6a2354b36e14c6920bb7a635e. --- src/plugProjectNishimuraU/Ujia.cpp | 49 +----------------------------- 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/src/plugProjectNishimuraU/Ujia.cpp b/src/plugProjectNishimuraU/Ujia.cpp index 9ac1cdc27..fab52f8f5 100644 --- a/src/plugProjectNishimuraU/Ujia.cpp +++ b/src/plugProjectNishimuraU/Ujia.cpp @@ -2,7 +2,7 @@ #include "Game/Entities/ItemBridge.h" #include "efx/TUjinko.h" #include "Dolphin/rand.h" -#include "Game/MapMgr.h" + namespace Game { namespace Ujia { @@ -516,53 +516,6 @@ void Obj::setCullingCheck() { } */ int Obj::checkBreakOrMove() { - if (mBridge) - { - Vector3f zVec = mBridge->getBridgeZVec(); - Vector3f bridgeDir = mBridge->getStartPos() - mPosition; - - if (dot(zVec, bridgeDir) > 0.0f) - { - return 7; - } - - Vector3f xVec = mBridge->getBridgeXVec(); - f32 width = mBridge->getStageWidth(); - - f32 xVecDotBridgeDir = dot(xVec, bridgeDir); - - f32 adjustedWidth = 20.0f + (width * 0.5f); - if (xVecDotBridgeDir < 0.0f) - { - _2D0 = adjustedWidth; - } - else - { - _2D0 = -adjustedWidth; - } - - xVecDotBridgeDir = (xVecDotBridgeDir > 0.0f) ? xVecDotBridgeDir : -xVecDotBridgeDir; - - if(xVecDotBridgeDir > width * 0.5f) - { - return 6; - } - - f32 pos = mapMgr->getMinY(mPosition); - if(mPosition.y > (pos + 5.0f)) - { - return 8; - } - else - { - return 6; - } - } - else - { - return 7; - } - /* stwu r1, -0xa0(r1) mflr r0 From bcfb5761d1c6ba26369ebe4247c45ddce2d5e5c6 Mon Sep 17 00:00:00 2001 From: roeming Date: Thu, 7 Sep 2023 16:45:19 -0400 Subject: [PATCH 5/7] match checkBreakOrMove --- src/plugProjectNishimuraU/Ujia.cpp | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/plugProjectNishimuraU/Ujia.cpp b/src/plugProjectNishimuraU/Ujia.cpp index fab52f8f5..3378bac90 100644 --- a/src/plugProjectNishimuraU/Ujia.cpp +++ b/src/plugProjectNishimuraU/Ujia.cpp @@ -2,6 +2,7 @@ #include "Game/Entities/ItemBridge.h" #include "efx/TUjinko.h" #include "Dolphin/rand.h" +#include "Game/MapMgr.h" namespace Game { namespace Ujia { @@ -516,6 +517,53 @@ void Obj::setCullingCheck() { } */ int Obj::checkBreakOrMove() { + if (mBridge) + { + Vector3f zVec = mBridge->getBridgeZVec(); + Vector3f bridgeDir = mBridge->getStartPos() - mPosition; + + if (dot(zVec, bridgeDir) > 0.0f) + { + return 7; + } + + Vector3f xVec = mBridge->getBridgeXVec(); + f32 width = mBridge->getStageWidth(); + + f32 xVecDotBridgeDir = dot(xVec, bridgeDir); + + f32 adjustedWidth = 20.0f + (width * 0.5f); + if (xVecDotBridgeDir < 0.0f) + { + _2D0 = adjustedWidth; + } + else + { + _2D0 = -adjustedWidth; + } + + xVecDotBridgeDir = (xVecDotBridgeDir > 0.0f) ? xVecDotBridgeDir : -xVecDotBridgeDir; + + if(xVecDotBridgeDir > width * 0.5f) + { + return 6; + } + + f32 pos = mapMgr->getMinY(mPosition); + if(mPosition.y > (pos + 5.0f)) + { + return 8; + } + else + { + return 6; + } + } + else + { + return 7; + } + /* stwu r1, -0xa0(r1) mflr r0 From 3d83d8a32223b2b0afa431a0fe46bed0667e12a6 Mon Sep 17 00:00:00 2001 From: roeming Date: Fri, 8 Sep 2023 15:59:20 -0400 Subject: [PATCH 6/7] Match StateTurn::exec --- include/Game/Creature.h | 12 ++++++------ include/Game/EnemyBase.h | 29 ++++++++++++++++++----------- 2 files changed, 24 insertions(+), 17 deletions(-) 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..dbdd2d1a3 100644 --- a/include/Game/EnemyBase.h +++ b/include/Game/EnemyBase.h @@ -535,19 +535,26 @@ 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, f32 turnFactor, f32 maxTurnSpeed) + { + EnemyParmsBase* parms = static_cast(mParms); - 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) { From 7e8c104dcee58a8e3252b7c1fca63923737bd4cc Mon Sep 17 00:00:00 2001 From: roeming Date: Fri, 8 Sep 2023 18:02:27 -0400 Subject: [PATCH 7/7] Simplifying params of turnToTarget --- include/Game/EnemyBase.h | 4 +++- src/plugProjectNishimuraU/FuefukiState.cpp | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/Game/EnemyBase.h b/include/Game/EnemyBase.h index dbdd2d1a3..b9909f604 100644 --- a/include/Game/EnemyBase.h +++ b/include/Game/EnemyBase.h @@ -543,9 +543,11 @@ struct EnemyBase : public Creature, public SysShape::MotionListener, virtual pub return val; } - inline f32 turnToTarget(Vector3f& targetPos, f32 turnFactor, f32 maxTurnSpeed) + inline f32 turnToTarget(Vector3f& targetPos) { EnemyParmsBase* parms = static_cast(mParms); + f32 maxTurnSpeed = parms->mGeneral.mRotationalSpeed.mValue; + f32 turnFactor = parms->mGeneral.mRotationalAccel.mValue; f32 angleDist = getAngDist(targetPos); f32 turnSpeed = limitting(angleDist * turnFactor, PI * (DEG2RAD * maxTurnSpeed)); 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;