summaryrefslogtreecommitdiff
path: root/src/npc/ezlo.c
blob: ba3532cdfaa01c85fac025bbbed2dd6b97ec7b5e (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
/**
 * @file ezlo.c
 * @ingroup NPCs
 *
 * @brief Ezlo NPC
 */
#include "npc.h"
#include "physics.h"
#include "effects.h"
#include "player.h"
#include "script.h"
#include "asm.h"

const u8 gUnk_08114134[];
const u8 gUnk_08114144[];

// Ezlo as a cap in the Minish Woods, is destroyed as soon as link wears ezlo
void Ezlo(Entity* this) {
    if (this->action == 0) {
        this->action++;
        SetEntityPriority(this, PRIO_MESSAGE);
        InitScriptForNPC(this);
    }
    ExecuteScriptForEntity(this, NULL);
    HandleEntity0x82Actions(this);
    UpdateAnimationSingleFrame(this);
}

void sub_0806D8A0(Entity* this, ScriptExecutionContext* context) {
    s32 xOffset;
    s32 yOffset;

    context->unk_19 = 8;
    context->postScriptActions |= 2;
    context->condition = 0;
    xOffset = 16;
    if (this->spriteSettings.flipX) {
        xOffset = -xOffset;
    }
    xOffset += gPlayerEntity.base.x.HALF.HI;
    yOffset = gPlayerEntity.base.y.HALF.HI + 2;
    context->x.HALF.HI = xOffset;
    context->y.HALF.HI = yOffset;

    xOffset -= this->x.HALF.HI;
    this->direction = CalculateDirectionFromOffsets(xOffset, yOffset - this->y.HALF.HI);
    this->animationState = (this->animationState & 0x80) | gUnk_08114134[this->direction >> 4];
}

void sub_0806D908(Entity* this) {
    this->direction = CalculateDirectionTo(this->x.HALF.HI, this->y.HALF.HI, gPlayerEntity.base.x.HALF.HI,
                                           gPlayerEntity.base.y.HALF.HI);
    this->animationState = (this->animationState & 0x80) | gUnk_08114144[this->direction >> 0x1];
}

// called when talk to ezlo, also when ezlo moves after you
void sub_0806D944(Entity* this) {
    this->spriteSettings.flipX = 0;
    if (this->x.WORD <= gPlayerEntity.base.x.WORD) {
        this->spriteSettings.flipX = 1;
    }
}

// Ezlo Angry FX
void sub_0806D96C(Entity* this) {
    Entity* fx = CreateFx(this, FX_STEAM_EFC, 0);
    if (fx != NULL) {
        fx->spritePriority.b0 = 1;
        PositionRelative(this, fx, 0, Q_16_16(-24.0));
    }
}

void sub_0806D9A4(Entity* this) {
    if (this->x.WORD <= gPlayerEntity.base.x.WORD) {
        gPlayerEntity.base.spriteSettings.flipX = 0;
    } else {
        gPlayerEntity.base.spriteSettings.flipX = 1;
    }
    gPlayerEntity.base.animationState = 4;
}

// animation states
const u8 gUnk_08114134[] = { 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04,
                             0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x00 };

// animation states
const u8 gUnk_08114144[] = { 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04,
                             0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x00 };