summaryrefslogtreecommitdiff
path: root/src/object/japaneseSubtitle.c
blob: 5a14192e395bdd1031e810a0aa11bfe90f257691 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
 * @file japaneseSubtitle.c
 * @ingroup Objects
 *
 * @brief Japanese Subtitle object
 */
#include "menu.h"
#include "object.h"
#include "asm.h"
#include "physics.h"

extern void sub_0806FB00(Entity*, u32, u32, u32);
extern bool32 sub_0806FB38(Entity*);

void JapaneseSubtitle_Type0(Entity*);
void JapaneseSubtitle_Type1(Entity*);
void JapaneseSubtitle_Type2(Entity*);
void JapaneseSubtitle_Type3(Entity*);

const u16 gUnk_08124B10[] = { 0x40, 0x58, 0x68, 0x80, 0x94, 0xA8, 0xB0, 0x0 };

void JapaneseSubtitle(Entity* this) {
    static void (*const JapaneseSubtitle_Types[])(Entity*) = {
        JapaneseSubtitle_Type0,
        JapaneseSubtitle_Type1,
        JapaneseSubtitle_Type2,
        JapaneseSubtitle_Type3,
    };

    JapaneseSubtitle_Types[this->type]((Entity*)this);
}

void JapaneseSubtitle_Type0(Entity* this) {
    Entity* pEVar3;

    switch (this->action) {
        case 0:
            this->action = 1;
            this->spriteSettings.draw = 2;
            this->frameIndex = 9;
            this->timer = 8;
            this->subtimer = 0;
            this->spriteRendering.b3 = 1;
            this->spritePriority.b0 = 4;
            this->spriteOrientation.flipY = 1;
            sub_0806FB00(this, 0xbf, 0x48, 0x1e);
            break;
        case 1:
            if ((this->subtimer < 7) && (--this->timer == 0)) {
                this->timer = 1;
                pEVar3 = CreateObject(JAPANESE_SUBTITLE, 1, this->subtimer);
                if (pEVar3 != NULL) {
                    CopyPosition(this, pEVar3);
                    pEVar3->y.HALF.HI = 0x68;
                    SortEntityBelow(this, pEVar3);
                }
                this->subtimer++;
            }

            if (sub_0806FB38(this) || (1 < gMenu.menuType)) {
                this->x.HALF.HI = 0xbf;
                this->y.HALF.HI = 0x48;
                this->frameIndex = 10;
                this->action = 2;
                while (this->subtimer < 7) {
                    pEVar3 = CreateObject(JAPANESE_SUBTITLE, 1, this->subtimer);
                    if (pEVar3 != NULL) {
                        CopyPosition(this, pEVar3);
                        pEVar3->y.HALF.HI = 0x68;
                        SortEntityBelow(this, pEVar3);
                    }
                    this->subtimer++;
                }

                pEVar3 = CreateObject(JAPANESE_SUBTITLE, 2, 0);
                if (pEVar3 != NULL) {
                    pEVar3->x.HALF.HI = 0xc4;
                    pEVar3->y.HALF.HI = 0x2c;
                    SortEntityAbove(this, pEVar3);
                }

                pEVar3 = CreateObject(JAPANESE_SUBTITLE, 3, 0);
                if (pEVar3 != NULL) {
                    pEVar3->x.HALF.HI = 0xb4;
                    pEVar3->y.HALF.HI = 0x19;
                    SortEntityAbove(this, pEVar3);
                }
            }
    }
}

void JapaneseSubtitle_Type1(Entity* this) {
    switch (this->action) {
        case 0:
            this->action = 1;
            this->spriteSettings.draw = 2;
            this->frameIndex = this->type2 + 2;
            sub_0806FB00(this, gUnk_08124B10[this->type2], 0x68, 0x14);
            break;
        case 1:
            if (sub_0806FB38(this) || 1 < gMenu.menuType) {
                this->x.HALF.HI = gUnk_08124B10[this->type2];
                this->y.HALF.HI = 0x68;
                this->spritePriority.b0 = 7 - this->type2;
                this->action = 2;
            }
            break;
    }
}

void JapaneseSubtitle_Type2(Entity* this) {
    static const u8 gUnk_08124B30[] = { 9, 10, 11, 12, 11, 10, 9, -1 };
    if (this->action == 0) {
        this->action = 1;
        this->spriteSettings.draw = 2;
        this->spriteRendering.b3 = 1;
        this->spritePriority.b0 = 0;
        this->spriteOrientation.flipY = 1;
        this->frameIndex = 11;
        this->timer = (Random() & 0x3f) + 64;
        this->subtimer = 0;
    }

    if (--this->timer == 0) {
        this->timer = 4;
        this->frameIndex = gUnk_08124B30[this->subtimer++] + 2;
        if (gUnk_08124B30[this->subtimer] == 0xff) {
            this->timer = (Random() & 0x3f) + 64;
            this->subtimer = 0;
        }
    }
}

void JapaneseSubtitle_Type3(Entity* this) {
    if (this->action == 0) {
        this->action = 1;
        this->spriteSettings.draw = 2;
        this->frameIndex = 15;
    }
}