DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
ebattle.cpp
1#include "common.h"
2
3#include <libvu0.h>
4
5#include <cmath>
6#include <cstdlib>
7
8#include "camerafollow.hpp"
9#include "character.hpp"
10#include "clsmes.hpp"
11#include "dataalloc.hpp"
12#include "dataread.hpp"
13#include "ebattle.hpp"
14#include "edit.hpp"
15#include "editground.hpp"
16#include "editloop.hpp"
17#include "editloop3.hpp"
18#include "effectgroup.hpp"
19#include "effectmacro.hpp"
20#include "fish.hpp"
21#include "fishing.hpp"
22#include "gamepad.hpp"
23#include "mainselect.hpp"
24#include "mapparts.hpp"
25#include "mathutil.hpp"
26#include "menu_save.hpp"
27#include "mglib.hpp"
28#include "npcharacter.hpp"
29#include "rect.hpp"
30#include "savedata.hpp"
31#include "shop.hpp"
32#include "snd.hpp"
33#include "sysmes.hpp"
34#include "texture.hpp"
35
36#pragma helper_mask_gpr 0x30
37#pragma helper_mask_fpr 0x1000
38#pragma name_counter 517
39
43struct EB_KEY {
44 int frame;
45 int buttons;
46 int mode;
47 int pressed;
48 int hit;
49 int passed;
51};
52
53STATIC_ASSERT(sizeof(EB_KEY) == 0x1C);
54
58struct EB_MOTION {
60 float start;
61 float end;
62 float speed;
63 int frames;
64};
65
66STATIC_ASSERT(sizeof(EB_MOTION) == 0x14);
67
71class CEbRect {
72public:
73 s32 x;
74 s32 y;
75 s32 width;
76 s32 height;
78 CEbRect() {
79 height = 0;
80 width = 0;
81 y = 0;
82 x = 0;
83 }
84} __attribute__((aligned(16)));
85
86#ifdef PAL
90class CEbSpriteRect : public CRect_i_ {
91public:
92 CEbSpriteRect();
93};
94#endif
95
97CEbRect draw_rect_store;
98
99#ifdef PAL
100CRect_i_ Caution(256, 0, 56, 56);
101#else
102const CRect_i_ Caution(256, 0, 56, 56);
103#endif
104
105#ifdef PAL
107CEbSpriteRect CautionRect[7];
109CEbSpriteRect EbResult0[7];
111CEbSpriteRect EbResult2[7];
113CEbSpriteRect EbResult1[7];
115CEbSpriteRect OkRect[7];
117CEbSpriteRect CoolRect[7];
118#endif
119
121EB_KEY eb_key[64];
122
124EB_MOTION eb_motion[32] = {{-1}};
125
127int eb_cool_flag = 1;
129float old_time = -1.0f;
131float speed = 1.0f;
133int now_eb_key = -1;
134
136int ebattle_flag;
138int ebattle_intro_flag;
140int eb_count;
142int eb_intro_cnt;
144int eb_finish_cnt;
146int eb_end_count;
148int eb_result;
150int eb_key_count;
152int now_button_no;
154CCharacter *eb_chara;
156int fade_bgm;
158int play_fanfare;
160float now_time;
162int sound_cnt;
164int debug_mode;
166CTexture *tex;
168CTexture *tex2;
170int eb_key_num;
172int ok_draw_cnt;
174int ok_type;
176int ok_effect_button;
178int viewMode;
180int chara_mode;
182int chara_fishing;
184int fishing_mes;
186float viewAngleH;
188float viewAngleV;
189
190ED_MOVE_CHARA_INFO EdMoveCharaInfo;
191
197 float start;
198 float end;
199 float speed;
200 int frames;
201};
202
207 int frame;
209 int mode;
211 int hit;
212 int passed;
214};
215
216static void init_draw_ok();
217static void set_draw_ok(int type, int button);
218void draw_ok_loop();
219void DrawButton(int buttons, int x, int y, float scale, int early);
220static void DrawButtonSub(int x, int y, int texture_x, int texture_y, float scale);
221static void draw_ok(int x);
222static float button_scale(int button);
223
224/* @ 0x168100 (0x10 bytes) -- EBInitialize__Fv */
225#ifdef PAL
226void EBInitialize() {
227 ebattle_flag = 0;
228
229 // Each prompt's sprite set holds one texture rectangle per language.
230 CautionRect[0].x = 256;
231 CautionRect[0].y = 0;
232 CautionRect[0].width = 56;
233 CautionRect[0].height = 56;
234 CautionRect[1].x = 256;
235 CautionRect[1].y = 0;
236 CautionRect[1].width = 56;
237 CautionRect[1].height = 56;
238 CautionRect[2].x = 256;
239 CautionRect[2].y = 0;
240 CautionRect[2].width = 56;
241 CautionRect[2].height = 56;
242 CautionRect[3].x = 256;
243 CautionRect[3].y = 0;
244 CautionRect[3].width = 56;
245 CautionRect[3].height = 56;
246 CautionRect[4].x = 256;
247 CautionRect[4].y = 0;
248 CautionRect[4].width = 56;
249 CautionRect[4].height = 56;
250 CautionRect[5].x = 215;
251 CautionRect[5].y = 0;
252 CautionRect[5].width = 56;
253 CautionRect[5].height = 56;
254 CautionRect[6].x = 256;
255 CautionRect[6].y = 0;
256 CautionRect[6].width = 56;
257 CautionRect[6].height = 56;
258
259 EbResult2[0].x = 0;
260 EbResult2[0].y = 0;
261 EbResult2[0].width = 256;
262 EbResult2[0].height = 70;
263 EbResult2[1].x = 0;
264 EbResult2[1].y = 0;
265 EbResult2[1].width = 256;
266 EbResult2[1].height = 70;
267 EbResult2[2].x = 0;
268 EbResult2[2].y = 0;
269 EbResult2[2].width = 256;
270 EbResult2[2].height = 70;
271 EbResult2[3].x = 0;
272 EbResult2[3].y = 0;
273 EbResult2[3].width = 256;
274 EbResult2[3].height = 70;
275 EbResult2[4].x = 0;
276 EbResult2[4].y = 0;
277 EbResult2[4].width = 256;
278 EbResult2[4].height = 70;
279 EbResult2[5].x = 0;
280 EbResult2[5].y = 0;
281 EbResult2[5].width = 214;
282 EbResult2[5].height = 70;
283 EbResult2[6].x = 0;
284 EbResult2[6].y = 0;
285 EbResult2[6].width = 256;
286 EbResult2[6].height = 70;
287
288 EbResult0[0].x = 0;
289 EbResult0[0].y = 80;
290 EbResult0[0].width = 146;
291 EbResult0[0].height = 60;
292 EbResult0[1].x = 0;
293 EbResult0[1].y = 80;
294 EbResult0[1].width = 146;
295 EbResult0[1].height = 60;
296 EbResult0[2].x = 0;
297 EbResult0[2].y = 80;
298 EbResult0[2].width = 146;
299 EbResult0[2].height = 60;
300 EbResult0[3].x = 0;
301 EbResult0[3].y = 70;
302 EbResult0[3].width = 140;
303 EbResult0[3].height = 70;
304 EbResult0[4].x = 0;
305 EbResult0[4].y = 70;
306 EbResult0[4].width = 172;
307 EbResult0[4].height = 70;
308 EbResult0[5].x = 0;
309 EbResult0[5].y = 70;
310 EbResult0[5].width = 274;
311 EbResult0[5].height = 70;
312 EbResult0[6].x = 0;
313 EbResult0[6].y = 70;
314 EbResult0[6].width = 182;
315 EbResult0[6].height = 70;
316
317 EbResult1[0].x = 0;
318 EbResult1[0].y = 146;
319 EbResult1[0].width = 184;
320 EbResult1[0].height = 64;
321 EbResult1[1].x = 0;
322 EbResult1[1].y = 146;
323 EbResult1[1].width = 184;
324 EbResult1[1].height = 64;
325 EbResult1[2].x = 0;
326 EbResult1[2].y = 146;
327 EbResult1[2].width = 184;
328 EbResult1[2].height = 64;
329 EbResult1[3].x = 0;
330 EbResult1[3].y = 140;
331 EbResult1[3].width = 180;
332 EbResult1[3].height = 70;
333 EbResult1[4].x = 0;
334 EbResult1[4].y = 140;
335 EbResult1[4].width = 168;
336 EbResult1[4].height = 70;
337 EbResult1[5].x = 0;
338 EbResult1[5].y = 140;
339 EbResult1[5].width = 298;
340 EbResult1[5].height = 70;
341 EbResult1[6].x = 0;
342 EbResult1[6].y = 140;
343 EbResult1[6].width = 230;
344 EbResult1[6].height = 70;
345
346 OkRect[0].x = 0;
347 OkRect[0].y = 208;
348 OkRect[0].width = 26;
349 OkRect[0].height = 16;
350 OkRect[1].x = 0;
351 OkRect[1].y = 208;
352 OkRect[1].width = 26;
353 OkRect[1].height = 16;
354 OkRect[2].x = 0;
355 OkRect[2].y = 208;
356 OkRect[2].width = 26;
357 OkRect[2].height = 16;
358 OkRect[3].x = 0;
359 OkRect[3].y = 208;
360 OkRect[3].width = 26;
361 OkRect[3].height = 16;
362 OkRect[4].x = 0;
363 OkRect[4].y = 208;
364 OkRect[4].width = 26;
365 OkRect[4].height = 16;
366 OkRect[5].x = 0;
367 OkRect[5].y = 208;
368 OkRect[5].width = 32;
369 OkRect[5].height = 20;
370 OkRect[6].x = 0;
371 OkRect[6].y = 208;
372 OkRect[6].width = 42;
373 OkRect[6].height = 16;
374
375 CoolRect[0].x = 0;
376 CoolRect[0].y = 224;
377 CoolRect[0].width = 50;
378 CoolRect[0].height = 16;
379 CoolRect[1].x = 0;
380 CoolRect[1].y = 224;
381 CoolRect[1].width = 50;
382 CoolRect[1].height = 16;
383 CoolRect[2].x = 0;
384 CoolRect[2].y = 224;
385 CoolRect[2].width = 50;
386 CoolRect[2].height = 16;
387 CoolRect[3].x = 0;
388 CoolRect[3].y = 224;
389 CoolRect[3].width = 50;
390 CoolRect[3].height = 16;
391 CoolRect[4].x = 0;
392 CoolRect[4].y = 224;
393 CoolRect[4].width = 50;
394 CoolRect[4].height = 16;
395 CoolRect[5].x = 0;
396 CoolRect[5].y = 230;
397 CoolRect[5].width = 60;
398 CoolRect[5].height = 20;
399 CoolRect[6].x = 0;
400 CoolRect[6].y = 224;
401 CoolRect[6].width = 62;
402 CoolRect[6].height = 16;
403}
404
405#pragma name_counter 518
406#else
407void EBInitialize() {
408 ebattle_flag = 0;
409}
410#endif
411
412/* @ 0x168110 (0xE0 bytes) -- EBInit__Ff */
413void EBInit(float speed_mult) {
414 tex = TexManager.GetTexture("ebat", -1);
415
416 if (tex) {
417 tex2 = TexManager.GetTexture("ebat2", -1);
418
419 if (tex2) {
420 eb_count = 0;
421 old_time = -1.0;
422 eb_key_num = 0;
423 speed = 4.0f * speed_mult;
424 eb_end_count = 0;
425 now_eb_key = -1;
426 sound_cnt = 0;
427 debug_mode = 0;
428 eb_motion[0].motion_no = -1;
429 eb_key_count = 0;
430 eb_finish_cnt = 0;
431 now_button_no = 0;
432 init_draw_ok();
433 fade_bgm = 1;
434 play_fanfare = 1;
435 }
436 }
437}
438
439/* @ 0x1681F0 (0x10 bytes) -- EBFinishSound__Fii */
440void EBFinishSound(int do_fade_bgm, int do_play_fanfare) {
441 fade_bgm = do_fade_bgm;
442 play_fanfare = do_play_fanfare;
443}
444
452void EBInitIntro() {
453 tex = TexManager.GetTexture("ebat", -1);
454
455 if (tex == NULL) {
456 return;
457 }
458
459 tex2 = TexManager.GetTexture("ebat2", -1);
460
461 if (tex2 == NULL) {
462 return;
463 }
464
465 eb_intro_cnt = 0;
466 ebattle_intro_flag = 1;
467 // The wipe opens from the right edge, so it starts with no width.
468 draw_rect = CRect_i_(0x280, 0, 0, 0x1C0);
469}
470
471void EBSetMotion(CCharacter *character, int *motions) {
472 if (character == NULL) {
473 return;
474 }
475
476 int i;
477
478 for (i = 0;; i++) {
479 int motion_no = motions[i];
480
481 if (motion_no < 0) {
482 break;
483 }
484
485 eb_motion[i].motion_no = motion_no;
486 }
487
488 eb_motion[i].motion_no = -1;
489
490 eb_chara = character;
491
492 for (i = 0;; i++) {
493 if (eb_motion[i].motion_no < 0) {
494 break;
495 }
496
497 MOTION_INFO *info = eb_chara->GetMotionInfo(eb_motion[i].motion_no);
498
499 if (info == NULL) {
500 return;
501 }
502
503 float start = (float) info->start;
504 float end = (float) info->end;
505 eb_motion[i].start = start;
506 eb_motion[i].end = end;
507 eb_motion[i].speed = info->speed;
508 int frames = (int) ((end - start) / info->speed);
509 eb_end_count += frames;
510 eb_motion[i].frames = frames;
511 }
512
513 ebattle_flag = 1;
514 eb_cool_flag = 1;
515 GamePad.MenuModeOn(0x50);
516}
517
518void EBDebug(int mode) {
519 debug_mode = mode;
520}
521
522void EBSetKey(float time, int buttons, int mode) {
523 if (eb_key_num < 64) {
524 EB_KEY_ENTRY *key = (EB_KEY_ENTRY *) &eb_key[eb_key_num++];
525 key->frame = 0;
526
527 for (int i = 0;; i++) {
528 EB_MOTION *motion = &eb_motion[i];
529
530 if (motion->motion_no < 0) {
531 break;
532 }
533
534 if (time >= motion->start && time < motion->end) {
535 key->frame += (time - motion->start) / motion->speed;
536 break;
537 }
538
539 key->frame += motion->frames;
540 }
541
542 key->buttons = buttons;
543 key->pressed = 0;
544
545 if (mode > 5) {
546 mode = 5;
547 }
548
549 key->mode = mode;
550 key->passed = false;
551 key->hit = 0;
552 key->highlight = false;
553 }
554}
555
556void EBExit() {
557 ebattle_flag = 0;
558 eb_intro_cnt = 0;
559 GamePad.MenuModeOff();
560 ebattle_intro_flag = 0;
561 eb_finish_cnt = 0;
562 init_draw_ok();
563
564 do {
565 } while (SndSPSeSyncBG() != 0);
566
567 InitReadBG();
568}
569
577int EBIntroLoop() {
578 int width;
579
580 if (ebattle_intro_flag == 0) {
581 return 1;
582 }
583
584 // The wipe crosses the screen over a hundred frames.
585 width = eb_intro_cnt * 640 / 100;
586
587 if (width > 640) {
588 width = 640;
589 }
590
591 draw_rect.x = 640 - width;
592 draw_rect.width = width;
593 eb_intro_cnt++;
594
595 if (eb_intro_cnt > 100) {
596 draw_rect = CRect_i_(0, 0, 640, 448);
597 return 1;
598 }
599
600 return 0;
601}
602
610int EBLoop() {
611 if (ebattle_flag == 0) {
612 return 1;
613 }
614
615 if (eb_finish_cnt > 0) {
616 if (eb_finish_cnt == 1) {
617 EBExit();
618 return eb_result;
619 }
620
621 eb_finish_cnt--;
622 return 0;
623 }
624
625 if (eb_count == 0 && play_fanfare != 0) {
626 int loaded_size;
627 StartReadBG();
628 SndSPSeLoadBG(0x2F, read_buffer, &loaded_size);
629 }
630
631 ReadBG();
632
633 int i;
634 float frame_speed = speed;
635 EB_KEY *active = NULL;
636 int cool = 0;
637
638 for (i = 0; i < eb_key_num; i++) {
639 EB_KEY *key = &eb_key[i];
640 float distance = eb_count - key->frame;
641 distance *= frame_speed;
642 int early = 0;
643
644 if (key->mode > 0) {
645 early = (6 - key->mode) << 6;
646 }
647
648 key->highlight = false;
649
650 if (distance > 0.0f) {
651 if (distance < 48.0f) {
652 active = key;
653 } else {
654 key->passed = true;
655 }
656
657 if (distance < 24.0f) {
658 cool = 1;
659 }
660 } else {
661 if (distance > -16.0f) {
662 active = key;
663 }
664
665 if (early > 0 && distance <= 16.0f - early) {
666 key->highlight = true;
667 }
668 }
669
670 if (debug_mode != 0 && eb_count == key->frame) {
671 SndSePlay(SE_EB_HIT, -1, 0);
672 SndSePlay(MENU_SOUND_CONFIRM, -1, 0);
673 }
674 }
675
676 int failed = 0;
677
678 if (active != NULL) {
679 active->pressed |= GamePad.GetPadDown();
680
681 if (active->pressed == active->buttons) {
682 if (active->hit == 0) {
683 if (cool) {
684 SndSePlay(SE_EB_HIT_COOL, -1, 0);
685 } else {
686 SndSePlay(SE_EB_HIT, -1, 0);
687 }
688
689 set_draw_ok(cool, active - eb_key);
690 eb_cool_flag &= cool;
691 eb_key_count++;
692 }
693
694 active->hit = 1;
695 }
696
697 if (active->buttons != (active->buttons | active->pressed)) {
698 failed = 1;
699 }
700 } else if (GamePad.GetPadDown()) {
701 failed = 1;
702 }
703
704 for (i = 0; i < eb_key_num; i++) {
705 EB_KEY *key = &eb_key[i];
706
707 if (key->passed == 0) {
708 break;
709 }
710
711 if (key->buttons != key->pressed) {
712 failed = 1;
713 }
714 }
715
716 if (failed && debug_mode == 0 && eb_key_count < eb_key_num && EdDebugParamDrawOff == 0) {
717 SndBgmFadeOut(40, 0);
718 eb_finish_cnt = 80;
719 eb_result = -1;
720 eb_count++;
721 return 0;
722 }
723
724 if (eb_count == eb_end_count - 100 && fade_bgm != 0) {
725 SndBgmFadeOut(100, 0);
726 }
727
728 if (eb_count >= eb_end_count) {
729 if (play_fanfare != 0) {
730 while (SndSPSeSyncBG() != 0) {
731 }
732
733 SndSPSePlay(0x2F, -1);
734 }
735
736 eb_finish_cnt = 160;
737 eb_result = (eb_cool_flag != 0) + 1;
738 return 0;
739 }
740
741 old_time = now_time;
742 draw_ok_loop();
743 eb_count++;
744 return 0;
745}
746
754void EBDraw() {
755 if (ebattle_intro_flag == 0 && ebattle_flag == 0) {
756 return;
757 }
758
759 setbilinear(0);
760
761#ifdef PAL
762 int lang = LanguageCode;
763
764 if (lang < LANG_JAPANESE || lang >= LANG_COUNT) {
765 lang = LANG_ENGLISH_US;
766 }
767
768#endif
769 if (EdDebugParamDrawOff != 0) {
770 return;
771 }
772
773 if (eb_finish_cnt > 0) {
774 TexManager.ReloadTexture(GetVif1Packet(), 0x2D);
775 CRect_i_ texel;
776 texel.x = texel.y = texel.width = texel.height = 0;
777
778#ifdef PAL
779 if (eb_result < 0) {
780 texel = EbResult0[lang];
781 }
782
783 if (eb_result == 2) {
784 texel = EbResult2[lang];
785 }
786
787 if (eb_result == 1) {
788 texel = EbResult1[lang];
789 }
790
791#else
792 if (eb_result < 0) {
793 texel = CRect_i_(0, 0x50, 0x92, 0x3C);
794 }
795
796 if (eb_result == 2) {
797 texel = CRect_i_(0, 0, 0x100, 0x46);
798 }
799
800 if (eb_result == 1) {
801 texel = CRect_i_(0, 0x92, 0xB8, 0x40);
802 }
803
804#endif
805 int left = 0x140 - (texel.width >> 1);
806 int top = SCREEN_HALF_HEIGHT - (texel.height >> 1);
807
808 if (eb_result > 0 || (eb_finish_cnt >> 2) % 2 != 0) {
809 set2DSprite(GetVif1Packet(), tex2, CRect_i_(left, top, texel.width, texel.height), texel.x, texel.y);
810 }
811
812 return;
813 }
814
815 CRect_i_ bar(0, 0xA00, 0x2800, 0x100);
816 CRect_i_ left_edge(0xA80, 0xA00, 0x400, 0x100);
817 CRect_i_ right_edge(0xC00, 0xA00, 0x100, 0x100);
818
819 if (ebattle_intro_flag != 0) {
820#ifdef PAL
821 int caution_lang = LanguageCode;
822
823 if (caution_lang < 0 || caution_lang >= 7) {
824 caution_lang = 0;
825 }
826
827 Caution = CautionRect[caution_lang];
828#endif
829 TexManager.ReloadTexture(GetVif1Packet(), 0x2D);
830 int shift = draw_rect.x << 4;
831 bar.x += shift;
832 left_edge.x += shift;
833 right_edge.x += shift;
834 MGFillBox(bar, 0, 0x28, 0xA0, 0x40);
835 MGFillBox(left_edge, 0xFF, 0xFF, 0xFF, 0x20);
836 MGFillBox(right_edge, 0xFF, 0xFF, 0xFF, 0x20);
837
838 if ((eb_intro_cnt >> 2) % 2 != 0) {
839 int left = 0x140 - (Caution.width >> 1);
840 int top = SCREEN_HALF_HEIGHT - (Caution.height >> 1);
841 set2DSprite(GetVif1Packet(), tex2, CRect_i_(left, top, Caution.width, Caution.height), Caution.x, Caution.y);
842 }
843
844 if (eb_intro_cnt % 8 == 0) {
845 SndSePlay(SE_EB_INTRO_TICK, -1, 0);
846 }
847
848 return;
849 }
850
851 if (ebattle_flag == 0) {
852 return;
853 }
854
855 TexManager.ReloadTexture(GetVif1Packet(), 0x2D);
856 MGFillBox(bar, 0, 0x28, 0xA0, 0x40);
857 MGFillBox(left_edge, 0xFF, 0xFF, 0xFF, 0x20);
858 MGFillBox(right_edge, 0xFF, 0xFF, 0xFF, 0x20);
859 eb_chara->GetMotionInfo(eb_chara->motion_no);
860
861 float frame_speed = speed;
862
863 for (int i = eb_key_count; i < eb_key_num; i++) {
864 EB_KEY *key = &eb_key[i];
865 float delta = eb_count - key->frame;
866 delta *= frame_speed;
867 float position = 200.0f - delta;
868 int x = position;
869 DrawButton(key->buttons, x, 0x140, button_scale(i), key->highlight);
870 }
871
872 if (eb_key_count > 0) {
873 EB_KEY *key = &eb_key[eb_key_count - 1];
874 float delta = eb_count - key->frame;
875 delta *= frame_speed;
876 float position = 200.0f - delta;
877 int x = position;
878 draw_ok(x);
879 }
880}
881
889void DrawButton(int buttons, int x, int y, float scale, int early) {
890 if (x < -0x20) {
891 return;
892 }
893
894 if (x > 0x280) {
895 return;
896 }
897
898 if (early != 0) {
899 DrawButtonSub(x, y, 0, 0x60, scale);
900 } else if ((buttons & 0x20) != 0) {
901 DrawButtonSub(x, y, 0, 0, scale);
902 } else if ((buttons & 0x10) != 0) {
903 DrawButtonSub(x, y, 0x20, 0, scale);
904 } else if ((buttons & 0x80) != 0) {
905 DrawButtonSub(x, y, 0x40, 0, scale);
906 } else if ((buttons & 0x40) != 0) {
907 DrawButtonSub(x, y, 0x60, 0, scale);
908 } else if ((buttons & 0x1000) != 0) {
909 if ((buttons & 0x8000) != 0) {
910 DrawButtonSub(x, y, 0x20, 0x40, scale);
911 } else if ((buttons & 0x2000) != 0) {
912 DrawButtonSub(x, y, 0, 0x40, scale);
913 } else {
914 DrawButtonSub(x, y, 0, 0x20, scale);
915 }
916 } else if ((buttons & 0x8000) != 0) {
917 DrawButtonSub(x, y, 0x60, 0x20, scale);
918 } else if ((buttons & 0x2000) != 0) {
919 DrawButtonSub(x, y, 0x40, 0x20, scale);
920 } else if ((buttons & 0x4000) != 0) {
921 if ((buttons & 0x8000) != 0) {
922 DrawButtonSub(x, y, 0x60, 0x40, scale);
923 } else if ((buttons & 0x2000) != 0) {
924 DrawButtonSub(x, y, 0x40, 0x40, scale);
925 } else {
926 DrawButtonSub(x, y, 0x20, 0x20, scale);
927 return;
928 }
929 }
930}
931
939static void DrawButtonSub(int x, int y, int texture_x, int texture_y, float scale) {
940 int width = 32.0f * scale;
941 int height = 32.0f * scale;
942 CRect_i_ screen;
943 CRect_i_ texel;
944
945 // The prompt grows about its own centre.
946 x -= (width - 32) >> 1;
947 y -= (height - 32) >> 1;
948 texel.x = texture_x;
949 texel.y = texture_y;
950 texel.width = 32;
951 texel.height = 32;
952 screen.x = x;
953 screen.y = y;
954 screen.width = width;
955 screen.height = height;
956 set2DSprite(GetVif1Packet(), tex, screen, texel);
957}
958
966static void init_draw_ok() {
967 ok_draw_cnt = 0;
968 ok_effect_button = -1;
969}
970
978static void set_draw_ok(int type, int button) {
979 ok_effect_button = button;
980 ok_draw_cnt = 30;
981 ok_type = type;
982}
983
991void draw_ok_loop() {
992 if (ok_draw_cnt > 0) {
993 --ok_draw_cnt;
994
995 if (ok_draw_cnt < 0) {
996 ok_draw_cnt = 0;
997 }
998 }
999}
1000
1008static void draw_ok(int x) {
1009 // clang-format off
1010 static sceVu0FVECTOR dir[8] = {
1011 {1.0f, 0.0f, 0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f, 0.0f},
1012 {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f, 0.0f},
1013 {1.0f, 1.0f, 0.0f, 0.0f}, {1.0f, -1.0f, 0.0f, 0.0f},
1014 {-1.0f, 1.0f, 0.0f, 0.0f}, {-1.0f, -1.0f, 0.0f, 0.0f},
1015 };
1016 // clang-format on
1017
1018 if (ok_draw_cnt <= 0) {
1019 return;
1020 }
1021
1022 CRect_i_ success_texel(0, 0xD0, 0x1A, 0x10);
1023#ifdef PAL
1024 CRect_i_ cool_texel(0, 0xE0, 0x32, 0x10);
1025 int lang = LanguageCode;
1026
1027 if (lang < LANG_JAPANESE || lang >= LANG_COUNT) {
1028 lang = LANG_ENGLISH_US;
1029 }
1030
1031 success_texel = OkRect[lang];
1032 cool_texel = CoolRect[lang];
1033#else
1034 CRect_i_ cool_texel(0, 0xE0, 0x28, 0x10);
1035#endif
1036 CRect_i_ spark_texel(0x20, 0x60, 0x20, 0x20);
1037 sceVu0FVECTOR offset;
1038 CRect_i_ *texel = &success_texel;
1039
1040 if (ok_type != 0) {
1041 texel = &cool_texel;
1042 }
1043
1044 if ((ok_draw_cnt / 3) % 2 != 0) {
1045 int width = texel->width;
1046 int left = 200 - (int) (width >> 1);
1047 int height = texel->height;
1048 int top = 318 - height;
1049 CRect_i_ result_screen(left, top, width, height);
1050
1051 set2DSprite(GetVif1Packet(), tex2, result_screen, texel->x, texel->y);
1052 }
1053
1054 texel = &spark_texel;
1055 int spark_x = x + 0x18;
1056
1057 for (int i = 0; i < 8; ++i) {
1058 sceVu0Normalize(dir[i], dir[i]);
1059 sceVu0ScaleVector(offset, dir[i], 2.0f * (float) (30 - ok_draw_cnt));
1060 int half;
1061 int left;
1062 int top;
1063 int alpha;
1064 int height;
1065 int width;
1066 int bottom;
1067 width = texel->width;
1068 half = width >> 1;
1069 left = spark_x + (int) offset[0] - half;
1070 bottom = (int) offset[1] + 0x160;
1071 height = texel->height;
1072 top = bottom - height - 2;
1073 alpha = 0x80 - (int) ((float) (30 - ok_draw_cnt * 2) * 128.0 / 30.0);
1074
1075 if (alpha > 0) {
1076 CRect_i_ screen(left, top, width, height);
1077 set2DSprite(GetVif1Packet(), tex, screen, spark_texel, (unsigned char) alpha);
1078 }
1079 }
1080}
1081
1089static float button_scale(int button) {
1090 if (button != ok_effect_button) {
1091 return 1.0f;
1092 }
1093
1094 // The prompt swells over the first five frames of the flash and settles
1095 // back over the next five.
1096 int elapsed = 30 - ok_draw_cnt;
1097 float scale = 1.0f;
1098
1099 if (elapsed < 5) {
1100 scale += 0.2f * (float) elapsed;
1101 } else if (elapsed < 10) {
1102 scale += 0.2f * (float) (10 - elapsed);
1103 }
1104
1105 return scale;
1106}
1107
1108#ifdef PAL
1116CEbSpriteRect::CEbSpriteRect() {
1117 height = 0;
1118 width = 0;
1119 y = 0;
1120 x = 0;
1121}
1122#endif
1123
1124static int key_mode = 0xFFFF;
1125
1127float camera_near_dist = 70.0f;
1129float camera_far_dist = 80.0f;
1130
1134static int check_key_mode(int mode) {
1135 if (mode == 0xFFFF) {
1136 return 1;
1137 }
1138
1139 return (key_mode & mode) != 0;
1140}
1141
1142int EdSetKeyMode(int mode) {
1143 return key_mode = mode;
1144}
1145
1146float EdGetRXf(int mode) {
1147 if (check_key_mode(mode)) {
1148 return GamePad.GetRXf();
1149 }
1150
1151 return 0.0f;
1152}
1153
1154float EdGetRYf(int mode) {
1155 if (check_key_mode(mode)) {
1156 return GamePad.GetRYf();
1157 }
1158
1159 return 0.0f;
1160}
1161
1162float EdGetLXf(int mode) {
1163 if (check_key_mode(mode)) {
1164 return GamePad.GetLXf();
1165 }
1166
1167 return 0.0f;
1168}
1169
1170float EdGetLYf(int mode) {
1171 if (check_key_mode(mode)) {
1172 return GamePad.GetLYf();
1173 }
1174
1175 return 0.0f;
1176}
1177
1178int EdPadOn(int keys, int mode) {
1179 if (check_key_mode(mode)) {
1180 return GamePad.On(keys);
1181 }
1182
1183 return 0;
1184}
1185
1186int EdPadDown(int keys, int mode) {
1187 if (check_key_mode(mode)) {
1188 return GamePad.Down(keys);
1189 }
1190
1191 return 0;
1192}
1193
1201static int keylock() {
1202 return chara_mode & 3;
1203}
1204
1208static float GetRXf() {
1209 if (keylock() != 0) {
1210 return 0.0f;
1211 }
1212
1213 return EdGetRXf(1);
1214}
1215
1219static float GetRYf() {
1220 if (keylock() != 0) {
1221 return 0.0f;
1222 }
1223
1224 return EdGetRYf(1);
1225}
1226
1230static float GetLXf() {
1231 if (keylock() != 0) {
1232 return 0.0f;
1233 }
1234
1235 return EdGetLXf(1);
1236}
1237
1241static float GetLYf() {
1242 if (keylock() != 0) {
1243 return 0.0f;
1244 }
1245
1246 return EdGetLYf(1);
1247}
1248
1256static int PadOn(int keys) {
1257 if (keylock() != 0) {
1258 return 0;
1259 }
1260
1261 return EdPadOn(keys, 1);
1262}
1263
1271static int PadDown(int keys) {
1272 if (keylock() != 0) {
1273 return 0;
1274 }
1275
1276 return EdPadDown(keys, 1);
1277}
1278
1286static void CameraAutoMove(CCameraFollow *camera, CCPoly *poly, float *position, float left_distance, float right_distance) {
1287 float reference[4];
1288 float offset[4];
1289 float step;
1290
1291 camera->GetRef(reference);
1292 offset[0] = position[0] - reference[0];
1293 offset[2] = position[2] - reference[2];
1294 offset[1] = 0.0f;
1295 camera->SetDistance(0.1f + DistVector(offset));
1296
1297 step = 0.0f;
1298 float excess = camera->GetDistance() - camera_near_dist;
1299
1300 if (excess < step) {
1301 step = -excess / 10.0f;
1302 }
1303
1304 if (excess > 0.0f) {
1305 step = excess / 15.0f;
1306 }
1307
1308 if (step > 2.0f) {
1309 step = 2.0f;
1310 }
1311
1312 if (step < 0.05f) {
1313 step = 0.05f;
1314 }
1315
1316 if (excess < 0.0f) {
1317 step *= 2.0f;
1318 }
1319
1320 camera->SetAngle(atan2f(offset[0], offset[2]));
1321
1322 if (left_distance < right_distance) {
1323 camera->AddAngle(0.2f * -step);
1324 } else {
1325 camera->AddAngle(0.2f * step);
1326 }
1327
1328 if (camera->GetDistance() < 0.8f * camera_near_dist) {
1329 camera->AddHeight(1.0f);
1330 }
1331}
1332
1340void EdViewModeOff() {
1341 viewMode = 0;
1342}
1343
1351static void InitEyeCamera(CCharacter *character) {
1352 // The camera looks the way the character faces.
1353 viewAngleH = character->GetRotation()->y;
1354 viewAngleV = 0.0f;
1355}
1356
1364void EyeCamera(CCamera *camera, CCharacter *character, int right_stick) {
1365 float stick_x;
1366 float stick_y;
1367
1368 if (right_stick != 0) {
1369 stick_x = 0.0f;
1370 stick_y = -GetRYf();
1371 } else {
1372 stick_x = GetLXf();
1373 stick_y = -GetLYf();
1374 }
1375
1376 if (stick_x > 0.0f) {
1377 float rate = 0.02f;
1378 viewAngleH -= stick_x * rate;
1379
1380 if (viewAngleH < -PI) {
1381 viewAngleH += TWO_PI;
1382 }
1383 }
1384
1385 if (stick_x < -0.0f) {
1386 float rate = 0.02f;
1387 viewAngleH -= stick_x * rate;
1388
1389 if (viewAngleH > PI) {
1390 viewAngleH -= TWO_PI;
1391 }
1392 }
1393
1394 if (stick_y > 0.0f && viewAngleV < 0.65f) {
1395 float rate = 0.02f;
1396 viewAngleV += stick_y * rate;
1397 }
1398
1399 if (stick_y < -0.0f && viewAngleV > -1.0f) {
1400 float rate = 0.02f;
1401 viewAngleV += stick_y * rate;
1402 }
1403
1404 EdEyeCamera(camera, character);
1405}
1406
1407void EdInitCameraParam(CCameraFollow *camera) {
1408 if (camera != 0) {
1409 camera->SetDistance(camera_near_dist);
1410 camera->SetHeight(5.0f);
1411 }
1412}
1413
1414void EdMoveCharaInit() {
1415 viewMode = 0;
1416 chara_mode = 0;
1417 chara_fishing = ED_FISHING_INIT;
1418 fishing_mes = ED_FISHING_MES_EVALUATE;
1419}
1420
1428void EdEyeCamera(CCamera *camera, CCharacter *character) {
1429 sceVu0FVECTOR position;
1430 sceVu0FVECTOR reference;
1431 sceVu0FMATRIX rotation;
1432 sceVu0FMATRIX unit;
1433
1434 // The point the camera looks at sits ten units ahead of the head, turned
1435 // by the two view angles.
1436 reference[0] = 0.0f;
1437 reference[1] = 0.0f;
1438 reference[2] = 10.0f;
1439 reference[3] = 0.0f;
1440 sceVu0UnitMatrix(unit);
1441 sceVu0RotMatrixX(rotation, unit, viewAngleV);
1442 sceVu0RotMatrixY(rotation, rotation, viewAngleH);
1443 sceVu0ApplyMatrix(reference, rotation, reference);
1444 character->GetPosition(position);
1445 position[1] += 14.0f;
1446 reference[0] += position[0];
1447 reference[1] += position[1];
1448 reference[2] += position[2];
1449 camera->SetPos(position);
1450 camera->SetRef(reference);
1451}
1452
1453int EdCheckViewMode() {
1454 return viewMode;
1455}
1456
1464float EdAGetViewAngleH() {
1465 return viewAngleH;
1466}
1467
1475float EdAGetViewAngleV() {
1476 return viewAngleV;
1477}
1478
1486void EdASetViewAngle(float horizontal, float vertical) {
1487 viewAngleH = horizontal;
1488 viewAngleV = vertical;
1489}
1490
1494static inline int IsVillagerActive(CNPCharacter *villager) {
1495 bool active = false;
1496
1497 if (villager->initialized != 0 && villager->draw_enabled != 0) {
1498 active = true;
1499 }
1500
1501 return active;
1502}
1503
1504void EdMoveChara() {
1505 int near_villager;
1506 CCamera *view_camera;
1507 int key_lock;
1508 CEditGround *ground;
1509 float angle;
1510 float time;
1511 int motion;
1512 float move_z;
1513 float move_x;
1514 float ly;
1515 float lx;
1516 float time_before;
1517 CCPoly *polys;
1518 int poly_count;
1519 int poly_event;
1520 int shallow;
1521 int left_clear;
1522 float *normal;
1523 CCameraFollow *camera;
1524 int keep_distance;
1525 CMainChara *chara;
1526 int interior;
1527 float float_weight;
1528 float hook_weight;
1529 int follow_line;
1530 float time_after;
1531 float motion_speed;
1532 float stick;
1533 CFrame *frame;
1534 float left_distance;
1535 float right_distance;
1536 float span;
1537 int wall_count;
1538 int hits;
1539 int wall_hit;
1540 int right_clear;
1541 CCPoly *walls;
1542 int last;
1543 float away;
1544 int floor_poly;
1545 int drift;
1546 float rx;
1547 float ry;
1548 float turn;
1549 float lowest;
1550 float drop;
1551 float behind_angle;
1552 int turn_side;
1553 int acted;
1554 int event_no;
1555 int system_event_no;
1556 ED_EVENT_POINT *points;
1557 int point_count;
1558 ED_EVENT_PARAM *param;
1559 int item;
1560 int refused;
1561 int attach;
1562 int fish_status;
1563 float reel_turn;
1564 float pull;
1565 char *fish_file;
1566 float tug;
1567 BG_READ_INFO *read_info;
1568 u_int *fish_data;
1569 int free_blocks;
1570 int fish_kind;
1571 int *caught;
1572 CFish *fish;
1573 float water_level;
1574 float fall_height;
1575 float rise;
1576 float walked;
1577 s16 floor_kind;
1578 int i;
1579
1580 static sceVu0FVECTOR reference = {0.0f, 0.0f, 0.0f, 0.0f};
1581
1582 EdMoveCharaInfo.event_no = -1;
1583 EdMoveCharaInfo.system_event_no = -1;
1584 time = EdMoveCharaInfo.time;
1585 camera = EdMoveCharaInfo.camera;
1586 view_camera = EdMoveCharaInfo.view_camera;
1587 key_lock = EdMoveCharaInfo.key_lock;
1588 chara = (CMainChara *) EdMoveCharaInfo.chara;
1589 interior = EdMoveCharaInfo.interior;
1590 ground = EdMoveCharaInfo.ground;
1591
1592 if (key_lock != 0) {
1593 chara_mode |= 1;
1594 } else {
1595 chara_mode &= ~1;
1596 }
1597
1598 sceVu0FVECTOR pos;
1599 sceVu0FVECTOR rot;
1600 chara->GetPosition(pos);
1601 chara->GetRotation(rot);
1602 sceVu0FVECTOR velocity = {0.0f, 0.0f, 0.0f, 0.0f};
1603 sceVu0FVECTOR move;
1604
1605 angle = camera->GetAngleH();
1606 lx = GetLXf();
1607 ly = GetLYf();
1608
1609 if (key_lock != 0 || chara_fishing > ED_FISHING_STAND) {
1610 lx = ly = 0.0f;
1611 }
1612
1613 if (PadOn(0x80) != 0 && EdDebugMoveFlag > 0) {
1614 if (EdDebugMoveFlag > 0) {
1615 lx *= 2.0f;
1616 ly *= 2.0f;
1617 } else {
1618 lx *= 1.5f;
1619 ly *= 1.5f;
1620 }
1621 }
1622
1623 motion = 0;
1624 motion_speed = -1.0f;
1625
1626 if (viewMode == 0) {
1627 move_x = lx * cosf(angle) + ly * sinf(angle);
1628 move_z = ly * cosf(angle) - lx * sinf(angle);
1629
1630 if (interior != 0) {
1631 velocity[0] = move_x;
1632 velocity[2] = move_z;
1633 } else {
1634 velocity[0] = 1.6f * move_x;
1635 velocity[2] = 1.6f * move_z;
1636 }
1637
1638 // A slope slows the step by how far its floor leans.
1639 if (chara->move_info.landed != 0) {
1640 sceVu0FVECTOR normal;
1641 sceVu0Normalize(normal, chara->move_info.ground_poly.normal);
1642 normal[1] = normal[1] < 0.0f ? -normal[1] : normal[1];
1643 velocity[0] *= normal[1];
1644 velocity[2] *= normal[1];
1645 }
1646
1647 if (lx != 0.0f || ly != 0.0f) {
1648 stick = sqrtf(lx * lx + ly * ly);
1649
1650 if (stick > 0.85f && EdMoveCharaInfo.fishing == 0) {
1651 motion = 1;
1652 } else {
1653 motion = 2;
1654 motion_speed = 0.8f * (0.2f + stick);
1655
1656 if (motion_speed > 0.85f) {
1657 motion_speed = 0.85f;
1658 }
1659 }
1660 } else {
1661 motion = 0;
1662 }
1663
1664 if (move_x != 0.0f || move_z != 0.0f) {
1665 chara->SetRotation(0.0f, AngleInterpolate(rot[1], atan2f(move_x, move_z), 0.2f, INTERPOLATE_STEP), 0.0f);
1666 }
1667 } else if (interior != 0) {
1668 if (lx == 0.0f) {
1669 lx = GetRXf();
1670 }
1671
1672 sceVu0FVECTOR eye_rot;
1673 chara->GetRotation(eye_rot);
1674 eye_rot[1] -= 0.04f * lx;
1675
1676 if (eye_rot[1] > PI) {
1677 eye_rot[1] -= TWO_PI;
1678 }
1679
1680 if (eye_rot[1] < -PI) {
1681 eye_rot[1] += TWO_PI;
1682 }
1683
1684 angle = eye_rot[1];
1685 viewAngleH = angle;
1686 chara->SetRotation(eye_rot);
1687 move_x = ly * sinf(angle);
1688 move_z = ly * cosf(angle);
1689 velocity[0] = 0.6f * -move_x;
1690 velocity[2] = 0.6f * -move_z;
1691
1692 if (chara->move_info.landed != 0) {
1693 sceVu0FVECTOR normal;
1694 sceVu0Normalize(normal, chara->move_info.ground_poly.normal);
1695 normal[1] = normal[1] < 0.0f ? -normal[1] : normal[1];
1696 velocity[0] *= normal[1];
1697 velocity[2] *= normal[1];
1698 }
1699 }
1700
1701 if ((chara_mode & 6) == 0 && chara_fishing < ED_FISHING_CAST_START) {
1702 chara->SetMotion(motion, 0);
1703 chara->SetMotionSpeed(motion_speed);
1704 }
1705
1706 if (PadDown(0x20) != 0 && EdDebugMoveFlag != 0 && key_lock == 0 && chara_fishing < ED_FISHING_CAST_START) {
1707 CVector3_f_ jump;
1708 chara->GetVelocity(&jump);
1709 jump.y = 2.0f;
1710 chara->SetVelocity(jump);
1711 }
1712
1713 sceVu0FVECTOR next;
1714 time_before = chara->GetNowTime();
1715 WorkBuffer__2->used = 0;
1716 polys = (CCPoly *) WorkBuffer__2->Alloc(0x7D0);
1717 poly_count = 0;
1718
1719 if (interior == 0) {
1720 poly_count = ground->PickUpPoly(polys, pos[0], pos[1], pos[2]);
1721 } else {
1722 CBoxVu0 box;
1723 box.max[0] = 20.0f + pos[0];
1724 box.min[0] = pos[0] - 20.0f;
1725 box.max[2] = 20.0f + pos[2];
1726 box.min[2] = pos[2] - 20.0f;
1727 box.max[1] = 1000.0f + pos[1];
1728 box.min[1] = pos[1] - 1000.0f;
1729
1730 for (i = 0; i < EdMoveCharaInfo.parts_count; i++) {
1731 frame = EdMoveCharaInfo.parts[i].GetCollisionFrame();
1732
1733 if (frame != NULL) {
1734 poly_count += frame->PickUpNearPoly(&polys[poly_count], box);
1735 }
1736 }
1737 }
1738
1739 poly_count += EdEventPointCpPoly(pos, EdMoveCharaInfo.points, EdMoveCharaInfo.point_count, &polys[poly_count], time);
1740
1741 if (EdMoveCharaInfo.fishing != 0) {
1742 poly_count += FishingPickUpPoly(&polys[poly_count]);
1743 }
1744
1745 for (i = 0; i < 10; i++) {
1746 if (IsVillagerActive(&EdVillager[i])) {
1747 poly_count += EdVillager[i].PickUpPoly(pos, &polys[poly_count]);
1748 }
1749 }
1750
1751 if (poly_count > 200) {
1752 printf("cpoly over!!!! %d\n", poly_count);
1753 }
1754
1755 CVector3_f_ fall;
1756 chara->GetVelocity(&fall);
1757 velocity[1] = fall.y;
1758 MoveCheck(pos, velocity, next, &chara->move_info, polys, poly_count, 0);
1759
1760 if (EdDebugMoveFlag >= 2) {
1761 next[0] = pos[0] + velocity[0];
1762 next[2] = pos[2] + velocity[2];
1763 }
1764
1765 CCPoly event_poly;
1766 sceVu0FVECTOR ahead;
1767 sceVu0FVECTOR event_hit;
1768 sceVu0FVECTOR eye;
1769 int event_index = -1;
1770 sceVu0CopyVector(eye, pos);
1771 eye[1] += 0.5f * chara->body_height;
1772 ahead[0] = 7.5f * sinf(rot[1]);
1773 ahead[1] = 0.0f;
1774 ahead[2] = 7.5f * cosf(rot[1]);
1775 poly_event = GetEventPoly(eye, ahead, &event_poly, &event_index, event_hit, polys, poly_count, 0);
1776 sceVu0SubVector(move, next, pos);
1777
1778 if (next[1] < -1000.0f) {
1779 next[1] = 1000.0f;
1780 }
1781
1782 if (interior != 0 && next[1] < 0.0f) {
1783 next[1] = 0.0f;
1784 chara->move_info.landed = 1;
1785 }
1786
1787 chara->SetPosition(next);
1788 fall.y += -0.1f;
1789
1790 if (fall.y < -4.0f) {
1791 fall.y = -4.0f;
1792 }
1793
1794 chara->SetVelocity(fall);
1795
1796 if ((chara_mode & 2) != 0 && (chara->motion_state == 3 || viewMode != 0)) {
1797 chara_mode &= ~2;
1798 }
1799
1800 if (chara->move_info.landed != 0) {
1801 if (fall.y < -1.0f) {
1802 chara_mode |= 2;
1803 chara->SetMotion(9, 6);
1804 }
1805
1806 chara->SetVelocity(CVector3_f_(0.0f, 0.0f, 0.0f));
1807 chara_mode &= ~4;
1808 } else {
1809 chara_mode |= 4;
1810
1811 if (fall.y < -0.5f) {
1812 chara->SetMotion(8, 0);
1813 }
1814 }
1815
1816 if (viewMode == 0 && interior == 0) {
1817 camera->FollowOn();
1818 sceVu0FVECTOR target;
1819 sceVu0CopyVector(target, next);
1820 target[0] += 7.0f * move[0];
1821 target[1] += 14.0f + (2.0f * move[1] + reference[1]);
1822 target[2] += 7.0f * move[2];
1823 camera->SetFollow(target[0], target[1], target[2]);
1824 } else {
1825 EyeCamera(view_camera, chara, interior);
1826 }
1827
1828 if (EdMoveCharaInfo.fishing == 0 && PadDown(2) != 0) {
1829 if (viewMode == 0) {
1830 sceVu0FVECTOR eye_pos;
1831 sceVu0FVECTOR eye_ref;
1832 camera->GetPos(eye_pos);
1833 camera->GetRef(eye_ref);
1834 view_camera->SetPos(eye_pos);
1835 view_camera->SetRef(eye_ref);
1836 viewMode = !viewMode;
1837 InitEyeCamera(chara);
1838 } else {
1839 viewMode = !viewMode;
1840 }
1841 }
1842
1843 shallow = 0;
1844
1845 if (chara->move_info.ground_found != 0 && chara->move_info.poly.attr.area_kind == AREA_KIND_HIGH_CAMERA) {
1846 shallow = 1;
1847 }
1848
1849 right_clear = left_clear = keep_distance = 1;
1850
1851 if (viewMode == 0 && interior == 0 && EdDebugMoveFlag < 2) {
1852 sceVu0FVECTOR last_hit;
1853 sceVu0FVECTOR eye_pos;
1854 sceVu0FVECTOR hit;
1855 sceVu0FVECTOR look;
1856 sceVu0FVECTOR behind;
1857 sceVu0FVECTOR forward;
1858 sceVu0FVECTOR towards;
1859 sceVu0FVECTOR left_end;
1860 sceVu0FVECTOR right_end;
1861 sceVu0FVECTOR left;
1862 sceVu0FVECTOR right;
1863 sceVu0FVECTOR reach;
1864 sceVu0FVECTOR direction;
1865 sceVu0FVECTOR wall;
1866 CBoxVu0 box;
1867 sceVu0FVECTOR to_eye;
1868 sceVu0FVECTOR to_wall;
1869 sceVu0FVECTOR cross;
1870 int hit_poly[32];
1871 float hit_point[32][4];
1872 sceVu0FVECTOR origin;
1873 sceVu0FVECTOR facing;
1874 sceVu0FVECTOR facing_first;
1875 sceVu0FVECTOR floor_normal;
1876
1877 right_distance = left_distance = 1000000;
1878 camera->GetPos(eye_pos);
1879 camera->GetRef(look);
1880 sceVu0SubVector(forward, look, eye_pos);
1881 sceVu0SubVector(behind, eye_pos, forward);
1882 sceVu0Normalize(direction, forward);
1883 WorkBuffer__2->used = 0;
1884 walls = (CCPoly *) WorkBuffer__2->Alloc(0x7D0);
1885 span = DistVector(behind, look);
1886 box.max[0] = eye_pos[0] + span;
1887 box.min[0] = eye_pos[0] - span;
1888 box.max[2] = eye_pos[2] + span;
1889 box.min[2] = eye_pos[2] - span;
1890 box.max[1] = 100.0f + eye_pos[1];
1891 box.min[1] = eye_pos[1] - 100.0f;
1892
1893 if (EdMoveCharaInfo.fishing != 0) {
1894 wall_count = ground->PickUpCameraPoly(walls, box, 1);
1895 } else {
1896 wall_count = ground->PickUpCameraPoly(walls, box, 0xFFFF);
1897 }
1898
1899 // A wall beside the eye turns the camera along it and stops it turning into it.
1900 if (CheckCameraWidth(walls, wall_count, eye_pos, 10.0f, wall, 0) != 0) {
1901 sceVu0SubVector(to_eye, look, eye_pos);
1902 sceVu0SubVector(to_wall, look, wall);
1903 to_eye[1] = to_wall[1] = 0.0f;
1904 sceVu0Normalize(to_eye, to_eye);
1905 sceVu0Normalize(to_wall, to_wall);
1906 sceVu0OuterProduct(cross, to_eye, to_wall);
1907 camera->AddAngle(0.5f * cross[1]);
1908 camera->SetAngleSoon(atan2f(-to_wall[0], -to_wall[2]));
1909
1910 if (cross[1] > 0.0f) {
1911 left_clear = 0;
1912 }
1913
1914 if (cross[1] < -0.0f) {
1915 right_clear = 0;
1916 }
1917 }
1918
1919 hits = CheckHits(walls, wall_count, look, behind, 32, hit_poly, hit_point, 1, 0);
1920 sceVu0CopyVector(origin, eye_pos);
1921 left[0] = forward[2];
1922 left[1] = 0.0f;
1923 left[2] = -forward[0];
1924 sceVu0Normalize(left, left);
1925 sceVu0ScaleVector(reach, left, 100.0f);
1926 sceVu0AddVector(left_end, origin, reach);
1927 wall_hit = CheckHit(walls, wall_count, origin, left_end, hit, 1, 0);
1928
1929 if (wall_hit >= 0) {
1930 normal = walls[wall_hit].normal;
1931 sceVu0Normalize(normal, normal);
1932
1933 if (sceVu0InnerProduct(left, normal) > 0.001f) {
1934 left_distance = DistVector(origin, hit);
1935 } else if (DistVector(origin, hit) < 5.0f) {
1936 left_clear = 0;
1937 }
1938 }
1939
1940 right[0] = -forward[2];
1941 right[1] = 0.0f;
1942 right[2] = forward[0];
1943 sceVu0Normalize(right, right);
1944 sceVu0ScaleVector(reach, right, 100.0f);
1945 sceVu0AddVector(right_end, origin, reach);
1946 wall_hit = CheckHit(walls, wall_count, origin, right_end, hit, 1, 0);
1947
1948 if (wall_hit >= 0) {
1949 normal = walls[wall_hit].normal;
1950 sceVu0Normalize(normal, normal);
1951
1952 if (sceVu0InnerProduct(right, normal) > 0.001f) {
1953 right_distance = DistVector(origin, hit);
1954 } else if (DistVector(origin, hit) < 5.0f) {
1955 right_clear = 0;
1956 }
1957 }
1958
1959 if (hits > 0) {
1960 camera_far_dist = 80.0f;
1961 last = -1;
1962
1963 for (i = 0; i < hits; i++) {
1964 sceVu0SubVector(towards, hit_point[i], eye_pos);
1965
1966 if (sceVu0InnerProduct(forward, towards) < 0.0f) {
1967 break;
1968 }
1969
1970 last = i;
1971 }
1972
1973 if (last >= 0) {
1974 keep_distance = 0;
1975 sceVu0CopyVector(facing, walls[hit_poly[last]].normal);
1976
1977 if (sceVu0InnerProduct(direction, facing) > 0.0f) {
1978 if (last + 1 < hits) {
1979 away = DistVector(eye_pos, hit_point[last + 1]);
1980
1981 if (away - DistVector(eye_pos, hit_point[last]) < 0.0f) {
1982 CameraAutoMove(camera, &walls[hit_poly[last + 1]], hit_point[last + 1], left_distance, right_distance);
1983 } else {
1984 CameraAutoMove(camera, &walls[hit_poly[last]], hit_point[last], left_distance, right_distance);
1985 }
1986 } else {
1987 CameraAutoMove(camera, &walls[hit_poly[last]], hit_point[last], left_distance, right_distance);
1988 sceVu0CopyVector(last_hit, hit_point[last]);
1989 }
1990 }
1991 } else {
1992 sceVu0CopyVector(facing_first, walls[hit_poly[0]].normal);
1993
1994 if (sceVu0InnerProduct(forward, facing_first) < 0.0f) {
1995 CameraAutoMove(camera, &walls[hit_poly[0]], hit_point[0], left_distance, right_distance);
1996 keep_distance = 0;
1997 }
1998 }
1999 }
2000
2001 // The eye keeps its height above whatever floor is under it.
2002 sceVu0CopyVector(behind, eye_pos);
2003 behind[1] += 15.0f;
2004 floor_poly = CheckHitVertical(walls, wall_count, behind, -100.0f, hit, 0);
2005
2006 if (floor_poly >= 0) {
2007 sceVu0Normalize(floor_normal, walls[floor_poly].normal);
2008
2009 if (eye_pos[1] - hit[1] < 18.0f) {
2010 if ((floor_normal[1] < 0.0f ? -floor_normal[1] : floor_normal[1]) > 0.5f) {
2011 eye_pos[1] = 18.0f + hit[1];
2012 camera->SetHeight(eye_pos[1] - look[1] - 0.01f);
2013 }
2014 }
2015 }
2016
2017 float half = 0.5f;
2018
2019 if ((camera->GetDistance() < camera_near_dist * half || camera->GetHeight() > 60.0f) && shallow == 0 && hits > 0) {
2020 camera->SetDistance(camera_near_dist);
2021 camera->SetHeight(10.0f);
2022 camera->SetAngleSoon(camera->GetAngle());
2023 camera->AddAngle(3.14f);
2024
2025 if (MapNo == 35 && eye_pos[2] > 200.0f) {
2026 camera->SetAngleSoon(3.14f);
2027 }
2028
2029 camera->Step(-1);
2030 }
2031 }
2032
2033 if (viewMode == 0 && interior == 0) {
2034 drift = 0;
2035 rx = GetRXf();
2036 ry = GetRYf();
2037
2038 if (EdDebugCameraFlag == 0) {
2039 if (camera->GetHeight() < 30.0f) {
2040 camera->AddHeight(-ry);
2041 }
2042 } else {
2043 camera->AddHeight(-ry);
2044 }
2045
2046 if (rx > 0.0f && left_clear != 0) {
2047 camera->AddAngle(0.03f * -rx);
2048 }
2049
2050 if (rx < 0.0f && right_clear != 0) {
2051 camera->AddAngle(0.03f * -rx);
2052 }
2053
2054 if (rx == 0.0f) {
2055 if (left_clear != 0 && PadOn(8) != 0) {
2056 camera->AddAngle(-DEG_TO_RAD);
2057 } else if (right_clear != 0 && PadOn(4) != 0) {
2058 camera->AddAngle(DEG_TO_RAD);
2059 } else {
2060 drift = 1;
2061 }
2062 }
2063
2064 if (camera->GetDistance() > camera_far_dist) {
2065 camera->AddDistance(-(camera->GetDistance() - camera_far_dist) / 10.0f);
2066 }
2067
2068 if (camera->GetDistance() < camera_near_dist) {
2069 camera->AddDistance(-(camera->GetDistance() - camera_near_dist) / 10.0f);
2070 }
2071
2072 // With the right stick at rest the camera swings round behind a walking character.
2073 if (drift != 0) {
2074 turn = lx;
2075
2076 if (ly > 0.05f) {
2077 if (!(lx < 0.0f) && lx < 0.5f) {
2078 lx = 0.5f;
2079 }
2080
2081 if (lx <= 0.0f && lx > -0.5f) {
2082 lx = -0.5f;
2083 }
2084
2085 if (left_clear == 0) {
2086 lx = 0.5f;
2087 }
2088
2089 if (right_clear == 0) {
2090 lx = -0.5f;
2091 }
2092 }
2093
2094 lx *= DistVector(move) / 1.6f / 2.0f;
2095
2096 if (lx > 0.1f && left_clear != 0) {
2097 if (turn < 0.4f) {
2098 turn = 0.4f;
2099 }
2100
2101 if (turn > 1.0f) {
2102 turn = 1.0f;
2103 }
2104
2105 camera->AddAngle(2.0f * (-DEG_TO_RAD * turn));
2106 }
2107
2108 if (lx < -0.1f && right_clear != 0) {
2109 if (turn > -0.4f) {
2110 turn = -0.4f;
2111 }
2112
2113 if (turn < -1.0f) {
2114 turn = -1.0f;
2115 }
2116
2117 camera->AddAngle(2.0f * (-DEG_TO_RAD * turn));
2118 }
2119 }
2120
2121 if (keep_distance != 0) {
2122 camera->SetDistance(camera_near_dist);
2123 }
2124
2125 if (EdDebugCameraFlag == 0) {
2126 if (camera->GetHeight() > 60.0f) {
2127 camera->SetHeight(60.0f);
2128 }
2129
2130 lowest = 5.0f;
2131
2132 if (shallow != 0) {
2133 lowest = 35.0f;
2134 }
2135
2136 if (camera->GetHeight() < lowest) {
2137 camera->SetHeight(lowest);
2138 }
2139
2140 if (camera->GetHeight() > 5.0f) {
2141 drop = camera->GetHeight() - lowest;
2142 drop *= 0.05f;
2143
2144 if (drop < 0.15f) {
2145 drop = 0.15f;
2146 }
2147
2148 if (drop > 0.5f) {
2149 drop = 0.5f;
2150 }
2151
2152 camera->AddHeight(-drop);
2153 }
2154 } else {
2155 if (PadOn(0x1000) != 0) {
2156 reference[1] += 2.0f;
2157 }
2158
2159 if (PadOn(0x4000) != 0) {
2160 reference[1] -= 2.0f;
2161 }
2162 }
2163
2164 // The button swings the camera round behind the character over thirty frames.
2165 static int rot_count = 0;
2166
2167 if (PadOn(0x20) != 0 && EdDebugMoveFlag == 0) {
2168 rot_count = 30;
2169 }
2170
2171 if (rot_count > 0) {
2172 behind_angle = chara->GetRotation()->y - PI_D;
2173 turn_side = AngleCmp(behind_angle, camera->GetAngle(), 0.1f);
2174
2175 if (turn_side < 0) {
2176 if (left_clear != 0) {
2177 camera->AddAngle(-0.1f);
2178 } else {
2179 rot_count = 0;
2180 }
2181 }
2182
2183 if (turn_side > 0) {
2184 if (right_clear != 0) {
2185 camera->AddAngle(0.1f);
2186 } else {
2187 rot_count = 0;
2188 }
2189 }
2190
2191 if (turn_side == 0) {
2192 rot_count = 0;
2193 }
2194 }
2195
2196 rot_count--;
2197
2198 if (rot_count < 0) {
2199 rot_count = 0;
2200 }
2201 }
2202
2203 near_villager = EdSearchNearNPC(chara, EdVillager, 10);
2204
2205 if (near_villager >= 0) {
2206 EdVillager[near_villager].talk_target = true;
2207 }
2208
2209 if (EdMoveCharaInfo.fishing == 0) {
2210 acted = false;
2211 sceVu0FVECTOR here;
2212 sceVu0FVECTOR heading;
2213 chara->GetPosition(here);
2214 chara->GetRotation(heading);
2215 system_event_no = event_no = -1;
2216 points = EdMoveCharaInfo.points;
2217 point_count = EdMoveCharaInfo.point_count;
2218 EdMoveCharaInfo.event_ready = false;
2219 param = &EdMoveCharaInfo.param;
2220
2221 if (EdGetEvent(points, point_count, param, here, heading, time) != 0) {
2222 if (param->kind == ED_EVENT_POINT_ITEM_BOX && PadDown(0x40) != 0 && (viewMode == 0 || interior != 0)) {
2223 item = param->point->side;
2224 refused = EdCheckGetItem(item);
2225
2226 if (refused == 0) {
2227 EdSetMapFlag(param->point->completion_flag, 1);
2228 attach = -1;
2229
2230 if (GetAddAttachItem(param->point->side) != 0) {
2231 attach = rand() % 3 + 1;
2232 }
2233
2234 EdGetItem(item, param->point->linked_value, attach);
2235 EdItemGetMes(item, param->point->linked_value, attach, 40);
2236 EdSetOpenItemBox(param->position, param->rotation);
2237 SndSePlay(SE_BOX_OPEN, -1, 0);
2238 } else {
2239 DontGetItemMes(refused);
2240 SndSePlay(SE_BOX_OPEN, -1, 0);
2241 }
2242 }
2243
2244 if (param->kind == ED_EVENT_POINT_EVENT && param->point->side > 0) {
2245 event_no = param->point->side;
2246 }
2247
2248 if (param->kind == ED_EVENT_POINT_LADDER_BOTTOM || param->kind == ED_EVENT_POINT_LADDER_TOP) {
2249 EdEventInfo.draw_exclamation_mark = true;
2250
2251 if (PadDown(0x40) != 0 && (interior != 0 || viewMode == 0)) {
2252 EdInitHashigo(&EdEventInfo, param);
2253 system_event_no = 1;
2254 }
2255 }
2256
2257 EdMoveCharaInfo.event_ready = acted = true;
2258 }
2259
2260 if (near_villager >= 10) {
2261 near_villager = -1;
2262 }
2263
2264 if (acted == 0 && (viewMode == 0 || interior != 0) && near_villager >= 0) {
2265 if (EdVillagerInfo[near_villager].talk_event_no > 0 && EdVillagerInfo[near_villager].talk_event_level != 0 && EdTalkModeInit(&EdVillager[near_villager], -1) != 0) {
2266 event_no = EdVillagerInfo[near_villager].talk_event_no;
2267 acted = true;
2268 }
2269 }
2270
2271 if (acted == 0 && PadDown(0x40) != 0 && (viewMode == 0 || interior != 0) && key_lock == 0) {
2272 if (near_villager >= 0) {
2273 if (EdTalkModeInit(&EdVillager[near_villager], -1) != 0) {
2274 event_no = 0x100;
2275 acted = true;
2276 }
2277 } else if (poly_event > 0) {
2278 event_no = poly_event;
2279 acted = true;
2280 }
2281 }
2282
2283 EdMoveCharaInfo.event_no = event_no;
2284 EdMoveCharaInfo.system_event_no = system_event_no;
2285 EdMoveCharaInfo.acted = acted;
2286 }
2287
2288 hook_weight = float_weight = -1.0f;
2289 follow_line = 0;
2290 static int bgm_vol = 0;
2291 static int load_file = 0;
2292
2293 if (EdMoveCharaInfo.fishing != 0) {
2294 EdViewModeOff();
2295
2296 if (EdDebugMoveFlag == 0) {
2297 camera->SetHeight(40.0f);
2298 }
2299
2300 sceVu0FVECTOR stand;
2301 sceVu0FVECTOR facing;
2302 sceVu0FVECTOR float_pos;
2303 chara->GetPosition(stand);
2304 chara->GetRotation(facing);
2305 FishLineGetUki(float_pos);
2306 int fish_no;
2307 fish_status = FishingFishStatus(&fish_no);
2308 static int st_cnt = 0;
2309 static int wait_cnt = 0;
2310
2311 switch (chara_fishing) {
2312 case ED_FISHING_INIT:
2313 chara_fishing = ED_FISHING_STAND;
2314 FishingInitFishStatus();
2315 FishingAngleFish(-1);
2316 wait_cnt = 0;
2317 st_cnt = 0;
2318 break;
2319 case ED_FISHING_STAND:
2320 if (st_cnt > 120) {
2321 EdFishingWalkHelpMes(FishingGetEsaItemNo());
2322 }
2323
2324 FishingAngleFish(-1);
2325
2326 if (EdPadDown(0x40, 0xFFFF) != 0) {
2327 chara_fishing = ED_FISHING_CAST_START;
2328 st_cnt = 0;
2329 }
2330
2331 if (EdPadDown(0x20, 0xFFFF) != 0) {
2332 EdMoveCharaInfo.event_no = 0x85;
2333 EdMoveCharaInfo.system_event_no = -1;
2334 EdMoveCharaInfo.acted = true;
2335 chara->SetMotion(0, 0);
2336 }
2337
2338 if (EdPadDown(0x80, 0xFFFF) != 0) {
2339 EdMoveCharaInfo.event_no = 0x86;
2340 EdMoveCharaInfo.system_event_no = -1;
2341 EdMoveCharaInfo.acted = true;
2342 chara->SetMotion(0, 0);
2343 }
2344
2345 float_weight = 1.0f;
2346 break;
2347 case ED_FISHING_CAST_START:
2348 chara->SetMotion(4, 6);
2349 chara_fishing = ED_FISHING_CASTING;
2350 st_cnt = 0;
2351 break;
2352 case ED_FISHING_CASTING:
2353 chara_mode = 1;
2354
2355 if (st_cnt == 90) {
2356 SndSePlay(SE_FISHING_CAST, pos, -1.0f, -1.0f);
2357 }
2358
2359 if (chara->motion_state == 3) {
2360 chara->SetMotion(5, 0);
2361 chara_fishing = ED_FISHING_WAIT_BITE;
2362 st_cnt = 0;
2363 wait_cnt = 0;
2364 }
2365
2366 break;
2367 case ED_FISHING_WAIT_BITE: {
2368 EdFishingAngleHelpMEs(FishingGetEsaItemNo());
2369 chara_mode = 1;
2370
2371 if (wait_cnt < 600) {
2372 chara->SetMotion(5, 0);
2373 } else if (wait_cnt < 1200) {
2374 chara->SetMotion(14, 0);
2375 } else {
2376 if (wait_cnt == 1200) {
2377 chara->SetMotion(15, 6);
2378 }
2379
2380 if (wait_cnt > 1250 && chara->motion_state == 3) {
2381 chara->SetMotion(5, 4);
2382 wait_cnt = 0;
2383 }
2384 }
2385
2386 reel_turn = -GamePad.GetLXf();
2387 facing[1] = AngleInterpolate(facing[1], facing[1] + 0.1f * reel_turn, 0.01f, INTERPOLATE_STEP);
2388 chara->SetRotation(facing);
2389
2390 if (reel_turn != 0.0f) {
2391 wait_cnt = 0;
2392 chara->SetMotion(13, 0);
2393 }
2394
2395 if (EdPadDown(0x40, 0xFFFF) != 0 || (st_cnt > 30 && FishingCheckUkiHook() != 0)) {
2396 chara_fishing = ED_FISHING_REEL_IN;
2397 chara->SetMotion(7, 6);
2398 st_cnt = 0;
2399 } else {
2400 if (fish_status == 7) {
2401 chara_fishing = ED_FISHING_BITE_CHECK;
2402 }
2403
2404 if (fish_status == 8) {
2405 chara_fishing = ED_FISHING_HOOKED;
2406 }
2407 }
2408
2409 wait_cnt++;
2410 follow_line = 1;
2411 break;
2412 }
2413 case ED_FISHING_REEL_IN:
2414 if (st_cnt == 40) {
2415 sceVu0FVECTOR hook;
2416 FishLineGetHook(hook);
2417
2418 if (hook[1] < 5.0f + FishingGetWaterLevel()) {
2419 SndSePlay(SE_FISHING_SINK, float_pos, -1.0f, -1.0f);
2420 }
2421 }
2422
2423 if (chara->motion_state == 3) {
2424 chara->SetMotion(0, 0);
2425 chara_fishing = ED_FISHING_STAND;
2426 wait_cnt = 0;
2427 }
2428
2429 if (st_cnt > 30) {
2430 float_weight = 0.02f * (float) (st_cnt - 30);
2431 }
2432
2433 if (float_weight > 1.0f) {
2434 float_weight = 1.0f;
2435 }
2436
2437 break;
2438 case ED_FISHING_BITE_CHECK: {
2439 EdFishingAngleHelpMEs(FishingGetEsaItemNo());
2440
2441 if (fish_status == 8) {
2442 chara_fishing = ED_FISHING_HOOKED;
2443 } else if (fish_status != 7) {
2444 chara_fishing = ED_FISHING_WAIT_BITE;
2445 st_cnt = 0;
2446 wait_cnt = 0;
2447 }
2448
2449 if (EdPadDown(0x40, 0xFFFF) != 0) {
2450 chara_fishing = ED_FISHING_SINK;
2451 chara->SetMotion(6, 6);
2452 st_cnt = 0;
2453 SndSePlay(SE_FISHING_SINK, float_pos, -1.0f, -1.0f);
2454
2455 if (rand() % 100 < 20) {
2456 EdFishingLostEsaMes();
2457 FishingDeleteEsa();
2458 }
2459 }
2460
2461 pull = -0.15f * (float) rand() / 2.1474836e9f;
2462
2463 if (pull < -0.1f) {
2464 sceVu0FVECTOR ripple;
2465 FishLineGetUki(ripple);
2466 ripple[1] = FishingGetWaterLevel();
2467 GamePad.SetVibration(1, 80, 2);
2468 EffectHamon(&EdEffectGroup, ripple, 10.0f);
2469 }
2470
2471 FishPullHook(pull);
2472 follow_line = 1;
2473 break;
2474 }
2475 case ED_FISHING_HOOKED:
2476 EdFishingAngleHelpMEs(FishingGetEsaItemNo());
2477
2478 if (FishingFishStatus(NULL) != 8) {
2479 chara_fishing = ED_FISHING_WAIT_BITE;
2480 wait_cnt = 0;
2481
2482 if (rand() % 100 < 30) {
2483 EdFishingLostEsaMes();
2484 FishingDeleteEsa();
2485 }
2486
2487 st_cnt = 0;
2488 } else {
2489#ifdef PAL
2490 if (EdPadDown(0x40, 0xFFFF) != 0 || DebugMode) {
2491#else
2492 if (EdPadDown(0x40, 0xFFFF) != 0) {
2493#endif
2494 SndSePlay(SE_FISHING_CAST, pos, -1.0f, -1.0f);
2495 chara_fishing = ED_FISHING_BATTLE;
2496 chara->SetMotion(12, 2);
2497 FishingBattleFish(fish_no);
2498 fish_file = GetFishFileName(FishingFishKind(fish_no));
2499
2500 if (fish_file != NULL) {
2501 StartReadBG();
2502 LoadFileBG(fish_file, (u_long128 *) read_buffer, NULL);
2503 }
2504
2505 st_cnt = 0;
2506 }
2507
2508 tug = -(0.1f + 0.05f * (float) rand() / 2.1474836e9f);
2509
2510 if (tug < -0.12f) {
2511 GamePad.SetVibration(1, 100, 10);
2512 }
2513
2514 FishPullHook(tug);
2515 follow_line = 1;
2516 }
2517
2518 break;
2519 case ED_FISHING_BATTLE:
2520 FishingDeleteEsa();
2521
2522 if (st_cnt > 120 && ReadBGSync() == 0) {
2523 read_info = GetReadBGFile(0);
2524 fish_data = NULL;
2525 CDataAlloc2<1> arena(-1);
2526
2527 if (read_info != NULL) {
2528 fish_data = (u_int *) read_info->buffer;
2529 free_blocks = EdVillagerBuffer.limit - EdVillagerBuffer.used;
2530 arena.base = EdVillagerBuffer.base + EdVillagerBuffer.used * 16;
2531 arena.limit = free_blocks;
2532 arena.used = 0;
2533 }
2534
2535 chara_fishing = ED_FISHING_LANDED;
2536 chara->SetMotion(6, 6);
2537 FishingBattleToAngleFish(fish_data, &arena);
2538 SndSePlay(SE_FISHING_BITE, -1, 0);
2539 }
2540
2541 GamePad.SetVibration(1, rand() % 40 + 80, 10);
2542 follow_line = 1;
2543 break;
2544 case ED_FISHING_LANDED:
2545 chara_fishing = ED_FISHING_RESULT;
2546 chara->SetMotion(10, 6);
2547 fishing_mes = ED_FISHING_MES_EVALUATE;
2548 follow_line = 1;
2549 bgm_vol = SndGetBgmVol();
2550 SndBgmFadeOut(60, 0);
2551 break;
2552 case ED_FISHING_SINK:
2553 if (chara->motion_state == 3) {
2554 chara_fishing = ED_FISHING_STAND;
2555 chara->SetMotion(0, 0);
2556 FishingAngleFish(fish_no);
2557 FishingInitFishStatus();
2558 wait_cnt = 0;
2559 }
2560
2561 if (st_cnt > 40) {
2562 float_weight = 0.02f * (float) (st_cnt - 40);
2563 }
2564
2565 if (float_weight > 1.0f) {
2566 float_weight = 1.0f;
2567 }
2568
2569 break;
2570 case ED_FISHING_RESULT:
2571 camera->SetAngle(AngleLimit(facing[1]));
2572 camera->SetHeight(10.0f);
2573 camera->SetDistance(40.0f);
2574 camera->Step(-1);
2575
2576 if (chara->motion_no == 10) {
2577 if (chara->motion_state == 3) {
2578 chara->SetMotion(8, 0);
2579 SndSPSePlay(0x2F, -1);
2580 }
2581 } else {
2582 switch (fishing_mes) {
2583 case ED_FISHING_MES_EVALUATE: {
2584 int size;
2585 int fish_points;
2586 fish_kind = FishingGetAngleFishSize(&size, &fish_points);
2587
2588 if (fish_kind < 0) {
2589 fishing_mes = ED_FISHING_MES_DONE;
2590 } else {
2591 if (fish_kind == 5 || fish_kind == 17) {
2592 caught = &SaveData->mardan_garayan_caught;
2593 (*caught)++;
2594 SetFishMardanGarayanNum(1);
2595 }
2596
2597 SaveData->AddFishingPoint(fish_points);
2598 SaveData->SetFishingRank(fish_kind, (float) size);
2599 fishing_mes++;
2600 EditMes1.mes_no[0] = GetFishMsgNo(fish_kind);
2601 EditMes1.values[0] = size;
2602 EditMes1.values[1] = fish_points;
2603 EditMes1.values[2] = SaveData->GetFishingPoint();
2604 EditMes1.tail_on = false;
2605 EditMes1.auto_pos = MES_POS_TOP_LEFT;
2606 EditMes1.MakeMesWin(2000);
2607 EditMes1.auto_pos = MES_POS_TOP_LEFT;
2608 int window[4];
2609 EditMes1.AutoSet(window);
2610 }
2611
2612 break;
2613 }
2614 case ED_FISHING_MES_WAIT:
2615 if (EdMenuLoop(&EditMes1) != 0) {
2616 EditMes1.auto_pos = MES_POS_TOP_LEFT;
2617 fishing_mes++;
2618 }
2619
2620 break;
2621 case ED_FISHING_MES_DONE:
2622 SndBgmFadeIn(60, bgm_vol, 0);
2623 chara->SetMotion(0, 0);
2624 chara_fishing = ED_FISHING_FINISH;
2625 chara->SetMotion(9, 6);
2626 st_cnt = 0;
2627 break;
2628 }
2629 }
2630
2631 hook_weight = 1.0f;
2632 break;
2633 case ED_FISHING_FINISH:
2634 camera->SetAngle(AngleLimit(facing[1]));
2635 camera->SetHeight(10.0f);
2636 camera->SetDistance(30.0f);
2637 camera->Step(-1);
2638
2639 if (st_cnt == 120) {
2640 FishingDeleteAngleFish();
2641 SndSePlay(SE_FISHING_LANDED, -1, 0);
2642 }
2643
2644 if (chara->motion_state == 3) {
2645 chara->SetMotion(0, 0);
2646 chara_fishing = ED_FISHING_INIT;
2647 FishingDeleteAngleFish();
2648 FishingAngleFish(-1);
2649 FishingInitFishStatus();
2650 }
2651
2652 hook_weight = float_weight = 1.0f;
2653 break;
2654 }
2655
2656 // The camera watches the point halfway between the angler and the float.
2657 if (follow_line != 0) {
2658 sceVu0FVECTOR centre;
2659 FishLineGetUki(centre);
2660 sceVu0AddVector(centre, centre, pos);
2661 sceVu0ScaleVector(centre, centre, 0.5f);
2662 camera->SetFollow(centre[0], centre[1], centre[2]);
2663 }
2664
2665 st_cnt++;
2666 } else {
2667 chara_fishing = ED_FISHING_INIT;
2668 }
2669
2670 chara->Step();
2671
2672 if (viewMode == 0) {
2673 chara->ShadowStep();
2674 }
2675
2676 if (viewMode == 0) {
2677 chara->ClothStep(0);
2678 }
2679
2680 if (viewMode != 0) {
2681 chara->SetMotion(0, 0);
2682 }
2683
2684 if (EdMoveCharaInfo.fishing != 0) {
2685 sceVu0FVECTOR rod;
2686 chara->GetPosition(rod);
2687
2688 if (chara->frame != NULL) {
2689 sceVu0FVECTOR origin = {0.0f, 0.0f, 0.0f, 1.0f};
2690 sceVu0FVECTOR hook_pos;
2691 sceVu0FVECTOR float_pos;
2692 frame = chara->frame->SearchFrame("sao");
2693
2694 if (frame != NULL) {
2695 frame->GetWorldPosition(rod, origin);
2696 }
2697
2698 frame = chara->frame->SearchFrame("uki");
2699
2700 if (frame != NULL) {
2701 frame->GetWorldPosition(float_pos, origin);
2702 }
2703
2704 frame = chara->frame->SearchFrame("hari");
2705
2706 if (frame != NULL) {
2707 frame->GetWorldPosition(hook_pos, origin);
2708 }
2709
2710 frame = chara->frame->SearchFrame("maru_uki");
2711
2712 if (frame != NULL) {
2713 frame->attr.draw_on = 2;
2714 }
2715
2716 frame = chara->frame->SearchFrame("turibari");
2717
2718 if (frame != NULL) {
2719 frame->attr.draw_on = 2;
2720 }
2721
2722 FishLineSetUki(float_pos, float_weight);
2723 FishLineSetHook(hook_pos, hook_weight);
2724 }
2725
2726 fish = FishingGetBattleFish();
2727
2728 if (fish != NULL) {
2729 sceVu0FVECTOR fish_pos;
2730 fish->GetPosition(fish_pos);
2731 FishLineSetHook(fish_pos, 1.0f);
2732 }
2733
2734 sceVu0FVECTOR before;
2735 sceVu0FVECTOR after;
2736 FishLineGetUki(before);
2737 FishLineStep(rod, rod);
2738 FishingStepFish();
2739 FishLineGetUki(after);
2740 // The float throws up ripples where it crosses the surface.
2741 water_level = FishingGetWaterLevel();
2742
2743 if (after[1] < water_level && !(before[1] < water_level)) {
2744 fall_height = after[1] - before[1];
2745
2746 if ((fall_height < 0.0f ? -fall_height : fall_height) > 0.8f) {
2747 SndSePlay(SE_FISHING_SPLASH, after, -1.0f, -1.0f);
2748 after[1] = FishingGetWaterLevel();
2749 EffectHamon(&EdEffectGroup, after, 15.0f);
2750 EffectHamon(&EdEffectGroup, after, 20.0f);
2751 EffectHamon(&EdEffectGroup, after, 25.0f);
2752 EffectHamon(&EdEffectGroup, after, 30.0f);
2753 }
2754 }
2755
2756 if (after[1] > water_level && before[1] <= water_level) {
2757 rise = after[1] - before[1];
2758
2759 if ((rise < 0.0f ? -rise : rise) > 0.1f) {
2760 after[1] = FishingGetWaterLevel();
2761 EffectHamon(&EdEffectGroup, after, 10.0f);
2762 EffectHamon(&EdEffectGroup, after, 15.0f);
2763 EffectHamon(&EdEffectGroup, after, 20.0f);
2764 }
2765 }
2766 }
2767
2768 EdStepOpenItemBox();
2769 time_after = chara->motion_type.state.time;
2770 chara->FootSoundEnable(chara->move_info.landed);
2771 chara->SetFootSoundID(chara->move_info.ground_poly.attr.foot_sound);
2772
2773 // In the first-person view the feet sound by the distance walked instead of the motion.
2774 if (viewMode != 0 && interior != 0 && chara->move_info.landed != 0) {
2775 static float cnt = 0.0f;
2776 walked = cnt;
2777 velocity[1] = 0.0f;
2778 cnt += DistVector(velocity);
2779
2780 if (cnt > 10.0f && walked <= 10.0f) {
2781 SndPlayFootSound(chara->move_info.ground_poly.attr.foot_sound, 1, pos);
2782 }
2783
2784 if (cnt > 20.0f && walked <= 20.0f) {
2785 SndPlayFootSound(chara->move_info.ground_poly.attr.foot_sound, 0, pos);
2786 }
2787
2788 if (cnt > 20.0f) {
2789 cnt = 0.0f;
2790 }
2791 }
2792
2793 sceVu0CopyVector(chara->ground_ambient[0], EditMapInfo->character_ambient[0]);
2794 sceVu0CopyVector(chara->ground_ambient[1], EditMapInfo->character_ambient[1]);
2795 chara->ground_ambient_no = -1;
2796 chara->fade_out = 0;
2797 sceVu0FVECTOR unused = {0.0f, 0.0f, 0.0f, 0.0f};
2798
2799 if (chara->move_info.ground_found != 0) {
2800 floor_kind = chara->move_info.poly.attr.area_kind;
2801
2802 switch (floor_kind) {
2803 case AREA_KIND_FADE_OUT:
2804 chara->fade_out = 1;
2805 break;
2806 case AREA_KIND_AMBIENT_0:
2807 case AREA_KIND_AMBIENT_1:
2808 chara->ground_ambient_no = floor_kind - 3;
2809 break;
2810 }
2811 }
2812
2813 EdMoveCharaInfo.motion_time_before = time_before;
2814 EdMoveCharaInfo.motion_time_after = time_after;
2815}
2816
2817void EdInitHashigo(ED_EVENT_INFO *info, ED_EVENT_PARAM *param) {
2818 if (param->kind == ED_EVENT_POINT_LADDER_BOTTOM) {
2819 sceVu0CopyVector(info->vector_arguments[1], param->position);
2820 sceVu0CopyVector(info->vector_arguments[0], param->camera_pos);
2821 info->integer_arguments[0] = 0;
2822 } else {
2823 sceVu0CopyVector(info->vector_arguments[0], param->position);
2824 sceVu0CopyVector(info->vector_arguments[1], param->camera_pos);
2825 info->integer_arguments[0] = 1;
2826 }
2827
2828 sceVu0CopyVector(info->vector_arguments[2], param->rotation);
2829 info->flag_arguments[0] = (int) param->point->trigger_range[3];
2830 info->integer_arguments[1] = param->point->side;
2831 info->integer_arguments[2] = param->point->linked_value;
2832}
2833
2834int EdInitGotoInterior(ED_EVENT_INFO *info, ED_EVENT_PARAM *param) {
2835 sceVu0CopyVector(info->vector_arguments[0], param->position);
2836 sceVu0CopyVector(info->vector_arguments[1], param->rotation);
2837 sceVu0CopyVector(info->vector_arguments[2], param->camera_pos);
2838 return param->point->minimum_progress;
2839}
sceVu0FVECTOR min
Definition collision.hpp:29
sceVu0FVECTOR max
Definition collision.hpp:28
s16 foot_sound
Definition collision.hpp:56
s16 area_kind
Definition collision.hpp:57
sceVu0FVECTOR normal
Definition collision.hpp:49
void SetHeight(float height)
void AddDistance(float delta)
void SetFollow(float x, float y, float z)
void SetAngleSoon(float angle)
void AddAngle(float delta)
void SetDistance(float distance)
virtual void Step(int steps)
void SetAngle(float angle)
void AddHeight(float delta)
void GetRef(float *ref)
Definition camera.cpp:234
void SetRef(CFrame *parent, float x, float y, float z)
Definition camera.cpp:124
float GetAngleH()
Definition camera.cpp:238
void SetPos(CFrame *parent, float x, float y, float z)
Definition camera.cpp:103
void GetPos(float *pos)
Definition camera.cpp:230
void SetMotion(int no, int mode, float speed=-1.0f)
CFrame * frame
virtual void GetPosition(float *out_position)
MOTION_INFO * GetMotionInfo(int motion_no)
void SetFootSoundID(int id)
virtual void Step()
sceVu0FVECTOR ground_ambient[2]
void SetMotionSpeed(float speed)
virtual void ShadowStep()
tagMOTION_TYPE motion_type
virtual void SetRotation(float x, float y, float z)
void FootSoundEnable(int on)
s32 ground_ambient_no
float body_height
float GetNowTime()
virtual void SetPosition(float x, float y, float z)
virtual void ClothStep(int step)
u_char * base
Definition dataalloc.hpp:24
s32 width
Definition ebattle.cpp:75
s32 x
Definition ebattle.cpp:73
s32 height
Definition ebattle.cpp:76
s32 y
Definition ebattle.cpp:74
int PickUpCameraPoly(CCPoly *out_polygons, CBoxVu0 &box, int flags)
int PickUpPoly(CCPoly *polygons, float x, float y, float z)
Definition fish.hpp:57
void GetPosition(float *position)
Definition fish.cpp:403
short draw_on
Definition frame.hpp:27
CFrameAttr attr
Definition frame.hpp:65
int GetPadDown()
Definition gamepad.cpp:517
int On(int mask)
Definition gamepad.cpp:557
float GetRYf()
Definition gamepad.cpp:537
int Down(int mask)
Definition gamepad.cpp:583
void MenuModeOff()
Definition gamepad.cpp:617
float GetLXf()
Definition gamepad.cpp:541
void MenuModeOn(int threshold)
Definition gamepad.cpp:613
float GetLYf()
Definition gamepad.cpp:545
void SetVibration(int motor, int intensity, int duration)
Definition gamepad.cpp:621
float GetRXf()
Definition gamepad.cpp:533
MoveCheckInfo move_info
CFrame * GetCollisionFrame()
Definition mapobject.cpp:12
virtual int PickUpPoly(float *position, CCPoly *polygons)
virtual void GetRotation(float *out_rotation)
Definition object.cpp:116
virtual void SetVelocity(CVector3_f_ velocity)
Definition object.cpp:50
virtual void GetVelocity(CVector3_f_ *out_velocity)
Definition object.cpp:100
s32 x
Definition rect.hpp:18
s32 width
Definition rect.hpp:20
s32 height
Definition rect.hpp:21
s32 y
Definition rect.hpp:19
void SetFishingRank(int fish_id, float score)
Definition savedata.cpp:129
s32 GetFishingPoint() const
Definition savedata.hpp:492
void AddFishingPoint(int add)
Definition savedata.cpp:105
s32 mardan_garayan_caught
Definition savedata.hpp:144
s32 auto_pos
Definition clsmes.hpp:172
s32 tail_on
Definition clsmes.hpp:173
s32 mes_no[10]
Definition clsmes.hpp:216
void AutoSet(int *pos)
Definition clsmes.cpp:173
s32 values[8]
Definition clsmes.hpp:217
int MakeMesWin(int mes_no)
Definition clsmes.cpp:1669
CDataAlloc2< 1 > * WorkBuffer__2
Definition dataread.hpp:250
@ INTERPOLATE_STEP
Definition mathutil.hpp:15
u_long128 * buffer
Definition dataread.hpp:29
Definition ebattle.cpp:206
int hit
Definition ebattle.cpp:211
int frame
Definition ebattle.cpp:207
int buttons
Definition ebattle.cpp:208
int highlight
Definition ebattle.cpp:213
int mode
Definition ebattle.cpp:209
int pressed
Definition ebattle.cpp:210
int passed
Definition ebattle.cpp:212
int passed
Definition ebattle.cpp:49
int pressed
Definition ebattle.cpp:47
int frame
Definition ebattle.cpp:44
int highlight
Definition ebattle.cpp:50
int buttons
Definition ebattle.cpp:45
int hit
Definition ebattle.cpp:48
int mode
Definition ebattle.cpp:46
Definition ebattle.cpp:195
int frames
Definition ebattle.cpp:200
float speed
Definition ebattle.cpp:199
float start
Definition ebattle.cpp:197
int motion_no
Definition ebattle.cpp:196
float end
Definition ebattle.cpp:198
float end
Definition ebattle.cpp:61
int motion_no
Definition ebattle.cpp:59
float start
Definition ebattle.cpp:60
float speed
Definition ebattle.cpp:62
int frames
Definition ebattle.cpp:63
float character_ambient[4][4]
Definition editloop.hpp:322
s32 integer_arguments[8]
Definition edit.hpp:213
s32 draw_exclamation_mark
Definition edit.hpp:198
s32 flag_arguments[8]
Definition edit.hpp:214
sceVu0FVECTOR vector_arguments[4]
Definition edit.hpp:212
sceVu0FVECTOR position
Definition edit.hpp:72
sceVu0FVECTOR camera_pos
Definition edit.hpp:73
ED_EVENT_POINT * point
Definition edit.hpp:76
sceVu0FVECTOR rotation
Definition edit.hpp:74
sceVu0FVECTOR trigger_range
Definition editloop.hpp:258
CCamera * view_camera
Definition edit.hpp:87
ED_EVENT_PARAM param
Definition edit.hpp:96
float motion_time_before
Definition edit.hpp:104
CCameraFollow * camera
Definition edit.hpp:86
float motion_time_after
Definition edit.hpp:103
CCharacter * chara
Definition edit.hpp:85
CEditGround * ground
Definition edit.hpp:91
ED_EVENT_POINT * points
Definition edit.hpp:97
CMapParts * parts
Definition edit.hpp:92
CCPoly ground_poly
Definition gameutil.hpp:471
MOTION_STATE state
Definition gameutil.hpp:273