DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
randomitem.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 1383
4
5#include "randomitem.hpp"
6
7#include <libvu0.h>
8
9#include <cmath>
10
11#include "character.hpp"
12#include "dngstatusdata.hpp"
13#include "dun/gameloop.hpp"
14#include "gameutil.hpp"
15#include "hitvalue.hpp"
16#include "mathutil.hpp"
17#include "mglib.hpp"
18#include "rect.hpp"
19#include "shot_freefuncs.hpp"
20#include "snd.hpp"
21#include "texture.hpp"
22
24 for (int i = 0; i < 32; i++) {
25 if (id[i] == -1 || distance[i] > 200.0f) {
26 continue;
27 }
28
29 sceVu0FVECTOR draw_position;
30 int texel_x;
31 int texel_y;
32 sceVu0CopyVector(draw_position, position[i]);
33 draw_position[1] += 8.0f * sinf(phase[i]);
34
35 if (amount[i] != -1) {
36 texel_x = 0x40;
37 texel_y = 0;
38 } else {
39 switch (item_no[i]) {
40 case ITEM_DRAN_S_CREST:
41 case ITEM_HOOK:
42 case ITEM_KING_S_SLATE:
43 case ITEM_GUN_POWDER:
44 case ITEM_CLOCK_HANDS:
45 case ITEM_POINTY_CHESTNUT:
46 case ITEM_BLACK_KNIGHT_CREST:
47 texel_x = 0;
48 texel_y = 0;
49 break;
50 case ITEM_SHINY_STONE:
51 texel_x = 0x40;
52 texel_y = 0x40;
53 break;
54 case ITEM_RED_BERRY:
55 texel_x = 0;
56 texel_y = 0x40;
57 break;
58 default:
59 texel_x = 0x40;
60 texel_y = 0xC0;
61 break;
62 }
63
64 if (item_no[i] >= ITEM_ATTACH_START && item_no[i] < ITEM_ATTACH_ELEMENT_END) {
65 texel_x = 0;
66 texel_y = 0x80;
67 }
68
69 if (item_no[i] >= ITEM_ATTACH_SLAYER_START && item_no[i] < ITEM_ATTACH_SLAYER_END) {
70 texel_x = 0x40;
71 texel_y = 0x80;
72 }
73 }
74
75 BtSet3DCellModel(draw_position, gold_texture, 3.5f, texel_x, texel_y, 0x40, 0x40, 0x80);
76 }
77}
78
80 CTexture *texture = TexManager.GetTexture("itempack", -1);
81
82 for (int i = 0; i < 32; i++) {
83 if (id[i] != -1 && amount[i] == -1) {
84 int x = (int) (0.1f * (position[i][0] - 80.0f));
85 int y = (int) (0.1f * (position[i][2] - 80.0f));
86 set2DSprite(Vif1Packet, texture, CRect_i_(x + 0x184, y + 0x48, 8, 8), CRect_i_(0x50, 0x68, 8, 8));
87 }
88 }
89}
90
92 for (int i = 0; i < 32; i++) {
93 int event = pickup_event[i];
94
95 if (event != -1) {
96 pickup_event[i] = -1;
97 return event;
98 }
99 }
100
101 return -1;
102}
103
105 for (int i = 0; i < 32; i++) {
106 if (pickup_blocked[i] > 0 && pickup_blocked[i] < 3) {
107 pickup_blocked[i] = 3;
108 return 1;
109 }
110 }
111
112 return 0;
113}
114
116 sceVu0FVECTOR player_position;
117 int gold = 0;
118
119 sceVu0CopyVector(player_position, CharaMain.pos);
120
121 for (int i = 0; i < 32; i++) {
122 if (id[i] == -1 || state[i] != RANDOM_ITEM_WAITING) {
123 continue;
124 }
125
126 distance[i] = DistVector(position[i], player_position);
127
128 if (pickup_blocked[i] > 0 && distance[i] >= 8.5f) {
129 pickup_blocked[i] = 0;
130 }
131
132 if (pickup_blocked[i] != 0 || distance[i] > 5.0f) {
133 continue;
134 }
135
136 if (amount[i] == -1 && item_no[i] != -1) {
137 int blocked = ((CDngStatusData *) UserStatus)->CheckItemGet(item_no[i]);
138
139 if (blocked == 0) {
140 pickup_event[i] = item_no[i];
141 id[i] = -1;
142 } else {
143 pickup_blocked[i] = blocked;
144 }
145 } else {
146 state[i] = RANDOM_ITEM_TAKEN;
147
148 if (item_no[i] == -1) {
149 SndSePlay(SE_ITEM_GET, -1, 0);
150 }
151
152 gold += amount[i];
153 position[i][1] += 5.0f;
154 HitValueEntry(NowHitValue, position[i], gold, HIT_VALUE_GOLD, NULL);
155 position[i][1] -= 5.0f;
156 }
157 }
158
159 return gold;
160}
161
162void CRandomItem::Set(float *drop_position, int slot_id, int gold, int item) {
163 int slot = CheckID();
164
165 if (slot != -1) {
166 sceVu0CopyVector(position[slot], drop_position);
167 position[slot][1] += 1.75f;
168 id[slot] = slot_id;
169 amount[slot] = gold;
170 item_no[slot] = item;
171 pickup_event[slot] = -1;
172 state[slot] = RANDOM_ITEM_RISING;
173 phase[slot] = 0.0f;
174 pickup_blocked[slot] = 0;
175 }
176}
177
179 for (int i = 0; i < 32; i++) {
180 if (id[i] == -1) {
181 return i;
182 }
183 }
184
185 bob_phase = 0.0f;
186 return -1;
187}
188
190 for (int i = 0; i < 32; i++) {
191 if (id[i] != -1 && item_no[i] == item) {
192 return item;
193 }
194 }
195
196 return 0;
197}
198
200 bob_phase += 0.05235988f;
201
202 if (bob_phase > PI) {
203 bob_phase -= PI;
204 }
205
206 for (int i = 0; i < 32; i++) {
207 if (id[i] == -1) {
208 continue;
209 }
210
211 switch (state[i]) {
212 case RANDOM_ITEM_RISING:
213 phase[i] += 0.10471976f;
214
215 if (phase[i] > PI) {
216 state[i] = RANDOM_ITEM_WAITING;
217 phase[i] = 0.0f;
218
219 if (item_no[i] == -1) {
220 SndSePlay(SE_RANDOM_ITEM_EMPTY, -1, 0);
221 } else {
222 SndSePlay(SE_RANDOM_ITEM, -1, 0);
223 }
224 }
225
226 break;
227 case RANDOM_ITEM_WAITING:
228 break;
229 case RANDOM_ITEM_TAKEN:
230 phase[i] += 0.10471976f;
231
232 if (phase[i] > 2.5132742f) {
233 id[i] = -1;
234 }
235
236 break;
237 }
238 }
239}
float pos[4]
Definition object.hpp:18
int CheckPosition()
s32 item_no[32]
s32 state[32]
void MapSymbolDraw()
int checkEvent()
int CheckItemNo(int item)
float position[32][4]
CTexture * gold_texture
float bob_phase
s32 amount[32]
float phase[32]
void Set(float *drop_position, int slot_id, int gold, int item)
float distance[32]
s32 pickup_blocked[32]
s32 pickup_event[32]