summaryrefslogtreecommitdiff
path: root/src/npc/epona.c
blob: 6cca50b8ba0ee2022dfb7b2b31934d18e6229c9e (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
/**
 * @file epona.c
 * @ingroup NPCs
 *
 * @brief Epona NPC
 */
#include "entity.h"
#include "message.h"
#include "npc.h"
#include "sound.h"
#include "player.h"
#include "physics.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u8 fusionOffer;
    /*0x69*/ u8 unk_69;
} EponaEntity;

void sub_08065A64(EponaEntity* this);
void sub_08065AA4(EponaEntity* this);
void sub_080659B8(EponaEntity* this);
void sub_080659F0(EponaEntity* this);
void sub_08065A00(EponaEntity* this);
void sub_08065A10(EponaEntity* this);
void sub_08065A34(EponaEntity* this);

void Epona(EponaEntity* this) {
    static void (*const actionFuncs[])(EponaEntity*) = {
        sub_080659B8, sub_080659F0, sub_08065A00, sub_08065A10, sub_08065A34,
    };
    actionFuncs[super->action](this);
    sub_08065A64(this);
    sub_0806ED78(super);
}

void sub_080659B8(EponaEntity* this) {
    super->action = 1;
    super->spriteSettings.draw = 1;
    super->animationState = 6;
    this->unk_69 = -1;
    this->fusionOffer = GetFusionToOffer(super);
    InitAnimationForceUpdate(super, super->animationState / 2);
}

void sub_080659F0(EponaEntity* this) {
    UpdateAnimationSingleFrame(super);
    sub_08065AA4(this);
}

void sub_08065A00(EponaEntity* this) {
    UpdateAnimationSingleFrame(super);
    sub_08065AA4(this);
}

void sub_08065A10(EponaEntity* this) {
    if ((gMessage.state & MESSAGE_ACTIVE) == 0) {
        super->action = 1;
        InitAnimationForceUpdate(super, super->animationState / 2);
    }
}

void sub_08065A34(EponaEntity* this) {
    if (UpdateFuseInteraction(super) != 0) {
        super->action = 1;
        InitAnimationForceUpdate(super, super->animationState / 2);
    }
}

void sub_08065A50(EponaEntity* this) {
    static const Dialog typeDialogs[] = {
        { 0, 0, DIALOG_MINISH, 1, { TEXT_INDEX(TEXT_LON_LON, 0X17), TEXT_INDEX(TEXT_TINGLE, 0x3c) } },
    };
    ShowNPCDialogue(super, &typeDialogs[super->type]);
}

void sub_08065A64(EponaEntity* this) {
    u32 uVar2;

    if ((gPlayerState.flags & PL_MINISH) != 0) {
        uVar2 = TRUE;
    } else {
        uVar2 = FALSE;
    }

    if (uVar2 != this->unk_69) {
        if (uVar2 == 0) {
            AddInteractableWhenBigObject(super);
        } else {
            AddInteractableAsMinishFuser(super, this->fusionOffer);
        }
    }
    this->unk_69 = uVar2;
}

void sub_08065AA4(EponaEntity* this) {
    if (super->interactType != INTERACTION_NONE) {
        if (gPlayerState.flags & PL_MINISH) {
            if (super->interactType == INTERACTION_FUSE) {
                super->action = 4;
                InitializeNPCFusion(super);
            } else {
                super->action = 3;
                SetEntityPriority(super, PRIO_MESSAGE);
                sub_08065A50(this);
            }
            InitAnimationForceUpdate(super,
                                     GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity.base)));
        } else {
            sub_08065A50(this);
            ResetPlayerAnimationAndAction();
        }
        SoundReq(SFX_VO_EPONA);
        super->interactType = INTERACTION_NONE;
    }
}

void Epona_Fusion(EponaEntity* this) {
    if (super->action == 0) {
        super->action++;
        super->spriteSettings.draw = 1;
        InitAnimationForceUpdate(super, 7);
    } else {
        UpdateAnimationSingleFrame(super);
    }
}