NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_wm_en_path.cpp
1#include <game/bases/d_wm_en_path.hpp>
2#include <lib/MSL_C/string.h>
3
4dWmEnPath_c::dWmEnPath_c() : mpCurrentPoint(nullptr) {
5 for (int i = 0; i < ARRAY_SIZE(mPoints); i++) {
6 mPoints[i].mpName = nullptr;
7 mPoints[i].mPointIndex = -1;
8 mPoints[i].mIndex = -1;
9 mPoints[i].mpPrev = nullptr;
10 mPoints[i].mpNext = nullptr;
11 }
12 mAdvancePoint = true;
13}
14
15dWmEnPath_c::~dWmEnPath_c() {}
16
17bool dWmEnPath_c::init(const char **names, int count, dWmConnect_c *connect, bool cyclic, PATH_DIRECTION_e dir) {
18 for (int i = 0; i < count; i++) {
19 mPoints[i].mpName = names[i];
20 mPoints[i].mIndex = i;
21 if (i == 0) {
22 if (cyclic) {
23 mPoints[i].mpPrev = &mPoints[count - 1];
24 } else {
25 mPoints[i].mpPrev = nullptr;
26 }
27 } else {
28 mPoints[i].mpPrev = &mPoints[i - 1];
29 }
30 if (i == count - 1) {
31 if (cyclic) {
32 mPoints[i].mpNext = &mPoints[0];
33 } else {
34 mPoints[i].mpNext = nullptr;
35 }
36 } else {
37 mPoints[i].mpNext = &mPoints[i + 1];
38 }
39 int pointIdx = 0;
40 while (true) {
41 if (strcmp(names[i], connect->GetPointFromIndex(pointIdx)->name) == 0) {
42 mPoints[i].mPointIndex = pointIdx;
43 break;
44 }
45 pointIdx++;
46 }
47 }
48 SetStartPoint(0);
49 mDir1 = dir;
50 mDir2 = dir;
51 return true;
52}
53
54void dWmEnPath_c::SetStartPoint(int i) {
55 mpCurrentPoint = &mPoints[i];
56}
57
58int dWmEnPath_c::GetNextPointIdx() {
59 return GetNextPointInfo(false)->mPointIndex;
60}
61
62int dWmEnPath_c::GetPathPointNo(const char *name) {
63 for (int i = 0; i < (int) ARRAY_SIZE(mPoints); i++) {
64 if (strcmp(mPoints[i].mpName, name) == 0) {
65 return i;
66 }
67 if (mPoints[i].mpNext == nullptr) {
68 break;
69 }
70 }
71 return -1;
72}
73
74dWmPathPoint_s *dWmEnPath_c::GetNextPointInfo(bool updateDirection) {
75 if (!mAdvancePoint) {
76 return mpCurrentPoint;
77 }
78 dWmPathPoint_s *res = nullptr;
79 if (mDir1 == PATH_DIR_NORMAL) {
80 res = mpCurrentPoint->mpNext;
81 if (res == nullptr) {
82 res = mpCurrentPoint->mpPrev;
83 if (updateDirection) {
84 mDir1 = PATH_DIR_REVERSE;
85 }
86 }
87 } else if (mDir1 == PATH_DIR_REVERSE) {
88 res = mpCurrentPoint->mpPrev;
89 if (res == nullptr) {
90 res = mpCurrentPoint->mpNext;
91 if (updateDirection) {
92 mDir1 = PATH_DIR_NORMAL;
93 }
94 }
95 }
96 return res;
97}
98
99void dWmEnPath_c::UpdatePoint() {
100 mpCurrentPoint = GetNextPointInfo(true);
101}
102
103bool dWmEnPath_c::isPointIn(int pointIndex) {
104 for (int i = 0; i < ARRAY_SIZE(mPoints); i++) {
105 if (mPoints[i].mPointIndex == pointIndex) {
106 return true;
107 }
108 }
109 return false;
110}
bool init(const char **names, int count, dWmConnect_c *connect, bool cyclic, PATH_DIRECTION_e dir)