summaryrefslogtreecommitdiff
path: root/src/npc/pina.c
blob: 592c42461897652d42c0478c2a86fa37f6a1d3b2 (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
/**
 * @file pina.c
 * @ingroup NPCs
 *
 * @brief Pina NPC
 */
#include "entity.h"
#include "message.h"
#include "npc.h"
#include "object.h"
#include "asm.h"
#include "physics.h"
#include "player.h"
#include "save.h"
#include "script.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u8 fusionOffer;
    /*0x69*/ u8 animIndex;
} PinaEntity;

void sub_08063B68(PinaEntity* this);
void sub_08063A80(Entity* this);
void sub_08063A98(Entity* this);
void sub_08063AC0(Entity* this);
void sub_08063B44(Entity* this);

void Pina(PinaEntity* this) {
    if ((super->flags & ENT_SCRIPTED) != 0) {
        sub_08063B68(this);
    } else {
        sub_08063A80(super);
    }
}

void sub_08063A80(Entity* this) {
    static void (*const Pina_Actions[])(Entity*) = {
        sub_08063A98,
        sub_08063AC0,
        sub_08063B44,
    };
    Pina_Actions[this->action](this);
}

void sub_08063A98(Entity* this) {
    this->action++;
    this->spriteSettings.draw = 1;
    InitAnimationForceUpdate(this, 4);
    AddInteractableWhenBigObject(this);
}

void sub_08063AC0(Entity* this) {
    if (GetAnimationStateInRectRadius(this, 0x20, 0x20) >= 0) {
        if (this->subtimer == 0) {
            if ((Random() & 0x3f) == 0) {
                InitAnimationForceUpdate(this, 0);
                this->subtimer = 1;
            }
        }
    }

    if (this->subtimer != 0) {
        UpdateAnimationSingleFrame(this);
        if ((this->frame & ANIM_DONE) != 0) {
            this->subtimer = 0;
        }
    }

    if (this->interactType != INTERACTION_NONE) {
        this->action = 2;
        InitAnimationForceUpdate(this, GetAnimationState(this) + 4);
        MessageFromTarget(this->timer + TEXT_INDEX(TEXT_EMPTY, 0x01));
    }
    sub_0806ED78(this);
}

void sub_08063B44(Entity* this) {
    u8 tmp = gMessage.state & MESSAGE_ACTIVE;
    if (tmp == 0) {
        this->action = 1;
        this->subtimer = tmp;
        InitAnimationForceUpdate(this, 4);
    }
}

void sub_08063B68(PinaEntity* this) {
    switch (super->action) {
        case 0:
            super->action = 1;
            super->spriteSettings.draw = 1;
            this->animIndex = 0;
            sub_0807DD64(super);
        case 1:
            if (super->interactType == INTERACTION_FUSE) {
                super->action = 2;
                super->interactType = INTERACTION_NONE;
                this->animIndex = super->animIndex;
                InitAnimationForceUpdate(
                    super, GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity.base)) + 4);
                InitializeNPCFusion(super);
            } else {
                ExecuteScriptForEntity(super, NULL);
                HandleEntity0x82Actions(super);
                UpdateAnimationSingleFrame(super);
            }
            break;
        case 2:
            if (UpdateFuseInteraction(super) == 0) {
                return;
            }
            super->action = 1;
            InitAnimationForceUpdate(super, this->animIndex);
            break;
    }
}

void sub_08063C14(void) {
    Entity* entity = DeepFindEntityByID(NPC, PINA);
    if (entity != NULL) {
        InitAnimationForceUpdate(entity, 8);
    }
}

void sub_08063C2C(void) {
    Entity* entity = DeepFindEntityByID(NPC, PINA);
    if (entity != NULL) {
        InitAnimationForceUpdate(entity, 4);
    }
}

void sub_08063C44(void) {
    Entity* entity = DeepFindEntityByID(NPC, PINA);
    if (entity != NULL) {
        InitAnimationForceUpdate(entity, 0);
    }
}

void sub_08063C5C(void) {
    Entity* entity = DeepFindEntityByID(NPC, PINA);
    if (entity != NULL) {
        InitAnimationForceUpdate(entity, 9);
    }
}

void sub_08063C74(void) {
    Entity* entity = DeepFindEntityByID(NPC, PINA);
    if (entity != NULL) {
        CreateSpeechBubbleExclamationMark(entity, 8, 0xffffffe8);
    }
}

void sub_08063C90(Entity* this) {
    static const Dialog gUnk_0810CE04[] = {
        { 6, DIALOG_ROOM_FLAG, DIALOG_TOGGLE_FLAG, 1, { TEXT_INDEX(TEXT_TOWN, 0x22), TEXT_INDEX(TEXT_TOWN, 0x21) } },
        { 6, DIALOG_ROOM_FLAG, DIALOG_TOGGLE_FLAG, 1, { TEXT_INDEX(TEXT_TOWN, 0x22), TEXT_INDEX(TEXT_TOWN, 0x21) } },
        { 6, DIALOG_ROOM_FLAG, DIALOG_TOGGLE_FLAG, 1, { TEXT_INDEX(TEXT_TOWN, 0x22), TEXT_INDEX(TEXT_TOWN, 0x21) } },
        { 6, DIALOG_ROOM_FLAG, DIALOG_TOGGLE_FLAG, 1, { TEXT_INDEX(TEXT_TOWN, 0x22), TEXT_INDEX(TEXT_TOWN, 0x21) } },
        { 6, DIALOG_ROOM_FLAG, DIALOG_TOGGLE_FLAG, 1, { TEXT_INDEX(TEXT_TOWN2, 0x1d), TEXT_INDEX(TEXT_TOWN2, 0x1c) } },
        { 6, DIALOG_ROOM_FLAG, DIALOG_TOGGLE_FLAG, 1, { TEXT_INDEX(TEXT_TOWN3, 0x1c), TEXT_INDEX(TEXT_TOWN3, 0x1b) } },
        { 6, DIALOG_ROOM_FLAG, DIALOG_TOGGLE_FLAG, 1, { TEXT_INDEX(TEXT_TOWN4, 0x1d), TEXT_INDEX(TEXT_TOWN4, 0x1c) } },
        { 6, DIALOG_ROOM_FLAG, DIALOG_TOGGLE_FLAG, 1, { TEXT_INDEX(TEXT_TOWN5, 0x1d), TEXT_INDEX(TEXT_TOWN5, 0x1c) } },
        { 6, DIALOG_ROOM_FLAG, DIALOG_TOGGLE_FLAG, 1, { TEXT_INDEX(TEXT_TOWN6, 0x17), TEXT_INDEX(TEXT_TOWN6, 0x16) } },
        { 6, DIALOG_ROOM_FLAG, DIALOG_TOGGLE_FLAG, 1, { TEXT_INDEX(TEXT_TOWN6, 0x17), TEXT_INDEX(TEXT_TOWN6, 0x16) } },
    };
    ShowNPCDialogue(this, &gUnk_0810CE04[gSave.global_progress]);
}

void Pina_MakeInteractable(PinaEntity* this) {
    this->fusionOffer = GetFusionToOffer(super);
    AddInteractableWhenBigFuser(super, this->fusionOffer);
}

void Pina_Fusion(Entity* this) {
    if (this->action == 0) {
        this->action++;
        this->spriteSettings.draw = 1;
        this->y.HALF.HI -= 4;
        InitAnimationForceUpdate(this, 2);
    } else {
        UpdateAnimationSingleFrame(this);
    }
}