5#include "collision.hpp"
6#include "editground.hpp"
14#include "visualvu1.hpp"
20enum MapConnectionAttribute {
21 MAP_CONNECTION_ROAD = 1,
22 MAP_CONNECTION_RIVER = 2
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
75 position->
z = this->
offset_z + ((float) z * this->unit_size);
79 if (x < 0 || x >=
width) {
83 if (y < 0 || y >=
height) {
91 if (x < 0 || x >=
width) {
95 if (y < 0 || y >=
height) {
103 if (x < 0 || x >=
width) {
107 if (y < 0 || y >=
height) {
115 if (x < 0 || x >=
width) {
119 if (y < 0 || y >=
height) {
127 if (x < 0 || x >=
width) {
131 if (y < 0 || y >=
height) {
139 if (x < 0 || x >=
width) {
143 if (y < 0 || y >=
height) {
151 if (x < 0 || x >=
width) {
155 if (y < 0 || y >=
height) {
163 if (altitude >= 128) {
171 if (x < 0 || x >=
width) {
175 if (y < 0 || y >=
height) {
183 if (x < 0 || x >=
width) {
187 if (y < 0 || y >=
height) {
196 GetPos(&position, x, y, z);
197 return GetAlt(position.
x, position.
z);
202 GetPos(&position, x, y, z);
211 if (x == 5 && y == -1) {
212 return MAP_CONNECTION_RIVER;
215 if (x == 2 && y == 8) {
216 return MAP_CONNECTION_RIVER;
221 if (x == 3 && y == 6) {
222 return MAP_CONNECTION_RIVER;
225 if (x == 12 && y == 3) {
226 return MAP_CONNECTION_RIVER;
231 if (x == 4 && y == -1) {
232 return MAP_CONNECTION_RIVER;
235 if (x == 3 && y == 8) {
236 return MAP_CONNECTION_RIVER;
243 if (x < 0 || x >=
width) {
247 if (y < 0 || y >=
height) {
260 int parts_width = target->
GetWidth();
262 GetPos(&position, x, y, z);
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);
272 if (cell_code != 0) {
273 SetCode(cell_x, cell_y, cell_code);
275 if (cell_code < 0x80) {
276 AddAlt(cell_x, cell_y, cell_code);
292 GetPos(&position, x, y, z);
299 int parts_width = target->
GetWidth();
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);
310 if (cell_code != 0) {
311 if (cell_code < 0x80) {
313 AddAlt(cell_x, cell_y, -cell_code);
316 CMapParts *occupant_parts = &parts[occupant];
317 sceVu0FVECTOR occupant_position;
319 occupant_position[1] =
GetAlt(cell_x, cell_y);
338 int negative_z, positive_x, positive_z, negative_x;
339 int count, shape, direction, i;
341 if ((x < 0) || (x >= this->
width)) {
345 if ((y < 0) || (y >= this->
height)) {
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;
371 for (i = 0; i < 4; i++) {
372 count += neighbors[i];
379 shape = MAP_CONNECTION_FOUR_WAY;
383 shape = MAP_CONNECTION_THREE_WAY;
385 if (neighbors[0] == 0) {
389 if (neighbors[1] == 0) {
393 if (neighbors[2] == 0) {
397 if (neighbors[3] == 0) {
403 if (((neighbors[0] != 0) && (neighbors[2] != 0)) || ((neighbors[1] != 0) && (neighbors[3] != 0))) {
404 shape = MAP_CONNECTION_STRAIGHT;
406 if (neighbors[0] != 0) {
410 if (neighbors[1] != 0) {
414 shape = MAP_CONNECTION_CORNER;
416 if ((neighbors[1] != 0) && (neighbors[2] != 0)) {
420 if ((neighbors[2] != 0) && (neighbors[3] != 0)) {
424 if ((neighbors[3] != 0) && (neighbors[0] != 0)) {
428 if ((neighbors[0] != 0) && (neighbors[1] != 0)) {
435 shape = MAP_CONNECTION_END;
437 if (neighbors[0] != 0) {
441 if (neighbors[1] != 0) {
445 if (neighbors[2] != 0) {
449 if (neighbors[3] != 0) {
455 shape = MAP_CONNECTION_ISOLATED;
462 shape = (shape << 4) & 0xFF0;
463 return shape | (direction & 0xF);
473 if ((x < 0) || (x >= this->
width)) {
477 if ((y < 0) || (y >= this->
height)) {
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;
491 for (i = 0; i < 4; i++) {
492 count += neighbors[i];
499 shape = MAP_CONNECTION_FOUR_WAY;
503 shape = MAP_CONNECTION_THREE_WAY;
505 if (neighbors[0] == 0) {
509 if (neighbors[1] == 0) {
513 if (neighbors[2] == 0) {
517 if (neighbors[3] == 0) {
523 if (((neighbors[0] != 0) && (neighbors[2] != 0)) || ((neighbors[1] != 0) && (neighbors[3] != 0))) {
524 shape = MAP_CONNECTION_STRAIGHT;
526 if (neighbors[0] != 0) {
530 if (neighbors[1] != 0) {
534 shape = MAP_CONNECTION_CORNER;
536 if ((neighbors[1] != 0) && (neighbors[2] != 0)) {
540 if ((neighbors[2] != 0) && (neighbors[3] != 0)) {
544 if ((neighbors[3] != 0) && (neighbors[0] != 0)) {
548 if ((neighbors[0] != 0) && (neighbors[1] != 0)) {
555 shape = MAP_CONNECTION_END;
557 if (neighbors[0] != 0) {
561 if (neighbors[1] != 0) {
565 if (neighbors[2] != 0) {
569 if (neighbors[3] != 0) {
575 shape = MAP_CONNECTION_ISOLATED;
582 shape = (shape << 4) & 0xFF0;
583 return shape | (direction & 0xF);
588 GetPos(&position, x, y, z);
594 GetPos(&position, x, y, z);
611 if (visual == NULL) {
621 sceVu0FVECTOR *vertices = (sceVu0FVECTOR *) ((
char *) model + model->
vertex_ofs);
625 for (x = 0; x <
width; x++) {
626 for (y = 0; y <
height; y++) {
627 int index = x + y *
width;
631 sceVu0CopyVector(vertices[index + 1], vertices[index]);
632 sceVu0CopyVector(vertices[index + 2], vertices[index]);
633 sceVu0CopyVector(vertices[index + 3], vertices[index]);
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];
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) {
681 GetPos(&position, max_x, 0, max_z);
686 GetPos(&position, 0, 0, min_z);
715 GetPos(&position, x, y, z);
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;
727 if (left < 0 || top < 0) {
731 if (right >= this->
width || bottom >= this->
height) {
739 if (parts->
info == NULL) {
744 GetPos(&position, x, y, z);
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);
767 if (cell_x < 0 || cell_x >= this->
width) {
771 if (cell_y < 0 || cell_y >= this->
height) {
777 if (cell_code != 0) {
799 for (
int i = 0; i < 4; i++) {
800 int extra = neighbors[i];
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)));
856 GetPos(&position, x, y, z);
857 CRect_i_ rect(position.
x - 1, position.
z - 1, 2, 2);
862 static int sound[] = {0, 1, 0, 14, 2};
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) {
869 sceVu0FVECTOR corner[4];
870 sceVu0FVECTOR normal;
872 GetPos(&position, x, 0, y);
873 memset(&surface, 0,
sizeof(surface));
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;
879 sceVu0CopyVector(corner[1], corner[0]);
880 sceVu0CopyVector(corner[2], corner[0]);
881 sceVu0CopyVector(corner[3], corner[0]);
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);
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);
917 int right = position.
x;
918 int bottom = position.
z;
922 rect.
width = right - left + 2;
923 rect.
height = bottom - top + 2;
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) {
941 parts_ids[count++] = parts_id;
945 for (
int i = 0; i < count; i++) {
946 if (parts_id == parts_ids[i]) {
952 parts_ids[count++] = parts_id;
963 for (
int x = 0; x < 16; x++) {
964 for (
int y = 0; y < 16; y++) {
971 if (x < 0 || y < 0 || x >= 16 || y >= 16) {
987 if (x == target_x && y == target_y) {
1007 sceVu0FVECTOR position;
1041 for (
int x = 0; x <
width; x++) {
1042 for (
int y = 0; y <
height; y++) {
void SetCode(int x, int y, int code)
void SetAlt(int x, int y, int altitude)
void SetMapInfo(int map_no, int area_id)
int SearchPartsID(float x, float y, float z)
void GetOffset(float *offset)
float GetAlt(int x, int y)
void GetPartsBox(CBoxVu0 *box)
void SetOffset(float x, float y, float z)
void SetGridFrame(CFrameVu1 *frame)
int GetAlt_i(int x, int y)
int DeleteMapParts(int parts_no, CMapParts *parts, float x, float y, float z)
CFrameVu1 * GetGridFrame()
int GetPartsExtra(int x, int y)
void SetSize(int width, int height, float unit_size, float unit_alt)
int CheckAreaRect(float x, float y, float z, int rect_width, int rect_height)
void SetPartsExtra(int x, int y, int parts_extra)
int SearchPartsExtra(float x, float y, float z)
int PickUpPoly(CCPoly *polygons, float x, float y, float z)
int CheckRiverChain(int x, int y, int target_x, int target_y)
int SetRiverParts(int x, int y)
int GetCode(int x, int y)
int GetPartsID(int x, int y)
int SetMapParts(int parts_id, CMapParts *parts, float x, float y, float z, int rot_y)
void SetPartsNo(int x, int y, int parts_no)
int GetPartsRect(CRect_i_ &rect, int *parts_ids, int capacity)
CEditAreaCell grid[16][16]
void SetPartsID(int x, int y, int parts_id)
int CheckArea(float x, float y, float z)
void GetPos(CVector3_i_ *position, float x, float y, float z)
void GetGrid(CVector3_f_ *snapped, float x, float y, float z)
int CheckParts(CMapParts *parts, float x, float y, float z, int rotation)
int SetRoadParts(int x, int y)
void AddAlt(int x, int y, int altitude_delta)
virtual void SetPosition(float *position)
void SetRotY(int direction)
void GetPosition(float *out_position)
int GetInfoData(int x, int y)
@ MAP_PARTS_SUBTYPE_RIVER
@ MAP_PARTS_SUBTYPE_ON_RIVER
@ MAP_PARTS_SUBTYPE_BRIDGE
struct GridPolyInfo::@1 attr