Skip to content

Commit

Permalink
Match almost all of Queen.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
HeartPiece44 committed Sep 10, 2023
1 parent f6ff234 commit 1f643a1
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 1,002 deletions.
12 changes: 6 additions & 6 deletions docs/recommended_todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,19 @@
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/MaroFrog.cpp">MaroFrog.cpp</a> | 7314 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/UmimushiShadow.cpp">UmimushiShadow.cpp</a> | 7565 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/ContRumble.cpp">ContRumble.cpp</a> | 9005 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/SnakeJointMgr.cpp">SnakeJointMgr.cpp</a> | 10097 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/KumaChappy.cpp">KumaChappy.cpp</a> | 11401 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/Kabuto.cpp">Kabuto.cpp</a> | 12265 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/BabyState.cpp">BabyState.cpp</a> | 12955 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/Tank.cpp">Tank.cpp</a> | 13313 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/BabyState.cpp">BabyState.cpp</a> | 12869 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/Tank.cpp">Tank.cpp</a> | 13313 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/Kogane.cpp">Kogane.cpp</a> | 14614 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/JointShadowBase.cpp">JointShadowBase.cpp</a> | 14958 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/ElecBugState.cpp">ElecBugState.cpp</a> | 15715 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/RandMapMgr.cpp">RandMapMgr.cpp</a> | 17083 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/TadpoleState.cpp">TadpoleState.cpp</a> | 17593 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/SnakeWholeShadow.cpp">SnakeWholeShadow.cpp</a> | 19376 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/SnakeCrowShadow.cpp">SnakeCrowShadow.cpp</a> | 19385 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/ImomushiState.cpp">ImomushiState.cpp</a> | 19863 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/UjiaState.cpp">UjiaState.cpp</a> | 20924 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/RumbleMgr.cpp">RumbleMgr.cpp</a> | 21534 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/Rock.cpp">Rock.cpp</a> | 21671 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/ElecHiba.cpp">ElecHiba.cpp</a> | 21823 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/Frog.cpp">Frog.cpp</a> | 22143 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/QueenState.cpp">QueenState.cpp</a> | 22514 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/Frog.cpp">Frog.cpp</a> | 22143 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/QueenState.cpp">QueenState.cpp</a> | 22521 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/Ujia.cpp">Ujia.cpp</a> | 22966 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/Ujib.cpp">Ujib.cpp</a> | 23602 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/ElecBug.cpp">ElecBug.cpp</a> | 24345 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/ArmorState.cpp">ArmorState.cpp</a> | 24714 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/SaraiState.cpp">SaraiState.cpp</a> | 24923 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/TobiState.cpp">TobiState.cpp</a> | 24962 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/UjibState.cpp">UjibState.cpp</a> | 25505 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/Armor.cpp">Armor.cpp</a> | 25767 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/Tobi.cpp">Tobi.cpp</a> | 25937 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/TankState.cpp">TankState.cpp</a> | 29293 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/UjibState.cpp">UjibState.cpp</a> | 25505 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/Armor.cpp">Armor.cpp</a> | 25780 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/Tobi.cpp">Tobi.cpp</a> | 25937 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectNishimuraU/Queen.cpp">Queen.cpp</a> | 28780 |

### <section id="plugProjectOgawaU">plugProjectOgawaU</section>
| File | Size (bytes) | File | Size (bytes) |
Expand All @@ -165,8 +165,8 @@
| ---- | ---- | ---- | ---- |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectYamashitaU/singleGS_ZukanParms.cpp">singleGS_ZukanParms.cpp</a> | 21445 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectYamashitaU/enemyStoneDrawInfo.cpp">enemyStoneDrawInfo.cpp</a> | 21939 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectYamashitaU/vtxAnm.cpp">vtxAnm.cpp</a> | 25420 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectYamashitaU/lifeGaugeMgr.cpp">lifeGaugeMgr.cpp</a> | 35497 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectYamashitaU/carryInfoMgr.cpp">carryInfoMgr.cpp</a> | 47646 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectYamashitaU/generalEnemyMgr.cpp">generalEnemyMgr.cpp</a> | 55601 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectYamashitaU/kochappyState.cpp">kochappyState.cpp</a> | 58844 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectYamashitaU/carryInfoMgr.cpp">carryInfoMgr.cpp</a> | 47646 | <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectYamashitaU/genEnemy.cpp">genEnemy.cpp</a> | 47838 |
| <a href="https://github.com/projectPiki/pikmin2/tree/main/src/plugProjectYamashitaU/generalEnemyMgr.cpp">generalEnemyMgr.cpp</a> | 55601 |

