♻️Apply point positioning to all remaning entities
This commit is contained in:
parent
d096a85803
commit
2bd13451a1
43 changed files with 1286 additions and 1375 deletions
|
|
@ -64,20 +64,20 @@ int FindPath(bool (*PosOk)(int, int, int), int PosOkArg, int sx, int sy, int dx,
|
|||
path_start = path_new_step();
|
||||
path_start->g = 0;
|
||||
path_start->h = path_get_h_cost(sx, sy, dx, dy);
|
||||
path_start->x = sx;
|
||||
path_start->position.x = sx;
|
||||
path_start->f = path_start->h + path_start->g;
|
||||
path_start->y = sy;
|
||||
path_start->position.y = sy;
|
||||
path_2_nodes->NextNode = path_start;
|
||||
// A* search until we find (dx,dy) or fail
|
||||
while ((next_node = GetNextPath())) {
|
||||
// reached the end, success!
|
||||
if (next_node->x == dx && next_node->y == dy) {
|
||||
if (next_node->position.x == dx && next_node->position.y == dy) {
|
||||
current = next_node;
|
||||
path_length = 0;
|
||||
while (current->Parent != nullptr) {
|
||||
if (path_length >= MAX_PATH_LENGTH)
|
||||
break;
|
||||
pnode_vals[path_length++] = path_directions[3 * (current->y - current->Parent->y) - current->Parent->x + 4 + current->x];
|
||||
pnode_vals[path_length++] = path_directions[3 * (current->position.y - current->Parent->position.y) - current->Parent->position.x + 4 + current->position.x];
|
||||
current = current->Parent;
|
||||
}
|
||||
if (path_length != MAX_PATH_LENGTH) {
|
||||
|
|
@ -119,7 +119,7 @@ int path_get_h_cost(int sx, int sy, int dx, int dy)
|
|||
*/
|
||||
int path_check_equal(PATHNODE *pPath, int dx, int dy)
|
||||
{
|
||||
if (pPath->x == dx || pPath->y == dy)
|
||||
if (pPath->position.x == dx || pPath->position.y == dy)
|
||||
return 2;
|
||||
|
||||
return 3;
|
||||
|
|
@ -156,7 +156,7 @@ PATHNODE *GetNextPath()
|
|||
bool path_solid_pieces(PATHNODE *pPath, int dx, int dy)
|
||||
{
|
||||
bool rv = true;
|
||||
switch (path_directions[3 * (dy - pPath->y) + 3 - pPath->x + 1 + dx]) {
|
||||
switch (path_directions[3 * (dy - pPath->position.y) + 3 - pPath->position.x + 1 + dx]) {
|
||||
case 5:
|
||||
rv = !nSolidTable[dPiece[dx][dy + 1]] && !nSolidTable[dPiece[dx + 1][dy]];
|
||||
break;
|
||||
|
|
@ -185,8 +185,8 @@ bool path_get_path(bool (*PosOk)(int, int, int), int PosOkArg, PATHNODE *pPath,
|
|||
bool ok;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
dx = pPath->x + pathxdir[i];
|
||||
dy = pPath->y + pathydir[i];
|
||||
dx = pPath->position.x + pathxdir[i];
|
||||
dy = pPath->position.y + pathydir[i];
|
||||
ok = PosOk(PosOkArg, dx, dy);
|
||||
if ((ok && path_solid_pieces(pPath, dx, dy)) || (!ok && dx == x && dy == y)) {
|
||||
if (!path_parent_path(pPath, dx, dy, x, y))
|
||||
|
|
@ -253,8 +253,7 @@ bool path_parent_path(PATHNODE *pPath, int dx, int dy, int sx, int sy)
|
|||
dxdy->g = next_g;
|
||||
dxdy->h = path_get_h_cost(dx, dy, sx, sy);
|
||||
dxdy->f = next_g + dxdy->h;
|
||||
dxdy->x = dx;
|
||||
dxdy->y = dy;
|
||||
dxdy->position = {dx,dy};
|
||||
// add it to the frontier
|
||||
path_next_node(dxdy);
|
||||
|
||||
|
|
@ -275,7 +274,7 @@ PATHNODE *path_get_node1(int dx, int dy)
|
|||
{
|
||||
PATHNODE *result = path_2_nodes->NextNode;
|
||||
while (result != nullptr) {
|
||||
if (result->x == dx && result->y == dy)
|
||||
if (result->position.x == dx && result->position.y == dy)
|
||||
return result;
|
||||
result = result->NextNode;
|
||||
}
|
||||
|
|
@ -289,7 +288,7 @@ PATHNODE *path_get_node2(int dx, int dy)
|
|||
{
|
||||
PATHNODE *result = pnode_ptr->NextNode;
|
||||
while (result != nullptr) {
|
||||
if (result->x == dx && result->y == dy)
|
||||
if (result->position.x == dx && result->position.y == dy)
|
||||
return result;
|
||||
result = result->NextNode;
|
||||
}
|
||||
|
|
@ -337,10 +336,10 @@ void path_set_coords(PATHNODE *pPath)
|
|||
if (PathAct == nullptr)
|
||||
break;
|
||||
|
||||
if (PathOld->g + path_check_equal(PathOld, PathAct->x, PathAct->y) < PathAct->g) {
|
||||
if (path_solid_pieces(PathOld, PathAct->x, PathAct->y)) {
|
||||
if (PathOld->g + path_check_equal(PathOld, PathAct->position.x, PathAct->position.y) < PathAct->g) {
|
||||
if (path_solid_pieces(PathOld, PathAct->position.x, PathAct->position.y)) {
|
||||
PathAct->Parent = PathOld;
|
||||
PathAct->g = PathOld->g + path_check_equal(PathOld, PathAct->x, PathAct->y);
|
||||
PathAct->g = PathOld->g + path_check_equal(PathOld, PathAct->position.x, PathAct->position.y);
|
||||
PathAct->f = PathAct->g + PathAct->h;
|
||||
path_push_active_step(PathAct);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue