1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 1008
5#pragma argument_flag_ones 69, 109, 232, 233, 278, 307, 308, 353, 409, 424
6#pragma argument_flag_ones 426, 480, 481, 497, 498, 499, 959
20#include "dun/gameloop.hpp"
23#include "frameattr.hpp"
24#include "framevu1.hpp"
30#include "textureanime.hpp"
31#include "userstatus.hpp"
38 BUILD_CELL_ROOM = 0x001,
39 BUILD_CELL_CORRIDOR = 0x002,
40 BUILD_CELL_DOOR = 0x004,
41 BUILD_CELL_HEAL_SPRING = 0x008,
42 BUILD_CELL_DIVIDING_WALL = 0x010,
43 BUILD_CELL_DIVIDING_DOOR = 0x020,
44 BUILD_CELL_PILLAR = 0x040,
45 BUILD_CELL_STAIR_DOWN = 0x080,
46 BUILD_CELL_STAIR_UP = 0x100,
47 BUILD_CELL_URA_ENTRANCE = 0x200,
48 BUILD_CELL_ROOM_LINK = 0x400,
76s32 chainTableDoor[4][3] = {
78 {13, MAP_PARTS_ROOM_DOOR_EAST, 0},
79 {7, MAP_PARTS_ROOM_DOOR_SOUTH, 0},
80 {11, MAP_PARTS_ROOM_DOOR_WEST, 0},
84s32 chainTableRoad[15][3] = {
103s32 chainTableRoom[8][3] = {
104 {1, MAP_PARTS_ROOM_WALL_NORTH, 0},
105 {2, MAP_PARTS_ROOM_WALL_EAST, 0},
106 {8, MAP_PARTS_ROOM_WALL_SOUTH, 0},
107 {4, MAP_PARTS_ROOM_WALL_WEST, 0},
108 {5, MAP_PARTS_ROOM_CORNER_NORTH_WEST, 0},
109 {3, MAP_PARTS_ROOM_CORNER_NORTH_EAST, 0},
110 {10, MAP_PARTS_ROOM_CORNER_SOUTH_EAST, 0},
111 {12, MAP_PARTS_ROOM_CORNER_SOUTH_WEST, 0},
115s32 chainTableDivid[6][3] = {
117 {0xD4, MAP_PARTS_DIVIDE_END_EAST, 0},
118 {0x71, MAP_PARTS_DIVIDE_END_SOUTH, 0},
119 {0xB2, MAP_PARTS_DIVIDE_END_WEST, 0},
121 {0xF6, MAP_PARTS_DIVIDE_WALL_EAST, 0},
125s32 chainTableDividDoor[2][3] = {
127 {6, MAP_PARTS_DIVIDE_DOOR_EAST, 0},
133 if (this->
npc[npc_no].used != 0) {
137 if (npc_no >= 4 || npc_no < 0) {
145 for (i = 0; i < 32; i++) {
152 if (this->
npc[npc_no].chara.frame == NULL) {
153 printf(
"******* NPCEntryErr\n");
157 SetFrameAttr(this->
npc[npc_no].chara.frame, 1);
159 sceVu0CopyVector(this->
npc[npc_no].pos, pos);
160 sceVu0CopyVector(this->
npc[npc_no].rot, rot);
171 for (
int i = 0; i < 4; i++) {
177 if (this->
npc[npc_no].used != 0 && this->
npc[npc_no].visible != 0 && this->
npc[npc_no].chara.frame != NULL) {
192 for (i = 0; i < 4; i++) {
199 if (this->
npc[i].chara.frame == NULL) {
203 sceVu0CopyVector(pos, this->
npc[i].draw_pos[j]);
204 sceVu0CopyVector(unused, this->
npc[i].draw_pos[j]);
205 pos[0] += this->
npc[i].
pos[0];
206 pos[1] += this->
npc[i].
pos[1];
207 pos[2] += this->
npc[i].
pos[2];
217 if (direction == 3) {
221 deg = -90.0f * direction;
222 angle = (PI * deg) / 180.0f;
223 angle += this->
npc[i].
rot[1];
225 if (!(angle <= PI)) {
234 TexManager.ReloadTexture(Vif1Packet, i + 64);
242 for (
int i = 0; i < 4; i++) {
243 if (this->
npc[i].used != 0 && this->
npc[i].visible != 0 && this->
npc[i].chara.frame != NULL && this->npc[i].motion_no != -1) {
266 for (
int i = 0; i < 72; i++) {
283 for (i = 0; this->
parts[i].
frame[0] != NULL; i++) {
291 for (npc_no = 0; npc_no < 4; npc_no++) {
292 if (this->
npc[npc_no].parts_no == i) {
305 for (row = 0; row < 20; row++) {
306 for (col = 0; col < 20; col++) {
307 int cell_no = col + row * 20;
315 part = &this->
parts[this->cells[cell_no].parts_no];
316 part->
pos[0] = 160.0f * col;
318 part->
pos[2] = 160.0f * row;
320 this->
parts[this->cells[cell_no].parts_no].
DrawCalc(col, row, this->cells[cell_no].direction, mode);
325 for (i = 0; this->
parts[i].
frame[0] != NULL; i++) {
340 float old_ambient[4];
361 ((
CCamera *) camera)->GetPos(cam_pos);
362 ((
CCamera *) camera)->GetRef(cam_ref);
363 view_delta[0] = cam_ref[0] - cam_pos[0];
364 view_delta[1] = cam_ref[1] - cam_pos[1];
365 view_delta[2] = cam_ref[2] - cam_pos[2];
366 view_delta[3] = 1.0f;
367 sceVu0Normalize(view, view_delta);
368 sceVu0CopyVector(player_pos, player->
position);
369 player_cell_x = (int) (player_pos[0] / 160.0f);
370 player_cell_y = (int) (player_pos[2] / 160.0f);
371 free_area = ItemFreeAreaAll[selectMapNo];
376 for (row = 0; row < 20; row++) {
377 for (col = 0; col < 20; col++) {
378 world_x = 160.0f * col;
379 delta_x = world_x - cam_pos[0];
380 world_z = 160.0f * row;
381 delta_z = world_z - cam_pos[2];
383 cell_delta[0] = delta_x;
384 cell_delta[1] = 0.0f;
385 cell_delta[2] = delta_z;
386 cell_delta[3] = 0.0f;
387 dist = DistVector(cell_delta);
388 cell_no = col + row * 20;
397 if (UserStatus->
cur_georama == 2 && dist < nearest) {
399 sound_pos[0] = world_x;
401 sound_pos[2] = world_z;
408 if (this->
cells[cell_no].parts_no == 75 && dist < nearest) {
410 sound_pos[0] = world_x;
412 sound_pos[2] = world_z;
422 cam_ref[0] = delta_x - view_delta[0];
424 cam_ref[2] = delta_z - view_delta[2];
426 sceVu0Normalize(cam_ref, cam_ref);
427 float facing = sceVu0InnerProduct(view, cam_ref);
435 if (facing <= 0.0f && !(dist < 160.0f)) {
459 position_part->
pos[0] = world_x;
460 position_part->
pos[1] = 0.0f;
461 position_part->
pos[2] = world_z;
462 position_part->
pos[3] = 1.0f;
465 for (npc_no = 0; npc_no < 4; npc_no++) {
466 if (this->
npc[npc_no].parts_no == this->cells[cell_no].parts_no) {
467 this->
ReservNPC_Draw(npc_no, world_x, 0.0f, world_z, this->cells[cell_no].direction);
472 MGGetAmbient(old_ambient);
473 MGGetAmbient(ambient);
475 if (dist <= 480.0f) {
478 ambient[3] = 128.0f - (dist - 480.0f);
480 if (ambient[3] < 0.0f) {
485 MGSetAmbient(ambient);
488 this->
parts[this->cells[cell_no].parts_no].
Draw();
491 MGSetAmbient(old_ambient);
495 if (DebugStatus[6] != 0) {
497 if (free_area[area_no].parts_no != this->cells[cell_no].parts_no) {
501 for (rect_no = 0; rect_no < free_area[area_no].
rect_num; rect_no++) {
508 rotation = (int) (
float) free_area[area_no].
direction;
509 rotation = rotation + this->cells[cell_no].direction;
516 float radians = (PI * ((4 - rotation) * 90)) / 180.0f;
520 float left = free_area[area_no].
rect[rect_no].
x0;
522 height = 10.0f * free_area[area_no].
rect[rect_no].
y0;
523 z[0] = 10.0f * free_area[area_no].
rect[rect_no].
z0;
524 x[3] = 10.0f * free_area[area_no].
rect[rect_no].
x1;
525 z[3] = 10.0f * free_area[area_no].
rect[rect_no].
z1;
531 for (corner_no = 0; corner_no < 4; corner_no++) {
532 corner[corner_no][0] = -z[corner_no] * sinf(radians) - x[corner_no] * cosf(radians);
533 corner[corner_no][2] = -x[corner_no] * sinf(radians) + z[corner_no] * cosf(radians);
534 corner[corner_no][0] *= -1.0f;
535 corner[corner_no][0] += world_x;
536 corner[corner_no][1] = 2.0f + height;
537 corner[corner_no][2] += world_z;
538 corner[corner_no][3] = 1.0f;
540 if (MGRotTransPers(screen[corner_no], corner[corner_no], 0) == 0) {
545 if (all_visible != 0) {
546 setColSprite(Vif1Packet, screen[0], screen[1], screen[2], screen[3], 0x80, 0, 0, 0x40);
554 if (nearest < 10000.0f) {
555 SndGetVolPan(&volume, &pan, sound_pos, 10.0f, 500.0f);
556 SndSetSeVolf(sound_no, volume, 0);
557 SndSetSePanf(sound_no, pan, 0);
568 for (
int i = 0; i < 6; i++) {
570 this->
bg_model[i]->SetPosition(pos);
586 for (
int i = 0; i < this->
dummy_num; i++) {
611 float player_screen_x;
633 unsigned char red_table[3] = {0x20, 0x40, 0x60};
634 unsigned char green_table[3] = {0x60, 0x80, 0xA2};
635 unsigned char blue_table[3] = {0x40, 0x60, 0xA2};
637 red = red_table[status];
638 green = green_table[status];
639 blue = blue_table[status];
640 saved_map = BtEquipMap;
641 saved_crystal = BtEquipMasuisyou;
643 if (DebugStatus[3] != 0) {
645 BtEquipMasuisyou = 1;
648 visible = BtEquipMap ? 0 : 1;
649 map_texture = TexManager.GetTexture(
"minimap1", -1);
650 symbol_texture = TexManager.GetTexture(
"itempack", -1);
652 for (row = 0; row < 20; row++) {
653 for (col = 0; col < 20; col++) {
654 cell_no = col + row * 20;
655 masked = this->
mask[cell_no];
658 if (visible == 0 && masked == 0) {
667 map_src.
x = (direction % 8) * 16;
668 map_src.
y = (direction / 8) * 16;
671 map_dst.
x = col * 16 + 380;
672 map_dst.
y = row * 16 + 64;
675 set2DSprite(Vif1Packet, map_texture, map_dst, map_src, alpha, alpha, alpha, blue);
684 player_src.
width = 12;
686 map_x = (int) (pos[2] + 64.0f + 8.0f);
687 player_screen_x = pos[0] + 380.0f + 8.0f;
688 map_y = (int) player_screen_x;
689 player_dst.
x = (int) player_screen_x;
690 player_dst.
y = map_x;
691 player_dst.
width = 12;
693 set2DSprite(Vif1Packet, symbol_texture, player_dst, player_src, 7, 7, angle);
695 for (
int i = 0; i < 3; i++) {
702 map_x = (int) (this->
trap_circle[i].pos[0] * 0.1f);
703 map_y = (int) (this->
trap_circle[i].pos[2] * 0.1f);
704 cellx = (int) ((80.0f + this->
trap_circle[i].pos[0]) / 160.0f);
705 cell = cellx + (int) ((80.0f + this->
trap_circle[i].pos[2]) / 160.0f) * 20;
706 show = this->
mask[cell];
708 if (BtEquipMasuisyou == 1) {
717 trap_dst.
x = map_x + 384;
718 trap_dst.
y = map_y + 68;
721 set2DSprite(Vif1Packet, symbol_texture, trap_dst, trap_src, blue);
725 for (
int i = 0; i < 24; i++) {
728 if (this->
boxes[i].used == 0 || this->
boxes[i].closed == 0) {
732 map_x = (int) (this->
boxes[i].pos[0] * 0.1f);
733 map_y = (int) (this->
boxes[i].pos[2] * 0.1f);
734 cellx = (int) ((80.0f + this->
boxes[i].pos[0]) / 160.0f);
735 cell = cellx + (int) ((80.0f + this->
boxes[i].pos[2]) / 160.0f) * 20;
736 show = this->
mask[cell];
738 if (BtEquipMasuisyou == 1) {
747 box_dst.
x = map_x + 384;
748 box_dst.
y = map_y + 68;
751 set2DSprite(Vif1Packet, symbol_texture, box_dst, box_src, blue);
755 for (
int i = 0; i < 8; i++) {
758 if (this->
atra[i].used == 0) {
762 map_x = (int) (this->
atra[i].pos[0] * 0.1f);
763 map_y = (int) (this->
atra[i].pos[2] * 0.1f);
764 cellx = (int) ((80.0f + this->
atra[i].pos[0]) / 160.0f);
765 cell = cellx + (int) ((80.0f + this->
atra[i].pos[2]) / 160.0f) * 20;
766 show = this->
mask[cell];
768 if (BtEquipMasuisyou == 1) {
777 atra_dst.
x = map_x + 384;
778 atra_dst.
y = map_y + 68;
781 set2DSprite(Vif1Packet, symbol_texture, atra_dst, atra_src, blue);
785 BtEquipMap = saved_map;
786 BtEquipMasuisyou = saved_crystal;
795 cell_x = (int) ((80.0f + x) / 160.0f);
796 cell_z = (int) ((80.0f + z) / 160.0f);
799 for (
int i = 0; i < this->
room_num; i++) {
800 if (cell_x >= this->
rooms[i].x && cell_x < this->
rooms[i].x + this->
rooms[i].width) {
801 if (cell_z >= this->
rooms[i].y && cell_z < this->
rooms[i].y + this->
rooms[i].height) {
810 if (this->
rooms[room].width != 0) {
818 this->
mask[col + row * 20] = 1;
825 this->
mask[cell_x + cell_z * 20] = 1;
832 for (i = 0; i < 400; i++) {
836 for (i = 0; i < 16; i++) {
841 for (i = 0; i < 400; i++) {
863 sceVu0CopyVector(frame_pos, frame->
position);
864 ((
CCamera *) camera)->GetPos(cam_pos);
865 sceVu0ScaleVectorXYZ(cam_pos, cam_pos, 0.1f);
867 this->
fire.
SetTexture(TexManager.GetTexture(
"lightling", -1), TexManager.GetTexture(
"blender", -1));
868 this->
fire.FireCreate();
870 near_dist = 16000.0f;
872 for (i = 0; this->
parts[i].
frame[0] != NULL; i++) {
873 sceVu0CopyVector(part_pos, this->
parts[i].frame_offset[0]);
895 angle = (PI * (90.0f * (4.0f - angle))) / 180.0f;
896 turn = -fire_pos[2] * sinf(angle);
897 rot_x = turn - fire_pos[0] * cosf(angle);
898 turn = -fire_pos[0] * sinf(angle);
899 rot_z = turn + fire_pos[2] * cosf(angle);
906 fire_pos[0] = part_pos[0] / 10.0f + rot_x;
907 fire_pos[1] += part_pos[1] / 10.0f;
908 fire_pos[2] = world_z = part_pos[2] / 10.0f + rot_z;
909 world_y = fire_pos[1];
911 this->
fire.
pos[0] = 10.0f * fire_pos[0];
912 this->
fire.
pos[1] = 10.0f * world_y;
913 this->
fire.
pos[2] = 10.0f * world_z;
915 this->
fire.DrawFire(1, 1, (
CCamera *) camera, frame_pos, 1.0f, param, 15.0f);
918 dist = DistVector(cam_pos, fire_pos);
920 if (!(near_dist < dist)) {
922 sceVu0CopyVector(best_pos, fire_pos);
923 sceVu0ScaleVectorXYZ(best_pos, best_pos, 10.0f);
928 if (near_dist <= 30.0f) {
929 SndGetVolPan(&vol, &pan, best_pos, 10.0f, 500.0f);
930 SndSetSeVolf(SE_AMBIENT_CAVE_DRIPS, vol, 0);
931 SndSetSePanf(53, pan, 0);
933 SndSetSeVol(53, 0, 0);
954 sceVu0CopyVector(frame_pos, frame->
position);
955 ((
CCamera *) camera)->GetPos(cam_pos);
956 ((
CCamera *) camera)->GetPos(cam_near);
957 sceVu0ScaleVectorXYZ(cam_near, cam_near, 0.1f);
959 this->
fire.
SetTexture(TexManager.GetTexture(
"lightling", -1), TexManager.GetTexture(
"blender", -1));
960 this->
fire.FireCreate();
962 sceVu0CopyVector(frame_near, frame->
position);
963 frame_near[0] /= 10.0f;
964 frame_near[1] /= 10.0f;
965 frame_near[2] /= 10.0f;
967 cam_col = (int) (cam_pos[0] / 160.0f);
968 cam_row = (int) (cam_pos[2] / 160.0f);
969 near_dist = 16000.0f;
972 for (row = cam_row - 5; row < cam_row + 5; row++) {
973 for (col = cam_col - 5; col < cam_col + 5; col++) {
974 if (row >= 0 && row < 20 && col >= 0 && col < 20) {
975 int cell_no = col + row * 20;
980 for (j = 0; j < (part = &this->
parts[this->
cells[cell_no].
parts_no])->fire_num; j++) {
995 angle = (PI * (float) ((4 - this->
cells[cell_no].direction) * 90)) / 180.0f;
997 if (this->
cells[cell_no].direction != 0) {
998 turn = -fire_pos[2] * sinf(angle);
999 rot_x = turn - fire_pos[0] * cosf(angle);
1000 turn = -fire_pos[0] * sinf(angle);
1001 rot_z = turn + fire_pos[2] * cosf(angle);
1004 rot_x = fire_pos[0];
1005 rot_z = fire_pos[2];
1008 fire_pos[0] = rot_x + 16.0f * (float) col;
1009 rot_z += 16.0f * (float) row;
1010 fire_pos[2] = rot_z;
1011 height = fire_pos[1];
1013 this->
fire.
pos[0] = 10.0f * fire_pos[0];
1014 this->
fire.
pos[1] = 10.0f * height;
1015 this->
fire.
pos[2] = 10.0f * rot_z;
1017 this->
fire.DrawFire(1, 1, (
CCamera *) camera, frame_pos, 1.0f, param, 15.0f);
1020 dist = DistVector(cam_near, fire_pos);
1022 if (!(near_dist < dist)) {
1024 sceVu0CopyVector(best_pos, fire_pos);
1025 sceVu0ScaleVectorXYZ(best_pos, best_pos, 10.0f);
1033 if (near_dist <= 30.0f) {
1034 SndGetVolPan(&vol, &pan, best_pos, 10.0f, 500.0f);
1035 SndSetSeVolf(SE_AMBIENT_CAVE_DRIPS, vol, 0);
1036 SndSetSePanf(53, pan, 0);
1038 SndSetSeVol(53, 0, 0);
1055 sceVu0CopyVector(pos, frame->
position);
1056 cell_x = (int) (pos[0] / 160.0f);
1057 cell_z = (int) (pos[2] / 160.0f);
1060 for (row = cell_z - 4; row < cell_z + 4; row++) {
1061 for (col = cell_x - 4; col < cell_x + 4; col++) {
1062 if (row >= 0 && row < 20 && col >= 0 && col < 20) {
1063 int cell_no = col + row * 20;
1068 for (i = 0; i < (part = &this->
parts[this->
cells[cell_no].
parts_no])->fire_num; i++) {
1082 angle = (PI * (float) ((4 - dir) * 90)) / 180.0f;
1085 rot_x = -z * sinf(angle) - x * cosf(angle);
1086 rot_z = -x * sinf(angle) + z * cosf(angle);
1093 x = rot_x + 16.0f * (float) col;
1094 z = rot_z + 16.0f * (float) row;
1096 this->
fire.
pos[0] = 10.0f * x;
1097 this->
fire.
pos[1] = 10.0f * y;
1098 this->
fire.
pos[2] = 10.0f * z;
1129 sound_dist = 300.0f;
1146 for (row = 0; row < 16; row++) {
1147 for (col = 0; col < 16; col++) {
1148 int cell_no = col + row * 20;
1158 if (this->
parts[this->cells[cell_no].parts_no].
water.used == 0) {
1162 vec[0] = 160.0f * (float) col;
1164 vec[2] = 160.0f * (float) row;
1165 dist = DistVector(pos, vec);
1167 if (dist < near_dist) {
1170 best_pos[0] = vec[0];
1171 best_pos[1] = vec[1];
1172 best_pos[2] = vec[2];
1177 if (sound_dist >= dist) {
1185 this->water.frame.SetPosition(best_pos);
1187 u8 green = best->
green;
1188 u8 blue = best->
blue;
1190 this->water.SetColor(red, green, blue, 0x80);
1193 if (selectMapNo == DUNGEON_DIVINE_BEAST_CAVE && selectMapNo == DUNGEON_DEMON_SHAFT) {
1194 float height = 1.0f;
1196 this->water.SetParam(0.12f, 0.018f, height, 11.0f);
1198 float speed = 11.0f;
1200 this->water.SetParam(0.12f, 0.018f, 0.0f, speed);
1203 this->water.Shake(16, 4, 2.15f);
1206 this->water.Hamon();
1207 DrawVu1__6CWaterFP10RenderInfoP13sceVif1PacketP1(&this->water, &mgRenderInfo, Vif1Packet, NULL);
1213 if (best->
has_fall != 0 && this->fall_model != NULL) {
1214 float x = 160.0f * (float) best_col;
1215 float z = 160.0f * (float) best_row;
1221 if (sound_dist < 300.0f) {
1222 SndGetVolPan(&vol, &pan, best_pos, 50.0f, 300.0f);
1228 SndSetSeVolf(SE_AMBIENT_DUNGEON_HISS, vol, 0);
1229 SndSetSePanf(61, pan, 0);
1231 SndSetSeVol(61, 0, 0);
1237 if (sound_dist < 300.0f) {
1238 SndGetVolPan(&vol, &pan, best_pos, 50.0f, 300.0f);
1244 SndSetSeVolf(SE_AMBIENT_TOWN_NOISE, vol, 0);
1245 SndSetSePanf(52, pan, 0);
1247 SndSetSeVol(52, 0, 0);
1265 for (i = 0; i < 24; i++) {
1266 if (this->
boxes[i].used == 0) {
1275 switch (this->
boxes[i].kind) {
1283 this->
box_lid_model->SetRotation((PI * angle) / 180.0f, 0.0f, 0.0f);
1294 this->
chest_lid_model->SetRotation((PI * angle) / 180.0f, 0.0f, 0.0f);
1309 for (
int i = 0; i < this->
atra_num; i++) {
1310 if (this->
atra[i].used != 0) {
1312 sceVu0CopyVector(draw_pos, this->
atra[i].pos);
1315 draw_pos[1] += sinf(this->
atra[i].phase);
1319 if (this->
atra[i].phase <= 360.0f) {
1337 if (frame == NULL) {
1341 for (
int i = 0; i < this->
atra_num; i++) {
1342 if (this->
atra[i].used != 0) {
1343 if (DistVector(this->
atra[i].pos, pos) <= 400.0f) {
1344 frame->SetPosition(this->
atra[i].pos);
1345 num += frame->PickUpNearPoly(&poly[num], box);
1354s32 scanRoomInfoWork[256];
1368static int buildRoom(
int x,
int y,
int w,
int h,
int room_no) {
1374 for (j = -1; j < h + 2; j++) {
1375 for (i = -1; i < w + 2; i++) {
1376 if (i + x >= 0 && i + x < 20 && j + y >= 0 && j + y < 20) {
1388 for (j = 0; j < h; j++) {
1389 for (i = 0; i < w; i++) {
1391 buildMapDat[x + (y + j) * 20 + i].link[room_no] = 1;
1392 buildMapDat[x + (y + j) * 20 + i].content |= BUILD_CELL_ROOM;
1402void mapPartsFilter() {
1412 for (row = 0; row < 20; row++) {
1413 for (col = 0; col < 20; col++) {
1415 if ((buildMapDat[col + row * 20].content & BUILD_CELL_CORRIDOR) == BUILD_CELL_CORRIDOR) {
1417 int north = buildMapDat[col + (row - 1) * 20].content;
1418 int south = buildMapDat[col + (row + 1) * 20].content;
1419 int east = buildMapDat[col + row * 20 + 1].
content;
1420 int west = buildMapDat[col + row * 20 - 1].
content;
1422 int allow_north = 1;
1424 if ((north & (BUILD_CELL_ROOM | BUILD_CELL_DOOR)) == BUILD_CELL_ROOM) {
1428 if ((north & (BUILD_CELL_STAIR_DOWN | BUILD_CELL_STAIR_UP)) != 0 && buildMapDat[col + (row - 1) * 20].
direction != 0) {
1432 int allow_south = 1;
1434 if ((south & (BUILD_CELL_ROOM | BUILD_CELL_DOOR)) == BUILD_CELL_ROOM) {
1438 if ((south & (BUILD_CELL_STAIR_DOWN | BUILD_CELL_STAIR_UP)) != 0 && buildMapDat[col + (row + 1) * 20].
direction != 2) {
1444 if ((east & (BUILD_CELL_ROOM | BUILD_CELL_DOOR)) == BUILD_CELL_ROOM) {
1448 if ((east & (BUILD_CELL_STAIR_DOWN | BUILD_CELL_STAIR_UP)) != 0 && buildMapDat[col + row * 20 + 1].direction != 1) {
1454 if ((west & (BUILD_CELL_ROOM | BUILD_CELL_DOOR)) == BUILD_CELL_ROOM) {
1458 if ((west & (BUILD_CELL_STAIR_DOWN | BUILD_CELL_STAIR_UP)) != 0 && buildMapDat[col + row * 20 - 1].direction != 3) {
1462 for (room_no = 0; room_no < 16; room_no++) {
1463 if (buildMapDat[col + row * 20].link[room_no] == 1) {
1464 if (buildMapDat[col + (row - 1) * 20].
link[room_no] == 1 && allow_north != 0) {
1468 if (buildMapDat[col + (row + 1) * 20].
link[room_no] == 1 && allow_south != 0) {
1472 if (buildMapDat[col + row * 20 + 1].link[room_no] == 1 && allow_east != 0) {
1476 if (buildMapDat[col + row * 20 - 1].link[room_no] == 1 && allow_west != 0) {
1482 for (table_no = 0; table_no < 15; table_no++) {
1483 if (mask == chainTableRoad[table_no][0]) {
1484 buildMapDat[col + row * 20].
kind = chainTableRoad[table_no][1];
1485 buildMapDat[col + row * 20].
direction = chainTableRoad[table_no][2];
1491 if ((buildMapDat[col + row * 20].content & BUILD_CELL_ROOM) == BUILD_CELL_ROOM) {
1493 north = row != 0 ? buildMapDat[col + (row - 1) * 20].content & BUILD_CELL_ROOM : 0;
1494 south = row != 19 ? buildMapDat[col + (row + 1) * 20].content & BUILD_CELL_ROOM : 0;
1495 east = col != 19 ? buildMapDat[col + row * 20 + 1].
content & BUILD_CELL_ROOM : 0;
1496 west = col != 0 ? buildMapDat[col + row * 20 - 1].
content & BUILD_CELL_ROOM : 0;
1498 if (north == BUILD_CELL_ROOM) {
1502 if (south == BUILD_CELL_ROOM) {
1506 if (east == BUILD_CELL_ROOM) {
1510 if (west == BUILD_CELL_ROOM) {
1514 for (table_no = 0; table_no < 8; table_no++) {
1515 if (mask == chainTableRoom[table_no][0]) {
1516 buildMapDat[col + row * 20].
kind = chainTableRoom[table_no][1];
1517 buildMapDat[col + row * 20].
direction = chainTableRoom[table_no][2];
1523 if ((buildMapDat[col + row * 20].content & (BUILD_CELL_DOOR | BUILD_CELL_ROOM_LINK)) == BUILD_CELL_DOOR) {
1526 if ((buildMapDat[col + (row - 1) * 20].content & BUILD_CELL_ROOM) == BUILD_CELL_ROOM) {
1530 if ((buildMapDat[col + (row + 1) * 20].content & BUILD_CELL_ROOM) == BUILD_CELL_ROOM) {
1534 if ((buildMapDat[col + row * 20 + 1].content & BUILD_CELL_ROOM) == BUILD_CELL_ROOM) {
1538 if ((buildMapDat[col + row * 20 - 1].content & BUILD_CELL_ROOM) == BUILD_CELL_ROOM) {
1542 for (table_no = 0; table_no < 4; table_no++) {
1543 if (mask == chainTableDoor[table_no][0]) {
1544 buildMapDat[col + row * 20].
kind = chainTableDoor[table_no][1];
1549 if ((buildMapDat[col + row * 20].content & BUILD_CELL_HEAL_SPRING) == BUILD_CELL_HEAL_SPRING) {
1551 buildMapDat[col + row * 20].
direction = 0;
1554 if ((buildMapDat[col + row * 20].content & BUILD_CELL_PILLAR) == BUILD_CELL_PILLAR) {
1555 if ((100.0f * (
float) rand()) / 2147483648.0f <= 50.0f) {
1558 buildMapDat[col + row * 20].
kind = MAP_PARTS_PILLAR_2;
1561 buildMapDat[col + row * 20].
direction = 0;
1565 if ((buildMapDat[col + row * 20].content & BUILD_CELL_DIVIDING_WALL) == BUILD_CELL_DIVIDING_WALL) {
1568 north = south = east = west = 0;
1571 north = buildMapDat[col + (row - 1) * 20].content;
1575 south = buildMapDat[col + (row + 1) * 20].content;
1579 east = buildMapDat[col + row * 20 + 1].
content;
1583 west = buildMapDat[col + row * 20 - 1].
content;
1586 if ((north & BUILD_CELL_DIVIDING_WALL) == BUILD_CELL_DIVIDING_WALL) {
1590 if ((south & BUILD_CELL_DIVIDING_WALL) == BUILD_CELL_DIVIDING_WALL) {
1594 if ((east & BUILD_CELL_DIVIDING_WALL) == BUILD_CELL_DIVIDING_WALL) {
1598 if ((west & BUILD_CELL_DIVIDING_WALL) == BUILD_CELL_DIVIDING_WALL) {
1602 if ((north & BUILD_CELL_ROOM) == BUILD_CELL_ROOM) {
1606 if ((south & BUILD_CELL_ROOM) == BUILD_CELL_ROOM) {
1610 if ((east & BUILD_CELL_ROOM) == BUILD_CELL_ROOM) {
1614 if ((west & BUILD_CELL_ROOM) == BUILD_CELL_ROOM) {
1618 for (table_no = 0; table_no < 6; table_no++) {
1619 if (mask == chainTableDivid[table_no][0]) {
1620 buildMapDat[col + row * 20].
kind = chainTableDivid[table_no][1];
1625 if ((buildMapDat[col + row * 20].content & BUILD_CELL_DIVIDING_DOOR) == BUILD_CELL_DIVIDING_DOOR) {
1628 north = south = east = west = 0;
1631 north = buildMapDat[col + (row - 1) * 20].content;
1635 south = buildMapDat[col + (row + 1) * 20].content;
1639 east = buildMapDat[col + row * 20 + 1].
content;
1643 west = buildMapDat[col + row * 20 - 1].
content;
1646 if ((north & BUILD_CELL_DIVIDING_WALL) == BUILD_CELL_DIVIDING_WALL) {
1650 if ((south & BUILD_CELL_DIVIDING_WALL) == BUILD_CELL_DIVIDING_WALL) {
1654 if ((east & BUILD_CELL_DIVIDING_WALL) == BUILD_CELL_DIVIDING_WALL) {
1658 if ((west & BUILD_CELL_DIVIDING_WALL) == BUILD_CELL_DIVIDING_WALL) {
1662 for (table_no = 0; table_no < 2; table_no++) {
1663 if (mask == chainTableDividDoor[table_no][0]) {
1664 buildMapDat[col + row * 20].
kind = chainTableDividDoor[table_no][1];
1669 if ((buildMapDat[col + row * 20].content & BUILD_CELL_STAIR_DOWN) == BUILD_CELL_STAIR_DOWN) {
1673 if ((buildMapDat[col + row * 20].content & BUILD_CELL_STAIR_UP) == BUILD_CELL_STAIR_UP) {
1677 if ((buildMapDat[col + row * 20].content & BUILD_CELL_URA_ENTRANCE) == BUILD_CELL_URA_ENTRANCE) {
1685 for (
int i = 0; i < 400; i++) {
1688 for (
int j = 0; j < 16; j++) {
1703int joinRoom(
int from_room,
int to_room) {
1717 copyMapInfo(buildMapWork, buildMapDat);
1720 dx = roomStack[from_room].
x - roomStack[to_room].
x;
1721 dy = roomStack[from_room].
y - roomStack[to_room].
y;
1723 if (dx * dx > dy * dy) {
1739 cx = roomStack[from_room].
x + (roomStack[from_room].
width >> 1);
1740 cy = roomStack[from_room].
y - 1;
1741 buildMapWork[cx + (cy + 1) * 20].content |= BUILD_CELL_DOOR;
1742 buildMapWork[cx + (cy + 1) * 20].link[from_room] = 1;
1743 steps = roomStack[from_room].
y - (roomStack[to_room].
y + roomStack[to_room].
height);
1746 cx = roomStack[from_room].
x + (roomStack[from_room].
width >> 1);
1747 buildMapWork[cx + (roomStack[from_room].
y + roomStack[from_room].
height - 1) * 20].content |= BUILD_CELL_DOOR;
1748 buildMapWork[cx + (roomStack[from_room].
y + roomStack[from_room].
height - 1) * 20].link[from_room] = 1;
1749 cy = roomStack[from_room].
y + roomStack[from_room].
height;
1750 steps = roomStack[to_room].
y - cy;
1753 cx = roomStack[from_room].
x + roomStack[from_room].
width;
1754 cy = roomStack[from_room].
y + (roomStack[from_room].
height >> 1);
1755 buildMapWork[cx + cy * 20 - 1].
content |= BUILD_CELL_DOOR;
1756 buildMapWork[cx + cy * 20 - 1].
link[from_room] = 1;
1757 steps = roomStack[to_room].
x - (roomStack[from_room].
x + roomStack[from_room].
width);
1760 cx = roomStack[from_room].
x - 1;
1761 cy = roomStack[from_room].
y + (roomStack[from_room].
height >> 1);
1762 buildMapWork[cx + cy * 20 + 1].
content |= BUILD_CELL_DOOR;
1763 buildMapWork[cx + cy * 20 + 1].
link[from_room] = 1;
1764 steps = roomStack[from_room].
x - (roomStack[to_room].
x + roomStack[to_room].
width);
1768 target_x = roomStack[to_room].
x + (roomStack[to_room].
width >> 1);
1769 target_y = roomStack[to_room].
y + (roomStack[to_room].
height >> 1);
1770 steps = (steps >> 1) + 1;
1773 if (roomStack[from_room].y == roomStack[to_room].y + roomStack[to_room].height) {
1781 if (roomStack[to_room].y == roomStack[from_room].y + roomStack[from_room].height) {
1794 buildMapWork[cx + cy * 20].
kind = from_room;
1795 buildMapWork[cx + cy * 20].
link[from_room] = 1;
1796 buildMapWork[cx + cy * 20].
content |= BUILD_CELL_CORRIDOR;
1816 if ((buildMapWork[cx + cy * 20].content & BUILD_CELL_ROOM) == BUILD_CELL_ROOM) {
1817 buildMapWork[cx + cy * 20].
content |= BUILD_CELL_DOOR;
1818 buildMapWork[cx + cy * 20].
link[from_room] = 1;
1820 buildMapWork[cx + cy * 20].
link[from_room] = 1;
1831 distance = target_x - cx;
1834 distance = -distance;
1840 for (i = 0; i < distance; i++) {
1844 buildMapWork[cx + cy * 20].
kind = from_room;
1845 buildMapWork[cx + cy * 20].
link[from_room] = 1;
1846 buildMapWork[cx + cy * 20].
content |= BUILD_CELL_CORRIDOR;
1848 if ((buildMapWork[cx + cy * 20].content & BUILD_CELL_ROOM) == BUILD_CELL_ROOM) {
1849 buildMapWork[cx + cy * 20].
content |= BUILD_CELL_DOOR;
1850 buildMapWork[cx + cy * 20].
link[from_room] = 1;
1852 buildMapWork[cx + cy * 20].
link[from_room] = 1;
1862 distance = target_y - cy;
1865 distance = -distance;
1871 for (i = 0; i < distance; i++) {
1875 buildMapWork[cx + cy * 20].
kind = from_room;
1876 buildMapWork[cx + cy * 20].
link[from_room] = 1;
1877 buildMapWork[cx + cy * 20].
content |= BUILD_CELL_CORRIDOR;
1879 if ((buildMapWork[cx + cy * 20].content & BUILD_CELL_ROOM) == BUILD_CELL_ROOM) {
1880 buildMapWork[cx + cy * 20].
content |= BUILD_CELL_DOOR;
1881 buildMapWork[cx + cy * 20].
link[from_room] = 1;
1883 buildMapWork[cx + cy * 20].
link[from_room] = 1;
1912 copyMapInfo(buildMapDat, buildMapWork);
1916static void setRoomObject() {
1927 for (i = 0; i < roomStackCnt; i++) {
1933 for (x = 1; x < roomStack[i].
width - 1; x++) {
1934 if ((buildMapDat[roomStack[i].x + (x + roomStack[i].y * 20)].content & (BUILD_CELL_ROOM | BUILD_CELL_DOOR)) == BUILD_CELL_ROOM) {
1935 found_x = x + roomStack[i].
x;
1936 found_y = roomStack[i].
y;
1941 if ((100.0f * (
float) rand()) / 2147483648.0f <= 30.0f) {
1943 buildMapDat[found_x + found_y * 20].
content |= BUILD_CELL_HEAL_SPRING;
1952 for (y = 1; y < roomStack[i].
height - 1; y++) {
1953 for (x = 1; x < roomStack[i].
width - 1; x++) {
1954 if ((buildMapDat[roomStack[i].x + (x + (y + roomStack[i].y) * 20)].content & (BUILD_CELL_ROOM | BUILD_CELL_DOOR | BUILD_CELL_HEAL_SPRING | BUILD_CELL_PILLAR)) == BUILD_CELL_ROOM) {
1955 found_x = x + roomStack[i].
x;
1956 found_y = y + roomStack[i].
y;
1962 if ((100.0f * (
float) rand()) / 2147483648.0f <= 30.0f) {
1964 buildMapDat[found_x + found_y * 20].
content |= BUILD_CELL_PILLAR;
1970static void setRoomDivid() {
1982 for (i = 0; i < roomStackCnt; i++) {
1986 for (y = 1; y < roomStack[i].
height - 1; y++) {
1989 for (x = 0; x < roomStack[i].
width; x++) {
1990 if ((buildMapDat[roomStack[i].x + (x + (y + roomStack[i].y) * 20)].content & (BUILD_CELL_ROOM | BUILD_CELL_DOOR | BUILD_CELL_HEAL_SPRING | BUILD_CELL_PILLAR)) != BUILD_CELL_ROOM) {
1996 line_x[line_num] = roomStack[i].
x;
1997 line_y[line_num] = y + roomStack[i].
y;
1998 line_len[line_num] = roomStack[i].
width;
1999 line_dir[line_num] = 0;
2005 for (x = 1; x < roomStack[i].
width - 1; x++) {
2008 for (y = 0; y < roomStack[i].
height; y++) {
2009 if ((buildMapDat[roomStack[i].x + (x + (y + roomStack[i].y) * 20)].content & (BUILD_CELL_ROOM | BUILD_CELL_DOOR | BUILD_CELL_HEAL_SPRING | BUILD_CELL_PILLAR)) != BUILD_CELL_ROOM) {
2015 line_x[line_num] = x + roomStack[i].
x;
2016 line_y[line_num] = roomStack[i].
y;
2017 line_len[line_num] = roomStack[i].
height;
2018 line_dir[line_num] = 1;
2023 if (line_num == 0) {
2027 if (!((100.0f * (
float) rand()) / 2147483648.0f <= 40.0f)) {
2032 line_no = (int) (((
float) line_num * (
float) rand()) / 2147483648.0f);
2034 if (line_dir[line_no] == 0) {
2035 for (x = line_x[line_no]; x < line_x[line_no] + line_len[line_no]; x++) {
2036 buildMapDat[x + line_y[line_no] * 20].
content |= BUILD_CELL_DIVIDING_WALL;
2039 buildMapDat[line_x[line_no] + line_y[line_no] * 20 + (int) (((
float) (line_len[line_no] - 2) * (
float) rand()) / 2147483648.0f) + 1]
2040 .
content |= BUILD_CELL_DIVIDING_DOOR;
2042 for (y = line_y[line_no]; y < line_y[line_no] + line_len[line_no]; y++) {
2043 buildMapDat[y * 20 + line_x[line_no]].
content |= BUILD_CELL_DIVIDING_WALL;
2046 buildMapDat[line_x[line_no] + (line_y[line_no] + (int) (((
float) (line_len[line_no] - 2) * (
float) rand()) / 2147483648.0f) + 1) * 20]
2047 .content |= BUILD_CELL_DIVIDING_DOOR;
2052static void setUnderDungeonStart() {
2064 for (i = 0; i < 120; i++) {
2069 for (y = 0; y < 20; y++) {
2070 for (x = 0; x < 20; x++) {
2071 if ((buildMapDat[x + y * 20].content & (BUILD_CELL_ROOM | BUILD_CELL_DOOR | BUILD_CELL_DIVIDING_WALL)) == BUILD_CELL_ROOM && safe_num < 60) {
2072 safe[safe_num * 2] = x;
2073 safe[safe_num * 2 + 1] = y;
2085 pick = (int) (((
float) safe_num * (
float) rand()) / 2147483648.0f);
2086 printf(
"[s]%d\n", pick);
2088 y = safe[pick * 2 + 1];
2090 if (buildMapDat[x + (y - 1) * 20].content == 0) {
2091 if ((buildMapDat[x + y * 20 + 1].content & (BUILD_CELL_ROOM | BUILD_CELL_DOOR)) == BUILD_CELL_ROOM) {
2092 if ((buildMapDat[x + y * 20 - 1].content & (BUILD_CELL_ROOM | BUILD_CELL_DOOR)) == BUILD_CELL_ROOM) {
2093 buildMapDat[x + y * 20].
content = BUILD_CELL_ROOM | BUILD_CELL_URA_ENTRANCE;
2103 if (tries >= 5000) {
2108 if (searching == 0) {
2109 printf(
"safeNum = %d, escapeCnt = %d\n", safe_num, tries);
2113static void setStair() {
2124 for (i = 0; i < 120; i++) {
2128 for (y = 0; y < 20; y++) {
2129 for (x = 0; x < 20; x++) {
2130 if ((buildMapDat[x + y * 20].content & BUILD_CELL_CORRIDOR) == BUILD_CELL_CORRIDOR) {
2131 if (buildMapDat[x + (y - 1) * 20].content == 0) {
2132 safe[safe_num * 2] = x;
2133 safe[safe_num * 2 + 1] = y;
2140 pick = (int) (((
float) safe_num * (
float) rand()) / 2147483648.0f);
2142 if (safe_num <= 0) {
2143 printf(
"ERR: DownStair!!\n");
2148 y = safe[pick * 2 + 1];
2151 buildMapDat[x + (y - 1) * 20].content = BUILD_CELL_STAIR_DOWN;
2152 buildMapDat[x + (y - 1) * 20].kind = buildMapDat[x + y * 20].kind;
2153 buildMapDat[x + (y - 1) * 20].link[buildMapDat[x + y * 20].kind] = 1;
2154 buildMapDat[x + (y - 1) * 20].direction = 0;
2159 for (i = 0; i < 120; i++) {
2163 for (y = 0; y < 20; y++) {
2164 for (x = 0; x < 20; x++) {
2165 if ((buildMapDat[x + y * 20].content & BUILD_CELL_CORRIDOR) == BUILD_CELL_CORRIDOR) {
2166 if (buildMapDat[x + (y + 1) * 20].content == 0) {
2167 safe[safe_num * 2] = x;
2168 safe[safe_num * 2 + 1] = y;
2175 pick = (int) (((
float) safe_num * (float) rand()) / 2147483648.0f);
2177 if (safe_num <= 0) {
2178 printf(
"ERR: UpStair!!\n");
2183 y = safe[pick * 2 + 1];
2186 buildMapDat[x + (y + 1) * 20].content = BUILD_CELL_STAIR_UP;
2187 buildMapDat[x + (y + 1) * 20].kind = buildMapDat[x + y * 20].kind;
2188 buildMapDat[x + (y + 1) * 20].link[buildMapDat[x + y * 20].kind] = 1;
2189 buildMapDat[x + (y + 1) * 20].direction = 2;
2193 for (
int i = 0; i < 3; i++) {
2199 for (
int i = 0; i < 3; i++) {
2201 if (DistVector(this->
trap_circle[i].pos, pos) < dist) {
2211 for (
int i = 0; i < 3; i++) {
2218 this->
trap_circle[i].
kind = (int) ((10.0f * (
float) rand()) / 2147483648.0f);
2236 sceVu0CopyVector(pos, CharaMain.
pos);
2238 for (i = 0; i < 3; i++) {
2247 TexManager.ReloadTexture(Vif1Packet, 71);
2252 wide = 1.0f + sinf(this->
trap_circle[i].timer) / 2.0f;
2253 Trap_Circle.
SetScale(wide, tall, wide);
2264 sceVu0CopyVector(pos, CharaMain.
pos);
2266 for (
int i = 0; i < 3; i++) {
2268 if (DistVector(this->
trap_circle[i].pos, pos) <= 5.0f) {
2279 for (
int i = 0; i < 3; i++) {
2283 if (this->
trap_circle[i].timer >= THREE_HALVES_PI) {
2291 for (
int i = 0; i < this->
box_num; i++) {
2292 if (this->
boxes[i].used != 0 && DistVector(this->
boxes[i].pos, pos) < dist) {
2302 if (selectMapNo >= DUNGEON_DEMON_SHAFT) {
2306 for (
int i = 0; i < this->
atra_num; i++) {
2307 if (this->
atra[i].used != 0 && DistVector(this->
atra[i].pos, pos) < dist) {
2324 for (i = 0; i < 48; i++) {
2331 printf(
"ivent buffer over !!\n");
2338 sceVu0CopyVector(this->
events[event_no].pos, pos);
2355 for (i = 0; i < 24; i++) {
2356 if (this->
boxes[i].used == 0) {
2366 sceVu0CopyVector(this->
boxes[box_no].pos, pos);
2374 for (j = 0; j < 48; j++) {
2381 printf(
"ivent buffer over !!\n");
2396 this->
events[event_no].
pos[2] = pos[2] + 10.0f;
2402 this->
events[event_no].
pos[2] = pos[2] + 8.0f;
2416 float object_pos[4];
2432 if (place_atla == 0) {
2437 target_count = (int) ((4.0f * (
float) rand()) / 2147483648.0f) + 1;
2439 while (object_count < target_count + 3) {
2440 SearchiDoPutArea(this->
cells, 0, 0, 20, 20, box_pos);
2447 if (this->
CheckAtra(box_pos, 20.0f) == 0) {
2456 if ((100.0f * (
float) rand()) / 2147483648.0f >= 88.0f && object_count >= 2) {
2457 int item_no = PresetSmallItemNo_Get(selectMapNo, floor_no, special, 0);
2459 if (item_no != -1) {
2460 int trap_no = (int) ((6.0f * (
float) rand()) / 2147483648.0f);
2462 if (trap_no < 0 || trap_no >= 6) {
2470 int item_no = PresetSmallItemNo_Get(selectMapNo, floor_no, special, 1);
2472 if (place_atla != 0) {
2473 if (object_count == 0) {
2477 if (object_count == 1) {
2478 item_no = ITEM_MAGICAL_CRYSTAL;
2482 if (item_no != -1) {
2492 for (
int i = 0; i < 3; i++) {
2493 if ((
int) ((100.0f * (
float) rand()) / 2147483648.0f) < 21) {
2494 SearchiDoPutArea(this->
cells, 0, 0, 20, 20, object_pos);
2501 if (this->
CheckAtra(object_pos, 20.0f) == 0) {
2515 if (place_atla != 0) {
2517 int atra_count = BtAtraFloorCyoice(selectMapNo, floor_no, atra_no);
2519 while (object_count < atra_count) {
2520 SearchiDoPutArea(this->
cells, 0, 0, 20, 20, object_pos);
2527 if (this->
CheckAtra(object_pos, 20.0f) == 0) {
2536 sceVu0CopyVector(this->
atra[this->
atra_num].pos, object_pos);
2541 for (
int k = 0; k < 48; k++) {
2544 goto found_atla_event;
2548 printf(
"ivent buffer over !!\n");
2557 sceVu0CopyVector(this->
events[event_no].pos, object_pos);
2579 for (i = 0; i < 24; i++) {
2580 if (this->
boxes[i].used == 0) {
2590 for (j = 0; j < 48; j++) {
2597 printf(
"ivent buffer over !!\n");
2601 if (event_no == -1) {
2610 sceVu0CopyVector(this->
boxes[box_no].pos, pos);
2621 this->
events[event_no].
pos[2] = z + 10.0f;
2627 this->
events[event_no].
pos[2] = z + 8.0f;
2634 for (
int i = 0; i < 48; i++) {
2647 sceVu0CopyVector(pos, frame->
position);
2650 (void) (
int) ((float) (
int) (80.0f + pos[0]) / 160.0f);
2651 (void) (
int) ((float) (
int) (80.0f + pos[2]) / 160.0f);
2653 for (
int i = 0; i < 48; i++) {
2679 x = (int) ((21.0f * (
float) rand()) / 2147483648.0f) - 1;
2680 z = (int) ((21.0f * (
float) rand()) / 2147483648.0f) - 1;
2681 shape = (int) ((3.0f * (
float) rand()) / 2147483648.0f);
2690 for (j = 0; j < 2; j++) {
2691 for (i = 0; i < 2; i++) {
2699 pos[0] = 80.0f + 160.0f * x;
2701 pos[2] = 80.0f + 160.0f * z;
2709 for (j = 0; j < 2; j++) {
2710 for (i = 0; i < 2; i++) {
2718 pos[0] = 160.0f + 160.0f * x;
2720 pos[2] = 160.0f + 160.0f * z;
2728 for (j = 0; j < 3; j++) {
2729 for (i = 0; i < 3; i++) {
2737 pos[0] = 240.0f + 160.0f * x;
2739 pos[2] = 240.0f + 160.0f * z;
2749 for (x = 0; x < num; x++) {
2750 if (DistVector(pos, this->
dummy_pos[x]) < 40.0f * kind) {
2756 for (x = 0; x < 20; x++) {
2757 for (z = 0; z < 20; z++) {
2759 stair_pos[0] = 80.0f + 160.0f * z;
2760 stair_pos[1] = 0.0f;
2761 stair_pos[2] = 80.0f + 160.0f * x;
2762 stair_pos[3] = 1.0f;
2764 if (DistVector(stair_pos, pos) < 160.0f * (kind + 2)) {
2784 if (tries > 10000) {
2796 int door_pos[32][2];
2807 int propagation_mask;
2813 for (
int i = 0; i < 4; i++) {
2817 for (
int i = 0; i < 256; i++) {
2818 scanRoomInfoWork[i] = -1;
2824 for (y = 0; y < 16; y++) {
2825 for (x = 0; x < 16; x++) {
2834 for (y = 0; y < 16; y++) {
2835 for (x = 0; x < 16; x++) {
2836 if ((buildMapDat[x + y * 20].content & BUILD_CELL_DOOR) != 0) {
2837 door_pos[door_count][0] = x;
2838 door_pos[door_count][1] = y;
2841 if (door_count >= 32) {
2849 int door_no = (int) (((
float) door_count * (
float) rand()) / 2147483648.0f);
2850 x = door_pos[door_no][0];
2851 y = door_pos[door_no][1];
2852 scanRoomInfoWork[x + y * 16] = 9;
2853 buildMapDat[x + y * 20].
content |= BUILD_CELL_ROOM_LINK;
2860 if ((buildMapDat[x + (y - 1) * 20].content & BUILD_CELL_CORRIDOR) == BUILD_CELL_CORRIDOR) {
2864 if ((buildMapDat[x + (y + 1) * 20].content & BUILD_CELL_CORRIDOR) == BUILD_CELL_CORRIDOR) {
2868 if ((buildMapDat[x + y * 20 + 1].content & BUILD_CELL_CORRIDOR) == BUILD_CELL_CORRIDOR) {
2872 if ((buildMapDat[x + y * 20 - 1].content & BUILD_CELL_CORRIDOR) == BUILD_CELL_CORRIDOR) {
2876 switch (direction_mask) {
2879 scanRoomInfoWork[x + (y - 1) * 16] = 0;
2880 scanRoomInfoWork[x + (y + 1) * 16] = 1;
2883 door_part = MAP_PARTS_ROOM_GATE_EAST;
2884 scanRoomInfoWork[x + y * 16 + 1] = 0;
2885 scanRoomInfoWork[x + y * 16 - 1] = 1;
2888 door_part = MAP_PARTS_ROOM_GATE_SOUTH;
2889 scanRoomInfoWork[x + (y - 1) * 16] = 0;
2890 scanRoomInfoWork[x + (y + 1) * 16] = 1;
2893 door_part = MAP_PARTS_ROOM_GATE_WEST;
2894 scanRoomInfoWork[x + y * 16 + 1] = 0;
2895 scanRoomInfoWork[x + y * 16 - 1] = 1;
2898 printf(
"ERROR !!\n");
2905 while (active != 0) {
2908 for (y = 1; y < 15; y++) {
2909 for (x = 1; x < 15; x++) {
2910 if (scanRoomInfoWork[x + y * 16] == -1 || scanRoomInfoWork[x + y * 16] == 9) {
2914 switch (buildMapDat[x + y * 20].content & (BUILD_CELL_ROOM | BUILD_CELL_CORRIDOR | BUILD_CELL_DOOR)) {
2915 case BUILD_CELL_CORRIDOR:
2916 propagation_mask = BUILD_CELL_CORRIDOR | BUILD_CELL_DOOR | BUILD_CELL_STAIR_DOWN;
2918 case BUILD_CELL_ROOM:
2919 propagation_mask = BUILD_CELL_ROOM | BUILD_CELL_DOOR;
2921 case BUILD_CELL_ROOM | BUILD_CELL_DOOR:
2922 propagation_mask = BUILD_CELL_ROOM | BUILD_CELL_CORRIDOR;
2929 if (buildMapDat[x + (y - 1) * 20].kind !=
MAP_PARTS_NONE && scanRoomInfoWork[x + (y - 1) * 16] == -1 && (propagation_mask & buildMapDat[x + (y - 1) * 20].content) != 0) {
2932 for (
int i = 0; i < 16; i++) {
2933 if (buildMapDat[x + y * 20].link[i] == 1 && buildMapDat[x + (y - 1) * 20].link[i] == 1) {
2939 scanRoomInfoWork[x + (y - 1) * 16] = scanRoomInfoWork[x + y * 16];
2944 if (buildMapDat[x + (y + 1) * 20].
kind !=
MAP_PARTS_NONE && scanRoomInfoWork[x + (y + 1) * 16] == -1 && (propagation_mask & buildMapDat[x + (y + 1) * 20].
content) != 0) {
2947 for (
int i = 0; i < 16; i++) {
2948 if (buildMapDat[x + y * 20].link[i] == 1 && buildMapDat[x + (y + 1) * 20].
link[i] == 1) {
2954 scanRoomInfoWork[x + (y + 1) * 16] = scanRoomInfoWork[x + y * 16];
2959 if (buildMapDat[x + y * 20 - 1].kind !=
MAP_PARTS_NONE && scanRoomInfoWork[x + y * 16 - 1] == -1 && (propagation_mask & buildMapDat[x + y * 20 - 1].content) != 0) {
2962 for (
int i = 0; i < 16; i++) {
2963 if (buildMapDat[x + y * 20].link[i] == 1 && buildMapDat[x + y * 20 - 1].link[i] == 1) {
2969 scanRoomInfoWork[x + y * 16 - 1] = scanRoomInfoWork[x + y * 16];
2974 if (buildMapDat[x + y * 20 + 1].kind !=
MAP_PARTS_NONE && scanRoomInfoWork[x + y * 16 + 1] == -1 && (propagation_mask & buildMapDat[x + y * 20 + 1].content) != 0) {
2977 for (
int i = 0; i < 16; i++) {
2978 if (buildMapDat[x + y * 20].link[i] == 1 && buildMapDat[x + y * 20 + 1].link[i] == 1) {
2984 scanRoomInfoWork[x + y * 16 + 1] = scanRoomInfoWork[x + y * 16];
2993 int target_label = scanRoomInfoWork[stair_x + (stair_y + 1) * 16];
2997 for (
int i = 0; i < this->
room_num; i++) {
2998 if (target_label == scanRoomInfoWork[this->
rooms[i].x + (this->
rooms[i].y + 1) * 16 + 1]) {
2999 room_list[room_count++] = i;
3003 if (room_count == 0) {
3004 printf(
"//////--------> SET NOOMAL DOOR PUTERR!![%d] ///////// \n", target_label);
3008 while (active != 0) {
3011 int list_no = (int) (((
float) room_count * (
float) rand()) / 2147483648.0f);
3013 if (list_no < 0 || list_no > room_count) {
3017 SearchiDoPutArea(this->
cells, this->
rooms[room_list[list_no]].x, this->
rooms[room_list[list_no]].y, this->
rooms[room_list[list_no]].width, this->
rooms[room_list[list_no]].height, pos);
3050 for (
int i = 0; i < 20; i++) {
3059 {{0, -1}, {0, 1}, {-1, 0}, {1, 0}}
3066 for (row = 1; row < 15; row++) {
3067 for (col = 1; col < 15; col++) {
3068 if (last_part != -1) {
3071 if (this->
cells[col + row * 20].parts_no >= first_part && this->
cells[col + row * 20].parts_no <= last_part) {
3072 list[num * 2] = col;
3073 list[num * 2 + 1] = row;
3076 if (num >= max - 1) {
3085 for (i = 0; i < 4; i++) {
3086 int dx = adjacent.
offset[i][0];
3087 int dy = adjacent.
offset[i][1];
3088 int cell_no = dx + (col + (row + dy) * 20);
3090 if (this->
cells[cell_no].parts_no !=
MAP_PARTS_NONE && (buildMapDat[cell_no].content & BUILD_CELL_ROOM_LINK) == BUILD_CELL_ROOM_LINK) {
3095 if (this->
cells[col + row * 20].parts_no == first_part && free != 0) {
3096 list[num * 2] = col;
3097 list[num * 2 + 1] = row;
3100 if (num >= max - 1) {
3124 unsigned int address;
3126 if (selectMapNo < DUNGEON_DEMON_SHAFT) {
3131 if (zone >= 0 && zone < 6) {
3132 if (zone == RES_LIMIT_ZONE_XIAO) {
3133 if ((
int) ((100.0f * (
float) rand()) / 2147483648.0f) >= 50) {
3147 roll = (int) ((100.0f * (
float) rand()) / 2147483648.0f);
3149 if (selectMapNo == DUNGEON_DIVINE_BEAST_CAVE && UserStatus->
cur_floor < 8) {
3153 if (UserStatus->
party_size >= 2 && roll > 0x32) {
3157 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3164 roll = (int) ((100.0f * (
float) rand()) / 2147483648.0f);
3167 switch (selectMapNo) {
3168 case DUNGEON_WISE_OWL_FOREST:
3169 if (UserStatus->
party_size >= 3 && roll > 0xA && floor >= 9) {
3173 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3174 address = (list[pick * 2] + list[pick * 2 + 1] * 20) *
sizeof(
MAP_CELL);
3175 address += (
unsigned int)
this;
3183 case DUNGEON_SHIPWRECK:
3184 if (UserStatus->
party_size >= 3 && roll < 0x28) {
3188 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3189 address = (list[pick * 2] + list[pick * 2 + 1] * 20) *
sizeof(
MAP_CELL);
3190 address += (
unsigned int)
this;
3197 if (UserStatus->
party_size >= 4 && roll >= 0x28 && floor >= 9) {
3201 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3202 address = (list[pick * 2] + list[pick * 2 + 1] * 20) *
sizeof(
MAP_CELL);
3203 address += (
unsigned int)
this;
3211 case DUNGEON_SUN_MOON_TEMPLE:
3212 if (UserStatus->
party_size >= 3 && roll < 0x14) {
3216 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3217 address = (list[pick * 2] + list[pick * 2 + 1] * 20) *
sizeof(
MAP_CELL);
3218 address += (
unsigned int)
this;
3225 if (UserStatus->
party_size >= 4 && roll < 0x28) {
3229 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3230 address = (list[pick * 2] + list[pick * 2 + 1] * 20) *
sizeof(
MAP_CELL);
3231 address += (
unsigned int)
this;
3238 if (UserStatus->
party_size >= 5 && roll >= 0x28 && floor >= 9) {
3242 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3249 case DUNGEON_MOON_SEA:
3250 if (UserStatus->
party_size >= 3 && roll < 0xA) {
3254 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3255 address = (list[pick * 2] + list[pick * 2 + 1] * 20) *
sizeof(
MAP_CELL);
3256 address += (
unsigned int)
this;
3263 if (UserStatus->
party_size >= 4 && roll < 0x14) {
3267 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3268 address = (list[pick * 2] + list[pick * 2 + 1] * 20) *
sizeof(
MAP_CELL);
3269 address += (
unsigned int)
this;
3276 if (UserStatus->
party_size >= 5 && roll < 0x1E) {
3280 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3286 if (UserStatus->
party_size >= 6 && roll > 0x28 && floor >= 8) {
3290 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3297 case DUNGEON_GALLERY_OF_TIME:
3298 if (UserStatus->
party_size >= 3 && roll < 0xA) {
3302 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3303 address = (list[pick * 2] + list[pick * 2 + 1] * 20) *
sizeof(
MAP_CELL);
3304 address += (
unsigned int)
this;
3311 if (UserStatus->
party_size >= 4 && roll < 0x14) {
3315 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3316 address = (list[pick * 2] + list[pick * 2 + 1] * 20) *
sizeof(
MAP_CELL);
3317 address += (
unsigned int)
this;
3324 if (UserStatus->
party_size >= 5 && roll < 0x1E) {
3328 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3334 if (UserStatus->
party_size >= 6 && roll > 0x28) {
3338 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3360 unsigned int address;
3371 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3381 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3382 address = (list[pick * 2] + list[pick * 2 + 1] * 20) *
sizeof(
MAP_CELL);
3383 address += (
unsigned int)
this;
3393 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3394 address = (list[pick * 2] + list[pick * 2 + 1] * 20) *
sizeof(
MAP_CELL);
3395 address += (
unsigned int)
this;
3405 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3406 address = (list[pick * 2] + list[pick * 2 + 1] * 20) *
sizeof(
MAP_CELL);
3407 address += (
unsigned int)
this;
3417 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3426 pick = (int) (((
float) num * (
float) rand()) / 2147483648.0f);
3455 if (first_build != 0) {
3456 this->
map_seed = (int) ((
float) rand() / (float) 100000);
3460 for (i = 0; i < 48; i++) {
3465 for (i = 0; i < 24; i++) {
3473 for (i = 0; i < 8; i++) {
3479 for (i = 0; i < 4; i++) {
3483 for (row = 0; row < 20; row++) {
3484 for (col = 0; col < 20; col++) {
3486 buildMapDat[col + row * 20].
direction = 0;
3488 for (j = 0; j < 16; j++) {
3489 buildMapDat[col + row * 20].
link[j] = 0;
3492 buildMapDat[col + row * 20].
content = 0;
3501 while (roomStackCnt < 2 && retry < 0x40) {
3506 w = (int) ((2.0f * (
float) rand()) / 2147483648.0f) + 3;
3507 h = (int) ((2.0f * (
float) rand()) / 2147483648.0f) + 3;
3508 x = (int) (((
float) (16 - w) * (
float) rand()) / 2147483648.0f);
3509 y = (int) (((
float) (16 - h) * (
float) rand()) / 2147483648.0f);
3511 if (buildRoom(x, y, w, h, roomStackCnt) == 1) {
3512 roomStack[roomStackCnt].
x = x;
3513 roomStack[roomStackCnt].
y = y;
3514 roomStack[roomStackCnt].
width = w;
3515 roomStack[roomStackCnt].
height = h;
3521 if (retry >= 0x40) {
3531 while (roomStackCnt <= room_max - 1 && retry < 0x200) {
3536 w = (int) ((2.0f * (
float) rand()) / 2147483648.0f) + 3;
3537 h = (int) ((2.0f * (
float) rand()) / 2147483648.0f) + 3;
3538 x = (int) (((
float) (16 - w) * (
float) rand()) / 2147483648.0f);
3539 y = (int) (((
float) (16 - h) * (
float) rand()) / 2147483648.0f);
3541 if (buildRoom(x, y, w, h, roomStackCnt) == 1) {
3542 roomStack[roomStackCnt].
x = x;
3543 roomStack[roomStackCnt].
y = y;
3544 roomStack[roomStackCnt].
width = w;
3545 roomStack[roomStackCnt].
height = h;
3550 for (j = 0; j < roomStackCnt - 1; j++) {
3551 w = (roomStack[roomStackCnt - 1].
x + roomStack[roomStackCnt - 1].
width / 2) - (roomStack[j].x + roomStack[j].width / 2);
3552 h = (roomStack[roomStackCnt - 1].
y + roomStack[roomStackCnt - 1].
height / 2) - (roomStack[j].y + roomStack[j].height / 2);
3554 dist = (int) sqrt((
double) (w * w + h * h));
3556 if (dist < near_dist) {
3562 joinRoom(roomStackCnt - 1, near_no);
3567 if (retry >= 0x200) {
3576 if (first_build != 0) {
3580 if (first_build != 0) {
3581 setUnderDungeonStart();
3583 setUnderDungeonStart();
3586 if (first_build != 0) {
3593 memcpy(this->
rooms, roomStack, 0x100);
3595 for (row = 0; row < 20; row++) {
3596 for (col = 0; col < 20; col++) {
3602 if (selectMapNo == DUNGEON_MOON_SEA) {
3606 if ((
int) ((100.0f * (
float) rand()) / 2147483648.0f) < 0x33 && first_build != 0) {
3610 if (first_build != 0) {
3615 switch (selectMapNo) {
3616 case DUNGEON_DIVINE_BEAST_CAVE:
3619 case DUNGEON_SHIPWRECK:
3622 case DUNGEON_SUN_MOON_TEMPLE:
3625 case DUNGEON_MOON_SEA:
3628 case DUNGEON_GALLERY_OF_TIME:
3631 case DUNGEON_DEMON_SHAFT:
3636 if (selectMapNo == DUNGEON_WISE_OWL_FOREST) {
3637 int pick = (int) ((3.0f * (
float) rand()) / 2147483648.0f);
3638 int gate_keys[3] = {0xC4, 0xC6, 0xCD};
3640 if (pick < 0 || pick > 2) {
3648 printf(
"map build success!!\n");
3655 for (i = 0; i < 6; i++) {
3659 for (i = 0; i < 3; i++) {
3671 for (i = 0; i < 24; i++) {
3675 for (i = 0; i < this->
atra_num; i++) {
3682 this->
water.SetSize(32, 32, alloc);
3684 for (i = 0; i < 72; i++) {
3688 for (i = 0; i < 400; i++) {
3695 for (i = 0; i < 16; i++) {
3699 for (i = 0; i < 4; i++) {
3705 for (j = 0; j < 48; j++) {
3710 for (j = 0; j < 24; j++) {
3718 for (j = 0; j < 8; j++) {
3724 for (j = 0; j < 4; j++) {
3733 for (i = 0; i < 6; i++) {
3737 for (i = 0; i < 3; i++) {
3749 for (i = 0; i < 24; i++) {
3753 for (i = 0; i < this->
atra_num; i++) {
3761 for (i = 0; i < 72; i++) {
3765 for (i = 0; i < 400; i++) {
3772 for (i = 0; i < 16; i++) {
3776 for (i = 0; i < 4; i++) {
3782 for (j = 0; j < 48; j++) {
3787 for (j = 0; j < 24; j++) {
3795 for (j = 0; j < 8; j++) {
3801 for (j = 0; j < 4; j++) {
virtual void LoadPackData2(unsigned int *pack, char *name, CDataAlloc2< 1 > *alloc, int texture_block_no, CDataAlloc2< 1 > *image_alloc, int visual_type)
virtual void SetScale(float x, float y, float z)
void InitializeTexAnime(CTexAnimeData *data, int count)
virtual void SetRotation(float x, float y, float z)
void TextureAnime(int step)
virtual void Initialize()
virtual void SetPosition(float x, float y, float z)
sceVu0FVECTOR dummy_pos[8]
CFrame * GetFrameSearch(char *name)
int SetTreasureBox(float *pos, int item_no, int kind, int trap_no)
ROOM_LINK_RESULT room_link[4]
void DrawFire(CFrameVu1 *frame, CCameraFollow *camera)
void DrawFireFreeStyle(CFrameVu1 *frame, CCameraFollow *camera)
MAP_TRAP_CIRCLE * DistTrapCircle()
void DrawItemBox(float *pos)
MAP_TRAP_CIRCLE trap_circle[3]
void SetupTrapCircle(float *pos)
int SetCharaDoor(int chara_no)
void DrawRaster(CFrameVu1 *frame)
int CreatPartsList(int *list, int max, int first_part, int last_part)
void initSubmap(CDataAlloc2< 1 > *alloc)
void DrawWater(float *pos, int mute)
void DrawBGModel(CCamera *camera)
void NPCSetMotion(int npc_no, int motion_no)
int CreateCollision(CCPoly *poly, CBoxVu0 box, int num)
int CheckTreasureBox(float *pos, float dist)
CFrame * box_collision_model
CFrame * chest_collision_model
void DrawDummyModel(CCamera *camera)
int GetActiveIvent(CFrameVu1 *frame)
void SetNPC(int npc_no, unsigned int *pack, int parts_no, sceVu0FVECTOR pos, sceVu0FVECTOR rot, int visible, int motion_no, CDataAlloc2< 1 > *alloc)
void DrawMap(CCameraFollow *camera, CFrameVu1 *player)
void DrawMiniMap(float *pos, float angle)
void BuildCharaSpecialParts()
void SetMimicEvent(float x, float y, float z, int item_no, int kind)
void buildEventData(int floor_no, int enabled, int place_atla)
float * CheckTrapCircle(float *pos, float dist)
CFrame * chest_body_model
void checkMask(float x, float z)
void DrawMapCalc(int mode)
int CheckAtra(float *pos, float dist)
void SetAtraBoll(float *pos, int atra_no)
void ReservNPC_Draw(int npc_no, float x, float y, float z, int direction)
void buildRandomMap(int room_max, int first_build)
void DrawAtraBoll(float *pos)
CFrame * GetSearchFrame(char *name)
void DrawCalc(int x, int z, int turn, int map_type)
void SetTexture(CTexture *core_texture, CTexture *glow_texture)
s32 res_limit_zone_current
@ MAP_PARTS_DIVIDE_WALL_NORTH
@ MAP_PARTS_ROOM_GATE_NORTH
@ MAP_PARTS_KEY_DOOR_RUBY_NORTH
@ MAP_PARTS_KEY_DOOR_GORO_NORTH
@ MAP_PARTS_ROOM_DOOR_NORTH
@ MAP_PARTS_DIVIDE_END_NORTH
@ MAP_PARTS_ROAD_DEAD_END
@ MAP_PARTS_ROAD_STRAIGHT
@ MAP_PARTS_URA_ENTRANCE_NORTH
@ MAP_PARTS_KEY_DOOR_XIAO_NORTH
@ MAP_PARTS_HEAL_SPRING_NORTH
@ MAP_PARTS_DIVIDE_DOOR_NORTH