fi_context OK (also cleanup dFlow_c)

This commit is contained in:
robojumper
2025-05-12 00:38:29 +02:00
parent ba4be30be7
commit 6646fb6135
19 changed files with 686 additions and 88 deletions
+10 -4
View File
@@ -28,6 +28,9 @@
#include "toBeSorted/arc_managers/oarc_manager.h"
#include "toBeSorted/d_d3d.h"
#include "toBeSorted/d_hbm.h"
#include "toBeSorted/d_emitter.h"
#include "toBeSorted/d_particle.h"
#include "toBeSorted/fi_context.h"
#include "toBeSorted/reload_color_fader.h"
#include "toBeSorted/save_manager.h"
#include "toBeSorted/save_related.h"
@@ -276,10 +279,13 @@ sFPhaseBase::sFPhaseState dScBoot_c::cb7() {
return sFPhaseBase::PHASE_RETRY;
}
// TODO JParticle monkaS
OarcManager::GetInstance()->getData("System", "dat/navi_table.dat");
OarcManager::GetInstance()->getData("JpaCommon", "dat/Common.jpc");
OarcManager::GetInstance()->getData("JpaCommon", "dat/Common.jpn");
void *naviDat = OarcManager::GetInstance()->getData("System", "dat/navi_table.dat");
FiContext::initialize(naviDat);
dParticle::mgr_c::create(dHeap::work1Heap.heap, 0xBB8, 0xFA, 0xF);
dJEffManager_c::createEffManagers();
void *jpc = OarcManager::GetInstance()->getData("JpaCommon", "dat/Common.jpc");
void *jpn = OarcManager::GetInstance()->getData("JpaCommon", "dat/Common.jpn");
dParticle::mgr_c::GetInstance()->createResource(dHeap::workExHeap.heap, 0, jpc, jpn);
return sFPhaseBase::PHASE_NEXT;
}
+73 -20
View File
@@ -285,7 +285,7 @@ bool dFlow_c::handleEventInternal(const MsbFlowInfo *element) {
case 2: {
hi = 6;
lo = 200;
field_0x5C = FiContext::getUnkObjectiveValue();
field_0x5C = FiContext::getObjective();
break;
}
case 3: {
@@ -319,7 +319,7 @@ bool dFlow_c::handleEventInternal(const MsbFlowInfo *element) {
lo = 900;
break;
}
FiContext::do_fn_8016CB00(FiContext::getGlobalFiInfo0(selectedOption));
FiContext::do_setAdviceOptions(FiContext::getGlobalFiInfo0(selectedOption));
field_0x46 = lo + hi * 1000;
} else {
triggerEntryPoint((params1n2 >> 16) & 0xFFFF, params1n2 & 0xFFFF);
@@ -549,21 +549,29 @@ bool dFlow_c::handleMessage() {
// Does this make sense? Result is unused...
LMS_GetAttribute(dMessage_c::getMsbtInfoForIndex(dMessage_c::getInstance()->getCurrentTextFileNumber()), hasLabel);
if (mCurrentTextLabelName == "KEN0_08") {
// "After winning the race in the Wing Ceremony..."
// Current objective - use value from FiContext::getObjective?
if (field_0x5C < 0) {
field_0x5C = 8;
}
mCurrentTextLabelName.sprintf("KEN0_%02d", field_0x5C);
} else if (mCurrentTextLabelName == "KEN1_000") {
// "This is Skyloft..."
// Area analysis - use value from FiContext::???
if (field_0x5C < 0) {
field_0x5C = 0;
}
mCurrentTextLabelName.sprintf("KEN1_%03d", field_0x5C);
} else if (mCurrentTextLabelName == "KEN2_000") {
// "To search for Zelda..."
// Hint - use value from FiContext::getFiAdviceHintEntry?
if (field_0x5C < 0) {
field_0x5C = 2;
}
mCurrentTextLabelName.sprintf("KEN2_%03d", field_0x5C);
} else if (mCurrentTextLabelName == "KEN3_500") {
// "Master, your current selection of pouch items is..."
// Equipment focus
FiAnalysisHandle analysis = FiContext::getNaviTableEquipmentCheckEntry();
SizedString<16> label;
label.sprintf("KEN3_%03d", analysis.getEquipmentFocus());
@@ -571,6 +579,8 @@ bool dFlow_c::handleMessage() {
dMessage_c::getTextMessageByLabel(label, true, nullptr, nullptr), 0
);
} else if (mCurrentTextLabelName == "KEN3_000") {
// "You are located in the Sealed Grounds..."
// Threat assessment
FiAnalysisHandle analysis = FiContext::getNaviTableEquipmentCheckEntry();
s16 value = analysis.getAreaIndexForFiAreaName();
if (value < 0) {
@@ -578,17 +588,23 @@ bool dFlow_c::handleMessage() {
}
mCurrentTextLabelName.sprintf("KEN3_%03d", value);
} else if (mCurrentTextLabelName == "KEN3_501") {
// "Suitability to current location is..."
// Suitability analysis
FiAnalysisHandle analysis = FiContext::getNaviTableEquipmentCheckEntry();
s32 arg = analysis.getSuitabilityArg();
s32 arg = analysis.getSuitabilityPercentageArg();
dLytMsgWindow_c::getInstance()->setNumericArg0(arg);
} else if (mCurrentTextLabelName == "KEN3_100") {
// "My projections indicate that equipping..."
// Equipment recommendation
FiAnalysisHandle analysis = FiContext::getNaviTableEquipmentCheckEntry();
s16 value = analysis.getSuitabilityLabel();
s16 value = analysis.getEquipmentRecommendation();
if (value < 0) {
value = 0;
}
mCurrentTextLabelName.sprintf("KEN3_%03d", value);
} else if (mCurrentTextLabelName == "KEN3_200") {
// "To make matters worse, your Wooden Shield..."
// Shield danger (wooden vs fire, iron vs electrical)
FiAnalysisHandle analysis = FiContext::getNaviTableEquipmentCheckEntry();
s16 value = analysis.getShieldMessage();
if (value < 0) {
@@ -596,6 +612,7 @@ bool dFlow_c::handleMessage() {
}
mCurrentTextLabelName.sprintf("KEN3_%03d", value);
} else if (mCurrentTextLabelName == "KEN4_000") {
// Your hearts have decreased quite dramatically...
s32 fiHelpIndex = FiContext::getHelpIndex();
if (fiHelpIndex < 0) {
fiHelpIndex = 0;
@@ -605,6 +622,7 @@ bool dFlow_c::handleMessage() {
}
mCurrentTextLabelName.sprintf("KEN4_%03d", fiHelpIndex);
} else if (mCurrentTextLabelName == "KEN5_000") {
// This is...
s32 targetActorId = FiContext::getTargetActorId();
if (targetActorId < 0) {
targetActorId = 0;
@@ -612,9 +630,12 @@ bool dFlow_c::handleMessage() {
if (targetActorId <= 480) {
mCurrentTextLabelName.sprintf("KEN5_%03d", targetActorId);
} else {
// "My apologies. I have no relevant information on the subject in my sizable memory."
// FiHead
mCurrentTextLabelName.sprintf("KEN7_000");
}
} else if (mCurrentTextLabelName == "KEN6_000") {
// "Target lock: ..."
s32 targetActorId = FiContext::getTargetActorId();
if (targetActorId < 0) {
targetActorId = 0;
@@ -625,6 +646,7 @@ bool dFlow_c::handleMessage() {
mCurrentTextLabelName.sprintf("KEN7_000");
}
} else if (mCurrentTextLabelName == "KEN6_107") {
// "You have defeated <X> of this type of enemy. My analysis shows that your battle performance..."
s32 targetActorId = FiContext::getTargetActorId();
if (targetActorId < 0) {
targetActorId = 0;
@@ -633,26 +655,31 @@ bool dFlow_c::handleMessage() {
u8 performance = FiContext::rateBattlePerformance(targetActorId);
if (performance == 0xFF) {
dLytMsgWindow_c::getInstance()->setNumericArg0(killCount);
// "You have defeated <X> of this enemy type. I am unable to analyze your battle performance..."
mCurrentTextLabelName.sprintf("KEN6_108");
} else {
dLytMsgWindow_c::getInstance()->setNumericArg0(killCount);
SizedString<16> tmpLabel;
// "very strong, ..., very weak"
tmpLabel.sprintf("KEN6_1%02d", performance);
dLytMsgWindow_c::getInstance()->getTagProcessor()->setStringArg(
dMessage_c::getTextMessageByLabel(tmpLabel, true, nullptr, nullptr), 0
);
}
} else if (mCurrentTextLabelName == "KEN7_000") {
// "My apologies. I have no relevant information on the subject in my sizable memory."
s32 targetActorId = FiContext::getTargetActorId();
if (targetActorId < 0) {
targetActorId = 0;
}
if (targetActorId <= 561) {
// object info
mCurrentTextLabelName.sprintf("KEN7_%03d", targetActorId);
} else {
mCurrentTextLabelName.sprintf("KEN7_000");
}
} else if (mCurrentTextLabelName == "KEN8_000" || mCurrentTextLabelName == "KEN2_096") {
// "Current Session Play Time: ... Total Play Time: ..."
s32 seconds = OS_TICKS_TO_SEC(SaveTimeRelated::GetInstance()->getField_0x08());
s32 minutes_ = seconds / 60;
s32 minutes = minutes_ % 60;
@@ -672,12 +699,16 @@ bool dFlow_c::handleMessage() {
s32 time[4] = {hours, minutes, hours1, minutes1};
dLytMsgWindow_c::getInstance()->setNumericArgs(time, 4);
} else if (mCurrentTextLabelName == "KEN9_000") {
// Random hint
s32 v;
if (StoryflagManager::sInstance->getCounterOrFlag(530)) {
// "When you require my analysis..."
v = 200;
} else if (dStageMgr_c::GetInstance()->getSTIFbyte4() == 0) {
// Sky rumor
v = cM::rndInt(30);
} else {
// Elsewhere rumor
v = cM::rndInt(30) + 30;
}
mCurrentTextLabelName.sprintf("KEN9_%03d", v);
@@ -705,14 +736,14 @@ u16 dFlow_c::getSwitchChoice(const MsbFlowInfo *element, u16 param) const {
return result;
}
inline void setTagProcessorFiArgument(s32 a1, s32 a2) {
inline void setTagProcessorFiArgument(s32 argIdx, s32 btnIdx) {
dTagProcessor_c *p = dLytMsgWindow_c::getInstance()->getTagProcessor();
p->setStringArg(FiContext::getMessageForFiInfo(a1), a2);
p->setStringArg(FiContext::getMessageForFiInfo(argIdx), btnIdx);
}
inline void setTagProcessorArgument(s32 a1, s32 a2) {
inline void setTagProcessorArgument(s32 textLabel, s32 btnIdx) {
dTagProcessor_c *p = dLytMsgWindow_c::getInstance()->getTagProcessor();
p->setStringArg(FiContext::getTextMessage(a1), a2);
p->setStringArg(FiContext::getButtonText(textLabel), btnIdx);
}
u16 dFlow_c::branchHandler00(const MsbFlowInfo *element) const {
@@ -726,7 +757,7 @@ u16 dFlow_c::branchHandler01(const MsbFlowInfo *element) const {
u16 dFlow_c::branchHandler02(const MsbFlowInfo *element) const {
if (FiContext::getDoSpecialFiMenuHandlingChecked()) {
if (dLytMsgWindow_c::getInstance()->getTextOptionSelection() == 0 && FiContext::getGlobalFiInfo0(0) == 9) {
FiContext::do_fn_8016CB20();
FiContext::do_resetAdviceOptions();
setTagProcessorFiArgument(0, 0);
setTagProcessorFiArgument(1, 1);
setTagProcessorFiArgument(2, 2);
@@ -849,7 +880,7 @@ u16 dFlow_c::branchHandler19(const MsbFlowInfo *element) const {
break;
case 6: {
FiAnalysisHandle handle = FiContext::getNaviTableEquipmentCheckEntry();
switch (handle.shieldRelated()) {
switch (handle.getThreatenedShield()) {
case 0:
if (dAcPy_c::getCurrentlyEquippedShieldType() == 0) {
ret = 0;
@@ -892,7 +923,7 @@ u16 dFlow_c::branchHandler20(const MsbFlowInfo *element) const {
u16 dFlow_c::branchHandler21(const MsbFlowInfo *element) const {
u16 ret = 0;
if (shouldActorShowKillCount(FiContext::getTargetActorId())) {
if (shouldHideKillCountForActor(FiContext::getTargetActorId())) {
ret = 1;
}
return ret;
@@ -965,20 +996,20 @@ void dFlow_c::triggerEntryPoint(s32 labelPart1, s32 labelPart2) {
if (labelPart1 == 6 && labelPart2 == 801) {
// "You called for me, Master?"
FiContext::do_fn_8016CA00();
FiContext::do_prepareFiCallOptions();
FiContext::setDoSpecialFiMenuHandling(true);
FiContext::do_fn_8016CB40();
setTagProcessorFiArgument(0, 0);
setTagProcessorFiArgument(1, 1);
setTagProcessorFiArgument(2, 2);
setTagProcessorArgument(7, 3);
setTagProcessorArgument(FiContext::KEN8_Nevermind, 3);
} else if (labelPart1 == 6 && labelPart2 == 802) {
// Doesn't seem to exist in the files
FiContext::setDoSpecialFiMenuHandling(true);
setTagProcessorFiArgument(0, 0);
setTagProcessorFiArgument(1, 1);
setTagProcessorFiArgument(2, 2);
setTagProcessorArgument(7, 3);
setTagProcessorArgument(FiContext::KEN8_Nevermind, 3);
}
u16 entry = findEntryPoint(labelPart1, labelPart2);
start(entry);
@@ -1086,13 +1117,35 @@ bool dFlow_c::advanceUntil(s32 searchType, s32 searchParam3, s32 *pOutParams1n2)
return 0;
}
// TODO: Where are these IDs from?
static const s32 sActorsWithKillCount[] = {0, 1, 10, 46, 47, 48, 49, 50, 51, 52, 53,
54, 55, 65, 67, 77, 81, 87, 88, 89, 90, -1};
// TODO: Used KEN6 as reference, will be set from dAcBase_c::targetFiTextId (0x114)
static const s32 sActorsWithoutKillCount[] = {
0, // Remlit (Day)
1, // Remlit (Night)
10, // Moldarach
46, // Stalmaster
47, // LD-002S Scervo
48, // Koloktos
49, // Ghirahim (G1)
50, // Ghirahim (G2)
51, // Ghirahim (G3.1)
52, // The Imprisoned
53, // The Imprisoned
54, // The Imprisoned
55, // Demise
65, // Scaldera
67, // <?>
77, // Tentalus
81, // Peahat
87, // Sentrobe Bomb
88, // LD-003D Dreadfuse
89, // Ghirahim (G3.2)
90, // Ghirahim (G3.3)
-1 // <end of array>
};
bool dFlow_c::shouldActorShowKillCount(s32 id) const {
for (s32 i = 0; sActorsWithKillCount[i] >= 0; i++) {
if (sActorsWithKillCount[i] == id) {
bool dFlow_c::shouldHideKillCountForActor(s32 id) const {
for (s32 i = 0; sActorsWithoutKillCount[i] >= 0; i++) {
if (sActorsWithoutKillCount[i] == id) {
return true;
}
}
+5 -5
View File
@@ -8,6 +8,7 @@
#include "d/lyt/d_lyt_unknowns.h"
#include "d/lyt/meter/d_lyt_meter.h"
#include "toBeSorted/event_manager.h"
#include "toBeSorted/fi_context.h"
#include "toBeSorted/small_sound_mgr.h"
STATE_DEFINE(dLytMeterCrossBtnParts_c, Wait);
@@ -406,7 +407,7 @@ bool dLytMeterCrossBtn_c::build(d2d::ResAccIf_c *resAcc) {
field_0x635 = 0;
field_0x636 = 0;
field_0x628 = 0xFFFF;
mSavedFiFlow = 0xFFFF;
mCallCount0 = 0;
mCallCount1 = 0;
field_0x620 = 6;
@@ -457,11 +458,10 @@ bool dLytMeterCrossBtn_c::remove() {
return true;
}
extern "C" u16 prepareFiHelpIndex();
bool dLytMeterCrossBtn_c::execute() {
u16 newFiValue = prepareFiHelpIndex();
if (newFiValue != field_0x628) {
field_0x628 = newFiValue;
u16 newFiFlow = FiContext::prepareFiHelpIndex();
if (newFiFlow != mSavedFiFlow) {
mSavedFiFlow = newFiFlow;
mCallCount0 = 0;
}
+1 -1
View File
@@ -278,7 +278,7 @@ bool dLytMeterShieldGauge_c::execute() {
}
if (mAnm[SHIELD_ANIM_BREAK].isEnabled()) {
if (field_0x318 == 0 && field_0x2E0 > 0) {
if (field_0x318 == 0 && field_0x2E0 > 0.0f) {
mAnm[SHIELD_ANIM_BREAK].setFrame(0.0f);
mAnm[SHIELD_ANIM_BREAK].setAnimEnable(true); // redundant?
field_0x30C = 0;
+4 -4
View File
@@ -90,7 +90,7 @@ bool dLytMsgWindow_c::build() {
mpMsgWindowUnk = new TextWindowUnk(mpTagProcessor);
if (FiContext::GetInstance() != nullptr) {
FiContext::GetInstance()->resetField_0x3C();
FiContext::GetInstance()->resetSaveTimeRelated();
}
mpWindowTalk = nullptr;
@@ -105,7 +105,7 @@ bool dLytMsgWindow_c::build() {
mpCurrentSubtype = nullptr;
mTextOptionSelection = 0;
mSpecialFiMenuValue = 7;
mSpecialFiMenuValue = FiContext::KEN8_Nevermind;
field_0x1220 = 0;
@@ -199,7 +199,7 @@ void dLytMsgWindow_c::executeState_Invisible() {
} else {
createSubMsgManager(mpTagProcessor->getMsgWindowSubtype());
field_0x828 = nullptr;
mSpecialFiMenuValue = 7;
mSpecialFiMenuValue = FiContext::KEN8_Nevermind;
if (mpTagProcessor->getMsgWindowSubtype() == 6) {
mpCurrentSubtype = mpWindowWood;
dTextBox_c *box = mpCurrentSubtype->getTextBox();
@@ -523,7 +523,7 @@ void dLytMsgWindow_c::executeState_WaitKeySelectQuestion() {
case 0: mSpecialFiMenuValue = FiContext::getGlobalFiInfo0(0); break;
case 1: mSpecialFiMenuValue = FiContext::getGlobalFiInfo0(1); break;
case 2: mSpecialFiMenuValue = FiContext::getGlobalFiInfo0(2); break;
case 3: mSpecialFiMenuValue = 7; break;
case 3: mSpecialFiMenuValue = FiContext::KEN8_Nevermind; break;
}
}
+2
View File
@@ -116,6 +116,7 @@ dEmitterBase_c::~dEmitterBase_c() {
}
JPABaseEmitter *dEmitterBase_c::GetNextEmitter(JPABaseEmitter *head) {
// Portability hazard: u32->pointer cast
return reinterpret_cast<JPABaseEmitter *>(head->getUserWork());
}
@@ -132,6 +133,7 @@ bool dEmitterBase_c::createEmitters(
);
if (last != nullptr) {
if (head != nullptr) {
// Portability hazard: pointer->u32 cast
head->setUserWork(reinterpret_cast<u32>(last));
} else {
mpEmitterHead = last;
+439
View File
@@ -0,0 +1,439 @@
#include "toBeSorted/fi_context.h"
#include "common.h"
#include "d/a/d_a_item.h"
#include "d/d_message.h"
#include "d/d_pouch.h"
#include "d/d_sc_game.h"
#include "d/d_stage_mgr.h"
#include "d/flag/itemflag_manager.h"
#include "d/flag/storyflag_manager.h"
#include "d/lyt/meter/d_lyt_meter.h"
#include "sized_string.h"
#include "toBeSorted/file_manager.h"
#include "toBeSorted/unk_save_time.h"
// https://github.com/lepelog/skywardsword-tools/wiki/Navi-Table-(Fi-Advice)
// Portability hazard, only works for 32 bit architectures
struct AdviceSummaryEntry {
/* 0x00 */ u16 storyflag;
/* 0x02 */ u16 KEN0_entry_num;
};
struct AdviceHintEntry {
/* 0x00 */ char *stage_name_ptr;
/* 0x04 */ s16 storyflag;
/* 0x06 */ u16 KEN1_entry_num;
};
struct ObjectiveEntry {
/* 0x00 */ u16 storyflag;
/* 0x02 */ u16 KEN2_entry_num;
};
struct AnalysisEntry {
/* 0x00 */ char *stage_name_ptr;
/* 0x04 */ s16 storyflag;
/* 0x06 */ u16 KEN3_danger_entry_num;
/* 0x08 */ u8 sutability_percent[4];
/* 0x0C */ u16 KEN3_sutability_entry_num[4];
/* 0x14 */ u16 area_shield_danger; // -1-no danger, 0-wooden burns, 1- iron electrifies
/* 0x16 */ u16 KEN3_shield_entry_num;
};
struct FileHeader {
/* 0x00 */ u32 magic; // Is `V001`
/* 0x04 */ u16 summary_count;
/* 0x06 */ u16 hint_count;
/* 0x08 */ u16 objective_count;
/* 0x0A */ u16 analysis_count;
/* 0x0C */ AdviceSummaryEntry *summary; // ptr to AdviceSummaryEntry[summary_count]
/* 0x10 */ AdviceHintEntry *hint; // ptr to AdviceHintEntry[hint_count]
/* 0x14 */ ObjectiveEntry *objective; // ptr to ObjectiveEntry[objective_count]
/* 0x18 */ AnalysisEntry *analysis; // ptr to AnalysisEntry[analysis_count]
};
bool FiAnalysisHandle::isValid() const {
return mpEntry != nullptr;
}
s16 FiAnalysisHandle::getAreaIndexForFiAreaName() const {
if (isValid()) {
return mpEntry->KEN3_danger_entry_num;
} else {
return -1;
}
}
FiAnalysisHandle::FiAnalysisEquipmentFocus_e FiAnalysisHandle::getCurrentFocus() {
s32 pouchContents = summarizePouchContents(nullptr, nullptr, nullptr);
if (pouchContents == 0) {
return FOCUS_COMBAT;
} else if (pouchContents == 1) {
return FOCUS_BALANCED;
} else if (pouchContents == 2) {
return FOCUS_TREASURE;
} else if (pouchContents == 3) {
return FOCUS_SURVIVAL;
}
return FOCUS_COMBAT;
}
s16 FiAnalysisHandle::getEquipmentFocus() const {
static const s16 sEquipmentFocuses[] = {400, 403, 402, 401};
if (!isValid()) {
return -1;
} else {
if (StoryflagManager::sInstance->getCounterOrFlag(530)) {
// "I cannot offer my usual analysis because you are currently engaged in a challenge created by the Thunder
// Dragon Lanayru."
return 180;
}
return sEquipmentFocuses[getCurrentFocus()];
}
}
s32 FiAnalysisHandle::getSuitabilityPercentageArg() const {
if (!isValid()) {
return -1;
} else {
return mpEntry->sutability_percent[getCurrentFocus()];
}
}
s16 FiAnalysisHandle::getEquipmentRecommendation() const {
if (!isValid()) {
return -1;
} else {
return mpEntry->KEN3_sutability_entry_num[getCurrentFocus()];
}
}
s16 FiAnalysisHandle::getThreatenedShield() {
if (isValid()) {
return mpEntry->area_shield_danger;
} else {
return -1;
}
}
s16 FiAnalysisHandle::getShieldMessage() {
if (isValid()) {
return mpEntry->KEN3_shield_entry_num;
} else {
return -1;
}
}
FiContext *FiContext::sInstance;
static FileHeader *sNaviTable;
#define BIND_PTR(type, header, pointer) \
pointer = reinterpret_cast<type *>(reinterpret_cast<char *>(header) + reinterpret_cast<u32>(pointer))
void FiContext::initialize(void *data) {
FileHeader *header = reinterpret_cast<FileHeader *>(data);
BIND_PTR(AdviceSummaryEntry, header, header->summary);
BIND_PTR(AdviceHintEntry, header, header->hint);
AdviceHintEntry *hint = header->hint;
for (s32 i = 0; i < header->hint_count; i++) {
BIND_PTR(char, header, hint[i].stage_name_ptr);
}
BIND_PTR(ObjectiveEntry, header, header->objective);
BIND_PTR(AnalysisEntry, header, header->analysis);
AnalysisEntry *analysis = header->analysis;
for (s32 i = 0; i < header->analysis_count; i++) {
BIND_PTR(char, header, analysis[i].stage_name_ptr);
}
sNaviTable = header;
}
s16 FiContext::getNaviTableProgressSummary() {
if (StoryflagManager::sInstance->getFlag(530)) {
// When in boss rush, no progress is available since story flags
// are unreliable here.
// "You are currently reliving some of your previous battles within the Thunder Dragon's Lightning Round..."
return 40;
} else {
// Find the last entry with a set story flag
AdviceSummaryEntry *last = sNaviTable->summary + (sNaviTable->summary_count - 1);
for (s32 i = 0; i < sNaviTable->summary_count; i++) {
if (StoryflagManager::sInstance->getFlag(last->storyflag)) {
return last->KEN0_entry_num;
}
last--;
}
return -1;
}
}
s16 FiContext::getFiAdviceHintEntry() {
if (StoryflagManager::sInstance->getFlag(530)) {
// When in boss rush, no hint since location doesn't make sense
// "Master, this is a world built from your memories by Lanayru, the Thunder Dragon"
return 37;
} else {
// Find the first entry that matches the current stage, if its story flag matches (if any)
AdviceHintEntry *first = sNaviTable->hint;
for (s32 i = 0; i < sNaviTable->hint_count; i++) {
if (dScGame_c::isCurrentStage(first->stage_name_ptr) &&
(first->storyflag < 0 || StoryflagManager::sInstance->getFlag(first->storyflag))) {
return first->KEN1_entry_num;
}
first++;
}
// "This place has no name registered in my memory, and I have no useful data..."
return 31;
}
}
s16 FiContext::getObjective() {
if (StoryflagManager::sInstance->getFlag(530)) {
// When in boss rush, objective is to beat the mode
// "Master, your primary objective is to defeat the enemy here and overcome the grueling task the Thunder
// Dragon, Lanayru, has set before you..."
return 92;
} else {
if (StoryflagManager::sInstance->getFlag(136) && StoryflagManager::sInstance->getFlag(143) &&
StoryflagManager::sInstance->getFlag(144) && StoryflagManager::sInstance->getFlag(145) &&
!StoryflagManager::sInstance->getFlag(133)) {
// "Demise has once again broken the seal that binds him..."
return 70;
}
if (!StoryflagManager::sInstance->getCounterOrFlag(21)) {
if (ItemflagManager::sInstance->getFlagDirect(0xC5) && !ItemflagManager::sInstance->getFlagDirect(0xC6)) {
// "I project that the soil in Lanayru Province will not provide enough nourishment for the Life Tree
// Seedling..."
return 90;
}
if (ItemflagManager::sInstance->getFlagDirect(0xC6)) {
// "Master, I recommend you take the Life Tree Fruit to the Thunder Dragon..."
return 91;
}
}
// Find the last entry with a set story flag
ObjectiveEntry *last = sNaviTable->objective + (sNaviTable->objective_count - 1);
for (s32 i = 0; i < sNaviTable->objective_count; i++) {
if (StoryflagManager::sInstance->getFlag(last->storyflag)) {
return last->KEN2_entry_num;
}
last--;
}
return -1;
}
}
FiAnalysisHandle FiContext::getNaviTableEquipmentCheckEntry() {
AnalysisEntry *first = sNaviTable->analysis;
for (s32 i = 0; i < sNaviTable->analysis_count; i++) {
// Find the first entry that matches the current stage, if its story flag matches (if any)
if (dScGame_c::isCurrentStage(first->stage_name_ptr) &&
(first->storyflag < 0 || StoryflagManager::sInstance->getFlag(first->storyflag))) {
return FiAnalysisHandle(first);
}
first++;
}
return FiAnalysisHandle(nullptr);
}
s32 FiContext::setTargetedActorTextId(s32 id) {
setTargetActorId(-1);
s32 ret;
if (id < 256) {
ret = 6600; // Flow?
setTargetActorId(id);
} else if (id < 512) {
ret = 6500; // Flow?
setTargetActorId(id - 256);
} else if (id < 768) {
ret = 6700; // Flow?
setTargetActorId(id - 512);
} else {
ret = 6500; // Flow?
setTargetActorId(id - 668);
}
return ret;
}
u8 FiContext::rateBattlePerformance(u8 id) {
u8 ret = 0xFF;
u16 killCount = FileManager::GetInstance()->getEnemyKillCount(id);
u16 enemyHitCount = FileManager::GetInstance()->getHitCountFromEnemy(id);
if (killCount > 3 || enemyHitCount > 5) {
if (killCount == 0) {
ret = 6;
} else {
f32 ratio = (f32)enemyHitCount / (f32)killCount;
if (ratio <= 0.2f) {
ret = 0;
} else if (ratio <= (1.0f / 3.0f)) {
ret = 1;
} else if (ratio <= 1.0f) {
ret = 2;
} else if (ratio <= 1.5f) {
ret = 3;
} else if (ratio <= 2.5f) {
ret = 4;
} else if (ratio <= 4.0f) {
ret = 5;
} else {
ret = 6;
}
}
}
return ret;
}
extern "C" bool isLowBattery1();
extern "C" bool isLowBattery2();
u16 FiContext::prepareFiHelpIndex() {
u16 ret = 0xFFFF;
setHelpIndex(-1);
if (dLytMeter_c::getShieldLevel() > 0.0f && dLytMeter_c::getShieldGaugePercentMaybe() > 0.0f) {
if (dLytMeter_c::getShieldGaugePercentMaybe() <= 6.0f) {
if (!getField_0x4A()) {
ret = 6402;
// "The integrity of your shield has weakened..."
setHelpIndex(1);
}
} else {
if (getField_0x4A()) {
setField_0x4A(false);
}
}
}
if (FileManager::GetInstance()->getCurrentHealth() <= 12 && !StoryflagManager::sInstance->getCounterOrFlag(808)) {
ret = 6401;
// "Your hearts have decreased quite dramatically..."
setHelpIndex(0);
}
if (isLowBattery2() || isLowBattery1()) {
if (!getField_0x48()) {
ret = 6400;
if (isLowBattery1()) {
// "Master, the batteries in your Wii Remote will be depleted any moment."
setHelpIndex(3);
} else {
// "Master, the batteries in your Wii Remote are nearly depleted."
setHelpIndex(2);
}
}
} else {
if (getField_0x48()) {
setField_0x48(false);
}
}
u32 numRupees = dAcItem_c::getRupeeCounter();
u32 walletCapacity = dAcItem_c::getCurrentWalletCapacity();
if (!StoryflagManager::sInstance->getFlag(727) && walletCapacity != 0 && numRupees == walletCapacity &&
!getField_0x47()) {
ret = 6400;
// "Master, your wallet is full..."
setHelpIndex(5);
}
return ret;
}
s32 FiContext::getGlobalFiInfo0(s32 idx) {
if (sInstance != nullptr) {
return sInstance->mFiButtonOptions[idx];
}
return KEN8_None;
}
const wchar_t *FiContext::getButtonText(s32 idx) {
SizedString<16> str;
str.sprintf("KEN8_1%02d", idx + 1);
return dMessage_c::getTextMessageByLabel(str, true, nullptr, 0);
}
void FiContext::create() {
sInstance = new FiContext();
sInstance->reset();
}
void FiContext::reset() {
for (s32 i = 0; i < 10; i++) {
mFiButtonOptions[i] = KEN8_None;
field_0x3D[i] = 0xFF;
}
field_0x47 = false;
field_0x48 = false;
field_0x49 = false;
field_0x4A = false;
mSaveTimeRelated = 0xFF;
fn_8016CB40();
mTargetActorId = -1;
mFiHelpIndex = -1;
mDoSpecialFiMenuHandling = false;
}
void FiContext::resetSaveTimeRelated() {
mSaveTimeRelated = 0xFF;
}
extern "C" bool isInAnySkyKeepRoom();
void FiContext::prepareFiCallOptions() {
s32 seconds1 = OS_TICKS_TO_SEC(SaveTimeRelated::GetInstance()->getField_0x30());
s32 seconds2 = OS_TICKS_TO_SEC(SaveTimeRelated::GetInstance()->getField_0x08());
u8 val = 2;
if (seconds2 < 300) {
val = 0;
} else if (seconds1 < 300) {
val = 1;
}
if (mSaveTimeRelated != val) {
mSaveTimeRelated = val;
}
mFiButtonOptions[0] = KEN8_Advice;
if (dStageMgr_c::GetInstance()->getSTIFbyte4() == 0 && !isInAnySkyKeepRoom() && !isInLeviasFightMaybe()) {
// In the Sky, show play time
mFiButtonOptions[1] = KEN8_PlayTime;
} else {
// Elswhere, and in Sky Keep and Levias fight, present analysis
mFiButtonOptions[1] = KEN8_Analysis;
}
mFiButtonOptions[2] = KEN8_Objective;
}
void FiContext::setAdviceOptions(s32 unused) {
mFiButtonOptions[0] = KEN8_Hint;
mFiButtonOptions[1] = KEN8_Rumors;
mFiButtonOptions[2] = KEN8_Summary;
}
void FiContext::resetAdviceOptions() {
mFiButtonOptions[0] = KEN8_Hint;
mFiButtonOptions[1] = KEN8_Rumors;
mFiButtonOptions[2] = KEN8_Summary;
}
void FiContext::fn_8016CB40() {
field_0x28 = 0;
field_0x2C = 1;
field_0x30 = 2;
}
bool FiContext::isInLeviasFightMaybe() {
if (dScGame_c::isCurrentStage("F023") && StoryflagManager::sInstance->getFlag(368) &&
!StoryflagManager::sInstance->getFlag(200)) {
return true;
}
return false;
}
+2 -2
View File
@@ -133,9 +133,9 @@ u16 *FileManager::getStoryFlagsMut() {
}
/* 8000ABD0 */ void FileManager::setCurrentHealthCapacity(s16 health) {}
/* 8000AC00 */ s16 FileManager::getCurrentHealthCapacity() {}
/* 8000AC00 */ u16 FileManager::getCurrentHealthCapacity() {}
/* 8000AC50 */ void FileManager::setCurrentHealth(s16 health) {}
/* 8000AC80 */ s16 FileManager::getCurrentHealth() {}
/* 8000AC80 */ u16 FileManager::getCurrentHealth() {}
/* 8000ACD0 */ u16 FileManager::getLoadRoomT1() {}
/* 8000AD20 */ u16 FileManager::getLoadRoomT2() {}