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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/**
* @file lightableSwitch.c
* @ingroup Objects
*
* @brief Lightable Switch object
*/
#include "asm.h"
#include "entity.h"
#include "flags.h"
#include "functions.h"
#include "hitbox.h"
#include "object.h"
#include "room.h"
#include "sound.h"
typedef struct {
/*0x00*/ Entity base;
/*0x68*/ u8 unused1[12];
/*0x74*/ u16 unk_74;
/*0x76*/ u8 unused2[14];
/*0x84*/ u16 unk_84;
/*0x86*/ u16 unk_86;
} LightableSwitchEntity;
static void sub_0809EB30(LightableSwitchEntity* this);
static void sub_0809EAD8(LightableSwitchEntity* this);
static void sub_0809EABC(LightableSwitchEntity* this);
static void LightableSwitch_Type0(LightableSwitchEntity* this);
static void LightableSwitch_Type1(LightableSwitchEntity* this);
static void LightableSwitch_Type0_Init(LightableSwitchEntity* this);
static void LightableSwitch_Type0_Action1(LightableSwitchEntity* this);
static void LightableSwitch_Type1_Action3(LightableSwitchEntity* this);
static void LightableSwitch_Type1_Action2(LightableSwitchEntity* this);
static void LightableSwitch_Type1_Action1(LightableSwitchEntity* this);
static void LightableSwitch_Type1_Init(LightableSwitchEntity* this);
void LightableSwitch(LightableSwitchEntity* this) {
static void (*const LightableSwitch_Types[])(LightableSwitchEntity*) = {
LightableSwitch_Type0,
LightableSwitch_Type1,
};
LightableSwitch_Types[super->type](this);
sub_0809EB30(this);
}
void LightableSwitch_Type0(LightableSwitchEntity* this) {
static void (*const LightableSwitch_Type0_Actions[])(LightableSwitchEntity*) = {
LightableSwitch_Type0_Init,
LightableSwitch_Type0_Action1,
};
LightableSwitch_Type0_Actions[super->action](this);
}
void LightableSwitch_Type0_Init(LightableSwitchEntity* this) {
super->action = 1;
COLLISION_ON(super);
super->frameIndex = 0;
super->collisionFlags = 7;
super->hurtType = 0x48;
super->hitType = 0x28;
super->flags2 = 10;
super->hitbox = (Hitbox*)&gHitbox_0;
sub_0809EAD8(this);
UpdateSpriteForCollisionLayer(super);
sub_0809EABC(this);
}
void LightableSwitch_Type0_Action1(LightableSwitchEntity* this) {
if ((super->contactFlags & CONTACT_TAKE_DAMAGE) != 0) {
if (CheckFlags(this->unk_86) != 0) {
ClearFlag(this->unk_86);
} else {
SetFlag(this->unk_86);
}
EnqueueSFX(SFX_110);
}
sub_0809EABC(this);
}
static void sub_0809EABC(LightableSwitchEntity* this) {
bool32 anySet = 0;
if (CheckFlags(this->unk_86)) {
anySet = 1;
}
if (super->frameIndex != anySet) {
super->frameIndex = anySet;
}
}
static void sub_0809EAD8(LightableSwitchEntity* this) {
u8 bVar1;
Entity* pEVar2;
if (super->type2 != 0) {
super->child = GetCurrentRoomProperty(super->type2);
UpdateRailMovement(super, (u16**)&super->child, &this->unk_74);
} else {
SetTile(0x4050, COORD_TO_TILE(super), super->collisionLayer);
}
}
static void sub_0809EB30(LightableSwitchEntity* this) {
u16 uVar1;
u16* puVar2;
if (super->type2 != 0) {
if ((super->direction & 0x80) == 0) {
LinearMoveUpdate(super);
}
puVar2 = &this->unk_74;
if (!--*puVar2) {
UpdateRailMovement(super, (u16**)&super->child, puVar2);
}
}
}
void LightableSwitch_Type1(LightableSwitchEntity* this) {
static void (*const LightableSwitch_Type1_Actions[])(LightableSwitchEntity*) = {
LightableSwitch_Type1_Init,
LightableSwitch_Type1_Action1,
LightableSwitch_Type1_Action2,
LightableSwitch_Type1_Action3,
};
LightableSwitch_Type1_Actions[super->action](this);
}
void LightableSwitch_Type1_Init(LightableSwitchEntity* this) {
super->action = 1;
COLLISION_ON(super);
super->frameIndex = 3;
super->collisionFlags = 7;
super->hurtType = 0x48;
super->hitType = 0x28;
super->flags2 = 10;
super->hitbox = (Hitbox*)&gHitbox_0;
sub_0809EAD8(this);
UpdateSpriteForCollisionLayer(super);
if (CheckFlags(this->unk_84)) {
super->action = 3;
super->frameIndex = 2;
}
}
void LightableSwitch_Type1_Action1(LightableSwitchEntity* this) {
if ((super->contactFlags & CONTACT_TAKE_DAMAGE) != 0) {
super->action = 2;
super->timer = 16;
super->frameIndex = 2;
SetFlag(this->unk_86);
EnqueueSFX(SFX_110);
}
}
void LightableSwitch_Type1_Action2(LightableSwitchEntity* this) {
if (CheckFlags(this->unk_84)) {
super->action = 3;
} else {
if (--super->timer == 0) {
super->action = 1;
super->frameIndex = 3;
ClearFlag(this->unk_86);
EnqueueSFX(SFX_110);
}
}
}
void LightableSwitch_Type1_Action3(LightableSwitchEntity* this) {
}
|