DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
savedata.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3
4#include "savedata.hpp"
5
6#include <libvu0.h>
7
8#include "editatra.hpp"
9#include "object.hpp"
10
11void CObject::SetPosition(float *position) {
12 sceVu0CopyVector(this->pos, position);
13}
14
24
34 return this->config;
35}
36
40
41s16 *CSaveData::GetCharaName(int chara_no) {
42 if (chara_no < 0 || chara_no >= 6) {
43 return NULL;
44 }
45
46 return this->chara_name[chara_no];
47}
48
49void CSaveData::AddPlayTime(int time) {
50 this->play_time += time;
51}
52
54 return this->play_time;
55}
56
57void CSaveData::SetNowTime(float time) {
58 this->now_time = time;
59}
60
62 return this->now_time;
63}
64
65void CSaveData::AddNowTime(float add) {
66 float old_time = this->now_time;
67 this->now_time += add;
68
69 if (old_time < 8.5f) {
70 if (this->now_time >= 8.5) {
71 this->AddDay(1);
72 }
73 }
74
75 if (this->now_time >= 12.0f) {
76 this->now_time -= 12.0f;
77 }
78
79 if (this->now_time < 0.0f) {
80 this->now_time += 12.0f;
81 }
82}
83
84void CSaveData::SetDay(int day) {
85 this->day = day;
86
87 if (this->day > 9998) {
88 this->day = 9998;
89 }
90
91 if (this->day < 0) {
92 this->day = 0;
93 }
94}
95
97 return this->day;
98}
99
100void CSaveData::AddDay(int add) {
101 this->day += add;
102 this->SetDay(this->day);
103}
104
106 this->fishing_point += add;
107
108 if (this->fishing_point > 0x270F) {
109 this->fishing_point = 0x270F;
110 }
111
112 if (this->fishing_point < 0) {
113 this->fishing_point = 0;
114 }
115}
116
118 this->fishing_point = value;
119
120 if (this->fishing_point > 0x270F) {
121 this->fishing_point = 0x270F;
122 }
123
124 if (this->fishing_point < 0) {
125 this->fishing_point = 0;
126 }
127}
128
129void CSaveData::SetFishingRank(int fish_id, float score) {
130 float lowest_score = -1.0f;
131 int lowest_index = -1;
132 int i;
133
134 for (i = 0; i < 64; i++) {
135 if (this->fish_data[i].rank <= 0.0f) {
136 this->fish_data[i].rank = score;
137 this->fish_data[i].fish_id = fish_id;
138 break;
139 }
140
141 if (lowest_score < 0.0f || lowest_score > this->fish_data[i].rank) {
142 lowest_index = i;
143 lowest_score = this->fish_data[i].rank;
144 }
145 }
146
147 if (i == 64 && lowest_index >= 0) {
148 this->fish_data[lowest_index].rank = score;
149 this->fish_data[lowest_index].fish_id = fish_id;
150 }
151
152 for (i = 0; i < 63; i++) {
153 for (int k = i + 1; k < 64; k++) {
154 if (this->fish_data[i].rank < this->fish_data[k].rank) {
155 SV_FISH_DATA swapped = this->fish_data[i];
156 this->fish_data[i] = this->fish_data[k];
157 this->fish_data[k] = swapped;
158 }
159 }
160 }
161}
162
164 if (rank_index < 0 || rank_index >= 64) {
165 return NULL;
166 }
167
168 if (this->fish_data[rank_index].rank <= 0.0f || this->fish_data[rank_index].fish_id < 0) {
169 return NULL;
170 }
171
172 return &this->fish_data[rank_index];
173}
174
176 if (georama_no < 0 || georama_no >= 6) {
177 return NULL;
178 }
179
180 return &this->georama[georama_no];
181}
182
183SV_EDIT_PARTS_INFO *CSaveData::GetEditPartsInfo(int georama_no, int plot_no) {
184 if (georama_no < 0 || georama_no >= 6) {
185 return NULL;
186 }
187
188 if (plot_no < 0 || plot_no >= 24) {
189 return NULL;
190 }
191
192 return &this->georama[georama_no].parts_info[plot_no];
193}
194
195SV_GRD_PART *CSaveData::GetParts(int georama_no, int *out_count) {
196 SV_GRD_PART *parts;
197 int count;
198
199 if (georama_no < 0 || georama_no >= 6) {
200 return NULL;
201 }
202
203 parts = this->georama[georama_no].placed_parts;
204
205 for (count = 0; count < 130; count++) {
206 if (parts[count].part_id < 0) {
207 break;
208 }
209 }
210
211 *out_count = count;
212 return parts;
213}
214
215SV_GRD_NPC *CSaveData::GetGrdNPCData(int map_no, int npc_no) {
216 static s32 sub_map[] = {14, 23, 11, 19, 42, 38, -1};
217 int i;
218
219 if (map_no >= 11) {
220 for (i = 0;; i++) {
221 if (sub_map[i] < 0) {
222 return NULL;
223 }
224
225 if (map_no == sub_map[i]) {
226 return (SV_GRD_NPC *) (this->special_npc + i * 12);
227 }
228 }
229 }
230
231 if (map_no < 0 || map_no >= 6) {
232 return NULL;
233 }
234
235 if (npc_no < 0 || npc_no >= 20) {
236 return NULL;
237 }
238
239 return &this->georama[map_no].npc[npc_no];
240}
241
242s16 *CSaveData::GetElemData(int georama_no) {
243 if (georama_no < 0 || georama_no >= 6) {
244 return NULL;
245 }
246
247 return this->elem_data[georama_no];
248}
249
253
255 return &this->stock_item;
256}
257
258int CSaveData::GetGameFlag(int flag_no) {
259 int bit_idx;
260
261 if (flag_no < 0) {
262 return 0;
263 }
264
265 if (flag_no >> 5 >= 256) {
266 return 0;
267 }
268
269 bit_idx = flag_no & 0x1F;
270
271 if (flag_no < 0 && bit_idx != 0) {
272 bit_idx -= 32;
273 }
274
275 u32 mask = 1 << bit_idx;
276 return (this->game_flags[flag_no >> 5] & mask) != 0;
277}
278
279int CSaveData::SetGameFlag(int flag_no, int value) {
280 int bit_idx;
281 int word_idx;
282 u32 mask;
283
284 if (flag_no < 0) {
285 return 0;
286 }
287
288 word_idx = flag_no >> 5;
289
290 if (word_idx >= 256) {
291 return 0;
292 }
293
294 bit_idx = flag_no & 0x1F;
295
296 if (flag_no < 0 && bit_idx != 0) {
297 bit_idx -= 32;
298 }
299
300 mask = 1 << bit_idx;
301 this->game_flags[word_idx] &= ~mask;
302
303 if (value) {
304 this->game_flags[word_idx] |= mask;
305 }
306
307 return value;
308}
309
311 if (flag_no >= 32) {
312 return 0;
313 }
314
315 return this->game_int_flag[flag_no];
316}
317
318int CSaveData::SetGameIntFlag(int flag_no, int value) {
319 if (flag_no >= 32) {
320 return 0;
321 }
322
323 this->game_int_flag[flag_no] = value;
324 return value;
325}
326
327int CSaveData::GetMapFlag(int map_no, int flag_no) {
328 int word_idx;
329 int bit_idx;
330 u32 mask;
331
332 if (map_no < 0 || map_no >= 0x50) {
333 return 0;
334 }
335
336 if (flag_no < 0) {
337 return 0;
338 }
339
340 word_idx = flag_no >> 5;
341
342 if (word_idx >= 16) {
343 return 0;
344 }
345
346 bit_idx = flag_no & 0x1F;
347
348 if (flag_no < 0 && bit_idx != 0) {
349 bit_idx -= 32;
350 }
351
352 mask = 1 << bit_idx;
353 return (this->map_flags[map_no][word_idx] & mask) != 0;
354}
355
356int CSaveData::SetMapFlag(int map_no, int flag_no, int value) {
357 int word_idx;
358 int bit_idx;
359 u32 mask;
360
361 if (map_no < 0 || map_no >= 0x50) {
362 return 0;
363 }
364
365 if (flag_no < 0) {
366 return 0;
367 }
368
369 word_idx = flag_no >> 5;
370
371 if (word_idx >= 16) {
372 return 0;
373 }
374
375 bit_idx = flag_no & 0x1F;
376
377 if (flag_no < 0 && bit_idx != 0) {
378 bit_idx -= 32;
379 }
380
381 mask = 1 << bit_idx;
382 this->map_flags[map_no][word_idx] &= ~mask;
383
384 if (value) {
385 this->map_flags[map_no][word_idx] |= mask;
386 }
387
388 return value;
389}
390
391int CSaveData::GetMapInitFlag(int map_no, int flag_no) {
392 int word_idx;
393 int bit_idx;
394 u32 mask;
395
396 if (map_no < 0 || map_no >= 0x50) {
397 return 0;
398 }
399
400 if (flag_no < 0) {
401 return 0;
402 }
403
404 word_idx = flag_no >> 5;
405
406 if (word_idx >= 16) {
407 return 0;
408 }
409
410 bit_idx = flag_no & 0x1F;
411
412 if (flag_no < 0 && bit_idx != 0) {
413 bit_idx -= 32;
414 }
415
416 mask = 1 << bit_idx;
417 return (this->map_init_flags[map_no][word_idx] & mask) != 0;
418}
419
420int CSaveData::SetMapInitFlag(int map_no, int flag_no, int value) {
421 int word_idx;
422 int bit_idx;
423 u32 mask;
424
425 if (map_no < 0 || map_no >= 0x50) {
426 return 0;
427 }
428
429 if (flag_no < 0) {
430 return 0;
431 }
432
433 word_idx = flag_no >> 5;
434
435 if (word_idx >= 16) {
436 return 0;
437 }
438
439 bit_idx = flag_no & 0x1F;
440
441 if (flag_no < 0 && bit_idx != 0) {
442 bit_idx -= 32;
443 }
444
445 mask = 1 << bit_idx;
446 this->map_init_flags[map_no][word_idx] &= ~mask;
447
448 if (value) {
449 this->map_init_flags[map_no][word_idx] |= mask;
450 }
451
452 return value;
453}
454
455int CSaveData::AtraPartsGet(int georama_no, int plot_no) {
456 SV_EDIT_PARTS_INFO *info;
457 SV_ATRA_PARTS_DEF *atra;
458
459 info = this->GetEditPartsInfo(georama_no, plot_no);
460
461 if (info == NULL) {
462 return 0;
463 }
464
465 atra = (SV_ATRA_PARTS_DEF *) GetEditAtraPartsData(georama_no, plot_no);
466
467 if (atra == NULL) {
468 return 0;
469 }
470
471 if (atra->stackable > 0) {
472 if (info->obtained == 0) {
473 info->stock = 5;
474 } else {
475 info->stock += 5;
476
477 if (info->stock > atra->max_stock) {
478 info->stock = (s16) atra->max_stock;
479 }
480 }
481
482 info->obtained = 1;
483 } else {
484 if (info->obtained != 0) {
485 return 0;
486 }
487
488 info->obtained = 1;
489 }
490
491 return 1;
492}
493
494int CSaveData::AtraChipGet(int georama_no, int chip_id) {
495 s16 *chips;
496 s16 *slot;
497 int i;
498
499 chips = this->GetElemData(georama_no);
500
501 if (chip_id < 0) {
502 return 0;
503 }
504
505 if (chips == NULL) {
506 return 0;
507 }
508
509 slot = chips;
510
511 for (i = 0; i < 128; i++, slot++) {
512 if (*slot < 0) {
513 *slot = chip_id;
514 return 1;
515 }
516 }
517
518 return 0;
519}
520
521int CSaveData::VisitMap(int map_no, int add) {
522 if (map_no < 0 || map_no >= 0x50) {
523 return 0;
524 }
525
526 this->visit_map[map_no] += add;
527
528 if (this->visit_map[map_no] > 0x270F) {
529 this->visit_map[map_no] = 0x270F;
530 }
531
532 return this->visit_map[map_no];
533}
534
535int CSaveData::QuestDungeon(int dungeon_no, int add) {
536 if (dungeon_no == 6) {
537 this->quest_dungeon_total += add;
538
539 if (this->quest_dungeon_total > 0x270F) {
540 this->quest_dungeon_total = 0x270F;
541 }
542
543 return this->quest_dungeon_total;
544 }
545
546 if (dungeon_no < 0 || dungeon_no >= 6) {
547 return 0;
548 }
549
550 this->quest_dungeon[dungeon_no] += add;
551
552 if (this->quest_dungeon[dungeon_no] > 0x270F) {
553 this->quest_dungeon[dungeon_no] = 0x270F;
554 }
555
556 return this->quest_dungeon[dungeon_no];
557}
558
560 char *src;
561 char *dst;
562 int copy;
563 int value_no;
564
565 dst = (char *) out;
566
567 this->config[16] = this->menu_cursor.reset_pos;
568 this->config[15] = this->dng_status.minimap_status;
569
570 src = (char *) this->config;
571 memset(dst, 0, sizeof(SV_CONFIG_SYS));
572
573 for (copy = 0; copy < 3; copy++) {
574 for (value_no = 0; value_no < 18; value_no++) {
575 *(dst + copy * 18 + value_no) = *(src + value_no * 4);
576 }
577 }
578}
579
581 int i;
582 int j;
583
584 for (j = 0; j < 18; j++) {
585 if (in->values[j] != in->values_copy1[j]) {
586 return 0;
587 }
588
589 if (in->values[j] != in->values_copy2[j]) {
590 return 0;
591 }
592 }
593
594 for (i = 0; i < 18; i++) {
595 this->config[i] = in->values[i];
596 }
597
598 s32 saved_reset_pos = this->config[16];
599 this->menu_cursor.reset_pos = (s16) saved_reset_pos;
600
601 if (this->menu_cursor.reset_pos != 0) {
602 this->menu_cursor.InitPos();
603 }
604
605 this->dng_status.minimap_status = this->config[15];
606
607 return 1;
608}
609
611 int i;
612 int j;
613
614 for (i = 0; i < 10; i++) {
615 this->pos[i] = 0;
616 }
617
618 for (j = 0; j < 10; j++) {
619 this->mode[j] = -1;
620 }
621
622 this->mode[0] = 4;
623 this->mode[2] = 6;
624 this->mode[3] = 0;
625 this->chara_no = 0;
626}
627
629 int i;
630 int j;
631 int k;
632
633 memset(this, 0, sizeof(CSaveData));
634 this->unk_1CC = -1;
635 this->now_time = 0.0f;
636
637 for (j = 0; j < 6; j++) {
638 for (k = 0; k < 128; k++) {
639 this->elem_data[j][k] = -1;
640 }
641 }
642
643 SV_GEORAMA_DATA *town = this->georama;
644
645 for (i = 0; i < 6; i++, town++) {
646 memset(town, 0, sizeof(SV_GEORAMA_DATA));
647
648 for (j = 0; j < 24; j++) {
649 SV_EDIT_PARTS_INFO *info = &town->parts_info[j];
650
651 for (k = 0; k < 6; k++) {
652 info->element_enabled[k] = 0;
653 }
654 }
655
656 for (j = 0; j < 130; j++) {
657 town->placed_parts[j].part_id = -1;
658 }
659 }
660
661 this->dng_status.Initialize();
662 this->stock_item.Initialize();
663
664 memset(this, 0, sizeof(this->config));
665 memset(this->game_flags, 0, sizeof(this->game_flags));
666 memset(this->map_flags, 0, 4);
667}
668
670 this->menu_cursor.reset_pos = 0;
671 this->menu_cursor.InitPos();
672 this->Initialize();
673}
s16 mode[10]
Definition savedata.hpp:22
void InitPos()
Definition savedata.cpp:610
s16 pos[10]
Definition savedata.hpp:21
virtual void SetPosition(CVector3_f_ position)
Definition object.cpp:38
float pos[4]
Definition object.hpp:18
void Initialize()
Definition savedata.cpp:628
void AddDay(int add)
Definition savedata.cpp:100
SV_GRD_NPC * GetGrdNPCData(int map_no, int npc_no)
Definition savedata.cpp:215
void SetFishingRank(int fish_id, float score)
Definition savedata.cpp:129
float GetNowTime()
Definition savedata.cpp:61
CMenuCursor * GetMenuCursor()
Definition savedata.cpp:37
CDngStatusData * GetDngStatus()
Definition savedata.cpp:250
s16 * GetCharaName(int chara_no)
Definition savedata.cpp:41
SV_GRD_PART * GetParts(int georama_no, int *out_count)
Definition savedata.cpp:195
s32 config[18]
Definition savedata.hpp:118
s32 play_time
Definition savedata.hpp:123
SV_FISH_DATA fish_data[64]
Definition savedata.hpp:126
void SetNowTime(float time)
Definition savedata.cpp:57
SV_GEORAMA_DATA georama[6]
Definition savedata.hpp:129
s32 fishing_point
Definition savedata.hpp:125
int QuestDungeon(int dungeon_no, int add)
Definition savedata.cpp:535
CMenuCursor menu_cursor
Definition savedata.hpp:128
int GetPlayTime()
Definition savedata.cpp:53
int GetMapInitFlag(int map_no, int flag_no)
Definition savedata.cpp:391
s16 quest_dungeon[6]
Definition savedata.hpp:143
int GetGameFlag(int flag_no)
Definition savedata.cpp:258
int SetMapFlag(int map_no, int flag_no, int value)
Definition savedata.cpp:356
s32 game_int_flag[32]
Definition savedata.hpp:139
s16 * GetElemData(int georama_no)
Definition savedata.cpp:242
void * GetConfigData()
Definition savedata.cpp:33
float now_time
Definition savedata.hpp:122
u32 game_flags[256]
Definition savedata.hpp:138
char special_npc[320]
Definition savedata.hpp:131
CDngStatusData dng_status
Definition savedata.hpp:136
int SetGameFlag(int flag_no, int value)
Definition savedata.cpp:279
int GetGameIntFlag(int flag_no)
Definition savedata.cpp:310
s16 chara_name[6][32]
Definition savedata.hpp:119
int SetMapInitFlag(int map_no, int flag_no, int value)
Definition savedata.cpp:420
CStockItem stock_item
Definition savedata.hpp:137
int GetDay()
Definition savedata.cpp:96
void SetFishingPoint(int value)
Definition savedata.cpp:117
SV_FISH_DATA * GetFishingRank(int rank_index)
Definition savedata.cpp:163
int VisitMap(int map_no, int add)
Definition savedata.cpp:521
void AddNowTime(float add)
Definition savedata.cpp:65
void AddPlayTime(int time)
Definition savedata.cpp:49
s32 quest_dungeon_total
Definition savedata.hpp:145
void AddFishingPoint(int add)
Definition savedata.cpp:105
void ConvertConfig(SV_CONFIG_SYS *out)
Definition savedata.cpp:559
s16 visit_map[80]
Definition savedata.hpp:142
s16 elem_data[6][128]
Definition savedata.hpp:130
int InvertConfig(SV_CONFIG_SYS *in)
Definition savedata.cpp:580
SV_GEORAMA_DATA * GetGrdData(int georama_no)
Definition savedata.cpp:175
int GetMapFlag(int map_no, int flag_no)
Definition savedata.cpp:327
void SetDay(int day)
Definition savedata.cpp:84
SV_EDIT_PARTS_INFO * GetEditPartsInfo(int georama_no, int plot_no)
Definition savedata.cpp:183
u32 map_init_flags[80][16]
Definition savedata.hpp:141
int AtraPartsGet(int georama_no, int plot_no)
Definition savedata.cpp:455
CStockItem * GetStockItem()
Definition savedata.cpp:254
int SetGameIntFlag(int flag_no, int value)
Definition savedata.cpp:318
u32 map_flags[80][16]
Definition savedata.hpp:140
int AtraChipGet(int georama_no, int chip_id)
Definition savedata.cpp:494
void Initialize()
Definition stockitem.cpp:38
char values[18]
Definition savedata.hpp:44
char values_copy1[18]
Definition savedata.hpp:45
char values_copy2[18]
Definition savedata.hpp:46
SV_EDIT_PARTS_INFO parts_info[24]
Definition savedata.hpp:99
SV_GRD_PART placed_parts[130]
Definition savedata.hpp:100
SV_GRD_NPC npc[20]
Definition savedata.hpp:101