summaryrefslogtreecommitdiff
path: root/src/playerItem/playerItemBomb.c
blob: 0a08c55d63b2071afad973834bf69dffdc5200f6 (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
198
199
200
201
202
203
/**
 * @file playerItemBomb.c
 * @ingroup Items
 *
 * @brief Bomb Player Item
 */
#include "asm.h"
#include "entity.h"
#include "functions.h"
#include "item.h"
#include "object.h"
#include "player.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u32 unk_68;
} PlayerItemBombEntity;

void sub_0801B418(Entity* this);
void sub_0801B3A4(PlayerItemBombEntity* this);
void PlayerItemBomb_Init(PlayerItemBombEntity* this);
void PlayerItemBomb_Action1(PlayerItemBombEntity* this);
void PlayerItemBomb_Action2(PlayerItemBombEntity* this);
void PlayerItemBomb_Action3(PlayerItemBombEntity* this);
void PlayerItemBomb_SubAction0(PlayerItemBombEntity* this);
void PlayerItemBomb_SubAction1(PlayerItemBombEntity* this);
void PlayerItemBomb_SubAction2(PlayerItemBombEntity* this);
void PlayerItemBomb_SubAction3(PlayerItemBombEntity* this);
void PlayerItemBomb_SubAction4(PlayerItemBombEntity* this);

static void (*const PlayerItemBomb_Actions[])(PlayerItemBombEntity*) = {
    PlayerItemBomb_Init,
    PlayerItemBomb_Action1,
    PlayerItemBomb_Action2,
    PlayerItemBomb_Action3,
};

static void (*const PlayerItemBomb_SubActions[])(PlayerItemBombEntity*) = {
    PlayerItemBomb_SubAction0, PlayerItemBomb_SubAction1, PlayerItemBomb_SubAction2,
    PlayerItemBomb_SubAction3, PlayerItemBomb_SubAction4,
};

static const Hitbox unusedHitbox = { 0, 0, { 4, 0, 0, 4 }, 22, 22 };
static const Hitbox gUnk_080B77F4 = { 0, 0, 6, 0, 0, 6, 4, 4 };

void PlayerItemBomb(PlayerItemBombEntity* this) {
    u8 action, uVar2;

    PlayerItemBomb_Actions[super->action](this);
    GetNextFrame(super);
    uVar2 = action = super->action;
    if (action != 3) {
        if (super->timer != 0) {
            if (*(u8*)&this->unk_68 == 7) {
                super->timer--;
            }
            if (super->timer == 0) {
                super->subtimer = 80;
                this->unk_68 = 0;
                super->spriteRendering.b0 = 3;
                SetAffineInfo(super, 0x100, 0x100, 0);
            }
        } else {
            if (super->subtimer != 0) {
                if (super->subtimer-- == 1) {
                    if ((action == 2) && (super->subAction == 1)) {
                        gPlayerState.heldObject = 0;
                    }
                    super->action = 3;
                    super->spritePriority.b1 = 2;
                    super->timer = 15;
                    super->spriteSettings.draw = 0;
                    sub_0805EC60(super);
                    FreeCarryEntity(super);
                    CreateObjectWithParent(super, SMOKE_PARTICLE, 0, 0);
                    sub_0801B418(super);
                } else {
                    sub_0801B3A4(this);
                }
            }
        }
    }
}

void PlayerItemBomb_Init(PlayerItemBombEntity* this) {
    super->spriteSettings.draw = 1;
    super->action = 1;
    super->spritePriority.b1 = 3;
    super->flags &= ~0x80;
    if (super->type == 0xff) {
        super->timer = 60;
    } else if (super->type == 0xfe) {
        super->timer = 15;
        super->type = 0xff;
    } else {
        super->timer = 150;
    }
    super->hitbox = (Hitbox*)&gUnk_080B77F4;
    super->carryFlags = 0;
    if (*(u8*)&this->unk_68 == 7) {
        InitializeAnimation(super, 5);
    } else {
        InitializeAnimation(super, 0x15);
    }
}

void PlayerItemBomb_Action1(PlayerItemBombEntity* this) {
    u16 input;

    if (!sub_0800442E(super)) {
        RegisterCarryEntity(super);
    }
    switch (IsItemEquipped(ITEM_REMOTE_BOMBS)) {
        case EQUIP_SLOT_A:
            input = INPUT_USE_ITEM1;
            break;
        case EQUIP_SLOT_B:
            input = INPUT_USE_ITEM2;
            break;
        case EQUIP_SLOT_NONE:
            input = 0;
            break;
    }
    if ((gPlayerState.playerInput.newInput & input) != 0) {
        super->timer = 0;
        super->subtimer = 1;
    }
}

void PlayerItemBomb_Action2(PlayerItemBombEntity* this) {
    PlayerItemBomb_SubActions[super->subAction](this);
}

void PlayerItemBomb_SubAction0(PlayerItemBombEntity* this) {
    super->subAction++;
    sub_08079BD8(super);
}

void PlayerItemBomb_SubAction1(PlayerItemBombEntity* this) {
    super->spritePriority.b1 = 2;
}

void PlayerItemBomb_SubAction2(PlayerItemBombEntity* this) {
    super->spritePriority.b1 = 3;
}

void PlayerItemBomb_SubAction3(PlayerItemBombEntity* this) {
    super->action--;
    super->subAction = 0;
    if (super->timer > 60) {
        super->timer = 60;
    }
}

void PlayerItemBomb_SubAction4(PlayerItemBombEntity* this) {
    DeleteThisEntity();
}

void PlayerItemBomb_Action3(PlayerItemBombEntity* this) {
    if (super->timer-- == 0) {
        DeleteThisEntity();
    }
}

void sub_0801B3A4(PlayerItemBombEntity* this) {
    u32 tmp;
    if (super->subtimer > 40) {
        tmp = 8;
    } else {
        tmp = 4;
        if ((this->unk_68 & 0x8000) != 0) {
            this->unk_68 -= 0x10;
        } else {
            this->unk_68 += 0x10;
        }
        if (0x7f < (this->unk_68 & 0xf0) - 1) {
            this->unk_68 ^= 0x8000;
        }
        SetAffineInfo(super, 0x130 - (this->unk_68 & 0xf0), 0x130 - (this->unk_68 & 0xf0), 0);
    }
    if ((super->subtimer & tmp) == 0) {
        super->palette.b.b0 = 0;
    } else {
        super->palette.b.b0 = super->palette.b.b4;
    }
}

void sub_0801B418(Entity* this) {
    s32 x;
    s32 y;
    s32 iVar3 = 0;

    y = 0x10;
    while (iVar3 >= -0x10) {
        x = 0x10;
        iVar3 = y - 0x10;
        while (x >= -0x10) {
            DoTileInteraction(this, 3, this->x.HALF.HI + x, this->y.HALF.HI + y);
            x -= 0x10;
        }
        y = iVar3;
    }
}