### <section id="sysBootupU">sysBootupU</section>
| File | Size (bytes) | File | Size (bytes) |
Expand Down
85 changes: 50 additions & 35 deletions include/Game/EnemyBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,26 +521,23 @@ struct EnemyBase : public Creature, public SysShape::MotionListener, virtual pub
mRotation.y = mFaceDir;
}

inline f32 turnToTarget(Creature* target, f32 turnFactor, f32 maxTurnSpeed)
inline f32 turnToTarget(Vector3f& targetPos, f32 turnFactor, f32 maxTurnSpeed)
{
f32 angleDist = getAngDist(target);
f32 turnSpeed = angleDist * turnFactor;
f32 limit = PI * (DEG2RAD * maxTurnSpeed);
if (FABS(turnSpeed) > limit) {
turnSpeed = (turnSpeed > 0.0f) ? limit : -limit;
}

f32 angleDist = getAngDist(targetPos);
f32 turnSpeed = clamp(angleDist * turnFactor, PI * (DEG2RAD * maxTurnSpeed));
updateFaceDir(roundAng(turnSpeed + getFaceDir()));

return angleDist;
}

inline f32 limitting(f32 val, f32 limit)
inline f32 turnToTarget(Creature* target, f32 turnFactor, f32 maxTurnSpeed)
{
if (FABS(val) > limit) {
val = (val > 0.0f) ? limit : -limit;
}
return val;
f32 angleDist = getAngDist(target);
f32 turnSpeed = clamp(angleDist * turnFactor, PI * (DEG2RAD * maxTurnSpeed));

updateFaceDir(roundAng(turnSpeed + getFaceDir()));

return angleDist;
}

inline f32 turnToTarget(Vector3f& targetPos)
Expand All @@ -550,7 +547,20 @@ struct EnemyBase : public Creature, public SysShape::MotionListener, virtual pub
f32 turnFactor = parms->mGeneral.mRotationalAccel.mValue;

f32 angleDist = getAngDist(targetPos);
f32 turnSpeed = limitting(angleDist * turnFactor, PI * (DEG2RAD * maxTurnSpeed));
f32 turnSpeed = clamp(angleDist * turnFactor, PI * (DEG2RAD * maxTurnSpeed));

updateFaceDir(roundAng(turnSpeed + getFaceDir()));

return angleDist;
}

