summaryrefslogtreecommitdiff
path: root/src/npc/talon.c
blob: c0558722b16c370dd13c7272b9572db29d0d4f5c (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
/**
 * @file talon.c
 * @ingroup NPCs
 *
 * @brief Talon NPC
 */
#include "physics.h"
#include "item.h"
#include "npc.h"
#include "script.h"
#include "message.h"
#include "asm.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u8 fusionOffer;
    /*0x69*/ u8 unk_69;
    /*0x6a*/ u8 unk_6a;
    /*0x6b*/ u8 unused[25];
    /*0x84*/ u32 unk_84;
} TalonEntity;

static const SpriteLoadData gUnk_0810FEB0[] = {
    { 0x4b, 0x8b, 0 },
    { 0x4b, 0x8b, 0 },
    { 0, 0, 0 },
};

extern u8 script_TalonGotKey;

void sub_0806574C(TalonEntity* this);
void sub_08065570(Entity* this);
void sub_0806559C(Entity* this);
void sub_08065608(TalonEntity* this);
void sub_08065648(TalonEntity* this);
void sub_080656D4(TalonEntity* this);
void sub_080656A4(TalonEntity* this);
void sub_08065680(TalonEntity* this);

void Talon(TalonEntity* this) {
    static void (*const actionFuncs[])(Entity*) = {
        sub_08065570,
        sub_0806559C,
    };
    static void (*const scriptedActionFuncs[])(TalonEntity*) = {
        sub_08065608, sub_08065648, sub_080656D4, sub_080656A4, sub_08065680,
    };
    if (super->flags & ENT_SCRIPTED) {
        scriptedActionFuncs[super->action](this);
    } else {
        actionFuncs[super->action](super);
    }
}

void sub_08065570(Entity* this) {
    if (LoadExtraSpriteData(this, gUnk_0810FEB0)) {
        InitializeAnimation(this, 0);
        AddInteractableWhenBigObject(this);
        this->action = 1;
        this->subtimer = 1;
        this->animationState = 2;
    }
}

void sub_0806559C(Entity* this) {
    s32 offset;
    s32 result;

    this->timer++;
    if (this->timer >= 9) {
        this->timer = 0;
        result = GetAnimationStateInRectRadius(this, 0x20, 0x20);
        if (result < 0) {
            offset = this->animationState + 4;
        } else {
            this->animationState = result;
            offset = result;
        }
    } else {
        offset = this->animIndex;
    }

    if (this->animIndex != offset) {
        InitializeAnimation(this, offset);
    } else {
        GetNextFrame(this);
    }
    sub_0806ED78(this);
    if (this->interactType != INTERACTION_NONE) {
        this->interactType = INTERACTION_NONE;
        ResetPlayerAnimationAndAction();
    }
}

void sub_08065608(TalonEntity* this) {
    if (LoadExtraSpriteData(super, gUnk_0810FEB0)) {
        super->action = 1;
        super->spriteSettings.draw = 1;
        this->fusionOffer = GetFusionToOffer(super);
        AddInteractableWhenBigFuser(super, this->fusionOffer);
        InitScriptForNPC(super);
    }
}

void sub_08065648(TalonEntity* this) {
    if (super->interactType == INTERACTION_FUSE) {
        this->unk_69 = super->action;
        super->action = 4;
        super->interactType = INTERACTION_NONE;
        InitializeNPCFusion(super);
    } else {
        ExecuteScriptAndHandleAnimation(super, NULL);
    }
}

void sub_08065680(TalonEntity* this) {
    if (UpdateFuseInteraction(super) != 0) {
        super->action = this->unk_69;
        InitAnimationForceUpdate(super, this->unk_6a);
    }
}

void sub_080656A4(TalonEntity* this) {
    if ((gMessage.state & MESSAGE_ACTIVE) == 0) {
        super->action = this->unk_69;
        InitAnimationForceUpdate(super, this->unk_6a);
    }
    UpdateAnimationSingleFrame(super);
}

void sub_080656D4(TalonEntity* this) {
    if (super->interactType == INTERACTION_FUSE) {
        this->unk_69 = super->action;
        super->action = 4;
        super->interactType = INTERACTION_NONE;
        InitializeNPCFusion(super);
        sub_0806574C(this);
    } else {
        if (super->interactType != INTERACTION_NONE) {
            if (GetInventoryValue(ITEM_QST_LONLON_KEY) != 0) {
                StartCutscene(super, (u16*)&script_TalonGotKey);
            } else {
                this->unk_69 = super->action;
                super->action = 3;
                super->interactType = INTERACTION_NONE;
                MessageNoOverlap(*(u32*)(*(u32*)&this->unk_84 + 4), super);
                sub_0806574C(this);
                return;
            }
        }
        ExecuteScriptAndHandleAnimation(super, NULL);
    }
}

void sub_0806574C(TalonEntity* this) {
    u32 j;

    j = (super->animIndex & ~3) + GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity.base));
    if (super->animIndex != j) {
        InitAnimationForceUpdate(super, j);
    }
    this->unk_6a = super->animIndex;
}

void sub_08065780(Entity* this, ScriptExecutionContext* context) {
    static const u8 gUnk_0810FED8[] = {
        10, 20, 30, 18, 28, 38, 12, 24,
    };
    u32 rand;

    rand = Random();
    this->animationState = rand & 6;
    context->wait = gUnk_0810FED8[rand >> 8 & 7];
}

void Talon_Head(Entity* this) {
    SetExtraSpriteFrame(this, 0, ((this->frame & 7) + 0xB));
    SetExtraSpriteFrame(this, 1, this->frameIndex);
    SetSpriteSubEntryOffsetData1(this, 1, 0);
    sub_0807000C(this);
}

void Talon_Fusion(Entity* this) {
    if (this->action == 0) {
        if (LoadExtraSpriteData(this, gUnk_0810FEB0)) {
            this->action++;
            this->spriteSettings.draw = 1;
            InitializeAnimation(this, 6);
        }
    } else {
        GetNextFrame(this);
    }
}