summaryrefslogtreecommitdiff
path: root/src/playerItem/playerItemGustJar.c
blob: 3425e6e45149b3f6a189421ede87a42126e452cf (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/**
 * @file playerItemGustJar.c
 * @ingroup Items
 *
 * @brief Gust Jar Player Item
 */
#include "entity.h"
#include "player.h"
#include "sound.h"
#include "vram.h"
#include "asm.h"

extern const u8* gUnk_08132714[]; // Anim index lists?
// TODO spriteAnimations in here
// TODO sprite frame in here
extern Hitbox gUnk_08132B28;

void sub_080ADC84(Entity*);
void PlayerItemGustJar_Init(Entity*);
void PlayerItemGustJar_Action1(Entity*);
void PlayerItemGustJar_Action2(Entity*);
void PlayerItemGustJar_Action3(Entity*);
void PlayerItemGustJar_Action4(Entity*);
void sub_080ADCDC(Entity*, u32);
void sub_080ADCA0(Entity*, u32);

void PlayerItemGustJar(Entity* this) {
    static void (*const PlayerItemGustJar_Actions[])(Entity*) = {
        PlayerItemGustJar_Init,    PlayerItemGustJar_Action1, PlayerItemGustJar_Action2,
        PlayerItemGustJar_Action3, PlayerItemGustJar_Action4,
    };

    if (((Entity*)gPlayerState.item != this) || (gPlayerState.gustJarState == PL_JAR_NONE)) {
        DeleteThisEntity();
    }
    PlayerItemGustJar_Actions[this->action](this);
    sub_08078E84(this, &gPlayerEntity.base);
}

void PlayerItemGustJar_Init(Entity* this) {
    this->action = 1;
    this->subtimer = 15;
    this->hitbox = &gUnk_08132B28;
    this->hitbox->unk2[2] = 3;
    this->hitbox->unk2[1] = 3;
    this->hitbox->unk2[3] = 6;
    this->hitbox->unk2[0] = 6;
    sub_080ADC84(this);
    LoadSwapGFX(this, 1, 3);
    InitAnimationForceUpdate(this, this->animationState >> 1);
}

void PlayerItemGustJar_Action1(Entity* this) {
    sub_080ADC84(this);
    if ((this->frame & ANIM_DONE) != 0) {
        this->action = 2;
        sub_080ADCA0(this, 0);
    } else {
        UpdateAnimationSingleFrame(this);
    }
}

void PlayerItemGustJar_Action2(Entity* this) {
    u32 in_r2;
    int windSound;

    if (gPlayerState.gustJarState == PL_JAR_3) {
        this->action++;
        InitAnimationForceUpdate(this, (gPlayerEntity.base.animationState >> 1) + 8);
    } else if (gPlayerState.gustJarState == PL_JAR_BLAST_DONE) {
        this->action = 4;
        InitAnimationForceUpdate(this, (gPlayerEntity.base.animationState >> 1) + 4);
    } else {
        windSound = 0;
        if (this->type != 0) {
            if (this->type == 1) {
                sub_080ADCA0(this, 4);
                this->timer = 24;
                this->type = 2;
            } else {
                sub_080ADCDC(this, 1);
                if (this->timer-- == 0) {
                    sub_080ADCA0(this, 0);
                    this->type = 0;
                }
            }
        } else {
            if ((gPlayerState.gustJarState & 0xf) == PL_JAR_ENT_ATTACHED) {
                this->frameDuration = 0x7f;
            }

            switch (gPlayerState.gustJarCharge) {
                case 3:
                    sub_080ADCDC(this, 3);
                    this->palette.b.b0 = 0;
                    in_r2 = 3;
                    windSound = SFX_WIND3;
                    break;
                case 2:
                    sub_080ADCDC(this, 2);
                    this->palette.b.b0 = 4;
                    in_r2 = 2;
                    windSound = SFX_WIND2;
                    break;
                case 1:
                    sub_080ADCDC(this, 1);
                    this->palette.b.b0 = 1;
                    in_r2 = 1;
                    windSound = SFX_WIND1;
                    break;
            }

            if ((gPlayerState.gustJarState & 0xf) == PL_JAR_ENT_ATTACHED) {
                windSound = SFX_EE;
                in_r2 = 1;
            }
            this->subtimer = this->subtimer - in_r2;
        }
        if ((s8)this->subtimer < 0) {
            if (windSound) {
                SoundReq(windSound);
            }
            this->subtimer = 15;
        }
        this->frameIndex = gPlayerEntity.base.frameIndex - (gPlayerEntity.base.frame & 0x7f);
    }
}

void PlayerItemGustJar_Action3(Entity* this) {
    switch (gPlayerState.gustJarState & 0xf) {
        case PL_JAR_BLAST_DONE:
            this->action++;
            InitAnimationForceUpdate(this, (gPlayerEntity.base.animationState >> 1) + 4);
            break;
        case PL_JAR_SUCK:
            sub_080ADCA0(this, 0);
            this->action = 2;
            break;
        default:
            UpdateAnimationSingleFrame(this);
            break;
    }
}

void PlayerItemGustJar_Action4(Entity* this) {
    if ((this->frame & ANIM_DONE) != 0) {
        this->spriteSettings.draw = 0;
    } else {
        UpdateAnimationSingleFrame(this);
    }
}

void sub_080ADC84(Entity* this) {
    this->spriteSettings.flipX = gPlayerEntity.base.spriteSettings.flipX;
}

void sub_080ADCA0(Entity* this, u32 param_2) {
    const u8* pFVar1 = gUnk_08132714[(param_2 + (gPlayerEntity.base.animationState >> 1))];
    const u8* pFVar2;

    this->animPtr = (void*)pFVar1;
    this->animIndex = *pFVar1;
    pFVar2 = pFVar1 + 1;
    this->animPtr = (void*)pFVar2;
    this->frameDuration = *pFVar2;
    this->animPtr = (void*)++pFVar2;
    sub_080042D0(this, this->animIndex, this->spriteIndex);
}

void sub_080ADCDC(Entity* this, u32 param_2) {
    u32 bVar1;
    u8* pFVar3;

    bVar1 = this->frameDuration;
    this->frameDuration = (u8)(bVar1 - param_2);
    if ((int)((bVar1 - param_2) * 0x1000000) < 1) {
        if (*(u8*)this->animPtr == 0xff) {
            this->animPtr = (u8*)this->animPtr + 1;
            this->animPtr = (u8*)this->animPtr - *(u8*)this->animPtr;
        }
        pFVar3 = this->animPtr;
        this->animIndex = *pFVar3;
        this->animPtr = ++pFVar3;
        this->frameDuration += *pFVar3;
        this->animPtr = ++pFVar3;
        sub_080042D0(this, this->animIndex, this->spriteIndex);
    }
}