summaryrefslogtreecommitdiff
path: root/src/npc/carpenter.c
blob: bc969bb570247f401ab1315a27a47522e580a74a (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
/**
 * @file carpenter.c
 * @ingroup NPCs
 *
 * @brief Carpenter NPC
 */
#include "entity.h"
#include "item.h"
#include "npc.h"
#include "player.h"
#include "message.h"
#include "flags.h"
#include "script.h"
#include "physics.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u8 fusionOffer;
    /*0x69*/ u8 animIndex;
    /*0x6a*/ u8 unused[26];
    /*0x84*/ ScriptExecutionContext* context;
} CarpenterEntity;

static const SpriteLoadData gUnk_08110CA8[] = {
    { 0x51, 0x3f, 0x4 }, { 0x1451, 0x3f, 0x4 }, { 0x4001, 0x3f, 0x4 }, { 0, 0, 0 },
    { 0x51, 0x3f, 0x4 }, { 0x1451, 0x3f, 0x4 }, { 0x4001, 0x3f, 0x4 }, { 0, 0, 0 },
    { 0x51, 0x3f, 0x4 }, { 0x1451, 0x3f, 0x4 }, { 0, 0, 0 },           { 0, 0, 0 },
    { 0x51, 0x3f, 0x4 }, { 0x1451, 0x3f, 0x4 }, { 0, 0, 0 },           { 0, 0, 0 },
};

void Carpenter(CarpenterEntity* this) {
    if (this->context == NULL) {
        DeleteThisEntity();
    }
    switch (super->action) {
        case 0:
            if (!LoadExtraSpriteData(super, gUnk_08110CA8 + super->type * 4))
                break;
            super->action = 1;
            this->animIndex = 0;
            SetEntityPriority(super, PRIO_MESSAGE);
            sub_0807DD64(super);

        case 1:
            if (super->interactType == INTERACTION_FUSE) {
                super->action = 2;
                super->interactType = INTERACTION_NONE;
                this->animIndex = super->animIndex;
                InitializeAnimation(super,
                                    GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity.base)) + 4 +
                                        (super->type * 8));
                InitializeNPCFusion(super);
            } else {
                ExecuteScriptForEntity(super, 0);
                HandleEntity0x82Actions(super);
                GetNextFrame(super);
            }
            break;
        case 2:
            if (!UpdateFuseInteraction(super))
                break;
            super->action = 1;
            InitializeAnimation(super, this->animIndex);
            break;
    }
}

void Carpenter_Head(Entity* this) {
    if (this->type < 2) {
        SetExtraSpriteFrame(this, 0, this->frame & ~0x80);
        SetExtraSpriteFrame(this, 1, this->frameIndex);
        SetExtraSpriteFrame(this, 2, this->frameSpriteSettings & 0x3f);
        SetSpriteSubEntryOffsetData1(this, 1, 0);
        SetSpriteSubEntryOffsetData2(this, 1, 2);
        sub_0807000C(this);
    } else {
        SetExtraSpriteFrame(this, 0, this->frame & ~0x80);
        SetExtraSpriteFrame(this, 1, this->frameIndex);
        SetSpriteSubEntryOffsetData1(this, 1, 0);
        sub_0807000C(this);
    }
}

void sub_080672B0(Entity* this, ScriptExecutionContext* context) {
    InitializeAnimation(this, context->intVariable + (this->animationState >> 1) + this->type * 8);
}

void sub_080672C8(Entity* this) {
    static const u16 messageIndices[] = {
        TEXT_INDEX(TEXT_CARPENTERS, 0xd),  TEXT_INDEX(TEXT_CARPENTERS, 0xe),  0x0,
        TEXT_INDEX(TEXT_CARPENTERS, 0x18), TEXT_INDEX(TEXT_CARPENTERS, 0x19), 0x0,
        TEXT_INDEX(TEXT_CARPENTERS, 0x23), TEXT_INDEX(TEXT_CARPENTERS, 0x23), 0x0,
        TEXT_INDEX(TEXT_CARPENTERS, 0x26), TEXT_INDEX(TEXT_CARPENTERS, 0x26), 0x0,
    };
    u32 dialog = 0;
    u32 tmp;
    if (GetInventoryValue(ITEM_GUST_JAR) == 0) {
        if (CheckGlobalFlag(TABIDACHI)) {
            dialog = 1;
        }
    }
    MessageNoOverlap(messageIndices[(dialog * 2 + this->type * 6) / 2], this);
}

void sub_08067304(Entity* this) {
    static const Dialog dialog = {
        0xb, DIALOG_KINSTONE, DIALOG_CHECK_FLAG, 1, { TEXT_INDEX(TEXT_TOWN3, 0x42), TEXT_INDEX(TEXT_TOWN3, 0x41) }
    };
    ShowNPCDialogue(this, &dialog);
}

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

void Carpenter_Fusion(Entity* this) {
    if (this->action == 0) {
        if (LoadExtraSpriteData(this, &gUnk_08110CA8[this->type * 4])) {
            this->action++;
            this->spriteSettings.draw = 1;
            SetEntityPriority(this, PRIO_MESSAGE);
            InitializeAnimation(this, (u32)this->type * 8 + 2);
        }
    } else {
        GetNextFrame(this);
    }
}