DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
op_a.cpp
1#ifdef PAL
2#pragma argument_flag 0
3#pragma argument_flag_ones 210, 230, 247, 255, 277, 308, 310, 484, 485, 486
4#pragma argument_flag_ones 494, 496, 499, 501, 545, 548, 552, 553, 557, 560
5#pragma argument_flag_ones 583, 594, 602, 609, 610, 611, 614, 615, 616, 655
6#pragma argument_flag_ones 665, 671, 672, 673, 679, 689, 695, 696, 697, 703
7#pragma argument_flag_ones 713, 719, 720, 721, 736, 751, 757, 758, 764, 772
8#pragma argument_flag_ones 825, 1002
9#else
10#pragma argument_flag 0
11#pragma argument_flag_ones 190, 210, 227, 235, 257, 288, 290, 295, 403, 428
12#pragma argument_flag_ones 430, 464, 465, 466, 474, 476, 479, 481, 525, 528
13#pragma argument_flag_ones 532, 533, 537, 540, 563, 574, 582, 589, 590, 591
14#pragma argument_flag_ones 594, 595, 596, 635, 645, 651, 652, 653, 659, 669
15#pragma argument_flag_ones 675, 676, 677, 683, 693, 699, 700, 701, 716, 731
16#pragma argument_flag_ones 737, 738, 744, 752, 805, 982
17#endif
18#include "common.h"
19
20#include <libgraph.h>
21#include <libpkt.h>
22#include <libvu0.h>
23
24#include <cmath>
25#include <cstdlib>
26
27#include "camera.hpp"
28#include "camerafollow.hpp"
29#include "character.hpp"
30#include "dataalloc.hpp"
31#include "dataread.hpp"
32#include "frame.hpp"
33#include "framevu1.hpp"
34#include "main.hpp"
35#include "mainselect.hpp"
36#include "mapobject.hpp"
37#include "mathutil.hpp"
38#include "mds.hpp"
39#include "mglib.hpp"
40#include "renderinfo.hpp"
41#include "sound.hpp"
42#include "texture.hpp"
43#include "title/op_a.hpp"
44#include "title/opening.hpp"
45#include "title/script.hpp"
46
48
49/* The rectangle a texture transfer takes, declared here rather than reached through rect.h for the
50 reason op_b.cpp declares its own: rect.h's four-argument constructor assigns h, w, y and x in
51 that order and every rectangle this file builds assigns them the other way round. The default
52 constructor keeps rect.h's order and is not dead code — the effect parameter block below carries
53 one as a member, so it runs wherever a caller builds that block. */
54template <class T>
55class CRect {
56public:
57 T x;
58 T y;
59 T w;
60 T h;
62 CRect() {
63 h = 0;
64 w = 0;
65 y = 0;
66 x = 0;
67 }
68
69 CRect(T new_x, T new_y, T new_width, T new_height) {
70 x = new_x;
71 y = new_y;
72 w = new_width;
73 h = new_height;
74 }
75} __attribute__((aligned(16)));
76
77/* One row of the table a map sorts its scenery by, and one piece of scenery. Both are another
78 unit's to type; this file holds three maps and so has to construct them, which is what needs
79 their extents and their constructors and nothing else. */
80class CategoryAttr {
81public:
82 char unk_00[24];
83
85};
86
87/* The scene's own map, of which this file keeps three — the ground, the buildings standing on it
88 and a second set of buildings nothing here draws. Initialize is called from the constructor
89 rather than by the scene, which is why the three are ready before OpA_InitProcess clears them. */
90class CMap {
91public:
93 CMapObject object[10];
94 char unk_AE0[16];
95
96 CMap() { Initialize(); }
97
98 void Initialize();
99 void Draw();
100};
101
102class CTexture;
103
104/* The scene's one fire, which is a light rather than a model. */
106public:
107 char unk_00[32];
108 sceVu0FVECTOR pos;
112 s32 unk_3C;
113
114 CFireOmni();
115
116 void FireStep();
117 void FireCreate();
118 void DrawFire(int unknown0, int unknown1, CCamera *camera, float *eye, float scale, int unknown2, float unknown3);
119};
120
121/* One particle of the smoke the chimney gives off, and the pool the group hands them out of. Both
122 classes are another unit's to type; this file only sizes the pool and names the group. */
123class CEffect;
124class CEffectParam;
125
127public:
131 CEffectGroup() { Initialize(0, 0); }
132
133 void Initialize(CEffect *table, int max);
134 void Clear();
135 void EnterEffect(CEffectParam *param);
136 void Step(int unknown0);
137 void Draw();
138};
139
140/* What one particle is entered with. Only the fields the smoke sets are named; the rectangle is a
141 member rather than filler because the block's own construction zeroes it. */
143public:
146 float unk_08;
147 float height;
148 char unk_10[16];
149 sceVu0FVECTOR position;
150 char unk_30[4];
152 char unk_38[24];
154 char unk_54[12];
156 char unk_64[28];
159 char unk_88[40];
162 float opacity;
165 char unk_D0[4];
167 char unk_D8[8];
168
169 CEffectParam() {}
170
171 void Initialize();
172};
173
174/* One actor's face, as this scene animates it. The eyes and the mouth are two strips of frames
175 stacked bottom-up in one 256-wide texture — the eyes down the left half and the mouth down the
176 right — and a tick copies the current frame of each over the plate the model draws with. The two
177 offsets are measured from the bottom edge of the plate; the blink state is kept here because this
178 scene blinks the cast on a clock of its own rather than from the script. */
192
193/* One looping object animation the scene's configuration file registers: a frame is found by name
194 and one of its properties is driven from a start value towards an end value by a step each
195 tick. Only the extent is read here — this file plays the table and never builds a row of it. */
197public:
198 char name[16];
200 int mode;
201 char unk_18[8];
202 sceVu0FVECTOR start_value;
203 sceVu0FVECTOR end_value;
204 float step_x;
205 float step_y;
206 float step_z;
207 float step_w;
208 sceVu0FVECTOR current;
211 int unk_8C;
212
214
215 void Initialize();
216};
217
218void wait_now_loading_vsync();
219void ObjAnimePlay(OBJ_ANIME_SEQ *sequence);
220void 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);
221void set2DSprite(sceVif1Packet *packet, CTexture *texture, const CRect<int> &src, const CRect<int> &dst, u_char alpha);
222void DepthOfField(float *dist, int level, int alpha, int blur);
223
224static void LoadTexture();
225static void LoadData();
226static void SetDanceMotion();
227static void InitDancerPos();
228static void DrawCloud();
229static void SmokeProcess();
230static void MoveDancers();
231static void ReaderShadow();
232static void DancerShadow();
233static void ShogunShadow();
234static void ShisaiShadow();
235static void DrawShadow(float x, float y, float z);
236static void setTexScroll();
237static void setCloudTexScroll();
238/* op_b.cpp owns these three; retail has this unit call across to them. */
239void FaceChange(int actor_no);
240void LoadCharaData(int buffer_no, int actor_no);
241void LoadMotionData();
242
243/* Each of the couple's motion files is one key range — the frame it starts at and the frame it ends
244 at — written straight over the character's own first key, so that a file loaded in the background
245 takes over without the motion driver being told anything. */
246#ifdef PAL
247tagMOTION_KEY noroi[10] = {
248 {100, 750, 0.5f, 0},
249 {201, 528, 0.5f, 0},
250 {103, 802, 0.5f, 0},
251 {126, 781, 0.5f, 0},
252 {1, 356, 0.5f, 0},
253 {50, 629, 0.5f, 0},
254 {185, 833, 0.5f, 0},
255 {93, 665, 0.5f, 0},
256 {124, 529, 0.5f, 0},
257 {298, 747, 0.5f, 0}
258};
259
260tagMOTION_KEY dancer[10] = {
261 {12, 536, 0.5f, 0},
262 {209, 536, 0.5f, 0},
263 {111, 810, 0.5f, 0},
264 {116, 771, 0.5f, 0},
265 {1, 356, 0.5f, 0},
266 {1, 629, 0.5f, 0},
267 {135, 783, 0.5f, 0},
268 {82, 660, 0.5f, 0},
269 {124, 529, 0.5f, 0},
270 {327, 782, 0.5f, 0}
271};
272#else
273tagMOTION_KEY noroi[10] = {
274 {100, 750, 0.5f, 0},
275 {201, 533, 0.5f, 0},
276 {103, 798, 0.5f, 0},
277 {136, 777, 0.5f, 0},
278 {1, 352, 0.5f, 0},
279 {50, 628, 0.5f, 0},
280 {195, 843, 0.5f, 0},
281 {103, 675, 0.5f, 0},
282 {139, 542, 0.5f, 0},
283 {298, 747, 0.5f, 0}
284};
285
286tagMOTION_KEY dancer[10] = {
287 {12, 536, 0.5f, 0},
288 {209, 541, 0.5f, 0},
289 {111, 806, 0.5f, 0},
290 {126, 767, 0.5f, 0},
291 {1, 352, 0.5f, 0},
292 {1, 628, 0.5f, 0},
293 {145, 793, 0.5f, 0},
294 {92, 670, 0.5f, 0},
295 {139, 542, 0.5f, 0},
296 {327, 782, 0.5f, 0}
297};
298#endif
299
300/* The scene's own world, and the objects the configuration file fills in. Both frame pointers are
301 typed from the loader that writes them rather than from anything here: title/opdata assigns
302 LoadCollisionFile's and LoadMDSFile's results to them, and nothing in this file reads either. */
303CMap OP_BuildingMap;
304CMap OP_BuildingMap2;
305CMap OP_GroundMap;
306OBJ_ANIME_SEQ OP_AnimeSeq[32];
307int OP_AnimeSeqRot;
308int OP_FireList;
309sceVu0FVECTOR OP_FirePosition[96];
310float OP_FireScale[96];
311int OP_FireFlg[96];
312CFrameVu1 *OP_GroundCol;
313CFrameVu1 *OP_SkyFrame;
314CFrame *OP_CharaFrame__2;
315char CloudFlag;
316
317CFireOmni CFire;
318static sceVu0FVECTOR DancerPos[35];
319static sceVu0FVECTOR DancerRot[35];
320static CCharacter Cloud;
321
322static CFrameVu1 *Shadow;
323static float DancerAmb;
324static CEffectGroup Smoke;
325static CEffect *EffectTable;
326static float DanceWait;
327int DanceCnt;
328int DanceStart;
329
330/* The dungeon square's set-up. The two maps are cleared first because this scene is placed from a
331 configuration file rather than from a table of its own, and the couple's second motion files are
332 started in the background so that the first change of step does not wait for a read. */
333void OpA_InitProcess() {
334 OP_FireList = 0;
335 OP_AnimeSeqRot = 0;
336 OP_GroundMap.Initialize();
337 OP_BuildingMap.Initialize();
338 OPAnalyz("opdat/opinfo.cfg");
339 LoadTexture();
340 OPMdsLoad();
341 LoadFile("opdat/dungeon/dungeon.pak", read_buffer, 0);
342 wait_now_loading_vsync();
343 LoadData();
344 CSnd.SetReverb(0, 4, 80);
345 CSnd.SetReverb(1, 4, 60);
346 CSnd.LoadSoundFileFromPack("o01a.txt", read_buffer);
347 CSnd.SetVol(MIDI_PORT_SE_TITLE, 256);
348 CSnd.SetVol(MIDI_PORT_SE_DEFAULT, 256);
349 CSnd.SetVol(MIDI_PORT_UNK_D, 256);
350 CSnd.SetVol(MIDI_PORT_SE_SPECIAL, 256);
351 CSnd.SE_Play(MIDI_PORT_SE_TITLE, 16, 20, 0, 0);
352 wait_now_loading_vsync();
353 SetDanceMotion();
354 LoadFile("opdat/chara/01p19a1b.chr", (void *) ((char *) read_buffer + 0x10C900), 0);
355 LoadFile("opdat/chara/01p17a1b.chr", (void *) read_buffer, 0);
356 StartReadBG();
357 DanceWait = 0.0f;
358 DanceCnt = 1;
359 DanceStart = 0;
360 CloudFlag = 0;
361}
362
373static void LoadTexture() {
374 LOADTEXTURE_INFO2 texture_list[] = {
375 {"#blender#640#" HALF_BUFFER_HEIGHT_STR "#4", 0, 0},
376 {"#fontbase#512#256#1", 26, 0},
377 {"#fukidashibase#640#" HALF_BUFFER_HEIGHT_STR "#4", 26, 0},
378 {"#frame_image#640#" HALF_BUFFER_HEIGHT_STR "#4", 22, 0},
379 {0, 26, 0},
380 {0, 26, 0},
381 {0, 26, 0},
382 {0, 1, 0},
383 {0, 1, 0},
384 {0, 6, 1},
385 {0, 2, 0},
386 {0, 4, 0},
387 {0, 4, 0},
388 {0, 3, 0},
389 {0, 3, 0},
390 {0, 5, 0},
391 {0, 5, 0},
392 {0, 7, 0},
393 {0, 8, 0},
394 {0, 8, 0},
395 {0, 8, 0},
396 {0, 10, 0},
397 {0, 10, 0},
398 {0, 11, 0},
399 {0, 0, 0},
400 {0, 19, 0},
401 {0, 19, 0},
402#ifndef PAL
403 {0, 19, 0},
404#endif
405 {0, 6, 0},
406 {"", 0, 0}
407 };
408
409 TexManager.Initialize(16352);
410 LoadFile("opdat/dungeon/dungeon.pim", (void *) read_buffer, 0);
411
412 texture_list[4].name = (char *) GetPackFile(read_buffer, "gaiji.img", 0);
413 texture_list[5].name = (char *) GetPackFile(read_buffer, "fuki256.img", 0);
414 texture_list[6].name = (char *) GetPackFile(read_buffer, "syst04.img", 0);
415 texture_list[7].name = (char *) GetPackFile(read_buffer, "c07a01.img", 0);
416 texture_list[8].name = (char *) GetPackFile(read_buffer, "c07a01an.img", 0);
417 texture_list[9].name = (char *) GetPackFile(read_buffer, "p17a01.img", 0);
418 texture_list[10].name = (char *) GetPackFile(read_buffer, "c08a01.img", 0);
419 texture_list[11].name = (char *) GetPackFile(read_buffer, "c09a01.img", 0);
420 texture_list[12].name = (char *) GetPackFile(read_buffer, "c09a01an.img", 0);
421 texture_list[13].name = (char *) GetPackFile(read_buffer, "c11a01.img", 0);
422 texture_list[14].name = (char *) GetPackFile(read_buffer, "c11a01an.img", 0);
423 texture_list[15].name = (char *) GetPackFile(read_buffer, "p19a01.img", 0);
424 texture_list[16].name = (char *) GetPackFile(read_buffer, "p19a01an.img", 0);
425 texture_list[17].name = (char *) GetPackFile(read_buffer, "ex.img", 0);
426 texture_list[18].name = (char *) GetPackFile(read_buffer, "cloud.img", 0);
427 texture_list[19].name = (char *) GetPackFile(read_buffer, "cloudan.img", 0);
428 texture_list[20].name = (char *) GetPackFile(read_buffer, "cloud2.img", 0);
429 texture_list[21].name = (char *) GetPackFile(read_buffer, "i01t01.img", 0);
430 texture_list[22].name = (char *) GetPackFile(read_buffer, "i01t02.img", 0);
431 texture_list[23].name = (char *) GetPackFile(read_buffer, "e01s01.img", 0);
432 texture_list[24].name = (char *) GetPackFile(read_buffer, "fire.img", 0);
433 texture_list[25].name = (char *) GetPackFile(read_buffer, "pause.img", 0);
434
435#ifdef PAL
436 switch (LanguageCode) {
437 case LANG_JAPANESE:
438 texture_list[26].name = (char *) GetPackFile(read_buffer, "pause_e.img", 0);
439 break;
440 case LANG_ENGLISH_US:
441 texture_list[26].name = (char *) GetPackFile(read_buffer, "pause_e.img", 0);
442 break;
443 case LANG_ENGLISH_UK:
444 texture_list[26].name = (char *) GetPackFile(read_buffer, "pause_e.img", 0);
445 break;
446 case LANG_FRENCH:
447 texture_list[26].name = (char *) GetPackFile(read_buffer, "pause_f.img", 0);
448 break;
449 case LANG_GERMAN:
450 texture_list[26].name = (char *) GetPackFile(read_buffer, "pause_g.img", 0);
451 break;
452 case LANG_ITALIAN:
453 texture_list[26].name = (char *) GetPackFile(read_buffer, "pause_i.img", 0);
454 break;
455 case LANG_SPANISH:
456 texture_list[26].name = (char *) GetPackFile(read_buffer, "pause_s.img", 0);
457 break;
458 }
459
460 texture_list[27].name = (char *) GetPackFile(read_buffer, "ashikage.img", 0);
461#else
462 texture_list[26].name = (char *) GetPackFile(read_buffer, "pause_e.img", 0);
463 texture_list[27].name = (char *) GetPackFile(read_buffer, "start2.img", 0);
464 texture_list[28].name = (char *) GetPackFile(read_buffer, "ashikage.img", 0);
465#endif
466
467 TexManager.LoadTextureBlock(-1, texture_list);
468
469 CharaTex__2[0] = 1;
470 CharaTex__2[1] = 2;
471 CharaTex__2[4] = 2;
472 CharaTex__2[5] = 2;
473 CharaTex__2[3] = 4;
474 CharaTex__2[2] = 3;
475 CharaTex__2[6] = 5;
476 CharaTex__2[7] = 6;
477}
478
489static void LoadData() {
490 char *config_names[4] = {"01c07a.cfg", "01c08a.cfg", "01c11a.cfg", "01c09a.cfg"};
491
492 for (int i = 0; i < 4; i++) {
493 Chara__3[i].LoadPackData(read_buffer, config_names[i], CharaDataBuffer__2, 0);
494
495 CFrameAttr attr;
496
497 attr.clip_enable = false;
498 Chara__3[i].frame->SetAttr(attr, 1, 4);
499 Chara__3[i].motion_type.state.time = 10.0f;
500 Chara__3[i].motion_type.state.blend_step = 0.05f;
501 Chara__3[i].motion_type.state.motion_no = 0;
502 Chara__3[i].motion_type.state.playing_no = 0;
503 }
504
505 Chara__3[1].motion_type.state.time = 115.0f;
506
507 wait_now_loading_vsync();
508
509 Chara__3[6].Initialize();
510 Chara__3[6].frame = LoadMDSFile(GetPackFile(read_buffer, "01p19a.mds", 0), &CharaDataBuffer__2[4], 6, 0, 0);
511
512 CFrameAttr noroi_attr;
513
514 noroi_attr.clip_enable = false;
515 Chara__3[6].frame->SetAttr(noroi_attr, 1, 4);
516
517 wait_now_loading_vsync();
518
519 Chara__3[7].Initialize();
520 Chara__3[7].frame = LoadMDSFile(GetPackFile(read_buffer, "01p17a.mds", 0), &CharaDataBuffer__2[4], 6, 0, 0);
521
522 CFrameAttr dancer_attr;
523
524 dancer_attr.clip_enable = false;
525 Chara__3[7].frame->SetAttr(dancer_attr, 1, 4);
526
527 float scale[4] = {4.5f, 1.0f, 4.5f, 0.0f};
528
529 Chara__3[7].frame->SearchFrame("body")->ScaleBoundBox(scale);
530
531 InitDancerPos();
532
533 wait_now_loading_vsync();
534
535 Cloud.frame = LoadMDSFile(GetPackFile(read_buffer, "01cloud.mds", 0), 2, 0);
536 Cloud.SetPosition(0.0f, 50.0f, 20.0f);
537
538 EffectTable = (CEffect *) MapDataBuffer.Alloc(12800);
539 Smoke.Initialize(EffectTable, 50);
540 Smoke.Clear();
541
542 Shadow = LoadMDSFile(GetPackFile(read_buffer, "ashikage.mds", 0), 2, 0);
543}
544
554static void SetDanceMotion() {
555 LoadFile("opdat/chara/01p19a1a.chr", (void *) read_buffer, 0);
556 Chara__3[6].LoadPackData(read_buffer, "01p19a1a.cfg", &CharaDataBuffer__2[4], &CharaDataBuffer__2[6], 0);
557 Chara__3[6].motion_type.state.time = 120.0f;
558 Chara__3[6].motion_type.state.blend_step = 0.1f;
559 Chara__3[6].motion_type.state.motion_no = 0;
560 Chara__3[6].motion_type.state.playing_no = 0;
561 Chara__3[6].motion_type.motion_info->start = noroi[0].start;
562 Chara__3[6].motion_type.motion_info->end = noroi[0].end;
563
564 LoadFile("opdat/chara/01p17a1a.chr", (void *) read_buffer, 0);
565 Chara__3[7].LoadPackData(read_buffer, "01p17a1a.cfg", &CharaDataBuffer__2[4], &CharaDataBuffer__2[6], 0);
566 Chara__3[7].motion_type.state.time = 1.0f;
567 Chara__3[7].motion_type.state.blend_step = 0.1f;
568 Chara__3[7].motion_type.state.motion_no = 0;
569 Chara__3[7].motion_type.state.playing_no = 0;
570 Chara__3[7].motion_type.motion_info->start = dancer[0].start;
571 Chara__3[7].motion_type.motion_info->end = dancer[0].end;
572}
573
583static void InitDancerPos() {
584 float layout[35][4] = {
585 {3.0f, 0.0f, 27.0f, 0.0f},
586 {0.0f, 0.0f, 27.0f, 0.0f},
587 {-3.0f, 0.0f, 27.0f, 0.0f},
588 {1.5f, 0.0f, 29.0f, 0.0f},
589 {-1.5f, 0.0f, 29.0f, 0.0f},
590 {4.5f, 0.0f, 29.0f, 0.0f},
591 {-4.5f, 0.0f, 29.0f, 0.0f},
592 {3.0f, 0.0f, 31.0f, 0.0f},
593 {0.0f, 0.0f, 31.0f, 0.0f},
594 {-3.0f, 0.0f, 31.0f, 0.0f},
595 {1.5f, 0.0f, 33.0f, 0.0f},
596 {-1.5f, 0.0f, 33.0f, 0.0f},
597 {4.5f, 0.0f, 33.0f, 0.0f},
598 {-4.5f, 0.0f, 33.0f, 0.0f},
599 {3.0f, 0.0f, 35.0f, 0.0f},
600 {0.0f, 0.0f, 35.0f, 0.0f},
601 {-3.0f, 0.0f, 35.0f, 0.0f},
602 {1.5f, 0.0f, 37.0f, 0.0f},
603 {-1.5f, 0.0f, 37.0f, 0.0f},
604 {4.5f, 0.0f, 37.0f, 0.0f},
605 {-4.5f, 0.0f, 37.0f, 0.0f},
606 {3.0f, 0.0f, 39.0f, 0.0f},
607 {0.0f, 0.0f, 39.0f, 0.0f},
608 {-3.0f, 0.0f, 39.0f, 0.0f},
609 {1.5f, 0.0f, 41.0f, 0.0f},
610 {-1.5f, 0.0f, 41.0f, 0.0f},
611 {4.5f, 0.0f, 41.0f, 0.0f},
612 {-4.5f, 0.0f, 41.0f, 0.0f},
613 {3.0f, 0.0f, 43.0f, 0.0f},
614 {0.0f, 0.0f, 43.0f, 0.0f},
615 {-3.0f, 0.0f, 43.0f, 0.0f},
616 {1.5f, 0.0f, 45.0f, 0.0f},
617 {-1.5f, 0.0f, 45.0f, 0.0f},
618 {4.5f, 0.0f, 45.0f, 0.0f},
619 {-4.5f, 0.0f, 45.0f, 0.0f}
620 };
621
622 for (int i = 0; i < 35; i++) {
623 DancerPos[i][0] = 10.0f * layout[i][0];
624 DancerPos[i][1] = 10.0f * layout[i][1];
625 DancerPos[i][2] = 10.0f + 10.0f * layout[i][2];
626 DancerRot[i][0] = 0.0f;
627 DancerRot[i][1] = PI_D;
628 /* The third store repeats the first rather than clearing the roll, which is deliberate here
629 and not a slip left in place: every row of the table has a zero roll already, so the
630 line has no effect either way, and the code the compiler emits is not the same without
631 it. */
632 DancerRot[i][0] = 0.0f;
633 }
634
635 Chara__3[6].SetPosition(0.0f, 0.0f, 250.0f);
636 Chara__3[6].SetRotation(0.0f, PI_D, 0.0f);
637}
638
639/* The tick's drawing, in the order the frame is built: the ground, the buildings standing on it,
640 the townspeople, the couple, the crowd behind them, the fires, the sky and last the depth of
641 field. The two ambients that fade are what makes the square go dark as the scene turns: one rides
642 up over the buildings while the camera holds on them, the other rides the crowd down as the
643 couple's motion runs out. */
644void OpA_DrawProcess() {
645 static sceVu0FVECTOR ambient = {0.0f, 0.0f, 0.0f, 0.0f};
646 static int wait;
647 sceVu0FVECTOR saved_ambient;
648
649 TexManager.ReloadTexture(Vif1Packet, 10);
650 OP_GroundMap.Draw();
651 TexManager.ReloadTexture(Vif1Packet, 11);
652
653 if (!Pause) {
654 setTexScroll();
655 }
656
657 if (CScript__2.camera_start != 44) {
658 if (CScript__2.camera_start < 15 || CScript__2.camera_start >= 39) {
659 OP_BuildingMap.Draw();
660 }
661
662 ambient[3] = 0.0f;
663 wait = 0;
664 } else {
665 MGGetAmbient(saved_ambient);
666
667 if (wait > 700) {
668 if (ambient[3] < 128.0f) {
669 ambient[3] += 0.1f;
670 }
671 } else {
672 wait++;
673 }
674
675 MGSetAmbient(ambient);
676 OP_BuildingMap.Draw();
677 MGSetAmbient(saved_ambient);
678 }
679
680 for (int i = 0; i < 6; i++) {
681 if (i != 1 && CScript__2.obj[i].disp) {
682 TexManager.ReloadTexture(Vif1Packet, CharaTex__2[i]);
683 FaceChange(i);
684
685 if (!Pause) {
686 Chara__3[i].Step();
687 }
688
689 Chara__3[i].Draw();
690
691 if (i == 2) {
692 ShisaiShadow();
693 }
694
695 if (i == 3) {
696 ShogunShadow();
697 }
698 }
699 }
700
701 if (CScript__2.obj[1].disp) {
702 TexManager.ReloadTexture(Vif1Packet, CharaTex__2[1]);
703
704 if (!Pause) {
705 Chara__3[1].Step();
706 }
707
708 static float col = 0.0f;
709 static float am = 0.0f;
710 static int wait = 0;
711
712 if (CScript__2.camera_start == 17) {
713 static sceVu0FMATRIX lcolor;
714
715 for (int i = 0; i < 3; i++) {
716 if (lightcolor[i][0] > col) {
717 lcolor[i][0] = col;
718 }
719
720 if (lightcolor[i][1] > col) {
721 lcolor[i][1] = col;
722 }
723
724 if (lightcolor[i][2] > col) {
725 lcolor[i][2] = col;
726 }
727 }
728
729 if (wait > 180) {
730 if (col < 128.0f) {
731 col += 0.5f;
732 }
733 } else {
734 wait++;
735 }
736
737 MGSetPLight(light, lcolor);
738
739 sceVu0FVECTOR lead_ambient = {22.0f, 22.0f, 12.0f, 0.0f};
740
741 lead_ambient[3] = am;
742
743 if (am < 128.0f) {
744 am += 0.5f;
745 }
746
747 MGSetAmbient(lead_ambient);
748 } else {
749 am = 0.0f;
750 col = 0.0f;
751 wait = 0;
752 }
753
754 Chara__3[1].Draw();
755 }
756
757 MGSetAmbient(ambientlight);
758 MGSetPLight(light, lightcolor);
759
760 sceVu0FVECTOR crowd_ambient;
761
762 sceVu0CopyVector(crowd_ambient, ambientlight);
763
764 if (CScript__2.camera_start == 44) {
765 if (Cam__2[SceneNp__2].motion_type.state.time > 249.0f) {
766 DancerAmb -= 0.2f;
767
768 if (DancerAmb < 0.0f) {
769 DancerAmb = 0.0f;
770 }
771
772 crowd_ambient[3] = DancerAmb;
773 }
774 } else {
775 DancerAmb = 127.0f;
776 }
777
778 if (CScript__2.obj[6].disp && !Pause) {
779#ifdef PAL_TIMING
780 if (DanceWait < 2.0f || DanceWait > 490.0f) {
781#else
782 if (DanceWait < 2.0f || DanceWait > 480.0f) {
783#endif
784 Chara__3[6].Step();
785 Chara__3[7].Step();
786 }
787
788#ifdef PAL_TIMING
789 // Advanced by a fifth more per frame to keep the 60 Hz timing at 50 Hz.
790 DanceWait += 1.2f;
791#else
792 DanceWait += 1.0f;
793#endif
794
795 if (DanceWait > 10000) {
796 DanceWait = 10000;
797 }
798 }
799
800 if (CScript__2.obj[6].disp) {
801 TexManager.ReloadTexture(Vif1Packet, CharaTex__2[6]);
802 FaceChange(6);
803 MGSetAmbient(crowd_ambient);
804 Chara__3[6].Draw();
805 ReaderShadow();
806 }
807
808 if (CScript__2.obj[7].disp) {
809 TexManager.ReloadTexture(Vif1Packet, 6);
810 Chara__3[7].SetPosition(DancerPos[0][0], DancerPos[0][1], DancerPos[0][2]);
811 Chara__3[7].SetRotation(DancerRot[0][0], DancerRot[0][1], DancerRot[0][2]);
812 MGSetAmbient(crowd_ambient);
813 Chara__3[7].Draw();
814 DancerShadow();
815
816 int crowd_count;
817
818 switch (CScript__2.camera_start) {
819 case 0:
820 crowd_count = 28;
821 break;
822 case 3:
823 crowd_count = 30;
824 break;
825 case 7:
826 crowd_count = 30;
827 break;
828 case 8:
829 crowd_count = 30;
830 break;
831 case 9:
832 crowd_count = 25;
833 break;
834 case 10:
835 crowd_count = 15;
836 break;
837 case 39:
838 crowd_count = 30;
839 break;
840 case 43:
841 crowd_count = 30;
842 break;
843 case 45:
844 crowd_count = 14;
845 break;
846 default:
847 crowd_count = 35;
848 break;
849 }
850
851 for (int i = 1; i < crowd_count; i++) {
852 CFrame *frame = Chara__3[7].frame;
853
854 frame->SetPosition(DancerPos[i][0], DancerPos[i][1], DancerPos[i][2]);
855 frame->SetRotation(DancerRot[i][0], DancerRot[i][1], DancerRot[i][2]);
856 MGSetAmbient(crowd_ambient);
857 MGDraw(frame);
858 DancerShadow();
859 }
860 }
861
862 MGSetAmbient(ambientlight);
863
864 sceVu0FVECTOR eye;
865
866 TexManager.ReloadTexture(GetVif1Packet(), 0);
867 OP_CharaFrame__2 = Cam__2[SceneNp__2].frame;
868 sceVu0CopyVector(eye, OP_CharaFrame__2->position);
869
870 if (!Pause) {
871 CFire.FireStep();
872 }
873
874 CFire.FireCreate();
875
876 for (int i = 0; i < OP_FireList; i++) {
877 float z = OP_FirePosition[i][2];
878 float y = OP_FirePosition[i][1];
879 float x = OP_FirePosition[i][0];
880
881 CFire.pos[0] = 10.0f * x;
882 CFire.pos[1] = 10.0f * y;
883 CFire.pos[2] = 10.0f * z;
884 CFire.pos[3] = 1.0f;
885 CFire.DrawFire(1, 1, &OP_MainCamera, eye, OP_FireScale[i], 15, 15.0f);
886 }
887
888 DrawCloud();
889
890 static float cnt = 1024.0f;
891 static int sw = 0;
892
893 if (CScript__2.sprite == 1) {
894 TexManager.ReloadTexture(Vif1Packet, 7);
895
896 int alpha = (int) (128.0f - cnt / 4.0f);
897
898 if (alpha < 0) {
899 alpha = 0;
900 }
901
902 set2DSprite(GetVif1Packet(), TexManager.GetTexture("ex", -1), CRect<int>((int) (272.0f - cnt / 2.0f), (int) (10.0f - cnt / 2.0f), (int) (128.0f + cnt), (int) (128.0f + cnt)), CRect<int>(0, 0, 128, 128), (u_char) alpha);
903
904 if (sw == 0) {
905 cnt -= cnt / 2.0f;
906
907 if (cnt < 2.0f) {
908 sw = 1;
909 }
910 } else {
911 cnt += cnt / 2.0f;
912
913 if (cnt > 16.0f) {
914 sw = 0;
915 }
916 }
917 } else {
918 cnt = 1024.0f;
919 sw = 0;
920 }
921
922 TexManager.ReloadTexture(Vif1Packet, 22);
923
924 switch (CScript__2.camera_start) {
925 case 0:
926 case 43:
927 case 45:
928 case 47:
929 break;
930 case 3:
931 case 10:
932 case 24:
933 case 25: {
934 float dof[] = {50.0f};
935
936 DepthOfField(dof, 1, 56, 0);
937 } break;
938 default: {
939 float dof[2] = {200.0f, 400.0f};
940
941 /* These dead values preserve the following sky pass's argument-selection state. */
942 float draw_phase0 = 0.0f, draw_phase1 = 0.0f, draw_phase2 = 0.0f, draw_phase3 = 0.0f, draw_phase4 = 0.0f, draw_phase5 = 0.0f, draw_phase6 = 0.0f, draw_phase7 = 0.0f;
943 DepthOfField(dof, 2, 40, 0);
944 } break;
945 }
946}
947
958static void DrawCloud() {
959 static sceVu0FVECTOR ambient = {0.0f, 0.0f, 0.0f, 0.0f};
960 static float sc = 0.0f;
961
962 if (CScript__2.sprite == 2) {
963 CloudFlag = 1;
964 }
965
966 if (CloudFlag == 1) {
967 TexManager.ReloadTexture(Vif1Packet, 8);
968
969 if (!Pause) {
970 setCloudTexScroll();
971 }
972
973 Cloud.frame->SetScale(sc, sc, sc);
974
975 if (CScript__2.camera_start == 44 || CScript__2.camera_start == 16) {
976 Cloud.SetPosition(0.0f, 30.0f, -10.0f);
977 Cloud.SetRotation(0.0f, PI_D, 0.0f);
978 } else {
979 Cloud.SetPosition(0.0f, 50.0f, 15.0f);
980 Cloud.SetRotation(0.0f, 0.0f, 0.0f);
981 }
982
983 sceVu0FVECTOR saved_ambient;
984
985 MGGetAmbient(saved_ambient);
986 MGSetAmbient(ambient);
987 Cloud.Draw();
988 SmokeProcess();
989 MGSetAmbient(saved_ambient);
990
991 if (!Pause) {
992 if (sc < 1.0) {
993 sc = 0.005f + sc;
994 }
995
996 if (ambient[3] < 80.0f) {
997 ambient[3] += 1.0f;
998 }
999 }
1000 } else {
1001 sc = 0.0f;
1002 ambient[3] = 0.0f;
1003 }
1004}
1005
1016static void SmokeProcess() {
1017 static int cnt = 0;
1018
1019 cnt++;
1020
1021 if (cnt > 7) {
1022 cnt = 0;
1023 }
1024
1025 CEffectParam param;
1026
1027 param.Initialize();
1028
1029 if (cnt == 0) {
1030 sceVu0FVECTOR chimney_position = {0.0f, 80.0f, 22.0f, 1.0f};
1031 sceVu0FVECTOR alternate_position = {-30.0f, 100.0f, 30.0f, 1.0f};
1032
1033 if (CScript__2.camera_start != 19) {
1034 sceVu0CopyVector(param.position, chimney_position);
1035 } else {
1036 sceVu0CopyVector(param.position, alternate_position);
1037 }
1038
1040 param.position_oscillation_x = 0.5f * (float) rand() / 2147483648.0f;
1041 param.position_oscillation_rate_x = (float) PI_D / (20.0f + (float) (rand() * 10) / 2147483648.0f);
1042 param.opacity_mode = 2;
1043 param.render_flags = 2;
1044 param.opacity = 0.07f;
1045 param.velocity_y = 1.5f + 0.2f * (float) rand() / 2147483648.0f;
1046 param.scale_velocity_x = 0.04f;
1047 param.scale_velocity_y = 0.04f;
1048 param.lifetime = 120;
1049 param.texture = TexManager.GetTexture("cloud2", -1);
1050 param.texel = CRect<int>(0, 0, 128, 128);
1051 param.unk_08 = 30.0f;
1052 param.height = 13.0f;
1053 param.texture_frame_period = 60;
1054 Smoke.EnterEffect(&param);
1055 }
1056
1057 Smoke.Step(1);
1058 Smoke.Draw();
1059
1060 if (cnt == 0) {
1061 sceVu0FVECTOR second_position = {0.0f, 50.0f, -17.0f, 1.0f};
1062
1063 sceVu0CopyVector(param.position, second_position);
1064 Smoke.EnterEffect(&param);
1065 }
1066
1067 /* These dead values preserve the following motion pass's argument-selection state. */
1068 float motion_phase0 = 0.0f, motion_phase1 = 0.0f, motion_phase2 = 0.0f, motion_phase3 = 0.0f, motion_phase4 = 0.0f, motion_phase5 = 0.0f, motion_phase6 = 0.0f, motion_phase7 = 0.0f, motion_phase8 = 0.0f, motion_phase9 = 0.0f, motion_phase10 = 0.0f;
1069 Smoke.Draw();
1070}
1071
1072/* The tick's motion. The projection is re-set first because the camera passes through the scenery
1073 in some of the shots and the near plane has to move with it; the camera is then shaken by a
1074 random tenth of a unit on each axis for the shots that want it. After that every actor takes what
1075 the script last asked of it, and the ones the camera's own frame tree carries take their place
1076 from it instead. */
1077void OpA_MotionProcess() {
1078 switch (CScript__2.camera_start) {
1079 case 2:
1080 case 3:
1081 case 15:
1082 MGSetRenderInfo(mgRenderInfo.scale[0], 10.0f, 0xffff);
1083 break;
1084 case 37: {
1085 /* The scoped middle arms and folded constants preserve their shared materialisation order. */
1086 MGSetRenderInfo(mgRenderInfo.scale[0], (float) ((1 << 3) + 2), (0x10000 - 1));
1087 break;
1088 }
1089 case 0:
1090 case 39: {
1091 MGSetRenderInfo(mgRenderInfo.scale[0], 16.0f, 0xffff);
1092 break;
1093 }
1094 case 40:
1095 case 41:
1096 case 42:
1097 case 48: {
1098 MGSetRenderInfo(mgRenderInfo.scale[0], 18.0f, 0xffff);
1099 break;
1100 }
1101 default:
1102 MGSetRenderInfo(mgRenderInfo.scale[0], 6.0f, 0xffff);
1103 break;
1104 }
1105
1106 bool shake = false;
1107 static int d;
1108
1109 switch (CScript__2.camera_start) {
1110 case 15:
1111 shake = true;
1112 d = 3;
1113 break;
1114 case 14:
1115 case 16:
1116 case 17:
1117 shake = true;
1118 d = 10;
1119 break;
1120 case 18:
1121 if (Cam__2[SceneNp__2].motion_type.state.time < 56.0f) {
1122 shake = true;
1123 d = 15;
1124 }
1125
1126 break;
1127 case 44:
1128 if (CloudFlag == 1) {
1129 shake = true;
1130 d = 5;
1131 }
1132
1133 break;
1134 }
1135
1136 if (shake) {
1137 sceVu0FVECTOR reference;
1138
1139 OP_MainCamera.GetRef(reference);
1140 reference[0] += (float) (rand() % d) / 10.0f;
1141 reference[1] += (float) (rand() % d) / 10.0f;
1142 reference[2] += (float) (rand() % d) / 10.0f;
1143 OP_MainCamera.SetRef(reference);
1144 }
1145
1146 for (int i = 0; i < OP_AnimeSeqRot; i++) {
1147 ObjAnimePlay(&OP_AnimeSeq[i]);
1148 }
1149
1150 for (int i = 0; i < 6; i++) {
1151 if (CScript__2.obj[i].disp) {
1152 if (CScript__2.obj[i].motion_end != -1) {
1153 if (Chara__3[i].motion_type.state.time > (float) (Chara__3[i].motion_type.motion_info[CScript__2.obj[i].motion].end - 1)) {
1154 CScript__2.obj[i].motion = CScript__2.obj[i].motion_end;
1155 CScript__2.obj[i].motion_end = -1;
1156 }
1157 }
1158
1159 Chara__3[i].motion_type.state.blend_step = CScript__2.obj[i].step;
1160
1161 if (CScript__2.obj[i].step == 1.0f) {
1162 if (CScript__2.obj[i].motion != Chara__3[i].motion_no) {
1163 Chara__3[i].motion_type.state.time = (float) Chara__3[i].motion_type.motion_info[CScript__2.obj[i].motion].start;
1164 Chara__3[i].motion_no = CScript__2.obj[i].motion;
1165 Chara__3[i].motion_flags = 4;
1166 Chara__3[i].motion_speed = -1.0f;
1167 } else {
1168 Chara__3[i].motion_no = CScript__2.obj[i].motion;
1169 Chara__3[i].motion_flags = 0;
1170 Chara__3[i].motion_speed = -1.0f;
1171 }
1172 } else {
1173 Chara__3[i].motion_no = CScript__2.obj[i].motion;
1174 Chara__3[i].motion_flags = 0;
1175 Chara__3[i].motion_speed = -1.0f;
1176 }
1177 }
1178 }
1179
1180 if (CScript__2.obj[6].disp) {
1181 LoadMotionData();
1182 }
1183
1184 char *frame_names[23] = {"c07a", "c08a", "c11a", "c09a", "c08a", "c08c", "p19a", "p17a", 0, 0, 0, 0,
1185 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1186 sceVu0FMATRIX matrix;
1187
1188 for (int i = 0; i < 8; i++) {
1189 if (CScript__2.obj[i].disp && CScript__2.obj[i].move_req) {
1190 CFrame *frame = Cam__2[SceneNp__2].frame->SearchFrame(frame_names[i]);
1191
1192 if (frame) {
1193 frame->GetLWMatrix(matrix);
1194
1195 if (i == 6) {
1196 Chara__3[i].SetRotation(0.0f, (float) (atan2f(matrix[2][0], matrix[2][2]) + PI_D), 0.0f);
1197 } else if (i == 5) {
1198 float tilt = atan2f(-matrix[2][1], matrix[2][2]);
1199
1200 if (tilt > 3.14f) {
1201 tilt -= 6.28f;
1202 }
1203
1204 if (tilt < -3.14f) {
1205 tilt += 6.28f;
1206 }
1207
1208 Chara__3[i].SetRotation(tilt, atan2f(matrix[2][0], matrix[2][2]), 0.0f);
1209 } else {
1210 Chara__3[i].SetRotation(0.0f, atan2f(matrix[2][0], matrix[2][2]), 0.0f);
1211 }
1212
1213 if (i == 2 && CScript__2.camera_start == 36) {
1214 static float f;
1215
1216 if (Chara__3[i].motion_type.state.time > 345 && Chara__3[i].motion_type.state.time < 350.0f) {
1217 f = 1.5f;
1218 } else if (Chara__3[i].motion_type.state.time >= 350.0f) {
1219 if (f > 0.0f) {
1220 f -= 0.1f;
1221 }
1222 } else {
1223 f = 0.0f;
1224 }
1225
1226 float x = matrix[3][0];
1227 float y = matrix[3][1] - f;
1228 float z = matrix[3][2];
1229
1230 Chara__3[i].SetPosition(x, y, z);
1231 } else {
1232 float x = matrix[3][0];
1233 float y = matrix[3][1];
1234 float z = matrix[3][2];
1235
1236 Chara__3[i].SetPosition(x, y, z);
1237 }
1238 }
1239 }
1240 }
1241
1242 if (CScript__2.obj[6].disp) {
1243 MoveDancers();
1244 }
1245
1246 for (int i = 0; i < 23; i++) {
1247 if (CScript__2.obj[i].load != -1) {
1248 LoadCharaData(CScript__2.obj[i].load, i);
1249 }
1250 }
1251}
1252
1262static void MoveDancers() {
1263 char *frame_names[35] = {"p17a1", "p17a2", "p17a3", "p17a4", "p17a5", "p17a6", "p17a7", "p17a8",
1264 "p17a9", "p17a10", "p17a11", "p17a12", "p17a13", "p17a14", "p17a15",
1265 "p17a16", "p17a17", "p17a18", "p17a19", "p17a20", "p17a21", "p17a22",
1266 "p17a23", "p17a24", "p17a25", "p17a26", "p17a27", "p17a28", "p17a29",
1267 "p17a30", "p17a31", "p17a32", "p17a33", "p17a34", "p17a35"};
1268 sceVu0FMATRIX matrix;
1269
1270 if (CScript__2.obj[7].move_req) {
1271 for (int i = 0; i < 35; i++) {
1272 CFrame *frame = Cam__2[SceneNp__2].frame->SearchFrame(frame_names[i]);
1273
1274 if (frame) {
1275 frame->GetLWMatrix(matrix);
1276 DancerPos[i][0] = matrix[3][0];
1277 DancerPos[i][1] = matrix[3][1];
1278 DancerPos[i][2] = matrix[3][2];
1279 DancerRot[i][0] = 0.0f;
1280 DancerRot[i][1] = (float) (atan2f(matrix[2][0], matrix[2][2]) + PI_D);
1281 DancerRot[i][2] = 0.0f;
1282 }
1283 }
1284 }
1285}
1286
1296static void ReaderShadow() {
1297 sceVu0FMATRIX matrix;
1298
1299 TexManager.ReloadTexture(Vif1Packet, 6);
1300
1301 CFrame *frame = Chara__3[6].frame->SearchFrame("eff20");
1302
1303 if (frame) {
1304 frame->GetLWMatrix(matrix);
1305 DrawShadow(matrix[3][0], matrix[3][1], matrix[3][2]);
1306 }
1307
1308 frame = Chara__3[6].frame->SearchFrame("eff14");
1309
1310 if (frame) {
1311 frame->GetLWMatrix(matrix);
1312 DrawShadow(matrix[3][0], matrix[3][1], matrix[3][2]);
1313 }
1314}
1315
1324static void DancerShadow() {
1325 sceVu0FMATRIX matrix;
1326 float *z_address;
1327 float *y_address;
1328 float *x_address;
1329 float x;
1330 float y;
1331 float z;
1332
1333 // The addresses stay valid when the second lookup replaces the matrix, so only the values
1334 // need to be loaded again.
1335 Chara__3[7].frame->SearchFrame("r_foot")->GetLWMatrix(matrix);
1336 x_address = &matrix[3][0];
1337 x = *x_address;
1338 y_address = &matrix[3][1];
1339 y = *y_address;
1340 z_address = &matrix[3][2];
1341 z = *z_address;
1342 DrawShadow(x, y, z);
1343 Chara__3[7].frame->SearchFrame("l_foot")->GetLWMatrix(matrix);
1344 x = *x_address;
1345 y = *y_address;
1346 z = *z_address;
1347 DrawShadow(x, y, z);
1348}
1349
1358static void ShogunShadow() {
1359 sceVu0FMATRIX matrix;
1360 float *z_address;
1361 float *y_address;
1362 float *x_address;
1363 float x;
1364 float y;
1365 float z;
1366
1367 // Both effect frames write the same matrix storage, so the coordinate addresses are shared.
1368 TexManager.ReloadTexture(Vif1Packet, 6);
1369 Chara__3[3].frame->SearchFrame("eff66")->GetLWMatrix(matrix);
1370 x_address = &matrix[3][0];
1371 x = *x_address;
1372 y_address = &matrix[3][1];
1373 y = *y_address;
1374 z_address = &matrix[3][2];
1375 z = *z_address;
1376 DrawShadow(x, y, z);
1377 Chara__3[3].frame->SearchFrame("eff62")->GetLWMatrix(matrix);
1378 x = *x_address;
1379 y = *y_address;
1380 z = *z_address;
1381 DrawShadow(x, y, z);
1382}
1383
1392static void ShisaiShadow() {
1393 sceVu0FMATRIX matrix;
1394 float *z_address;
1395 float *y_address;
1396 float *x_address;
1397 float x;
1398 float y;
1399 float z;
1400
1401 // Both effect frames write the same matrix storage, so the coordinate addresses are shared.
1402 TexManager.ReloadTexture(Vif1Packet, 6);
1403 Chara__3[2].frame->SearchFrame("eff93")->GetLWMatrix(matrix);
1404 x_address = &matrix[3][0];
1405 x = *x_address;
1406 y_address = &matrix[3][1];
1407 y = *y_address;
1408 z_address = &matrix[3][2];
1409 z = *z_address;
1410 DrawShadow(x, y, z);
1411 Chara__3[2].frame->SearchFrame("eff99")->GetLWMatrix(matrix);
1412 x = *x_address;
1413 y = *y_address;
1414 z = *z_address;
1415 DrawShadow(x, y, z);
1416}
1417
1428static void DrawShadow(float x, float y, float z) {
1429 sceVu0FVECTOR ambient = {0.0f, 0.0f, 0.0f, 64.0f};
1430
1431 ambient[3] -= 10.0f * y;
1432
1433 if (ambient[3] > 0.0f) {
1434 if (ambient[3] > DancerAmb) {
1435 ambient[3] = DancerAmb;
1436 }
1437
1438 MGSetAmbient(ambient);
1439
1440 float heading = atan2f(x, z);
1441
1442 Shadow->SetPosition(x, 0.05f, z);
1443 Shadow->SetRotation(89.0f * PI_D / 180.0f, heading, 0.0f);
1444 MGDraw(Shadow);
1445 MGSetAmbient(ambientlight);
1446 }
1447}
1448
1449/* The tick's sound. The three footfalls are windows on an actor's own motion frame with a wait
1450 behind each, because a frame number is only inside its window for one tick at the motion's rate
1451 and the wait keeps a motion that stalls there from playing the step twice. The rest is the
1452 square's own ambience: the fountain from a fixed point, the wind while the sky is up, and the
1453 change of music the camera makes when it turns away. */
1454void OpA_SoundProcess() {
1455 /* These type-only names preserve the first footfall's argument-selection state. */
1456 typedef float SoundSetup0, SoundSetup1, SoundSetup2, SoundSetup3, SoundSetup4, SoundSetup5, SoundSetup6, SoundSetup7, SoundSetup8, SoundSetup9, SoundSetup10, SoundSetup11, SoundSetup12, SoundSetup13, SoundSetup14;
1457 static int mus = 0;
1458
1459 if (DanceWait > 5.0f) {
1460 if (mus == 0) {
1461 OpBgmSqPort = 0;
1462 OpBgmPlay();
1463 mus = 1;
1464 }
1465 } else {
1466 mus = 0;
1467 }
1468
1469 sceVu0FVECTOR camera_position;
1470 sceVu0FVECTOR shogun_position;
1471
1472 sceVu0CopyVector(shogun_position, Chara__3[3].pos);
1473 OP_MainCamera.GetPos(camera_position);
1474
1475 if (CScript__2.obj[3].motion == 1) {
1476 int motion_frame = (int) Chara__3[3].motion_type.state.time;
1477 static int wait = 0;
1478
1479 if (wait == 0) {
1480 if (motion_frame > 38 && motion_frame < 40) {
1481 OpPlayVolPanSE(shogun_position, 100.0f, 500.0f, MIDI_PORT_SE_DEFAULT, 21, 28);
1482 wait = 10;
1483 } else if (motion_frame > 48 && motion_frame < 50) {
1484 OpPlayVolPanSE(shogun_position, 100.0f, 500.0f, MIDI_PORT_SE_DEFAULT, 21, 29);
1485 wait = 10;
1486 }
1487 } else {
1488 wait--;
1489 }
1490 }
1491
1492 if (CScript__2.obj[3].motion == 4) {
1493 int motion_frame = (int) Chara__3[3].motion_type.state.time;
1494 static int wait = 0;
1495
1496 if (wait == 0) {
1497 if (motion_frame > 98 && motion_frame < 100) {
1498 OpPlayVolPanSE(shogun_position, 100.0f, 500.0f, MIDI_PORT_SE_DEFAULT, 21, 28);
1499 wait = 10;
1500 } else if (motion_frame > 108 && motion_frame < 110) {
1501 OpPlayVolPanSE(shogun_position, 100.0f, 500.0f, MIDI_PORT_SE_DEFAULT, 21, 29);
1502 wait = 10;
1503 }
1504 } else {
1505 wait--;
1506 }
1507 }
1508
1509 if (CScript__2.obj[3].motion == 10) {
1510 int motion_frame = (int) Chara__3[3].motion_type.state.time;
1511 static int wait = 0;
1512
1513 if (wait == 0) {
1514 if (motion_frame > 228 && motion_frame < 230) {
1515 OpPlayVolPanSE(shogun_position, 100.0f, 500.0f, MIDI_PORT_SE_DEFAULT, 21, 28);
1516 wait = 10;
1517 } else if (motion_frame > 238 && motion_frame < 240) {
1518 OpPlayVolPanSE(shogun_position, 100.0f, 500.0f, MIDI_PORT_SE_DEFAULT, 21, 29);
1519 wait = 10;
1520 }
1521 } else {
1522 wait--;
1523 }
1524 }
1525
1526 if (CScript__2.obj[2].motion == 14) {
1527 int motion_frame = (int) Chara__3[2].motion_type.state.time;
1528 static int wait = 0;
1529
1530 if (wait == 0) {
1531 if (motion_frame > 295 && motion_frame < 297) {
1532 OpPlayVolPanSE(shogun_position, 100.0f, 500.0f, MIDI_PORT_SE_DEFAULT, 21, 28);
1533 wait = 5;
1534 } else if (motion_frame > 298 && motion_frame < 300) {
1535 OpPlayVolPanSE(shogun_position, 100.0f, 500.0f, MIDI_PORT_SE_DEFAULT, 21, 29);
1536 wait = 5;
1537 } else if (motion_frame > 301 && motion_frame < 303) {
1538 OpPlayVolPanSE(shogun_position, 100.0f, 500.0f, MIDI_PORT_SE_DEFAULT, 21, 28);
1539 wait = 5;
1540 }
1541 } else {
1542 wait--;
1543 }
1544 }
1545
1546 sceVu0FVECTOR fountain = {0.0f, 0.0f, 0.0f, 0.0f};
1547
1548 OpSetVolPanSE(fountain, 200.0f, 500.0f, 15, 16, 20);
1549
1550 static int seflg = 0;
1551 static int secnt = 0;
1552 static float vol = 128.0f;
1553
1554 if (CloudFlag == 1) {
1555 if (seflg == 0) {
1556 OpPlayVolSE(MIDI_PORT_SE_TITLE, 16, 28, 0.8f);
1557 seflg = 1;
1558 } else if (CScript__2.camera_start != 44) {
1559 sceVu0FVECTOR wind = {0.0f, 50.0f, 0.0f, 0.0f};
1560
1561 OpSetVolPanSE(wind, 100.0f, 400.0f, 15, 16, 28);
1562 }
1563 } else {
1564 seflg = 0;
1565 secnt = 0;
1566 vol = 128.0f;
1567 }
1568
1569 {
1570 static int flg = 0;
1571
1572#ifdef PAL_TIMING
1573 if (CScript__2.camera_start == 44 && Cam__2[SceneNp__2].motion_type.state.time > 252.0) {
1574#else
1575 if (CScript__2.camera_start == 44 && Cam__2[SceneNp__2].motion_type.state.time > 249.0) {
1576#endif
1577 if (flg == 0) {
1578 while (ReadBGSync())
1579 ;
1580
1581 LoadFileBG("opdat/dungeon/o1bbgm.snd", (u_long128 *) read_buffer, 0);
1582 flg = 1;
1583 }
1584 } else {
1585 flg = 0;
1586 }
1587 }
1588
1589 {
1590 static int flg = 0;
1591
1592 if (CScript__2.camera_start == 14) {
1593 if (flg == 0) {
1594 CSnd.Stop(MIDI_PORT_BGM);
1595 CSnd.SetReverb(0, 4, 50);
1596 CSnd.LoadSoundFileFromPack("o01b.txt", read_buffer);
1597 OpBgmSqPort = 0;
1598 OpBgmPlay();
1599 flg = 1;
1600 }
1601 } else {
1602 flg = 0;
1603 }
1604 }
1605}
1606
1619static void setTexScroll() {
1620 static int setTexScrollCnt = 0;
1621 static float setTexScrollCntf = 0.0f;
1622
1623 sceGifTag giftag = {0, 1, 0, 0, 0, 0, 1, SCE_GIF_PACKED_AD};
1624 CTexture *plate;
1625 CTexture *strip;
1626 int dbp;
1627 int sbp;
1628 int dbw;
1629 int sbw;
1630
1631 sceVif1PkCnt(Vif1Packet, 0);
1632 sceVif1PkOpenDirectCode(Vif1Packet, 0);
1633 sceVif1PkOpenGifTag(Vif1Packet, *(u_long128 *) &giftag);
1634 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEXFLUSH, 0);
1635 sceVif1PkCloseGifTag(Vif1Packet);
1636 sceVif1PkCloseDirectCode(Vif1Packet);
1637 sceVif1PkTerminate(Vif1Packet);
1638
1639 if (setTexScrollCntf <= 0.0f) {
1640 setTexScrollCntf = 126.0f;
1641 } else {
1642 setTexScrollCntf -= 0.5f;
1643 }
1644
1645 setTexScrollCnt = (int) setTexScrollCntf;
1646
1647 plate = TexManager.GetTexture("i01t06", -1);
1648 strip = TexManager.GetTexture("i01t06a", -1);
1649
1650 if (plate == 0 || strip == 0) {
1651 return;
1652 }
1653
1654 dbp = plate->tex0 & 0x3fff;
1655 sbp = strip->tex0 & 0x3fff;
1656 dbw = (plate->tex0 >> 14) & 0x3f;
1657 sbw = (strip->tex0 >> 14) & 0x3f;
1658
1659 if (setTexScrollCnt != 128) {
1660 MoveImageTest(Vif1Packet, sbp, sbw, 0, CRect<int>(0, setTexScrollCnt, 128, 128 - setTexScrollCnt), dbp, dbw, 0, 0, 0, 0);
1661 }
1662
1663 if (setTexScrollCnt != 0) {
1664 MoveImageTest(Vif1Packet, sbp, sbw, 0, CRect<int>(0, 0, 128, setTexScrollCnt), dbp, dbw, 0, 0, 128 - setTexScrollCnt, 0);
1665 }
1666}
1667
1676static void setCloudTexScroll() {
1677 static int setTexScrollCnt = 0;
1678 static float setTexScrollCntf = 0.0f;
1679
1680 sceGifTag giftag = {0, 1, 0, 0, 0, 0, 1, SCE_GIF_PACKED_AD};
1681 CTexture *plate;
1682 CTexture *strip;
1683 int dbp;
1684 int sbp;
1685 int dbw;
1686 int sbw;
1687
1688 sceVif1PkCnt(Vif1Packet, 0);
1689 sceVif1PkOpenDirectCode(Vif1Packet, 0);
1690 sceVif1PkOpenGifTag(Vif1Packet, *(u_long128 *) &giftag);
1691 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEXFLUSH, 0);
1692 sceVif1PkCloseGifTag(Vif1Packet);
1693 sceVif1PkCloseDirectCode(Vif1Packet);
1694 sceVif1PkTerminate(Vif1Packet);
1695
1696 if (setTexScrollCntf <= 0.0f) {
1697 setTexScrollCntf = 126.0f;
1698 } else {
1699 setTexScrollCntf -= 0.5f;
1700 }
1701
1702 setTexScrollCnt = (int) setTexScrollCntf;
1703
1704 plate = TexManager.GetTexture("cloud", -1);
1705 strip = TexManager.GetTexture("cloudan", -1);
1706
1707 if (plate == 0 || strip == 0) {
1708 return;
1709 }
1710
1711 dbp = plate->tex0 & 0x3fff;
1712 sbp = strip->tex0 & 0x3fff;
1713 dbw = (plate->tex0 >> 14) & 0x3f;
1714 sbw = (strip->tex0 >> 14) & 0x3f;
1715
1716 if (setTexScrollCnt != 128) {
1717 MoveImageTest(Vif1Packet, sbp, sbw, 0, CRect<int>(0, setTexScrollCnt, 128, 128 - setTexScrollCnt), dbp, dbw, 0, 0, 0, 0);
1718 }
1719
1720 if (setTexScrollCnt != 0) {
1721 MoveImageTest(Vif1Packet, sbp, sbw, 0, CRect<int>(0, 0, 128, setTexScrollCnt), dbp, dbw, 0, 0, 128 - setTexScrollCnt, 0);
1722 }
1723}
void GetRef(float *ref)
Definition camera.cpp:234
void SetRef(CFrame *parent, float x, float y, float z)
Definition camera.cpp:124
void GetPos(float *pos)
Definition camera.cpp:230
CFrame * frame
virtual void LoadPackData(unsigned int *pack, char *name, CDataAlloc2< 1 > *model_alloc, CDataAlloc2< 1 > *texture_alloc)
virtual void Step()
tagMOTION_TYPE motion_type
virtual void SetRotation(float x, float y, float z)
virtual void Initialize()
float motion_speed
virtual void Draw()
virtual void SetPosition(float x, float y, float z)
CEffect * effect_table
Definition op_a.cpp:128
int capacity
Definition op_a.cpp:129
sceVu0FVECTOR position
Definition op_a.cpp:149
float position_oscillation_rate_x
Definition op_a.cpp:155
float scale_velocity_x
Definition op_a.cpp:157
float scale_velocity_y
Definition op_a.cpp:158
int position_oscillation_flags
Definition op_a.cpp:145
float height
Definition op_a.cpp:147
CRect< int > texel
Definition op_a.cpp:164
float velocity_y
Definition op_a.cpp:151
float unk_08
Definition op_a.cpp:146
int render_flags
Definition op_a.cpp:161
float position_oscillation_x
Definition op_a.cpp:153
float opacity
Definition op_a.cpp:162
int texture_frame_period
Definition op_a.cpp:166
int opacity_mode
Definition op_a.cpp:160
int lifetime
Definition op_a.cpp:144
CTexture * texture
Definition op_a.cpp:163
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
char clip_enable
Definition frame.hpp:29
sceVu0FVECTOR position
Definition frame.hpp:76
Definition op_a.cpp:90
CategoryAttr category[16]
Definition op_a.cpp:92
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
int sprite
Definition script.hpp:141
int camera_start
Definition script.hpp:135
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 SetVol(int port, int volume)
Definition sound.cpp:983
void Stop(int port)
Definition sound.cpp:978
void SetReverb(int core, int mode, int depth)
Definition sound.cpp:74
u_long tex0
Definition texture.hpp:57
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 blend_step
Definition gameutil.hpp:190
sceVu0FVECTOR scale
float step
Definition script.hpp:125
int motion_end
Definition script.hpp:113
MOTION_INFO * motion_info
Definition gameutil.hpp:275
MOTION_STATE state
Definition gameutil.hpp:273