DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
dngstatusdata.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 781
4
5#include "dngstatusdata.hpp"
6
7#include "dun/gameloop.hpp"
8#include "dungeonparts.hpp"
9#include "itemdata.hpp"
10#include "menu_dungeon.hpp"
11#include "menu_inventory.hpp"
12#include "userstatus.hpp"
13
14/* CDngStatusData's and CUserStatus's methods are interleaved in retail
15 * (SetNowFloor..SearchItemIndexNo, ChkEventFlag..ClearEventFlag, LostItem..
16 * CheckDefaultWeapon, AddDrink..Init, SetDead..GetAtraData), so both classes
17 * live in this one translation unit, in that order.
18 */
19
20#include <cstdio>
21#include <cstdlib>
22
24static s32 defWeapon[6] = {ITEM_WEAPON_DAGGER_BROKEN, ITEM_WEAPON_WOODENSLINGSHOT_BROKEN, ITEM_WEAPON_MALLET_BROKEN, ITEM_WEAPON_GOLD_RING_BROKEN, ITEM_WEAPON_FIGHTING_STICK_BROKEN, ITEM_WEAPON_MACHINE_GUN_BROKEN};
25
26static inline int GetMaxDungeonItems() {
27 return 100;
28}
29
30/* Number of atra_grid slots per floor (atra_grid[georama][floor][0..8)). */
31static inline int GetMaxAtraSlotNo() {
32 return 8;
33}
34
35/* @ 0x1BD900 (0x40 bytes) -- SetNowFloor__14CDngStatusDataFi */
37
38 this->prev_floor = this->cur_floor;
39 this->cur_floor = floor;
40
41 int cur_georama = this->cur_georama;
42 s8 *reached_table = this->floor_reached;
43 s8 *reached = reached_table + cur_georama;
44
45 if (floor > *reached) {
46 *reached = floor;
47 }
48}
49
50/* Item-id ranges are semantic: [132,257)=dungeon items (quick-slots + 103-slot
51 * inventory), [81,132)=consumables (43-slot array, only first 40 searched
52 * here), [257,+)=weapons (per-character 11-slot equipment, only first 10 of
53 * 11 slots searched here). */
54/* @ 0x1BD940 (0x180 bytes) -- SearchItemIndexNo__14CDngStatusDataFi */
56 int i;
57 int valid;
58
59 if (!(valid = item_id < ITEM_DUNGEON_START) && item_id < ITEM_WEAPON_START) {
60 for (i = 0; (valid = i < 3) != 0; i++) {
61 if (this->item_pack.quick_item_slot[i] == item_id) {
62 return i;
63 }
64 }
65 }
66
67 if (!(valid = item_id <= ITEM_DUNGEON_START - 1) && item_id < ITEM_WEAPON_START) {
68 for (i = 0; (valid = i < this->item_pack.num) != 0; i++) {
69 if (this->item_pack.item[i] == item_id) {
70 return i;
71 }
72 }
73 }
74
75 if (!(valid = item_id < ITEM_ATTACH_START) && item_id < ITEM_DUNGEON_START) {
76 for (i = 0; (valid = i < 40) != 0; i++) {
77 if (this->consumable_items[i].id == item_id) {
78 return i;
79 }
80 }
81 }
82
83 if (!(valid = item_id < ITEM_WEAPON_START)) {
84 int j;
85
86 for (j = 0; (valid = j < this->party_size) != 0; j++) {
87 for (i = 0; (valid = i < 10) != 0; i++) {
88 if (this->chara_weapons[j][i].item_no == item_id) {
89 return i;
90 }
91 }
92 }
93 }
94
95 return -1;
96}
97
98/* Reads one of the 50 story event flags. The range guard is `&&` in retail,
99 * not `||` -- both halves can never hold at once, so it never fires and the
100 * out-of-range read it was meant to stop happens anyway. Reproduced as
101 * written; that dead guard is also why nobody noticed its bound is 51, one
102 * past the 50 flags ClearEventFlag actually clears. */
103/* @ 0x1BDAC0 (0x60 bytes) -- ChkEventFlag__11CUserStatusFi */
105 if (flag_no < 0 && flag_no > 50) {
106 printf("err flag\n");
107 return 0;
108 }
109
110 return this->event_flags[flag_no];
111}
112
113/* @ 0x1BDB20 (0x40 bytes) -- ClearEventFlag__11CUserStatusFv */
115 int i;
116 int valid;
117
118 for (i = 0; (valid = i < 50) != 0; i++) {
119 this->event_flags[i] = 0;
120 }
121}
122
123/* @ 0x1BDB60 (0x60 bytes) -- LostItem__14CDngStatusDataFi */
124int CDngStatusData::LostItem(int item_id) {
125 int i;
126 int valid;
127
128 for (i = 0; (valid = i < 103) != 0; i++) {
129 if (this->item_pack.item[i] == item_id) {
130 this->item_pack.item[i] = -1;
131 this->item_pack.item_vol[i] = 0;
132 return i;
133 }
134 }
135
136 return -1;
137}
138
139/* @ 0x1BDBC0 (0x130 bytes) -- LostGateKey__14CDngStatusDataFv */
141 int i;
142 int valid;
143
144 for (i = 0; (valid = i < 103) != 0; i++) {
145 if (this->item_pack.item[i] == ITEM_DRAN_S_CREST) {
146 this->item_pack.item[i] = -1;
147 }
148
149 if (this->item_pack.item[i] == ITEM_SHINY_STONE) {
150 this->item_pack.item[i] = -1;
151 }
152
153 if (this->item_pack.item[i] == ITEM_RED_BERRY) {
154 this->item_pack.item[i] = -1;
155 }
156
157 if (this->item_pack.item[i] == ITEM_HOOK) {
158 this->item_pack.item[i] = -1;
159 }
160
161 if (this->item_pack.item[i] == ITEM_KING_S_SLATE) {
162 this->item_pack.item[i] = -1;
163 }
164
165 if (this->item_pack.item[i] == ITEM_GUN_POWDER) {
166 this->item_pack.item[i] = -1;
167 }
168
169 if (this->item_pack.item[i] == ITEM_CLOCK_HANDS) {
170 this->item_pack.item[i] = -1;
171 }
172
173 if (this->item_pack.item[i] == ITEM_POINTY_CHESTNUT) {
174 this->item_pack.item[i] = -1;
175 }
176
177 if (this->item_pack.item[i] == ITEM_BLACK_KNIGHT_CREST) {
178 this->item_pack.item[i] = -1;
179 }
180
181 if (!(valid = this->item_pack.item[i] < ITEM_BONE_KEY) && this->item_pack.item[i] <= ITEM_SILVER_KEY) {
182 this->item_pack.item[i] = -1;
183 }
184 }
185}
186
187/* @ 0x1BDCF0 (0x50 bytes) -- GetLiveUnit__14CDngStatusDataFv */
189 int result = 0;
190 int i;
191 int valid;
192
193 for (i = 0; (valid = i < this->party_size) != 0; i++) {
194 if (this->hp[i] > 0) {
195 result++;
196 }
197 }
198
199 return result;
200}
201
202/* @ 0x1BDD40 (0x190 bytes) -- CheckItemGet__14CDngStatusDataFi */
204 int result = 0;
205
206 if ((u32) (item_id - ITEM_MAP) <= 1 || item_id == ITEM_WORLDMAP) {
207 return 0;
208 }
209
210 {
211 int valid;
212 int i;
213
214 if (!(valid = item_id < GetDungeonItemStart()) && item_id < GetDungeonItemEnd()) {
215 int count = 0;
216 int k;
217
218 for (i = 0; (valid = i < GetMaxDungeonItems()) != 0; i++) {
219 if (!(valid = this->item_pack.item[i] < ITEM_DUNGEON_START) && this->item_pack.item[i] < ITEM_WEAPON_START) {
220 count++;
221 }
222 }
223
224 for (k = 0; (valid = k < 3) != 0; k++) {
225 if (this->item_pack.quick_item_slot[k] != -1) {
226 count += this->item_pack.quick_item_qty[k];
227 }
228 }
229
230 if (count < this->item_pack.num) {
231 result = 0;
232 } else {
233 return 1;
234 }
235 }
236
237 if (!(valid = item_id < ITEM_ATTACH_START) && item_id < ITEM_DUNGEON_START) {
238 int count = 0;
239 int j;
240
241 for (j = 0; (valid = j < 40) != 0; j++) {
242 s16 held_id = this->consumable_items[j].id;
243
244 if (!(valid = held_id < ITEM_ATTACH_START) && held_id < ITEM_DUNGEON_START) {
245 count++;
246 }
247 }
248
249 /* Retail assigns `result` here rather than returning it, so the
250 * two-constant tail stays a real branch instead of collapsing to
251 * a movn/movz conditional move. */
252 if (count < 40) {
253 result = 0;
254 } else {
255 return 2;
256 }
257 }
258 }
259
260 return result;
261}
262
263/* @ 0x1BDED0 (0xC0 bytes) -- CheckWeaponUser__14CDngStatusDataFi */
265 int result = -1;
266 int valid;
267
268 if (!(valid = weapon_id < ITEM_WEAPON_DAGGER_BROKEN) && weapon_id < ITEM_WEAPON_WOODENSLINGSHOT_BROKEN) {
269 result = CHARA_TOAN;
270 }
271
272 if (!(valid = weapon_id < ITEM_WEAPON_WOODENSLINGSHOT_BROKEN) && weapon_id < ITEM_WEAPON_MALLET_BROKEN) {
273 result = CHARA_XIAO;
274 }
275
276 if (!(valid = weapon_id < ITEM_WEAPON_MALLET_BROKEN) && weapon_id < ITEM_WEAPON_GOLD_RING_BROKEN) {
277 result = CHARA_GORO;
278 }
279
280 if (!(valid = weapon_id < ITEM_WEAPON_GOLD_RING_BROKEN) && weapon_id < ITEM_WEAPON_FIGHTING_STICK_BROKEN) {
281 result = CHARA_RUBY;
282 }
283
284 if (!(valid = weapon_id < ITEM_WEAPON_FIGHTING_STICK_BROKEN) && weapon_id < ITEM_WEAPON_MACHINE_GUN_BROKEN) {
285 result = CHARA_UNGAGA;
286 }
287
288 if (!(valid = weapon_id < ITEM_WEAPON_MACHINE_GUN_BROKEN) && weapon_id < ITEM_WEAPON_END) {
289 result = CHARA_OSMOND;
290 }
291
292 return result;
293}
294
295/* @ 0x1BDF90 (0xC0 bytes) -- CheckWeaponRot__14CDngStatusDataFi */
297 int chara_no = this->CheckWeaponUser(weapon_id);
298
299 if (chara_no == -1) {
300 return -1;
301 }
302
303 /* Retail places this early-out physically LAST (right before the
304 * epilogue, falling through with no extra jump) rather than as an
305 * early return -- the loop's "return count" path is emitted first.
306 * The goto reproduces that exact block layout/branch-threading. */
307 int valid;
308
309 if ((valid = weapon_id < ITEM_WEAPON_START) != 0) {
310 goto ret_minus1;
311 }
312
313 {
314 int count = 0;
315 int i;
316
317 for (i = 0; (valid = i < 10) != 0; i++) {
318 if (!(valid = this->chara_weapons[chara_no][i].item_no < ITEM_WEAPON_START)) {
319 count++;
320 }
321 }
322
323 return count;
324 }
325
326ret_minus1:
327 return -1;
328}
329
330/* Index 6 is the bonus "Deamon Shaft" dungeon (0-5 are the six story
331 * georama dungeons). */
332/* @ 0x1BE050 (0x10 bytes) -- ClearDeamonShaft__14CDngStatusDataFv */
334 this->floor_reached[6] = -1;
335}
336
337/* Routes by the same id ranges as SearchItemIndexNo. Dungeon items (103-slot
338 * array) and consumables (43-slot array) are both sized capacity+3 to allow
339 * temporary overflow before overflow_flag is latched. Weapons are auto-routed
340 * to their owning character via the per-item ownership table (see
341 * ItemPutListTbl12 above), not the id-range heuristic CheckWeaponUser uses. */
342/* @ 0x1BE060 (0x400 bytes) -- GetItem__14CDngStatusDataFii */
343int CDngStatusData::GetItem(int item_id, int qty) {
344 int valid;
345
346 printf("GetITEM No === %d\n", item_id);
347
348 if (!(valid = item_id < ITEM_DUNGEON_START) && item_id < ITEM_WEAPON_START) {
349 int i;
350
351 for (i = 0; (valid = i < 103) != 0; i++) {
352 if (this->item_pack.item[i] < ITEM_DUNGEON_START) {
353 if (item_id == ITEM_WORLDMAP) {
354 this->special_flag_238 = true;
355 return 0;
356 }
357
358 int count = 0;
359 int j;
360
361 for (j = 0; (valid = j < 103) != 0; j++) {
362 if (!(valid = this->item_pack.item[j] < ITEM_DUNGEON_START)) {
363 count++;
364 }
365 }
366
367 int k;
368
369 for (k = 0; (valid = k < 3) != 0; k++) {
370 if (this->item_pack.quick_item_slot[k] != -1) {
371 count += this->item_pack.quick_item_qty[k];
372 }
373 }
374
375 if (count + 1 > this->item_pack.num) {
376 this->overflow_flag = true;
377 }
378
379 int have_copy = ItemDataToHaveCopy(item_id);
380
381 if (this->overflow_flag != 0) {
382 int m;
383
384 for (m = 0; (valid = m < 3) != 0; m++) {
385 if (this->item_pack.item[this->item_pack.num + m] == -1) {
386 this->item_pack.item[this->item_pack.num + m] = item_id;
387 this->item_pack.item_vol[this->item_pack.num + m] = have_copy;
388 return i;
389 }
390 }
391 } else {
392 this->item_pack.item[i] = item_id;
393 this->item_pack.item_vol[i] = have_copy;
394 }
395
396 return i;
397 }
398 }
399 }
400
401 if (!(valid = item_id < ITEM_ATTACH_START) && item_id < ITEM_DUNGEON_START) {
402 int n;
403
404 for (n = 0; (valid = n < 43) != 0; n++) {
405 if (this->consumable_items[n].id < ITEM_ATTACH_START) {
406 this->consumable_items[n].id = item_id;
407 SetAttachMentValue(item_id, n, qty, (ATTACH_LIST *) 0);
408
409 int count = 0;
410 int ii;
411
412 for (ii = 0; (valid = ii < 43) != 0; ii++) {
413 s16 held_id = this->consumable_items[ii].id;
414
415 if (!(valid = held_id < ITEM_ATTACH_START) && held_id < ITEM_DUNGEON_START) {
416 count++;
417 }
418 }
419
420 if (count > 40) {
421 this->overflow_flag++;
422 }
423
424 return n;
425 }
426 }
427 }
428
429 if (!(valid = item_id < ITEM_WEAPON_START)) {
430 printf("get weapon!! %d\n", item_id);
431 int chara_no = ItemPutListTbl12_bytes[750 + item_id * 76];
432
433 int jj;
434
435 for (jj = 0; (valid = jj < 11) != 0; jj++) {
436 if (this->chara_weapons[chara_no][jj].item_no < ITEM_WEAPON_START) {
437 WepDataListToHaveCopy(item_id, &this->chara_weapons[chara_no][jj]);
438
439 int count = 0;
440 int kk;
441
442 for (kk = 0; (valid = kk < 10) != 0; kk++) {
443 if (!(valid = this->chara_weapons[chara_no][kk].item_no < ITEM_WEAPON_START)) {
444 count++;
445 }
446 }
447
448 if (!(valid = count < 10)) {
449 this->overflow_flag = true;
450 }
451
452 return jj;
453 }
454 }
455 }
456
457 return -1;
458}
459
460/* @ 0x1BE460 (0x50 bytes) -- CheckActItemSlot__14CDngStatusDataFi */
462 int i;
463 int valid;
464
465 for (i = 0; (valid = i < 3) != 0; i++) {
466 if (this->item_pack.quick_item_slot[i] == item_id) {
467 return i;
468 }
469 }
470
471 return -1;
472}
473
474/* True if the character's currently-equipped weapon slot doesn't hold their
475 * canonical default weapon (defWeapon[chara_no]). */
476/* @ 0x1BE4B0 (0x60 bytes) -- CheckDefaultWeapon__14CDngStatusDataFi */
478 s32 def_weapon = defWeapon[chara_no];
479
480 if (def_weapon == this->chara_weapons[chara_no][this->equipped_weapon_slot[chara_no]].item_no) {
481 return 0;
482 }
483
484 return 1;
485}
486
487/* Adds to a character's water gauge. With ratio == 0 the gauge moves
488 * instantly; otherwise the target is latched into drink_next[] and
489 * drink_step[] holds the per-frame delta CUserStatus::Step applies, signed so
490 * that a zero-rounding step still moves the gauge one unit in the right
491 * direction. */
492/* @ 0x1BE510 (0x200 bytes) -- AddDrink__11CUserStatusFisf */
493void CUserStatus::AddDrink(int chara_no, s16 amount, float ratio) {
494 if (this->drink_step[chara_no] != 0) {
495 this->water_now[chara_no] = (float) this->drink_next[chara_no];
496 this->drink_step[chara_no] = 0;
497 }
498
499 if (0.0f == ratio) {
500 this->water_now[chara_no] = this->water_now[chara_no] + (float) amount;
501
502 if (this->water_now[chara_no] >= this->water_max[chara_no]) {
503 this->water_now[chara_no] = this->water_max[chara_no];
504 }
505 } else {
506 this->drink_next[chara_no] = this->water_now[chara_no] + (float) amount;
507
508 if (this->drink_next[chara_no] <= 0) {
509 this->drink_next[chara_no] = 0;
510 }
511
512 if ((float) this->drink_next[chara_no] >= this->water_max[chara_no]) {
513 this->drink_next[chara_no] = this->water_max[chara_no];
514 }
515
516 this->drink_step[chara_no] = ratio * (((float) this->drink_next[chara_no] - this->water_now[chara_no]) / 100.0f);
517
518 if (this->drink_step[chara_no] == 0) {
519 if ((float) this->drink_next[chara_no] - this->water_now[chara_no] < 0.0f) {
520 this->drink_step[chara_no] = -1;
521 } else {
522 this->drink_step[chara_no] = 1;
523 }
524 }
525 }
526}
527
528/* Same instant/interpolated split as AddDrink, for HP. */
529/* @ 0x1BE710 (0x180 bytes) -- AddNowLife__11CUserStatusFisf */
530void CUserStatus::AddNowLife(int chara_no, s16 amount, float ratio) {
531 int valid;
532
533 if (this->life_step[chara_no] != 0) {
534 this->hp[chara_no] = this->next_hp[chara_no];
535 this->life_step[chara_no] = 0;
536 }
537
538 if (0.0f == ratio) {
539 this->hp[chara_no] = this->hp[chara_no] + amount;
540
541 if (this->hp[chara_no] <= 0) {
542 this->hp[chara_no] = 0;
543 }
544
545 {
546 s16 life_value = this->hp[chara_no];
547
548 if (!(valid = life_value < this->max_hp[chara_no])) {
549 this->hp[chara_no] = this->max_hp[chara_no];
550 }
551 }
552 } else {
553 this->next_hp[chara_no] = this->hp[chara_no] + amount;
554
555 if (this->next_hp[chara_no] <= 0) {
556 this->next_hp[chara_no] = 0;
557 }
558
559 {
560 s16 life_value = this->next_hp[chara_no];
561
562 if (!(valid = life_value < this->max_hp[chara_no])) {
563 this->next_hp[chara_no] = this->max_hp[chara_no];
564 }
565 }
566
567 this->life_step[chara_no] = ratio * ((float) (this->next_hp[chara_no] - this->hp[chara_no]) / 100.0f);
568
569 if (this->life_step[chara_no] == 0) {
570 if (this->next_hp[chara_no] - this->hp[chara_no] < 0) {
571 this->life_step[chara_no] = -1;
572 } else {
573 this->life_step[chara_no] = 1;
574 }
575 }
576 }
577}
578
579/* Alive iff the active character has HP left -- and, while an interpolated HP
580 * change is in flight, iff its target is above zero too. */
581/* @ 0x1BE890 (0x70 bytes) -- CheckLife__11CUserStatusFv */
583 if (this->life_step[this->cur_chara] != 0 && this->next_hp[this->cur_chara] <= 0) {
584 return 0;
585 }
586
587 if (this->hp[this->cur_chara] <= 0) {
588 return 0;
589 }
590
591 return 1;
592}
593
594/* Sets an absolute HP target (clamped to 0..max_hp), instantly or
595 * interpolated, per the same rules as AddNowLife. */
596/* @ 0x1BE900 (0x150 bytes) -- SetNextLife__11CUserStatusFisf */
597void CUserStatus::SetNextLife(int chara_no, s16 value, float ratio) {
598 if (this->life_step[chara_no] != 0) {
599 this->hp[chara_no] = this->next_hp[chara_no];
600 this->life_step[chara_no] = 0;
601 }
602
603 if (value <= 0) {
604 value = 0;
605 }
606
607 if (value >= this->max_hp[chara_no]) {
608 value = this->max_hp[chara_no];
609 }
610
611 if (ratio == 0.0f) {
612 this->hp[chara_no] = value;
613 } else {
614 this->next_hp[chara_no] = value;
615
616 this->life_step[chara_no] = ratio * ((this->next_hp[chara_no] - this->hp[chara_no]) / 100.0f);
617
618 if (this->life_step[chara_no] == 0) {
619 if (this->next_hp[chara_no] - this->hp[chara_no] < 0) {
620 this->life_step[chara_no] = -1;
621 } else {
622 this->life_step[chara_no] = 1;
623 }
624 }
625 }
626}
627
628/* Per-frame update: drains the active character's water gauge at a rate that
629 * scales with dungeon depth (and is multiplied by the level-11 restriction
630 * zone and by two equipped-weapon flags), costs 1 HP per 120 frames once the
631 * gauge is empty, then advances every character's in-flight water and HP
632 * interpolations by one step. */
633/* @ 0x1BEA50 (0x390 bytes) -- Step__11CUserStatusFi */
634void CUserStatus::Step(int mode) {
635 float drain;
636 int dungeon;
637
638 if (this->step_disable != 0) {
639 return;
640 }
641
642 dungeon = this->cur_georama;
643 drain = 1.0f + 0.2f * dungeon;
644 drain = 0.003f * drain;
645
646 if (this->water_drain_disable == 0 && mode == 0) {
647 if (this->water_now[this->cur_chara] <= 0.0f) {
648 this->water_now[this->cur_chara] = 0.0f;
649 } else {
650 if (this->res_limit_zone_current == RES_LIMIT_ZONE_THIRST) {
651 drain = 5.0f * drain;
652 }
653
654 if (NowWeaponHave->flags & 0x8) {
655 drain *= 0.8f;
656 }
657
658 if (NowWeaponHave->flags & 0x10) {
659 drain *= 2.0f;
660 }
661
662 if (mode == 0) {
663 this->water_now[this->cur_chara] -= drain;
664 }
665
666 if (this->water_now[this->cur_chara] <= 0.0f) {
667 this->water_now[this->cur_chara] = 0.0f;
668 }
669 }
670
671 if (this->water_now[this->cur_chara] <= 0.0f) {
672 this->thirst_damage[this->cur_chara] += 0.008333334f;
673 }
674
675 if (this->thirst_damage[this->cur_chara] >= 1.0f) {
676 this->thirst_damage[this->cur_chara] = 0.0f;
677 this->AddNowLife(this->cur_chara, -1, 10.0f);
678 }
679 }
680
681 for (int i = 0; i < 6; i++) {
682 if (this->drink_step[i] != 0) {
683 this->water_now[i] += this->drink_step[i];
684
685 if (this->drink_step[i] < 0) {
686 if (this->water_now[i] <= this->drink_next[i]) {
687 this->water_now[i] = this->drink_next[i];
688 this->drink_step[i] = 0;
689 }
690 }
691
692 if (this->drink_step[i] > 0) {
693 if (this->water_now[i] >= this->drink_next[i]) {
694 this->water_now[i] = this->drink_next[i];
695 this->drink_step[i] = 0;
696 }
697 }
698 }
699 }
700
701 for (int i = 0; i < 6; i++) {
702 if (this->life_step[i] != 0) {
703 this->hp[i] += this->life_step[i];
704
705 if (this->life_step[i] < 0) {
706 if (this->hp[i] <= this->next_hp[i]) {
707 this->hp[i] = this->next_hp[i];
708 this->life_step[i] = 0;
709 }
710 }
711
712 if (this->life_step[i] > 0) {
713 if (this->hp[i] >= this->next_hp[i]) {
714 this->hp[i] = this->next_hp[i];
715 this->life_step[i] = 0;
716 }
717 }
718 }
719 }
720}
721
722/* @ 0x1BEDE0 (0x110 bytes) -- Init__11CUserStatusFv */
724 int i;
725 int valid;
726
727 for (i = 0; (valid = i < 6) != 0; i++) {
728 this->thirst_damage[i] = 0.0f;
729 }
730
731 this->water_drain_disable = 0;
732 this->step_disable = 0;
733 this->res_limit_zone_current = RES_LIMIT_ZONE_NONE;
734
735 this->ClearEventFlag();
736
737 int j;
738
739 for (j = 0; (valid = j < 6) != 0; j++) {
740 this->life_step[j] = 0;
741 }
742
743 for (j = 0; (valid = j < 6) != 0; j++) {
744 this->unk_8A8C[j] = 0;
745 this->unk_8A74[j] = 0;
746 this->drink_step[j] = 0;
747 }
748}
749
750/* @ 0x1BEEF0 (0x20 bytes) -- SetDead__14CDngStatusDataFv */
752 this->money_signed = (u32) (u16) this->money_signed >> 1;
753}
754
755/* Looks up the current floor's "Res Limit Zone" id and latches it into
756 * res_limit_zone_current if the floor has one assigned. */
757/* @ 0x1BEF10 (0x50 bytes) -- SetResLimmitZone__14CDngStatusDataFv */
759 int zone = this->res_limit_zone_id[this->cur_georama][this->cur_floor];
760
761 if (zone != RES_LIMIT_ZONE_NONE) {
762 this->res_limit_zone_current = zone;
763 }
764}
765
766/* Randomly (~50/50) assigns level-10 or level-11 restriction zones to 3-4
767 * random floors per georama (georamas 1-5 only; georama 0 untouched). The
768 * float divisor is RAND_MAX+1 (2^31), i.e. rand()/(RAND_MAX+1) scaled by the
769 * floor count / 100 to pick a floor index / percentile roll.
770 *
771 * Each branch of the zone-level choice also writes `valid`; that dead store
772 * is what keeps retail's real branch instead of a movn/movz conditional move,
773 * and it forces the roll comparison into a real register rather than `at`. */
774/* @ 0x1BEF60 (0x3E0 bytes) -- InitResLimmitZone__14CDngStatusDataFv */
776 int floor_index;
777 int roll;
778 int i;
779 int valid;
780
781 for (i = 0; (valid = i < 3) != 0; i++) {
782 int zone;
783 floor_index = (int) ((15.0f * (float) rand()) / 2147483648.0f);
784 roll = (int) ((100.0f * (float) rand()) / 2147483648.0f);
785
786 if (!(valid = roll < 50)) {
787 zone = RES_LIMIT_ZONE_NO_WEAPON_CHANGE;
788 valid = 0;
789 } else {
790 zone = RES_LIMIT_ZONE_THIRST;
791 valid = 1;
792 }
793
794 this->res_limit_zone_id[1][floor_index] = zone;
795 }
796
797 for (i = 0; (valid = i < 3) != 0; i++) {
798 int zone;
799 floor_index = (int) ((16.0f * (float) rand()) / 2147483648.0f);
800 roll = (int) ((100.0f * (float) rand()) / 2147483648.0f);
801
802 if (!(valid = roll < 50)) {
803 zone = RES_LIMIT_ZONE_NO_WEAPON_CHANGE;
804 valid = 0;
805 } else {
806 zone = RES_LIMIT_ZONE_THIRST;
807 valid = 1;
808 }
809
810 this->res_limit_zone_id[2][floor_index] = zone;
811 }
812
813 for (i = 0; (valid = i < 3) != 0; i++) {
814 int zone;
815 floor_index = (int) ((16.0f * (float) rand()) / 2147483648.0f);
816 roll = (int) ((100.0f * (float) rand()) / 2147483648.0f);
817
818 if (!(valid = roll < 50)) {
819 zone = RES_LIMIT_ZONE_NO_WEAPON_CHANGE;
820 valid = 0;
821 } else {
822 zone = RES_LIMIT_ZONE_THIRST;
823 valid = 1;
824 }
825
826 this->res_limit_zone_id[3][floor_index] = zone;
827 }
828
829 for (i = 0; (valid = i < 4) != 0; i++) {
830 int zone;
831 floor_index = (int) ((14.0f * (float) rand()) / 2147483648.0f);
832 roll = (int) ((100.0f * (float) rand()) / 2147483648.0f);
833
834 if (!(valid = roll < 50)) {
835 zone = RES_LIMIT_ZONE_NO_WEAPON_CHANGE;
836 valid = 0;
837 } else {
838 zone = RES_LIMIT_ZONE_THIRST;
839 valid = 1;
840 }
841
842 this->res_limit_zone_id[4][floor_index] = zone;
843 }
844
845 for (i = 0; (valid = i < 4) != 0; i++) {
846 int zone;
847 floor_index = (int) ((23.0f * (float) rand()) / 2147483648.0f);
848 roll = (int) ((100.0f * (float) rand()) / 2147483648.0f);
849
850 if (!(valid = roll < 50)) {
851 zone = RES_LIMIT_ZONE_NO_WEAPON_CHANGE;
852 valid = 0;
853 } else {
854 zone = RES_LIMIT_ZONE_THIRST;
855 valid = 1;
856 }
857
858 this->res_limit_zone_id[5][floor_index] = zone;
859 }
860}
861
862/* The five inventory fields at 0x4360..0x450A form one contiguous block that
863 * Initialize's final loop addresses through a single base pointer, with the
864 * two arrays reached by small (+14/+220) displacements off it rather than
865 * their full struct offsets. Reproducing retail's instruction order needs the
866 * base to be struct-typed: subscripting through it yields MWCC's index-first
867 * `addu index, base`, whereas the equivalent raw `s8 *` plus casts yields
868 * base-first. */
871 char unk_01;
874 s16 dungeon_items[103];
875 s16 item_vol[103];
876};
877
878/* Resets the whole class to a fresh-game state: party HP/weapons/atra grid/
879 * kills/restriction zones/inventory all cleared, then character 0 is given
880 * the starting weapon (item 258) via GetItem. */
881/* @ 0x1BF340 (0x3C0 bytes) -- Initialize__14CDngStatusDataFv */
883 this->cur_georama = -1;
884 this->unk_01[0] = 0;
885 this->cur_floor = -1;
886 this->prev_floor = -1;
887 this->cur_chara = CHARA_TOAN;
888 this->party_size = 1;
889
890 // The first weapon id of each character's range; copied but never read.
891 s32 weapon_base[6] = {ITEM_WEAPON_DAGGER_BROKEN, ITEM_WEAPON_WOODENSLINGSHOT_BROKEN, ITEM_WEAPON_MALLET_BROKEN, ITEM_WEAPON_GOLD_RING_BROKEN, ITEM_WEAPON_FIGHTING_STICK_BROKEN, ITEM_WEAPON_MACHINE_GUN_BROKEN};
892 s32 start_hp[6] = {70, 60, 100, 90, 110, 100};
893 s32 start_stat[6] = {3, 1, 12, 23, 38, 46};
894
895 int t;
896 int q;
897 int k;
898 int m;
899 int j;
900 int i;
901 int valid;
902
903 for (t = 0; (valid = t < 6) != 0; t++) {
904 this->max_hp[t] = start_hp[t];
905 this->hp[t] = start_hp[t];
906 this->defense[t] = start_stat[t];
907 this->ailments[t] = 0;
908 this->ailment_frames[t] = 0;
909 this->equipped_weapon_slot[t] = -1;
910
911 for (q = 0; (valid = q < 11) != 0; q++) {
912 this->chara_weapons[t][q].item_no = -1;
913 }
914
915 this->water_max[t] = 30.0f;
916 this->water_now[t] = 30.0f;
917 this->skill_owned[t] = 0;
918 }
919
920 this->equipped_weapon_slot[0] = 0;
921 this->GetItem(ITEM_WEAPON_DAGGER, 0);
922 this->special_flag_238 = false;
923 this->minimap_status = 1;
924 this->overflow_flag = false;
925
926 for (k = 0; (valid = k < 7) != 0; k++) {
927 this->floor_reached[k] = -1;
928 }
929
930 for (m = 0; (valid = m < 6) != 0; m++) {
931 for (k = 0; (valid = k < 100) != 0; k++) {
932 this->kills[m][k] = 0;
933 }
934 }
935
936 for (t = 0; (valid = t < 6) != 0; t++) {
937 for (k = 0; (valid = k < 25) != 0; k++) {
938 this->res_limit_zone_id[t][k] = RES_LIMIT_ZONE_NONE;
939 }
940 }
941
942 this->InitResLimmitZone();
943
944 for (t = 0; (valid = t < 6) != 0; t++) {
945 for (k = 0; (valid = k < 40) != 0; k++) {
946 for (j = 0; (valid = j < 8) != 0; j++) {
947 this->atra_grid[t][k][j] = -1;
948 }
949 }
950 }
951
952 for (m = 0; (valid = m < 6) != 0; m++) {
953 for (q = 0; (valid = q < 100) != 0; q++) {
954 this->atra_registry[m][q].id = -1;
955 }
956 }
957
958 this->money_signed = 0;
959 DNG_ITEM_BLOCK *item_block = (DNG_ITEM_BLOCK *) &this->item_pack.num;
960 this->item_pack.num = 50;
961 this->item_pack.quick_item_slot[0] = -1;
962 this->item_pack.quick_item_slot[1] = -1;
963 this->item_pack.quick_item_slot[2] = -1;
964
965 for (t = 0; (valid = t < 103) != 0; t++) {
966 item_block->dungeon_items[t] = -1;
967 item_block->item_vol[t] = 0;
968 }
969
970 for (i = 0; (valid = i < 43) != 0; i++) {
971 this->consumable_items[i].id = -1;
972 }
973}
974
975/* Per-(georama, floor) monster kill counter, indexed by the CURRENT
976 * georama/floor for AddKills but by explicit params for ChkKills. */
977/* @ 0x1BF700 (0x40 bytes) -- AddKills__14CDngStatusDataFv */
979 this->kills[this->cur_georama][this->cur_floor]++;
980}
981
982/* @ 0x1BF740 (0x30 bytes) -- ChkKills__14CDngStatusDataFii */
983s16 CDngStatusData::ChkKills(int georama_no, int floor) {
984 return this->kills[georama_no][floor];
985}
986
987/* Counts already-collected (-3) atra slots on a floor. Returns 0 for
988 * georama_no == 6. */
989/* @ 0x1BF770 (0x80 bytes) -- GetAtraNum__14CDngStatusDataFii */
990int CDngStatusData::GetAtraNum(int georama_no, int floor) {
991 if (georama_no == 6) {
992 return 0;
993 }
994
995 int result = 0;
996 int i;
997 int valid;
998
999 for (i = 0; (valid = i < 8) != 0; i++) {
1000 if (this->atra_grid[georama_no][floor][i] == -3) {
1001 result++;
1002 }
1003 }
1004
1005 return result;
1006}
1007
1008/* Counts non-(-1) entries in atra_grid[georama_no][floor][0..8), i.e. how
1009 * many atra slots are assigned to this floor. Returns 0 for georama_no==6. */
1010/* @ 0x1BF7F0 (0x80 bytes) -- GetMaxAtraNum__14CDngStatusDataFii */
1011int CDngStatusData::GetMaxAtraNum(int georama_no, int floor) {
1012 if (georama_no == 6) {
1013 return 0;
1014 }
1015
1016 int result = 0;
1017 int i;
1018 int valid;
1019
1020 for (i = 0; (valid = i < 8) != 0; i++) {
1021 if (this->atra_grid[georama_no][floor][i] != -1) {
1022 result++;
1023 }
1024 }
1025
1026 return result;
1027}
1028
1029/* @ 0x1BF870 (0x80 bytes) -- SetGetAtra__14CDngStatusDataFiii */
1030int CDngStatusData::SetGetAtra(int georama_no, int floor, int atra_id) {
1031 int i;
1032
1033 if (georama_no == 6) {
1034 i = 0;
1035 } else {
1036 int valid;
1037
1038 for (i = 0; (valid = i < 8) != 0; i++) {
1039 if (this->atra_grid[georama_no][floor][i] == -1) {
1040 this->atra_grid[georama_no][floor][i] = atra_id;
1041 return i;
1042 }
1043 }
1044
1045 i = -1;
1046 }
1047
1048 return i;
1049}
1050
1051/* Copies atra_grid[georama_no][floor][0..8) into out8. No-op for
1052 * georama_no==6. */
1053/* @ 0x1BF8F0 (0x60 bytes) -- SetCopyAtraList__14CDngStatusDataFiiPi */
1054void CDngStatusData::SetCopyAtraList(int georama_no, int floor, int *out_list) {
1055 if (georama_no != 6) {
1056 int i;
1057 int valid;
1058
1059 for (i = 0; (valid = i < 8) != 0; i++) {
1060 out_list[i] = this->atra_grid[georama_no][floor][i];
1061 }
1062 }
1063}
1064
1065/* Marks the matching (or wildcard, -2) atra slot on this floor collected (-3)
1066 * and drops the registry refcount for that id, freeing the entry at zero.
1067 * The two loops use separate counters and the second's refcount test is
1068 * phrased as an early return -- both are needed to reproduce retail's
1069 * register allocation and branch threading. */
1070/* @ 0x1BF950 (0x160 bytes) -- GetAtraData__14CDngStatusDataFiii */
1071void CDngStatusData::GetAtraData(int georama_no, int floor, int atra_id) {
1072 if (georama_no < 6) {
1073 int i;
1074 int valid;
1075 int j;
1076
1077 for (i = 0; (valid = i < GetMaxAtraSlotNo()) != 0; i++) {
1078 if (this->atra_grid[georama_no][floor][i] == atra_id) {
1079 this->atra_grid[georama_no][floor][i] = -3;
1080 this->atra_registry[georama_no][atra_id].refcount--;
1081
1082 if (this->atra_registry[georama_no][atra_id].refcount == 0) {
1083 this->atra_registry[georama_no][atra_id].id = -1;
1084 }
1085
1086 return;
1087 }
1088 }
1089
1090 for (j = 0; (valid = j < GetMaxAtraSlotNo()) != 0; j++) {
1091 if (this->atra_grid[georama_no][floor][j] == -2) {
1092 this->atra_grid[georama_no][floor][j] = -3;
1093 this->atra_registry[georama_no][atra_id].refcount--;
1094
1095 if (this->atra_registry[georama_no][atra_id].refcount != 0) {
1096 return;
1097 }
1098
1099 this->atra_registry[georama_no][atra_id].id = -1;
1100 return;
1101 }
1102 }
1103 }
1104}
void SetCopyAtraList(int georama_no, int floor, int *out_list)
void SetNowFloor(int floor)
int SetGetAtra(int georama_no, int floor, int atra_id)
s16 ChkKills(int georama_no, int floor)
int CheckWeaponRot(int weapon_id)
int CheckWeaponUser(int weapon_id)
int GetItem(int item_id, int qty)
int CheckActItemSlot(int item_id)
int LostItem(int item_id)
int CheckDefaultWeapon(int chara_no)
int GetAtraNum(int georama_no, int floor)
int SearchItemIndexNo(int item_id)
int GetMaxAtraNum(int georama_no, int floor)
int CheckItemGet(int item_id)
void GetAtraData(int georama_no, int floor, int atra_id)
s16 max_hp[6]
s32 atra_grid[6][40][8]
void SetNextLife(int chara_no, s16 value, float ratio)
void ClearEventFlag()
s16 kills[6][100]
ITEM_PACK item_pack
s32 water_drain_disable
s8 event_flags[50]
s32 ailments[6]
float water_max[6]
void AddDrink(int chara_no, s16 amount, float ratio)
char res_limit_zone_id[6][25]
s32 skill_owned[6]
float water_now[6]
DNG_CONSUMABLE consumable_items[43]
s16 life_step[6]
int ChkEventFlag(int flag_no)
s16 drink_next[6]
void AddNowLife(int chara_no, s16 amount, float ratio)
s8 floor_reached[7]
WEAPON_HAVE chara_weapons[6][11]
s16 ailment_frames[6]
s8 equipped_weapon_slot[6]
s32 res_limit_zone_current
ATRA_SAVE atra_registry[6][100]
s16 drink_step[6]
float thirst_damage[6]
void Step(int mode)
s8 ItemPutListTbl12_bytes[]
int GetDungeonItemStart()
Definition itemdata.hpp:783
int GetDungeonItemEnd()
Definition itemdata.hpp:786
s16 quick_item_slot[3]
s16 quick_item_qty[3]
s16 item_vol[103]
s16 item[103]