summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPistonight <pistonknight@outlook.com>2024-12-30 21:38:59 -0800
committerPistonight <pistonknight@outlook.com>2024-12-30 21:43:28 -0800
commit2363fbfe206f1203e753b9aab90e990a13e91354 (patch)
treed22aace0f36e7100a41c6a307ebff6cc37b546d7 /src
parentd5128f8fb43c20a8de388d5a7a4bbb6a549bf1b4 (diff)
PlayerInfo stuff that doesn't require PlayerBase
Diffstat (limited to 'src')
-rw-r--r--src/Game/AI/Query/queryComparePlayerHeart.cpp2
-rw-r--r--src/Game/AI/Query/queryComparePlayerMaxHeart.cpp2
-rw-r--r--src/Game/AI/Query/queryComparePlayerMaxStamina.cpp2
-rw-r--r--src/Game/AI/Query/queryComparePlayerOriginalHeart.cpp4
-rw-r--r--src/KingSystem/ActorSystem/CMakeLists.txt2
-rw-r--r--src/KingSystem/ActorSystem/Profiles/actPlayerBase.h6
-rw-r--r--src/KingSystem/ActorSystem/actPlayerInfo.cpp133
-rw-r--r--src/KingSystem/ActorSystem/actPlayerInfo.h109
-rw-r--r--src/KingSystem/ActorSystem/actPlayerInfoBase.cpp6
-rw-r--r--src/KingSystem/ActorSystem/actPlayerInfoStub.cpp19
-rw-r--r--src/KingSystem/ksys.h6
11 files changed, 279 insertions, 12 deletions
diff --git a/src/Game/AI/Query/queryComparePlayerHeart.cpp b/src/Game/AI/Query/queryComparePlayerHeart.cpp
index b7742ad6..deed74e0 100644
--- a/src/Game/AI/Query/queryComparePlayerHeart.cpp
+++ b/src/Game/AI/Query/queryComparePlayerHeart.cpp
@@ -13,7 +13,7 @@ int ComparePlayerHeart::doQuery() {
if (pi == nullptr)
return 0;
- return pi->getLife() >= *mThreshold;
+ return pi->getLifeFromPlayerActor() >= *mThreshold;
}
void ComparePlayerHeart::loadParams(const evfl::QueryArg& arg) {
diff --git a/src/Game/AI/Query/queryComparePlayerMaxHeart.cpp b/src/Game/AI/Query/queryComparePlayerMaxHeart.cpp
index 4482a6f7..3c0dade0 100644
--- a/src/Game/AI/Query/queryComparePlayerMaxHeart.cpp
+++ b/src/Game/AI/Query/queryComparePlayerMaxHeart.cpp
@@ -13,7 +13,7 @@ int ComparePlayerMaxHeart::doQuery() {
if (pi == nullptr)
return 0;
- s32 full_hearts = pi->getMaxHearts() / 4;
+ s32 full_hearts = pi->getMaxHeartValue() / 4;
return full_hearts >= *mThreshold;
}
diff --git a/src/Game/AI/Query/queryComparePlayerMaxStamina.cpp b/src/Game/AI/Query/queryComparePlayerMaxStamina.cpp
index fa2c8c54..82a15bdd 100644
--- a/src/Game/AI/Query/queryComparePlayerMaxStamina.cpp
+++ b/src/Game/AI/Query/queryComparePlayerMaxStamina.cpp
@@ -13,7 +13,7 @@ int ComparePlayerMaxStamina::doQuery() {
if (pi == nullptr)
return 0;
- s32 stamina = pi->getMaxStamina();
+ s32 stamina = pi->getStaminaMax();
if (stamina % 200 <= 0)
return stamina / 200 >= *mThreshold;
else
diff --git a/src/Game/AI/Query/queryComparePlayerOriginalHeart.cpp b/src/Game/AI/Query/queryComparePlayerOriginalHeart.cpp
index a107699a..1b9d7a75 100644
--- a/src/Game/AI/Query/queryComparePlayerOriginalHeart.cpp
+++ b/src/Game/AI/Query/queryComparePlayerOriginalHeart.cpp
@@ -15,8 +15,8 @@ int ComparePlayerOriginalHeart::doQuery() {
if (PlayerInfo::instance() == nullptr)
return 0;
- s32 life = PlayerInfo::instance()->getLife();
- s32 hearts = PlayerInfo::instance()->getMaxHearts();
+ s32 life = PlayerInfo::instance()->getLifeFromPlayerActor();
+ s32 hearts = PlayerInfo::instance()->getMaxHeartValue();
s32 compare;
if (life <= hearts)
compare = life;
diff --git a/src/KingSystem/ActorSystem/CMakeLists.txt b/src/KingSystem/ActorSystem/CMakeLists.txt
index 307975d0..2c4514ea 100644
--- a/src/KingSystem/ActorSystem/CMakeLists.txt
+++ b/src/KingSystem/ActorSystem/CMakeLists.txt
@@ -118,6 +118,8 @@ target_sources(uking PRIVATE
actPhysicsUserTag.h
actPlayerInfo.cpp
actPlayerInfo.h
+ actPlayerInfoBase.cpp
+ actPlayerInfoStub.cpp
actTag.h
actionDummyAction.cpp
diff --git a/src/KingSystem/ActorSystem/Profiles/actPlayerBase.h b/src/KingSystem/ActorSystem/Profiles/actPlayerBase.h
index 47c9cace..4b6e6ec7 100644
--- a/src/KingSystem/ActorSystem/Profiles/actPlayerBase.h
+++ b/src/KingSystem/ActorSystem/Profiles/actPlayerBase.h
@@ -1,15 +1,19 @@
#pragma once
#include <prim/seadSafeString.h>
+#include "KingSystem/ActorSystem/actActor.h"
namespace ksys::act {
// TODO
-class PlayerBase {
+class PlayerBase : public Actor {
public:
// FIXME: name for x and name+type for y
void switchEquipment(const sead::SafeString& slot, int frames, int x = -1,
const uintptr_t& y = {});
+
+ // FIXME: name for x
+ void setExtraLife(s32 extra_life, f32 x);
};
} // namespace ksys::act
diff --git a/src/KingSystem/ActorSystem/actPlayerInfo.cpp b/src/KingSystem/ActorSystem/actPlayerInfo.cpp
index fca8b658..5b5b9ca1 100644
--- a/src/KingSystem/ActorSystem/actPlayerInfo.cpp
+++ b/src/KingSystem/ActorSystem/actPlayerInfo.cpp
@@ -1 +1,134 @@
#include "KingSystem/ActorSystem/actPlayerInfo.h"
+#include "KingSystem/ActorSystem/Profiles/actPlayerBase.h"
+#include "KingSystem/ActorSystem/actActorConstDataAccess.h"
+#include "KingSystem/ActorSystem/actActorLinkConstDataAccess.h"
+#include "KingSystem/ActorSystem/actBaseProc.h"
+#include "KingSystem/ActorSystem/actBaseProcMgr.h"
+#include "KingSystem/GameData/gdtCommonFlagsUtils.h"
+#include "KingSystem/ksys.h"
+
+namespace ksys::act {
+
+SEAD_SINGLETON_DISPOSER_IMPL(PlayerInfo)
+
+PlayerInfo::PlayerInfo() = default;
+PlayerInfo::~PlayerInfo() = default;
+
+bool PlayerInfo::init() {
+ return true;
+}
+
+void PlayerInfo::resetPlayer(PlayerBase* player) {
+ if (mPlayerActor == player) {
+ mPlayerActor = nullptr;
+ ksys::setPlayerLink(nullptr);
+ }
+}
+
+bool PlayerInfo::acquireHorse(BaseProc* horse) {
+ return mHorseLink.acquire(horse, false);
+}
+
+void PlayerInfo::setHorseLink(const BaseProcLink& horse_link) {
+ mHorseLink = horse_link;
+}
+
+PlayerBase* PlayerInfo::getPlayer() const {
+ if (!mPlayerActor) {
+ return nullptr;
+ }
+ BaseProcMgr::instance()->isAccessingProcSafe(mPlayerActor, nullptr);
+ return mPlayerActor;
+}
+
+PlayerBase* PlayerInfo::getPlayer_() const {
+ if (!mPlayerActor) {
+ return nullptr;
+ }
+ BaseProcMgr::instance()->isAccessingProcSafe(mPlayerActor, nullptr);
+ return mPlayerActor;
+}
+
+s32 PlayerInfo::getMaxLifeFromPlayerActor() const {
+ return mPlayerActor ? mPlayerActor->getMaxLife() : 0;
+}
+
+void PlayerInfo::setMaxHeartValue(s32 quarter_hearts) {
+ gdt::setFlag_MaxHartValue(quarter_hearts);
+ mMaxHeartValue = static_cast<f32>(quarter_hearts);
+}
+
+u32 PlayerInfo::getMaxHeartValue() const {
+ // Return type is unsigned, but the conversion is signed
+ return static_cast<s32>(mMaxHeartValue);
+}
+
+void PlayerInfo::updateMaxHeartValueFromGameData() {
+ mMaxHeartValue = static_cast<f32>(gdt::getFlag_MaxHartValue());
+}
+
+void PlayerInfo::setLifeForPlayerActor(s32 life) {
+ if (mPlayerActor) {
+ *mPlayerActor->getLife() = life;
+ }
+}
+
+s32 PlayerInfo::getLifeFromPlayerActor() const {
+ if (!mPlayerActor) {
+ return 0;
+ }
+ auto* life = mPlayerActor->getLife();
+ return life ? *life : 1;
+}
+
+void PlayerInfo::recoverLife() {
+ setLifeForPlayerActor(getMaxLifeFromPlayerActor());
+}
+
+void PlayerInfo::setStaminaCurrentMax(f32 max_stamina) {
+ gdt::setFlag_StaminaCurrentMax(max_stamina);
+ mStaminaCurrentMax = max_stamina;
+}
+
+f32 PlayerInfo::getStaminaCurrentMax() const {
+ return mStaminaCurrentMax;
+}
+
+void PlayerInfo::updateStaminaCurrentMaxFromGameData() {
+ mStaminaCurrentMax = gdt::getFlag_StaminaCurrentMax();
+}
+
+void PlayerInfo::setStaminaMax(f32 max_stamina) {
+ gdt::setFlag_StaminaMax(max_stamina);
+ mStaminaMax = max_stamina;
+}
+
+f32 PlayerInfo::getStaminaMax() const {
+ return mStaminaMax;
+}
+
+void PlayerInfo::updateStaminaMaxFromGameData() {
+ mStaminaMax = gdt::getFlag_StaminaMax();
+}
+
+PlayerBase* PlayerInfo::getPlayerUnchecked() {
+ return mPlayerActor;
+}
+
+sead::Vector3f& PlayerInfo::getPlayerPos() {
+ ActorConstDataAccess accessor;
+
+ acquireActor(&mPlayerLink, &accessor);
+ accessor.debugLog(1, "getPlayerPos");
+ return mPlayerPos;
+}
+
+sead::Vector3f& PlayerInfo::getPlayerPosForPostCalc() {
+ ActorConstDataAccess accessor;
+
+ acquireActor(&mPlayerLink, &accessor);
+ accessor.debugLog(0, "getPlayerPosForPostCalc");
+ return mPlayerPosForPostCalc;
+}
+
+} // namespace ksys::act
diff --git a/src/KingSystem/ActorSystem/actPlayerInfo.h b/src/KingSystem/ActorSystem/actPlayerInfo.h
index c356c3f9..317b126b 100644
--- a/src/KingSystem/ActorSystem/actPlayerInfo.h
+++ b/src/KingSystem/ActorSystem/actPlayerInfo.h
@@ -1,22 +1,119 @@
#pragma once
#include <heap/seadDisposer.h>
+#include <math/seadVector.h>
+#include "KingSystem/ActorSystem/actBaseProcLink.h"
+#include "container/seadRingBuffer.h"
namespace ksys::act {
+class Actor;
class PlayerBase;
-// TODO
-class PlayerInfo {
+class PlayerInfoBase {
+public:
+ PlayerInfoBase();
+ virtual ~PlayerInfoBase();
+};
+
+class PlayerInfo : public PlayerInfoBase {
SEAD_SINGLETON_DISPOSER(PlayerInfo)
PlayerInfo();
- virtual ~PlayerInfo();
+ ~PlayerInfo() override;
public:
+ bool init();
+ void setAndAcquirePlayer(PlayerBase* player); // requires PlayerOrEnemy and PlayerBase
+ void resetPlayer(PlayerBase* player);
+ bool acquireHorse(BaseProc* horse);
+ void setHorseLink(const BaseProcLink& horse_link);
PlayerBase* getPlayer() const;
- s32 getLife() const;
- u32 getMaxHearts() const;
- f32 getMaxStamina() const;
+ PlayerBase* getPlayer_() const; // possibly duped by compiler?
+ Actor* getRiddenHorse() const; // requires PlayerBase vtable
+ void setMaxLifeForPlayerActor(s32 max_heart); // requires PlayerBase
+ s32 getMaxLifeFromPlayerActor() const;
+ void setMaxHeartValue(s32 quarter_hearts);
+ u32 getMaxHeartValue() const;
+ void updateMaxHeartValueFromGameData();
+ void setLifeForPlayerActor(s32 life);
+ s32 getLifeFromPlayerActor() const;
+ void updateCurrentHartFlagFromPlayerActor(); // TODO
+ void updateLifeAfterGameOver(); // requires a global flag
+ void
+ resetLifeToBeforeSwordPull(); // requires HeartDisplayMgr (0x25D6578) and PlayerBase vtable
+ void saveLifeInfoForSwordPull(); // requires PlayerBase vtable
+ void recoverLife();
+ void setStaminaCurrentMax(f32 max_stamina);
+ f32 getStaminaCurrentMax() const;
+ void updateStaminaCurrentMaxFromGameData();
+ void setStaminaMax(f32 max_stamina);
+ f32 getStaminaMax() const;
+ void updateStaminaMaxFromGameData();
+ void setMaxStaminaForPlayerActor(f32 max_stamina); // requires PlayerBase
+ f32 getMaxStaminaFromPlayerActor() const; // requires PlayerBase
+ void recoverStamina(); // requires PlayerBase
+ void recoverCondition(); // requires PlayerBase
+
+ PlayerBase* getPlayerUnchecked();
+
+ sead::Vector3f& getPlayerPos();
+ sead::Vector3f& getPlayerPosForPostCalc();
+
+ // TODO: name and PlayerBase vtable
+ sead::Vector3f& getPlayerM265();
+
+private:
+ // These are probably debug stuff that were removed
+ class Info1 : public PlayerInfoBase {
+ public:
+ Info1();
+ ~Info1() override;
+ } mInfo1;
+ class Info2 : public PlayerInfoBase {
+ public:
+ Info2();
+ ~Info2() override;
+ } mInfo2;
+ class Info3 : public PlayerInfoBase {
+ public:
+ Info3();
+ ~Info3() override;
+ } mInfo3;
+ class Info4 : public PlayerInfoBase {
+ public:
+ Info4();
+ ~Info4() override;
+ } mInfo4;
+ class Info5 : public PlayerInfoBase {
+ public:
+ Info5();
+ ~Info5() override;
+ } mInfo5;
+ class Info6 : public PlayerInfoBase {
+ public:
+ Info6();
+ ~Info6() override;
+ } mInfo6;
+ class Info7 : public PlayerInfoBase {
+ public:
+ Info7();
+ ~Info7() override;
+ } mInfo7;
+ PlayerBase* mPlayerActor = nullptr;
+ BaseProcLink mPlayerLink;
+ BaseProcLink mHorseLink;
+ sead::Vector3f mPlayerPos{0, 0, 0};
+ sead::Vector3f mPlayerPosForPostCalc{0, 0, 0};
+ f32 mMaxHeartValue = 0;
+ f32 mStaminaCurrentMax = 1000; // 1000 = 1 wheel
+ f32 mStaminaMax = 1000;
+ f32 mLifeBeforeSwordPull = 0;
+ f32 mExtraLifeBeforeSwordPull = 0;
+ sead::FixedRingBuffer<sead::Vector3f, 60> mPreviousPositions;
+ f32 _3a0 = 65535;
+ f32 _3a4 = 65535;
+ f32 _3a8 = -1;
};
+KSYS_CHECK_SIZE_NX150(PlayerInfo, 0x3B0);
} // namespace ksys::act
diff --git a/src/KingSystem/ActorSystem/actPlayerInfoBase.cpp b/src/KingSystem/ActorSystem/actPlayerInfoBase.cpp
new file mode 100644
index 00000000..dbca9baa
--- /dev/null
+++ b/src/KingSystem/ActorSystem/actPlayerInfoBase.cpp
@@ -0,0 +1,6 @@
+#include "KingSystem/ActorSystem/actPlayerInfo.h"
+namespace ksys::act {
+// these are separate from actPlayerInfo.cpp so clang doesn't inline/dedupe them
+[[gnu::noinline]] PlayerInfoBase::PlayerInfoBase() = default;
+[[gnu::noinline]] PlayerInfoBase::~PlayerInfoBase() = default;
+} // namespace ksys::act
diff --git a/src/KingSystem/ActorSystem/actPlayerInfoStub.cpp b/src/KingSystem/ActorSystem/actPlayerInfoStub.cpp
new file mode 100644
index 00000000..2f9dc100
--- /dev/null
+++ b/src/KingSystem/ActorSystem/actPlayerInfoStub.cpp
@@ -0,0 +1,19 @@
+#include "KingSystem/ActorSystem/actPlayerInfo.h"
+namespace ksys::act {
+// these are separate from actPlayerInfo.cpp so clang doesn't inline/dedupe them
+PlayerInfo::Info1::Info1() = default;
+PlayerInfo::Info1::~Info1() = default;
+PlayerInfo::Info2::Info2() = default;
+PlayerInfo::Info2::~Info2() = default;
+PlayerInfo::Info3::Info3() = default;
+PlayerInfo::Info3::~Info3() = default;
+PlayerInfo::Info4::Info4() = default;
+PlayerInfo::Info4::~Info4() = default;
+PlayerInfo::Info5::Info5() = default;
+PlayerInfo::Info5::~Info5() = default;
+PlayerInfo::Info6::Info6() = default;
+PlayerInfo::Info6::~Info6() = default;
+PlayerInfo::Info7::Info7() = default;
+PlayerInfo::Info7::~Info7() = default;
+
+} // namespace ksys::act
diff --git a/src/KingSystem/ksys.h b/src/KingSystem/ksys.h
index 46c17c82..5d78f4c4 100644
--- a/src/KingSystem/ksys.h
+++ b/src/KingSystem/ksys.h
@@ -5,6 +5,9 @@ class Heap;
}
namespace ksys {
+namespace act {
+class PlayerLink;
+}
struct InitParams {
sead::Heap* king_sys_heap;
@@ -20,4 +23,7 @@ void initBaseProcMgr(sead::Heap* heap);
// 0x0000007100f3a8d8
void preInitializeApp(const InitParams& params);
+// 0x0000007100f40370
+void setPlayerLink(act::PlayerLink* link);
+
} // namespace ksys