summaryrefslogtreecommitdiff
path: root/src/npc/farmers.c
blob: 9d5a2806359b041830bb74defdb26b43b98f1e1a (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
/**
 * @file farmers.c
 * @ingroup NPCs
 *
 * @brief Farmers NPC
 */
#include "entity.h"
#include "message.h"
#include "npc.h"
#include "script.h"

static const SpriteLoadData gUnk_08113140[] = {
    { 0xf7, 0x48, 0x4 }, { 0x40f7, 0x48, 0x4 }, { 0, 0, 0 }, { 0xf8, 0x49, 0x4 }, { 0x40f8, 0x49, 0x4 }, { 0, 0, 0 },
};

void sub_0806BC58(Entity* this);

void Farmers(Entity* this) {
    if (this->action == 0) {
        if (!LoadExtraSpriteData(this, &gUnk_08113140[this->type * 3])) {
            return;
        }
        this->action++;
        this->spriteSettings.flipX = this->timer;
        if (this->spriteSettings.flipX == 0) {
            this->animationState = 6;
        } else {
            this->animationState = 2;
        }
        this->timer = this->animationState;
        sub_0806BC58(this);
        sub_0807DD64(this);
    }
    ExecuteScriptForEntity(this, 0);
    HandleEntity0x82Actions(this);
    GetNextFrame(this);
}

void sub_0806BC58(Entity* this) {
    SetEntityPriority(this, PRIO_MESSAGE);
}

void Farmers_Head(Entity* this) {
    SetExtraSpriteFrame(this, 0, this->frame & 0x7f);
    SetExtraSpriteFrame(this, 1, this->frameIndex);
    SetSpriteSubEntryOffsetData1(this, 1, 0);
    sub_0807000C(this);
}

void sub_0806BC94(Entity* this, ScriptExecutionContext* context) {
    u32 offset = 0;
    if (this->spriteSettings.flipX) {
        offset = 8;
    }
    InitializeAnimation(this, context->intVariable + offset + (this->animationState >> 1));
}

void sub_0806BCB8(Entity* this) {
    this->animationState = this->timer;
}

void Farmers_MarkEenieFuserDoner(Entity* this) {
    if (this->type == 0) {
        MarkFuserDone(this);
    }
}

void Farmers_MakeInteractable(Entity* this) {
    AddInteractableWhenBigFuser(this, GetFusionToOffer(this));
}

void sub_0806BCE8(Entity* this) {
    static const Dialog gUnk_08113158[] = {
        { 0x29,
          DIALOG_KINSTONE,
          DIALOG_CHECK_FLAG,
          1,
          { TEXT_INDEX(TEXT_FARMERS, 0x7), TEXT_INDEX(TEXT_FARMERS, 0x2) } },
        { 0x29,
          DIALOG_KINSTONE,
          DIALOG_CHECK_FLAG,
          1,
          { TEXT_INDEX(TEXT_FARMERS, 0x11), TEXT_INDEX(TEXT_FARMERS, 0xd) } },
    };
    ShowNPCDialogue(this, &gUnk_08113158[this->type]);
}

void Farmers_Fusion(Entity* this) {
    if (this->action == 0) {
        if (LoadExtraSpriteData(this, &gUnk_08113140[this->type * 3])) {
            this->action++;
            this->spriteSettings.draw = 1;
            this->spriteSettings.flipX = 0;
            sub_0806BC58(this);
            InitAnimationForceUpdate(this, 3);
        }
    } else {
        UpdateAnimationSingleFrame(this);
    }
}