summaryrefslogtreecommitdiff
path: root/src/object/kinstoneSpark.c
blob: 7b359ee02d278a5be84636f6086ca68e696abfd0 (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
/**
 * @file kinstoneSpark.c
 * @ingroup Objects
 *
 * @brief Kinstone Fusion Particle object
 */
#include "script.h"
#include "kinstone.h"
#include "object.h"
#include "asm.h"
#include "sound.h"
#include "color.h"

void sub_080A0ADC(Entity*);
void sub_080A0AF0(Entity*);
void sub_080A0AC4(Entity*);
void sub_080A0AD0(Entity*);
void sub_080A0B4C(Entity*);
void sub_080A0B60(Entity*);
void sub_080A0B80(Entity*);

void KinstoneSpark(Entity* this) {
    static void (*const gUnk_08124A10[])(Entity*) = {
        sub_080A0ADC,
        sub_080A0AF0,
    };
    static void (*const gUnk_08124A18[])(Entity*) = {
        sub_080A0AC4,
        sub_080A0AD0,
    };
    static void (*const gUnk_08124A20[])(Entity*) = {
        sub_080A0B4C,
        sub_080A0B60,
        sub_080A0B80,
    };
    void (*const* ptr)(Entity*);

    switch (this->type) {
        case 0:
            if ((this->flags & 2) != 0) {
                ptr = gUnk_08124A10;
            } else {
                ptr = gUnk_08124A18;
            }
            break;
        case 1:
            ptr = gUnk_08124A20;
            break;
    }
    ptr[this->action](this);
    if (this->action == 0) {
        this->action = 1;
        this->spriteRendering.b3 = 1;
        this->spritePriority.b0 = 0;
        this->spriteOrientation.flipY = 1;
        ChangeObjPalette(this, gKinstoneWorldEvents[gFuseInfo.kinstoneId].objPalette);
    }
    GetNextFrame(this);
}

void sub_080A0AC4(Entity* this) {
    InitializeAnimation(this, this->type);
}

void sub_080A0AD0(Entity* this) {
    GravityUpdate(this, Q_8_8(0.5));
}

void sub_080A0ADC(Entity* this) {
    sub_0807DD64(this);
    ExecuteScriptForEntity(this, NULL);
}

void sub_080A0AF0(Entity* this) {
    ExecuteScriptForEntity(this, NULL);
    GetNextFrame(this);
    if (this->animIndex == 5) {
        if ((this->frame & ANIM_DONE) != 0) {
            DeleteThisEntity();
        }
    }
    GravityUpdate(this, Q_8_8(0.5));
}

void sub_080A0B28(Entity* this, ScriptExecutionContext* context) {
    LookAt(this, context, this->x.HALF.HI, this->y.HALF.HI);
    this->y.HALF.HI -= 0xb0;
    this->spriteSettings.draw = 0;
}

void sub_080A0B4C(Entity* this) {
    this->x.HALF.HI = 0x78;
    this->y.HALF.HI = 0x50;
    InitializeAnimation(this, 0);
}

void sub_080A0B60(Entity* this) {
    if ((this->frame & 0x40) != 0) {
        this->action = 2;
        SoundReq(SFX_136);
    }
}

void sub_080A0B80(Entity* this) {
    this->y.WORD -= Q_16_16(2.5);
}