DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
stockitem.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 459
4
5#include "stockitem.hpp"
6#include "types.h"
7
8#include <cstdio>
9#include <cstring>
10
11#include "itemdata.hpp"
12#include "menu_draw.hpp"
13
15int sort_top_type__3 = ITEM_SORT_FOOD;
16
18int asort_top_type__3 = 1;
19
21int sort_table__3[9] = {9, 0, 1, 2, 3, 4, 5, 6, 7};
22
24int asort_table__3[5] = {5, 1, 2, 3, 4};
25
30 int values[3];
31};
32
34StockSlotCounts LIT_459 = {
35 {60, 30, 30}
36};
37
39 memset(this->dungeon_items, 0, sizeof(this->dungeon_items));
40 memset(this->dungeon_item_vols, 0, sizeof(this->dungeon_item_vols));
41 memset(this->weapons, 0, sizeof(this->weapons));
42 memset(this->attachments, 0, sizeof(this->attachments));
43}
44
45int CStockItem::SearchSpace(int slot_index, int search_space) {
46 int item_no = 0;
47
48 switch (search_space) {
50 item_no = this->dungeon_items[slot_index];
51
52 if ((item_no >= ITEM_DUNGEON_START) && (item_no <= ITEM_DUNGEON_END)) {
53 return item_no;
54 }
55
56 item_no = 0;
57 break;
59 if (this->weapons[slot_index].item_no >= ITEM_WEAPON_START) {
60 item_no = this->weapons[slot_index].item_no;
61 }
62
63 break;
65 item_no = this->attachments[slot_index].item_no;
66
67 if (item_no < ITEM_ATTACH_START) {
68 item_no = 0;
69 return item_no;
70 }
71
72 break;
73 }
74
75 return item_no;
76}
77
78void CStockItem::SetItemToPos(int slot_index, s16 *item_no, s16 *volume) {
79 s16 *item_slot = &this->dungeon_items[slot_index];
80 s16 old_item_no = *item_slot;
81 *item_slot = *item_no;
82 *item_no = old_item_no;
83
84 s16 *volume_slot = &this->dungeon_item_vols[slot_index];
85 s16 old_volume = *volume_slot;
86 *volume_slot = *volume;
87 *volume = old_volume;
88}
89
90void CStockItem::GetItemInfo(int slot_index, s16 *item_no, s16 *volume) {
91 *item_no = this->dungeon_items[slot_index];
92 *volume = this->dungeon_item_vols[slot_index];
93}
94
95void CStockItem::SetWepToPos(int slot_index, WEAPON_HAVE *weapon) {
96 WEAPON_HAVE *slot = &this->weapons[slot_index];
97 WEAPON_HAVE old_weapon;
98 memcpy(&old_weapon, slot, sizeof(WEAPON_HAVE));
99 memcpy(slot, weapon, sizeof(WEAPON_HAVE));
100 memcpy(weapon, &old_weapon, sizeof(WEAPON_HAVE));
101}
102
103void CStockItem::GetWeaponInfo(int slot_index, WEAPON_HAVE *weapon) {
104 memcpy(weapon, &this->weapons[slot_index], sizeof(WEAPON_HAVE));
105}
106
107void CStockItem::SetAttachToPos(int slot_index, ATTACH_LIST *attachment) {
108 ATTACH_LIST *slot = &this->attachments[slot_index];
109 ATTACH_LIST old_attachment;
110 memcpy(&old_attachment, slot, sizeof(ATTACH_LIST));
111 memcpy(slot, attachment, sizeof(ATTACH_LIST));
112 memcpy(attachment, &old_attachment, sizeof(ATTACH_LIST));
113}
114
115void CStockItem::GetAttachInfo(int slot_index, ATTACH_LIST *attachment) {
116 memcpy(attachment, &this->attachments[slot_index], sizeof(ATTACH_LIST));
117}
118
119int CStockItem::SearchItem(int item_no) {
120 if (item_no < ITEM_ATTACH_START) {
121 return 0;
122 }
123
124 int found = false;
125
126 if ((item_no > 0 && item_no < ITEM_ATTACH_START) || item_no >= ITEM_WEAPON_START) {
127 for (int slot_index = 0; slot_index < 30; slot_index++) {
128 if (this->weapons[slot_index].item_no == item_no) {
129 found = true;
130 break;
131 }
132 }
133 } else if (item_no >= ITEM_ATTACH_START && item_no < ITEM_DUNGEON_START) {
134 for (int slot_index = 0; slot_index < 30; slot_index++) {
135 if (this->attachments[slot_index].item_no == item_no) {
136 found = true;
137 break;
138 }
139 }
140 } else if (item_no >= ITEM_DUNGEON_START && item_no <= ITEM_DUNGEON_END) {
141 for (int slot_index = 0; slot_index < 60; slot_index++) {
142 if (this->dungeon_items[slot_index] == item_no) {
143 found = true;
144 break;
145 }
146 }
147 }
148
149#ifndef PAL
150 if (found != 0) {
151 printf("itemNo [%d] is exist!\n", item_no);
152 } else {
153 printf("itemNo [%d] is none!\n", item_no);
154 }
155#endif
156
157 return found;
158}
159
160int CompChargeItem(int first_item_no, int second_item_no) {
161 ITEM_DATA *first = GetItemData(first_item_no);
162 ITEM_DATA *second = GetItemData(second_item_no);
163
164 int first_priority = 0;
165 int second_priority = 0;
166
167 if (first != NULL) {
168 first_priority = sort_table__3[first->sort_key];
169 }
170
171 if (second != NULL) {
172 second_priority = sort_table__3[second->sort_key];
173 }
174
175 if (first_item_no < ITEM_DUNGEON_START) {
176 first_priority = 9;
177 }
178
179 if (second_item_no < ITEM_DUNGEON_START) {
180 second_priority = 9;
181 }
182
183 if (second_priority < first_priority) {
184 return 1;
185 }
186
187 if (first_priority < second_priority) {
188 return -1;
189 }
190
191 if (second_item_no < first_item_no) {
192 return 1;
193 }
194
195 if (first_item_no < second_item_no) {
196 return -1;
197 }
198
199 return 0;
200}
201
203 int sort_type = sort_top_type__3;
204 int first_slot;
205 int second_slot;
206 int moved;
207
208 for (first_slot = 0; first_slot < ITEM_SORT_COUNT; first_slot++) {
209 sort_table__3[sort_type] = first_slot;
210 sort_type++;
211
212 if (sort_type >= ITEM_SORT_COUNT) {
213 sort_type = ITEM_SORT_NONE;
214 }
215 }
216
217 sort_table__3[ITEM_SORT_NONE] = 9;
218
219 moved = false;
220
221 for (first_slot = 0; first_slot < 59; first_slot++) {
222 for (second_slot = first_slot + 1; second_slot < 60; second_slot++) {
223 if (CompChargeItem(this->dungeon_items[first_slot], this->dungeon_items[second_slot]) > 0) {
224 MenuDataSwap(&this->dungeon_items[first_slot], &this->dungeon_items[second_slot]);
225 MenuDataSwap(&this->dungeon_item_vols[first_slot], &this->dungeon_item_vols[second_slot]);
226 moved = true;
227 }
228 }
229 }
230
231 return moved;
232}
233
235 for (int attempt = 0; attempt < ITEM_SORT_COUNT; attempt++) {
236 if (SeitonChargeItemBoardSub() != 0) {
237 break;
238 }
239
240 sort_top_type__3++;
241
242 if (sort_top_type__3 >= ITEM_SORT_COUNT) {
243 sort_top_type__3 = ITEM_SORT_FOOD;
244 }
245 }
246}
247
251static int CompChargeAttach(ATTACH_LIST *first, ATTACH_LIST *second) {
252 int first_priority = asort_table__3[GetAttachKind(first->item_no)];
253 int second_priority = asort_table__3[GetAttachKind(second->item_no)];
254 int second_item_no;
255 int first_item_no;
256
257 first_item_no = first->item_no;
258
259 if (ITEM_ATTACH_START > first_item_no) {
260 first_priority = 5;
261 }
262
263 second_item_no = second->item_no;
264
265 if (ITEM_ATTACH_START > second_item_no) {
266 second_priority = 5;
267 }
268
269 if (second_priority < first_priority) {
270 return 1;
271 }
272
273 if (first_priority < second_priority) {
274 return -1;
275 }
276
277 if (first_item_no > second_item_no) {
278 return 1;
279 }
280
281 if (first_item_no < second_item_no) {
282 return -1;
283 }
284
285 return 0;
286}
287
291static int SeitonAttachBoardSub(ATTACH_LIST *attachments) {
292 int sort_type = asort_top_type__3;
293 int first_slot;
294 int second_slot;
295 int moved;
296
297 for (first_slot = 0; first_slot < 5; first_slot++) {
298 asort_table__3[sort_type] = first_slot;
299 sort_type++;
300
301 if (sort_type >= 5) {
302 sort_type = 0;
303 }
304 }
305
306 asort_table__3[0] = 5;
307 moved = false;
308
309 for (first_slot = 0; first_slot < 29; first_slot++) {
310 for (second_slot = first_slot + 1; second_slot < 30; second_slot++) {
311 if (CompChargeAttach(&attachments[first_slot], &attachments[second_slot]) > 0) {
312 MenuDataSwap(&attachments[first_slot], &attachments[second_slot]);
313 moved = true;
314 }
315 }
316 }
317
318 return moved;
319}
320
322 for (int attempt = 0; attempt < 5; attempt++) {
323 if (SeitonAttachBoardSub(this->attachments) != 0) {
324 break;
325 }
326
327 asort_top_type__3++;
328
329 if (asort_top_type__3 >= 5) {
330 asort_top_type__3 = 0;
331 }
332 }
333}
334
335int CStockItem::GetNowModeSpace(int search_space) {
336 int empty_slot = -1;
337 StockSlotCounts slot_counts = LIT_459;
338
339 for (int slot_index = 0; slot_index < slot_counts.values[search_space]; slot_index++) {
340 if (SearchSpace(slot_index, search_space) == 0) {
341 empty_slot = slot_index;
342 break;
343 }
344 }
345
346 return empty_slot;
347}
ATTACH_LIST attachments[30]
Definition stockitem.hpp:34
void SeitonItem()
int SearchSpace(int slot_index, int search_space)
Definition stockitem.cpp:45
int SearchItem(int item_no)
void GetAttachInfo(int slot_index, ATTACH_LIST *attachment)
void SeitonAttach()
void SetAttachToPos(int slot_index, ATTACH_LIST *attachment)
void SetWepToPos(int slot_index, WEAPON_HAVE *weapon)
Definition stockitem.cpp:95
int SeitonChargeItemBoardSub()
void Initialize()
Definition stockitem.cpp:38
WEAPON_HAVE weapons[30]
Definition stockitem.hpp:33
s16 dungeon_items[60]
Definition stockitem.hpp:31
int GetNowModeSpace(int search_space)
void GetItemInfo(int slot_index, s16 *item_no, s16 *volume)
Definition stockitem.cpp:90
s16 dungeon_item_vols[60]
Definition stockitem.hpp:32
void GetWeaponInfo(int slot_index, WEAPON_HAVE *weapon)
void SetItemToPos(int slot_index, s16 *item_no, s16 *volume)
Definition stockitem.cpp:78
@ ITEM_SORT_FOOD
Definition itemdata.hpp:23
@ ITEM_SORT_COUNT
Definition itemdata.hpp:31
@ ITEM_SORT_NONE
Definition itemdata.hpp:22
int CompChargeItem(int first_item_no, int second_item_no)
SearchSpace
Definition stockitem.hpp:18
@ SEARCHSPACE_WEAPONS
Definition stockitem.hpp:20
@ SEARCHSPACE_DUNGEON_ITEMS
Definition stockitem.hpp:19
@ SEARCHSPACE_ATTACH
Definition stockitem.hpp:21