DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
op_b.cpp
1#pragma helper_mask_gpr 0x30
2
3#include "common.h"
4
5#include <libgraph.h>
6#include <libpkt.h>
7#include <libvu0.h>
8
9#include <cmath>
10#include <cstdlib>
11#include <cstring>
12
13#include "camera.hpp"
14#include "camerafollow.hpp"
15#include "character.hpp"
16#include "dataalloc.hpp"
17#include "dataread.hpp"
18#include "frame.hpp"
19#include "framevu1.hpp"
20#include "mainselect.hpp"
21#include "mathutil.hpp"
22#include "mds.hpp"
23#include "mglib.hpp"
24#include "renderinfo.hpp"
25#include "sound.hpp"
26#include "texture.hpp"
27#include "title/op_a.hpp"
28#include "title/op_b.hpp"
29#include "title/opening.hpp"
30#include "title/script.hpp"
31#include "vector3.hpp"
32#include "wind.hpp"
33
37// clang-format off
38enum FaceBlink {
39 BLINK_IDLE = 0,
40 BLINK_CLOSING = 1,
41 BLINK_OPENING = 2,
42};
43
44// clang-format on
45
47
48/* The rectangle a texture transfer takes, declared here rather than reached through rect.h for
49 the reason title.cpp declares its own: every rectangle this overlay builds is built by a
50 constructor that assigns x, y, w and h in that order, and rect.h's assigns them in the other. */
51template <class T>
52class CRect {
53public:
54 T x;
55 T y;
56 T w;
57 T h;
59 CRect() {}
60
61 CRect(T new_x, T new_y, T new_width, T new_height) {
62 x = new_x;
63 y = new_y;
64 w = new_width;
65 h = new_height;
66 }
67} __attribute__((aligned(16)));
68
69/* The three classes this scene places in the world, declared here rather than reached through
70 headers of their own because each is another unit's to type. Only the members this file touches
71 are named; the extents are the sizes the executable gives the objects below. */
72
73/* A frame parented to an object, which is what lets the world transform drive a model. */
74class CObjectFrame : public CObject {
75public:
78 s32 draw_on;
80 virtual void FrameObjectOnOff(char *name, int on);
81 virtual void Draw();
82
83 void SetFrame(CFrameVu1 *frame, int unknown0);
84};
85
86/* One piece of scenery. The scene builds a table of them, hands each its model, and drives them
87 through the object dispatch like anything else in the world. */
88class CMapObject : public CObjectFrame {
89public:
95 int unk_34;
96 int handle;
97 char unk_EC[4];
98
99 CMapObject();
100
101 virtual void Draw();
102
103 void Initialize();
104 void DrawShadow(int unknown0);
105};
106
107class CTexture;
108
109/* The scene's one fire, which is a light rather than a model. */
110class CFireOmni {
111public:
112 char unk_00[32];
113 sceVu0FVECTOR pos;
114 s32 texture_set;
115 CTexture *core;
116 CTexture *glow;
117 s32 unk_3C;
118
119 CFireOmni();
120
121 void FireStep();
122 void FireCreate();
123 void DrawFire(int unknown0, int unknown1, CCamera *camera, float *eye, float scale, int unknown2, float unknown3);
124};
125
126/* One looping object animation: a frame is found by name and one of its properties is driven from
127 a start value towards an end value by a step each tick. */
128class OBJ_ANIME_SEQ {
129public:
130 char name[16];
131 int property;
132 int mode;
133 char unk_18[8];
134 sceVu0FVECTOR start_value;
135 sceVu0FVECTOR end_value;
136 float step_x;
137 float step_y;
138 float step_z;
139 float step_w;
140 sceVu0FVECTOR current;
141 CFrame *frames[10];
142 int completion_flag;
143 int unk_8C;
144
146
147 void Initialize();
148};
149
150/* One actor's face, as this scene animates it. The eyes and the mouth are two strips of frames
151 stacked bottom-up in one 256-wide texture — the eyes down the left half and the mouth down the
152 right — and a tick copies the current frame of each over the plate the model draws with. The two
153 offsets are measured from the bottom edge of the plate; the blink state is kept here because this
154 scene blinks the cast on a clock of its own rather than from the script. */
155struct FACE_INFO {
156 char *plate;
157 char *strip;
158 int eye_bottom;
159 int eye_height;
160 int mouth_bottom;
161 int mouth_height;
162 int eye;
163 int mouth;
164 int strip_bottom;
165 int eye_max;
166 int blink;
167};
168
169/* One piece of scenery as the scene was laid out: the model, the model its shadow is drawn
170 from, where it stands in tenths of a world unit, and its heading in degrees. */
172 char *name;
174 float position[3];
175 float rotation[3];
176};
177
178void InitObjAnime(CFrame *frame, OBJ_ANIME_SEQ *sequence);
179void ObjAnimePlay(OBJ_ANIME_SEQ *sequence);
180void MoveImageTest(sceVif1Packet *packet, int sbp, int sbw, int spsm, const CRect<int> &rect, int dbp, int dbw, int dpsm, int dsax, int dsay, int dir);
181void DepthOfField(float *dist, int level, int alpha, int blur);
182
183static CFrameVu1 *ToansHouse;
184static CFrameVu1 *DoransFuusya[2];
185static int VolFade;
186
187static void setTexAnime();
188void FaceChangeC(int no);
189
190CMapObject OP_NornMapObj[76];
191CMapObject OP_NornMapObj2[87];
192
193static CFireOmni CFire;
194static CCharacter Komono;
195static OBJ_ANIME_SEQ Door;
196static OBJ_ANIME_SEQ Fuusya[2];
197CWind Wind;
198static CFrame *TaimatsuFrame[12];
199static OBJ_ANIME_SEQ Taimatsu[12];
200static CMapObject OP_ToanMapObj;
201
202/* One actor's blinking and speaking. Four of the eight rows are never blinked because their actors
203 are too far from the camera for it to read, and the two the script talks through carry a hand-off
204 of their own: an eye number the script set is stepped on by one here once the line it belongs to
205 has been on screen long enough, which is how a raised eyebrow outlasts the word that raised it.
206 The mouth is driven from the script's own clock, a new frame picked at random every sixth
207 hundredth of a second left on the line's timer while the actor is talking. */
208void FaceChange(int actor_no) {
209 sceGifTag giftag = {0, 1, 0, 0, 0, 0, 1, SCE_GIF_PACKED_AD};
210 static FACE_INFO face[8] = {
211 {"c07a01", "c07a01an", 42, 40, 87, 35, 0, 0, 256, 2, 0},
212 {"c08a01", "c08a01an", 42, 40, 87, 35, 0, 0, 320, 2, 0},
213 {"c11a01", "c11a01an", 32, 40, 84, 35, 0, 0, 448, 3, 0},
214 {"c09a01", "c09a01an", 10, 40, 73, 35, 0, 0, 448, 2, 0},
215 {"c08a01", "c08a01an", 42, 40, 87, 35, 0, 0, 320, 2, 0},
216 {"c08a01", "c08a01an", 42, 40, 87, 35, 0, 0, 320, 2, 0},
217 {"p19a_03", "p19a_03an", 8, 40, 76, 35, 0, 0, 256, 2, 0},
218 {"p17a01", "p17a01an", 42, 40, 87, 35, 0, 0, 320, 2, 0}
219 };
220 CTexture *plate;
221 CTexture *strip;
222 int sbp;
223 int dbp;
224 int sbw;
225 int dbw;
226
227 sceVif1PkCnt(Vif1Packet, 0);
228 sceVif1PkOpenDirectCode(Vif1Packet, 0);
229 sceVif1PkOpenGifTag(Vif1Packet, *(u_long128 *) &giftag);
230 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEXFLUSH, 0);
231 sceVif1PkCloseGifTag(Vif1Packet);
232 sceVif1PkCloseDirectCode(Vif1Packet);
233 sceVif1PkTerminate(Vif1Packet);
234
235 plate = TexManager.GetTexture(face[actor_no].plate, -1);
236 strip = TexManager.GetTexture(face[actor_no].strip, -1);
237
238 if (plate == 0 || strip == 0) {
239 return;
240 }
241
242 sbp = strip->tex0 & 0x3fff;
243 dbp = plate->tex0 & 0x3fff;
244 sbw = (strip->tex0 >> 14) & 0x3f;
245 dbw = (plate->tex0 >> 14) & 0x3f;
246
247 if (actor_no == 1) {
248 return;
249 }
250
251 if (actor_no == 4) {
252 return;
253 }
254
255 if (actor_no == 5) {
256 return;
257 }
258
259 if (actor_no == 7) {
260 return;
261 }
262
263 if (!Pause) {
264 if (CScript__2.obj[actor_no].eye > face[actor_no].eye_max) {
265 face[actor_no].blink = BLINK_IDLE;
266 }
267
268 if (CScript__2.obj[actor_no].eye_time >= CScript__2.motion_step) {
269 CScript__2.obj[actor_no].eye_time -= CScript__2.motion_step;
270
271 switch (face[actor_no].blink) {
272 case BLINK_CLOSING:
273 if (CScript__2.obj[actor_no].eye < face[actor_no].eye_max) {
274 CScript__2.obj[actor_no].eye++;
275
276 if (CScript__2.obj[actor_no].eye == face[actor_no].eye_max) {
277 face[actor_no].blink = BLINK_OPENING;
278 }
279 }
280
281 break;
282 case BLINK_OPENING:
283 if (CScript__2.obj[actor_no].eye > 0) {
284 CScript__2.obj[actor_no].eye--;
285 }
286
287 break;
288 }
289 } else if (rand() % 200 == 0) {
290 if (CScript__2.obj[actor_no].eye == 0) {
291 face[actor_no].blink = BLINK_CLOSING;
292 CScript__2.obj[actor_no].eye = 1;
293 CScript__2.obj[actor_no].eye_time = 15.0f * CScript__2.motion_step;
294 }
295 } else if (actor_no == 2) {
296 if (CScript__2.obj[2].eye == 5) {
297 CScript__2.obj[2].eye = 4;
298 CScript__2.obj[2].eye_time = CScript__2.motion_step;
299 } else {
300 CScript__2.obj[actor_no].eye = 0;
301 face[actor_no].blink = BLINK_IDLE;
302 }
303 } else {
304 CScript__2.obj[actor_no].eye = 0;
305 face[actor_no].blink = BLINK_IDLE;
306 }
307 }
308
309 face[actor_no].eye = CScript__2.obj[actor_no].eye;
310
311 MoveImageTest(Vif1Packet, sbp, sbw, SCE_GS_PSMT8, CRect<int>(0, face[actor_no].strip_bottom - face[actor_no].eye_height * (face[actor_no].eye + 1), 128, face[actor_no].eye_height), dbp, dbw, SCE_GS_PSMT8, 0, 88 - face[actor_no].eye_bottom, 0);
312
313 if (!Pause) {
314 if (CScript__2.obj[2].eye_time > 1.0f) {
315 if (CScript__2.obj[2].eye == 4) {
316 CScript__2.obj[2].eye = 5;
317 }
318
319 if (CScript__2.obj[2].eye == 6) {
320 CScript__2.obj[2].eye = 7;
321 }
322 }
323
324 if (CScript__2.obj[3].eye_time > 1.0f) {
325 if (CScript__2.obj[3].eye == 3) {
326 CScript__2.obj[3].eye = 4;
327 }
328 }
329 }
330
331 if (!Pause) {
332 if (CScript__2.obj[actor_no].mouth_time >= CScript__2.motion_step) {
333 CScript__2.obj[actor_no].mouth_time -= CScript__2.motion_step;
334
335 if (CScript__2.obj[actor_no].talk) {
336#ifdef PAL_TIMING
337 if (rand() % 5 == 0) {
338#else
339 if ((int) (100.0f * CScript__2.obj[actor_no].mouth_time) % 6 == 0) {
340#endif
341 CScript__2.obj[actor_no].mouth = rand() % 4;
342 }
343 }
344 } else {
345 CScript__2.obj[actor_no].mouth = 0;
346 CScript__2.obj[actor_no].talk = false;
347 }
348 }
349
350 face[actor_no].mouth = CScript__2.obj[actor_no].mouth;
351
352 MoveImageTest(Vif1Packet, sbp, sbw, SCE_GS_PSMT8, CRect<int>(128, face[actor_no].strip_bottom - face[actor_no].mouth_height * (face[actor_no].mouth + 1), 128, face[actor_no].mouth_height), dbp, dbw, SCE_GS_PSMT8, 0, 88 - face[actor_no].mouth_bottom, 0);
353
354 if (!Pause) {
355 if (CScript__2.obj[2].mouth == 4) {
356 CScript__2.obj[2].mouth = 5;
357 }
358 }
359
360 sceVif1PkCnt(Vif1Packet, 0);
361 sceVif1PkOpenDirectCode(Vif1Packet, 0);
362 sceVif1PkOpenGifTag(Vif1Packet, *(u_long128 *) &GiftagAD);
363 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEXFLUSH, 0);
364 sceVif1PkCloseGifTag(Vif1Packet);
365 sceVif1PkCloseDirectCode(Vif1Packet);
366}
367
368void LoadCharaData(int buffer_no, int actor_no) {
369 char *name[6][2] = {
370 {"opdat/chara/01c07a.chr", "01c07a.cfg"},
371 {"opdat/chara/01c08a.chr", "01c08a.cfg"},
372 {"opdat/chara/01c11a.chr", "01c11a.cfg"},
373 {"opdat/chara/01c09a.chr", "01c09a.cfg"},
374 {"opdat/chara/01c08b.chr", "01c08b.cfg"},
375 {"opdat/chara/01c08c.chr", "01c08c.cfg"}
376 };
377
378 switch (CScript__2.obj[actor_no].load_step) {
379 case TSLOAD_START:
380 LoadFileBG(name[actor_no][0], (u_long128 *) read_buffer, 0);
381 CScript__2.obj[actor_no].load_step = TSLOAD_WAIT;
382 break;
383 case TSLOAD_WAIT:
384 if (!ReadBGSync()) {
385 CScript__2.obj[actor_no].load_step = TSLOAD_UNPACK;
386 }
387
388 break;
389 case TSLOAD_UNPACK:
390 Chara__3[actor_no].Initialize();
391 CharaDataBuffer__2[buffer_no].used = 0;
392 Chara__3[actor_no].LoadPackData(read_buffer, name[actor_no][1], &CharaDataBuffer__2[buffer_no], 0);
393 Chara__3[actor_no].motion_type.state.time = 10.0f;
394 Chara__3[actor_no].motion_type.state.blend_step = 0.05f;
395 Chara__3[actor_no].motion_type.state.motion_no = 0;
396 Chara__3[actor_no].motion_type.state.playing_no = 0;
397 CScript__2.obj[actor_no].load = -1;
398 CScript__2.obj[actor_no].load_step = TSLOAD_NONE;
399 break;
400 }
401}
402
403/* The couple's dance, which is ten motion files played end to end. A file is swapped in when the
404 one running reaches its last key and the next pair is started in the background straight after,
405 so the dance runs continuously off a buffer that only ever holds two steps. */
406void LoadMotionData() {
407 char *motion_files[20][2] = {
408 {"opdat/chara/01p19a1a.chr", "01p19a1a.cfg"},
409 {"opdat/chara/01p19a1b.chr", "01p19a1b.cfg"},
410 {"opdat/chara/01p19a2a.chr", "01p19a2a.cfg"},
411 {"opdat/chara/01p19a2a.chr", "01p19a2a.cfg"},
412 {"opdat/chara/01p19a2b.chr", "01p19a2b.cfg"},
413 {"opdat/chara/01p19a3.chr", "01p19a3.cfg" },
414 {"opdat/chara/01p19a3b.chr", "01p19a3b.cfg"},
415 {"opdat/chara/01p19a4a.chr", "01p19a4a.cfg"},
416 {"opdat/chara/01p19a4b.chr", "01p19a4b.cfg"},
417 {"opdat/chara/01p19a5.chr", "01p19a5.cfg" },
418 {"opdat/chara/01p17a1a.chr", "01p17a1a.cfg"},
419 {"opdat/chara/01p17a1b.chr", "01p17a1b.cfg"},
420 {"opdat/chara/01p17a2a.chr", "01p17a2a.cfg"},
421 {"opdat/chara/01p17a2a.chr", "01p17a2a.cfg"},
422 {"opdat/chara/01p17a2b.chr", "01p17a2b.cfg"},
423 {"opdat/chara/01p17a3.chr", "01p17a3.cfg" },
424 {"opdat/chara/01p17a3b.chr", "01p17a3b.cfg"},
425 {"opdat/chara/01p17a4a.chr", "01p17a4a.cfg"},
426 {"opdat/chara/01p17a4b.chr", "01p17a4b.cfg"},
427 {"opdat/chara/01p17a5.chr", "01p17a5.cfg" }
428 };
429
430 if (DanceCnt < 10) {
431 if (Chara__3[6].motion_type.state.time > (float) (Chara__3[6].motion_type.motion_info->end - 1)) {
432 if (DanceCnt != 2) {
433 CharaDataBuffer__2[6].used = 0;
434 Chara__3[6].LoadPackData((u_int *) ((char *) read_buffer + 0x10C900), motion_files[DanceCnt][1], &CharaDataBuffer__2[4], &CharaDataBuffer__2[6], 0);
435 Chara__3[7].LoadPackData(read_buffer, motion_files[DanceCnt + 10][1], &CharaDataBuffer__2[4], &CharaDataBuffer__2[6], 0);
436 }
437
438 Chara__3[6].motion_type.motion_info->start = noroi[DanceCnt].start;
439 Chara__3[6].motion_type.motion_info->end = noroi[DanceCnt].end;
440 Chara__3[6].motion_type.state.time = (float) Chara__3[6].motion_type.motion_info->start;
441 Chara__3[7].motion_type.motion_info->start = dancer[DanceCnt].start;
442 Chara__3[7].motion_type.motion_info->end = dancer[DanceCnt].end;
443 Chara__3[7].motion_type.state.time = (float) Chara__3[7].motion_type.motion_info->start;
444 DanceCnt++;
445
446 if (DanceCnt != 3 && DanceCnt < 10) {
447 LoadFileBG(motion_files[DanceCnt][0], (u_long128 *) ((char *) read_buffer + 0x10C900), 0);
448 LoadFileBG(motion_files[DanceCnt + 10][0], (u_long128 *) read_buffer, 0);
449 }
450 }
451
452 Chara__3[6].motion_no = 0;
453 Chara__3[6].motion_flags = 0;
454 Chara__3[6].motion_speed = -1.0f;
455
456 if (Chara__3[6].motion_type.state.time > 225.0f) {
457 DanceStart = 1;
458 }
459
460 if (DanceStart == 1) {
461 Chara__3[7].motion_no = 0;
462 Chara__3[7].motion_flags = 0;
463 Chara__3[7].motion_speed = -1.0f;
464 } else {
465 Chara__3[7].motion_no = 1;
466 Chara__3[7].motion_flags = 0;
467 Chara__3[7].motion_speed = -1.0f;
468 }
469 }
470}
471
472void OpB_LoadDataBG() {
473 while (ReadBGSync())
474 ;
475
476 LoadFileBG("opdat/norn/norn.pak", (u_long128 *) read_buffer, 0);
477 CScript__2.load_no = OP_SCENE_NONE;
478}
479
480void OpB_LoadDataBG2() {
481 while (ReadBGSync())
482 ;
483
484 LoadFileBG("opdat/toan/toan.pim", (u_long128 *) read_buffer, 0);
485 CScript__2.load_no = OP_SCENE_NONE;
486}
487
488/* The village scene's set-up, and the shape every scene file's is a variation of. The textures come
489 out of the pack the background load left in memory, so the manifest is built with its five fixed
490 surfaces named and its eighteen scene images filled in by name afterwards. The two tables below
491 are the scene as it was laid out: a model, the model its shadow is drawn from, a position in
492 tenths of a world unit and a heading in degrees, one row per piece of scenery. The rows with no
493 model of their own are further copies of the row above them, which is why the frame is only
494 reloaded where a name is given. */
495void OpB_InitProcess() {
496 LOADTEXTURE_INFO2 texture_list[] = {
497 {"#blender#640#" HALF_BUFFER_HEIGHT_STR "#4", 0, 0},
498 {"#fontbase#512#256#1", 26, 0},
499 {"#fukidashibase#640#" HALF_BUFFER_HEIGHT_STR "#4", 26, 0},
500 {"#shadow_buff#640#" HALF_BUFFER_HEIGHT_STR "#4", 23, 0},
501 {"#frame_image#640#" HALF_BUFFER_HEIGHT_STR "#4", 21, 0},
502 {0, 2, 0},
503 {0, 10, 0},
504 {0, 10, 0},
505 {0, 10, 0},
506 {0, 10, 0},
507 {0, 11, 0},
508 {0, 11, 0},
509 {0, 11, 0},
510 {0, 11, 0},
511 {0, 11, 0},
512 {0, 26, 0},
513 {0, 26, 0},
514 {0, 26, 0},
515 {0, 0, 0},
516 {0, 19, 0},
517 {0, 19, 0},
518#ifndef PAL
519 {0, 19, 0},
520#endif
521 {0, 2, 0},
522 {"", 0, 0}
523 };
524
525 while (ReadBGSync())
526 ;
527
528 texture_list[5].name = (char *) GetPackFile(read_buffer, "p09a01.img", 0);
529 texture_list[6].name = (char *) GetPackFile(read_buffer, "e01b01.img", 0);
530 texture_list[7].name = (char *) GetPackFile(read_buffer, "e01b02.img", 0);
531 texture_list[8].name = (char *) GetPackFile(read_buffer, "e01b03.img", 0);
532 texture_list[9].name = (char *) GetPackFile(read_buffer, "e01t01.img", 0);
533 texture_list[10].name = (char *) GetPackFile(read_buffer, "t0003.img", 0);
534 texture_list[11].name = (char *) GetPackFile(read_buffer, "e01s03.img", 0);
535 texture_list[12].name = (char *) GetPackFile(read_buffer, "e01s06.img", 0);
536 texture_list[13].name = (char *) GetPackFile(read_buffer, "t0001.img", 0);
537 texture_list[14].name = (char *) GetPackFile(read_buffer, "t0002.img", 0);
538 texture_list[15].name = (char *) GetPackFile(read_buffer, "gaiji.img", 0);
539 texture_list[16].name = (char *) GetPackFile(read_buffer, "fuki256.img", 0);
540 texture_list[17].name = (char *) GetPackFile(read_buffer, "syst04.img", 0);
541 texture_list[18].name = (char *) GetPackFile(read_buffer, "fire.img", 0);
542 texture_list[19].name = (char *) GetPackFile(read_buffer, "pause.img", 0);
543
544#ifdef PAL
545 switch (LanguageCode) {
546 case LANG_JAPANESE:
547 texture_list[20].name = (char *) GetPackFile(read_buffer, "pause_e.img", 0);
548 break;
549 case LANG_ENGLISH_US:
550 texture_list[20].name = (char *) GetPackFile(read_buffer, "pause_e.img", 0);
551 break;
552 case LANG_ENGLISH_UK:
553 texture_list[20].name = (char *) GetPackFile(read_buffer, "pause_e.img", 0);
554 break;
555 case LANG_FRENCH:
556 texture_list[20].name = (char *) GetPackFile(read_buffer, "pause_f.img", 0);
557 break;
558 case LANG_GERMAN:
559 texture_list[20].name = (char *) GetPackFile(read_buffer, "pause_g.img", 0);
560 break;
561 case LANG_ITALIAN:
562 texture_list[20].name = (char *) GetPackFile(read_buffer, "pause_i.img", 0);
563 break;
564 case LANG_SPANISH:
565 texture_list[20].name = (char *) GetPackFile(read_buffer, "pause_s.img", 0);
566 break;
567 }
568
569 texture_list[21].name = (char *) GetPackFile(read_buffer, "p09a01an.img", 0);
570#else
571 texture_list[20].name = (char *) GetPackFile(read_buffer, "pause_e.img", 0);
572 texture_list[21].name = (char *) GetPackFile(read_buffer, "start2.img", 0);
573 texture_list[22].name = (char *) GetPackFile(read_buffer, "p09a01an.img", 0);
574#endif
575
576 TexManager.Initialize(16352);
577 TexManager.LoadTextureBlock(-1, texture_list);
578
579 CharaTex__2[9] = 2;
580 CharaTex__2[11] = 22;
581 CharaTex__2[8] = 22;
582 CharaTex__2[10] = 22;
583
584 CSnd.SetReverb(0, 4, 30);
585 CSnd.SetReverb(1, 4, 5);
586 CSnd.LoadSoundFileFromPack("o02a.txt", read_buffer);
587 CSnd.SetVol(MIDI_PORT_SE_TITLE, 256);
588 CSnd.SetVol(MIDI_PORT_SE_DEFAULT, 256);
589 CSnd.SetVol(MIDI_PORT_UNK_D, 256);
590 CSnd.SetVol(MIDI_PORT_SE_SPECIAL, 256);
591 OpBgmSqPort = 0;
592 OpBgmPlay();
593 CSnd.SQ_Play(MIDI_PORT_AMBIENT, 0);
594 OpPlayVolSE(MIDI_PORT_SE_TITLE, 16, 22, 0.6f);
595 CSnd.Step();
596 CSnd.SE_Play(MIDI_PORT_SE_TITLE, 16, 21, 0);
597 OP_FireList = 0;
598 OPAnalyz("opdat/norn.cfg");
599 OPMdsLoad();
600
601 MAPOBJ_INFO norn[] = {
602 {"opdat/norn/t0005.mds", 0, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f} },
603 {"opdat/norn/e01h01_0.mds", "opdat/norn/e01h01_s.mds", {-35.0f, 0.0f, -10.0f}, {0.0f, 0.0f, 0.0f} },
604 {"opdat/norn/e01h03_2.mds", "opdat/norn/e01h03_s.mds", {-15.0f, 0.0f, -50.0f}, {0.0f, 0.0f, 0.0f} },
605 {"opdat/norn/e01h10_2.mds", "opdat/norn/e01h10_s.mds", {15.0f, 0.0f, -50.0f}, {0.0f, 0.0f, 0.0f} },
606 {"opdat/norn/e01h07_0.mds", "opdat/norn/e01h07_s.mds", {5.0f, 0.0f, -10.0f}, {0.0f, 0.0f, 0.0f} },
607 {"opdat/norn/e01h08_2.mds", "opdat/norn/e01h08_s.mds", {-45.0f, 0.0f, -35.0f}, {0.0f, 0.0f, 0.0f} },
608 {"opdat/norn/t0002.mds", 0, {-35.0f, 0.0f, -55.0f}, {0.0f, 0.0f, 0.0f} },
609 {0, 0, {-55.0f, 0.0f, -45.0f}, {0.0f, 0.0f, 0.0f} },
610 {"opdat/norn/e01t01_0.mds", 0, {-5.0f, 0.1f, 5.0f}, {0.0f, 0.0f, 0.0f} },
611 {"opdat/norn/e01t01_1.mds", 0, {15.0f, 0.1f, 5.0f}, {0.0f, 0.0f, 0.0f} },
612 {0, 0, {-55.0f, 0.1f, 15.0f}, {0.0f, 0.0f, 0.0f} },
613 {"opdat/norn/e01t01_2.mds", 0, {-45.0f, 0.1f, -55.0f}, {0.0f, 0.0f, 0.0f} },
614 {0, 0, {-55.0f, 0.1f, -65.0f}, {0.0f, 0.0f, 0.0f} },
615 {0, 0, {-45.0f, 0.1f, -65.0f}, {0.0f, 0.0f, 0.0f} },
616 {0, 0, {-35.0f, 0.1f, -65.0f}, {0.0f, 0.0f, 0.0f} },
617 {0, 0, {-5.0f, 0.1f, -75.0f}, {0.0f, 0.0f, 0.0f} },
618 {0, 0, {5.0f, 0.1f, -75.0f}, {0.0f, 0.0f, 0.0f} },
619 {0, 0, {15.0f, 0.1f, -65.0f}, {0.0f, 0.0f, 0.0f} },
620 {0, 0, {25.0f, 0.1f, -65.0f}, {0.0f, 0.0f, 0.0f} },
621 {0, 0, {35.0f, 0.1f, -55.0f}, {0.0f, 0.0f, 0.0f} },
622 {"opdat/norn/e01c01_0.mds", 0, {25.0f, 0.0f, -35.0f}, {0.0f, 180.0f, 0.0f}},
623 {0, 0, {-55.0f, 0.0f, -25.0f}, {0.0f, 90.0f, 0.0f} },
624 {0, 0, {-55.0f, 0.0f, -25.0f}, {0.0f, -90.0f, 0.0f}},
625 {"opdat/norn/e01c02_0.mds", 0, {-25.0f, 0.0f, -35.0f}, {0.0f, 90.0f, 0.0f} },
626 {0, 0, {-5.0f, 0.0f, -35.0f}, {0.0f, 90.0f, 0.0f} },
627 {0, 0, {5.0f, 0.0f, -35.0f}, {0.0f, 90.0f, 0.0f} },
628 {0, 0, {15.0f, 0.0f, -35.0f}, {0.0f, 90.0f, 0.0f} },
629 {0, 0, {25.0f, 0.0f, -15.0f}, {0.0f, 0.0f, 0.0f} },
630 {0, 0, {25.0f, 0.0f, -5.0f}, {0.0f, 0.0f, 0.0f} },
631 {0, 0, {25.0f, 0.0f, 5.0f}, {0.0f, 0.0f, 0.0f} },
632 {0, 0, {15.0f, 0.0f, 15.0f}, {0.0f, 90.0f, 0.0f} },
633 {0, 0, {-5.0f, 0.0f, 15.0f}, {0.0f, 90.0f, 0.0f} },
634 {0, 0, {-15.0f, 0.0f, 15.0f}, {0.0f, 90.0f, 0.0f} },
635 {0, 0, {-35.0f, 0.0f, 15.0f}, {0.0f, 90.0f, 0.0f} },
636 {0, 0, {-45.0f, 0.0f, 25.0f}, {0.0f, 0.0f, 0.0f} },
637 {0, 0, {-45.0f, 0.0f, 35.0f}, {0.0f, 0.0f, 0.0f} },
638 {0, 0, {-45.0f, 0.0f, 45.0f}, {0.0f, 0.0f, 0.0f} },
639 {"opdat/norn/e01c06_0.mds", 0, {-35.0f, 0.0f, -35.0f}, {0.0f, 90.0f, 0.0f} },
640 {"opdat/norn/e01c07_0.mds", 0, {-15.0f, 0.0f, -35.0f}, {0.0f, -90.0f, 0.0f}},
641 {0, 0, {25.0f, 0.0f, -25.0f}, {0.0f, 0.0f, 0.0f} },
642 {0, 0, {5.0f, 0.0f, 15.0f}, {0.0f, 90.0f, 0.0f} },
643 {0, 0, {0.0f, 0.0f, 15.0f}, {0.0f, 90.0f, 0.0f} },
644 {"opdat/norn/e01r01_0.mds", 0, {-55.0f, 0.05f, -35.0f}, {0.0f, -90.0f, 0.0f}},
645 {0, 0, {-55.0f, 0.05f, -25.0f}, {0.0f, 90.0f, 0.0f} },
646 {"opdat/norn/e01r02_0.mds", 0, {-45.0f, 0.05f, -25.0f}, {0.0f, 90.0f, 0.0f} },
647 {0, 0, {-35.0f, 0.05f, -25.0f}, {0.0f, 90.0f, 0.0f} },
648 {0, 0, {-25.0f, 0.05f, -25.0f}, {0.0f, 90.0f, 0.0f} },
649 {0, 0, {-5.0f, 0.05f, -25.0f}, {0.0f, 90.0f, 0.0f} },
650 {0, 0, {5.0f, 0.05f, -25.0f}, {0.0f, 90.0f, 0.0f} },
651 {0, 0, {15.0f, 0.05f, -25.0f}, {0.0f, 90.0f, 0.0f} },
652 {0, 0, {-15.0f, 0.05f, -15.0f}, {0.0f, 0.0f, 0.0f} },
653 {"opdat/norn/e01r03_0.mds", 0, {-15.0f, 0.05f, -25.0f}, {0.0f, 0.0f, 0.0f} },
654 {"opdat/norn/e01r06_0.mds", 0, {-65.0f, 0.05f, -35.0f}, {0.0f, 90.0f, 0.0f} },
655 {0, 0, {-15.0f, 0.05f, -5.0f}, {0.0f, 180.0f, 0.0f}},
656 {"opdat/norn/t0004.mds", 0, {-22.9331f, 0.05f, 9.8816f}, {0.0f, 0.0f, 0.0f} },
657 {0, 0, {-26.9302f, 0.05f, 9.8816f}, {0.0f, 0.0f, 0.0f} },
658 {0, 0, {-26.9302f, 0.05f, 20.2919f}, {0.0f, 0.0f, 0.0f} },
659 {0, 0, {-22.9331f, 0.05f, 20.2919f}, {0.0f, 0.0f, 0.0f} },
660 {0, 0, {3.0797f, 0.05f, 20.2919f}, {0.0f, 0.0f, 0.0f} },
661 {0, 0, {7.0849f, 0.05f, 20.2919f}, {0.0f, 0.0f, 0.0f} },
662 {0, 0, {7.0849f, 0.05f, 9.8816f}, {0.0f, 0.0f, 0.0f} },
663 {0, 0, {3.0797f, 0.05f, 9.8816f}, {0.0f, 0.0f, 0.0f} },
664 {0, 0, {19.8785f, 0.05f, -22.8436f}, {0.0f, 0.0f, 0.0f} },
665 {0, 0, {19.8785f, 0.05f, -27.0007f}, {0.0f, 0.0f, 0.0f} },
666 {0, 0, {-12.8131f, 0.05f, -28.8014f}, {0.0f, 0.0f, 0.0f} },
667 {0, 0, {-16.9416f, 0.05f, -28.8014f}, {0.0f, 0.0f, 0.0f} },
668 {"opdat/norn/e01g02_0.mds", 0, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f} },
669 {"opdat/norn/e01g03_0.mds", 0, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f} }
670 };
671 CFrameAttr attr;
672 CFrameVu1 *frame;
673 CMapObject *object;
674
675 attr.fog_enable = true;
676 MapDataBuffer.used = 0;
677
678 for (int i = 0; i < 68; i++) {
679 if (norn[i].name) {
680 LoadFile(norn[i].name, (void *) read_buffer, 0);
681 frame = LoadMDSFile(read_buffer, &MapDataBuffer, 2, 0, 0);
682 }
683
684 if (i == 4) {
685 DoransFuusya[0] = frame;
686 }
687
688 if (i == 5) {
689 DoransFuusya[1] = frame;
690 }
691
692 if (i >= 54 && i < 66) {
693 TaimatsuFrame[i - 54] = frame;
694 }
695
696 frame->SetAttr(attr, 1, 64);
697 SetFrameAttr(frame, 1);
698
699 object = &OP_NornMapObj[i];
700
701 object->Initialize();
702 object->SetFrame(frame, 0);
703 OP_NornMapObj[i].handle = 0;
704 OP_NornMapObj[i].unk_34 = 0;
705
706 object->SetPosition(CVector3_f_(10.0f * norn[i].position[0], 10.0f * norn[i].position[1], 10.0f * norn[i].position[2]));
707 object->SetRotation(CVector3_f_((float) (PI_D * norn[i].rotation[0] / 180), (float) (PI_D * norn[i].rotation[1] / 180), (float) (PI_D * norn[i].rotation[2] / 180)));
708
709 object->FrameObjectOnOff("win1", 0);
710 object->FrameObjectOnOff("light1", 0);
711
712 if (norn[i].shadow_name) {
713 LoadFile(norn[i].shadow_name, (void *) read_buffer, 0);
714 object->shadow_frame = LoadMDSFile(read_buffer, &MapDataBuffer, 14, 0, 0);
715 object->shadow_offset = -20.0f;
716 }
717 }
718
719 MAPOBJ_INFO ground[] = {
720 {"opdat/norn/t0006.mds", 0, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}},
721 {"opdat/norn/t0001.mds", 0, {-25.0203f, 0.03f, -21.3403f}, {0.0f, 0.0f, 0.0f}},
722 {0, 0, {-35.0203f, 0.03f, -21.3403f}, {0.0f, 0.0f, 0.0f}},
723 {0, 0, {-45.0203f, 0.03f, -21.3403f}, {0.0f, 0.0f, 0.0f}},
724 {0, 0, {-55.0203f, 0.03f, -21.3403f}, {0.0f, 0.0f, 0.0f}},
725 {0, 0, {-45.0203f, 0.03f, -28.3403f}, {0.0f, 0.0f, 0.0f}},
726 {0, 0, {-35.0203f, 0.03f, -28.3403f}, {0.0f, 0.0f, 0.0f}},
727 {0, 0, {-25.0203f, 0.03f, -28.3403f}, {0.0f, 0.0f, 0.0f}},
728 {0, 0, {-5.0203f, 0.03f, -28.3403f}, {0.0f, 0.0f, 0.0f}},
729 {0, 0, {4.9797f, 0.03f, -28.3403f}, {0.0f, 0.0f, 0.0f}},
730 {0, 0, {14.9797f, 0.03f, -21.3403f}, {0.0f, 0.0f, 0.0f}},
731 {0, 0, {14.9797f, 0.03f, -28.3403f}, {0.0f, 0.0f, 0.0f}},
732 {0, 0, {4.9797f, 0.03f, -21.3403f}, {0.0f, 0.0f, 0.0f}},
733 {0, 0, {-5.0203f, 0.03f, -21.3403f}, {0.0f, 0.0f, 0.0f}},
734 {"opdat/norn/t0003.mds", 0, {-50.0f, 0.03f, -21.2932f}, {0.0f, 0.0f, 0.0f}},
735 {0, 0, {-40.0f, 0.03f, -21.2932f}, {0.0f, 0.0f, 0.0f}},
736 {0, 0, {-30.0f, 0.03f, -21.2932f}, {0.0f, 0.0f, 0.0f}},
737 {0, 0, {0.0f, 0.03f, -21.2932f}, {0.0f, 0.0f, 0.0f}},
738 {0, 0, {10.0f, 0.03f, -21.2932f}, {0.0f, 0.0f, 0.0f}},
739 {0, 0, {10.0f, 0.03f, -28.2932f}, {0.0f, 0.0f, 0.0f}},
740 {0, 0, {-30.0f, 0.03f, -28.2932f}, {0.0f, 0.0f, 0.0f}},
741 {0, 0, {0.0f, 0.03f, -28.2932f}, {0.0f, 0.0f, 0.0f}},
742 {0, 0, {-40.0f, 0.03f, -28.2932f}, {0.0f, 0.0f, 0.0f}}
743 };
744
745 for (int i = 0; i < 23; i++) {
746 if (ground[i].name) {
747 LoadFile(ground[i].name, (void *) read_buffer, 0);
748 frame = LoadMDSFile(read_buffer, &MapDataBuffer, 2, 0, 0);
749 }
750
751 if (i > 0) {
752 frame->SetAttr(attr, 1, 64);
753 SetFrameAttr(frame, 1);
754 }
755
756 if (i == 0) {
757 CFrame *sun = frame->SearchFrame("sun3");
758 sceVu0FVECTOR position;
759
760 sceVu0CopyVector(position, sun->position);
761 position[1] += 30.0f;
762 position[2] -= 300.0f;
763 sun->SetPosition(position);
764 }
765
766 object = &OP_NornMapObj2[i];
767
768 object->Initialize();
769 object->SetFrame(frame, 0);
770 OP_NornMapObj2[i].handle = 0;
771 OP_NornMapObj2[i].unk_34 = 0;
772
773 object->SetPosition(CVector3_f_(10.0f * ground[i].position[0], 10.0f * ground[i].position[1], 10.0f * ground[i].position[2]));
774 ((CMapObject &) OP_NornMapObj2[i]).SetRotation(CVector3_f_((float) (PI_D * ground[i].rotation[0] / 180), (float) (PI_D * ground[i].rotation[1] / 180), (float) (PI_D * ground[i].rotation[2] / 180)));
775 }
776
777 LoadFile("opdat/chara/03p09a.chr", (void *) read_buffer, 0);
778 CharaDataBuffer__2[6].used = 0;
779 Chara__3[9].LoadPackData(read_buffer, "03p09a.cfg", &CharaDataBuffer__2[6], 0);
780
781 CFrameAttr chara_attr;
782
783 chara_attr.clip_enable = false;
784 Chara__3[9].frame->SetAttr(chara_attr, 1, 4);
785 Chara__3[9].motion_type.state.time = 10.0f;
786 Chara__3[9].motion_type.state.blend_step = 0.05f;
787 Chara__3[9].motion_type.state.motion_no = 0;
788 Chara__3[9].motion_type.state.playing_no = 0;
789
790 Fuusya[0].Initialize();
791 Fuusya[0].property = 0;
792 Fuusya[0].mode = 0;
793 Fuusya[0].start_value[2] = 0.0f;
794 Fuusya[0].start_value[1] = 0.0f;
795 Fuusya[0].start_value[0] = 0.0f;
796 Fuusya[0].end_value[2] = 0.0f;
797 Fuusya[0].end_value[1] = 0.0f;
798 Fuusya[0].end_value[0] = 0.0f;
799 Fuusya[0].step_y = 0.0f;
800 Fuusya[0].step_x = 0.0f;
801 Fuusya[0].step_z = -0.5f;
802 strcpy(Fuusya[0].name, "hane");
803 InitObjAnime(DoransFuusya[0], &Fuusya[0]);
804
805 Fuusya[1].Initialize();
806 Fuusya[1].property = 0;
807 Fuusya[1].mode = 0;
808 Fuusya[1].start_value[2] = 0.0f;
809 Fuusya[1].start_value[1] = 0.0f;
810 Fuusya[1].start_value[0] = 0.0f;
811 Fuusya[1].end_value[2] = 0.0f;
812 Fuusya[1].end_value[1] = 0.0f;
813 Fuusya[1].end_value[0] = 0.0f;
814 Fuusya[1].step_y = 0.0f;
815 Fuusya[1].step_x = 0.0f;
816 Fuusya[1].step_z = -0.5f;
817 strcpy(Fuusya[1].name, "hane");
818 InitObjAnime(DoransFuusya[1], &Fuusya[1]);
819
820 for (int i = 0; i < 12; i++) {
821 Taimatsu[i].Initialize();
822 Taimatsu[i].property = 3;
823 Taimatsu[i].mode = 4;
824 Taimatsu[i].start_value[2] = 80.0f;
825 Taimatsu[i].start_value[1] = 80.0f;
826 Taimatsu[i].start_value[0] = 80.0f;
827 Taimatsu[i].end_value[2] = 128.0f;
828 Taimatsu[i].end_value[1] = 128.0f;
829 Taimatsu[i].end_value[0] = 128.0f;
830 strcpy(Taimatsu[i].name, "effect");
831 InitObjAnime(TaimatsuFrame[i], &Taimatsu[i]);
832 }
833
834 VolFade = 0;
835 CScript__2.init_no = 0;
836}
837
838/* The second half of the scene, which starts when the camera cuts to Toan's house. Everything the
839 first half loaded is thrown away and the pack the background read left in memory is unpacked
840 again: the block numbers say which of the registry's blocks each image belongs to, and the five
841 named entries are the fixed surfaces the registry keeps for every scene. The three actors are
842 loaded one at a time rather than through a table because each is followed by set-up of its own —
843 Toan's mother has a frame turned off, Toan himself carries the cloth the wind drives, and the
844 second Toan is the one the door animation is timed against. */
845void OpB_InitProcess2() {
846 LOADTEXTURE_INFO2 texture_list[] = {
847 {"#blender#640#" HALF_BUFFER_HEIGHT_STR "#4", 0, 0},
848 {"#fontbase#512#256#1", 26, 0},
849 {"#fukidashibase#640#" HALF_BUFFER_HEIGHT_STR "#4", 26, 0},
850 {"#shadow_buff#640#" HALF_BUFFER_HEIGHT_STR "#4", 23, 0},
851 {"#frame_image#640#" HALF_BUFFER_HEIGHT_STR "#4", 21, 0},
852 {0, 26, 0},
853 {0, 26, 0},
854 {0, 26, 0},
855 {0, 10, 0},
856 {0, 2, 0},
857 {0, 22, 0},
858 {0, 22, 0},
859 {0, 22, 0},
860 {0, 22, 0},
861 {0, 0, 0},
862 {0, 19, 0},
863 {0, 19, 0},
864#ifndef PAL
865 {0, 19, 0},
866#endif
867 {0, 2, 0},
868 {"", 0, 0}
869 };
870
871 while (ReadBGSync())
872 ;
873
874 texture_list[5].name = (char *) GetPackFile(read_buffer, "gaiji.img", 0);
875 texture_list[6].name = (char *) GetPackFile(read_buffer, "fuki256.img", 0);
876 texture_list[7].name = (char *) GetPackFile(read_buffer, "syst04.img", 0);
877 texture_list[8].name = (char *) GetPackFile(read_buffer, "i01h01n.img", 0);
878 texture_list[9].name = (char *) GetPackFile(read_buffer, "p09a01.img", 0);
879 texture_list[10].name = (char *) GetPackFile(read_buffer, "p10a01.img", 0);
880 texture_list[11].name = (char *) GetPackFile(read_buffer, "c01d01.img", 0);
881 texture_list[12].name = (char *) GetPackFile(read_buffer, "03c01d.img", 0);
882 texture_list[13].name = (char *) GetPackFile(read_buffer, "03komono.img", 0);
883 texture_list[14].name = (char *) GetPackFile(read_buffer, "fire.img", 0);
884 texture_list[15].name = (char *) GetPackFile(read_buffer, "pause.img", 0);
885
886#ifdef PAL
887 switch (LanguageCode) {
888 case LANG_JAPANESE:
889 texture_list[16].name = (char *) GetPackFile(read_buffer, "pause_e.img", 0);
890 break;
891 case LANG_ENGLISH_US:
892 texture_list[16].name = (char *) GetPackFile(read_buffer, "pause_e.img", 0);
893 break;
894 case LANG_ENGLISH_UK:
895 texture_list[16].name = (char *) GetPackFile(read_buffer, "pause_e.img", 0);
896 break;
897 case LANG_FRENCH:
898 texture_list[16].name = (char *) GetPackFile(read_buffer, "pause_f.img", 0);
899 break;
900 case LANG_GERMAN:
901 texture_list[16].name = (char *) GetPackFile(read_buffer, "pause_g.img", 0);
902 break;
903 case LANG_ITALIAN:
904 texture_list[16].name = (char *) GetPackFile(read_buffer, "pause_i.img", 0);
905 break;
906 case LANG_SPANISH:
907 texture_list[16].name = (char *) GetPackFile(read_buffer, "pause_s.img", 0);
908 break;
909 }
910
911 texture_list[17].name = (char *) GetPackFile(read_buffer, "p09a01an.img", 0);
912#else
913 texture_list[16].name = (char *) GetPackFile(read_buffer, "pause_e.img", 0);
914 texture_list[17].name = (char *) GetPackFile(read_buffer, "start2.img", 0);
915 texture_list[18].name = (char *) GetPackFile(read_buffer, "p09a01an.img", 0);
916#endif
917
918 TexManager.Initialize(16352);
919 TexManager.LoadTextureBlock(-1, texture_list);
920
921 OP_FireList = 0;
922 OPAnalyz("opdat/toan.cfg");
923 OPMdsLoad();
924
925 LoadFile("opdat/toan/t0101.mds", (void *) read_buffer, 0);
926 MapDataBuffer.used = 0;
927 ToansHouse = LoadMDSFile(read_buffer, &MapDataBuffer, 2, 0, 0);
928 OP_ToanMapObj.Initialize();
929 OP_ToanMapObj.SetFrame(ToansHouse, 0);
930 OP_ToanMapObj.handle = 0;
931 OP_ToanMapObj.unk_34 = 0;
932
933 LoadFile("opdat/toan/03komono.chr", (void *) read_buffer, 0);
934 Komono.LoadPackData(read_buffer, "03komono.cfg", &MapDataBuffer, 0);
935
936 CFrameAttr komono_attr;
937
938 komono_attr.clip_enable = false;
939 Komono.frame->SetAttr(komono_attr, 1, 4);
940 Komono.motion_type.state.time = 10.0f;
941 Komono.motion_type.state.blend_step = 0.05f;
942 Komono.motion_type.state.motion_no = 0;
943 Komono.motion_type.state.playing_no = 0;
944
945 LoadFile("opdat/chara/03p10a.chr", (void *) read_buffer, 0);
946 Chara__3[10].LoadPackData(read_buffer, "03p10a.cfg", &CharaDataBuffer__2[6], 0);
947
948 CFrameAttr mother_attr;
949
950 mother_attr.clip_enable = false;
951 Chara__3[10].frame->SetAttr(mother_attr, 1, 4);
952 Chara__3[10].motion_type.state.time = 10.0f;
953 Chara__3[10].motion_type.state.blend_step = 0.05f;
954 Chara__3[10].motion_type.state.motion_no = 0;
955 Chara__3[10].motion_type.state.playing_no = 0;
956
957 CFrame *soup = Chara__3[10].frame->SearchFrame("soup_nakami2");
958
959 if (soup) {
960 soup->attr.draw_on = 0;
961 }
962
963 LoadFile("opdat/chara/03c01d.chr", (void *) read_buffer, 0);
964 Chara__3[8].LoadPackData(read_buffer, "03c01d.cfg", &CharaDataBuffer__2[6], 0);
965
966 CFrameAttr toan_attr;
967
968 toan_attr.clip_enable = false;
969 Chara__3[8].frame->SetAttr(toan_attr, 1, 4);
970 Chara__3[8].motion_type.state.time = 10.0f;
971 Chara__3[8].motion_type.state.blend_step = 0.05f;
972 Chara__3[8].motion_type.state.motion_no = 0;
973 Chara__3[8].motion_type.state.playing_no = 0;
974
975 sceVu0FVECTOR wind_dir;
976
977 wind_dir[3] = 0.0f;
978 wind_dir[1] = 0.0f;
979 wind_dir[2] = 0.0f;
980 wind_dir[0] = 0.0f;
981 Wind.SetDir(wind_dir);
982 Wind.SetVelocity(0.0f);
983 Chara__3[8].wind = (int) &Wind;
984 Chara__3[8].ClothStep(-1);
985
986 LoadFile("opdat/chara/03c01d2.chr", (void *) read_buffer, 0);
987 Chara__3[11].LoadPackData(read_buffer, "03c01d2.cfg", &CharaDataBuffer__2[6], 0);
988
989 toan_attr.clip_enable = false;
990 Chara__3[11].frame->SetAttr(toan_attr, 1, 4);
991 Chara__3[11].motion_type.state.time = 160.0f;
992 Chara__3[11].motion_type.state.blend_step = 0.1f;
993 Chara__3[11].motion_type.state.motion_no = 0;
994 Chara__3[11].motion_type.state.playing_no = 0;
995
996 Door.Initialize();
997 Door.property = 0;
998 Door.mode = 3;
999 Door.start_value[0] = 0.0f;
1000 Door.start_value[1] = 0.0f;
1001 Door.start_value[2] = 0.0f;
1002 Door.end_value[0] = 0.0f;
1003 Door.end_value[1] = 0.0f;
1004 Door.end_value[2] = 0.0f;
1005 Door.step_x = 0.0f;
1006 Door.step_y = 0.0f;
1007 Door.step_z = 0.0f;
1008 strcpy(Door.name, "door_1");
1009 InitObjAnime(ToansHouse, &Door);
1010
1011 CSnd.SE_Stop(MIDI_PORT_SE_TITLE, 16, 22, 0);
1012 CSnd.SE_Stop(MIDI_PORT_SE_TITLE, 16, 21, 0);
1013 CSnd.SetVol(MIDI_PORT_BGM, (float) (OpGetVolSQ(0) * 0.5));
1014 CSnd.SetVol(MIDI_PORT_AMBIENT, (float) (OpGetVolSQ(1) * 0.1));
1015 CScript__2.init_no = 0;
1016}
1017
1018/* The scene's per-tick motion. Four of the actors are told what the script last asked of them —
1019 the loop is over the four the scene animates rather than over all of them — and a motion that
1020 has run past its last key falls through to whatever motion was queued behind it. Then the three
1021 models the camera's own frame tree carries drive three more actors: each is found by name in the
1022 camera model, and its world transform becomes that actor's position and heading. */
1023void OpB_MotionProcess() {
1024 for (int i = 8; i < 12; i++) {
1025 if (CScript__2.obj[i].disp) {
1026 if (CScript__2.obj[i].motion_end != -1) {
1027 if (Chara__3[i].motion_type.state.time > (float) (Chara__3[i].motion_type.motion_info[CScript__2.obj[i].motion].end - 1)) {
1028 CScript__2.obj[i].motion = CScript__2.obj[i].motion_end;
1029 CScript__2.obj[i].motion_end = -1;
1030 }
1031 }
1032
1033 Chara__3[i].motion_type.state.blend_step = CScript__2.obj[i].step;
1034 Chara__3[i].motion_no = CScript__2.obj[i].motion;
1035 Chara__3[i].motion_flags = 0;
1036 Chara__3[i].motion_speed = -1.0f;
1037 }
1038 }
1039
1040 char *frame_names[4] = {"c01d", "p09a", "p10a", "c01d"};
1041 sceVu0FMATRIX matrix;
1042#ifndef PAL
1043 float zero = 0.0f;
1044#endif
1045 sceVu0FVECTOR wind_dir;
1046
1047 for (int i = 0; i < 4; i++) {
1048 CFrame *frame = Cam__2[SceneNp__2].frame->SearchFrame(frame_names[i]);
1049
1050 if (frame) {
1051 frame->GetLWMatrix(matrix);
1052#ifdef PAL
1053 float rot_y = atan2f(matrix[2][0], matrix[2][2]);
1054 float rot_x = 0.0f, rot_z = 0.0f;
1055
1056 Chara__3[i + 8].SetRotation(rot_x, rot_y, rot_z);
1057#else
1058 Chara__3[i + 8].SetRotation(zero, atan2f(matrix[2][0], matrix[2][2]), zero);
1059#endif
1060 float x = matrix[3][0];
1061 float y = matrix[3][1];
1062 float z = matrix[3][2];
1063
1064 Chara__3[i + 8].SetPosition(x, y, z);
1065 }
1066 }
1067
1068 wind_dir[0] = 0.0f;
1069 wind_dir[2] = 0.0f;
1070 wind_dir[1] = 0.0f;
1071 wind_dir[3] = 0.0f;
1072 Wind.SetDir(wind_dir);
1073 Wind.SetVelocity(0.0f);
1074
1075 static int camera = 0;
1076
1077 if (camera != CScript__2.camera_start) {
1078 camera = CScript__2.camera_start;
1079
1080 if (camera == 51) {
1081 Chara__3[8].ClothStep(-1);
1082
1083 for (int i = 0; i < 10; i++) {
1084 Chara__3[8].ClothStep(0);
1085 }
1086 }
1087
1088 if (camera == 57) {
1089 Chara__3[11].ClothStep(-1);
1090
1091 for (int i = 0; i < 10; i++) {
1092 Chara__3[11].ClothStep(0);
1093 }
1094 }
1095 }
1096
1097 if (CScript__2.scene == OP_SCENE_NORUNE && !Pause) {
1098 ObjAnimePlay(&Fuusya[0]);
1099 ObjAnimePlay(&Fuusya[1]);
1100
1101 for (int i = 0; i < 12; i++) {
1102 ObjAnimePlay(&Taimatsu[i]);
1103 }
1104 }
1105
1106 if (CScript__2.scene == OP_SCENE_TOAN_HOUSE) {
1107 if (CScript__2.sprite == 1) {
1108 Door.end_value[1] = -85.0f;
1109 Door.step_y = -2.8f;
1110 }
1111
1112 if (CScript__2.sprite == 2) {
1113 Door.end_value[1] = 0.0f;
1114 Door.step_y = 1.2f;
1115 }
1116
1117 if (!Pause) {
1118 ObjAnimePlay(&Door);
1119 }
1120 }
1121}
1122
1123/* The scene's per-tick sound. Two of the actors' footfalls are played from their own positions
1124 rather than from a track, which is why each is a window on the actor's motion frame with a wait
1125 behind it: a frame number is only inside its window for one tick at the motion's own rate, and
1126 the wait keeps a stutter in the motion from playing the step twice. Which of the two samples a
1127 footfall takes is decided by how far the camera's motion has run, because the ground changes
1128 under the actor part way through the scene. */
1129void OpB_SoundProcess() {
1130 if (CScript__2.scene == OP_SCENE_NORUNE) {
1131 float camera_time = Cam__2[SceneNp__2].motion_type.state.time;
1132
1133 if (CScript__2.obj[9].motion == 0) {
1134 static int wait = 0;
1135 sceVu0FVECTOR position;
1136 int motion_frame;
1137
1138 sceVu0CopyVector(position, Chara__3[9].pos);
1139 motion_frame = (int) Chara__3[9].motion_type.state.time;
1140
1141 if (wait == 0) {
1142 if (motion_frame > 28 && motion_frame < 30) {
1143 if (camera_time < 387.0f) {
1144 OpPlayVolPanSE(position, 10.0f, 400.0f, MIDI_PORT_SE_DEFAULT, 21, 20);
1145 } else {
1146 OpPlayVolPanSE(position, 10.0f, 400.0f, MIDI_PORT_SE_DEFAULT, 21, 32);
1147 }
1148
1149 wait = 4;
1150 } else if (motion_frame > 38 && motion_frame < 40) {
1151 if (camera_time < 387.0f) {
1152 OpPlayVolPanSE(&position[0], (float) (10 + (motion_frame & 0)), (float) (wait - wait + 400), MIDI_PORT_SE_DEFAULT, 21, 21);
1153 } else {
1154 OpPlayVolPanSE(position, 10.0f, 400.0f, MIDI_PORT_SE_DEFAULT, 21, 33);
1155 }
1156
1157 wait = 4;
1158 }
1159 } else {
1160 wait = wait - 1;
1161 }
1162 }
1163
1164 sceVu0FVECTOR river = {50.0f, 50.0f, -100.0f, 0.0f};
1165
1166 OpSetVolPanSE(river, 100.0f, 400.0f, 15, 16, 21);
1167 } else if (CScript__2.scene == OP_SCENE_TOAN_HOUSE) {
1168 if (CScript__2.sprite == 1) {
1169 CSnd.SetVol(MIDI_PORT_BGM, (float) (OpGetVolSQ(0) * 1.0));
1170 CSnd.SetVol(MIDI_PORT_AMBIENT, (float) (OpGetVolSQ(1) * 0.7));
1171 }
1172
1173 if (CScript__2.camera_start == 55) {
1174 CSnd.SetVol(MIDI_PORT_BGM, (float) (OpGetVolSQ(0) * 0.5));
1175 CSnd.SetVol(MIDI_PORT_AMBIENT, (float) (OpGetVolSQ(1) * 0.1));
1176 }
1177
1178 if (CScript__2.camera_start == 55 && CScript__2.obj[10].motion == 6) {
1179 static int wait = 0;
1180 sceVu0FVECTOR position;
1181 int motion_frame;
1182
1183 sceVu0CopyVector(position, Chara__3[9].pos);
1184 motion_frame = (int) Chara__3[10].motion_type.state.time;
1185
1186 if (wait == 0) {
1187 if (motion_frame > 134 && motion_frame < 136) {
1188 OpPlayVolPanSE(position, 50.0f, 300.0f, MIDI_PORT_SE_DEFAULT, 21, 32);
1189 wait = 5;
1190 } else if (motion_frame > 144 && motion_frame < 146) {
1191 OpPlayVolPanSE(position, 50.0f, 300.0f, MIDI_PORT_SE_DEFAULT, 21, 33);
1192 wait = 5;
1193 }
1194 } else {
1195 wait = wait - 1;
1196 }
1197 }
1198
1199 sceVu0FVECTOR position;
1200
1201 sceVu0CopyVector(position, Chara__3[10].pos);
1202 OpSetVolPanSE(position, 100.0f, 200.0f, 14, 40, 39);
1203 }
1204}
1205
1206/* The scene's per-tick drawing, in the order the frame is built: the world, then the fires that
1207 are lights rather than models, then the actors' shadows onto the one buffer that holds them all,
1208 then the actors themselves, and last the depth of field the two outdoor scenes take. The near
1209 plane is pulled in to half a unit because the camera passes through the scenery, and the far one
1210 is the largest the Z buffer holds. */
1211void OpB_DrawProcess() {
1212 RenderInfo *info = &mgRenderInfo;
1213
1214 MGSetRenderInfo(info->scale[0], 0.5f, 0xffff);
1215 TexManager.ReloadTexture(Vif1Packet, 10);
1216
1217 switch (CScript__2.scene) {
1218 case OP_SCENE_NORUNE:
1219 for (int i = 0; i < 68; i++) {
1220 CMapObject *obj = &OP_NornMapObj[i];
1221
1222 obj->Draw();
1223 }
1224
1225 TexManager.ReloadTexture(Vif1Packet, 11);
1226
1227 for (int i = 0; i < 23; i++) {
1228 CMapObject *obj = &OP_NornMapObj2[i];
1229
1230 obj->Draw();
1231 }
1232
1233 break;
1234
1235 case OP_SCENE_TOAN_HOUSE:
1236 setTexAnime();
1237 OP_ToanMapObj.Draw();
1238 break;
1239 }
1240
1241 if (OP_FireList > 0) {
1242 sceVu0FVECTOR eye;
1243
1244 TexManager.ReloadTexture(GetVif1Packet(), 0);
1245 OP_CharaFrame__2 = Cam__2[SceneNp__2].frame;
1246 sceVu0CopyVector(eye, OP_CharaFrame__2->position);
1247
1248 if (!Pause) {
1249 CFire.FireStep();
1250 }
1251
1252 CFire.FireCreate();
1253
1254 for (int i = 0; i < OP_FireList; i++) {
1255 float z = OP_FirePosition[i][2];
1256 float y = OP_FirePosition[i][1];
1257 float x = OP_FirePosition[i][0];
1258
1259 CFire.pos[0] = 10.0f * x;
1260 CFire.pos[1] = 10.0f * y;
1261 CFire.pos[2] = 10.0f * z;
1262 CFire.pos[3] = 1.0f;
1263
1264 int fire_flag = OP_FireFlg[i];
1265
1266 if (fire_flag == 1) {
1267 CFire.DrawFire(1, 1, &OP_MainCamera, eye, OP_FireScale[i], 3, 15.0f);
1268 } else {
1269 CFire.DrawFire(1, 1, &OP_MainCamera, eye, OP_FireScale[i], 2, 15.0f);
1270 }
1271 }
1272 }
1273
1274 if (CScript__2.sprite == 3) {
1275 CFrame *frame = Chara__3[8].frame->SearchFrame("soup_nakami");
1276
1277 if (frame) {
1278 frame->attr.draw_on = 0;
1279 }
1280 }
1281
1282 TexManager.ReloadTexture(Vif1Packet, 23);
1283 MGBeginDrawShadow(*(sceGsTex0 *) &TexManager.GetTexture("shadow_buff", -1)->tex0);
1284
1285 for (int i = 8; i < 12; i++) {
1286 if (CScript__2.obj[i].disp) {
1287 if (!Pause) {
1288 Chara__3[i].ShadowStep();
1289 }
1290
1291 Chara__3[i].DrawShadow();
1292 }
1293 }
1294
1295 MGEndDrawShadow(52);
1296
1297 for (int i = 8; i < 12; i++) {
1298 if (CScript__2.obj[i].disp) {
1299 TexManager.ReloadTexture(Vif1Packet, CharaTex__2[i]);
1300
1301 if (!Pause) {
1302 Chara__3[i].Step();
1303 Chara__3[i].ClothStep(0);
1304 }
1305
1306 if (i == 9) {
1307 FaceChangeC(i);
1308 }
1309
1310 Chara__3[i].Draw();
1311 }
1312 }
1313
1314 if (CScript__2.scene == OP_SCENE_TOAN_HOUSE) {
1315 TexManager.ReloadTexture(Vif1Packet, 22);
1316
1317 if (!Pause) {
1318 Komono.Step();
1319 }
1320
1321 Komono.Draw();
1322 }
1323
1324 if (CScript__2.scene == OP_SCENE_NORUNE) {
1325 TexManager.ReloadTexture(Vif1Packet, 23);
1326 MGBeginDrawShadow(*(sceGsTex0 *) &TexManager.GetTexture("shadow_buff", -1)->tex0);
1327
1328 switch (CScript__2.scene) {
1329 case OP_SCENE_NORUNE:
1330 for (int i = 0; i < 68; i++) {
1331 OP_NornMapObj[i].DrawShadow(0);
1332 }
1333
1334 break;
1335
1336 case OP_SCENE_TOAN_HOUSE:
1337 OP_ToanMapObj.DrawShadow(0);
1338 break;
1339 }
1340
1341 MGEndDrawShadow(52);
1342 }
1343
1344 if (CScript__2.scene != OP_SCENE_TOAN_HOUSE) {
1345 TexManager.ReloadTexture(Vif1Packet, 21);
1346
1347 float dof[2] = {300.0f, 1000.0f};
1348
1349 DepthOfField(dof, 2, 64, 0);
1350 }
1351}
1352
1365static void setTexAnime() {
1366 sceGifTag giftag = {0, 1, 0, 0, 0, 0, 1, SCE_GIF_PACKED_AD};
1367 CTexture *plate;
1368 CTexture *strip;
1369 int dbp;
1370 int dbw;
1371 int sbp;
1372 int sbw;
1373
1374 sceVif1PkCnt(Vif1Packet, 0);
1375 sceVif1PkOpenDirectCode(Vif1Packet, 0);
1376 sceVif1PkOpenGifTag(Vif1Packet, *(u_long128 *) &giftag);
1377 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEXFLUSH, 0);
1378 sceVif1PkCloseGifTag(Vif1Packet);
1379 sceVif1PkCloseDirectCode(Vif1Packet);
1380 sceVif1PkTerminate(Vif1Packet);
1381
1382 plate = TexManager.GetTexture("i01e01", -1);
1383 strip = TexManager.GetTexture("i01e01_a", -1);
1384
1385 if (plate == 0 || strip == 0) {
1386 return;
1387 }
1388
1389 dbp = plate->tex0 & 0x3fff;
1390 dbw = (plate->tex0 >> 14) & 0x3f;
1391 sbp = strip->tex0 & 0x3fff;
1392 sbw = (strip->tex0 >> 14) & 0x3f;
1393
1394 static float cnt = 0.0f;
1395
1396 MoveImageTest(Vif1Packet, sbp, sbw, 0, CRect<int>(0, (int) cnt * 64, 64, 64), dbp, dbw, 0, 0, 0, 0);
1397
1398 cnt += 0.5f;
1399
1400 if (cnt > 7.0f) {
1401 cnt = 0.0f;
1402 }
1403}
1404
1405/* One actor's blinking and speaking. The mouth is driven from the script's own clock rather than
1406 from a motion: while the actor is talking, a new mouth frame is picked at random every sixth
1407 hundredth of a second left on the timer, and the timer running out closes the mouth and ends the
1408 line. The eyes are whatever the script last asked for. The cache is flushed on both sides of the
1409 two transfers because the plate is a texture the previous tick drew from and the next one will. */
CFrame * frame
virtual void LoadPackData(unsigned int *pack, char *name, CDataAlloc2< 1 > *model_alloc, CDataAlloc2< 1 > *texture_alloc)
virtual void Step()
virtual void ShadowStep()
tagMOTION_TYPE motion_type
virtual void SetRotation(float x, float y, float z)
virtual void DrawShadow()
virtual void Initialize()
float motion_speed
virtual void Draw()
virtual void SetPosition(float x, float y, float z)
virtual void ClothStep(int step)
CTexture * core
Definition op_a.cpp:110
s32 texture_set
Definition op_a.cpp:109
sceVu0FVECTOR pos
Definition op_a.cpp:108
CTexture * glow
Definition op_a.cpp:111
short draw_on
Definition frame.hpp:27
char clip_enable
Definition frame.hpp:29
char fog_enable
Definition frame.hpp:33
CFrameAttr attr
Definition frame.hpp:65
sceVu0FVECTOR position
Definition frame.hpp:76
float shadow_offset
Definition op_b.cpp:94
CFrameVu1 * collision_frame
Definition op_b.cpp:90
int handle
Definition op_b.cpp:96
int unk_34
Definition op_b.cpp:95
CFrameVu1 * shadow_frame
Definition op_b.cpp:91
CFrameVu1 * shade_frame
Definition op_b.cpp:92
CFrameVu1 * camera_frame
Definition op_b.cpp:93
s32 rotation_changed
Definition op_b.cpp:77
CFrameVu1 * frame[4]
Definition op_b.cpp:76
s32 draw_on
Definition op_b.cpp:78
Definition op_a.cpp:55
T h
Definition op_a.cpp:60
T y
Definition op_a.cpp:58
T x
Definition op_a.cpp:57
T w
Definition op_a.cpp:59
SCRIPT_OBJ obj[23]
Definition script.hpp:149
float motion_step
Definition script.hpp:152
int load_no
Definition script.hpp:143
int scene
Definition script.hpp:142
int sprite
Definition script.hpp:141
int camera_start
Definition script.hpp:135
int init_no
Definition script.hpp:144
void SE_Play(int port, int bank, int program, int pan, int velocity, int volume, int voice)
Definition sound.cpp:579
int LoadSoundFileFromPack(char *name, unsigned int *pack)
Definition sound.cpp:186
void Step()
Definition sound.cpp:814
void SetVol(int port, int volume)
Definition sound.cpp:983
void SE_Stop(int port, int bank, int program, int voice)
Definition sound.cpp:719
void SQ_Play(int port, int seq_no)
Definition sound.cpp:495
void SetReverb(int core, int mode, int depth)
Definition sound.cpp:74
u_long tex0
Definition texture.hpp:57
Definition wind.hpp:12
void SetVelocity(float speed)
Definition wind.cpp:9
void SetDir(float *direction)
Definition wind.cpp:5
sceVu0FVECTOR end_value
Definition op_a.cpp:203
float step_y
Definition op_a.cpp:205
sceVu0FVECTOR current
Definition op_a.cpp:208
void Initialize()
Definition objanime.cpp:33
char name[16]
Definition op_a.cpp:198
int completion_flag
Definition op_a.cpp:210
CFrame * frames[10]
Definition op_a.cpp:209
sceVu0FVECTOR start_value
Definition op_a.cpp:202
float step_z
Definition op_a.cpp:206
float step_x
Definition op_a.cpp:204
char * plate
Definition op_a.cpp:180
char * strip
Definition op_a.cpp:181
int eye_bottom
Definition op_a.cpp:182
int blink
Definition op_a.cpp:190
int strip_bottom
Definition op_a.cpp:188
int mouth
Definition op_a.cpp:187
int mouth_height
Definition op_a.cpp:185
int eye_height
Definition op_a.cpp:183
int eye
Definition op_a.cpp:186
int mouth_bottom
Definition op_a.cpp:184
int eye_max
Definition op_a.cpp:189
float rotation[3]
Definition op_b.cpp:175
char * name
Definition op_b.cpp:172
float position[3]
Definition op_b.cpp:174
char * shadow_name
Definition op_b.cpp:173
float blend_step
Definition gameutil.hpp:190
sceVu0FVECTOR scale
float step
Definition script.hpp:125
float eye_time
Definition script.hpp:118
int motion_end
Definition script.hpp:113
int load_step
Definition script.hpp:124
float mouth_time
Definition script.hpp:120
MOTION_INFO * motion_info
Definition gameutil.hpp:275
MOTION_STATE state
Definition gameutil.hpp:273