DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
editarea.cpp
1#include "editarea.hpp"
2
3#include <cstring>
4
5#include "collision.hpp"
6#include "editground.hpp"
7#include "frame.hpp"
8#include "framevu1.hpp"
9#include "mapparts.hpp"
10#include "mdt.hpp"
11#include "mglib.hpp"
12#include "rect.hpp"
13#include "vector3.hpp"
14#include "visualvu1.hpp"
15
19// clang-format off
20enum MapConnectionAttribute {
21 MAP_CONNECTION_ROAD = 1,
22 MAP_CONNECTION_RIVER = 2
23};
24
25// clang-format on
26
30// clang-format off
31enum MapConnectionShape {
32 MAP_CONNECTION_CORNER = 1,
33 MAP_CONNECTION_STRAIGHT = 2,
34 MAP_CONNECTION_THREE_WAY = 3,
35 MAP_CONNECTION_FOUR_WAY = 4,
36 MAP_CONNECTION_ISOLATED = 5,
37 MAP_CONNECTION_END = 6
38};
39
40// clang-format on
41
48 struct {
51 } attr;
52};
53
54void CEditArea::SetSize(s32 width, s32 height, float unit_size, float unit_alt) {
55 this->width = width;
56 this->height = height;
57 this->unit_size = unit_size;
58 this->unit_alt = unit_alt;
59}
60
61void CEditArea::GetPos(CVector3_i_ *position, float x, float y, float z) {
62 x -= offset_x;
63 y -= offset_y;
64 z -= offset_z;
65 x += 0.1f;
66 z += 0.1f;
67 position->x = (int) (x / unit_size);
68 position->y = (int) (y / unit_alt);
69 position->z = (int) (z / unit_size);
70}
71
72void CEditArea::GetPos(CVector3_f_ *position, s32 x, s32 y, s32 z) {
73 position->x = this->offset_x + ((float) x * this->unit_size);
74 position->y = this->offset_y + ((float) y * this->unit_alt);
75 position->z = this->offset_z + ((float) z * this->unit_size);
76}
77
78void CEditArea::SetPartsNo(int x, int y, int parts_no) {
79 if (x < 0 || x >= width) {
80 return;
81 }
82
83 if (y < 0 || y >= height) {
84 return;
85 }
86
87 grid[x][y].parts_no = parts_no;
88}
89
90void CEditArea::SetPartsID(int x, int y, int parts_id) {
91 if (x < 0 || x >= width) {
92 return;
93 }
94
95 if (y < 0 || y >= height) {
96 return;
97 }
98
99 grid[x][y].parts_id = parts_id;
100}
101
102void CEditArea::SetPartsExtra(int x, int y, int parts_extra) {
103 if (x < 0 || x >= width) {
104 return;
105 }
106
107 if (y < 0 || y >= height) {
108 return;
109 }
110
111 grid[x][y].parts_extra = parts_extra;
112}
113
114void CEditArea::SetCode(int x, int y, int code) {
115 if (x < 0 || x >= width) {
116 return;
117 }
118
119 if (y < 0 || y >= height) {
120 return;
121 }
122
123 grid[x][y].code = code;
124}
125
126int CEditArea::GetPartsID(int x, int y) {
127 if (x < 0 || x >= width) {
128 return -1;
129 }
130
131 if (y < 0 || y >= height) {
132 return -1;
133 }
134
135 return grid[x][y].parts_id;
136}
137
138int CEditArea::GetCode(int x, int y) {
139 if (x < 0 || x >= width) {
140 return -1;
141 }
142
143 if (y < 0 || y >= height) {
144 return -1;
145 }
146
147 return grid[x][y].code;
148}
149
150void CEditArea::SetAlt(int x, int y, int altitude) {
151 if (x < 0 || x >= width) {
152 return;
153 }
154
155 if (y < 0 || y >= height) {
156 return;
157 }
158
159 if (altitude < 0) {
160 altitude = 0;
161 }
162
163 if (altitude >= 128) {
164 altitude = 127;
165 }
166
167 grid[x][y].altitude = altitude;
168}
169
170int CEditArea::GetAlt_i(int x, int y) {
171 if (x < 0 || x >= width) {
172 return 0;
173 }
174
175 if (y < 0 || y >= height) {
176 return 0;
177 }
178
179 return grid[x][y].altitude;
180}
181
182float CEditArea::GetAlt(int x, int y) {
183 if (x < 0 || x >= width) {
184 return 0.0f;
185 }
186
187 if (y < 0 || y >= height) {
188 return 0.0f;
189 }
190
191 return offset_y + static_cast<float>(grid[x][y].altitude) * unit_alt;
192}
193
194float CEditArea::GetAlt(float x, float y, float z) {
195 CVector3_i_ position;
196 GetPos(&position, x, y, z);
197 return GetAlt(position.x, position.z);
198}
199
200int CEditArea::GetAlt_i(float x, float y, float z) {
201 CVector3_i_ position;
202 GetPos(&position, x, y, z);
203 return GetAlt_i(position.x, position.z);
204}
205
206int CEditArea::GetPartsExtra(int x, int y) {
207 switch (map_no) {
208 case TOWN_MATATAKI:
209 switch (area_id) {
210 case 0:
211 if (x == 5 && y == -1) {
212 return MAP_CONNECTION_RIVER;
213 }
214
215 if (x == 2 && y == 8) {
216 return MAP_CONNECTION_RIVER;
217 }
218
219 break;
220 case 1:
221 if (x == 3 && y == 6) {
222 return MAP_CONNECTION_RIVER;
223 }
224
225 if (x == 12 && y == 3) {
226 return MAP_CONNECTION_RIVER;
227 }
228
229 break;
230 case 2:
231 if (x == 4 && y == -1) {
232 return MAP_CONNECTION_RIVER;
233 }
234
235 if (x == 3 && y == 8) {
236 return MAP_CONNECTION_RIVER;
237 }
238
239 break;
240 }
241 }
242
243 if (x < 0 || x >= width) {
244 return -1;
245 }
246
247 if (y < 0 || y >= height) {
248 return -1;
249 }
250
251 return grid[x][y].parts_extra;
252}
253
254int CEditArea::SetMapParts(int parts_id, CMapParts *parts, float x, float y, float z, int rot_y) {
255 CVector3_i_ position;
256 int i;
257 int j;
258 CMapParts *target = &parts[parts_id];
259 target->unit_size = unit_size;
260 int parts_width = target->GetWidth();
261 int parts_height = target->GetHeight();
262 GetPos(&position, x, y, z);
263
264 for (i = 0; i < parts_width; i++) {
265 for (j = 0; j < parts_height; j++) {
266 int half_width = parts_width >> 1;
267 int cell_x = i + (position.x - half_width);
268 int half_height = parts_height >> 1;
269 int cell_y = j + (position.z - half_height);
270 int cell_code = target->GetInfoData(i, j);
271
272 if (cell_code != 0) {
273 SetCode(cell_x, cell_y, cell_code);
274
275 if (cell_code < 0x80) {
276 AddAlt(cell_x, cell_y, cell_code);
277 } else {
278 SetPartsNo(cell_x, cell_y, target->handle);
279 SetPartsID(cell_x, cell_y, parts_id);
280 SetPartsExtra(cell_x, cell_y, target->subtype);
281 }
282 }
283 }
284 }
285
286 grid_redraw = 1;
287 return 1;
288}
289
290int CEditArea::DeleteMapParts(int parts_no, CMapParts *parts, float x, float y, float z) {
291 CVector3_i_ position;
292 GetPos(&position, x, y, z);
293
294 if (parts_no < 0) {
295 return 0;
296 }
297
298 CMapParts *target = &parts[parts_no];
299 int parts_width = target->GetWidth();
300 int parts_height = target->GetHeight();
301
302 for (int i = 0; i < parts_width; i++) {
303 for (int j = 0; j < parts_height; j++) {
304 int half_width = parts_width >> 1;
305 int cell_x = i + (position.x - half_width);
306 int half_height = parts_height >> 1;
307 int cell_y = j + (position.z - half_height);
308 s16 cell_code = target->GetInfoData(i, j);
309
310 if (cell_code != 0) {
311 if (cell_code < 0x80) {
312 int occupant = GetPartsID(cell_x, cell_y);
313 AddAlt(cell_x, cell_y, -cell_code);
314
315 if (occupant >= 0) {
316 CMapParts *occupant_parts = &parts[occupant];
317 sceVu0FVECTOR occupant_position;
318 occupant_parts->GetPosition(occupant_position);
319 occupant_position[1] = GetAlt(cell_x, cell_y);
320 occupant_parts->SetPosition(occupant_position);
321 }
322 } else {
323 SetPartsNo(cell_x, cell_y, -1);
324 SetPartsID(cell_x, cell_y, -1);
325 SetPartsExtra(cell_x, cell_y, -1);
326 SetCode(cell_x, cell_y, -1);
327 }
328 }
329 }
330 }
331
332 grid_redraw = 1;
333 return 1;
334}
335
336int CEditArea::SetRiverParts(int x, int y) {
337 int neighbors[4];
338 int negative_z, positive_x, positive_z, negative_x;
339 int count, shape, direction, i;
340
341 if ((x < 0) || (x >= this->width)) {
342 return -1;
343 }
344
345 if ((y < 0) || (y >= this->height)) {
346 return -1;
347 }
348
349 if (GetPartsExtra(x, y) != MAP_CONNECTION_RIVER) {
350 return -1;
351 }
352
353 negative_z = GetPartsExtra(x, y - 1);
354 positive_x = GetPartsExtra(x + 1, y);
355 positive_z = GetPartsExtra(x, y + 1);
356 negative_x = GetPartsExtra(x - 1, y);
357 neighbors[0] = negative_z == MAP_CONNECTION_RIVER;
358 neighbors[1] = positive_x == MAP_CONNECTION_RIVER;
359 neighbors[2] = positive_z == MAP_CONNECTION_RIVER;
360 neighbors[3] = negative_x == MAP_CONNECTION_RIVER;
361 neighbors[0] = neighbors[0] || negative_z == MAP_PARTS_SUBTYPE_BRIDGE;
362 neighbors[1] = neighbors[1] || positive_x == MAP_PARTS_SUBTYPE_BRIDGE;
363 neighbors[2] = neighbors[2] || positive_z == MAP_PARTS_SUBTYPE_BRIDGE;
364 neighbors[3] = neighbors[3] || negative_x == MAP_PARTS_SUBTYPE_BRIDGE;
365 neighbors[0] = neighbors[0] || negative_z == MAP_PARTS_SUBTYPE_ON_RIVER;
366 neighbors[1] = neighbors[1] || positive_x == MAP_PARTS_SUBTYPE_ON_RIVER;
367 neighbors[2] = neighbors[2] || positive_z == MAP_PARTS_SUBTYPE_ON_RIVER;
368 neighbors[3] = neighbors[3] || negative_x == MAP_PARTS_SUBTYPE_ON_RIVER;
369 count = 0;
370
371 for (i = 0; i < 4; i++) {
372 count += neighbors[i];
373 }
374
375 shape = -1;
376 direction = 0;
377
378 if (count == 4) {
379 shape = MAP_CONNECTION_FOUR_WAY;
380 }
381
382 if (count == 3) {
383 shape = MAP_CONNECTION_THREE_WAY;
384
385 if (neighbors[0] == 0) {
386 direction = 3;
387 }
388
389 if (neighbors[1] == 0) {
390 direction = 2;
391 }
392
393 if (neighbors[2] == 0) {
394 direction = 1;
395 }
396
397 if (neighbors[3] == 0) {
398 direction = 0;
399 }
400 }
401
402 if (count == 2) {
403 if (((neighbors[0] != 0) && (neighbors[2] != 0)) || ((neighbors[1] != 0) && (neighbors[3] != 0))) {
404 shape = MAP_CONNECTION_STRAIGHT;
405
406 if (neighbors[0] != 0) {
407 direction = 0;
408 }
409
410 if (neighbors[1] != 0) {
411 direction = 1;
412 }
413 } else {
414 shape = MAP_CONNECTION_CORNER;
415
416 if ((neighbors[1] != 0) && (neighbors[2] != 0)) {
417 direction = 3;
418 }
419
420 if ((neighbors[2] != 0) && (neighbors[3] != 0)) {
421 direction = 2;
422 }
423
424 if ((neighbors[3] != 0) && (neighbors[0] != 0)) {
425 direction = 1;
426 }
427
428 if ((neighbors[0] != 0) && (neighbors[1] != 0)) {
429 direction = 0;
430 }
431 }
432 }
433
434 if (count == 1) {
435 shape = MAP_CONNECTION_END;
436
437 if (neighbors[0] != 0) {
438 direction = 2;
439 }
440
441 if (neighbors[1] != 0) {
442 direction = 1;
443 }
444
445 if (neighbors[2] != 0) {
446 direction = 0;
447 }
448
449 if (neighbors[3] != 0) {
450 direction = 3;
451 }
452 }
453
454 if (count == 0) {
455 shape = MAP_CONNECTION_ISOLATED;
456 }
457
458 if (shape < 0) {
459 return -1;
460 }
461
462 shape = (shape << 4) & 0xFF0;
463 return shape | (direction & 0xF);
464}
465
466int CEditArea::SetRoadParts(int x, int y) {
467 int neighbors[4];
468 int count;
469 int shape;
470 int direction;
471 int i;
472
473 if ((x < 0) || (x >= this->width)) {
474 return -1;
475 }
476
477 if ((y < 0) || (y >= this->height)) {
478 return -1;
479 }
480
481 if (GetPartsExtra(x, y) != MAP_CONNECTION_ROAD) {
482 return -1;
483 }
484
485 neighbors[0] = GetPartsExtra(x, y - 1) == MAP_CONNECTION_ROAD;
486 neighbors[1] = GetPartsExtra(x + 1, y) == MAP_CONNECTION_ROAD;
487 neighbors[2] = GetPartsExtra(x, y + 1) == MAP_CONNECTION_ROAD;
488 neighbors[3] = GetPartsExtra(x - 1, y) == MAP_CONNECTION_ROAD;
489 count = 0;
490
491 for (i = 0; i < 4; i++) {
492 count += neighbors[i];
493 }
494
495 shape = -1;
496 direction = 0;
497
498 if (count == 4) {
499 shape = MAP_CONNECTION_FOUR_WAY;
500 }
501
502 if (count == 3) {
503 shape = MAP_CONNECTION_THREE_WAY;
504
505 if (neighbors[0] == 0) {
506 direction = 0;
507 }
508
509 if (neighbors[1] == 0) {
510 direction = 3;
511 }
512
513 if (neighbors[2] == 0) {
514 direction = 2;
515 }
516
517 if (neighbors[3] == 0) {
518 direction = 1;
519 }
520 }
521
522 if (count == 2) {
523 if (((neighbors[0] != 0) && (neighbors[2] != 0)) || ((neighbors[1] != 0) && (neighbors[3] != 0))) {
524 shape = MAP_CONNECTION_STRAIGHT;
525
526 if (neighbors[0] != 0) {
527 direction = 0;
528 }
529
530 if (neighbors[1] != 0) {
531 direction = 1;
532 }
533 } else {
534 shape = MAP_CONNECTION_CORNER;
535
536 if ((neighbors[1] != 0) && (neighbors[2] != 0)) {
537 direction = 0;
538 }
539
540 if ((neighbors[2] != 0) && (neighbors[3] != 0)) {
541 direction = 3;
542 }
543
544 if ((neighbors[3] != 0) && (neighbors[0] != 0)) {
545 direction = 2;
546 }
547
548 if ((neighbors[0] != 0) && (neighbors[1] != 0)) {
549 direction = 1;
550 }
551 }
552 }
553
554 if (count == 1) {
555 shape = MAP_CONNECTION_END;
556
557 if (neighbors[0] != 0) {
558 direction = 2;
559 }
560
561 if (neighbors[1] != 0) {
562 direction = 1;
563 }
564
565 if (neighbors[2] != 0) {
566 direction = 0;
567 }
568
569 if (neighbors[3] != 0) {
570 direction = 3;
571 }
572 }
573
574 if (count == 0) {
575 shape = MAP_CONNECTION_ISOLATED;
576 }
577
578 if (shape < 0) {
579 return -1;
580 }
581
582 shape = (shape << 4) & 0xFF0;
583 return shape | (direction & 0xF);
584}
585
586int CEditArea::SearchPartsID(float x, float y, float z) {
587 CVector3_i_ position;
588 GetPos(&position, x, y, z);
589 return grid[position.x][position.z].parts_id;
590}
591
592int CEditArea::SearchPartsExtra(float x, float y, float z) {
593 CVector3_i_ position;
594 GetPos(&position, x, y, z);
595 return GetPartsExtra(position.x, position.z);
596}
597
598void CEditArea::GetGrid(CVector3_f_ *snapped, float x, float y, float z) {
599 CVector3_i_ cell;
600 GetPos(&cell, x, y, z);
601 GetPos(snapped, cell.x, cell.y, cell.z);
602}
603
605 if (grid_frame == NULL) {
606 return;
607 }
608
609 CVisualVu1 *visual = grid_frame->GetVisual();
610
611 if (visual == NULL) {
612 return;
613 }
614
615 MDT_HEADER *model = (MDT_HEADER *) visual->GetMDTDataAddress();
616
617 if (model == NULL) {
618 return;
619 }
620
621 sceVu0FVECTOR *vertices = (sceVu0FVECTOR *) ((char *) model + model->vertex_ofs);
622 int y;
623 int x;
624
625 for (x = 0; x < width; x++) {
626 for (y = 0; y < height; y++) {
627 int index = x + y * width;
628 index *= 4;
629
630 if (GetCode(x, y) == 0x81) {
631 sceVu0CopyVector(vertices[index + 1], vertices[index]);
632 sceVu0CopyVector(vertices[index + 2], vertices[index]);
633 sceVu0CopyVector(vertices[index + 3], vertices[index]);
634 } else {
635 vertices[index + 1][0] = 1.002f * unit_size + vertices[index][0];
636 vertices[index + 1][2] = vertices[index][2];
637 vertices[index + 2][0] = vertices[index][0];
638 vertices[index + 2][2] = 1.002f * unit_size + vertices[index][2];
639 vertices[index + 3][0] = 1.002f * unit_size + vertices[index][0];
640 vertices[index + 3][2] = 1.002f * unit_size + vertices[index][2];
641 }
642 }
643 }
644
646}
647
649 memcpy(box, &this->parts_box, sizeof(CBoxVu0));
650}
651
653 CVector3_f_ position;
654 int min_x = 0;
655 int max_x = 0;
656 int max_z = 0;
657 int min_z = 0;
658
659 for (int x = 0; x < width; x++) {
660 for (int z = 0; z < height; z++) {
661 if (grid[x][z].parts_no >= 0 && grid[x][z].parts_id >= 0) {
662 if (max_x < x) {
663 max_x = x;
664 }
665
666 if (max_z < z) {
667 max_z = z;
668 }
669
670 if (min_x > x) {
671 max_x = x;
672 }
673
674 if (z < min_z) {
675 min_z = z;
676 }
677 }
678 }
679 }
680
681 GetPos(&position, max_x, 0, max_z);
682 parts_box.max[0] = position.x + unit_size;
683 parts_box.max[1] = position.y;
684 parts_box.max[2] = position.z + unit_size;
685 parts_box.max[3] = 1.0f;
686 GetPos(&position, 0, 0, min_z);
687 parts_box.min[0] = position.x;
688 parts_box.min[1] = position.y;
689 parts_box.min[2] = position.z;
690 parts_box.min[3] = 1.0f;
691}
692
693int CEditArea::CheckArea(float x, float y, float z) {
694 if (x < offset_x) {
695 return 0;
696 }
697
698 if (z < offset_z) {
699 return 0;
700 }
701
702 if (x > offset_x + unit_size * static_cast<float>(width)) {
703 return 0;
704 }
705
706 if (z > offset_z + unit_size * static_cast<float>(height)) {
707 return 0;
708 }
709
710 return 1;
711}
712
713int CEditArea::CheckAreaRect(float x, float y, float z, int rect_width, int rect_height) {
714 CVector3_i_ position;
715 GetPos(&position, x, y, z);
716 int bottom;
717 int right;
718 int left;
719 int top;
720 int half_width = rect_width >> 1;
721 left = position.x - half_width;
722 right = rect_width + left - 1;
723 int half_height = rect_height >> 1;
724 top = position.z - half_height;
725 bottom = rect_height + top - 1;
726
727 if (left < 0 || top < 0) {
728 return 0;
729 }
730
731 if (right >= this->width || bottom >= this->height) {
732 return 0;
733 }
734
735 return 1;
736}
737
738int CEditArea::CheckParts(CMapParts *parts, float x, float y, float z, int rotation) {
739 if (parts->info == NULL) {
740 return 0;
741 }
742
743 CVector3_i_ position;
744 GetPos(&position, x, y, z);
745
746 if (parts->subtype == MAP_PARTS_SUBTYPE_ON_RIVER) {
747 if (GetPartsExtra(position.x, position.z) != MAP_PARTS_SUBTYPE_RIVER) {
748 return 0;
749 }
750
751 return 1;
752 }
753
754 parts->SetRotY(rotation);
755 int i;
756 int j;
757 int part_width = parts->GetWidth();
758 int part_height = parts->GetHeight();
759
760 for (i = 0; i < part_width; i++) {
761 for (j = 0; j < part_height; j++) {
762 int half_width = part_width >> 1;
763 int cell_x = i + (position.x - half_width);
764 int half_height = part_height >> 1;
765 int cell_y = j + (position.z - half_height);
766
767 if (cell_x < 0 || cell_x >= this->width) {
768 return 0;
769 }
770
771 if (cell_y < 0 || cell_y >= this->height) {
772 return 0;
773 }
774
775 s16 cell_code = parts->GetInfoData(i, j);
776
777 if (cell_code != 0) {
778 int occupant = grid[cell_x][cell_y].parts_no;
779 int extra = GetPartsExtra(cell_x, cell_y);
780
781 if ((parts->subtype == MAP_PARTS_SUBTYPE_ROAD || extra != MAP_PARTS_SUBTYPE_ROAD) && occupant >= 0) {
782 return 0;
783 }
784 }
785 }
786 }
787
788 if (parts->subtype == MAP_PARTS_SUBTYPE_RIVER) {
789 if (GetAlt_i(position.x, position.z) > 0) {
790 return 0;
791 }
792
793 int neighbors[4];
794 neighbors[0] = GetPartsExtra(position.x + 1, position.z);
795 neighbors[1] = GetPartsExtra(position.x - 1, position.z);
796 neighbors[2] = GetPartsExtra(position.x, position.z - 1);
797 neighbors[3] = GetPartsExtra(position.x, position.z + 1);
798
799 for (int i = 0; i < 4; i++) {
800 int extra = neighbors[i];
801
802 if (extra == MAP_PARTS_SUBTYPE_BRIDGE) {
803 return 0;
804 }
805
806 if (extra == MAP_PARTS_SUBTYPE_LAKE) {
807 return 0;
808 }
809
810 if (extra == MAP_PARTS_SUBTYPE_ON_RIVER) {
811 return 0;
812 }
813
814 if (extra == MAP_PARTS_SUBTYPE_ON_RIVER) {
815 return 0;
816 }
817 }
818 }
819
820 if (parts->subtype == MAP_PARTS_SUBTYPE_LAKE) {
821 if (GetAlt_i(position.x, position.z) > 0) {
822 return 0;
823 }
824
825 for (int i = -1; i < part_width + 1; i++) {
826 for (int j = -1; j < part_height + 1; j++) {
827 int half_width = part_width >> 1;
828 int cell_x = i + (position.x - half_width);
829 int extra = GetPartsExtra(cell_x, j + (position.z - (part_height >> 1)));
830
831 if (extra == MAP_PARTS_SUBTYPE_BRIDGE) {
832 return 0;
833 }
834
835 if (extra == MAP_PARTS_SUBTYPE_RIVER) {
836 return 0;
837 }
838
839 if (extra == MAP_PARTS_SUBTYPE_ON_RIVER) {
840 return 0;
841 }
842 }
843 }
844 }
845
846 return 1;
847}
848
849int CEditArea::PickUpPoly(CCPoly *polygons, float x, float y, float z) {
850 CVector3_i_ position;
851
852 if (CheckArea(x, y, z) == 0) {
853 return 0;
854 }
855
856 GetPos(&position, x, y, z);
857 CRect_i_ rect(position.x - 1, position.z - 1, 2, 2);
858 return PickUpPoly(polygons, rect);
859}
860
862 static int sound[] = {0, 1, 0, 14, 2};
863 int count = 0;
864
865 for (int x = rect.x; x < rect.x + rect.width; x++) {
866 for (int y = rect.y; y < rect.y + rect.height; y++) {
867 if (x >= 0 && x < width && y >= 0 && y < height && GetCode(x, y) != 0x81) {
868 CVector3_f_ position;
869 sceVu0FVECTOR corner[4];
870 sceVu0FVECTOR normal;
871 GridPolyInfo surface;
872 GetPos(&position, x, 0, y);
873 memset(&surface, 0, sizeof(surface));
874 surface.attr.foot_sound = sound[map_no];
875 corner[0][0] = position.x - 0.01f * unit_size;
876 corner[0][1] = position.y;
877 corner[0][2] = position.z - 0.01f * unit_size;
878 corner[0][3] = 1.0f;
879 sceVu0CopyVector(corner[1], corner[0]);
880 sceVu0CopyVector(corner[2], corner[0]);
881 sceVu0CopyVector(corner[3], corner[0]);
882 corner[1][0] = 0.02f * unit_size + (corner[0][0] + unit_size);
883 corner[2][2] = 0.02f * unit_size + (corner[0][2] + unit_size);
884 corner[3][0] = 0.02f * unit_size + (corner[0][0] + unit_size);
885 corner[3][2] = 0.02f * unit_size + (corner[0][2] + unit_size);
886 normal[0] = 0.0f;
887 normal[1] = 1.0f;
888 normal[2] = 0.0f;
889 normal[3] = 0.0f;
890 sceVu0CopyVector(polygons->vertex[0], corner[0]);
891 sceVu0CopyVector(polygons->vertex[1], corner[1]);
892 sceVu0CopyVector(polygons->vertex[2], corner[2]);
893 sceVu0CopyVector(polygons->normal, normal);
894 polygons->info = surface.info;
895 polygons++;
896 sceVu0CopyVector(polygons->vertex[0], corner[2]);
897 sceVu0CopyVector(polygons->vertex[1], corner[1]);
898 sceVu0CopyVector(polygons->vertex[2], corner[3]);
899 sceVu0CopyVector(polygons->normal, normal);
900 polygons->info = surface.info;
901 polygons++;
902 count += 2;
903 }
904 }
905 }
906
907 return count;
908}
909
911 int left, top;
912 CVector3_i_ position;
913 GetPos(&position, box.min[0], box.min[1], box.min[2]);
914 left = position.x;
915 top = position.z;
916 GetPos(&position, box.max[0], box.max[1], box.max[2]);
917 int right = position.x;
918 int bottom = position.z;
919 CRect_i_ rect;
920 rect.x = left - 1;
921 rect.y = top - 1;
922 rect.width = right - left + 2;
923 rect.height = bottom - top + 2;
924 return PickUpPoly(polygons, rect);
925}
926
927int CEditArea::GetPartsRect(CRect_i_ &rect, int *parts_ids, int capacity) {
928 int x, y;
929 int count = 0;
930
931 for (x = rect.x; x < rect.x + rect.width; x++) {
932 for (y = rect.y; y < rect.y + rect.height; y++) {
933 if (count >= capacity) {
934 break;
935 }
936
937 int parts_id = GetPartsID(x, y);
938
939 if (parts_id >= 0) {
940 if (count == 0) {
941 parts_ids[count++] = parts_id;
942 } else {
943 int found = 0;
944
945 for (int i = 0; i < count; i++) {
946 if (parts_id == parts_ids[i]) {
947 found = 1;
948 }
949 }
950
951 if (!found) {
952 parts_ids[count++] = parts_id;
953 }
954 }
955 }
956 }
957 }
958
959 return count;
960}
961
963 for (int x = 0; x < 16; x++) {
964 for (int y = 0; y < 16; y++) {
965 chain_work[x][y] = 0;
966 }
967 }
968}
969
970int CEditArea::CheckRiverChain(int x, int y, int target_x, int target_y) {
971 if (x < 0 || y < 0 || x >= 16 || y >= 16) {
972 return 0;
973 }
974
975 if (chain_work[x][y] != 0) {
976 return 0;
977 }
978
979 chain_work[x][y] = 1;
980 static int ext = 0;
981 ext = GetPartsExtra(x, y);
982
983 if (ext != MAP_CONNECTION_RIVER && ext != MAP_PARTS_SUBTYPE_BRIDGE && ext != MAP_PARTS_SUBTYPE_ON_RIVER) {
984 return 0;
985 }
986
987 if (x == target_x && y == target_y) {
988 return 1;
989 }
990
991 if (CheckRiverChain(x - 1, y, target_x, target_y)) {
992 return 1;
993 }
994
995 if (CheckRiverChain(x + 1, y, target_x, target_y)) {
996 return 1;
997 }
998
999 if (CheckRiverChain(x, y - 1, target_x, target_y)) {
1000 return 1;
1001 }
1002
1003 return CheckRiverChain(x, y + 1, target_x, target_y) ? 1 : 0;
1004}
1005
1007 sceVu0FVECTOR position;
1008
1010
1011 if (grid_redraw != 0) {
1013 }
1014
1015 if (grid_redraw_count > 0) {
1016 RemakeGrid();
1017
1018 if (grid_frame != NULL) {
1019 grid_frame->attr.cull_enable = false;
1020 }
1021 } else {
1022 if (grid_frame != NULL) {
1023 grid_frame->attr.cull_enable = true;
1024 }
1025 }
1026
1027 grid_redraw = 0;
1028
1029 if (grid_redraw_count < 0) {
1031 }
1032
1033 position[0] = offset_x;
1034 position[1] = offset_y;
1035 position[2] = offset_z;
1036 grid_frame->SetPosition(position);
1037 MGDraw(grid_frame);
1038}
1039
1041 for (int x = 0; x < width; x++) {
1042 for (int y = 0; y < height; y++) {
1043 grid[x][y].parts_no = -1;
1044 grid[x][y].altitude = 0;
1045 grid[x][y].spare = 0;
1046 grid[x][y].parts_id = -1;
1047 grid[x][y].code = -1;
1048 grid[x][y].parts_extra = -1;
1049 grid[x][y].spare_index = -1;
1050 }
1051 }
1052
1053 grid_redraw = 1;
1055}
1056
1058 float zero = 0.0f;
1059 SetOffset(zero, zero, zero);
1060 SetSize(16, 16, 1.0f, 1.0f);
1061 grid_frame = NULL;
1062 Clear();
1063 map_no = 0;
1064 area_id = 0;
1065}
1066
1067void CEditArea::SetMapInfo(s32 map_no, s32 area_id) {
1068 this->map_no = map_no;
1069 this->area_id = area_id;
1070}
1071
1073 return this->map_no;
1074}
1075
1077 return this->area_id;
1078}
1079
1081 this->grid_frame = frame;
1082}
1083
1085 return this->grid_frame;
1086}
1087
1088void CEditArea::SetOffset(float x, float y, float z) {
1089 this->offset_x = x;
1090 this->offset_y = y;
1091 this->offset_z = z;
1092}
1093
1094void CEditArea::GetOffset(float *offset) {
1095 offset[0] = offset_x;
1096 offset[1] = offset_y;
1097 offset[2] = offset_z;
1098}
1099
1101 return this->width;
1102}
1103
1105 return this->height;
1106}
1107
1108void CEditArea::AddAlt(int x, int y, int altitude_delta) {
1109 SetAlt(x, y, GetAlt_i(x, y) + altitude_delta);
1110}
1111
1113 return this->unit_size;
1114}
1115
1117 return this->unit_alt;
1118}
1119
sceVu0FVECTOR min
Definition collision.hpp:29
sceVu0FVECTOR max
Definition collision.hpp:28
CCPolyInfo info
Definition collision.hpp:52
sceVu0FVECTOR normal
Definition collision.hpp:49
sceVu0FVECTOR vertex[3]
Definition collision.hpp:48
void SetCode(int x, int y, int code)
Definition editarea.cpp:114
int GetMapNo()
void SetAlt(int x, int y, int altitude)
Definition editarea.cpp:150
void SetMapInfo(int map_no, int area_id)
int SearchPartsID(float x, float y, float z)
Definition editarea.cpp:586
void GetOffset(float *offset)
void Clear()
float GetAlt(int x, int y)
Definition editarea.cpp:182
void GetPartsBox(CBoxVu0 *box)
Definition editarea.cpp:648
void SetOffset(float x, float y, float z)
void DrawGrid()
float unit_alt
Definition editarea.hpp:46
void SetGridFrame(CFrameVu1 *frame)
void ChainWorkClear()
Definition editarea.cpp:962
int GetAlt_i(int x, int y)
Definition editarea.cpp:170
int DeleteMapParts(int parts_no, CMapParts *parts, float x, float y, float z)
Definition editarea.cpp:290
CFrameVu1 * GetGridFrame()
CFrameVu1 * grid_frame
Definition editarea.hpp:49
void RemakeGrid()
Definition editarea.cpp:604
int GetPartsExtra(int x, int y)
Definition editarea.cpp:206
void MakePartsBox()
Definition editarea.cpp:652
int GetHeight()
void SetSize(int width, int height, float unit_size, float unit_alt)
Definition editarea.cpp:54
int CheckAreaRect(float x, float y, float z, int rect_width, int rect_height)
Definition editarea.cpp:713
void SetPartsExtra(int x, int y, int parts_extra)
Definition editarea.cpp:102
int GetWidth()
int SearchPartsExtra(float x, float y, float z)
Definition editarea.cpp:592
int grid_redraw
Definition editarea.hpp:52
int PickUpPoly(CCPoly *polygons, float x, float y, float z)
Definition editarea.cpp:849
int chain_work[16][16]
Definition editarea.hpp:48
float GetUnitAlt()
int CheckRiverChain(int x, int y, int target_x, int target_y)
Definition editarea.cpp:970
int SetRiverParts(int x, int y)
Definition editarea.cpp:336
float unit_size
Definition editarea.hpp:45
CBoxVu0 parts_box
Definition editarea.hpp:51
int GetCode(int x, int y)
Definition editarea.cpp:138
float GetUnitSize()
int GetPartsID(int x, int y)
Definition editarea.cpp:126
void Initialize()
int SetMapParts(int parts_id, CMapParts *parts, float x, float y, float z, int rot_y)
Definition editarea.cpp:254
void SetPartsNo(int x, int y, int parts_no)
Definition editarea.cpp:78
float offset_y
Definition editarea.hpp:42
int GetPartsRect(CRect_i_ &rect, int *parts_ids, int capacity)
Definition editarea.cpp:927
int GetAreaID()
CEditAreaCell grid[16][16]
Definition editarea.hpp:47
void SetPartsID(int x, int y, int parts_id)
Definition editarea.cpp:90
float offset_x
Definition editarea.hpp:41
int CheckArea(float x, float y, float z)
Definition editarea.cpp:693
int grid_redraw_count
Definition editarea.hpp:53
void GetPos(CVector3_i_ *position, float x, float y, float z)
Definition editarea.cpp:61
void GetGrid(CVector3_f_ *snapped, float x, float y, float z)
Definition editarea.cpp:598
int CheckParts(CMapParts *parts, float x, float y, float z, int rotation)
Definition editarea.cpp:738
float offset_z
Definition editarea.hpp:43
int area_id
Definition editarea.hpp:37
int SetRoadParts(int x, int y)
Definition editarea.cpp:466
void AddAlt(int x, int y, int altitude_delta)
char remake_pending
Definition frame.hpp:31
char cull_enable
Definition frame.hpp:40
CVisualVu1 * GetVisual()
Definition frame.cpp:1337
CFrameAttr attr
Definition frame.hpp:65
int handle
Definition op_b.cpp:96
virtual void SetPosition(float *position)
Definition mapparts.cpp:20
int GetHeight()
Definition mapparts.cpp:111
void SetRotY(int direction)
Definition mapparts.cpp:36
s32 subtype
Definition mapparts.hpp:61
int GetWidth()
Definition mapparts.cpp:94
float unit_size
Definition mapparts.hpp:69
void GetPosition(float *out_position)
Definition mapparts.cpp:16
int GetInfoData(int x, int y)
Definition mapparts.cpp:127
EDITPARTS_INFO * info
Definition mapparts.hpp:57
s32 x
Definition rect.hpp:18
s32 width
Definition rect.hpp:20
s32 height
Definition rect.hpp:21
s32 y
Definition rect.hpp:19
@ MAP_PARTS_SUBTYPE_RIVER
Definition mapparts.hpp:20
@ MAP_PARTS_SUBTYPE_LAKE
Definition mapparts.hpp:22
@ MAP_PARTS_SUBTYPE_ROAD
Definition mapparts.hpp:19
@ MAP_PARTS_SUBTYPE_ON_RIVER
Definition mapparts.hpp:23
@ MAP_PARTS_SUBTYPE_BRIDGE
Definition mapparts.hpp:21
int vertex_ofs
Definition mdt.hpp:14
struct GridPolyInfo::@1 attr
CCPolyInfo info
Definition editarea.cpp:46