DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
weapon_buildup.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3
4#include "weapon_buildup.hpp"
5
6#include <cstring>
7
8#include "battlemenu.hpp"
9#include "itemdata.hpp"
10#include "menu_draw.hpp"
11#include "menu_dungeon.hpp"
12#include "menu_inventory.hpp"
13#include "menu_save.hpp"
14#include "shop.hpp"
15
16static int BuildMenuCompVolume(char requirement, char value) {
17 int passes;
18
19 if (0 <= requirement) {
20 if (value >= requirement) {
21 passes = 1;
22 } else {
23 passes = 0;
24 }
25
26 return passes;
27 }
28
29 requirement = -requirement;
30 return requirement < value ? 0 : 1;
31}
32
33static int BuildMenuCompVolume(short requirement, short value) {
34 int passes;
35
36 if (0 <= requirement) {
37 if (value >= requirement) {
38 passes = 1;
39 } else {
40 passes = 0;
41 }
42
43 return passes;
44 }
45
46 requirement = -requirement;
47 return requirement < value ? 0 : 1;
48}
49
50int CompareBuildUpModelData2(WEAPON_HAVE *destination, WEAPON_HAVE *weapon) {
51 WEAPON_HAVE held_values;
52 WeaponAllValueSet(weapon, &held_values, 1);
53
54 s16 held_status[2] = {0, 0};
55 held_status[0] = held_values.attack;
56 held_status[1] = held_values.magic;
57
58 s16 required_status[2] = {0, 0};
59 required_status[0] = destination->attack;
60 required_status[1] = destination->magic;
61
62 for (int i = 0; i < 2; i++) {
63 if (!BuildMenuCompVolume(required_status[i], held_status[i])) {
64 return 0;
65 }
66 }
67
68 for (int i = 0; i < 5; i++) {
69 s8 required = destination->elem[i];
70
71 if (!BuildMenuCompVolume(required, held_values.elem[i])) {
72 return 0;
73 }
74 }
75
76 for (int i = 0; i < 10; i++) {
77 s8 required = destination->vs_monster[i];
78
79 if (!BuildMenuCompVolume(required, held_values.vs_monster[i])) {
80 return 0;
81 }
82 }
83
84 return 1;
85}
86
87int IsLastWeapon(int weapon_no) {
88 int result = 0;
89 s16 last_weapons[15] = {
90 ITEM_WEAPON_ARISE_MARDAN,
91 ITEM_WEAPON_7THHEAVEN,
92 ITEM_WEAPON_SWORD_OF_ZEUS,
93 ITEM_WEAPON_CHRONICLE_SWORD,
94 ITEM_WEAPON_SUPER_STEVE,
95 ITEM_WEAPON_ANGE_GEAR,
96 ITEM_WEAPON_TALL_HAMMER,
97 ITEM_WEAPON_INFERNO,
98 ITEM_WEAPON_MOBIUS_RING,
99 ITEM_WEAPON_SECRET_ARMLET,
100 ITEM_WEAPON_HERCULES_WRATH,
101 ITEM_WEAPON_BABEL_S_SPEAR,
102 ITEM_WEAPON_STAR_BREAKER,
103 ITEM_WEAPON_SUPERNOVA,
104 -1,
105 };
106 int i = 0;
107
108 do {
109 int translated_no = TransWepNo(last_weapons[i]);
110
111 if (weapon_no == translated_no) {
112 result = 1;
113 } else {
114 i++;
115
116 if (translated_no > 0 && i < 15) {
117 continue;
118 }
119 }
120
121 break;
122 } while (true);
123
124 return result;
125}
126
127int IsNotBuildUpWeapon(int weapon_no) {
128 if (weapon_no < ITEM_WEAPON_START) {
129 return 1;
130 }
131
132 WEAPON_DATA *weapon = GetWeaponData(weapon_no);
133
134 if (weapon->buildup_mask0 != 0 || weapon->buildup_mask1 != 0) {
135 return 0;
136 }
137
138 return 1;
139}
140
141void SetWeaponBuildValue(WEAPON_HAVE *weapon, int destination_no) {
142 WEAPON_DATA *destination = GetWeaponData(destination_no);
143
144 if (weapon->endurance <= destination->endurance) {
145 weapon->endurance = destination->endurance;
146 }
147
148 if (weapon->speed <= destination->speed) {
149 weapon->speed = destination->speed;
150 }
151
152 if (weapon->durability < destination->durability) {
153 weapon->durability = destination->durability;
154 }
155}
156
157int EnableBuildUpModelSpecial(WEP_BUILDUP_INFO *build_info, WEAPON_HAVE *weapon) {
158 int result = 0;
159
160 if (weapon == NULL) {
161 return 0;
162 }
163
164 build_info[0].weapon_no = -1;
165 build_info[0].enabled = false;
166
167 switch (weapon->item_no) {
168 case ITEM_WEAPON_MARDAN_EINS:
169 case ITEM_WEAPON_MARDAN_TWEI:
170 build_info[0].enabled = false;
171 build_info[0].weapon_no = weapon->item_no + 1;
172
173 int fish_count = GetFishMardanGarayanNum();
174 int required_fish[2] = {5, 15};
175
176 if (required_fish[weapon->item_no - ITEM_WEAPON_MARDAN_EINS] > fish_count) {
177 break;
178 }
179
180 result = 1;
181 build_info[0].enabled = true;
182 break;
183 }
184
185 build_info[1].weapon_no = -1;
186 build_info[1].enabled = false;
187 return result;
188}
189
190int EnableBuildUpModel(WEP_BUILDUP_INFO *build_info, WEAPON_HAVE *weapon) {
191 if (weapon == NULL) {
192 return 0;
193 }
194
195 int weapon_no = weapon->item_no;
196
197 if (weapon_no != ITEM_WEAPON_MARDAN_EINS && weapon_no != ITEM_WEAPON_MARDAN_TWEI) {
198 } else {
199 EnableBuildUpModelSpecial(build_info, weapon);
200 return 1;
201 }
202
203 WEAPON_DATA *weapon_data = GetWeaponData(weapon_no);
204 WEAPON_HAVE weapon_copy;
205 memcpy(&weapon_copy, weapon, sizeof(WEAPON_HAVE));
206 s8 owner = weapon_data->owner;
207 int default_weapon_no = GetDefaultWeaponNo(owner);
208 int weapon_max = MenuCharaWeaponMax[owner];
209 int count = 0;
210
211 for (int position = 2; position <= weapon_max; position++) {
212 if ((position > 20 || (weapon_data->buildup_mask0 & (1 << position))) && (position <= 20 || (weapon_data->buildup_mask1 & (1 << (position - 20))))) {
213 build_info[count].weapon_no = default_weapon_no + position;
214
215 WEAPON_HAVE destination_have;
216 WepDataListToHaveCopy(build_info[count].weapon_no, &destination_have);
217
218 if (CompareBuildUpModelData2(&destination_have, weapon)) {
219 build_info[count].enabled = true;
220 } else {
221 build_info[count].enabled = false;
222 }
223
224 count++;
225 }
226 }
227
228 build_info[count].weapon_no = -1;
229 return 1;
230}
u32 buildup_mask1
Definition itemdata.hpp:674
u32 buildup_mask0
Definition itemdata.hpp:673
char vs_monster[10]
Definition itemdata.hpp:699