inline f32 turnToTarget(Creature* creature)
{
EnemyParmsBase* parms = static_cast<EnemyParmsBase*>(mParms);
f32 maxTurnSpeed = parms->mGeneral.mRotationalSpeed.mValue;
f32 turnFactor = parms->mGeneral.mRotationalAccel.mValue;
f32 angleDist = getAngDist(creature);
f32 turnSpeed = clamp(angleDist * turnFactor, PI * (DEG2RAD * maxTurnSpeed));

updateFaceDir(roundAng(turnSpeed + getFaceDir()));

Expand All @@ -572,30 +582,33 @@ struct EnemyBase : public Creature, public SysShape::MotionListener, virtual pub

inline f32 changeFaceDir(Vector3f& XYZ)
{
f32 approxSpeed;
f32 rotSpeed;
// f32 approxSpeed;
f32 rotAccel;
f32 rotSpeed;

f32 x;
f32 z;

EnemyParmsBase* parms = static_cast<EnemyParmsBase*>(mParms);
rotSpeed = parms->mGeneral.mRotationalSpeed.mValue;
rotAccel = parms->mGeneral.mRotationalAccel.mValue;
rotSpeed = *parms->mGeneral.mRotationalSpeed();
rotAccel = *parms->mGeneral.mRotationalAccel();

Vector3f pos = getPosition();
x = XYZ.x;
z = XYZ.z;

f32 angleDist = angDist(_angXZ(x, z, pos.x, pos.z), getFaceDir());

f32 limit = (DEG2RAD * rotSpeed) * PI;
approxSpeed = angleDist * rotAccel;
if (FABS(approxSpeed) > limit) {
approxSpeed = (approxSpeed > 0.0f) ? limit : -limit;
}
f32 approxSpeed = clamp(angleDist * rotAccel, PI * (DEG2RAD * rotSpeed));
// f32 limit = (DEG2RAD * rotSpeed) * PI;
// approxSpeed = angleDist * rotAccel;
// if (FABS(approxSpeed) > limit) {
// approxSpeed = (approxSpeed > 0.0f) ? limit : -limit;
// }

mFaceDir = roundAng(approxSpeed + getFaceDir());
mRotation.y = mFaceDir;
updateFaceDir(roundAng(approxSpeed + getFaceDir()));
// mFaceDir = roundAng(approxSpeed + getFaceDir());
// mRotation.y = mFaceDir;
return angleDist;
}

Expand All @@ -617,11 +630,12 @@ struct EnemyBase : public Creature, public SysShape::MotionListener, virtual pub

f32 angleDist = angDist(_angXZ(x, z, pos.x, pos.z), getFaceDir());

f32 limit = (DEG2RAD * rotSpeed) * PI;
approxSpeed = angleDist * rotAccel;
if (FABS(approxSpeed) > limit) {
approxSpeed = (approxSpeed > 0.0f) ? limit : -limit;
}
approxSpeed = clamp(angleDist * rotAccel, PI * (DEG2RAD * rotSpeed));
// f32 limit = (DEG2RAD * rotSpeed) * PI;
// approxSpeed = angleDist * rotAccel;
// if (FABS(approxSpeed) > limit) {
// approxSpeed = (approxSpeed > 0.0f) ? limit : -limit;
// }

mFaceDir = roundAng(approxSpeed + getFaceDir());
mRotation.y = mFaceDir;
Expand All @@ -643,11 +657,12 @@ struct EnemyBase : public Creature, public SysShape::MotionListener, virtual pub

f32 angleDist = angDist(angXZ(targetPos, pos), getFaceDir());

f32 limit = (DEG2RAD * rotSpeed) * PI;
approxSpeed = angleDist * rotAccel;
if (FABS(approxSpeed) > limit) {
approxSpeed = (approxSpeed > 0.0f) ? limit : -limit;
}
approxSpeed = clamp(angleDist * rotAccel, PI * (DEG2RAD * rotSpeed));
// f32 limit = (DEG2RAD * rotSpeed) * PI;
// approxSpeed = angleDist * rotAccel;
// if (FABS(approxSpeed) > limit) {
// approxSpeed = (approxSpeed > 0.0f) ? limit : -limit;
// }

mFaceDir = roundAng(approxSpeed + getFaceDir());
mRotation.y = mFaceDir;
Expand Down
6 changes: 4 additions & 2 deletions include/Game/Entities/Queen.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,19 @@ struct Obj : public EnemyBase {
void effectDrawOn();
void effectDrawOff();

int getBabyChappyCount();

// _00 = VTBL
// _00-_2BC = EnemyBase
FSM* mFsm; // _2BC
bool mCanCreateLarva; // _2C0
u8 _2C1; // _2C1
bool mIsRoomForLarva; // _2C1, have not hit max capacity yet
u8 _2C2; // _2C2
u8 _2C3; // _2C3
u8 _2C4; // _2C4
u8 _2C5; // _2C5
f32 mWaitTimer; // _2C8
f32 _2CC; // _2CC, timer?
f32 mBirthTimer; // _2CC
f32 _2D0; // _2D0
StateID mNextState; // _2D4
QueenShadowMgr* mShadowMgr; // _2D8
Expand Down
15 changes: 15 additions & 0 deletions include/trig.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ inline f32 altSin(f32 x)
return JMath::sincosTable_.mTable[GetTableIdxPos(x) & 0x7ffU].first;
}

inline f32 absF(f32 val)
{
f64 newVal = fabs(val);
return (f32)newVal;
}

inline f32 scaledSin(f32 theta) { return altSin(theta * TAU); }

inline f32 absVal(f32 val) { return (val > 0.0f) ? val : -val; }
Expand Down Expand Up @@ -93,4 +99,13 @@ inline Vector3f getRotationOffset(f32 scale, f32 y, f32 angle)

inline Vector3f getRotation(f32 angle) { return Vector3f(pikmin2_sinf(angle), 0.0f, pikmin2_cosf(angle)); }

inline f32 clamp(f32 val, f32 limit)
{
// f64 abs = fabs(val);
if (absF(val) > limit) {
val = (val > 0.0f) ? limit : -limit;
}
return val;
}

#endif
1 change: 1 addition & 0 deletions src/plugProjectNishimuraU/Armor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ bool Obj::isBreakBridge()
*/
bool Obj::moveBridgeSide()
{
f32 speed;
Vector3f startPos = mBridge->getStartPos();
Vector3f xVec = mBridge->getBridgeXVec();
Vector3f zVec = mBridge->getBridgeZVec();
Expand Down
4 changes: 2 additions & 2 deletions src/plugProjectNishimuraU/BabyState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ void StateMove::exec(EnemyBase* enemy)

if (creature) {

f32 angleDist = baby->turnToTarget(creature, CG_PARMS(baby)->mGeneral.mRotationalAccel.mValue,
CG_PARMS(baby)->mGeneral.mRotationalSpeed.mValue);
// Vector3f targetPos = creature->getPosition();
f32 angleDist = baby->turnToTarget(creature);

f32 limit = PI * (DEG2RAD * *CG_PARMS(baby)->mGeneral.mMinAttackRange());
f32 absDist = FABS(angleDist);
Expand Down
Loading

0 comments on commit 1f643a1

Please sign in to comment.