summaryrefslogtreecommitdiff
path: root/src/d/d_path.cpp
blob: a01cfdc8a6b4967d458b0b36a3c3452cd6981906 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
 * d_path.cpp
 * dolzel2 - Room Path & Point Management
 */

#include "d/dolzel.h" // IWYU pragma: keep

#include "d/d_path.h"
#include "d/d_com_inf_game.h"

dPnt* dPath_GetPnt(dPath const* path, int pnt_index) {
    if (path == NULL || path->m_points == NULL || pnt_index < 0 || pnt_index >= path->m_num) {
        return NULL;
    }

    return &path->m_points[pnt_index];
}

dPath* dPath_GetRoomPath(int path_index, int room_no) {
    dStage_dPath_c* path;

    if (room_no == -1) {
        path = dComIfGp_getStage()->getPath2Inf();
    } else {
        dStage_roomDt_c* roomDt = dComIfGp_roomControl_getStatusRoomDt(room_no);
        if (roomDt == NULL) {
            return NULL;
        }

        path = roomDt->getPath2Inf();
    }

    if (path == NULL || path_index < 0 || path_index >= path->m_num) {
        return NULL;
    }

    return &path->m_path[path_index];
}

dPath* dPath_GetNextRoomPath(dPath const* p_path, int room_no) {
    dStage_dPath_c* path;

    if (room_no == -1) {
        path = dComIfGp_getStage()->getPath2Inf();
    } else {
        dStage_roomDt_c* roomDt = dComIfGp_roomControl_getStatusRoomDt(room_no);
        if (roomDt == NULL) {
            return NULL;
        }

        path = roomDt->getPath2Inf();
    }

    int next_id = p_path->m_nextID;
    if (path == NULL || next_id == 0xFFFF) {
        return NULL;
    }

    if (next_id < 0 || next_id >= path->m_num) {
        return NULL;
    }

    return &path->m_path[next_id];
}

#if !PLATFORM_GCN  // Fakematch due to differing return type on non-GCN platforms
int dPath_GetPolyRoomPathVec(cBgS_PolyInfo const& poly, cXyz* p_pathVec, int* param_2) {
#else
u8 dPath_GetPolyRoomPathVec(cBgS_PolyInfo const& poly, cXyz* p_pathVec, int* param_2) {
#endif
    int roomId = dComIfG_Bgsp().GetRoomId(poly);
    int roomPathId = dComIfG_Bgsp().GetRoomPathId(poly);

    p_pathVec->x = 0.0f;
    p_pathVec->y = 0.0f;
    p_pathVec->z = 0.0f;
    *param_2 = 0;
    
    if (roomId == -1) {
        return 0;
    }

    dPath* path = dPath_GetRoomPath(roomPathId, roomId);
    if (path == NULL) {
        return 0;
    }

    if (path->field_0x6 != 0xFF && dComIfGs_isSwitch(path->field_0x6, roomId)) {
        return 0;
    }

    int pnt_no = dComIfG_Bgsp().GetRoomPathPntNo(poly);
    if (pnt_no == 0xFF || pnt_no < 0 || pnt_no >= path->m_num) {
        return 0;
    }

    dPnt* pnt_start = path->m_points;
    dPnt* pnt_end = &pnt_start[pnt_no];

    dPnt* pnt_begin;
    if (pnt_no == path->m_num - 1) {
        pnt_begin = pnt_start;
    } else {
        pnt_begin = &pnt_start[pnt_no + 1];
    }

    p_pathVec->x = pnt_begin->m_position.x - pnt_end->m_position.x;
    p_pathVec->y = pnt_begin->m_position.y - pnt_end->m_position.y;
    p_pathVec->z = pnt_begin->m_position.z - pnt_end->m_position.z;
    *param_2 = path->field_0x4;

    return 1;
}

#if VERSION == VERSION_SHIELD_DEBUG
void dPath_Ct() {
    #if DEBUG
    #endif
}

void dPath_Dt() {
    #if DEBUG
    #endif
}

void dPath_Move() {}

void dPath_Draw() {
    #if DEBUG
    #endif
}
#endif