DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
btmisc.cpp
1#include "common.h"
2
3#include <libvu0.h>
4
5#include <cstdio>
6#include <cstdlib>
7#include <cstring>
8
9#include "btitem.hpp"
10#include "btmisc.hpp"
11#include "camera.hpp"
12#include "dataalloc.hpp"
13#include "dataread.hpp"
14#include "dngstatusdata.hpp"
15#include "dun/gameloop.hpp"
16#include "frame.hpp"
17#include "framevu1.hpp"
18#include "hitvalue.hpp"
19#include "itemdata.hpp"
20#include "mds.hpp"
21#include "menu_save.hpp"
22#include "savedata.hpp"
23#include "snd.hpp"
24
25/* Battle support: pack loading, item name paths, battle music, floor queries. */
26
30int BtBattleMusic_Flag;
31
35int BtBattleMusic_Wait;
36
40float BtBattleMusic_Vol;
41
42CFrame *LoadMDSFilePack(unsigned int *pack, char *name, CDataAlloc2<1> *buffer) {
43 int size;
44 unsigned int *file = GetPackFile(pack, name, &size);
45
46 if (file == NULL) {
47 printf("Model NotFound!!%s\n", name);
48 exit__2(-1);
49 }
50
51 return (CFrame *) LoadMDSFile(file, buffer, 0, NULL, NULL);
52}
53
54CFrame *LoadCollisionFilePack(unsigned int *pack, char *name, CDataAlloc2<1> *buffer) {
55 int size;
56 unsigned int *file = GetPackFile(pack, name, &size);
57
58 if (file == NULL) {
59 printf("Model NotFound!!%s\n", name);
60 exit__2(-1);
61 }
62
63 return (CFrame *) LoadCollisionFile(file, buffer);
64}
65
73void setCameraPassData(CFrameVu1 *frame, CCamera *camera, char *position_name, char *reference_name) {
74 sceVu0FMATRIX matrix;
75
76 // A matrix's fourth row is where the frame stands.
77 frame->SearchFrame(reference_name)->GetLWMatrix(matrix);
78 camera->SetRef(matrix[3]);
79 frame->SearchFrame(position_name)->GetLWMatrix(matrix);
80 camera->SetPos(matrix[3]);
81}
82
90void getFramePos(CFrameVu1 *frame, char *name, float *position) {
91 CFrame *named_frame = frame->SearchFrame(name);
92 sceVu0FVECTOR origin;
93
94 // The position wanted is the frame's own origin.
95 origin[0] = origin[1] = origin[2] = 0.0f;
96 origin[3] = 0.0f;
97 named_frame->GetWorldPosition(position, origin);
98}
99
107void makeWeaponName(char *name, int weapon_no) {
108 char *prefix[6] = {"c01w", "c04w", "c06w", "c05w", "c10w", "c18w"};
109 int first_weapon[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};
110 char number[16];
111 int chara_no = 0;
112
113 if (weapon_no >= ITEM_WEAPON_DAGGER_BROKEN) {
114 if (weapon_no >= ITEM_WEAPON_DAGGER_BROKEN && weapon_no < ITEM_WEAPON_WOODENSLINGSHOT_BROKEN) {
115 chara_no = 0;
116 }
117
118 if (weapon_no >= ITEM_WEAPON_WOODENSLINGSHOT_BROKEN && weapon_no < ITEM_WEAPON_MALLET_BROKEN) {
119 chara_no = 1;
120 }
121
122 if (weapon_no >= ITEM_WEAPON_MALLET_BROKEN && weapon_no < ITEM_WEAPON_GOLD_RING_BROKEN) {
123 chara_no = 2;
124 }
125
126 if (weapon_no >= ITEM_WEAPON_GOLD_RING_BROKEN && weapon_no < ITEM_WEAPON_FIGHTING_STICK_BROKEN) {
127 chara_no = 3;
128 }
129
130 if (weapon_no >= ITEM_WEAPON_FIGHTING_STICK_BROKEN && weapon_no < ITEM_WEAPON_MACHINE_GUN_BROKEN) {
131 chara_no = 4;
132 }
133
134 if (weapon_no >= ITEM_WEAPON_MACHINE_GUN_BROKEN) {
135 chara_no = 5;
136 }
137 }
138
139 strcpy(name, "dun/item/main_wep/");
140 strcat(name, prefix[chara_no]);
141 int offset = weapon_no - first_weapon[chara_no];
142
143 if (offset < 10) {
144 sprintf(number, "0%d", offset);
145 } else {
146 sprintf(number, "%2d", offset);
147 }
148
149 strcat(name, number);
150}
151
160void BtGetItemNamePath(char *model_path, char *texture_path, int item_no) {
161 item_no = TransWepNo(item_no);
162
163 if (item_no >= ITEM_WEAPON_START) {
164 makeWeaponName(model_path, item_no);
165 } else {
166 if (ITEM_NAME_TBL_NEW[item_no - ITEM_ATTACH_START] == NULL) {
167 item_no = ITEM_REGULAR_WATER;
168 }
169
170 strcpy(model_path, "dun/item/main_data/");
171 strcat(model_path, ITEM_NAME_TBL_NEW[item_no - ITEM_ATTACH_START]);
172 }
173
174 strcpy(texture_path, model_path);
175 strcat(model_path, MdsExtension);
176 strcat(texture_path, ".img");
177 printf("mds = %s\n", model_path);
178 printf("img = %s\n", texture_path);
179}
180
184char nameWepBuff_mds[64];
185
189char nameWepBuff_img[64];
190
191void BtGetWeaponNamePath2(char *chr_name, char *cfg_name, int chara, int weapon_index) {
192 char *prefix[6] = {"c01w", "c04w", "c06w", "c05w", "c10w", "c18w"};
193 char number[32];
194 char *base = prefix[chara];
195
196 strcpy(nameWepBuff_mds, base);
197 strcpy(nameWepBuff_img, base);
198
199 if (weapon_index < 10) {
200 sprintf(number, "0%d", weapon_index);
201 } else {
202 sprintf(number, "%2d", weapon_index);
203 }
204
205 strcat(nameWepBuff_mds, number);
206 strcat(nameWepBuff_mds, ".chr");
207 strcat(nameWepBuff_img, number);
208 strcat(nameWepBuff_img, ".cfg");
209 strcpy(chr_name, nameWepBuff_mds);
210 strcpy(cfg_name, nameWepBuff_img);
211}
212
213void BtGetWeaponNamePath3(char *chr_name, char *cfg_name, int weapon_no) {
214 WEAPON_DATA *weapon_data;
215 int chara_no;
216
217 if (weapon_no < ITEM_WEAPON_START) {
218 weapon_data = NULL;
219 } else {
220 weapon_data = GetWeaponData(weapon_no);
221
222 if (weapon_data != NULL) {
223 chara_no = (s8) weapon_data->owner;
224 weapon_no -= defWeapon__2[chara_no];
225 printf("offset %d\n", weapon_no);
226 BtGetWeaponNamePath2(chr_name, cfg_name, chara_no, weapon_no);
227 }
228 }
229}
230
238void getAtraToSaveData(int atra, int atra_no, CSaveData *save, int dungeon, int floor) {
239 printf("GET ATRA [%d] !!\n", atra);
240
241 if (atra < 0x28) {
242 save->AtraPartsGet(dungeon, atra);
243 } else {
244 save->AtraChipGet(dungeon, atra - 0x28);
245 }
246
247 ((CDngStatusData *) UserStatus)->GetAtraData(dungeon, floor, atra_no);
248}
249
257int createAttachVolume(int item_no, int dungeon) {
258 int volume;
259
260 if (item_no < ITEM_ATTACH_STAT_START || item_no > ITEM_ATTACH_MAGICAL_POWER) {
261 return 0;
262 }
263
264 int roll = (int) ((50.0f * (float) rand()) / 2.1474836e9f);
265 roll += (int) ((50.0f * (float) rand()) / 2.1474836e9f);
266 volume = 1;
267
268 if (roll < 31) {
269 volume = 2;
270 }
271
272 if (roll < 16) {
273 volume = 3;
274 }
275
276 return volume;
277}
278
279void BtBattleMusic_Init() {
280 BtBattleMusic_Flag = 0;
281 BtBattleMusic_Wait = 0;
282 BtBattleMusic_Vol = 0.0f;
283}
284
285void BtBattleMusic_Stop() {
286 if (BtBattleMusic_Flag != 0) {
287 SndSetBgmVolf(1.0f);
288 SndAmbientSetVolf(0.0f);
289 BtBattleMusic_Init();
290 }
291}
292
300void BtBattleMusic_Excg(float distance, float *field_volume, float *battle_volume) {
301 if (BtBattleMusic_Flag != 0) {
302 if (distance >= 110.0f) {
303 if (BtBattleMusic_Wait == 0) {
304 BtBattleMusic_Vol -= 1.0f / 30.0f;
305
306 if (BtBattleMusic_Vol < 0.1f) {
307 BtBattleMusic_Flag = 0;
308 BtBattleMusic_Vol = 0.0f;
309 }
310 } else {
311 BtBattleMusic_Wait--;
312 }
313 } else if (BtBattleMusic_Vol < 0.9f) {
314 BtBattleMusic_Vol += 1.0f / 30.0f;
315 }
316 }
317
318 if (BtBattleMusic_Flag == 0 && distance <= 100.0f) {
319 BtBattleMusic_Flag = 1;
320 }
321
322 if (BtBattleMusic_Vol >= 0.9f) {
323 BtBattleMusic_Vol = 0.9f;
324 }
325
326 if (BtBattleMusic_Vol <= 0.0f) {
327 BtBattleMusic_Vol = 0.0f;
328 }
329
330 *field_volume = 1.0f - BtBattleMusic_Vol;
331 *battle_volume = BtBattleMusic_Vol;
332}
333
337int yearFloorTbl[25] = {5, 18, 23, 38, 51, 66, 102, 109, 122, 140, 151, 162, 205,
338 208, 213, 225, 238, 249, 300, 310, 322, 340, 356, 382, 400};
339
340int BtGetFloorLevel(int floor) {
341 if (floor >= 0 && floor < 25) {
342 return yearFloorTbl[floor];
343 }
344
345 return 0;
346}
void SetRef(CFrame *parent, float x, float y, float z)
Definition camera.cpp:124
void SetPos(CFrame *parent, float x, float y, float z)
Definition camera.cpp:103
int AtraPartsGet(int georama_no, int plot_no)
Definition savedata.cpp:455
int AtraChipGet(int georama_no, int chip_id)
Definition savedata.cpp:494