summaryrefslogtreecommitdiff
path: root/src/enemy/tektiteGolden.c
blob: 4e0d8862e2c9176eaad0992cfaf5114ad47f88ab (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
/**
 * @file tektiteGolden.c
 * @ingroup Enemies
 *
 * @brief Golden Tektite enemy
 */
#include "collision.h"
#include "enemy.h"
#include "item.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u8 unused1[24];
    /*0x80*/ u8 unk_80;
} TektiteGoldenEntity;

void sub_08038168(TektiteGoldenEntity*);
void TektiteGolden_OnTick(TektiteGoldenEntity*);
void TektiteGolden_OnCollision(TektiteGoldenEntity*);
void TektiteGolden_OnDeath(TektiteGoldenEntity*);
void TektiteGolden_OnConfused(TektiteGoldenEntity*);
void TektiteGolden_OnTick(TektiteGoldenEntity*);
void sub_08037FA0(TektiteGoldenEntity*);
void sub_08037Fe0(TektiteGoldenEntity*);
void sub_08038048(TektiteGoldenEntity*);
void sub_08038110(TektiteGoldenEntity*);

static void (*const TektiteGolden_Functions[])(TektiteGoldenEntity*) = {
    TektiteGolden_OnTick,  TektiteGolden_OnCollision, (void (*)(TektiteGoldenEntity*))GenericKnockback,
    TektiteGolden_OnDeath, TektiteGolden_OnConfused,  TektiteGolden_OnTick,
};

void TektiteGolden(TektiteGoldenEntity* this) {
    EnemyFunctionHandler(super, (EntityActionArray)TektiteGolden_Functions);
    EnemySetFXOffset(super, 0, 1, -0x10);
}

void TektiteGolden_OnTick(TektiteGoldenEntity* this) {
    static void (*const actionFuncs[])(TektiteGoldenEntity*) = {
        sub_08037FA0,
        sub_08037Fe0,
        sub_08038048,
        sub_08038110,
    };
    actionFuncs[super->action](this);
}

void TektiteGolden_OnCollision(TektiteGoldenEntity* this) {
    if (super->confusedTime != 0) {
        EnemyCreateFX(super, FX_STARS);
    }
    EnemyFunctionHandlerAfterCollision(super, TektiteGolden_Functions);
    if (super->contactFlags == (CONTACT_NOW | 0x14)) {
        super->action = 1;
        super->subAction = 0;
        super->timer = 20;
        super->subtimer = 0;
        this->unk_80 = 0;
        if (super->z.HALF.HI != 0) {
            super->zVelocity >>= 2;
        } else {
            super->zVelocity = 0;
        }

        InitializeAnimation(super, 0);
    }
}

void TektiteGolden_OnDeath(TektiteGoldenEntity* this) {
    u32 uVar1;

    if ((super->gustJarState & 2) == 0) {
        SetGlobalFlag(super->type2);
    }
    if (super->type != 0) {
        uVar1 = ITEM_RUPEE200;
    } else {
        uVar1 = ITEM_RUPEE100;
    }
    EnemyCreateDeathFX((Enemy*)super, 0xff, uVar1);
}

void TektiteGolden_OnConfused(TektiteGoldenEntity* this) {
    GenericConfused(super);
    if (super->z.HALF.HI != 0) {
        GravityUpdate(super, Q_8_8(48.0));
    }
}

void sub_08037FA0(TektiteGoldenEntity* this) {
    if (CheckGlobalFlag(super->type2)) {
        DeleteThisEntity();
    }
    sub_0804A720(super);
    super->action = 1;
    super->subAction = 0;
    super->timer = (Random() & 0x1f) + 32;
    super->subtimer = 0;
    this->unk_80 = 0;
    InitializeAnimation(super, 0);
}

void sub_08037Fe0(TektiteGoldenEntity* this) {
    UpdateAnimationVariableFrames(super, 2);
    if (super->timer != 0) {
        super->timer--;
    } else if (super->subtimer != 0) {
        if (super->frame & ANIM_DONE) {
            super->action = 2;
            super->timer = 6;
            super->subtimer = 0;
            super->zVelocity = Q_16_16(3.5);
            sub_08038168(this);
            InitializeAnimation(super, 2);
        }
    } else if (super->frame & ANIM_DONE) {
        super->subtimer = 64;
        InitializeAnimation(super, 1);
    }
}

void sub_08038048(TektiteGoldenEntity* this) {
    s32 temp;
    u32 rand;

    UpdateAnimationVariableFrames(super, 2);
    ProcessMovement0(super);
    temp = super->z.HALF.HI;
    rand = Random() & 0xf;

    if (BounceUpdate(super, Q_8_8(48.0)) == BOUNCE_INIT_NEXT) {
        super->action = 3;
        super->subAction = 0;
        super->timer = 20;
        InitializeAnimation(super, 3);
        return;
    } else if (super->collisions != COL_NONE) {
        sub_0800417E(super, super->collisions);
    } else if ((GetActTileAtEntity(super) & 0xf0) == 0x50) { // ACT_TILE_240 and ACT_TILE_241?
        super->direction = (super->direction + 0x10) & (0x3 | DirectionNorthWest);
    }

    if (--super->timer == 0) {
        super->timer = rand + 16;
        sub_08038168(this);
    }

    if ((super->subAction == 0) && (temp < super->z.HALF.HI)) {
        InitializeAnimation(super, 4);
        super->subAction = 1;
    }

    if (temp < -0xc) {
        super->spriteRendering.b3 = 1;
        super->spriteOrientation.flipY = 1;
    } else {
        super->spriteRendering.b3 = 2;
        super->spriteOrientation.flipY = 2;
    }
}

void sub_08038110(TektiteGoldenEntity* this) {
    UpdateAnimationVariableFrames(super, 2);
    if (super->frame & ANIM_DONE) {
        if (this->unk_80 < 5) {
            super->action = 2;
            super->timer = 8;
            super->zVelocity = Q_16_16(3.5);
            sub_08038168(this);
            InitializeAnimation(super, 2);
        } else {
            super->action = 1;
            this->unk_80 = 0;
            super->timer = 192;
            InitializeAnimation(super, 0);
        }
    }
}

void sub_08038168(TektiteGoldenEntity* this) {
    u32 temp;

    if (sub_08049FA0(super) == 0) {
        super->direction = sub_08049EE4(super);
    } else if (sub_08049FDC(super, 1) != 0) {
        super->direction = sub_08049F84(super, 1);
    } else {
        temp = (Random() & 0xf) + 0x18;
        super->direction = (temp + super->direction) & (0x3 | DirectionNorthWest);
    }
}