summaryrefslogtreecommitdiff
path: root/src/npc/mailbox.c
blob: 7732485b7ef264ba023e3f812cca345c2339c7f4 (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
/**
 * @file mailbox.c
 * @ingroup NPCs
 *
 * @brief Mailbox NPC
 */
#include "effects.h"
#include "entity.h"
#include "message.h"
#include "npc.h"
#include "player.h"

void sub_08063280(Entity*);
void sub_08063210(Entity*);
void sub_08063220(Entity*);
void sub_08063254(Entity*);
void sub_08063278(Entity*);

void Mailbox(Entity* this) {
    static void (*const gMailboxBehaviors[4])(Entity*) = {
        sub_08063210,
        sub_08063220,
        sub_08063254,
        sub_08063278,
    };
    gMailboxBehaviors[this->action](this);

    if (this->action != 0) {
        sub_0806ED78(this);
    }
}

void sub_08063210(Entity* this) {
    this->action = 1;
    InitAnimationForceUpdate(this, 0);
}

void sub_08063220(Entity* this) {
    u8 bVar1;

    if (this->interactType != INTERACTION_NONE) {
        this->action = 2;
        bVar1 = 8;
    } else {
        bVar1 = 0;
    }

    if (this->animIndex != bVar1) {
        InitAnimationForceUpdate(this, bVar1);
    } else {
        sub_08063280(this);
    }
}

void sub_08063254(Entity* this) {
    sub_08063280(this);
    if ((this->frame & ANIM_DONE) != 0) {
        this->action = 3;
        MessageFromTarget(0);
    }
}

void sub_08063278(Entity* this) {
    sub_08063280(this);
}

void sub_08063280(Entity* this) {
    u8 var; // r2@1

    UpdateAnimationSingleFrame(this);
    var = this->frame & ~ANIM_DONE;
    this->frame ^= var;
    if (var == 2)
        CreateFx(this, FX_MAILBOX_UNUSED, 0);
}