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
|
/**
* @file lightLevelSetManager.c
* @ingroup Managers
*
* @brief Changes the light level when a flag is set.
*/
#include "manager/lightLevelSetManager.h"
#include "flags.h"
#include "game.h"
#include "object.h"
#include "asm.h"
#include "effects.h"
#include "player.h"
#include "room.h"
#include "tiles.h"
void sub_0805BE94(LightLevelSetManager*);
void sub_0805BEC4(LightLevelSetManager*);
void LightLevelSetManager_Type0(LightLevelSetManager*);
void LightLevelSetManager_Type1(LightLevelSetManager*);
void LightLevelSetManager_Type2(LightLevelSetManager*);
void LightLevelSetManager_Type3(LightLevelSetManager*);
void sub_0805BE70(LightLevelSetManager* this, u32 tileType);
void LightLevelSetManager_Main(Manager* this) {
static void (*const LightLevelSetManager_Types[])(LightLevelSetManager*) = {
LightLevelSetManager_Type0,
LightLevelSetManager_Type1,
LightLevelSetManager_Type2,
LightLevelSetManager_Type3,
};
LightLevelSetManager_Types[this->type]((LightLevelSetManager*)this);
}
void LightLevelSetManager_Type0(LightLevelSetManager* this) {
if (super->action == 0) {
super->action = 1;
super->subtimer = 30;
if (CheckFlags(this->field_0x3e) != 0) {
sub_0805BE94(this);
}
}
if ((CheckFlags(this->field_0x3e) != 0) && (--super->subtimer == 0)) {
sub_0805BEC4(this);
sub_0805BE94(this);
}
}
void LightLevelSetManager_Type1(LightLevelSetManager* this) {
switch (super->action) {
case 0:
super->action = 1;
super->subtimer = 30;
if (CheckFlags(this->field_0x3e) != 0) {
sub_0805BE70(this, TILE_TYPE_117);
super->action = 2;
}
break;
case 1:
if (CheckFlags(this->field_0x3e) != 0 && --super->subtimer == 0) {
super->subtimer = 30;
sub_0805BEC4(this);
sub_0805BE70(this, TILE_TYPE_118);
}
break;
case 2:
if (CheckFlags(this->field_0x3e) == 0 && --super->subtimer == 0) {
super->subtimer = 30;
sub_0805BE70(this, TILE_TYPE_117);
}
break;
}
}
void LightLevelSetManager_Type2(LightLevelSetManager* this) {
if (super->action == 0) {
if (CheckFlags(this->field_0x3e) != 0) {
sub_0805BE94(this);
}
this->field_0x20 =
((s16)this->field_0x38 >> 4 & 0x3fU) | ((s32)((this->field_0x3a << 0x10) >> 0x14 & 0x3fU) << 6);
super->action = 1;
} else {
if (GetTileTypeAtTilePos(this->field_0x20, super->type2) == TILE_TYPE_118) {
SetFlag(this->field_0x3e);
ChangeLightLevel(super->timer);
DeleteThisEntity();
}
}
}
void LightLevelSetManager_Type3(LightLevelSetManager* this) {
u8 bVar1;
u16 uVar2;
u32 uVar3;
switch (super->action) {
case 0:
if (CheckFlags(this->field_0x3e) != 0 || CheckFlags(this->field_0x3c) != 0) {
sub_0805BE94(this);
}
this->field_0x20 =
((s16)this->field_0x38 >> 4 & 0x3fU) | (((s32)(this->field_0x3a << 0x10) >> 0x14 & 0x3fU) << 6);
super->action = 1;
break;
case 1:
if (GetTileTypeAtTilePos(this->field_0x20, super->type2) != TILE_TYPE_118) {
return;
}
SetFlag(this->field_0x3e);
ChangeLightLevel(super->timer);
super->action = 2;
this->field_0x22 = this->field_0x36 * 0x3c;
return;
break;
default:
if (--this->field_0x22 == 0) {
CreateDeathFxAt(*(s16*)&this->field_0x38, *(s16*)&this->field_0x3a, super->type2);
ClearFlag(this->field_0x3e);
RestorePrevTileEntity(this->field_0x20, super->type2);
ChangeLightLevel(-super->timer);
super->action = 1;
} else {
if (CheckFlags(this->field_0x3c) == 0) {
return;
}
sub_0805BEC4(this);
DeleteThisEntity();
}
break;
}
}
void sub_0805BE70(LightLevelSetManager* this, u32 tileType) {
SetTileType(tileType,
((this->field_0x38 << 0x10) >> 0x14 & 0x3fU) | ((this->field_0x3a << 0x10) >> 0x14 & 0x3fU) << 6,
super->type2);
}
void sub_0805BE94(LightLevelSetManager* this) {
SetTileType(TILE_TYPE_118,
((this->field_0x38 << 0x10) >> 0x14 & 0x3fU) | ((this->field_0x3a << 0x10) >> 0x14 & 0x3fU) << 6,
super->type2);
ChangeLightLevel(super->timer);
DeleteThisEntity();
}
void sub_0805BEC4(LightLevelSetManager* this) {
Entity* object = CreateObject(FLAME, 1, 0);
if (object != NULL) {
*(s8*)(&object->flags + 1) = ((*(s8*)(&object->flags + 1)) & (-0x10)) | 3;
object->x.HALF.HI = this->field_0x38 + gRoomControls.origin_x;
object->y.HALF.HI = this->field_0x3a + gRoomControls.origin_y;
object->collisionLayer = super->type2;
object->spritePriority.b0 = 2;
}
}
|