DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
stealitem.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3
4#include "stealitem.hpp"
5
6#include <cmath>
7
8#include "character.hpp"
9#include "dun/gameloop.hpp"
10#include "frame.hpp"
11#include "framevu1.hpp"
12#include "mathutil.hpp"
13#include "mglib.hpp"
14
16 this->frame = model;
17
18 for (int i = 0; i < STEAL_ITEM_MAX; i++) {
19 this->state[i] = STEAL_ITEM_NONE;
20 this->aux_state[i] = -1;
21 }
22}
23
24void CStealItem::Set(float *position, int item_no) {
25 int slot = -1;
26
27 for (int i = 0; i < STEAL_ITEM_MAX; i++) {
28 if (this->state[i] == STEAL_ITEM_NONE) {
29 slot = i;
30 break;
31 }
32 }
33
34 if (slot == -1) {
35 return;
36 }
37
38 sceVu0CopyVector(this->pos[slot], position);
39 this->base_height[slot] = position[1];
40 this->state[slot] = STEAL_ITEM_RISE;
41 this->speed[slot] = 0.5f;
42 this->phase[slot] = 0.0f;
43 this->item[slot] = item_no;
44 this->angle = 0.0f;
45}
46
48 sceVu0FVECTOR target;
49 sceVu0FVECTOR direction;
50
51 sceVu0CopyVector(target, CharaMain.pos);
52 target[1] = 15.0f;
53
54 this->angle += 0.31415927f;
55
56 if (this->angle >= TWO_PI) {
57 this->angle -= TWO_PI;
58 }
59
60 for (int i = 0; i < STEAL_ITEM_MAX; i++) {
61 int state = this->state[i];
62
63 switch (state) {
64 case STEAL_ITEM_RISE:
65 this->speed[i] += 0.05f;
66 this->pos[i][1] = this->base_height[i] + 12.0f * sinf(this->phase[i]);
67 this->phase[i] += 0.034906585f;
68
69 direction[0] = target[0] - this->pos[i][0];
70 direction[1] = target[1] - this->pos[i][1];
71 direction[2] = target[2] - this->pos[i][2];
72 direction[3] = 1.0f;
73 sceVu0Normalize(direction, direction);
74 sceVu0ScaleVectorXYZ(direction, direction, this->speed[i]);
75 this->pos[i][0] += direction[0];
76 this->pos[i][1] += direction[1];
77 this->pos[i][2] += direction[2];
78
79 if (this->phase[i] >= HALF_PI) {
80 this->state[i] = STEAL_ITEM_HOME;
81 }
82
83 break;
84
85 case STEAL_ITEM_HOME:
86 if (DistVector(target, this->pos[i]) <= 5.0f) {
87 this->state[i] = STEAL_ITEM_ARRIVED;
88 break;
89 }
90
91 this->speed[i] += 0.02f;
92 direction[0] = target[0] - this->pos[i][0];
93 direction[1] = target[1] - this->pos[i][1];
94 direction[2] = target[2] - this->pos[i][2];
95 direction[3] = 1.0f;
96 sceVu0Normalize(direction, direction);
97 sceVu0ScaleVectorXYZ(direction, direction, this->speed[i]);
98 this->pos[i][0] += direction[0];
99 this->pos[i][1] += direction[1];
100 this->pos[i][2] += direction[2];
101 break;
102
103 case STEAL_ITEM_ARRIVED:
104 break;
105
106 case STEAL_ITEM_NONE:
107 break;
108 }
109 }
110}
111
113 for (int i = 0; i < STEAL_ITEM_MAX; i++) {
114 if (this->state[i] == STEAL_ITEM_NONE) {
115 continue;
116 }
117
118 this->frame->SetPosition(this->pos[i]);
119 this->frame->SetRotation(this->angle, 0.0f, 0.0f);
120 MGDraw(this->frame);
121 }
122}
123
125 for (int i = 0; i < STEAL_ITEM_MAX; i++) {
126 if (this->state[i] == STEAL_ITEM_NONE) {
127 continue;
128 }
129
130 if (this->state[i] == STEAL_ITEM_ARRIVED) {
131 this->state[i] = STEAL_ITEM_NONE;
132 return this->item[i];
133 }
134 }
135
136 return -1;
137}
float pos[4]
Definition object.hpp:18
s32 item[STEAL_ITEM_MAX]
Definition stealitem.hpp:44
void Initialize(CFrameVu1 *model)
Definition stealitem.cpp:15
float base_height[STEAL_ITEM_MAX]
Definition stealitem.hpp:38
float phase[STEAL_ITEM_MAX]
Definition stealitem.hpp:43
int checkEvent()
CFrame * frame
Definition stealitem.hpp:35
s32 aux_state[STEAL_ITEM_MAX]
Definition stealitem.hpp:41
float speed[STEAL_ITEM_MAX]
Definition stealitem.hpp:39
void Draw()
sceVu0FVECTOR pos[STEAL_ITEM_MAX]
Definition stealitem.hpp:37
s32 state[STEAL_ITEM_MAX]
Definition stealitem.hpp:40
void Set(float *position, int item_no)
Definition stealitem.cpp:24
void Step()
Definition stealitem.cpp:47
float angle
Definition stealitem.hpp:42