ManagerB.c: Documentation

Split out the jump table data, renamed all the functions, added some comments for what is going on
This commit is contained in:
Ibot02 2020-08-23 15:02:59 +02:00
parent 8ab5503804
commit 9b8f80ef77
6 changed files with 5937 additions and 5895 deletions

View File

@ -1161,7 +1161,7 @@ sub_0804A4E4: @ 0x0804A4E4
beq _0804A550
adds r0, r5, #0
adds r1, r6, #0
bl sub_08058800
bl ReplaceMonitoredEntity
_0804A550:
pop {r4, r5, r6, r7, pc}
.align 2, 0
@ -1828,4 +1828,4 @@ sub_0804AA1C: @ 0x0804AA1C
str r0, [r2, #0x68]
_0804AA2C:
pop {pc}
.align 2, 0
.align 2, 0

View File

@ -85,7 +85,7 @@ sub_0804525C: @ 0x0804525C
beq _08045298
adds r0, r4, #0
adds r1, r3, #0
bl sub_08058800
bl ReplaceMonitoredEntity
_08045298:
adds r0, r4, #0
bl sub_0804A7D4

File diff suppressed because it is too large Load Diff

5852
data/data_0810821C.s Normal file

File diff suppressed because it is too large Load Diff

View File

@ -918,6 +918,8 @@ SECTIONS {
data/data_080D5360.o(.rodata);
src/mainLoop.o(.rodata);
data/data_08100CD4.o(.rodata);
src/manager/managerB.o(.rodata);
data/data_0810821C.o(.rodata);
src/item.o(.rodata);
data/data_0811BD44.o(.rodata);
src/object/greatFairy.o(.rodata);

View File

@ -6,25 +6,42 @@
#include "area.h"
#include "functions.h"
extern void (*(gUnk_08108208[]))(Manager*);
/*
* Manager B is used to create fights:
* It possibly waits for an inhibitor flag to be set, then spawns a bunch of entities (based on room data).
* Once all enemies created this way are dead, it sets a flag.
* (There is also a part about changing the music and setting it back when the fight is done, which is song 0x33 (a fight theme) by default but can be overridden through room data)
*/
void (*const ManagerB_ActionFuncs[])(Manager*);
void sub_080585F0(Manager* this) {
gUnk_08108208[this->unk_0a](this);
//make a distincion if this is a controller (unk_0a = 0) or a helper (unk_0a = 1)
ManagerB_ActionFuncs[this->unk_0a](this);
}
extern void (*(gUnk_08108210[]))(Manager*);
enum ManagerB_State {
Init,
WaitForFlag,
WaitForDone
};
void sub_08058608(Manager* this) {
gUnk_08108210[this->action](this);
void (*const ManagerB_StateFuncs[])(ManagerB*);
void ManagerB_Main(ManagerB* this) {
//make a distinction based on the state of this controller
ManagerB_StateFuncs[this->manager.action](this);
}
void sub_080586EC(Manager*);
void ManagerB_LoadFight(Manager*);
void sub_08058620(ManagerB* this) {
void ManagerB_Init(ManagerB* this) {
//check if the fight was already completed previously (checks the flag that gets set after the fight is done)
if (!CheckFlags(this->unk_3e)) {
this->manager.action = 1;
this->manager.action = WaitForFlag;
//if there is no flag that needs to be set before the fight is started, start it immediately
if (!this->unk_3c) {
sub_080586EC(&this->manager);
ManagerB_LoadFight(&this->manager);
}
sub_0805E3A0(this, 3);
} else {
@ -33,10 +50,10 @@ void sub_08058620(ManagerB* this) {
}
extern void sub_080186C0(u32);
void sub_08058650(ManagerB* this) {
void ManagerB_WaitForFlag(ManagerB* this) {
int tmp;
if (CheckFlags(this->unk_3c)) {
sub_080586EC(&this->manager);
ManagerB_LoadFight(&this->manager);
if (!this->unk_35) {
tmp = gRoomVars.field_0x9 ? gRoomVars.field_0x9 : 0x33;
this->unk_20 = gArea.musicIndex;
@ -49,9 +66,12 @@ void sub_08058650(ManagerB* this) {
extern void sub_0801855C(void);
void sub_080586A8(ManagerB* this) {
void ManagerB_WaitForDone(ManagerB* this) {
//check if all helpers are done
if (this->manager.unk_0e) return;
//set the completion flag for the fight
SetFlag(this->unk_3e);
//restore music (if it was set, which apparently is only possible if there's a flag the fight waited for)
if (this->unk_3c) {
if (!this->unk_35) {
gArea.musicIndex = this->unk_20;
@ -62,40 +82,45 @@ void sub_080586A8(ManagerB* this) {
DeleteThisEntity();
}
ManagerBHelper* sub_08058760(Manager*);
void sub_08058798(ManagerBHelper*, Entity*, u32);
ManagerBHelper* CreateHelper(Manager*);
void ManagerBHelper_Monitor(ManagerBHelper*, Entity*, u32);
extern EntityData* GetCurrentRoomProperty(u8);
extern Entity* LoadRoomEntity(EntityData*);
void sub_080586EC(Manager* this) {
ManagerBHelper* tmp;
void ManagerB_LoadFight(Manager* this) {
ManagerBHelper* monitor;
EntityData* prop;
Entity* ent;
u32 counter;
this->action = 2;
this->unk_0e = 0;
counter = 0;
tmp = sub_08058760(this);
if (!tmp) DeleteThisEntity();
//Create a helper to keep track of the created entities.
monitor = CreateHelper(this);
if (!monitor) DeleteThisEntity();
prop = (EntityData*) GetCurrentRoomProperty(this->unk_0b);
if (prop) {
while (*((u8*)prop) != 0xFF) {
ent = LoadRoomEntity(prop++);
if (ent && (ent->entityType.type == 3)) {
ent->field_0x6c.HALF.HI |= 0x40;
sub_08058798(tmp, ent, counter++);
ManagerBHelper_Monitor(monitor, ent, counter++);
}
if (counter >= 7) {
counter = 0;
tmp = sub_08058760(this);
if (!tmp) return;
monitor = CreateHelper(this);
if (!monitor) return;
}
}
}
}
ManagerBHelper* sub_08058760(Manager* this) {
/*
* Create a helper and increment the counter for the number of helpers (unk_0e).
* The helper will decrease said counter when it deletes itself (when none of the enemies it monitors remain).
*/
ManagerBHelper* CreateHelper(Manager* this) {
ManagerBHelper* extra;
extra = (ManagerBHelper*) GetEmptyManager();
if (extra) {
@ -110,51 +135,67 @@ ManagerBHelper* sub_08058760(Manager* this) {
return extra;
}
void sub_08058798(ManagerBHelper* this, Entity* value, u32 index) {
this->enemies[index]=value;
void ManagerBHelper_Monitor(ManagerBHelper* this, Entity* ent, u32 index) {
this->enemies[index]=ent;
this->manager.unk_0e++;
}
void sub_080587AC(ManagerBHelper* this) {
u8 i, tmp;
//case unk_0a is 1: The manager is a helper
void ManagerBHelper_Main(Manager* this) {
u8 i, anyRemaining;
Entity* current;
if (this->manager.action == 0) {
this->manager.action = 1;
if (this->action == 0) {
this->action = 1;
sub_0805E3A0(this,3);
}
tmp = 0;
//go through and check all monitored enemies.
anyRemaining = 0;
for (i = 0; i < 8; i++) {
if ((current = this->enemies[i])) {
if ((current = ((ManagerBHelper*)this)->enemies[i])) {
if (!current->next) {
this->enemies[i] = 0;
((ManagerBHelper*) this)->enemies[i] = 0;
} else {
tmp = 1;
anyRemaining = 1;
}
}
}
if (!tmp) {
if (((ManagerB*) this->manager.parent)->manager.unk_0e) {
((ManagerB*) this->manager.parent)->manager.unk_0e--;
if (!anyRemaining) {
//inform the parent that we're done
if (((ManagerB*) this->parent)->manager.unk_0e) {
((ManagerB*) this->parent)->manager.unk_0e--;
}
DeleteThisEntity();
DeleteThisEntity();
}
}
extern Manager gUnk_03003DB0;
void sub_08058800(Entity* this, Entity* unk1) {
/*
* Replace an entity that is currently being monitored with a new one
*/
void ReplaceMonitoredEntity(Entity* old, Entity* new) {
ManagerBHelper* current;
Manager* end = &gUnk_03003DB0;
u32 i;
for (current = (ManagerBHelper*) end->next; (Manager*)current != end; current=(ManagerBHelper*)current->manager.next) {
if (current->manager.type != 0x9 || current->manager.subtype != 0xB) continue;
for (i = 0; i < 8; i++) {
if (this == current->enemies[i]) {
current->enemies[i] = unk1;
if (old == current->enemies[i]) {
current->enemies[i] = new;
return;
}
}
}
}
void (*const ManagerB_ActionFuncs[])(Manager*) = {
(void (*)(Manager*)) ManagerB_Main,
(void (*)(Manager*)) ManagerBHelper_Main
};
void (*const ManagerB_StateFuncs[])(ManagerB*) = {
ManagerB_Init,
ManagerB_WaitForFlag,
ManagerB_WaitForDone
};