summaryrefslogtreecommitdiff
path: root/src/item/itemMoleMitts.c
blob: 9732776d6c89e629b4aa59cb3fa0f8279d6ab891 (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
189
190
191
192
193
194
195
196
197
#include "effects.h"
#include "item.h"
#include "object.h"
#include "asm.h"
#include "room.h"
#include "player.h"
#include "sound.h"
#include "tiles.h"

s32 sub_080774A0(void);
extern s32 DoItemTileInteraction(Entity*, u32, ItemBehavior*);
extern void UpdatePlayerMovement(void);
extern bool32 sub_0807B5B0(Entity*);
void sub_08077130(ItemBehavior*, u32);
void sub_080771C8(ItemBehavior*, u32);
void sub_080772A8(ItemBehavior*, u32);
void sub_08077448(ItemBehavior*, u32);

void ItemMoleMitts(ItemBehavior* this, u32 index) {
    static void (*const stateFuncs[])(ItemBehavior*, u32) = {
        sub_08077130,
        sub_080771C8,
        sub_080772A8,
        sub_08077448,
    };
    stateFuncs[this->stateID](this, index);
}

void sub_08077130(ItemBehavior* this, u32 index) {
    s32 iVar1;

    if (gPlayerState.jump_status == 0) {
        sub_08077D38(this, index);
        gPlayerState.moleMittsState = 1;
        this->priority |= 0x80;
        iVar1 = sub_080774A0();
        if (iVar1 != 0) {
            if (this->timer == 0) {
                SetItemAnim(this, ANIM_MOLEMITTS_DIG);
                this->stateID = 2;
                if (iVar1 == 0x56) {
                    if ((gPlayerEntity.base.animationState & 2) != 0) {
                        gPlayerEntity.base.y.HALF.HI = (gPlayerEntity.base.y.HALF.HI & 0xfff0) | 6;
                    } else {
                        gPlayerEntity.base.x.HALF.HI = (gPlayerEntity.base.x.HALF.HI & 0xfff0) | 8;
                    }
                }
            }
        } else {
            SetItemAnim(this, ANIM_MOLEMITTS_FLOOR);
            this->stateID = 1;
        }
    } else {
        DeleteItemBehavior(this, index);
        gPlayerState.moleMittsState = 0;
    }
}

void sub_080771C8(ItemBehavior* this, u32 index) {
    static const u8 gUnk_0811BE14[] = {
        0x1,
        0x12,
    };
    Entity* object;

    UpdateItemAnim(this);
    if ((this->playerFrame & 0x80) != 0) {
        DeleteItemBehavior(this, index);
        gPlayerState.moleMittsState = 0;
    } else {
        if (((this->playerFrame & 0x20) != 0) && (this->subtimer == 0xff)) {
            CreateObjectWithParent(&gPlayerEntity.base, MOLE_MITTS_PARTICLE, this->playerFrame, 1);
        }
        if ((this->playerFrame & 0x10) != 0) {
            if (DoItemTileInteraction(&gPlayerEntity.base, 0xd, this) == 0) {
                SetItemAnim(this, ANIM_MOLEMITTS_MISS);
                this->stateID = 3;
                SoundReq(SFX_ITEM_GLOVES_AIR);
            } else {
                if (this->subtimer != 0xff) {
                    object = CreateObjectWithParent(&gPlayerEntity.base, OBJECT_1F, 0, this->field_0x2[1]);
                    if (object != NULL) {
                        object->timer = this->timer;
                        object->subtimer = this->subtimer;
                        object->animationState = gPlayerEntity.base.animationState & 6;
                        gPlayerEntity.base.frame = 0;
                        gPlayerEntity.base.frameDuration = gUnk_0811BE14[this->subtimer];
                    }
                } else {
                    if ((this->field_0x2[1] == 0x0f) && (this->timer == 0x17)) {
                        this->subtimer = 0;
                    }
                }
                SoundReq(SFX_108);
            }
        }
    }
}

void sub_080772A8(ItemBehavior* this, u32 index) {
    static const s16 gUnk_0811BE16[] = {
        0,
        0xc0,
        0x100,
        0x180,
    };
    Entity* effect;

    if (((this->playerFrame & 8) != 0) && IsItemActivatedThisFrame(this)) {
        this->timer = 1;
    }
    if (GetInventoryValue(ITEM_DIG_BUTTERFLY) == 1) {
        if ((this->playerFrame & 7) != 3) {
            sub_08077E3C(this, 2);
            gPlayerEntity.base.speed = gUnk_0811BE16[this->playerFrame & 7] << 1;
        } else {
            UpdateItemAnim(this);
            gPlayerEntity.base.speed = gUnk_0811BE16[this->playerFrame & 7];
        }
    } else {
        UpdateItemAnim(this);
        gPlayerEntity.base.speed = gUnk_0811BE16[this->playerFrame & 7];
    }
    gPlayerEntity.base.direction = gPlayerEntity.base.animationState << 2;
    if (gPlayerEntity.base.speed != 0) {
        UpdatePlayerMovement();
    }
    if ((this->playerFrame & 0x10) != 0) {
        if (this->timer != 0) {
            gPlayerEntity.base.frameDuration = 1;
            if (sub_080774A0()) {
                this->timer = 0;
                return;
            }
        }
        DeleteItemBehavior(this, index);
        gPlayerState.moleMittsState = 0;
    } else {
        if ((this->playerFrame & 0x60) != 0) {
            gPlayerEntity.base.frameDuration = 1;
            if (sub_0807B5B0(&gPlayerEntity.base)) {
                SoundReq(SFX_108);
                CreateObjectWithParent(&gPlayerEntity.base, MOLE_MITTS_PARTICLE, this->playerFrame, 0);
            } else {
                SetItemAnim(this, ANIM_MOLEMITTS_CLANG);
                effect = CreateFx(&gPlayerEntity.base, FX_STARS_STRIKE, 0);
                if (effect != NULL) {
                    effect->animationState = this->playerAnimationState;
                    effect->spritePriority.b0 = gPlayerEntity.base.spritePriority.b0 - 1;
                }
                effect = CreateFx(&gPlayerEntity.base, FX_STARS_STRIKE, 0);
                if (effect != NULL) {
                    effect->animationState = this->playerAnimationState;
                    effect->spritePriority.b0 = gPlayerEntity.base.spritePriority.b0 - 1;
                    effect->subtimer = 1;
                }
                this->stateID = 3;
                this->field_0x5 = 1;
                SoundReq(SFX_ITEM_GLOVES_KNOCKBACK);
            }
        }
    }
}

void sub_08077448(ItemBehavior* this, u32 index) {
    gPlayerEntity.base.direction = gPlayerEntity.base.animationState << 2 ^ 0x10;
    gPlayerEntity.base.speed = 0x100;
    if (((this->playerFrame & 1) != 0) && (this->field_0x5 != 0)) {
        UpdatePlayerMovement();
    }
    UpdateItemAnim(this);
    if ((this->playerFrame & 0x80) != 0) {
        gPlayerState.moleMittsState = 0;
        DeleteItemBehavior(this, index);
    }
}

s32 sub_080774A0(void) {
    static const s8 gUnk_0811BE1E[] = { 0, -13, 13, 0, 0, 16, -13, 0, 0, 0 };
    u32 collisionData;
    u32 tilePos;

    tilePos = COORD_TO_TILE_OFFSET((&gPlayerEntity.base), -gUnk_0811BE1E[gPlayerEntity.base.animationState & 6],
                                   -gUnk_0811BE1E[(gPlayerEntity.base.animationState & 6) + 1]);

    collisionData = GetCollisionDataAtTilePos(tilePos, gPlayerEntity.base.collisionLayer);

    if (collisionData > 0x16)
        return 0;
    if (collisionData < 0xf)
        return 0;
    if (GetActTileAtTilePos(tilePos, gPlayerEntity.base.collisionLayer) != ACT_TILE_86) {
        return 1;
    } else {
        return 0x56;
    }
}