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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
#include <common.h>
#include <game.h>
// Patches MIST_INTERMITTENT (sprite 239)
class daEnEventBlock_c : public daEnBlockMain_c {
public:
enum Mode {
TOGGLE_EVENT = 0,
SWAP_EVENTS = 1
};
typedef State<daEnEventBlock_c> State;
TileRenderer tile;
Physics::Info physicsInfo;
u8 event1;
u8 event2;
Mode mode;
void equaliseEvents();
int onCreate();
int onDelete();
int onExecute();
void calledWhenUpMoveExecutes();
void calledWhenDownMoveExecutes();
void wait_Begin();
void wait_Execute();
void wait_End();
void blockWasHit(bool isDown);
static State StateID_Wait;
static daEnEventBlock_c *build();
};
daEnEventBlock_c::State daEnEventBlock_c::StateID_Wait(
"daEnEventBlock_c::StateID_Wait",
&daEnEventBlock_c::wait_Begin,
&daEnEventBlock_c::wait_Execute,
&daEnEventBlock_c::wait_End);
int daEnEventBlock_c::onCreate() {
blockInit(pos.y);
physicsInfo.x1 = -8;
physicsInfo.y1 = 16;
physicsInfo.x2 = 8;
physicsInfo.y2 = 0;
physicsInfo.otherCallback1 = &daEnBlockMain_c::OPhysicsCallback1;
physicsInfo.otherCallback2 = &daEnBlockMain_c::OPhysicsCallback2;
physicsInfo.otherCallback3 = &daEnBlockMain_c::OPhysicsCallback3;
physics.setup(this, &physicsInfo, 3, currentLayerID);
physics.flagsMaybe = 0x260;
physics.callback1 = &daEnBlockMain_c::PhysicsCallback1;
physics.callback2 = &daEnBlockMain_c::PhysicsCallback2;
physics.callback3 = &daEnBlockMain_c::PhysicsCallback3;
physics.addToList();
TileRenderer::List *list = dBgGm_c::instance->getTileRendererList(0);
list->add(&tile);
tile.x = pos.x - 8;
tile.y = -(16 + pos.y);
tile.tileNumber = 0x97;
mode = (Mode)((settings >> 16) & 0xF);
event1 = ((settings >> 8) & 0xFF) - 1;
event2 = (settings & 0xFF) - 1;
equaliseEvents();
doStateChange(&daEnEventBlock_c::StateID_Wait);
return true;
}
int daEnEventBlock_c::onDelete() {
TileRenderer::List *list = dBgGm_c::instance->getTileRendererList(0);
list->remove(&tile);
physics.removeFromList();
return true;
}
int daEnEventBlock_c::onExecute() {
acState.execute();
physics.update();
blockUpdate();
tile.setPosition(pos.x-8, -(16+pos.y), pos.z);
tile.setVars(scale.x);
equaliseEvents();
bool isActive = dFlagMgr_c::instance->active(event2);
tile.tileNumber = (isActive ? 0x96 : 0x97);
// now check zone bounds based on state
if (acState.getCurrentState()->isEqual(&StateID_Wait)) {
checkZoneBoundaries(0);
}
return true;
}
daEnEventBlock_c *daEnEventBlock_c::build() {
OSReport("Creating EventBlock\n");
void *buffer = AllocFromGameHeap1(sizeof(daEnEventBlock_c));
daEnEventBlock_c *c = new(buffer) daEnEventBlock_c;
OSReport("Created EventBlock @ %p\n", c);
return c;
}
void daEnEventBlock_c::equaliseEvents() {
if (mode != SWAP_EVENTS)
return;
bool f1 = dFlagMgr_c::instance->active(event1);
bool f2 = dFlagMgr_c::instance->active(event2);
if (!f1 && !f2) {
dFlagMgr_c::instance->set(event1, 0, true, false, false);
}
if (f1 && f2) {
dFlagMgr_c::instance->set(event2, 0, false, false, false);
}
}
void daEnEventBlock_c::blockWasHit(bool isDown) {
pos.y = initialY;
if (mode == TOGGLE_EVENT) {
if (dFlagMgr_c::instance->active(event2))
dFlagMgr_c::instance->set(event2, 0, false, false, false);
else
dFlagMgr_c::instance->set(event2, 0, true, false, false);
} else if (mode == SWAP_EVENTS) {
if (dFlagMgr_c::instance->active(event1)) {
dFlagMgr_c::instance->set(event1, 0, false, false, false);
dFlagMgr_c::instance->set(event2, 0, true, false, false);
} else {
dFlagMgr_c::instance->set(event1, 0, true, false, false);
dFlagMgr_c::instance->set(event2, 0, false, false, false);
}
}
physics.setup(this, &physicsInfo, 3, currentLayerID);
physics.addToList();
doStateChange(&StateID_Wait);
}
void daEnEventBlock_c::calledWhenUpMoveExecutes() {
if (initialY >= pos.y)
blockWasHit(false);
}
void daEnEventBlock_c::calledWhenDownMoveExecutes() {
if (initialY <= pos.y)
blockWasHit(true);
}
void daEnEventBlock_c::wait_Begin() {
}
void daEnEventBlock_c::wait_End() {
}
void daEnEventBlock_c::wait_Execute() {
int result = blockResult();
if (result == 0)
return;
if (result == 1) {
doStateChange(&daEnBlockMain_c::StateID_UpMove);
anotherFlag = 2;
isGroundPound = false;
} else {
doStateChange(&daEnBlockMain_c::StateID_DownMove);
anotherFlag = 1;
isGroundPound = true;
}
}
|