summaryrefslogtreecommitdiff
path: root/src/object/bedCover.c
blob: 10697f494a223e3cddf2b752d31381475c843e5f (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
/**
 * @file bedCover.c
 * @ingroup Objects
 *
 * @brief Bed Cover object
 */
#include "script.h"
#include "object.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u8 unk_68[0x1a];
    /*0x82*/ u16 unk_82;
    /*0x84*/ ScriptExecutionContext* unk_84;
} BedCoverEntity;

void sub_080928C8(BedCoverEntity*);
void nullsub_119(BedCoverEntity*);
void sub_08092930(BedCoverEntity*);
void sub_08092940(BedCoverEntity*);
void sub_08092958(BedCoverEntity*, ScriptExecutionContext*);

void BedCover(BedCoverEntity* this) {
    static void (*const gUnk_08122794[])(BedCoverEntity*) = {
        sub_080928C8,
        nullsub_119,
    };
    static void (*const gUnk_0812279C[])(BedCoverEntity*) = {
        sub_08092930,
        sub_08092940,
    };
    if ((super->flags & 2) != 0) {
        gUnk_0812279C[super->action](this);
    } else {
        gUnk_08122794[super->action](this);
    }
}

void sub_080928C8(BedCoverEntity* this) {
    super->action = 1;
    super->spriteSettings.draw = 1;
    super->frameIndex = super->type;
    super->spriteRendering.b3 = 3;
    super->spritePriority.b0 = 6;
    super->spriteOrientation.flipY = 2;
    switch (super->type) {
        case 2:
            CreateObjectWithParent(super, BED_COVER, 4, 0);
            break;
        case 4:
            super->spritePriority.b0 = 7;
            break;
    }
}

void nullsub_119(BedCoverEntity* this) {
}

void sub_08092930(BedCoverEntity* this) {
    sub_080928C8(this);
    this->unk_82 = 0;
}

void sub_08092940(BedCoverEntity* this) {
    ExecuteScript(super, this->unk_84);
    sub_08092958(this, this->unk_84);
}

void sub_08092958(BedCoverEntity* this, ScriptExecutionContext* context) {
    u32 tmp;
    while (context->postScriptActions != 0) {
        tmp = (~context->postScriptActions + 1) & context->postScriptActions;
        context->postScriptActions = context->postScriptActions ^ tmp;
        switch (tmp) {
            case 1:
                super->frameIndex = 0;
                break;
            case 2:
                super->frameIndex = context->intVariable;
                break;
        }
    }
}