DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
hitvalue.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 612
4
5#include "hitvalue.hpp"
6
7#include <libvu0.h>
8
9#include <cmath>
10
11#include "dngmessageman.hpp"
12#include "dun/gameloop.hpp"
13#include "frame.hpp"
14#include "itemdata.hpp"
15#include "menu_dungeon.hpp"
16#include "menu_inventory.hpp"
17#include "mglib.hpp"
18#include "rect.hpp"
19#include "savedata.hpp"
20#include "snd.hpp"
21#include "texture.hpp"
22#include "userstatus.hpp"
23
27int defWeapon__2[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};
28
29int element_tbl[6] = {1, 2, 4, 8, 0x10, 0};
30
31#ifdef PAL
33char *LanguageStr[7] = {"dun/img/jp/", "dun/img/us/", "dun/img/us_e/", "dun/img/fr/",
34 "dun/img/gr/", "dun/img/it/", "dun/img/sp/"};
35#endif
36
37int BattleSubWeaponDmg(float amount, int kind) {
38 int default_weapons[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};
39 int chara_no = UserStatus->cur_chara;
40 int default_weapon;
41 WEAPON_HAVE *weapon = &UserStatus->chara_weapons[chara_no][UserStatus->equipped_weapon_slot[chara_no]];
42
43 if (weapon->item_no == ITEM_WEAPON_SERPENT_SWORD && SaveData->GetGameFlag(0x30) == 0) {
44 return 0;
45 }
46
47 if (weapon->flags & 0x200) {
48 amount *= 0.5f;
49 }
50
51 if (weapon->flags & 0x100) {
52 amount *= 2.0f;
53 }
54
55 default_weapon = default_weapons[chara_no];
56
57 if (default_weapon == UserStatus->chara_weapons[chara_no][UserStatus->equipped_weapon_slot[chara_no]].item_no) {
58 return 0;
59 }
60
61 float wear = 1.5f - 0.01f * NowWeaponHave->endurance;
62 float old_durability = weapon->durability_f;
63 wear *= amount;
64 wear += 0.1f * kind;
65 weapon->durability_f = old_durability - wear;
66
67 if (weapon->durability_f <= 0.0f) {
68 int powder_slot = ((CDngStatusData *) UserStatus)->CheckActItemSlot(ITEM_AUTO_REPAIR_POWDER);
69
70 if (powder_slot != -1) {
71 DelActiveItem(powder_slot + 1);
72 weapon->durability_f = weapon->durability;
73 DngMessMan.message = 0xBC;
74 DngMessMan.timer = 0xF0;
75 DngMessMan.steev_window = false;
76 SndSePlay(SE_WEAPON_REPAIR, -1, 0);
77 }
78 }
79
80 if (weapon->durability_f <= 0.0f) {
81 weapon->durability_f = 0.0f;
82 SndSePlay(SE_WEAPON_BREAK, -1, 0);
83
84 int now_item = UserStatus->chara_weapons[chara_no][UserStatus->equipped_weapon_slot[chara_no]].item_no;
85
86 if (default_weapon + 1 == now_item) {
87 DngMessMan.insert_mes_1 = GetCommonItemDataSystemMsg(weapon->item_no);
88 DngMessMan.insert_value_1 = weapon->level;
89 DngMessMan.message = 0xA1;
90 DngMessMan.timer = 0x1E0;
91 DngMessMan.steev_window = false;
92 WepDataListToHaveCopy(default_weapon, weapon);
93 SetWeaponAttachStatus(NowWeaponHave);
94 NowWeaponHave->durability_f = 0.0f;
95 weapon->durability_f = 0.0f;
96 return 1;
97 }
98
99 if (default_weapon + 1 != (s16) now_item) {
100 WEAPON_HAVE *replacement = UserStatus->chara_weapons[chara_no];
101
102 for (int slot = 0; slot < 10; replacement++, slot++) {
103 if (replacement->item_no == default_weapon) {
104 UserStatus->equipped_weapon_slot[chara_no] = slot;
105 SetWeaponAttachStatus(NowWeaponHave);
106 DngMessMan.insert_mes_1 = GetCommonItemDataSystemMsg(weapon->item_no);
107 DngMessMan.insert_value_1 = weapon->level;
108 DngMessMan.insert_mes_2 = GetCommonItemDataSystemMsg(replacement->item_no);
109 DngMessMan.insert_value_2 = replacement->level;
110 DngMessMan.message = 0xA0;
111 DngMessMan.timer = 0x1E0;
112 DngMessMan.steev_window = false;
113 weapon->item_no = -1;
114 return 1;
115 }
116
117 if (replacement->item_no == default_weapon + 1) {
118 UserStatus->equipped_weapon_slot[chara_no] = slot;
119 SetWeaponAttachStatus(NowWeaponHave);
120 DngMessMan.insert_mes_1 = GetCommonItemDataSystemMsg(weapon->item_no);
121 DngMessMan.insert_value_1 = weapon->level;
122 DngMessMan.insert_mes_2 = GetCommonItemDataSystemMsg(replacement->item_no);
123 DngMessMan.insert_value_2 = replacement->level;
124 DngMessMan.message = 0xA0;
125 DngMessMan.timer = 0x1E0;
126 DngMessMan.steev_window = false;
127
128 if (chara_no == 3) {
129 replacement->best_elem = 0;
130 }
131
132 weapon->item_no = -1;
133 return 2;
134 }
135 }
136 }
137 }
138
139 if (0.1f * weapon->durability <= old_durability && 0.1f * weapon->durability > weapon->durability_f) {
140 DngMessMan.insert_mes_1 = GetCommonItemDataSystemMsg(weapon->item_no);
141 DngMessMan.insert_value_1 = weapon->level;
142 DngMessMan.message = 0x97;
143 DngMessMan.timer = 0xF0;
144 DngMessMan.steev_window = false;
145 }
146
147 if (0.05f * weapon->durability <= old_durability && 0.05f * weapon->durability > weapon->durability_f) {
148 DngMessMan.insert_mes_1 = GetCommonItemDataSystemMsg(weapon->item_no);
149 DngMessMan.insert_value_1 = weapon->level;
150 DngMessMan.message = 0x98;
151 DngMessMan.timer = 0xF0;
152 DngMessMan.steev_window = false;
153 }
154
155 return 0;
156}
157
158void HitValueEntry(CHitValue *values, float *world, int amount, int kind, CFrame *frame) {
159 for (int i = 0; i < 32; i++) {
160 if (values[i].active == 0) {
161 values[i].EntryValue(world, amount, kind, frame);
162 return;
163 }
164 }
165}
166
167void CHitValue::EntryValue(float *world, int amount, int kind, CFrame *frame) {
168 int divisor = 10000;
169
170 for (int i = 0; i < 5; i++) {
171 digit[i] = -1;
172 phase[i] = -PI_SHORT;
173 }
174
175 this->kind = kind;
176 opacity = 0.0f;
177 opacity_speed = 3.0f;
178 active = true;
179 this->frame = frame;
180 sceVu0CopyVector(pos, world);
181 pos[3] = 1.0f;
182
183 // A kind of -1 is a mark rather than a number, so it has no digits.
184 if (kind == HIT_VALUE_ZERO) {
185 digit[0] = -2;
186 last_digit = 1;
187 return;
188 }
189
190 int digit_value;
191 int seen_nonzero = 0;
192
193 for (int i = 4; i >= 0; i--) {
194 digit_value = amount / divisor;
195
196 if (digit_value > 0) {
197 seen_nonzero = 1;
198 }
199
200 // The units place is always drawn; the rest only past the first digit.
201 if (i == 0 || seen_nonzero != 0) {
202 digit[i] = digit_value;
203 amount -= digit_value * divisor;
204
205 if (divisor < 9) {
206 last_digit = i;
207 }
208 }
209
210 divisor /= 10;
211 }
212
213 switch (kind) {
214 case HIT_VALUE_MONSTER:
215 texel.x = 0;
216 texel.y = 0x9E;
217 texel.width = 0xC;
218 texel.height = 0x12;
219 break;
220 case HIT_VALUE_GOLD:
221 texel.x = 0;
222 texel.y = 0x8C;
223 texel.width = 0xC;
224 texel.height = 0x12;
225 break;
226 case HIT_VALUE_PLAYER:
227 texel.x = 0;
228 texel.y = 0x7C;
229 texel.width = 0xC;
230 texel.height = 0x12;
231 break;
232 }
233}
234
236 if (active == 0) {
237 return;
238 }
239
240 if (kind == HIT_VALUE_PLAYER && ((s32 *) SaveData->GetConfigData())[9] == 1) {
241 return;
242 }
243
244 if ((kind == HIT_VALUE_MONSTER || kind == HIT_VALUE_ZERO) && ((s32 *) SaveData->GetConfigData())[10] == 1) {
245 return;
246 }
247
248 CTexture *digit_texture = TexManager.GetTexture("stayframe", -1);
249 CTexture *mark_texture = TexManager.GetTexture("itempack", -1);
250 int screen[4];
251 sceVu0FVECTOR world;
252
253 if (frame != NULL) {
254 sceVu0CopyVector(world, frame->position);
255 world[0] += pos[0];
256 world[1] += pos[1];
257 world[2] += pos[2];
258 world[3] = 1.0f;
259 } else {
260 sceVu0CopyVector(world, pos);
261 }
262
263 if (MGRotTransPers2D(screen, world, 0) == 0) {
264 return;
265 }
266
267 if (digit[0] == -2) {
268 int bounce = (int) (48.0f * sinf(phase[0]));
269 set2DSprite(Vif1Packet, mark_texture, CRect_i_(screen[0], screen[1] - bounce - 48, 72, 24), CRect_i_(0, 128, 72, 24), (u8) opacity);
270 return;
271 }
272
273 for (int place = 0; place < 5; place++) {
274 if (digit[place] == -1) {
275 continue;
276 }
277
278 int bounce = (int) (48.0f * sinf(phase[place]));
279 set2DSprite(Vif1Packet, digit_texture, CRect_i_(screen[0] - place * texel.width, screen[1] - bounce - 48, texel.width, texel.height), CRect_i_(texel.x + digit[place] * texel.width, texel.y, texel.width, texel.height), (u8) opacity);
280 }
281}
282
284 if (active != 0) {
285 if (digits[0] == -2) {
286 digit_angle[0] += PI_SHORT / 20.0f;
287
288 if (digit_angle[0] >= PI_SHORT) {
289 digit_angle[0] = PI_SHORT;
290 alpha_speed *= -1.2f;
291 }
292 } else {
293 // Each place further along hops more slowly.
294 for (int i = 0; i < 5; i++) {
295 if (digits[i] != -1) {
296 digit_angle[i] += PI_SHORT / (20.0f + 5.0f * i);
297
298 if (digit_angle[i] >= PI_SHORT) {
299 digit_angle[i] = PI_SHORT;
300
301 if (i == last_digit) {
302 alpha_speed *= -1.2f;
303 last_digit = -1;
304 }
305 }
306 }
307 }
308 }
309
310 if (alpha_speed > 0.0f) {
312
313 if (alpha >= 128.0f) {
314 alpha = 128.0f;
315 }
316 }
317
318 if (alpha_speed < 0.0f) {
320
321 if (alpha <= 0.0f) {
322 alpha = 0.0f;
323 active = false;
324 }
325 }
326 }
327}
sceVu0FVECTOR position
Definition frame.hpp:76
void EntryValue(float *world, int amount, int kind, CFrame *frame)
Definition hitvalue.cpp:167
float opacity
Definition hitvalue.hpp:44
float alpha_speed
Definition hitvalue.hpp:48
void Draw()
Definition hitvalue.cpp:235
CFrame * frame
Definition hitvalue.hpp:30
void Step()
Definition hitvalue.cpp:283
sceVu0FVECTOR pos
Definition hitvalue.hpp:29
float digit_angle[5]
Definition hitvalue.hpp:33
s32 digit[5]
Definition hitvalue.hpp:39
float phase[5]
Definition hitvalue.hpp:34
s32 last_digit
Definition hitvalue.hpp:53
s32 digits[5]
Definition hitvalue.hpp:38
float alpha
Definition hitvalue.hpp:43
RECT texel
Definition hitvalue.hpp:58
float opacity_speed
Definition hitvalue.hpp:49
int GetGameFlag(int flag_no)
Definition savedata.cpp:258
void * GetConfigData()
Definition savedata.cpp:33
WEAPON_HAVE chara_weapons[6][11]
s8 equipped_weapon_slot[6]
s32 width
Definition rect.hpp:36
s32 height
Definition rect.hpp:37
int y
Definition title.cpp:63
int x
Definition title.cpp:62
float durability_f
Definition itemdata.hpp:695