DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
editpartsinfo.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3
4#include "editpartsinfo.hpp"
5
6#include <cstring>
7
8#include "editatra.hpp"
9#include "savedata.hpp"
10
18int CheckPartsInfo(EDITPARTS_INFO *info);
19
21 if ((index < 0) || (index >= 0x18)) {
22 return NULL;
23 }
24
25 return &parts[index];
26}
27
29 EDITPARTS_INFO *info = GetPartsInfo(index);
30
31 if (info == NULL) {
32 return 0;
33 }
34
35 for (int i = 0; i < 6; i++) {
36 // A negative identifier is an unused slot, so it asks for nothing.
37 if (info->elements[i].id >= 0 && info->elements[i].enabled == 0) {
38 return 0;
39 }
40 }
41
42 return 1;
43}
44
45void CEditPartsInfo::SetCompEvent(int index, int completed) {
46 EDITPARTS_INFO *info = GetPartsInfo(index);
47
48 if (info != NULL) {
49 if (completed != 0) {
50 info->completion_flags |= 1;
51 return;
52 }
53
54 info->completion_flags &= ~1;
55 }
56}
57
59 EDITPARTS_INFO *info = GetPartsInfo(index);
60
61 if (info == NULL) {
62 return 0;
63 }
64
65 return (info->completion_flags & 1) != 0;
66}
67
69 if (index < 0 || index >= 24) {
70 return 0;
71 }
72
73 return request[index];
74}
75
77 int remaining = 0;
78
79 for (int i = index + 1; i < 24; i++) {
81
82 if (info == NULL) {
83 break;
84 }
85
86 if (CheckPartsInfo(info) != 0) {
87 remaining++;
88 }
89 }
90
91 return remaining;
92}
93
95 for (;;) {
96 index++;
97 EDITPARTS_INFO *info = GetPartsInfo(index);
98
99 if (info != NULL) {
100 if (CheckPartsInfo(info) != 0) {
101 return index;
102 }
103 } else {
104 return -1;
105 }
106 }
107}
108
110 for (int plot = 0; plot < 24; plot++) {
111 parts[plot].placed = false;
112 }
113}
114
115void CEditPartsInfo::Save(int georama_no, CSaveData *save_data) {
116 int plot;
117 SV_GEORAMA_DATA *georama = save_data->GetGrdData(georama_no);
118
119 if (georama == NULL) {
120 return;
121 }
122
123 georama->request_count = parts_max;
124
125 for (plot = 0; plot < 24; plot++) {
126 georama->request_complete[plot] = request[plot];
127 SV_EDIT_PARTS_INFO *saved_part = save_data->GetEditPartsInfo(georama_no, plot);
128
129 if (saved_part == NULL) {
130 continue;
131 }
132
133 saved_part->obtained = parts[plot].obtained;
134 saved_part->completion_flags = parts[plot].completion_flags;
135 saved_part->placed = parts[plot].placed;
136 saved_part->stock = parts[plot].stock;
137
138 for (int element = 0; element < 6; element++) {
139 saved_part->element_enabled[element] = parts[plot].elements[element].enabled;
140 }
141 }
142}
143
144void CEditPartsInfo::Load(int georama_no, CSaveData *save_data, int load_requests) {
145 int plot;
146
147 if (georama_no < 0 || georama_no >= 6) {
148 return;
149 }
150
151 Initialize(georama_no);
152 SV_GEORAMA_DATA *georama = save_data->GetGrdData(georama_no);
153
154 if (georama == NULL) {
155 return;
156 }
157
158 if (load_requests != 0) {
159 parts_max = georama->request_count;
160 }
161
162 for (plot = 0; plot < 24; plot++) {
163 SV_EDIT_PARTS_INFO *saved_part = save_data->GetEditPartsInfo(georama_no, plot);
164
165 if (saved_part == NULL) {
166 continue;
167 }
168
169 parts[plot].obtained = saved_part->obtained;
170 parts[plot].completion_flags = saved_part->completion_flags;
171
172 if (load_requests != 0) {
173 parts[plot].placed = saved_part->placed;
174 request[plot] = georama->request_complete[plot];
175 }
176
177 if (saved_part->stock > 0) {
178 parts[plot].stock = saved_part->stock;
179 }
180
181 for (int element = 0; element < 6; element++) {
182 parts[plot].elements[element].enabled = saved_part->element_enabled[element];
183 }
184 }
185}
186
187void CEditPartsInfo::Initialize(int georama_no) {
188 int plot;
189 int name_no;
190 char **names;
191 int element;
192 EDIT_PARTS_ATRA *source;
193 EDIT_PARTS_ATRA empty_part;
194
195 memset(&empty_part, 0, sizeof(empty_part));
196
197 for (element = 0; element < 6; element++) {
198 empty_part.elements[element].required_element = -1;
199 }
200
201 unk_1624 = 0;
202
203 for (plot = 0; plot < 24; plot++) {
204 if (georama_no < 0 || georama_no >= 6) {
205 source = &empty_part;
206 } else {
207 source = GetEditAtraPartsData(georama_no, plot);
208 }
209
210 parts[plot].parts_no = plot;
211 parts[plot].obtained = 0;
212 parts[plot].completion_flags = 0;
213 parts[plot].stock = source->max;
214 parts[plot].placed = false;
215 parts[plot].tex_no = source->tex_no;
216 parts[plot].kind = source->kind;
217
218 for (element = 0; element < 6; element++) {
219 parts[plot].elements[element].id = source->elements[element].id;
220 parts[plot].elements[element].required_element = source->elements[element].required_element;
221 parts[plot].elements[element].enabled = false;
222 names = parts[plot].elements[element].names;
223 names[0] = NULL;
224
225 for (name_no = 0; name_no < 4; name_no++) {
226 names[name_no] = NULL;
227
228 if (source->elements[element].names[name_no] != NULL && source->elements[element].names[name_no][0] != '\0') {
229 names[name_no] = source->elements[element].names[name_no];
230 }
231 }
232
233 parts[plot].elements[element].npc_no = source->elements[element].npc_no;
234 }
235 }
236}
237
239 parts[index].parts_no = index;
240 parts[index].obtained = 0;
241 parts[index].completion_flags = 0;
242 parts[index].placed = false;
243
244 for (int element = 0; element < 6; element++) {
245 }
246
247 parts[index].width = header->width;
248 parts[index].height = header->height;
249 parts[index].header = header;
250}
int GetCompEvent(int index)
void Initialize(int georama_no)
void Save(int georama_no, CSaveData *save_data)
int GetNextParts(int index)
int GetNextPartsNum(int index)
int GetRequest(int index)
int CheckComplete(int index)
void SetCompEvent(int index, int completed)
EDITPARTS_INFO * GetPartsInfo(int index)
EDITPARTS_INFO parts[24]
void Load(int georama_no, CSaveData *save_data, int load_requests)
SV_GEORAMA_DATA * GetGrdData(int georama_no)
Definition savedata.cpp:175
SV_EDIT_PARTS_INFO * GetEditPartsInfo(int georama_no, int plot_no)
Definition savedata.cpp:183
EPARTS_INFO_HEADER * header
EDITPARTS_ELEMENT elements[6]
EDIT_CHIP_ATTACH_DATA elements[6]
s32 request_complete[24]
Definition savedata.hpp:97