summaryrefslogtreecommitdiff
path: root/src/object/minishPortalStone.c
blob: b8e7a96007a8366d34da3bbeeef4811e8df3a694 (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
/**
 * @file minishPortalStone.c
 * @ingroup Objects
 *
 * @brief Minish Portal Stone object
 */
#include "object.h"
#include "asm.h"
#include "sound.h"
#include "flags.h"
#include "room.h"
#include "player.h"
#include "screen.h"
#include "beanstalkSubtask.h"
#include "manager/lightManager.h"
#include "effects.h"
#include "pauseMenu.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u8 unk_68[0x1e];
    /*0x86*/ u16 flag;
} MinishPortalStoneEntity;

void MinishPortalStone_Init(MinishPortalStoneEntity* this);
void MinishPortalStone_Action1(MinishPortalStoneEntity* this);
void MinishPortalStone_Action2(MinishPortalStoneEntity* this);
void MinishPortalStone_Action3(MinishPortalStoneEntity* this);
void MinishPortalStone_Action4(MinishPortalStoneEntity* this);
void sub_08097CFC(MinishPortalStoneEntity* this);
bool32 sub_08097CB0(MinishPortalStoneEntity* this);
void sub_08097CB4(MinishPortalStoneEntity* this);

const Hitbox gUnk_08123328 = { 0, 0, { 4, 0, 0, 4 }, 18, 18 };

void MinishPortalStone(MinishPortalStoneEntity* this) {
    static void (*const MinishPortalStone_Actions[])(MinishPortalStoneEntity*) = {
        MinishPortalStone_Init,    MinishPortalStone_Action1, MinishPortalStone_Action2,
        MinishPortalStone_Action3, MinishPortalStone_Action4,
    };
    MinishPortalStone_Actions[super->action](this);
}

void MinishPortalStone_Init(MinishPortalStoneEntity* this) {
    super->action = 1;
    super->spritePriority.b0 = 7;
    super->hitbox = (Hitbox*)&gUnk_08123328;
    if ((this->flag == 0xffff) || CheckFlags(this->flag)) {
        super->spriteSettings.draw = 1;
        super->action = 4;
        sub_08097CFC(this);
    } else {
        UnDarkRoom();
    }
}

void MinishPortalStone_Action1(MinishPortalStoneEntity* this) {
    if (CheckFlags(this->flag)) {
        SetPlayerControl(CONTROL_1);
        gPauseMenuOptions.disabled = 1;
        RequestPriorityDuration(super, 30);
        if (sub_08097CB0(this) == FALSE) {
            sub_08097CB4(this);
        }
    }
}

void MinishPortalStone_Action2(MinishPortalStoneEntity* this) {
}

void MinishPortalStone_Action4(MinishPortalStoneEntity* this) {
}

void MinishPortalStone_Action3(MinishPortalStoneEntity* this) {
    u32 tmp;
    SetPriorityTimer(30);
    sub_0800445C(super);
    CreateMagicSparklesFxAt(super->x.HALF.HI, super->y.HALF.HI, super->collisionLayer);
    if (--super->timer == 0) {
        super->timer = 8;
        tmp = ++super->subtimer;
        gScreen.controls.alphaBlend = (((0x10 - tmp) * 0x100)) | tmp;
        if (gScreen.controls.alphaBlend == 0x10) {
            SetPlayerControl(CONTROL_ENABLED);
            gPauseMenuOptions.disabled = 0;
            gScreen.controls.layerFXControl = 0;
            sub_08097CFC(this);
            super->action = 4;
            super->spriteRendering.alphaBlend = 0;
            SoundReq(SFX_SECRET);
            SetGlobalFlag(TINY_ENTRANCE);
        }
    }
}

bool32 sub_08097CB0(MinishPortalStoneEntity* this) {
    return FALSE;
}

void sub_08097CB4(MinishPortalStoneEntity* this) {
    super->action = 3;
    super->spriteSettings.draw = 1;
    super->spriteRendering.alphaBlend = 1;
    super->timer = 30;
    super->subtimer = 0;
    gScreen.controls.layerFXControl = 0xf40;
    gScreen.controls.alphaBlend = 0x1000;
    SoundReq(SFX_14A);
}

void sub_08097CFC(MinishPortalStoneEntity* this) {
    // TODO recreate as TileData[]
    static const u16 gUnk_08123344[] = { 16448, 65471, 16449, 65472, 16450, 65473, 16451, 65535, 16452, 0,
                                         16453, 1,     16454, 63,    16455, 64,    16456, 65,    65535 };
    static const u16 gUnk_0812336A[] = {
        16449, 65471, 16449, 65472, 16452, 65535, 16452, 0, 16455, 63, 16455, 64, 65535
    };
    if ((super->x.HALF.HI & 0xf) == 0) {
        SetMultipleTiles((TileData*)gUnk_0812336A, COORD_TO_TILE(super), super->collisionLayer);
    } else {
        SetMultipleTiles((TileData*)gUnk_08123344, COORD_TO_TILE(super), super->collisionLayer);
    }
}