summaryrefslogtreecommitdiff
path: root/src/d/d_path.cpp
blob: 7c6c905ed5d750048e716e9d3a1a819d123af2e2 (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
//
// Generated by dtk
// Translation Unit: d_path.cpp
//

#include "d/dolzel.h" // IWYU pragma: keep
#include "d/d_path.h"
#include "d/d_com_inf_game.h"
#include "JSystem/JUtility/JUTAssert.h"

/* 80080018-8008010C       .text dPath_GetPnt__FP5dPathi */
dPnt* dPath_GetPnt(dPath* path, int pnt_index) {
    JUT_ASSERT(30, path != NULL);
    JUT_ASSERT(31, 0 <= pnt_index && pnt_index < path->m_num);

    if (path == NULL || path->m_points == NULL || 0 > pnt_index || pnt_index >= path->m_num)
        return NULL;
    else
        return &path->m_points[pnt_index];
}

/* 8008010C-80080218       .text dPath_GetRoomPath__Fii */
dPath* dPath_GetRoomPath(int path_index, int room_no) {
    dStage_dPath_c * pd;
    if (room_no == -1) {
        pd = dComIfGp_getStage().getPath2Inf();
    } else {
        JUT_ASSERT(0x3d, 0 <= room_no && room_no < 64);
        dStage_roomDt_c * pRoom = dComIfGp_roomControl_getStatusRoomDt(room_no);
        if (pRoom == NULL)
            return NULL;
        pd = pRoom->getPath2Inf();
    }

    if (pd == NULL || 0 > path_index || path_index >= pd->num)
        return NULL;
    else
        return &pd->m_path[path_index];
}

/* 80080218-80080340       .text dPath_GetNextRoomPath__FP5dPathi */
dPath* dPath_GetNextRoomPath(dPath* path, int room_no) {
    dStage_dPath_c * pd;
    if (room_no == -1) {
        pd = dComIfGp_getStage().getPath2Inf();
    } else {
        dStage_roomDt_c * pRoom = dComIfGp_roomControl_getStatusRoomDt(room_no);
        if (pRoom == NULL)
            return NULL;
        pd = pRoom->getPath2Inf();
    }

    s32 next_id = path->m_nextID;
    if (pd == NULL || (next_id & 0xFFFF) == 0xFFFF) {
        return NULL;
    } else {
        JUT_ASSERT(0x72, 0 <= next_id && next_id < pd->num);
        if (0 > next_id || next_id >= pd->num)
            return NULL;
        else
            return &pd->m_path[next_id];
    }
}

/* 80080340-800804A4       .text dPath_GetPolyRoomPathVec__FR13cBgS_PolyInfoP4cXyzPi */
bool dPath_GetPolyRoomPathVec(cBgS_PolyInfo& polyInfo, cXyz* pDstPos, int* pDstArg0) {
    int room_no = dComIfG_Bgsp()->GetRoomId(polyInfo);
    int path_index = dComIfG_Bgsp()->GetRoomPathId(polyInfo);

    pDstPos->x = 0.0f;
    pDstPos->y = 0.0f;
    pDstPos->z = 0.0f;
    *pDstArg0 = 0;

    if (room_no == -1)
        return FALSE;

    dPath * path = dPath_GetRoomPath(path_index, room_no);
    if (path == NULL)
        return FALSE;

    if (path->field4_0x6 != 0xFF && dComIfGs_isSwitch(path->field4_0x6, room_no))
        return FALSE;

    int pnt_no = dComIfG_Bgsp()->GetRoomPathPntNo(polyInfo);
    if (pnt_no == 0xFF || pnt_no < 0 || pnt_no >= path->m_num)
        return FALSE;

    dPnt *point = &path->m_points[pnt_no];
    dPnt *next_point;
    if (pnt_no == path->m_num - 1)
        next_point = &path->m_points[0];
    else
        next_point = &path->m_points[pnt_no + 1];
    pDstPos->x = next_point->m_position.x - point->m_position.x;
    pDstPos->y = next_point->m_position.y - point->m_position.y;
    pDstPos->z = next_point->m_position.z - point->m_position.z;
    *pDstArg0 = path->mArg0;
    return TRUE;
}