DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
mainitemmodel.cpp
1#pragma argument_flag 0
2#pragma argument_flag_ones 33, 34, 39, 59, 225, 254, 266, 268
3#include "mainitemmodel.hpp"
4
5#include <cstdio>
6#pragma argument_flag_ones 58
7#include <libvu0.h>
8
9#include <cstring>
10
11#include "character.hpp"
12#include "collisiondata.hpp"
13#include "dataalloc.hpp"
14#include "dun/gameloop.hpp"
15#include "frame.hpp"
16#include "itembombeffect.hpp"
17#include "itemdata.hpp"
18#include "mds.hpp"
19#include "mglib.hpp"
20#include "shot_effect.hpp"
21#include "snd.hpp"
22#include "texture.hpp"
23
25 for (int i = 0; i < 6; i++) {
26 if (cash[i] == NULL) {
27 return i;
28 }
29 }
30
31 return -1;
32}
33
35 for (int i = 0; i < 16; i++) {
36 if (model[i] == ITEM_MODEL_FREE) {
37 return i;
38 }
39 }
40
41 return -1;
42}
43
44int CMainItemModel::SetCashModel(int item_no, unsigned int *model_data, unsigned int *texture_data, int texture_size) {
45 int slot = GetFreeCashNo();
46
47 if (slot == -1) {
48 return -1;
49 }
50
51 BtItemCashArea[slot].Reset();
52 u_char *texture_copy = BtItemCashArea[slot].base + BtItemCashArea[slot].used * 16;
53 CDataAlloc2<1> *area = &BtItemCashArea[slot];
54 area->Alloc((texture_size >> 4) + 1);
55 memcpy(texture_copy, texture_data, texture_size);
56 TexManager.DeleteTextureBlock(slot + 0x38);
57 TexManager.CleanUpBuffer();
58 LOADTEXTURE_INFO2 textures[2] = {};
59 textures[0].name = (char *) texture_copy;
60 textures[0].block_no = slot + 0x38;
61 TexManager.LoadTextureBlockEX(slot + 0x38, textures);
62 cash[slot] = (u_int *) LoadMDSFile(model_data, area, 0, NULL, NULL);
63 cash_lock[slot] = 1;
64 cash_item[slot] = item_no;
65 int model_no = GetFreeModelNo();
66 model[model_no] = ITEM_MODEL_LOADED;
67 model_cash[model_no] = slot;
68 return model_no;
69}
70
71void CMainItemModel::DeleteModel(int model_no) {
72 cash_lock[model_cash[model_no]]--;
73
74 if (cash_lock[model_cash[model_no]] <= 0) {
75 cash[model_cash[model_no]] = NULL;
76 cash_lock[model_cash[model_no]] = 0;
77 printf(MainItemRemoveMessage);
78 }
79
80 model[model_no] = ITEM_MODEL_FREE;
81 model_cash[model_no] = -1;
82}
83
84int CMainItemModel::SetHandModel(int source_no) {
85 int hand_no = GetFreeModelNo();
86
87 if (hand_no == -1) {
88 return -1;
89 }
90
91 model[hand_no] = ITEM_MODEL_HAND;
92 float zero = 0.0f;
93 frame[hand_no].SetPosition(zero, zero, zero);
94 float angle = HALF_PI;
95 frame[hand_no].SetRotation(angle, 0.0f, 0.0f);
96 model_cash[hand_no] = model_cash[source_no];
97 cash_lock[model_cash[source_no]]++;
98 printf(MainItemHandMessage, hand_no, cash_lock[model_cash[source_no]]);
99 return hand_no;
100}
101
103 for (int i = 0; i < 16; i++) {
104 switch (model[i]) {
105 case ITEM_MODEL_HAND:
106 DeleteModel(i);
107 break;
108 }
109 }
110}
111
115int CMainItemModel::SetThrowModel(int source_no, float *position, float *heading) {
116 int slot = GetFreeModelNo();
117 model[slot] = ITEM_MODEL_THROWN;
118 sceVu0CopyVector(velocity[slot], heading);
119 frame[slot].SetPosition(position);
120 frame[slot].SetRotation(HALF_PI, 0.0f, 0.0f);
121 throw_time[slot] = 0;
122 model_cash[slot] = model_cash[source_no];
123 cash_lock[model_cash[source_no]]++;
124 return slot;
125}
126
128 sceVu0FVECTOR position;
129 sceVu0FVECTOR rotation;
130 CFrame *hand = CharaMain.frame->SearchFrame("item");
131 int i;
132 s32 *cash_no;
133 CFrame *placement;
134
135 for (i = 0; i < 16; i++) {
136 switch (model[i]) {
137 case ITEM_MODEL_HAND:
138 cash_no = &model_cash[i];
139 TexManager.ReloadTexture(Vif1Packet, *cash_no + 0x38);
140 placement = &frame[i];
141 sceVu0CopyVector(position, placement->position);
142 placement->GetRotation(rotation);
143 ((CFrame *) cash[*cash_no])->SetPosition(position);
144 ((CFrame *) cash[*cash_no])->SetRotation(rotation[0], rotation[1], rotation[2]);
145 ((CFrame *) cash[*cash_no])->SetReference(hand);
146 MGDraw((CFrame *) cash[*cash_no]);
147 break;
148 case ITEM_MODEL_THROWN:
149 cash_no = &model_cash[i];
150 TexManager.ReloadTexture(Vif1Packet, *cash_no + 0x38);
151 placement = &frame[i];
152 sceVu0CopyVector(position, placement->position);
153 placement->GetRotation(rotation);
154 placement->SetPosition(position);
155 ((CFrame *) cash[*cash_no])->SetPosition(position);
156 ((CFrame *) cash[*cash_no])->SetRotation(rotation[0], rotation[1], rotation[2]);
157 ((CFrame *) cash[*cash_no])->DeleteReference();
158 MGDraw((CFrame *) cash[*cash_no]);
159 break;
160 case ITEM_MODEL_UNK_3:
161 cash_no = &model_cash[i];
162 TexManager.ReloadTexture(Vif1Packet, *cash_no + 0x38);
163 ((CFrame *) cash[*cash_no])->DeleteReference();
164 placement = &frame[i];
165 sceVu0CopyVector(position, placement->position);
166 placement->GetRotation(rotation);
167 ((CFrame *) cash[*cash_no])->SetPosition(position);
168 ((CFrame *) cash[*cash_no])->SetRotation(rotation[0], rotation[1], rotation[2]);
169 MGDraw((CFrame *) cash[*cash_no]);
170 break;
171 case ITEM_MODEL_FREE:
172 case ITEM_MODEL_LOADED:
173 break;
174 }
175 }
176}
177
178char MainItemRemoveMessage[] __attribute__((section(".rodata"))) = "remove !!\n";
179char MainItemHandMessage[] __attribute__((section(".rodata"))) = "code = %d, lock = %d\n";
180int ItemThrowStep(float *position, float *velocity);
181
183 int i;
184 int step_result;
185 CFrame *placement;
186 int item_no;
187 sceVu0FVECTOR position;
188 sceVu0FVECTOR up = {0.0f, 1.0f, 0.0f, 0.0f};
189
190 for (i = 0; i < 16; i++) {
191 switch (model[i]) {
192 case ITEM_MODEL_HAND:
193 break;
194 case ITEM_MODEL_THROWN: {
195 placement = &frame[i];
196 sceVu0CopyVector(position, placement->position);
197 step_result = ItemThrowStep(position, velocity[i]);
198 placement->SetPosition(position);
199
200 if (step_result == 2) {
201 throw_time[i] = 45;
202 }
203
204 throw_time[i]++;
205
206 if (throw_time[i] < 45) {
207 break;
208 }
209
210 throw_time[i] = 0;
211 item_no = cash_item[model_cash[i]];
212
213 switch (item_no) {
214 case ITEM_STONE:
215 NowColData->Set(position, 8, 5, 8.0f, 1.0f, 2, 2, 0, 0);
216 DeleteModel(i);
217 break;
218 case ITEM_GOOEY_PEACH:
219 NowColData->Set(position, 8, 5, 8.0f, 1.0f, 2, 2, 0x800, 0);
220 DeleteModel(i);
221 break;
222 case ITEM_THROBBING_CHERRY:
223 NowColData->Set(position, 2, 5, 8.0f, 1.0f, 2, 2, 0x100, 0);
224 DeleteModel(i);
225 break;
226 case ITEM_POISONOUS_APPLE:
227 NowColData->Set(position, 2, 5, 8.0f, 1.0f, 2, 2, 0x200, 0);
228 DeleteModel(i);
229 break;
230 case ITEM_BOMB:
231 default:
232 SetBombEffect(position, 3, (selectMapNo + 1) * 30, 1.0f);
233 DeleteModel(i);
234 break;
235 case ITEM_HOLY_WATER:
236 SndSePlay(SE_HOLY_GEM, -1, 0);
237 SndSePlay(SE_EXPLOSION, -1, 0);
238 MasekiEffect[4].Set(position, up, -1, -1, 0, NULL, -1);
239 MasekiEffect[4].SetDmg((int) (30.0f * (float) (selectMapNo + 1)));
240 MasekiEffect[4].SetEnemyAttr(1);
241 MasekiEffect[4].SetWait(2);
242 DeleteModel(i);
243 break;
244 case ITEM_FIRE_GEM:
245 case ITEM_ICE_GEM:
246 case ITEM_THUNDER_GEM:
247 case ITEM_WIND_GEM:
248 case ITEM_HOLY_GEM: {
249 SndSePlay(item_no - 0x3C, -1, 0);
250 SndSePlay(SE_EXPLOSION, -1, 0);
251 CSHOT_EFFECT *effect = &MasekiEffect[item_no - ITEM_FIRE_GEM];
252 effect->Set(position, up, -1, -1, 0, NULL, -1);
253 effect->SetDmg((int) (30.0f * (float) (selectMapNo + 1)));
254 effect->SetLifeTime(10);
255 effect->SetWait(5);
256 DeleteModel(i);
257 break;
258 }
259 }
260
261 break;
262 }
263 case ITEM_MODEL_UNK_3:
264 case ITEM_MODEL_FREE:
265 case ITEM_MODEL_LOADED:
266 break;
267 }
268 }
269}
270
272 for (int i = 0; i < 6; i++) {
273 cash[i] = NULL;
274 cash_lock[i] = 0;
275 throw_time[i] = 0;
276 }
277
278 for (int i = 0; i < 16; i++) {
279 model[i] = ITEM_MODEL_FREE;
280 frame[i].SetPosition(0.0f, 0.0f, 0.0f);
281 frame[i].SetRotation(PI, 0.0f, 0.0f);
282 }
283}
284
286 int type;
287
288 if (now <= 0) {
289 return ACTIVE_ITEM_NONE;
290 }
291
292 int item_no = item[now];
293 type = -1;
294
295 if (item_no == -1) {
296 return ACTIVE_ITEM_NONE;
297 }
298
299 switch (item_no) {
300 case ITEM_REGULAR_WATER:
301 case ITEM_TASTY_WATER:
302 case ITEM_PREMIUM_WATER:
303 case ITEM_STAMINA_DRINK:
304 case ITEM_ANTIDOTE_DRINK:
305 type = ACTIVE_ITEM_DRINK;
306 break;
307 case ITEM_BREAD:
308 case ITEM_PREMIUM_CHICKEN:
309 case ITEM_SOAP:
310 case ITEM_MIGHTY_HEALING:
311 case ITEM_CHEESE:
312 case ITEM_MELLOW_BANANA:
313 type = ACTIVE_ITEM_EAT;
314 break;
315 }
316
317 if (type != -1) {
318 return type;
319 }
320
321 if (ITEM_LIST[item_no - ITEM_ATTACH_START].kind_flags & 2) {
322 return ACTIVE_ITEM_ACTION;
323 }
324
325 if (item_no == ITEM_DRAN_S_FEATHER) {
326 return ACTIVE_ITEM_FEATHER;
327 }
328
329 return ACTIVE_ITEM_NONE;
330}
CFrame * frame
int Set(float *position, int damage, int life, float radius, float scale_rate, int target_mask, int kind, int flags, int attribute)
sceVu0FVECTOR position
Definition frame.hpp:76
void DeleteModel(int model_no)
float velocity[16][4]
int SetHandModel(int source_no)
int SetThrowModel(int source_no, float *position, float *heading)
int SetCashModel(int item_no, unsigned int *model_data, unsigned int *texture_data, int texture_size)
void SetEnemyAttr(int attribute)
void SetDmg(int damage)
void SetLifeTime(int life_time)
void SetWait(int wait)
int Set(float *position, float *target, int owner, int sub_id, int source, CFrame *parent, int initial_phase)