summaryrefslogtreecommitdiff
path: root/src/object/thunderbolt.c
blob: 312b13069e53eff3d4015c5132a859ac7a9934f8 (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
/**
 * @file thunderbolt.c
 * @ingroup Objects
 *
 * @brief Thunderbolt object
 */
#include "object.h"
#include "asm.h"
#include "sound.h"
#include "physics.h"
#include "player.h"

typedef struct {
    /*0x00*/ Entity base;
} ThunderboltEntity;

void Thunderbolt_Init(ThunderboltEntity*);
void Thunderbolt_Action1(ThunderboltEntity*);
void sub_08093ED0(ThunderboltEntity*);
void sub_08093EF0(ThunderboltEntity*);

typedef struct {
    u16 sfx;
    u8 unk_2;
    u8 unk_3;
} struct_08122950;

const struct_08122950 gUnk_08122950[] = {
    { 244, 31, 0 },
    { 0, 31, 0 },
    { 0, 31, 0 },
};

void Thunderbolt(ThunderboltEntity* this) {
    static void (*const Thunderbolt_Actions[])(ThunderboltEntity*) = {
        Thunderbolt_Init,
        Thunderbolt_Action1,
    };
    Thunderbolt_Actions[super->action](this);
}

void Thunderbolt_Init(ThunderboltEntity* this) {
    const struct_08122950* ptr;
    super->action = 1;
    super->flags &= ~0x80;
    super->spriteSettings.draw = 1;
    if (super->collisionLayer == 0) {
        ResolveCollisionLayer(super);
    }
    InitializeAnimation(super, super->type);
    ptr = &gUnk_08122950[super->type];
    if ((ptr->sfx != SFX_NONE) && ((super->type2 & 0x40) == 0)) {
        EnqueueSFX(ptr->sfx);
    }
    if ((super->type2 & 0x20) != 0) {
        super->spriteRendering.b3 = 1;
    }
}

void Thunderbolt_Action1(ThunderboltEntity* this) {
    static void (*const gUnk_08122964[])(ThunderboltEntity*) = {
        sub_08093ED0,
        sub_08093EF0,
    };
    gUnk_08122964[gUnk_08122950[super->type].unk_2 >> 4](this);
}

void sub_08093ED0(ThunderboltEntity* this) {
    GetNextFrame(super);
    if ((super->frame & ANIM_DONE) != 0) {
        DeleteEntity(super);
    }
}

void sub_08093EF0(ThunderboltEntity* this) {
    Entity* object;
    switch (super->type) {
        case 0:
            if (super->subAction != 0) {
                return;
            }
            GetNextFrame(super);
            if ((super->frame & ANIM_DONE) == 0) {
                return;
            }
            object = CreateObject(THUNDERBOLT, 1, 0);
            if (object != NULL) {
                object->parent = super->parent;
                CopyPosition(super, object);
            }
            DeleteThisEntity();
            break;
        case 1:
            GetNextFrame(super);
            if ((super->frame & 1) != 0) {
                super->frame = 0;
                object = CreateObject(THUNDERBOLT, 2, 0);
                if (object != NULL) {
                    object->parent = super->parent;
                    CopyPosition(super, object);
                }
            }
            if ((super->frame & ANIM_DONE) == 0) {
                return;
            }
            if (super->parent == &gPlayerEntity.base) {
                SoundReq(SFX_PLY_VO6);
                sub_08079D84();
            }
            DeleteThisEntity();
            break;
        case 2:
            GetNextFrame(super);
            if ((super->frame & ANIM_DONE) == 0) {
                return;
            }
            DeleteThisEntity();
            break;
    }
}