Deltarune (Chapter 3) script viewer

← back to main script listing

gml_GlobalScript_scr_pathfind_to_closest_point_32x32

(view raw script w/o annotations or w/e)
1
function 
scr_pathfind_to_closest_point_32x32
scr_pathfind_to_closest_point_32x32

function
scr_pathfind_to_closest_point_32x32(arg0, arg1, arg2, arg3, arg4)
{ with (obj_mainchara_board) { if (name == arg0) { allow_diagonals = arg4; var __destx = arg1 + 16; var __desty = arg2 + 16; if (arg1 < 12 && arg2 < 8) { __destx = 128 + (32 * arg1) + 16; __desty = 64 + (32 * arg2) + 16; } var dist = 999; var found_spot = false; if (mp_grid_path(global.grid, path, x + 16, y + 16, __destx + 2, __desty - 32, arg4) == 1) { if (distance_to_point(__destx + 2, __desty - 32) < dist) { dist = distance_to_point(__destx, __desty - 32); path_target_x = __destx + 2; path_target_y = __desty - 32; if (arg3 == -1) grab_dir = 0; found_spot = true; } } if (mp_grid_path(global.grid, path, x + 16, y + 16, __destx + 34, __desty, arg4) == 1) { if (distance_to_point(__destx + 34, __desty) < dist) { dist = distance_to_point(__destx + 34, __desty); path_target_x = __destx + 34; path_target_y = __desty; if (arg3 == -1) grab_dir = 3; found_spot = true; } } if (mp_grid_path(global.grid, path, x + 16, y + 16, __destx - 32, __desty, arg4) == 1) { if (distance_to_point(__destx - 32, __desty) < dist) { dist = distance_to_point(__destx - 32, __desty); path_target_x = __destx - 32; path_target_y = __desty; if (arg3 == -1) grab_dir = 1; found_spot = true; } } if (mp_grid_path(global.grid, path, x + 16, y + 16, __destx, __desty + 30, arg4) == 1) { if (distance_to_point(__destx, __desty + 30) < dist) { dist = distance_to_point(__destx, __desty + 30); path_target_x = __destx + 2; path_target_y = __desty + 30; if (arg3 == -1) grab_dir = 2; found_spot = true; } } if (found_spot == true) { path_end(); is_moving_timer = 0; is_moving = true; if (arg0 == "ralsei") follow = false; path_end_facing = grab_dir; } else { show_debug_message("PATHFINDING ERROR 5: cannot path to target location"); } } } }
(arg0, arg1, arg2, arg3, arg4)
2
{
3
    with (obj_mainchara_board)
4
    {
5
        if (name == arg0)
6
        {
7
            allow_diagonals = arg4;
8
            var __destx = arg1 + 16;
9
            var __desty = arg2 + 16;
10
            if (arg1 < 12 && arg2 < 8)
11
            {
12
                __destx = 128 + (32 * arg1) + 16;
13
                __desty = 64 + (32 * arg2) + 16;
14
            }
15
            var dist = 999;
16
            var found_spot = false;
17
            if (mp_grid_path(global.grid, path, x + 16, y + 16, __destx + 2, __desty - 32, arg4) == 1)
18
            {
19
                if (distance_to_point(__destx + 2, __desty - 32) < dist)
20
                {
21
                    dist = distance_to_point(__destx, __desty - 32);
22
                    path_target_x = __destx + 2;
23
                    path_target_y = __desty - 32;
24
                    if (arg3 == -1)
25
                        grab_dir = 0;
26
                    found_spot = true;
27
                }
28
            }
29
            if (mp_grid_path(global.grid, path, x + 16, y + 16, __destx + 34, __desty, arg4) == 1)
30
            {
31
                if (distance_to_point(__destx + 34, __desty) < dist)
32
                {
33
                    dist = distance_to_point(__destx + 34, __desty);
34
                    path_target_x = __destx + 34;
35
                    path_target_y = __desty;
36
                    if (arg3 == -1)
37
                        grab_dir = 3;
38
                    found_spot = true;
39
                }
40
            }
41
            if (mp_grid_path(global.grid, path, x + 16, y + 16, __destx - 32, __desty, arg4) == 1)
42
            {
43
                if (distance_to_point(__destx - 32, __desty) < dist)
44
                {
45
                    dist = distance_to_point(__destx - 32, __desty);
46
                    path_target_x = __destx - 32;
47
                    path_target_y = __desty;
48
                    if (arg3 == -1)
49
                        grab_dir = 1;
50
                    found_spot = true;
51
                }
52
            }
53
            if (mp_grid_path(global.grid, path, x + 16, y + 16, __destx, __desty + 30, arg4) == 1)
54
            {
55
                if (distance_to_point(__destx, __desty + 30) < dist)
56
                {
57
                    dist = distance_to_point(__destx, __desty + 30);
58
                    path_target_x = __destx + 2;
59
                    path_target_y = __desty + 30;
60
                    if (arg3 == -1)
61
                        grab_dir = 2;
62
                    found_spot = true;
63
                }
64
            }
65
            if (found_spot == true)
66
            {
67
                path_end();
68
                is_moving_timer = 0;
69
                is_moving = true;
70
                if (arg0 == "ralsei")
71
                    follow = false;
72
                path_end_facing = grab_dir;
73
            }
74
            else
75
            {
76
                show_debug_message("PATHFINDING ERROR 5: cannot path to target location");
77
            }
78
        }
79
    }
80
}