DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
npcharacter.cpp
1#include "npcharacter.hpp"
2
3#include <cmath>
4
5#include "collision.hpp"
6#include "mathutil.hpp"
7#include "mglib.hpp"
8
10 if (!initialized || frame == NULL) {
11 return;
12 }
13
14 if (near_camera || step_hidden) {
16 }
17
18 int fade_step = alpha_step;
19 int override_step = alpha_step_override;
20
21 if (!(float(override_step) <= 0.0f)) {
22 fade_step = override_step;
23 }
24
26
27 if (near_camera) {
28 ambient_offset[3] += float(fade_step);
29 } else {
30 ambient_offset[3] -= float(fade_step);
31 }
32
33 if (ambient_offset[3] < 0.0f) {
34 ambient_offset[3] = 0;
35 }
36
37 if (!(ambient_offset[3] <= 128.0f)) {
38 ambient_offset[3] = 128.0f;
39 }
40
41 PlaySeq();
42}
43
45 if (!initialized || frame == NULL) {
46 return;
47 }
48
49 if (near_camera) {
51 }
52}
53
55 sceVu0FVECTOR position;
56 sceVu0FVECTOR movement;
57 sceVu0FVECTOR destination;
58 sceVu0FVECTOR flat_position;
59
60 if (!CheckSeq() || !sequence_enabled) {
61 return;
62 }
63
64 NP_SEQUENCE *sequence = GetNowSeq();
65 GetPosition(position);
66
67 switch (sequence->operation) {
68 case NP_SEQUENCE_MOVE: {
69 sceVu0SubVector(movement, sequence->destination, position);
70 movement[1] = 0;
71 sceVu0Normalize(movement, movement);
72 sceVu0ScaleVector(movement, movement, sequence->speed[0]);
73 sceVu0CopyVector(flat_position, position);
74 flat_position[1] = sequence->destination[1];
75
76 if (DistVector(sequence->destination, flat_position) <= sequence->speed[0]) {
77 sceVu0CopyVector(destination, sequence->destination);
78 NextSeq();
79 SetMotion(0, 0);
80 } else {
81 sceVu0AddVector(destination, position, movement);
82 }
83
84 float angle = AngleInterpolate(rotation.y, atan2f(movement[0], movement[2]), 0.1f, INTERPOLATE_STEP);
85 SetRotation(0, angle, 0);
86 SetPosition(destination);
87 SetMotion(1, 0);
88 return;
89 }
90 case NP_SEQUENCE_WAIT:
91 sequence->wait_frames--;
92
93 if (sequence->wait_frames < 0) {
94 NextSeq();
95 }
96
97 SetMotion(0, 0);
98 break;
99 }
100}
101
103 read_index = 0;
104 write_index = 0;
106
107 for (int index = 0; index < 8; index++) {
108 sequences[index].operation = NP_SEQUENCE_UNUSED;
109 }
110}
111
112int CNPCharacter::SetSeq(float *destination, float speed) {
113 NP_SEQUENCE *sequence = GetNextSeq();
114 sequence->operation = NP_SEQUENCE_MOVE;
115 sceVu0CopyVector(sequence->destination, destination);
116 sequence->speed[0] = speed;
117 sequence->speed[1] = speed;
118 sequence->speed[2] = speed;
119 return 1;
120}
121
122int CNPCharacter::SetWait(int frames) {
123 NP_SEQUENCE *sequence = GetNextSeq();
124 sequence->operation = NP_SEQUENCE_WAIT;
125 sequence->wait_frames = frames;
126 return 1;
127}
128
132
134 NP_SEQUENCE *sequence = &sequences[write_index];
135 write_index++;
136
137 if (write_index >= 8) {
138 write_index = 0;
139 }
140
141 return sequence;
142}
143
147
149 GetNowSeq()->operation = NP_SEQUENCE_UNUSED;
150
151 if (CheckSeq()) {
152 read_index++;
153
154 if (read_index >= 8) {
155 read_index = 0;
156 }
157 }
158}
159
161 sceVu0FVECTOR saved_ambient;
162 sceVu0FVECTOR ambient;
163
164 if (!initialized || frame == NULL) {
165 return;
166 }
167
168 if (!(ambient_offset[3] <= 0.0f)) {
169 MGGetAmbient(saved_ambient);
170 sceVu0CopyVector(ambient, saved_ambient);
171 ambient[0] += ambient_offset[0];
172 ambient[1] += ambient_offset[1];
173 ambient[2] += ambient_offset[2];
174 ambient[3] = ambient_offset[3];
175 MGSetAmbient(ambient);
177 MGSetAmbient(saved_ambient);
178 }
179}
180
182 if (!initialized || frame == NULL) {
183 return;
184 }
185
186 if (near_camera) {
188 }
189}
190
192 if (!initialized || frame == NULL) {
193 return 0;
194 }
195
196 if (ambient_offset[3] <= 0.0f) {
197 return 0;
198 }
199
200 return 1;
201}
202
203int CNPCharacter::PickUpPoly(float *position, CCPoly *polygons) {
204 if (initialized) {
205 return CCharacter::PickUpPoly(position, polygons);
206 }
207
208 return 0;
209}
210
211int CCharacter::PickUpPoly(float *position, CCPoly *polygons) {
212 sceVu0FVECTOR origin;
213 sceVu0FVECTOR direction;
214 sceVu0FVECTOR centre;
215 sceVu0FVECTOR upper_left;
216 sceVu0FVECTOR upper_right;
217 sceVu0FVECTOR lower_left;
218 sceVu0FVECTOR lower_right;
219 GetPosition(origin);
220 float radius = body_width;
221
222 if (radius < 2.0f) {
223 radius = 2.0f;
224 }
225
226 sceVu0SubVector(direction, position, origin);
227 direction[1] = 0;
228 float distance = DistVector(direction);
229
230 if (!(distance <= 4.0f * radius) || distance < radius) {
231 return 0;
232 }
233
234 if (origin[1] + body_height < position[1]) {
235 return 0;
236 }
237
238 if (!(origin[1] - body_height <= position[1])) {
239 return 0;
240 }
241
242 sceVu0Normalize(direction, direction);
243 upper_left[0] = 20.0f * -direction[2];
244 upper_left[1] = 30.0f;
245 upper_left[2] = 20.0f * direction[0];
246 upper_left[3] = 1.0f;
247 sceVu0CopyVector(upper_right, upper_left);
248 upper_right[0] = -upper_left[0];
249 upper_right[2] = -upper_left[2];
250 sceVu0CopyVector(lower_left, upper_left);
251 lower_left[1] = -30.0f;
252 sceVu0CopyVector(lower_right, upper_right);
253 lower_right[1] = -30.0f;
254 sceVu0ScaleVector(centre, direction, radius);
255 sceVu0AddVector(centre, centre, origin);
256 sceVu0AddVector(upper_left, upper_left, centre);
257 sceVu0AddVector(upper_right, upper_right, centre);
258 sceVu0AddVector(lower_left, lower_left, centre);
259 sceVu0AddVector(lower_right, lower_right, centre);
260 sceVu0CopyVector(polygons[0].vertex[0], upper_left);
261 sceVu0CopyVector(polygons[0].vertex[1], upper_right);
262 sceVu0CopyVector(polygons[0].vertex[2], lower_left);
263 sceVu0CopyVector(polygons[0].normal, direction);
264 sceVu0CopyVector(polygons[1].vertex[0], lower_left);
265 sceVu0CopyVector(polygons[1].vertex[1], upper_right);
266 sceVu0CopyVector(polygons[1].vertex[2], lower_right);
267 sceVu0CopyVector(polygons[1].normal, direction);
268 return 2;
269}
270
273 initialized = false;
274 near_camera = false;
275 ambient_offset[0] = 0;
276 ambient_offset[1] = 0;
277 ambient_offset[2] = 0;
278 ambient_offset[3] = 0;
279 alpha_step = 0;
281 body_width = 7.0f;
282 texture_block = 0;
283 talk_target = false;
284 event_status = 0;
285 draw_enabled = false;
286 resource_name[0] = 0;
287 ClearSeq();
288 map_parts_no = 0;
289 unk_1480 = 0;
290 step_hidden = 0;
292}
293
void SetMotion(int no, int mode, float speed=-1.0f)
CFrame * frame
virtual void GetPosition(float *out_position)
virtual void Step()
sceVu0FVECTOR ambient_offset
virtual void ShadowStep()
virtual void SetRotation(float x, float y, float z)
virtual void DrawShadow()
virtual void Initialize()
float body_height
virtual void Draw()
float body_width
virtual void SetPosition(float x, float y, float z)
virtual int PickUpPoly(float *position, CCPoly *polygons)
int SetSeq(float *destination, float speed)
virtual void Step()
s32 recurring_talk_event
virtual int PickUpPoly(float *position, CCPoly *polygons)
virtual void Initialize()
NP_SEQUENCE sequences[8]
s32 alpha_step_override
virtual void DrawShadow()
NP_SEQUENCE * GetNowSeq()
virtual void Draw()
NP_SEQUENCE * GetNextSeq()
char resource_name[0x20]
int SetWait(int frames)
virtual void ShadowStep()
CVector3_f_ rotation
Definition object.hpp:23
@ INTERPOLATE_STEP
Definition mathutil.hpp:15
float speed[3]
NP_SEQUENCE_OPERATION operation
float destination[4]