DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
dungeoneventman.cpp
1#include "dungeoneventman.hpp"
2
3#include <cmath>
4#include <cstdio>
5
6#include "collisiondata.hpp"
7#include "dun/gameloop.hpp"
8#include "dungeonmap.hpp"
9#include "frame.hpp"
10#include "mathutil.hpp"
11
13 int slot_parts_id;
14
15 if (slot[index].enabled != 0) {
16 slot_parts_id = slot[index].parts_id;
17 } else {
18 slot_parts_id = -1;
19 }
20
21 if (parts_id == slot_parts_id) {
22 return &slot[index];
23 }
24
25 return NULL;
26}
27
29 for (int i = 0; i < 64; i++) {
30 if (slot[i].enabled == 0) {
31 return &slot[i];
32 }
33 }
34
35 return NULL;
36}
37
38void CDungeonEventMan::SearchDataSwitch(int script_no, int enable) {
39 for (int i = 0; i < 96; i++) {
40 int active;
41
42 if (event[i].event != NULL) {
43 active = event[i].enabled;
44 } else {
45 active = false;
46 }
47
48 if (active != 0) {
49 int event_script_no = event[i].event->script_no;
50
51 if (script_no == event_script_no) {
52 if (enable != 0) {
53 event[i].Start();
54 }
55
56 if (enable == 0) {
57 event[i].Stop();
58 }
59 }
60 }
61 }
62}
63
65 for (int i = 0; i < 96; i++) {
66 int active;
67
68 if (event[i].event != NULL) {
69 active = event[i].enabled;
70 } else {
71 active = false;
72 }
73
74 if (active != 0 && script_no == event[i].event->script_no) {
75 event[i].hold = 0;
76 }
77 }
78}
79
81 int count = 0;
82
83 for (int i = 0; i < 96; i++) {
84 int active;
85
86 if (event[i].event != NULL) {
87 active = event[i].enabled;
88 } else {
89 active = false;
90 }
91
92 if (active == 0) {
93 count++;
94 }
95 }
96
97 return count;
98}
99
101 for (int i = 0; i < 96; i++) {
102 int active;
103
104 if (event[i].event != NULL) {
105 active = event[i].enabled;
106 } else {
107 active = false;
108 }
109
110 if (active == 0) {
111 return &event[i];
112 }
113 }
114
115 return NULL;
116}
117
119 int i;
120 int chara_no;
121 int key_id;
122
123 chara_no = event[index].event->chara_no;
124 key_id = event[index].event->key_id;
125
126 if (chara_no != -1) {
127 for (i = 0; i < 96; i++) {
128 if (NowColData->active[i] == 0) {
129 continue;
130 }
131
132 if (NowColData->hit[i].owner != chara_no) {
133 continue;
134 }
135
136 if (key_id != -1 && NowColData->hit[i].attack_no != key_id) {
137 continue;
138 }
139
140 sceVu0FVECTOR hit_position;
141 sceVu0CopyVector(hit_position, NowColData->hit[i].pos);
142 float radius = event[index].event->radius;
143
144 if (DistVector(hit_position, event[index].pos) <= radius) {
145 return &event[index];
146 }
147 }
148 }
149
150 return NULL;
151}
152
154 for (int i = 0; i < 96; i++) {
155 CDungeonEventData *event_data = &event[i];
156
157 if (event_data->CheckSwitch() != 0) {
158 float radius = event[i].event->radius;
159
160 if (DistVector(event[i].pos, position) <= radius && event[i].event->chara_no == -1) {
161 return event_data;
162 }
163
164 CDungeonEventData *collision_event = CheckCollisionDataHit(i);
165
166 if (collision_event != NULL) {
167 return collision_event;
168 }
169 }
170 }
171
172 return NULL;
173}
174
176 int i;
177 sceVu0FVECTOR event_position;
178 sceVu0FVECTOR target_position;
179
180 sceVu0CopyVector(target_position, position);
181 float target_height = target_position[1];
182 target_position[1] = 0.0f;
183
184 for (i = 0; i < 96; i++) {
185 if (event[i].CheckSwitch() != 0) {
186 sceVu0CopyVector(event_position, event[i].pos);
187 float height_difference = target_height - event_position[1];
188 height_difference = height_difference < 0.0f ? -height_difference : height_difference;
189
190 if (height_difference < 40.0f) {
191 event_position[1] = 0.0f;
192 float radius = event[i].event->radius;
193
194 if (DistVector(event_position, target_position) <= radius + 10.0f) {
195 return &event[i];
196 }
197 }
198 }
199 }
200
201 return NULL;
202}
203
205 sceVu0FVECTOR local_origin = {0.0f, 0.0f, 0.0f, 0.0f};
206 sceVu0FMATRIX matrix;
207 sceVu0FMATRIX part_matrix;
208 CDungeonEvent *definition;
209 CDungeonEventData *runtime_event;
210 int column;
211 int row;
212
213 if (mode == 1) {
214 for (row = 0; row < 16; row++) {
215 for (column = 0; column < 16; column++) {
216 int parts_id = map->cells[column + row * 20].parts_no;
217
218 if (parts_id == MAP_PARTS_NONE) {
219 continue;
220 }
221
222 for (int slot_no = 0; slot_no < 64; slot_no++) {
223 if ((definition = SearchPartsID(slot_no, parts_id)) == NULL) {
224 continue;
225 }
226
227 runtime_event = SearchDataSlot();
228
229 if (runtime_event == NULL) {
230 printf("** eventdata err \n");
231
232 while (true) {
233 }
234 }
235
236 runtime_event->Set(definition);
237 float direction = (float) map->cells[column + row * 20].direction;
238 direction += (float) (map->cells[column + row * 20].parts_no == MAP_PARTS_NONE ? 0 : map->parts[map->cells[column + row * 20].parts_no].collision_turn);
239
240 if (direction > 3.0f) {
241 direction -= 3.0f;
242 }
243
244 if (direction == 3.0f) {
245 direction = -1.0f;
246 }
247
248 direction = (PI * (-90.0f * direction)) / 180.0f;
249 definition->placement_frame->SetRotation(0.0f, direction, 0.0f);
250 definition->trigger_frame->GetLWMatrix(matrix);
251 runtime_event->dir[0] = 0.0f;
252 runtime_event->dir[1] = atan2f(matrix[2][0], matrix[2][2]);
253 runtime_event->dir[2] = 0.0f;
254 runtime_event->dir[3] = 1.0f;
255 definition->placement_frame->SetPosition(160.0f * (float) column, 0.0f, 160.0f * (float) row);
256 definition->trigger_frame->GetWorldPosition(runtime_event->pos, local_origin);
257 }
258 }
259 }
260
261 return;
262 }
263
264 for (int parts_id = 0; map->parts[parts_id].frame[0] != NULL; parts_id++) {
265 for (int slot_no = 0; slot_no < 64; slot_no++) {
266 if ((definition = SearchPartsID(slot_no, parts_id)) == NULL) {
267 continue;
268 }
269
270 runtime_event = SearchDataSlot();
271 runtime_event->Set(definition);
272 float direction = map->parts[parts_id].frame_turn[0];
273 direction += (float) (parts_id == MAP_PARTS_NONE ? 0 : map->parts[parts_id].collision_turn);
274
275 if (direction > 3.0f) {
276 direction -= 3.0f;
277 }
278
279 if (direction == 3.0f) {
280 direction = -1.0f;
281 }
282
283 float angle = (PI * (-90.0f * direction)) / 180.0f;
284 definition->placement_frame->SetRotation(0.0f, angle, 0.0f);
285 definition->trigger_frame->GetLWMatrix(part_matrix);
286 runtime_event->dir[0] = 0.0f;
287 runtime_event->dir[1] = atan2f(part_matrix[2][0], part_matrix[2][2]);
288 runtime_event->dir[2] = 0.0f;
289 runtime_event->dir[3] = 1.0f;
290 definition->trigger_frame->GetWorldPosition(runtime_event->pos, local_origin);
291 }
292 }
293}
COLLISION_HIT hit[96]
void Set(CDungeonEvent *source)
CDungeonEvent * event
CDungeonEventData * CheckCollisionDataHit(int index)
void SearchItemEventHold(int script_no)
CDungeonEvent slot[64]
CDungeonEventData * SearchDataSlot()
CDungeonEventData * SearchDataSlotPos2(float *position)
CDungeonEventData event[96]
CDungeonEvent * SearchPartsID(int index, int parts_id)
void SetupEvent(CDungeonMap *map, int mode)
CDungeonEvent * SearchSlot()
void SearchDataSwitch(int script_no, int enable)
CDungeonEventData * SearchDataSlotPos(float *position)
MAP_CELL cells[400]
CDungeonParts parts[72]
float frame_turn[6]
CFrame * frame[6]
@ MAP_PARTS_NONE
sceVu0FVECTOR pos
s32 direction