DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
fishing.cpp
1#include "fishing.hpp"
2
3#include <libgraph.h>
4#include <libpkt.h>
5#include <libvu0.h>
6
7#include <cstdlib>
8#include <cstring>
9
10#include "boxvu0.hpp"
11#include "dataalloc.hpp"
12#include "dataread.hpp"
13#include "edit.hpp"
14#include "editloop3.hpp"
15#include "fish.hpp"
16#include "framevu1.hpp"
17#include "mainselect.hpp"
18#include "mathutil.hpp"
19#include "mds.hpp"
20#include "mglib.hpp"
21#include "savedata.hpp"
22#include "snd.hpp"
23#include "texture.hpp"
24
28struct EsaInfo {
29 int item_no;
30 float radius;
31};
32
36static EsaInfo esa_info[13] = {
37 {ITEM_EVY, 50.0f},
38 {ITEM_MIMI, 25.0f},
39 {ITEM_PRICKLY, 25.0f},
40 {ITEM_THROBBING_CHERRY, 25.0f},
41 {ITEM_GOOEY_PEACH, 25.0f},
42 {ITEM_BOMB_NUTS, 25.0f},
43 {ITEM_POISONOUS_APPLE, 25.0f},
44 {ITEM_MELLOW_BANANA, 25.0f},
45 {ITEM_CARROT, 25.0f},
46 {ITEM_POTATO_CAKE, 25.0f},
47 {ITEM_MINON, 25.0f},
48 {ITEM_BATTAN, 25.0f},
49 {ITEM_PETITE_FISH, 40.0f},
50};
51
52int draw_under_water = 1;
53float distp = 1.6666666f;
54float WaterLevel;
55float GroundLevel;
56float UkiGroundLevel;
57float HookGroundLevel;
58float LineGroundLevel;
59CFrameVu1 *EsaFrame;
60int esa_type;
61CFrame *HookFrame;
62CFrame *UkiFrame;
63int fishing_texb;
64int fish_texb;
65int esa_texb;
66CFish *Fish;
67CFish *AngleFish;
68CFish *BattleFish;
69int FishNum;
70CCPoly *cpoly;
71int cpoly_num;
72int set_hook_pos;
73int set_uki_pos;
74float pull_hook;
75CBoxVu0 fishing_rect;
76CBoxVu0 fish_rect;
77CFrameVu1 UkiFrameTop;
78CCharacter Rod;
79sceVu0FVECTOR point[24];
80sceVu0FVECTOR old_p[24];
81sceVu0FVECTOR velo[24];
82sceVu0FVECTOR hookp[3];
83sceVu0FVECTOR hookop[3];
84sceVu0FVECTOR hookv[3];
85float hook_dist[3];
86sceVu0FVECTOR ukip[4];
87sceVu0FVECTOR ukiop[4];
88sceVu0FVECTOR ukiv[4];
89float uki_dist[6];
90sceVu0FVECTOR rod_top;
91sceVu0FVECTOR fishhook;
92sceVu0FVECTOR uki;
93
94static void GetHookPos(float *position);
95
96void FishingLoad(CDataAlloc2<1> *alloc, int slot) {
97 LoadFile("chara/fishing.pak", read_buffer, NULL);
98 fishing_texb = slot;
99 HookFrame = LoadMDSFile(GetPackFile(read_buffer, "hari.mds", NULL), alloc, 0, NULL, NULL);
100 UkiFrame = LoadMDSFile(GetPackFile(read_buffer, "uki.mds", NULL), alloc, 0, NULL, NULL);
101 CFrameAttr attr;
102 attr.use_color = true;
103
104 if (UkiFrame != NULL) {
105 UkiFrame->SetAttr(attr, 1, 0x200);
106 }
107
108 cpoly = (CCPoly *) alloc->Alloc(0x1800);
109 cpoly_num = 0;
110 SndSPSeLoad(0x2F);
111}
112
113void FishingLoadFish(int spot, CDataAlloc2<1> *alloc, int slot) {
114 int rare_interval;
115 int loaded;
116
117 draw_under_water = 1;
118
119 if (spot == 3) {
120 draw_under_water = 0;
121 }
122
123 Fish = new ((u_long128 *) alloc->Alloc(0xD8C)) CFish[6];
124 fish_texb = slot;
125 FishNum = 5;
126
127 if (spot == 0) {
128 FishNum = 4;
129 }
130
131 if (spot == 4) {
132 FishNum = 4;
133 }
134
135#ifdef PAL
136 if (DebugMode) {
137 FishNum = 5;
138 }
139
140#endif
141 rare_interval = 30;
142
143 switch (EdGetTime(SaveData->GetNowTime())) {
144 case ED_TIME_DAY:
145 rare_interval = 50;
146 break;
147 case ED_TIME_EVENING:
148 rare_interval = 20;
149 break;
150 case ED_TIME_NIGHT:
151 rare_interval = 35;
152 break;
153 case ED_TIME_MORNING:
154 rare_interval = 25;
155 break;
156 }
157
158 loaded = false;
159 LoadFile("chara/f00s.chr", read_buffer, NULL);
160
161 for (int i = 0; i < FishNum; i++) {
162 int kind = -1;
163 int rand_value = rand();
164
165 switch (spot) {
166 case 0:
167 switch ((int) (3.99999f * rnd())) {
168 case 0:
169 kind = 1;
170 break;
171 case 1:
172 kind = 2;
173 break;
174 case 2:
175 kind = 6;
176 break;
177 case 3:
178 kind = 7;
179 break;
180 }
181
182 break;
183 case 1: {
184 int roll = 100.0f * rnd();
185
186 if (roll < 35) {
187 kind = 1;
188 } else if (roll < 70) {
189 kind = 4;
190 } else if (roll < 80) {
191 kind = 9;
192 } else if (roll < 100) {
193 kind = 10;
194 }
195
196 break;
197 }
198 case 2:
199 if (rand_value % rare_interval == 0) {
200 if (rand() % 5 == 0) {
201 kind = 17;
202 } else {
203 kind = 5;
204 }
205 } else {
206 rand_value %= 3;
207
208 if (rand_value == 0) {
209 kind = 2;
210 }
211
212 if (rand_value == 1) {
213 kind = 4;
214 }
215
216 if (rand_value == 2) {
217 kind = 6;
218 }
219 }
220
221 break;
222 case 3: {
223 int roll = rand_value % 100;
224
225 if (roll < 20) {
226 kind = 0;
227 } else if (roll < 40) {
228 kind = 3;
229 } else if (roll < 60) {
230 kind = 11;
231 } else if (roll < 80) {
232 kind = 12;
233 } else {
234 kind = 13;
235 }
236
237 break;
238 }
239 case 4:
240 if (rand_value % rare_interval == 0) {
241 if (rand() % 5 == 0) {
242 kind = 17;
243 } else {
244 kind = 5;
245 }
246 } else {
247 int roll = rand_value % 100;
248
249 if (roll < 40) {
250 kind = 14;
251 } else if (roll < 70) {
252 kind = 15;
253 } else if (roll < 100) {
254 kind = 16;
255 }
256 }
257
258 break;
259 }
260
261#ifdef PAL
262 if (DebugMode) {
263 static int fish_type[5][8] = {
264 {1, 2, 6, 7, 1, 2, 6, 7},
265 {1, 4, 9, 10, 1, 4, 9, 10},
266 {2, 4, 6, 5, 17, 2, 4, 6},
267 {0, 3, 11, 12, 13, 0, 3, 11},
268 {14, 15, 16, 5, 17}
269 };
270 kind = fish_type[spot][i % 5];
271 }
272
273#endif
274 LoadFish(&Fish[i], kind, slot, alloc, loaded);
275 loaded = true;
276 }
277}
278
280 Initialize();
281}
282
283void FishingLoadEsa(int item_no, CFrameVu1 *frame, int slot) {
284 if (esa_type >= 0) {
285 EdGetItem(esa_info[esa_type].item_no, 1, -1);
286 }
287
288 EsaFrame = frame;
289 esa_texb = slot;
290 esa_type = 0;
291
292 for (int i = 0; i < 13; i++) {
293 if (item_no == esa_info[i].item_no) {
294 esa_type = i;
295 return;
296 }
297 }
298}
299
300void FishingDeleteEsa() {
301 EsaFrame = NULL;
302 esa_type = -1;
303}
304
305int FishingGetEsaItemNo() {
306 if (esa_type < 0) {
307 return -1;
308 }
309
310 return esa_info[esa_type].item_no;
311}
312
313void FishingInit() {
314 WaterLevel = 0.0f;
315 GroundLevel = 0.0f;
316 HookFrame = NULL;
317 UkiFrame = NULL;
318 EsaFrame = NULL;
319 esa_type = -1;
320 UkiFrameTop.Initialize();
321 Rod.Initialize();
322 esa_texb = -99;
323 fish_texb = -99;
324 fishing_texb = -99;
325 Fish = NULL;
326 FishNum = 0;
327 AngleFish = NULL;
328 BattleFish = NULL;
329 cpoly = NULL;
330 cpoly_num = 0;
331}
332
333void FishingExit() {
334 if (esa_type >= 0) {
335 EdGetItem(esa_info[esa_type].item_no, 1, -1);
336 }
337
338 for (int i = 0; i < 6; i++) {
339 Fish[i].Initialize();
340 }
341
342 FishingInit();
343}
344
345void FishingSetWaterLevel(float water_level, float ground_level) {
346 WaterLevel = water_level;
347 GroundLevel = ground_level;
348 FishingSetGroundLevel(ground_level, ground_level);
349}
350
351void FishingSetGroundLevel(float uki_height, float hook_height) {
352 UkiGroundLevel = uki_height;
353 HookGroundLevel = hook_height;
354}
355
356float FishingGetWaterLevel() {
357 return WaterLevel;
358}
359
360void FishingSetCPoly(CCPoly *polys, int count) {
361 for (int i = 0; i < count; i++) {
362 memcpy(&cpoly[i], &polys[i], sizeof(CCPoly));
363 }
364
365 cpoly_num = count;
366}
367
368void FishingSetRect(CBoxVu0 bounds) {
369 memcpy(&fishing_rect, &bounds, sizeof(CBoxVu0));
370}
371
372int FishingPickUpPoly(CCPoly *polys) {
373 sceVu0FVECTOR corner[8];
374 sceVu0FVECTOR bound[2];
375
376 sceVu0CopyVector(bound[0], fishing_rect.min);
377 sceVu0CopyVector(bound[1], fishing_rect.max);
378
379 for (int i = 0; i < 8; i++) {
380 corner[i][3] = 1.0f;
381 corner[i][0] = bound[(i & 1) != 0][0];
382 corner[i][1] = bound[(i & 2) != 0][1];
383 corner[i][2] = bound[(i & 4) != 0][2];
384 }
385
386 int face[8][3] = {
387 {0, 1, 2},
388 {1, 3, 2},
389 {1, 5, 3},
390 {5, 7, 3},
391 {5, 4, 7},
392 {4, 6, 7},
393 {4, 0, 6},
394 {0, 2, 6},
395 };
396
397 for (int i = 0; i < 8; i++) {
398 CCPoly *poly = &polys[i];
399 memset(poly, 0, sizeof(CCPoly));
400
401 for (int j = 0; j < 3; j++) {
402 sceVu0CopyVector(poly->vertex[j], corner[face[i][j]]);
403 }
404
405 PlaneNormal(poly->normal, poly->vertex[0], poly->vertex[1], poly->vertex[2]);
406 }
407
408 return 8;
409}
410
411void FishingInitFish(CBoxVu0 bounds) {
412 sceVu0FVECTOR position;
413
414 if (Fish == NULL) {
415 return;
416 }
417
418 memcpy(&fish_rect, &bounds, sizeof(CBoxVu0));
419
420 for (int i = 0; i < FishNum; i++) {
421 position[0] = 0.5f * (bounds.max[0] + bounds.min[0]);
422 position[1] = WaterLevel - 12.0f;
423 position[2] = 0.5f * (bounds.max[2] + bounds.min[2]);
424 Fish[i].SetPosition(position);
425 Fish[i].SetCPoly(cpoly, cpoly_num);
426 }
427}
428
429int FishingFishStatus(int *fish_no) {
430 int status;
431
432 if (Fish == NULL) {
433 return -1;
434 }
435
436 status = -1;
437
438 for (int i = 0; i < 6; i++) {
439 if (fish_no != NULL) {
440 *fish_no = i;
441 }
442
443 CFish *fish;
444
445 if (status == -1) {
446 fish = &Fish[i];
447
448 if (fish->action == FISH_ACTION_EAT_FOOD) {
449 status = FISH_ACTION_EAT_FOOD;
450 }
451 }
452
453 fish = &Fish[i];
454
455 if (fish->action == FISH_ACTION_BITE_HOOK) {
456 return FISH_ACTION_BITE_HOOK;
457 }
458
459 if (fish->action == FISH_ACTION_BATTLE) {
460 return FISH_ACTION_BATTLE;
461 }
462 }
463
464 return status;
465}
466
467void FishingBattleFish(int fish_no) {
468 BattleFish = NULL;
469
470 if (fish_no >= 0 && fish_no < 6) {
471 CFish *fish = &Fish[fish_no];
472
473 if (fish->action == FISH_ACTION_BITE_HOOK) {
474 BattleFish = fish;
475 fish->SetBattleMode();
476 }
477 }
478}
479
480int FishingFishKind(int fish_no) {
481 // The range check can never fail: it needs both bounds exceeded at once.
482 if (fish_no < 0 && fish_no >= 6) {
483 return -1;
484 }
485
486 return Fish[fish_no].fish_kind;
487}
488
489void FishingBattleToAngleFish(u_int *pack, CDataAlloc2<1> *alloc) {
490 AngleFish = BattleFish;
491 BattleFish = NULL;
492
493 if (AngleFish != NULL) {
494 if (pack != NULL) {
495 CCharacter *model = &AngleFish->angle_model;
496 model->LoadPackData2(pack, "info.cfg", alloc, fish_texb + 1, alloc, 0);
497 }
498
499 AngleFish->SetAngleMode();
500 CFish *fish = AngleFish;
501 fish->use_angle_model = true;
502 }
503}
504
505char fishing_err_format[] __attribute__((section(".rodata"))) = "err %d\n";
506
507CFish *FishingGetBattleFish() {
508 return BattleFish;
509}
510
511void FishingAngleFish(int fish_no) {
512 AngleFish = NULL;
513
514 if (fish_no >= 0 && fish_no < 6) {
515 CFish *fish = &Fish[fish_no];
516
517 if (fish->action == FISH_ACTION_BITE_HOOK) {
518 AngleFish = fish;
519 fish->SetAngleMode();
520 fish = &Fish[fish_no];
521 fish->use_angle_model = true;
522 }
523 }
524}
525
526int FishingGetAngleFishSize(int *size, int *fp) {
527 if (AngleFish == NULL) {
528 return -1;
529 }
530
531 float length = AngleFish->size;
532 *size = length * 10.0f;
533 *fp = AngleFish->GetFP();
534 return AngleFish->fish_kind;
535}
536
537void FishingInitFishStatus() {
538 if (Fish != NULL) {
539 for (int i = 0; i < 6; i++) {
540 CFish *fish = &Fish[i];
541 fish->action = FISH_ACTION_NONE;
542 fish->move_mode = FISH_MOVE_UNSET;
543 fish->use_angle_model = false;
544 }
545 }
546}
547
548void FishingDeleteAngleFish() {
549 if (AngleFish != NULL) {
550 AngleFish->fish_kind = -1;
551 }
552}
553
554void FishingStepFish() {
555 sceVu0FVECTOR hook;
556
557 GetHookPos(hook);
558 hook[1] -= 3.0f;
559
560 if (Fish == NULL) {
561 return;
562 }
563
564 if (AngleFish != NULL) {
565 AngleFish->Step();
566 return;
567 }
568
569 for (int i = 0; i < 6; i++) {
570 if (esa_type < 0 || EsaFrame == NULL) {
571 float radius = 0.0f;
572 Fish[i].SetFoodPos(-1, hook, radius);
573 } else {
574 float radius = esa_info[esa_type].radius;
575
576#ifdef PAL
577 // Debug builds let every fish notice the bait from anywhere.
578 if (DebugMode) {
579 radius = 100000000;
580 }
581
582#endif
583 Fish[i].SetFoodPos(esa_type, hook, radius);
584 }
585
586 Fish[i].Step();
587 }
588}
589
590void FishingDrawFish() {
591 if (Fish == NULL) {
592 return;
593 }
594
595 if (AngleFish != NULL) {
596 TexManager.ReloadTexture(GetVif1Packet(), fish_texb + 1);
597 AngleFish->SetReference(HookFrame);
598 sceVu0FVECTOR position = {0.0f, 0.0f, 0.0f, 0.0f};
599 sceVu0FVECTOR rotation = {-1.57f, 1.57f, 0.0f, 0.0f};
600 AngleFish->SetPosition(position);
601 AngleFish->SetRotation(rotation);
602 AngleFish->Draw();
603 AngleFish->DeleteReference();
604 } else {
605 TexManager.ReloadTexture(GetVif1Packet(), fish_texb);
606
607 if (draw_under_water) {
608 for (int i = 0; i < 6; i++) {
609 Fish[i].Draw();
610 }
611 }
612 }
613}
614
622static void GetHookPos(float *position) {
623 sceVu0CopyVector(position, hookp[0]);
624}
625
629static int hook_link[3][2] = {
630 {0, 1},
631 {0, 2},
632 {1, 2}
633};
634
638static int uki_link[6][2] = {
639 {0, 1},
640 {0, 2},
641 {0, 3},
642 {1, 2},
643 {2, 3},
644 {3, 1}
645};
646
647void FishLineInit(float *position) {
648 sceVu0FVECTOR p;
649 int i;
650
651 set_uki_pos = 0;
652 set_hook_pos = 0;
653 pull_hook = 0.0f;
654 sceVu0FVECTOR zero = {0.0f, 0.0f, 0.0f, 0.0f};
655 sceVu0CopyVector(rod_top, position);
656 sceVu0CopyVector(p, position);
657 p[3] = 1.0f;
658
659 for (i = 0; i < 24; i++) {
660 sceVu0CopyVector(point[i], p);
661 sceVu0CopyVector(old_p[i], p);
662 sceVu0CopyVector(velo[i], zero);
663 p[1] -= distp;
664 }
665
666 for (i = 0; i < 3; i++) {
667 sceVu0CopyVector(hookp[i], point[23]);
668 }
669
670 for (i = 1; i < 3; i++) {
671 hookp[i][1] -= 2.0f;
672 }
673
674 hookp[1][0] -= 1.0f;
675 hookp[2][0] += 1.0f;
676
677 for (i = 0; i < 3; i++) {
678 sceVu0CopyVector(hookop[i], hookp[i]);
679 sceVu0CopyVector(hookv[i], zero);
680 }
681
682 for (i = 0; i < 3; i++) {
683 hook_dist[i] = DistVector(hookp[hook_link[i][0]], hookp[hook_link[i][1]]);
684 }
685
686 for (i = 0; i < 4; i++) {
687 sceVu0CopyVector(ukip[i], point[18]);
688 }
689
690 for (i = 1; i < 4; i++) {
691 ukip[i][1] -= 0.866f;
692 }
693
694 ukip[1][2] += 1.005f;
695 ukip[2][0] += 0.866f;
696 ukip[2][2] -= 0.5f;
697 ukip[3][0] -= 0.866f;
698 ukip[3][2] -= 0.5f;
699
700 for (i = 0; i < 4; i++) {
701 sceVu0CopyVector(ukiop[i], ukip[i]);
702 sceVu0CopyVector(ukiv[i], zero);
703 }
704
705 for (i = 0; i < 6; i++) {
706 uki_dist[i] = DistVector(ukip[uki_link[i][0]], ukip[uki_link[i][1]]);
707 }
708}
709
710void FishLineSetUki(float *position, float rate) {
711 sceVu0FVECTOR offset;
712
713 if (rate < 0.0f) {
714 set_uki_pos = 0;
715 return;
716 }
717
718 sceVu0SubVector(offset, position, ukip[0]);
719 sceVu0ScaleVector(offset, offset, rate);
720 sceVu0AddVector(uki, ukip[0], offset);
721 set_uki_pos = 1;
722}
723
724void FishLineSetHook(float *position, float rate) {
725 sceVu0FVECTOR offset;
726
727 if (rate < 0.0f) {
728 set_hook_pos = 0;
729 return;
730 }
731
732 sceVu0SubVector(offset, position, hookp[0]);
733 sceVu0ScaleVector(offset, offset, rate);
734 sceVu0AddVector(fishhook, hookp[0], offset);
735 set_hook_pos = 1;
736}
737
738void FishPullHook(float tension) {
739 pull_hook = tension;
740}
741
742void FishLineGetUki(float *position) {
743 sceVu0CopyVector(position, point[18]);
744}
745
746void FishLineGetHook(float *position) {
747 sceVu0CopyVector(position, point[23]);
748}
749
750int FishingCheckUkiHook() {
751 sceVu0FVECTOR uki_pos;
752 sceVu0FVECTOR hook_pos;
753 float water;
754
755 FishLineGetUki(uki_pos);
756 FishLineGetHook(hook_pos);
757
758 for (int i = 0; i < 3; i++) {
759 if (fishing_rect.max[i] < uki_pos[i]) {
760 return 1;
761 }
762
763 if (fishing_rect.max[i] < hook_pos[i]) {
764 return 1;
765 }
766
767 if (fishing_rect.min[i] > uki_pos[i]) {
768 return 1;
769 }
770
771 if (fishing_rect.min[i] > hook_pos[i]) {
772 return 1;
773 }
774 }
775
776 water = 5.0f + FishingGetWaterLevel();
777
778 if (hook_pos[1] > water) {
779 return 1;
780 }
781
782 if (uki_pos[1] > water) {
783 return 1;
784 }
785
786 return 0;
787}
788
789void FishLineStep(float *rod_position, float *unused) {
790 sceVu0FVECTOR hook_from;
791 sceVu0FVECTOR hook_to;
792 sceVu0FVECTOR uki_from;
793 sceVu0FVECTOR uki_to;
794 sceVu0FVECTOR hit;
795 sceVu0FVECTOR normal;
796 sceVu0FVECTOR diff;
797 sceVu0FVECTOR move0;
798 sceVu0FVECTOR move1;
799 float water;
800 float weight;
801 int i;
802 int iteration;
803
804 if (cpoly != NULL) {
805 sceVu0CopyVector(hook_from, point[23]);
806 sceVu0CopyVector(hook_to, point[23]);
807 hook_from[1] += 40.0f;
808 hook_to[1] -= 40.0f;
809 int hit_no = CheckHit(cpoly, cpoly_num, hook_from, hook_to, hit, 1, 0);
810
811 if (hit_no >= 0) {
812 sceVu0Normalize(normal, cpoly[hit_no].normal);
813 float slope = normal[1] < 0.0f ? -normal[1] : normal[1];
814
815 if (slope > 0.2f) {
816 HookGroundLevel = 0.2f + hit[1];
817 }
818 }
819
820 sceVu0CopyVector(uki_from, point[18]);
821 sceVu0CopyVector(uki_to, point[18]);
822 uki_from[1] += 40.0f;
823 uki_to[1] -= 40.0f;
824 hit_no = CheckHit(cpoly, cpoly_num, uki_from, uki_to, hit, 1, 0);
825
826 if (hit_no >= 0) {
827 sceVu0Normalize(normal, cpoly[hit_no].normal);
828 float slope = normal[1] < 0.0f ? -normal[1] : normal[1];
829
830 if (slope > 0.2f) {
831 UkiGroundLevel = 1.0f + hit[1];
832 }
833 }
834 }
835
836 if (UkiGroundLevel < HookGroundLevel) {
837 LineGroundLevel = UkiGroundLevel;
838 } else {
839 LineGroundLevel = HookGroundLevel;
840 }
841
842 water = WaterLevel;
843
844 sceVu0CopyVector(rod_top, rod_position);
845 rod_top[3] = 1.0f;
846 fishhook[3] = 1.0f;
847
848 for (i = 0; i < 24; i++) {
849 velo[i][1] += -0.1f;
850 velo[i][3] = 0.0f;
851 sceVu0AddVector(point[i], point[i], velo[i]);
852 }
853
854 weight = pull_hook;
855 point[23][1] += weight;
856
857 for (i = 0; i < 3; i++) {
858 hookv[i][1] += -0.1f + weight;
859 hookv[i][3] = 0.0f;
860 sceVu0AddVector(hookp[i], hookp[i], hookv[i]);
861 }
862
863 for (i = 0; i < 4; i++) {
864 ukiv[i][1] += -0.1f + weight;
865 ukiv[i][3] = 0.0f;
866 sceVu0AddVector(ukip[i], ukip[i], ukiv[i]);
867 }
868
869 for (iteration = 0; iteration < 16; iteration++) {
870 sceVu0CopyVector(point[0], rod_top);
871 sceVu0CopyVector(old_p[0], rod_top);
872
873 for (i = 1; i < 24; i++) {
874 weight = 0.5f;
875
876 if (i == 23) {
877 weight = 0.9f;
878 }
879
880 float rest = 1.0f - weight;
881 float *near = point[i - 1];
882 float *far = point[i];
883 sceVu0SubVector(diff, near, far);
884 float length = DistVector(diff);
885 float stretch = length - distp;
886 float scale = rest * stretch / length;
887 weight = weight * stretch / length;
888 sceVu0ScaleVector(move0, diff, scale);
889 sceVu0ScaleVector(move1, diff, weight);
890 sceVu0SubVector(near, near, move0);
891 sceVu0AddVector(far, far, move1);
892 }
893
894 sceVu0CopyVector(hookp[0], point[23]);
895
896 for (i = 0; i < 3; i++) {
897 sceVu0SubVector(diff, hookp[hook_link[i][0]], hookp[hook_link[i][1]]);
898 float length = DistVector(diff);
899 sceVu0ScaleVector(move0, diff, 0.5f * (length - hook_dist[i]) / length);
900 sceVu0SubVector(hookp[hook_link[i][0]], hookp[hook_link[i][0]], move0);
901 sceVu0AddVector(hookp[hook_link[i][1]], hookp[hook_link[i][1]], move0);
902 }
903
904 sceVu0SubVector(diff, point[18], ukip[0]);
905 float length = DistVector(diff);
906 weight = 0.2f;
907 float scale = length * (1.0f - weight) / length;
908 weight = length * weight / length;
909 sceVu0ScaleVector(move0, diff, scale);
910 sceVu0ScaleVector(move1, diff, weight);
911 sceVu0SubVector(point[18], point[18], move0);
912 sceVu0AddVector(ukip[0], ukip[0], move1);
913
914 for (i = 0; i < 6; i++) {
915 sceVu0SubVector(diff, ukip[uki_link[i][0]], ukip[uki_link[i][1]]);
916 float length = DistVector(diff);
917 sceVu0ScaleVector(move0, diff, 0.5f * (length - uki_dist[i]) / length);
918 sceVu0SubVector(ukip[uki_link[i][0]], ukip[uki_link[i][0]], move0);
919 sceVu0AddVector(ukip[uki_link[i][1]], ukip[uki_link[i][1]], move0);
920 }
921
922 if (set_hook_pos) {
923 sceVu0CopyVector(point[23], fishhook);
924 sceVu0CopyVector(hookp[0], fishhook);
925 }
926
927 if (set_uki_pos) {
928 sceVu0CopyVector(point[18], uki);
929 sceVu0CopyVector(ukip[0], uki);
930 }
931 }
932
933 for (i = 0; i < 24; i++) {
934 sceVu0SubVector(velo[i], point[i], old_p[i]);
935
936 if (i != 23) {
937 sceVu0ScaleVector(velo[i], velo[i], 0.96f);
938 } else {
939 sceVu0ScaleVector(velo[i], velo[i], 0.999f);
940 }
941
942 if (point[i][1] < LineGroundLevel) {
943 point[i][1] = LineGroundLevel;
944 velo[i][0] *= 0.4f;
945 velo[i][1] *= -0.4f;
946 velo[i][2] *= 0.4f;
947 }
948
949 if (point[i][1] < water) {
950 sceVu0ScaleVector(velo[i], velo[i], 0.4f);
951
952 if (i < 19) {
953 velo[i][1] += 0.1f;
954 }
955 }
956
957 sceVu0CopyVector(old_p[i], point[i]);
958 }
959
960 for (i = 0; i < 3; i++) {
961 sceVu0SubVector(hookv[i], hookp[i], hookop[i]);
962
963 if (hookp[i][1] < HookGroundLevel) {
964 hookp[i][1] = HookGroundLevel;
965 hookv[i][0] *= 0.8f;
966 hookv[i][1] *= -0.6f;
967 hookv[i][2] *= 0.8f;
968 }
969
970 sceVu0CopyVector(hookop[i], hookp[i]);
971 sceVu0ScaleVector(hookv[i], hookv[i], 0.99f);
972 }
973
974 for (i = 0; i < 4; i++) {
975 sceVu0SubVector(ukiv[i], ukip[i], ukiop[i]);
976
977 if (ukip[i][1] < UkiGroundLevel) {
978 ukip[i][1] = UkiGroundLevel;
979 ukiv[i][0] *= 0.6f;
980 ukiv[i][1] *= -0.8f;
981 ukiv[i][2] *= 0.6f;
982 }
983
984 if (i != 0 && ukip[i][1] < water && ukip[0][1] < water) {
985 sceVu0ScaleVector(ukiv[i], ukiv[i], 0.6f);
986 ukiv[i][1] += 0.3f;
987 }
988
989 if (ukip[0][1] < water && !(ukip[i][1] < water)) {
990 float height = ukip[0][1] - ukip[i][1];
991 float depth = ukip[0][1] - ukip[i][1];
992 height = depth < 0.0f ? -depth : height;
993 ukiv[i][0] *= 0.6f;
994 ukiv[i][2] *= 0.6f;
995
996 if ((depth < 0.0f ? -depth : depth) > 0.001f) {
997 ukiv[i][1] += 0.3f * (water - ukip[0][1]) / height;
998 }
999 }
1000
1001 if (ukip[i][1] < water && !(ukip[0][1] < water)) {
1002 float height = ukip[i][1] - ukip[0][1];
1003 height = height < 0.0f ? -height : height;
1004 float depth = ukip[0][1] - ukip[i][1];
1005
1006 if ((depth < 0.0f ? -depth : depth) > 0.001f) {
1007 ukiv[i][1] += 0.3f * (water - ukip[i][1]) / height;
1008 }
1009 }
1010
1011 sceVu0CopyVector(ukiop[i], ukip[i]);
1012 sceVu0ScaleVector(ukiv[i], ukiv[i], 0.999f);
1013 }
1014
1015 LineGroundLevel = HookGroundLevel = UkiGroundLevel = GroundLevel;
1016 set_uki_pos = 0;
1017 set_hook_pos = 0;
1018 pull_hook = 0.0f;
1019}
1020
1021void FishLineDraw(int above_water) {
1022 int screen[4];
1023 sceVu0FVECTOR center;
1024 sceVu0FVECTOR direction;
1025 sceVu0FMATRIX matrix;
1026 sceVu0FVECTOR uki_top;
1027 sceVu0FVECTOR hook_top;
1028 sceVu0FVECTOR esa_position;
1029 sceGsTest test;
1030 int draw;
1031 int visible;
1032 int prev_visible;
1033 int i;
1034 sceVif1Packet *packet;
1035
1036 TexManager.ReloadTexture(GetVif1Packet(), fishing_texb);
1037 prev_visible = 0;
1038 packet = GetVif1Packet();
1039 sceVif1PkCnt(packet, 0);
1040 sceVif1PkOpenDirectCode(packet, 0);
1041 sceVif1PkOpenGifTag(packet, *(u_long128 *) &GiftagAD);
1042 sceVif1PkAddGsAD(packet, SCE_GS_PRIM, SCE_GS_SET_PRIM(2, 1, 0, 0, 1, 0, 1, 0, 0));
1043 sceVif1PkAddGsAD(packet, SCE_GS_RGBAQ, SCE_GS_SET_RGBAQ(0x80, 0x80, 0x80, 0x80, 0));
1044 test = mgPixelTest;
1045 test.bits.aref = 0;
1046 sceVif1PkAddGsAD(packet, SCE_GS_TEST_1, *(u_long *) &test);
1047
1048 for (i = 0; i < 24; i++) {
1049 visible = MGRotTransPers(screen, point[i], 0);
1050 u_char above = point[i][1] > WaterLevel;
1051 int reg = SCE_GS_XYZF2;
1052
1053 if (visible == 0 || prev_visible == 0) {
1054 reg = SCE_GS_XYZF3;
1055 }
1056
1057 if (above_water) {
1058 if (!above) {
1059 reg = SCE_GS_XYZF3;
1060 }
1061 } else if (above || draw_under_water == 0) {
1062 reg = SCE_GS_XYZF3;
1063 }
1064
1065 sceVif1PkAddGsAD(packet, reg, (u_long) screen[0] | ((u_long) screen[1] << 16) | ((u_long) screen[2] << 32));
1066 prev_visible = visible;
1067 }
1068
1069 sceVif1PkAddGsAD(packet, SCE_GS_TEST_1, *(u_long *) &mgPixelTest);
1070 sceVif1PkCloseGifTag(packet);
1071 sceVif1PkCloseDirectCode(packet);
1072
1073 draw = true;
1074 VectorMax(uki_top, ukip[0], ukip[1], ukip[2], ukip[3]);
1075
1076 if (above_water) {
1077 if (uki_top[1] < WaterLevel) {
1078 draw = false;
1079 }
1080 } else if (uki_top[1] > WaterLevel || draw_under_water == 0) {
1081 draw = false;
1082 }
1083
1084 if (UkiFrame != NULL && draw) {
1085 sceVu0AddVector(center, ukip[1], ukip[2]);
1086 sceVu0AddVector(center, center, ukip[3]);
1087 sceVu0ScaleVector(center, center, 0.333333f);
1088 sceVu0SubVector(direction, ukip[0], center);
1089 sceVu0Normalize(matrix[1], direction);
1090 matrix[1][3] = 0.0f;
1091 sceVu0SubVector(direction, center, ukip[1]);
1092 sceVu0Normalize(matrix[2], direction);
1093 sceVu0OuterProduct(matrix[0], matrix[1], matrix[2]);
1094 matrix[0][3] = 0.0f;
1095 matrix[3][0] = matrix[3][1] = matrix[3][2] = 0.0f;
1096 matrix[3][3] = 1.0f;
1097 UkiFrameTop.Initialize();
1098 UkiFrameTop.SetTransMatrix(matrix);
1099 UkiFrameTop.SetPosition(ukip[0]);
1100 UkiFrame->SetReference(&UkiFrameTop);
1101 MGDraw(UkiFrame);
1102 }
1103
1104 draw = true;
1105 VectorMax(hook_top, hookp[0], hookp[1], hookp[2]);
1106
1107 if (above_water) {
1108 if (hook_top[1] < WaterLevel) {
1109 draw = false;
1110 }
1111 } else if (hook_top[1] > WaterLevel || draw_under_water == 0) {
1112 draw = false;
1113 }
1114
1115 if (HookFrame != NULL && draw) {
1116 sceVu0AddVector(center, hookp[1], hookp[2]);
1117 sceVu0ScaleVector(center, center, 0.5f);
1118 sceVu0SubVector(direction, hookp[0], center);
1119 sceVu0Normalize(matrix[1], direction);
1120 matrix[1][3] = 0.0f;
1121 sceVu0SubVector(center, hookp[1], hookp[0]);
1122 sceVu0SubVector(direction, hookp[2], hookp[0]);
1123 sceVu0OuterProduct(matrix[2], center, direction);
1124 sceVu0Normalize(matrix[2], matrix[2]);
1125 matrix[2][3] = 0.0f;
1126 sceVu0OuterProduct(matrix[0], matrix[1], matrix[2]);
1127 matrix[0][3] = 0.0f;
1128 matrix[3][0] = matrix[3][1] = matrix[3][2] = 0.0f;
1129 matrix[3][3] = 1.0f;
1130 HookFrame->SetTransMatrix(matrix);
1131 HookFrame->SetPosition(hookp[0]);
1132 MGDraw(HookFrame);
1133
1134 if (EsaFrame != NULL) {
1135 sceVu0AddVector(esa_position, hookp[0], hookp[1]);
1136 sceVu0AddVector(esa_position, esa_position, hookp[2]);
1137 sceVu0ScaleVector(esa_position, esa_position, 0.3333f);
1138 EsaFrame->SetTransMatrix(matrix);
1139 EsaFrame->SetPosition(esa_position);
1140 TexManager.ReloadTexture(GetVif1Packet(), esa_texb);
1141 MGDraw(EsaFrame);
1142 }
1143 }
1144}
sceVu0FVECTOR min
Definition collision.hpp:29
sceVu0FVECTOR max
Definition collision.hpp:28
sceVu0FVECTOR normal
Definition collision.hpp:49
sceVu0FVECTOR vertex[3]
Definition collision.hpp:48
virtual void LoadPackData2(unsigned int *pack, char *name, CDataAlloc2< 1 > *alloc, int texture_block_no, CDataAlloc2< 1 > *image_alloc, int visual_type)
virtual void Initialize()
Definition fish.hpp:57
void Step()
Definition fish.cpp:133
void Draw()
Definition fish.cpp:326
void DeleteReference()
Definition fish.cpp:422
CCharacter angle_model
Definition fish.hpp:80
FishMoveMode move_mode
Definition fish.hpp:61
void SetPosition(float *position)
Definition fish.cpp:398
float size
Definition fish.hpp:66
void SetRotation(float *rotation)
Definition fish.cpp:405
void SetAngleMode()
Definition fish.cpp:344
FishAction action
Definition fish.hpp:62
s32 fish_kind
Definition fish.hpp:59
void SetCPoly(CCPoly *polys, int count)
Definition fish.cpp:128
void SetBattleMode()
Definition fish.cpp:350
CFish()
Definition fishing.cpp:279
void SetFoodPos(int kind, float *position, float radius)
Definition fish.cpp:338
void SetReference(CFrame *reference)
Definition fish.cpp:412
void Initialize()
Definition fish.cpp:432
int GetFP()
Definition fish.cpp:377
s32 use_angle_model
Definition fish.hpp:65
char use_color
Definition frame.hpp:38
virtual void Initialize()
Definition frame.cpp:1341
float GetNowTime()
Definition savedata.cpp:61
float radius
Definition fishing.cpp:30
int item_no
Definition fishing.cpp:29