summaryrefslogtreecommitdiff
path: root/src/manager/manager5.c
blob: fbb4da2e2b29d5e39667a1440480fe90921f3cb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "global.h"
#include "audio.h"
#include "manager.h"
#include "flags.h"
#include "functions.h"

typedef struct {
    Manager manager;
    u8 unk_20[0x08];
    u16 unk_28;
    u16 unk_2a;
    u16 unk_2c;
    u16 unk_2e;
    u16 unk_30;
    u16 unk_32;
    u8 unk_34[0x04];
    s16 unk_38;
    s16 unk_3a;
    u16 unk_3c;
    u16 unk_3e;
} Manager5;

void sub_08057AE8(Manager5*);
void sub_08057BA4(Manager5*);
void sub_08057C28(Manager5*);

const u16 gUnk_08108024[] = { 0, -1, 1, 0, 0, 1, -1, 0 };
const u16 gUnk_08108034[] = { 0, 1, -1, 0, 0, -1, 1, 0 };

void (*const gUnk_08108044[])(Manager5*) = { sub_08057AE8, sub_08057BA4, sub_08057C28 };

void sub_08057AD0(Manager5* this) {
    gUnk_08108044[this->manager.action](this);
}

void sub_08057CA4(Manager5*, u32, u32);

void sub_08057AE8(Manager5* this) {
    u32 tmp;
    tmp = (this->manager.unk_0b & 0x3) << 1;
    if (this->manager.unk_0e == 1) {
        this->unk_30 = 0x323;
    } else {
        this->unk_30 = tmp & 2 ? 0x37 : 0x36;
    }
    this->unk_28 = gUnk_08108024[tmp];
    this->unk_2a = gUnk_08108024[tmp + 1];
    this->unk_2c = gUnk_08108034[tmp];
    this->unk_2e = gUnk_08108034[tmp + 1];
    this->unk_32 = ((this->manager.unk_0b >> 2) & 0xF) + 1;
    this->manager.unk_0e = 0x1C;
    this->manager.unk_0f = 0;
    this->manager.action = (this->manager.unk_0b & 0x80) ? 2 : 1;
    if (this->manager.action != 2 || !CheckFlags(this->unk_3e))
        return;
    for (; this->unk_32; this->unk_32--) {
        sub_08057CA4(this, this->unk_28, this->unk_2a);
        sub_0807B7D8(this->unk_30, this->unk_38 | (this->unk_3a << 6), this->unk_3c);
    }
    DeleteManager(&this->manager);
}

void sub_08057BA4(Manager5* this) {
    if (--this->manager.unk_0e)
        return;
    this->manager.unk_0e = 8;
    if (CheckFlags(this->unk_3e)) {
        if (this->unk_32 == this->manager.unk_0f)
            return;
        sub_08057CA4(this, this->unk_28, this->unk_2a);
        sub_0807B7D8(this->unk_30, this->unk_38 | (this->unk_3a << 6), this->unk_3c);
        this->manager.unk_0f++;
        SoundReq(SFX_HEART_GET);
    } else {
        if (!this->manager.unk_0f)
            return;
        sub_0807BA8C(this->unk_38 | (this->unk_3a << 6), this->unk_3c);
        sub_08057CA4(this, this->unk_2c, this->unk_2e);
        this->manager.unk_0f--;
        SoundReq(SFX_HEART_GET);
    }
}

void sub_08057C28(Manager5* this) {
    if (!this->manager.unk_0d) {
        if (!CheckFlags(this->unk_3e))
            return;
        this->manager.unk_0d++;
    } else {
        if (--this->manager.unk_0e)
            return;
        this->manager.unk_0e = 8;
        if (this->unk_32 != this->manager.unk_0f) {
            sub_08057CA4(this, this->unk_28, this->unk_2a);
            sub_0807B7D8(this->unk_30, this->unk_38 | (this->unk_3a << 6), this->unk_3c);
            this->manager.unk_0f++;
            SoundReq(SFX_HEART_GET);
        } else {
            if (this->unk_30 != 0x323) {
                SoundReq(SFX_SECRET);
            }
            DeleteManager(&this->manager);
        }
    }
}

void sub_08057CA4(Manager5* this, u32 unk1, u32 unk2) {
    this->unk_38 += unk1;
    this->unk_3a += unk2;
}